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-store-UID nil
638 "Non-nil means, store any created UIDs in properties.
639 The iCalendar standard requires that all entries have a unique identifyer.
640 Org will create these identifiers as needed. When this variable is non-nil,
641 the created UIDs will be stored in the ID property of the entry. Then the
642 next time this entry is exported, it will be exported with the same UID,
643 superceeding the previous form of it. This is essential for
644 synchronization services.
645 This variable is not turned on by default because we want to avoid creating
646 a property drawer in every entry if people are only playing with this feature,
647 or if they are only using it locally."
648 :group
'org-export-icalendar
653 ;;; Variables, constants, and parameter plists
655 (defconst org-level-max
20)
657 (defvar org-export-html-preamble nil
658 "Preamble, to be inserted just after <body>. Set by publishing functions.")
659 (defvar org-export-html-postamble nil
660 "Preamble, to be inserted just before </body>. Set by publishing functions.")
661 (defvar org-export-html-auto-preamble t
662 "Should default preamble be inserted? Set by publishing functions.")
663 (defvar org-export-html-auto-postamble t
664 "Should default postamble be inserted? Set by publishing functions.")
665 (defvar org-current-export-file nil
) ; dynamically scoped parameter
666 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
668 (defconst org-export-plist-vars
669 '((:link-up . org-export-html-link-up
)
670 (:link-home . org-export-html-link-home
)
671 (:language . org-export-default-language
)
672 (:customtime . org-display-custom-times
)
673 (:headline-levels . org-export-headline-levels
)
674 (:section-numbers . org-export-with-section-numbers
)
675 (:table-of-contents . org-export-with-toc
)
676 (:preserve-breaks . org-export-preserve-breaks
)
677 (:archived-trees . org-export-with-archived-trees
)
678 (:emphasize . org-export-with-emphasize
)
679 (:sub-superscript . org-export-with-sub-superscripts
)
680 (:special-strings . org-export-with-special-strings
)
681 (:footnotes . org-export-with-footnotes
)
682 (:drawers . org-export-with-drawers
)
683 (:tags . org-export-with-tags
)
684 (:TeX-macros . org-export-with-TeX-macros
)
685 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
686 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
687 (:fixed-width . org-export-with-fixed-width
)
688 (:timestamps . org-export-with-timestamps
)
689 (:author-info . org-export-author-info
)
690 (:time-stamp-file . org-export-time-stamp-file
)
691 (:tables . org-export-with-tables
)
692 (:table-auto-headline . org-export-highlight-first-table-line
)
693 (:style . org-export-html-style
)
694 (:agenda-style . org-agenda-export-html-style
)
695 (:convert-org-links . org-export-html-link-org-files-as-html
)
696 (:inline-images . org-export-html-inline-images
)
697 (:html-extension . org-export-html-extension
)
698 (:html-table-tag . org-export-html-table-tag
)
699 (:expand-quoted-html . org-export-html-expand
)
700 (:timestamp . org-export-html-with-timestamp
)
701 (:publishing-directory . org-export-publishing-directory
)
702 (:preamble . org-export-html-preamble
)
703 (:postamble . org-export-html-postamble
)
704 (:auto-preamble . org-export-html-auto-preamble
)
705 (:auto-postamble . org-export-html-auto-postamble
)
706 (:author . user-full-name
)
707 (:email . user-mail-address
)))
709 (defun org-default-export-plist ()
710 "Return the property list with default settings for the export variables."
711 (let ((l org-export-plist-vars
) rtn e
)
712 (while (setq e
(pop l
))
713 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
716 (defvar org-export-inbuffer-options-extra nil
717 "List of additional in-buffer options that should be detected.
718 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
719 etc. Extensions can add to this list to get their options detected, and they
720 can then add a function to `org-export-options-filters' to process these
722 Each element in this list must be a list, with the in-buffer keyword as car,
723 and a property (a symbol) as the next element. All occurences of the
724 keyword will be found, the values concatenated with a space character
725 in between, and the result stored in the export options property list.")
727 (defvar org-export-options-filters nil
728 "Functions to be called to finalize the export/publishing options.
729 All these options are stored in a property list, and each of the functions
730 in this hook gets a chance to modify this property list. Each function
731 must accept the property list as an argument, and must return the (possibly
734 (defun org-infile-export-plist ()
735 "Return the property list with file-local settings for export."
739 (goto-char (point-min))
740 (let ((re (org-make-options-regexp
742 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
743 "LINK_UP" "LINK_HOME" "SETUPFILE")
744 (mapcar 'car org-export-inbuffer-options-extra
))))
745 p key val text options js-up js-main js-css js-opt a pr
746 ext-setup-or-nil setup-contents
(start 0))
747 (while (or (and ext-setup-or-nil
748 (string-match re ext-setup-or-nil start
)
749 (setq start
(match-end 0)))
750 (and (setq ext-setup-or-nil nil start
0)
751 (re-search-forward re nil t
)))
752 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
753 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
755 ((setq a
(assoc key org-export-inbuffer-options-extra
))
757 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
758 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
759 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
760 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
761 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
762 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
763 ((string-equal key
"TEXT")
764 (setq text
(if text
(concat text
"\n" val
) val
)))
765 ((string-equal key
"OPTIONS")
766 (setq options
(concat val
" " options
)))
767 ((string-equal key
"LINK_UP")
768 (setq p
(plist-put p
:link-up val
)))
769 ((string-equal key
"LINK_HOME")
770 (setq p
(plist-put p
:link-home val
)))
771 ((equal key
"SETUPFILE")
772 (setq setup-contents
(org-file-contents
774 (org-remove-double-quotes
777 (if (not ext-setup-or-nil
)
778 (setq ext-setup-or-nil setup-contents start
0)
779 (setq ext-setup-or-nil
780 (concat (substring ext-setup-or-nil
0 start
)
781 "\n" setup-contents
"\n"
782 (substring ext-setup-or-nil start
)))))))
783 (setq p
(plist-put p
:text text
))
785 (setq p
(org-export-add-options-to-plist p options
)))
788 (defun org-export-add-options-to-plist (p options
)
789 "Parse an OPTONS line and set values in the property list P."
792 (let ((op '(("H" .
:headline-levels
)
793 ("num" .
:section-numbers
)
794 ("toc" .
:table-of-contents
)
795 ("\\n" .
:preserve-breaks
)
796 ("@" .
:expand-quoted-html
)
799 ("^" .
:sub-superscript
)
800 ("-" .
:special-strings
)
805 ("TeX" .
:TeX-macros
)
806 ("LaTeX" .
:LaTeX-fragments
)
807 ("skip" .
:skip-before-1st-heading
)
808 ("author" .
:author-info
)
809 ("timestamp" .
:time-stamp-file
)))
811 (while (setq o
(pop op
))
812 (if (string-match (concat (regexp-quote (car o
))
813 ":\\([^ \t\n\r;,.]*\\)")
815 (setq p
(plist-put p
(cdr o
)
816 (car (read-from-string
817 (match-string 1 options
))))))))))
820 (defun org-export-add-subtree-options (p pos
)
821 "Add options in subtree at position POS to property list P."
824 (when (org-at-heading-p)
826 ;; This is actually read in `org-export-get-title-from-subtree'
827 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
828 ;; (setq p (plist-put p :title a)))
829 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
830 (setq p
(plist-put p
:text a
)))
831 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
832 (setq p
(org-export-add-options-to-plist p a
)))))
835 (defun org-export-directory (type plist
)
836 (let* ((val (plist-get plist
:publishing-directory
))
838 (or (cdr (assoc type val
)) ".")
842 (defun org-export-process-option-filters (plist)
843 (let ((functions org-export-options-filters
) f
)
844 (while (setq f
(pop functions
))
845 (setq plist
(funcall f plist
))))
849 (defun org-export (&optional arg
)
850 "Export dispatcher for Org-mode.
851 When `org-export-run-in-background' is non-nil, try to run the command
852 in the background. This will be done only for commands that write
853 to a file. For details see the docstring of `org-export-run-in-background'.
855 The prefix argument ARG will be passed to the exporter. However, if
856 ARG is a double universal prefix `C-u C-u', that means to inverse the
857 value of `org-export-run-in-background'."
859 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
860 (help "[t] insert the export option template
861 \[v] limit export to visible part of outline tree
866 \[H] export as HTML to temporary buffer
867 \[R] export region as HTML
868 \[b] export as HTML and browse immediately
872 \[L] export as LaTeX to temporary buffer
874 \[i] export current file as iCalendar file
875 \[I] export all agenda files as iCalendar files
876 \[c] export agenda files into combined iCalendar file
878 \[F] publish current file
879 \[P] publish current project
880 \[X] publish... (project will be prompted for)
881 \[A] publish all projects")
883 '((?t org-insert-export-options-template nil
)
884 (?v org-export-visible nil
)
885 (?a org-export-as-ascii t
)
886 (?h org-export-as-html t
)
887 (?b org-export-as-html-and-open t
)
888 (?H org-export-as-html-to-buffer nil
)
889 (?R org-export-region-as-html nil
)
890 (?x org-export-as-xoxo t
)
891 (?l org-export-as-latex t
)
892 (?L org-export-as-latex-to-buffer nil
)
893 (?i org-export-icalendar-this-file t
)
894 (?I org-export-icalendar-all-agenda-files t
)
895 (?c org-export-icalendar-combine-agenda-files t
)
896 (?F org-publish-current-file t
)
897 (?P org-publish-current-project t
)
899 (?A org-publish-all t
)))
901 (save-window-excursion
902 (delete-other-windows)
903 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
905 (message "Select command: ")
906 (setq r1
(read-char-exclusive)))
907 (setq r2
(if (< r1
27) (+ r1
96) r1
))
908 (unless (setq ass
(assq r2 cmds
))
909 (error "No command associated with key %c" r1
))
910 (if (and bg
(nth 2 ass
))
911 ;; execute in background
912 (let ((p (start-process
913 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
915 (expand-file-name invocation-name invocation-directory
)
918 "--eval" "(require 'org-exp)"
919 "--eval" "(setq org-wait .2)"
921 "-f" (symbol-name (nth 1 ass
)))))
922 (set-process-sentinel p
'org-export-process-sentinel
)
923 (message "Background process \"%s\": started" p
))
924 ;; background processing not requested, or not possible
925 (call-interactively (nth 1 ass
)))))
927 (defun org-export-process-sentinel (process status
)
928 (if (string-match "\n+\\'" status
)
929 (setq status
(substring status
0 -
1)))
930 (message "Background process \"%s\": %s" process status
))
932 (defconst org-html-entities
973 ("Aring") ("AA".
"Å")
1062 ("varepsilon".
"ε")
1075 ("sigmaf") ("varsigma".
"ς")
1083 ("thetasym") ("vartheta".
"ϑ")
1086 ("bull") ("bullet".
"•")
1087 ("hellip") ("dots".
"…")
1097 ("larr") ("leftarrow".
"←") ("gets".
"←")
1098 ("uarr") ("uparrow".
"↑")
1099 ("rarr") ("to".
"→") ("rightarrow".
"→")
1100 ("darr")("downarrow".
"↓")
1101 ("harr") ("leftrightarrow".
"↔")
1102 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1103 ("lArr") ("Leftarrow".
"⇐")
1104 ("uArr") ("Uparrow".
"⇑")
1105 ("rArr") ("Rightarrow".
"⇒")
1106 ("dArr") ("Downarrow".
"⇓")
1107 ("hArr") ("Leftrightarrow".
"⇔")
1109 ("part") ("partial".
"∂")
1110 ("exist") ("exists".
"∃")
1111 ("empty") ("emptyset".
"∅")
1113 ("isin") ("in".
"∈")
1119 ("lowast") ("ast".
"∗")
1121 ("prop") ("proptp".
"∝")
1122 ("infin") ("infty".
"∞")
1123 ("ang") ("angle".
"∠")
1124 ("and") ("wedge".
"∧")
1125 ("or") ("vee".
"∨")
1131 ("cong") ("simeq".
"≅")
1132 ("asymp")("approx".
"≈")
1133 ("ne") ("neq".
"≠")
1137 ("sub") ("subset".
"⊂")
1138 ("sup") ("supset".
"⊃")
1145 ("sdot") ("cdot".
"⋅")
1152 ("loz") ("Diamond".
"◊")
1153 ("spades") ("spadesuit".
"♠")
1154 ("clubs") ("clubsuit".
"♣")
1155 ("hearts") ("diamondsuit".
"♥")
1156 ("diams") ("diamondsuit".
"♦")
1157 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1224 "Entities for TeX->HTML translation.
1225 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1226 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1227 In that case, \"\\ent\" will be translated to \"&other;\".
1228 The list contains HTML entities for Latin-1, Greek and other symbols.
1229 It is supplemented by a number of commonly used TeX macros with appropriate
1230 translations. There is currently no way for users to extend this.")
1232 ;;; General functions for all backends
1234 (defun org-export-preprocess-string (string &rest parameters
)
1235 "Cleanup STRING so that that the true exported has a more consistent source.
1236 This function takes STRING, which should be a buffer-string of an org-file
1237 to export. It then creates a temporary buffer where it does its job.
1238 The result is then again returned as a string, and the exporter works
1239 on this string to produce the exported version."
1241 (let* ((re-radio (and org-target-link-regexp
1242 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1243 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1244 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1245 (re-archive (concat ":" org-archive-tag
":"))
1246 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1247 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1248 (htmlp (plist-get parameters
:for-html
))
1249 (asciip (plist-get parameters
:for-ascii
))
1250 (latexp (plist-get parameters
:for-LaTeX
))
1251 (commentsp (plist-get parameters
:comments
))
1252 (archived-trees (plist-get parameters
:archived-trees
))
1253 (inhibit-read-only t
)
1254 (drawers org-drawers
)
1255 (exp-drawers (plist-get parameters
:drawers
))
1256 (outline-regexp "\\*+ ")
1257 target-alist tmp target level
1260 (with-current-buffer (get-buffer-create " org-mode-tmp")
1263 (setq case-fold-search t
)
1265 (run-hooks 'org-export-preprocess-hook
)
1267 ;; Remove license-to-kill stuff
1268 ;; The caller markes some stuff fo killing, stuff that has been
1269 ;; used to create the page title, for example.
1270 (while (setq p
(text-property-any (point-min) (point-max)
1271 :org-license-to-kill t
))
1272 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1274 (let ((org-inhibit-startup t
)) (org-mode))
1275 (setq case-fold-search t
)
1276 (untabify (point-min) (point-max))
1278 ;; Handle incude files
1279 (org-export-handle-include-files)
1281 ;; Handle source code snippets
1282 (org-export-replace-src-segments)
1284 ;; Get rid of drawers
1285 (unless (eq t exp-drawers
)
1286 (goto-char (point-min))
1287 (let ((re (concat "^[ \t]*:\\("
1290 (org-delete-all exp-drawers
1291 (copy-sequence drawers
))
1293 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1294 (while (re-search-forward re nil t
)
1295 (replace-match ""))))
1297 ;; Get the correct stuff before the first headline
1298 (when (plist-get parameters
:skip-before-1st-heading
)
1299 (goto-char (point-min))
1300 (when (re-search-forward "^\\*+[ \t]" nil t
)
1301 (delete-region (point-min) (match-beginning 0))
1302 (goto-char (point-min))
1304 (when (plist-get parameters
:add-text
)
1305 (goto-char (point-min))
1306 (insert (plist-get parameters
:add-text
) "\n"))
1308 ;; Get rid of archived trees
1309 (when (not (eq archived-trees t
))
1310 (goto-char (point-min))
1311 (while (re-search-forward re-archive nil t
)
1312 (if (not (org-on-heading-p t
))
1313 (org-end-of-subtree t
)
1314 (beginning-of-line 1)
1315 (setq a
(if archived-trees
1316 (1+ (point-at-eol)) (point))
1317 b
(org-end-of-subtree t
))
1318 (if (> b a
) (delete-region a b
)))))
1320 ;; Find all headings and compute the targets for them
1321 (goto-char (point-min))
1322 (org-init-section-numbers)
1323 (let ((re (concat "^" org-outline-regexp
)))
1324 (while (re-search-forward re nil t
)
1325 (setq level
(org-reduced-level
1326 (save-excursion (goto-char (point-at-bol))
1327 (org-outline-level))))
1328 (setq target
(org-solidify-link-text
1329 (format "sec-%s" (org-section-number level
))))
1330 (push (cons target target
) target-alist
)
1331 (add-text-properties
1332 (point-at-bol) (point-at-eol)
1333 (list 'target target
))))
1335 ;; Find targets in comments and move them out of comments,
1336 ;; but mark them as targets that should be invisible
1337 (goto-char (point-min))
1338 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1339 ;; Check if the line before or after is a headline with a target
1340 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1341 (get-text-property (point-at-bol 2) 'target
)))
1343 ;; use the existing target in a neighboring line
1344 (setq tmp
(match-string 2))
1346 (and (looking-at "\n") (delete-char 1))
1347 (push (cons (org-solidify-link-text tmp
) target
)
1349 ;; Make an invisible target
1350 (replace-match "\\1(INVISIBLE)")))
1352 ;; Protect backend specific stuff, throw away the others.
1354 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1355 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1356 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1358 (goto-char (point-min))
1359 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1360 (goto-char (match-end 0))
1361 (while (not (looking-at "#\\+END_EXAMPLE"))
1363 (beginning-of-line 2)))
1364 (goto-char (point-min))
1365 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1366 (add-text-properties (match-beginning 0) (match-end 0)
1367 '(org-protected t
)))
1369 (setq fmt
(pop formatters
))
1371 (goto-char (point-min))
1372 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1373 ":[ \t]*\\(.*\\)") nil t
)
1374 (replace-match "\\1" t
)
1375 (add-text-properties
1376 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1377 '(org-protected t
))))
1378 (goto-char (point-min))
1379 (while (re-search-forward
1381 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1382 (cadddr fmt
) "\\>.*\n?") nil t
)
1384 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1386 (delete-region (match-beginning 0) (match-end 0))))))
1388 ;; Protect quoted subtrees
1389 (goto-char (point-min))
1390 (while (re-search-forward re-quote nil t
)
1391 (goto-char (match-beginning 0))
1393 (add-text-properties (point) (org-end-of-subtree t
)
1394 '(org-protected t
)))
1396 ;; Protect verbatim elements
1397 (goto-char (point-min))
1398 (while (re-search-forward org-verbatim-re nil t
)
1399 (add-text-properties (match-beginning 4) (match-end 4)
1401 (goto-char (1+ (match-end 4))))
1404 (goto-char (point-min))
1405 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*" nil t
)
1406 (replace-match (if (equal (downcase (match-string 1)) "end")
1407 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1410 (goto-char (point-min))
1411 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1412 (replace-match (if (equal (downcase (match-string 1)) "end")
1413 "ORG-VERSE-END" "ORG-VERSE-START")
1416 ;; Remove comment environment
1417 (goto-char (point-min))
1418 (while (re-search-forward
1419 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1420 (replace-match "" t t
))
1422 ;; Remove subtrees that are commented
1423 (goto-char (point-min))
1424 (while (re-search-forward re-commented nil t
)
1425 (goto-char (match-beginning 0))
1426 (delete-region (point) (org-end-of-subtree t
)))
1428 ;; Remove special table lines
1429 (when org-export-table-remove-special-lines
1430 (goto-char (point-min))
1431 (while (re-search-forward "^[ \t]*|" nil t
)
1432 (beginning-of-line 1)
1433 (if (or (looking-at "[ \t]*| *[!_^] *|")
1434 (and (looking-at ".*?| *<[0-9]+> *|")
1435 (not (looking-at ".*?| *[^ <|]"))))
1436 (delete-region (max (point-min) (1- (point-at-bol)))
1440 ;; Specific LaTeX stuff
1442 (require 'org-export-latex nil
)
1443 (org-export-latex-preprocess))
1446 (org-export-ascii-clean-string))
1448 ;; Specific HTML stuff
1450 ;; Convert LaTeX fragments to images
1451 (when (plist-get parameters
:LaTeX-fragments
)
1453 (concat "ltxpng/" (file-name-sans-extension
1454 (file-name-nondirectory
1455 org-current-export-file
)))
1456 org-current-export-dir nil
"Creating LaTeX image %s"))
1457 (message "Exporting..."))
1459 ;; Remove or replace comments
1460 (goto-char (point-min))
1461 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1462 (setq pos
(match-beginning 0))
1464 (progn (add-text-properties
1465 (match-beginning 0) (match-end 0) '(org-protected t
))
1466 (replace-match (format commentsp
(match-string 1)) t t
))
1467 (goto-char (1+ pos
))
1470 (goto-char (max (point-min) (1- pos
))))
1473 ;; Find matches for radio targets and turn them into internal links
1474 (goto-char (point-min))
1476 (while (re-search-forward re-radio nil t
)
1478 (replace-match "\\1[[\\2]]"))))
1480 ;; Find all links that contain a newline and put them into a single line
1481 (goto-char (point-min))
1482 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1484 (replace-match "\\1 \\3")
1485 (goto-char (match-beginning 0))))
1487 ;; Find all internal links. If they have a fuzzy match (i.e. not
1488 ;; a *dedicated* target match, let the link point to the
1489 ;; correspinding section.
1491 (goto-char (point-min))
1492 (while (re-search-forward org-bracket-link-regexp nil t
)
1494 (let* ((md (match-data))
1495 (desc (match-end 2))
1496 (link (org-link-unescape (match-string 1)))
1497 (slink (org-solidify-link-text link
))
1500 (or (cdr (assoc slink target-alist
))
1502 (unless (string-match org-link-types-re link
)
1503 (setq found
(condition-case nil
(org-link-search link
)
1506 (or (org-on-heading-p)
1507 (not (eq found
'dedicated
))))
1508 (or (get-text-property (point) 'target
)
1511 (1- (previous-single-property-change
1516 (goto-char (match-beginning 1))
1517 (setq props
(text-properties-at (point)))
1518 (delete-region (match-beginning 1) (match-end 1))
1521 (unless desc
(insert "][" link
))
1522 (add-text-properties pos
(point) props
)))))
1524 ;; Normalize links: Convert angle and plain links into bracket links
1525 ;; Expand link abbreviations
1526 (goto-char (point-min))
1527 (while (re-search-forward re-plain-link nil t
)
1528 (goto-char (1- (match-end 0)))
1530 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1531 ":" (match-string 3) "]]")))
1532 ;; added 'org-link face to links
1533 (put-text-property 0 (length s
) 'face
'org-link s
)
1534 (replace-match s t t
))))
1535 (goto-char (point-min))
1536 (while (re-search-forward re-angle-link nil t
)
1537 (goto-char (1- (match-end 0)))
1539 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1540 ":" (match-string 3) "]]")))
1541 (put-text-property 0 (length s
) 'face
'org-link s
)
1542 (replace-match s t t
))))
1543 (goto-char (point-min))
1544 (while (re-search-forward org-bracket-link-regexp nil t
)
1546 (let* ((s (concat "[[" (setq xx
(save-match-data
1547 (org-link-expand-abbrev (match-string 1))))
1551 (concat "[" xx
"]"))
1553 (put-text-property 0 (length s
) 'face
'org-link s
)
1554 (replace-match s t t
))))
1556 ;; Find multiline emphasis and put them into single line
1557 (when (plist-get parameters
:emph-multiline
)
1558 (goto-char (point-min))
1559 (while (re-search-forward org-emph-re nil t
)
1560 (if (not (= (char-after (match-beginning 3))
1561 (char-after (match-beginning 4))))
1563 (subst-char-in-region (match-beginning 0) (match-end 0)
1565 (goto-char (1- (match-end 0))))
1566 (goto-char (1+ (match-beginning 0))))))
1568 (setq rtn
(buffer-string)))
1569 (kill-buffer " org-mode-tmp")
1572 (defun org-export-grab-title-from-buffer ()
1573 "Get a title for the current document, from looking at the buffer."
1574 (let ((inhibit-read-only t
))
1576 (goto-char (point-min))
1577 (let ((end (save-excursion (outline-next-heading) (point))))
1578 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1579 ;; Mark the line so that it will not be exported as normal text.
1581 (add-text-properties (match-beginning 0) (match-end 0)
1582 (list :org-license-to-kill t
)))
1583 ;; Return the title string
1584 (org-trim (match-string 0)))))))
1586 (defun org-export-get-title-from-subtree ()
1587 "Return subtree title and exclude it from export."
1588 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1591 (when (and (org-at-heading-p)
1592 (>= (org-end-of-subtree t t
) rend
))
1593 ;; This is a subtree, we take the title from the first heading
1595 (looking-at org-todo-line-regexp
)
1596 (setq title
(match-string 3))
1598 (add-text-properties (point) (1+ (point-at-eol))
1599 (list :org-license-to-kill t
)))
1600 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1603 (defun org-solidify-link-text (s &optional alist
)
1604 "Take link text and make a safe target out of it."
1609 (org-split-string s
"[ \t\r\n]+") "=="))
1610 (a (assoc rtn alist
)))
1613 (defun org-get-min-level (lines)
1614 "Get the minimum level in LINES."
1615 (let ((re "^\\(\\*+\\) ") l min
)
1617 (while (setq l
(pop lines
))
1618 (if (string-match re l
)
1619 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1622 ;; Variable holding the vector with section numbers
1623 (defvar org-section-numbers
(make-vector org-level-max
0))
1625 (defun org-init-section-numbers ()
1626 "Initialize the vector for the section numbers."
1628 (numbers (nreverse (org-split-string "" "\\.")))
1629 (depth (1- (length org-section-numbers
)))
1630 (i depth
) number-string
)
1633 (aset org-section-numbers i
0)
1634 (setq number-string
(or (car numbers
) "0"))
1635 (if (string-match "\\`[A-Z]\\'" number-string
)
1636 (aset org-section-numbers i
1637 (- (string-to-char number-string
) ?A -
1))
1638 (aset org-section-numbers i
(string-to-number number-string
)))
1642 (defun org-section-number (&optional level
)
1643 "Return a string with the current section number.
1644 When LEVEL is non-nil, increase section numbers on that level."
1645 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1648 (aset org-section-numbers
1649 level
(1+ (aref org-section-numbers level
))))
1650 (setq idx
(1+ level
))
1651 (while (<= idx depth
)
1653 (aset org-section-numbers idx
0))
1654 (setq idx
(1+ idx
))))
1656 (while (<= idx depth
)
1657 (setq n
(aref org-section-numbers idx
))
1658 (setq string
(concat string
(if (not (string= string
"")) "." "")
1660 (setq idx
(1+ idx
)))
1662 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1663 (setq string
(replace-match "" t nil string
)))
1664 (if (string-match "\\(\\.0\\)+\\'" string
)
1665 (setq string
(replace-match "" t nil string
))))
1670 (defun org-export-handle-include-files ()
1671 "Include the contents of include files, with proper formatting."
1672 (let ((case-fold-search t
)
1673 params file markup lang start end
)
1674 (goto-char (point-min))
1675 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1676 (setq params
(read (concat "(" (match-string 1) ")"))
1677 file
(org-symname-or-string (pop params
))
1678 markup
(org-symname-or-string (pop params
))
1679 lang
(org-symname-or-string (pop params
)))
1680 (delete-region (match-beginning 0) (match-end 0))
1682 (not (file-exists-p file
))
1683 (not (file-readable-p file
)))
1684 (insert (format "CANNOT INCLUDE FILE %s" file
))
1686 (if (equal (downcase markup
) "src")
1687 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1689 (setq start
(format "#+begin_%s\n" markup
)
1690 end
(format "#+end_%s" markup
))))
1691 (insert (or start
""))
1692 (forward-char (nth 1 (insert-file-contents (expand-file-name file
))))
1693 (or (bolp) (newline))
1694 (insert (or end
""))))))
1696 (defun org-symname-or-string (s)
1698 (if s
(symbol-name s
) s
)
1701 ;;; Fontification of code
1702 ;; Currently only for th HTML backend, but who knows....
1703 (defun org-export-replace-src-segments ()
1704 "Replace source code segments with special code for export."
1705 (let ((case-fold-search t
)
1707 (goto-char (point-min))
1708 (while (re-search-forward
1709 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1711 (setq lang
(match-string 1) code
(match-string 2)
1712 trans
(org-export-format-source-code lang code
))
1713 (replace-match trans t t
))))
1715 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1717 (defun org-export-format-source-code (lang code
)
1718 "Format CODE from language LANG and return it formatted for export.
1719 Currently, this only does something for HTML export, for all other
1720 backends, it converts the segment into an EXAMPLE segment."
1724 ;; We are exporting to HTML
1725 (condition-case nil
(require 'htmlize
) (nil t
))
1726 (if (not (fboundp 'htmlize-region-for-paste
))
1728 ;; we do not have htmlize.el, or an old version of it
1730 "htmlize.el 1.34 or later is needed for source code formatting")
1731 (concat "#+BEGIN_EXAMPLE\n" code
1732 (if (string-match "\n\\'" code
) "" "\n")
1734 ;; ok, we are good to go
1735 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1736 (org-inhibit-startup t
)
1737 (org-startup-folded nil
)
1741 ;; Free up the protected stuff
1742 (goto-char (point-min))
1743 (while (re-search-forward "^," nil t
)
1746 (if (functionp mode
)
1749 (font-lock-fontify-buffer)
1750 (org-export-htmlize-region-for-paste
1751 (point-min) (point-max)))))
1752 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1753 (setq htmltext
(replace-match "<pre class=\"src\">"
1755 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1757 ;; This is not HTML, so just make it an example.
1758 (concat "#+BEGIN_EXAMPLE\n" code
1759 (if (string-match "\n\\'" code
) "" "\n")
1760 "#+END_EXAMPLE\n")))))
1764 (defvar org-last-level nil
) ; dynamically scoped variable
1765 (defvar org-min-level nil
) ; dynamically scoped variable
1766 (defvar org-levels-open nil
) ; dynamically scoped parameter
1767 (defvar org-ascii-current-indentation nil
) ; For communication
1770 (defun org-export-as-ascii (arg)
1771 "Export the outline as a pretty ASCII file.
1772 If there is an active region, export only the region.
1773 The prefix ARG specifies how many levels of the outline should become
1774 underlined headlines. The default is 3."
1776 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1777 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1778 (org-infile-export-plist)))
1779 (region-p (org-region-active-p))
1780 (rbeg (and region-p
(region-beginning)))
1781 (rend (and region-p
(region-end)))
1786 (and (org-at-heading-p)
1787 (>= (org-end-of-subtree t t
) rend
)))))
1788 (opt-plist (if subtree-p
1789 (org-export-add-subtree-options opt-plist rbeg
)
1791 (custom-times org-display-custom-times
)
1792 (org-ascii-current-indentation '(0 .
0))
1796 (case-fold-search nil
)
1797 (filename (concat (file-name-as-directory
1798 (org-export-directory :ascii opt-plist
))
1799 (file-name-sans-extension
1801 (org-entry-get (region-beginning)
1802 "EXPORT_FILE_NAME" t
))
1803 (file-name-nondirectory buffer-file-name
)))
1805 (filename (if (equal (file-truename filename
)
1806 (file-truename buffer-file-name
))
1807 (concat filename
".txt")
1809 (buffer (find-file-noselect filename
))
1810 (org-levels-open (make-vector org-level-max nil
))
1811 (odd org-odd-levels-only
)
1812 (date (plist-get opt-plist
:date
))
1813 (author (plist-get opt-plist
:author
))
1814 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1815 (plist-get opt-plist
:title
)
1817 (plist-get opt-plist
:skip-before-1st-heading
))
1818 (org-export-grab-title-from-buffer))
1819 (file-name-sans-extension
1820 (file-name-nondirectory buffer-file-name
))))
1821 (email (plist-get opt-plist
:email
))
1822 (language (plist-get opt-plist
:language
))
1823 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1824 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1829 (if (org-region-active-p) (region-beginning) (point-min))
1830 (if (org-region-active-p) (region-end) (point-max))))
1831 (lines (org-split-string
1832 (org-export-preprocess-string
1835 :skip-before-1st-heading
1836 (plist-get opt-plist
:skip-before-1st-heading
)
1837 :drawers
(plist-get opt-plist
:drawers
)
1838 :verbatim-multiline t
1840 (plist-get opt-plist
:archived-trees
)
1841 :add-text
(plist-get opt-plist
:text
))
1843 thetoc have-headings first-heading-pos
1844 table-open table-buffer
)
1846 (let ((inhibit-read-only t
))
1848 (remove-text-properties (point-min) (point-max)
1849 '(:org-license-to-kill t
))))
1851 (setq org-min-level
(org-get-min-level lines
))
1852 (setq org-last-level org-min-level
)
1853 (org-init-section-numbers)
1855 (find-file-noselect filename
)
1857 (setq lang-words
(or (assoc language org-export-language-setup
)
1858 (assoc "en" org-export-language-setup
)))
1859 (switch-to-buffer-other-window buffer
)
1862 ;; create local variables for all options, to make sure all called
1863 ;; functions get the correct information
1865 (set (make-local-variable (cdr x
))
1866 (plist-get opt-plist
(car x
))))
1867 org-export-plist-vars
)
1868 (org-set-local 'org-odd-levels-only odd
)
1869 (setq umax
(if arg
(prefix-numeric-value arg
)
1870 org-export-headline-levels
))
1871 (setq umax-toc
(if (integerp org-export-with-toc
)
1872 (min org-export-with-toc umax
)
1876 (if title
(org-insert-centered title ?
=))
1878 (if (and (or author email
)
1879 org-export-author-info
)
1880 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1881 (if email
(concat " <" email
">") "")
1885 ((and date
(string-match "%" date
))
1886 (setq date
(format-time-string date
)))
1888 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1890 (if (and date org-export-time-stamp-file
)
1891 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1895 (if org-export-with-toc
1897 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1898 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1899 (mapc '(lambda (line)
1900 (if (string-match org-todo-line-regexp
1902 ;; This is a headline
1904 (setq have-headings t
)
1905 (setq level
(- (match-end 1) (match-beginning 1))
1906 level
(org-tr-level level
)
1907 txt
(match-string 3 line
)
1909 (or (and org-export-mark-todo-in-toc
1911 (not (member (match-string 2 line
)
1912 org-done-keywords
)))
1914 (and org-export-mark-todo-in-toc
1916 (org-search-todo-below
1917 line lines level
))))
1918 (setq txt
(org-html-expand-for-ascii txt
))
1920 (while (string-match org-bracket-link-regexp txt
)
1923 (match-string (if (match-end 2) 3 1) txt
)
1926 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1928 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1930 (setq txt
(replace-match "" t t txt
)))
1931 (if (string-match quote-re0 txt
)
1932 (setq txt
(replace-match "" t t txt
)))
1934 (if org-export-with-section-numbers
1935 (setq txt
(concat (org-section-number level
)
1937 (if (<= level umax-toc
)
1942 (* (max 0 (- level org-min-level
)) 4) ?\
)
1943 (format (if todo
"%s (*)\n" "%s\n") txt
))
1945 (setq org-last-level level
))
1948 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1950 (org-init-section-numbers)
1951 (while (setq line
(pop lines
))
1952 ;; Remove the quoted HTML tags.
1953 (setq line
(org-html-expand-for-ascii line
))
1955 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1956 (setq line
(replace-match "" t t line
)))
1957 ;; Replace internal links
1958 (while (string-match org-bracket-link-regexp line
)
1959 (setq line
(replace-match
1960 (if (match-end 3) "[\\3]" "[\\1]")
1963 (setq line
(org-translate-time line
)))
1965 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1967 (setq first-heading-pos
(or first-heading-pos
(point)))
1968 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1969 txt
(match-string 2 line
))
1970 (org-ascii-level-start level txt umax lines
))
1972 ((and org-export-with-tables
1973 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1974 (if (not table-open
)
1976 (setq table-open t table-buffer nil
))
1978 (setq table-buffer
(cons line table-buffer
))
1979 (when (or (not lines
)
1980 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1982 (setq table-open nil
1983 table-buffer
(nreverse table-buffer
))
1986 (org-fix-indentation x org-ascii-current-indentation
))
1987 (org-format-table-ascii table-buffer
)
1990 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1991 (if (and org-export-with-fixed-width
1992 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1993 (setq line
(replace-match "\\1" nil nil line
)))
1994 (insert line
"\n"))))
1998 ;; insert the table of contents
2000 (goto-char (point-min))
2001 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2003 (goto-char (match-beginning 0))
2005 (goto-char first-heading-pos
))
2006 (mapc 'insert thetoc
)
2007 (or (looking-at "[ \t]*\n[ \t]*\n")
2010 ;; Convert whitespace place holders
2011 (goto-char (point-min))
2013 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2014 (setq end
(next-single-property-change beg
'org-whitespace
))
2016 (delete-region beg end
)
2017 (insert (make-string (- end beg
) ?\
))))
2020 ;; remove display and invisible chars
2022 (goto-char (point-min))
2023 (while (setq beg
(next-single-property-change (point) 'display
))
2024 (setq end
(next-single-property-change beg
'display
))
2025 (delete-region beg end
)
2028 (goto-char (point-min))
2029 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2030 (setq end
(next-single-property-change beg
'org-cwidth
))
2031 (delete-region beg end
)
2033 (goto-char (point-min))))
2035 (defun org-export-ascii-clean-string ()
2036 "Do extra work for ASCII export"
2037 (goto-char (point-min))
2038 (while (re-search-forward org-verbatim-re nil t
)
2039 (goto-char (match-end 2))
2040 (backward-delete-char 1) (insert "'")
2041 (goto-char (match-beginning 2))
2042 (delete-char 1) (insert "`")
2043 (goto-char (match-end 2))))
2045 (defun org-search-todo-below (line lines level
)
2046 "Search the subtree below LINE for any TODO entries."
2047 (let ((rest (cdr (memq line lines
)))
2048 (re org-todo-line-regexp
)
2051 (while (setq line
(pop rest
))
2052 (if (string-match re line
)
2054 (setq lv
(- (match-end 1) (match-beginning 1))
2055 todo
(and (match-beginning 2)
2056 (not (member (match-string 2 line
)
2057 org-done-keywords
))))
2059 (if (<= lv level
) (throw 'exit nil
))
2060 (if todo
(throw 'exit t
))))))))
2062 (defun org-html-expand-for-ascii (line)
2063 "Handle quoted HTML for ASCII export."
2064 (if org-export-html-expand
2065 (while (string-match "@<[^<>\n]*>" line
)
2066 ;; We just remove the tags for now.
2067 (setq line
(replace-match "" nil nil line
))))
2070 (defun org-insert-centered (s &optional underline
)
2071 "Insert the string S centered and underline it with character UNDERLINE."
2072 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
2073 (insert (make-string ind ?\
) s
"\n")
2075 (insert (make-string ind ?\
)
2076 (make-string (string-width s
) underline
)
2079 (defun org-ascii-level-start (level title umax
&optional lines
)
2080 "Insert a new level in ASCII export."
2081 (let (char (n (- level umax
1)) (ind 0))
2084 (insert (make-string (* 2 n
) ?\
)
2085 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2086 org-export-ascii-bullets
))
2088 ;; find the indentation of the next non-empty line
2091 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2092 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2093 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2095 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2096 (if (or (not (equal (char-before) ?
\n))
2097 (not (equal (char-before (1- (point))) ?
\n)))
2099 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2100 (unless org-export-with-tags
2101 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2102 (setq title
(replace-match "" t t title
))))
2103 (if org-export-with-section-numbers
2104 (setq title
(concat (org-section-number level
) " " title
)))
2105 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2106 (setq org-ascii-current-indentation
'(0 .
0)))))
2109 (defun org-export-visible (type arg
)
2110 "Create a copy of the visible part of the current buffer, and export it.
2111 The copy is created in a temporary buffer and removed after use.
2112 TYPE is the final key (as a string) that also select the export command in
2113 the `C-c C-e' export dispatcher.
2114 As a special case, if the you type SPC at the prompt, the temporary
2115 org-mode file will not be removed but presented to you so that you can
2116 continue to use it. The prefix arg ARG is passed through to the exporting
2120 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2121 (read-char-exclusive))
2122 current-prefix-arg
))
2123 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2124 (error "Invalid export key"))
2125 (let* ((binding (cdr (assoc type
2126 '((?a . org-export-as-ascii
)
2127 (?\C-a . org-export-as-ascii
)
2128 (?b . org-export-as-html-and-open
)
2129 (?\C-b . org-export-as-html-and-open
)
2130 (?h . org-export-as-html
)
2131 (?H . org-export-as-html-to-buffer
)
2132 (?R . org-export-region-as-html
)
2133 (?x . org-export-as-xoxo
)))))
2134 (keepp (equal type ?\
))
2135 (file buffer-file-name
)
2136 (buffer (get-buffer-create "*Org Export Visible*"))
2138 ;; Need to hack the drawers here.
2140 (goto-char (point-min))
2141 (while (re-search-forward org-drawer-regexp nil t
)
2142 (goto-char (match-beginning 1))
2143 (or (org-invisible-p) (org-flag-drawer nil
))))
2144 (with-current-buffer buffer
(erase-buffer))
2146 (setq s
(goto-char (point-min)))
2147 (while (not (= (point) (point-max)))
2148 (goto-char (org-find-invisible))
2149 (append-to-buffer buffer s
(point))
2150 (setq s
(goto-char (org-find-visible))))
2151 (org-cycle-hide-drawers 'all
)
2152 (goto-char (point-min))
2154 ;; Copy all comment lines to the end, to make sure #+ settings are
2155 ;; still available for the second export step. Kind of a hack, but
2156 ;; does do the trick.
2157 (if (looking-at "#[^\r\n]*")
2158 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2159 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2160 (append-to-buffer buffer
(1+ (match-beginning 0))
2161 (min (point-max) (1+ (match-end 0))))))
2163 (let ((buffer-file-name file
)
2164 (org-inhibit-startup t
))
2167 (unless keepp
(funcall binding arg
))))
2169 (kill-buffer buffer
)
2170 (switch-to-buffer-other-window buffer
)
2171 (goto-char (point-min)))))
2173 (defun org-find-visible ()
2175 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2176 (get-char-property s
'invisible
)))
2178 (defun org-find-invisible ()
2180 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2181 (not (get-char-property s
'invisible
))))
2186 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2187 (defun org-get-current-options ()
2188 "Return a string with current options as keyword options.
2189 Does include HTML export options as well as TODO and CATEGORY stuff."
2190 (require 'org-archive
)
2197 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2198 #+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
2205 #+PRIORITIES: %c %c %c
2207 #+STARTUP: %s %s %s %s %s
2212 (buffer-name) (user-full-name) user-mail-address
2213 (format-time-string (car org-time-stamp-formats
))
2214 org-export-default-language
2215 org-export-headline-levels
2216 org-export-with-section-numbers
2218 org-export-preserve-breaks
2219 org-export-html-expand
2220 org-export-with-fixed-width
2221 org-export-with-tables
2222 org-export-with-sub-superscripts
2223 org-export-with-special-strings
2224 org-export-with-footnotes
2225 org-export-with-emphasize
2226 org-export-with-TeX-macros
2227 org-export-with-LaTeX-fragments
2228 org-export-skip-text-before-1st-heading
2229 org-export-with-drawers
2230 org-export-with-tags
2231 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2232 org-export-html-link-up
2233 org-export-html-link-home
2234 (file-name-nondirectory buffer-file-name
)
2235 "TODO FEEDBACK VERIFY DONE"
2236 "Me Jason Marie DONE"
2237 org-highest-priority org-lowest-priority org-default-priority
2238 (mapconcat 'identity org-drawers
" ")
2239 (cdr (assoc org-startup-folded
2240 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2241 (if org-odd-levels-only
"odd" "oddeven")
2242 (if org-hide-leading-stars
"hidestars" "showstars")
2243 (if org-startup-align-all-tables
"align" "noalign")
2244 (cond ((eq org-log-done t
) "logdone")
2245 ((equal org-log-done
'note
) "lognotedone")
2246 ((not org-log-done
) "nologdone"))
2247 (or (mapconcat (lambda (x)
2249 ((equal '(:startgroup
) x
) "{")
2250 ((equal '(:endgroup
) x
) "}")
2251 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2253 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2254 org-archive-location
2255 "org file:~/org/%s.org"
2259 (defun org-insert-export-options-template ()
2260 "Insert into the buffer a template with information for exporting."
2262 (if (not (bolp)) (newline))
2263 (let ((s (org-get-current-options)))
2264 (and (string-match "#\\+CATEGORY" s
)
2265 (setq s
(substring s
0 (match-beginning 0))))
2269 (defun org-export-as-html-and-open (arg)
2270 "Export the outline as HTML and immediately open it with a browser.
2271 If there is an active region, export only the region.
2272 The prefix ARG specifies how many levels of the outline should become
2273 headlines. The default is 3. Lower levels will become bulleted lists."
2275 (org-export-as-html arg
'hidden
)
2276 (org-open-file buffer-file-name
))
2279 (defun org-export-as-html-batch ()
2280 "Call `org-export-as-html', may be used in batch processing as
2282 --load=$HOME/lib/emacs/org.el
2283 --eval \"(setq org-export-headline-levels 2)\"
2284 --visit=MyFile --funcall org-export-as-html-batch"
2285 (org-export-as-html org-export-headline-levels
'hidden
))
2288 (defun org-export-as-html-to-buffer (arg)
2289 "Call `org-exort-as-html` with output to a temporary buffer.
2290 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2292 (org-export-as-html arg nil nil
"*Org HTML Export*")
2293 (switch-to-buffer-other-window "*Org HTML Export*"))
2296 (defun org-replace-region-by-html (beg end
)
2297 "Assume the current region has org-mode syntax, and convert it to HTML.
2298 This can be used in any buffer. For example, you could write an
2299 itemized list in org-mode syntax in an HTML buffer and then use this
2300 command to convert it."
2302 (let (reg html buf pop-up-frames
)
2303 (save-window-excursion
2305 (setq html
(org-export-region-as-html
2307 (setq reg
(buffer-substring beg end
)
2308 buf
(get-buffer-create "*Org tmp*"))
2309 (with-current-buffer buf
2313 (setq html
(org-export-region-as-html
2314 (point-min) (point-max) t
'string
)))
2316 (delete-region beg end
)
2320 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2321 "Convert region from BEG to END in org-mode buffer to HTML.
2322 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2323 contents, and only produce the region of converted text, useful for
2324 cut-and-paste operations.
2325 If BUFFER is a buffer or a string, use/create that buffer as a target
2326 of the converted HTML. If BUFFER is the symbol `string', return the
2327 produced HTML as a string and leave not buffer behind. For example,
2328 a Lisp program could call this function in the following way:
2330 (setq html (org-export-region-as-html beg end t 'string))
2332 When called interactively, the output buffer is selected, and shown
2333 in a window. A non-interactive call will only return the buffer."
2334 (interactive "r\nP")
2335 (when (interactive-p)
2336 (setq buffer
"*Org HTML Export*"))
2337 (let ((transient-mark-mode t
) (zmacs-regions t
)
2340 (set-mark (point)) ;; to activate the region
2342 (setq rtn
(org-export-as-html
2345 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2346 (if (and (interactive-p) (bufferp rtn
))
2347 (switch-to-buffer-other-window rtn
)
2350 (defvar html-table-tag nil
) ; dynamically scoped into this.
2352 (defun org-export-as-html (arg &optional hidden ext-plist
2353 to-buffer body-only pub-dir
)
2354 "Export the outline as a pretty HTML file.
2355 If there is an active region, export only the region. The prefix
2356 ARG specifies how many levels of the outline should become
2357 headlines. The default is 3. Lower levels will become bulleted
2358 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2359 EXT-PLIST is a property list with external parameters overriding
2360 org-mode's default settings, but still inferior to file-local
2361 settings. When TO-BUFFER is non-nil, create a buffer with that
2362 name and export to that buffer. If TO-BUFFER is the symbol
2363 `string', don't leave any buffer behind but just return the
2364 resulting HTML as a string. When BODY-ONLY is set, don't produce
2365 the file header and footer, simply return the content of
2366 <body>...</body>, without even the body tags themselves. When
2367 PUB-DIR is set, use this as the publishing directory."
2370 ;; Make sure we have a file name when we need it.
2371 (when (and (not (or to-buffer body-only
))
2372 (not buffer-file-name
))
2373 (if (buffer-base-buffer)
2374 (org-set-local 'buffer-file-name
2375 (with-current-buffer (buffer-base-buffer)
2377 (error "Need a file name to be able to export.")))
2379 (message "Exporting...")
2380 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2381 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2382 (setq-default org-done-keywords org-done-keywords
)
2383 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2385 (org-export-process-option-filters
2386 (org-combine-plists (org-default-export-plist)
2388 (org-infile-export-plist))))
2390 (style (plist-get opt-plist
:style
))
2391 (html-extension (plist-get opt-plist
:html-extension
))
2392 (link-validate (plist-get opt-plist
:link-validation-function
))
2393 valid thetoc have-headings first-heading-pos
2394 (odd org-odd-levels-only
)
2395 (region-p (org-region-active-p))
2396 (rbeg (and region-p
(region-beginning)))
2397 (rend (and region-p
(region-end)))
2402 (and (org-at-heading-p)
2403 (>= (org-end-of-subtree t t
) rend
)))))
2404 (opt-plist (if subtree-p
2405 (org-export-add-subtree-options opt-plist rbeg
)
2407 ;; The following two are dynamically scoped into other
2409 (org-current-export-dir
2410 (or pub-dir
(org-export-directory :html opt-plist
)))
2411 (org-current-export-file buffer-file-name
)
2412 (level 0) (line "") (origline "") txt todo
2415 (filename (if to-buffer nil
2418 (file-name-sans-extension
2420 (org-entry-get (region-beginning)
2421 "EXPORT_FILE_NAME" t
))
2422 (file-name-nondirectory buffer-file-name
)))
2424 (file-name-as-directory
2425 (or pub-dir
(org-export-directory :html opt-plist
))))))
2426 (current-dir (if buffer-file-name
2427 (file-name-directory buffer-file-name
)
2429 (buffer (if to-buffer
2431 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2432 (t (get-buffer-create to-buffer
)))
2433 (find-file-noselect filename
)))
2434 (org-levels-open (make-vector org-level-max nil
))
2435 (date (plist-get opt-plist
:date
))
2436 (author (plist-get opt-plist
:author
))
2437 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2438 (plist-get opt-plist
:title
)
2440 (plist-get opt-plist
:skip-before-1st-heading
))
2441 (org-export-grab-title-from-buffer))
2442 (and buffer-file-name
2443 (file-name-sans-extension
2444 (file-name-nondirectory buffer-file-name
)))
2446 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2447 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2448 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2452 (local-list-type nil
)
2453 (local-list-indent nil
)
2454 (llt org-plain-list-ordered-item-terminator
)
2455 (email (plist-get opt-plist
:email
))
2456 (language (plist-get opt-plist
:language
))
2460 (coding-system (and (boundp 'buffer-file-coding-system
)
2461 buffer-file-coding-system
))
2462 (coding-system-for-write (or org-export-html-coding-system
2464 (save-buffer-coding-system (or org-export-html-coding-system
2466 (charset (and coding-system-for-write
2467 (fboundp 'coding-system-get
)
2468 (coding-system-get coding-system-for-write
2472 (if region-p
(region-beginning) (point-min))
2473 (if region-p
(region-end) (point-max))))
2476 (org-export-preprocess-string
2480 :skip-before-1st-heading
2481 (plist-get opt-plist
:skip-before-1st-heading
)
2482 :drawers
(plist-get opt-plist
:drawers
)
2484 (plist-get opt-plist
:archived-trees
)
2486 (plist-get opt-plist
:text
)
2488 (plist-get opt-plist
:LaTeX-fragments
))
2491 table-buffer table-orig-buffer
2492 ind item-type starter didclose
2493 rpl path desc descp desc1 desc2 link
2494 snumber fnc item-tag
2497 (let ((inhibit-read-only t
))
2499 (remove-text-properties (point-min) (point-max)
2500 '(:org-license-to-kill t
))))
2502 (message "Exporting...")
2504 (setq org-min-level
(org-get-min-level lines
))
2505 (setq org-last-level org-min-level
)
2506 (org-init-section-numbers)
2509 ((and date
(string-match "%" date
))
2510 (setq date
(format-time-string date
)))
2512 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2514 ;; Get the language-dependent settings
2515 (setq lang-words
(or (assoc language org-export-language-setup
)
2516 (assoc "en" org-export-language-setup
)))
2518 ;; Switch to the output buffer
2520 (let ((inhibit-read-only t
)) (erase-buffer))
2523 (and (fboundp 'set-buffer-file-coding-system
)
2524 (set-buffer-file-coding-system coding-system-for-write
))
2526 (let ((case-fold-search nil
)
2527 (org-odd-levels-only odd
))
2528 ;; create local variables for all options, to make sure all called
2529 ;; functions get the correct information
2531 (set (make-local-variable (cdr x
))
2532 (plist-get opt-plist
(car x
))))
2533 org-export-plist-vars
)
2534 (setq umax
(if arg
(prefix-numeric-value arg
)
2535 org-export-headline-levels
))
2536 (setq umax-toc
(if (integerp org-export-with-toc
)
2537 (min org-export-with-toc umax
)
2542 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2543 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2544 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2545 lang=\"%s\" xml:lang=\"%s\">
2548 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2549 <meta name=\"generator\" content=\"Org-mode\"/>
2550 <meta name=\"generated\" content=\"%s\"/>
2551 <meta name=\"author\" content=\"%s\"/>
2555 language language
(org-html-expand title
)
2556 (or charset
"iso-8859-1") date author style
))
2558 (insert (or (plist-get opt-plist
:preamble
) ""))
2560 (when (plist-get opt-plist
:auto-preamble
)
2561 (if title
(insert (format org-export-html-title-format
2562 (org-html-expand title
))))))
2564 (if (and org-export-with-toc
(not body-only
))
2566 (push (format "<h%d>%s</h%d>\n"
2567 org-export-html-toplevel-hlevel
2569 org-export-html-toplevel-hlevel
)
2571 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2572 (push "<ul>\n<li>" thetoc
)
2574 (mapcar '(lambda (line)
2575 (if (string-match org-todo-line-regexp line
)
2576 ;; This is a headline
2578 (setq have-headings t
)
2579 (setq level
(- (match-end 1) (match-beginning 1))
2580 level
(org-tr-level level
)
2581 txt
(save-match-data
2583 (org-export-cleanup-toc-line
2584 (match-string 3 line
))))
2586 (or (and org-export-mark-todo-in-toc
2588 (not (member (match-string 2 line
)
2589 org-done-keywords
)))
2591 (and org-export-mark-todo-in-toc
2593 (org-search-todo-below
2594 line lines level
))))
2596 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2597 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2598 (if (string-match quote-re0 txt
)
2599 (setq txt
(replace-match "" t t txt
)))
2600 (setq snumber
(org-section-number level
))
2601 (if org-export-with-section-numbers
2602 (setq txt
(concat snumber
" " txt
)))
2603 (if (<= level
(max umax umax-toc
))
2604 (setq head-count
(+ head-count
1)))
2605 (if (<= level umax-toc
)
2607 (if (> level org-last-level
)
2609 (setq cnt
(- level org-last-level
))
2610 (while (>= (setq cnt
(1- cnt
)) 0)
2611 (push "\n<ul>\n<li>" thetoc
))
2612 (push "\n" thetoc
)))
2613 (if (< level org-last-level
)
2615 (setq cnt
(- org-last-level level
))
2616 (while (>= (setq cnt
(1- cnt
)) 0)
2617 (push "</li>\n</ul>" thetoc
))
2618 (push "\n" thetoc
)))
2619 ;; Check for targets
2620 (while (string-match org-any-target-regexp line
)
2621 (setq line
(replace-match
2622 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2624 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2625 (setq txt
(replace-match "" t t txt
)))
2629 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2630 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2631 snumber txt
) thetoc
)
2633 (setq org-last-level level
))
2637 (while (> org-last-level
(1- org-min-level
))
2638 (setq org-last-level
(1- org-last-level
))
2639 (push "</li>\n</ul>\n" thetoc
))
2640 (push "</div>\n" thetoc
)
2641 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2644 (org-init-section-numbers)
2646 (while (setq line
(pop lines
) origline line
)
2649 ;; end of quote section?
2650 (when (and inquote
(string-match "^\\*+ " line
))
2653 ;; inside a quote section?
2655 (insert (org-html-protect line
) "\n")
2656 (throw 'nextline nil
))
2659 (when (and org-export-with-fixed-width
2660 (string-match "^[ \t]*:\\(.*\\)" line
))
2664 (insert (org-html-protect (match-string 1 line
)) "\n")
2666 (not (string-match "^[ \t]*\\(:.*\\)"
2669 (insert "</pre>\n"))
2670 (throw 'nextline nil
))
2673 (when (get-text-property 0 'org-protected line
)
2675 (when (re-search-backward
2676 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2677 (setq par
(match-string 1))
2678 (replace-match "\\2\n"))
2681 (not (string-match "^[ \t]*:" (car lines
)))
2682 (or (= (length (car lines
)) 0)
2683 (get-text-property 0 'org-protected
(car lines
))))
2684 (insert (pop lines
) "\n"))
2685 (and par
(insert "<p>\n")))
2686 (throw 'nextline nil
))
2689 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2690 (insert "\n<hr/>\n")
2691 (throw 'nextline nil
))
2693 ;; Blockquotes and verse
2694 (when (equal "ORG-BLOCKQUOTE-START" line
)
2695 (insert "<blockquote>\n<p>\n")
2696 (throw 'nextline nil
))
2697 (when (equal "ORG-BLOCKQUOTE-END" line
)
2698 (insert "</p>\n</blockquote>\n")
2699 (throw 'nextline nil
))
2700 (when (equal "ORG-VERSE-START" line
)
2701 (insert "<verse>\n<p>\n")
2702 (throw 'nextline nil
))
2703 (when (equal "ORG-VERSE-END" line
)
2704 (insert "</p>\n</verse>\n")
2705 (throw 'nextline nil
))
2707 ;; make targets to anchors
2708 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2711 (setq line
(replace-match
2712 (concat "@<a name=\""
2713 (org-solidify-link-text (match-string 1 line
))
2716 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2717 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2718 (setq line
(replace-match
2719 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2720 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2723 (setq line
(replace-match
2724 (concat "@<a name=\""
2725 (org-solidify-link-text (match-string 1 line
))
2726 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2729 (setq line
(org-html-handle-time-stamps line
))
2731 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2732 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2733 ;; Also handle sub_superscripts and checkboxes
2734 (or (string-match org-table-hline-regexp line
)
2735 (setq line
(org-html-expand line
)))
2739 (while (string-match org-bracket-link-analytic-regexp line start
)
2740 (setq start
(match-beginning 0))
2741 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2742 (setq path
(match-string 3 line
))
2743 (setq desc1
(if (match-end 5) (match-string 5 line
))
2744 desc2
(if (match-end 2) (concat type
":" path
) path
)
2745 descp
(and desc1
(not (equal desc1 desc2
)))
2746 desc
(or desc1 desc2
))
2747 ;; Make an image out of the description if that is so wanted
2748 (when (and descp
(org-file-image-p desc
))
2750 (if (string-match "^file:" desc
)
2751 (setq desc
(substring desc
(match-end 0)))))
2752 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2753 ;; FIXME: do we need to unescape here somewhere?
2755 ((equal type
"internal")
2759 (org-solidify-link-text
2760 (save-match-data (org-link-unescape path
)) nil
)
2761 "\">" desc
"</a>")))
2762 ((member type
'("http" "https"))
2763 ;; standard URL, just check if we need to inline an image
2764 (if (and (or (eq t org-export-html-inline-images
)
2765 (and org-export-html-inline-images
(not descp
)))
2766 (org-file-image-p path
))
2767 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2768 (setq link
(concat type
":" path
))
2769 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2770 ((member type
'("ftp" "mailto" "news"))
2772 (setq link
(concat type
":" path
))
2773 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2774 ((string= type
"file")
2776 (let* ((filename path
)
2777 (abs-p (file-name-absolute-p filename
))
2778 thefile file-is-image-p search
)
2780 (if (string-match "::\\(.*\\)" filename
)
2781 (setq search
(match-string 1 filename
)
2782 filename
(replace-match "" t nil filename
)))
2784 (if (functionp link-validate
)
2785 (funcall link-validate filename current-dir
)
2787 (setq file-is-image-p
(org-file-image-p filename
))
2788 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2789 (when (and org-export-html-link-org-files-as-html
2790 (string-match "\\.org$" thefile
))
2791 (setq thefile
(concat (substring thefile
0
2792 (match-beginning 0))
2793 "." html-extension
))
2795 ;; make sure this is can be used as target search
2796 (not (string-match "^[0-9]*$" search
))
2797 (not (string-match "^\\*" search
))
2798 (not (string-match "^/.*/$" search
)))
2799 (setq thefile
(concat thefile
"#"
2800 (org-solidify-link-text
2801 (org-link-unescape search
)))))
2802 (when (string-match "^file:" desc
)
2803 (setq desc
(replace-match "" t t desc
))
2804 (if (string-match "\\.org$" desc
)
2805 (setq desc
(replace-match "" t t desc
))))))
2806 (setq rpl
(if (and file-is-image-p
2807 (or (eq t org-export-html-inline-images
)
2808 (and org-export-html-inline-images
2810 (concat "<img src=\"" thefile
"\"/>")
2811 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2812 (if (not valid
) (setq rpl desc
))))
2814 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2817 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2820 ;; just publish the path, as default
2821 (setq rpl
(concat "<i><" type
":"
2822 (save-match-data (org-link-unescape path
))
2824 (setq line
(replace-match rpl t t line
)
2825 start
(+ start
(length rpl
))))
2828 (if (and (string-match org-todo-line-regexp line
)
2829 (match-beginning 2))
2832 (concat (substring line
0 (match-beginning 2))
2834 (if (member (match-string 2 line
)
2837 "\">" (match-string 2 line
)
2838 "</span>" (substring line
(match-end 2)))))
2840 ;; Does this contain a reference to a footnote?
2841 (when org-export-with-footnotes
2843 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2844 (if (get-text-property (match-beginning 2) 'org-protected line
)
2845 (setq start
(match-end 2))
2846 (let ((n (match-string 2 line
)))
2850 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2851 (match-string 1 line
) n n n
)
2855 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2856 ;; This is a headline
2857 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2858 txt
(match-string 2 line
))
2859 (if (string-match quote-re0 txt
)
2860 (setq txt
(replace-match "" t t txt
)))
2861 (if (<= level
(max umax umax-toc
))
2862 (setq head-count
(+ head-count
1)))
2864 ;; Close any local lists before inserting a new header line
2865 (while local-list-type
2866 (org-close-li (car local-list-type
))
2867 (insert (format "</%sl>\n" (car local-list-type
)))
2868 (pop local-list-type
))
2869 (setq local-list-indent nil
2871 (setq first-heading-pos
(or first-heading-pos
(point)))
2872 (org-html-level-start level txt umax
2873 (and org-export-with-toc
(<= level umax
))
2876 (when (string-match quote-re line
)
2880 ((and org-export-with-tables
2881 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2882 (if (not table-open
)
2884 (setq table-open t table-buffer nil table-orig-buffer nil
))
2886 (setq table-buffer
(cons line table-buffer
)
2887 table-orig-buffer
(cons origline table-orig-buffer
))
2888 (when (or (not lines
)
2889 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2891 (setq table-open nil
2892 table-buffer
(nreverse table-buffer
)
2893 table-orig-buffer
(nreverse table-orig-buffer
))
2894 (org-close-par-maybe)
2895 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2900 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2901 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2902 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2903 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2905 (setq ind
(org-get-string-indentation line
)
2906 item-type
(if (match-beginning 4) "o" "u")
2907 starter
(if (match-beginning 2)
2908 (substring (match-string 2 line
) 0 -
1))
2909 line
(substring line
(match-beginning 5))
2911 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
2913 item-tag
(match-string 1 line
)
2914 line
(substring line
(match-end 0))))
2915 (when (and (not (equal item-type
"d"))
2916 (not (string-match "[^ \t]" line
)))
2917 ;; empty line. Pretend indentation is large.
2918 (setq ind
(if org-empty-line-terminates-plain-lists
2920 (1+ (or (car local-list-indent
) 1)))))
2922 (while (and in-local-list
2923 (or (and (= ind
(car local-list-indent
))
2925 (< ind
(car local-list-indent
))))
2927 (org-close-li (car local-list-type
))
2928 (insert (format "</%sl>\n" (car local-list-type
)))
2929 (pop local-list-type
) (pop local-list-indent
)
2930 (setq in-local-list local-list-indent
))
2933 (or (not in-local-list
)
2934 (> ind
(car local-list-indent
))))
2935 ;; Start new (level of) list
2936 (org-close-par-maybe)
2938 ((equal item-type
"u") "<ul>\n<li>\n")
2939 ((equal item-type
"o") "<ol>\n<li>\n")
2940 ((equal item-type
"d")
2941 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
2942 (push item-type local-list-type
)
2943 (push ind local-list-indent
)
2944 (setq in-local-list t
))
2946 ;; continue current list
2947 (org-close-li (car local-list-type
))
2949 ((equal (car local-list-type
) "d")
2950 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
2953 ;; we did close a list, normal text follows: need <p>
2955 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2958 (if (equal (match-string 1 line
) "X")
2960 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2963 ;; Empty lines start a new paragraph. If hand-formatted lists
2964 ;; are not fully interpreted, lines starting with "-", "+", "*"
2965 ;; also start a new paragraph.
2966 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2968 ;; Is this the start of a footnote?
2969 (when org-export-with-footnotes
2970 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2971 (org-close-par-maybe)
2972 (let ((n (match-string 1 line
)))
2973 (setq line
(replace-match
2974 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
))
2975 (setq line
(concat line
"</p>")))))
2977 ;; Check if the line break needs to be conserved
2979 ((string-match "\\\\\\\\[ \t]*$" line
)
2980 (setq line
(replace-match "<br/>" t t line
)))
2981 (org-export-preserve-breaks
2982 (setq line
(concat line
"<br/>"))))
2984 (insert line
"\n")))))
2986 ;; Properly close all local lists and other lists
2987 (when inquote
(insert "</pre>\n"))
2989 ;; Close any local lists before inserting a new header line
2990 (while local-list-type
2991 (org-close-li (car local-list-type
))
2992 (insert (format "</%sl>\n" (car local-list-type
)))
2993 (pop local-list-type
))
2994 (setq local-list-indent nil
2996 (org-html-level-start 1 nil umax
2997 (and org-export-with-toc
(<= level umax
))
2999 ;; the </div> to lose the last text-... div.
3003 (when (plist-get opt-plist
:auto-postamble
)
3004 (insert "<div id=\"postamble\">")
3005 (when (and org-export-author-info author
)
3006 (insert "<p class=\"author\"> "
3007 (nth 1 lang-words
) ": " author
"\n")
3009 (if (listp (split-string email
",+ *"))
3011 (insert "<a href=\"mailto:" e
"\"><"
3013 (split-string email
",+ *"))
3014 (insert "<a href=\"mailto:" email
"\"><"
3015 email
"></a>\n")))
3017 (when (and date org-export-time-stamp-file
)
3018 (insert "<p class=\"date\"> "
3019 (nth 2 lang-words
) ": "
3023 (if org-export-html-with-timestamp
3024 (insert org-export-html-html-helper-timestamp
))
3025 (insert (or (plist-get opt-plist
:postamble
) ""))
3026 (insert "</body>\n</html>\n"))
3029 (if (eq major-mode default-major-mode
) (html-mode))
3031 ;; insert the table of contents
3032 (goto-char (point-min))
3034 (if (or (re-search-forward
3035 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3037 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3039 (goto-char (match-beginning 0))
3041 (goto-char first-heading-pos
)
3042 (when (looking-at "\\s-*</p>")
3043 (goto-char (match-end 0))
3045 (insert "<div id=\"table-of-contents\">\n")
3046 (mapc 'insert thetoc
)
3047 (insert "</div>\n"))
3048 ;; remove empty paragraphs and lists
3049 (goto-char (point-min))
3050 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3052 (goto-char (point-min))
3053 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3055 (goto-char (point-min))
3056 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3058 ;; Convert whitespace place holders
3059 (goto-char (point-min))
3061 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3062 (setq n
(get-text-property beg
'org-whitespace
)
3063 end
(next-single-property-change beg
'org-whitespace
))
3065 (delete-region beg end
)
3066 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3067 (make-string n ?x
)))))
3068 (or to-buffer
(save-buffer))
3069 (goto-char (point-min))
3070 (message "Exporting... done")
3071 (if (eq to-buffer
'string
)
3072 (prog1 (buffer-substring (point-min) (point-max))
3073 (kill-buffer (current-buffer)))
3074 (current-buffer)))))
3076 (defvar org-table-colgroup-info nil
)
3077 (defun org-format-table-ascii (lines)
3078 "Format a table for ascii export."
3080 (setq lines
(org-split-string lines
"\n")))
3081 (if (not (string-match "^[ \t]*|" (car lines
)))
3082 ;; Table made by table.el - test for spanning
3085 ;; A normal org table
3086 ;; Get rid of hlines at beginning and end
3087 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3088 (setq lines
(nreverse lines
))
3089 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3090 (setq lines
(nreverse lines
))
3091 (when org-export-table-remove-special-lines
3092 ;; Check if the table has a marking column. If yes remove the
3093 ;; column and the special lines
3094 (setq lines
(org-table-clean-before-export lines
)))
3095 ;; Get rid of the vertical lines except for grouping
3096 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3098 (while (setq line
(pop lines
))
3099 (if (string-match org-table-hline-regexp line
)
3100 (and (string-match "|\\(.*\\)|" line
)
3101 (setq line
(replace-match " \\1" t nil line
)))
3102 (setq start
0 vl1 vl
)
3103 (while (string-match "|" line start
)
3104 (setq start
(match-end 0))
3105 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3109 (defun org-colgroup-info-to-vline-list (info)
3112 (setq last new new
(pop info
))
3113 (if (or (memq last
'(:end
:startend
))
3114 (memq new
'(:start
:startend
)))
3117 (setq vl
(nreverse vl
))
3118 (and vl
(setcar vl nil
))
3121 (defvar org-table-number-regexp
) ; defined in org-table.el
3122 (defun org-format-table-html (lines olines
)
3123 "Find out which HTML converter to use and return the HTML code."
3125 (setq lines
(org-split-string lines
"\n")))
3126 (if (string-match "^[ \t]*|" (car lines
))
3127 ;; A normal org table
3128 (org-format-org-table-html lines
)
3129 ;; Table made by table.el - test for spanning
3130 (let* ((hlines (delq nil
(mapcar
3132 (if (string-match "^[ \t]*\\+-" x
) x
3135 (first (car hlines
))
3136 (ll (and (string-match "\\S-+" first
)
3137 (match-string 0 first
)))
3138 (re (concat "^[ \t]*" (regexp-quote ll
)))
3139 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3141 (if (and (not spanning
)
3142 (not org-export-prefer-native-exporter-for-tables
))
3143 ;; We can use my own converter with HTML conversions
3144 (org-format-table-table-html lines
)
3145 ;; Need to use the code generator in table.el, with the original text.
3146 (org-format-table-table-html-using-table-generate-source olines
)))))
3148 (defvar org-table-number-fraction
) ; defined in org-table.el
3149 (defun org-format-org-table-html (lines &optional splice
)
3150 "Format a table into HTML."
3151 (require 'org-table
)
3152 ;; Get rid of hlines at beginning and end
3153 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3154 (setq lines
(nreverse lines
))
3155 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3156 (setq lines
(nreverse lines
))
3157 (when org-export-table-remove-special-lines
3158 ;; Check if the table has a marking column. If yes remove the
3159 ;; column and the special lines
3160 (setq lines
(org-table-clean-before-export lines
)))
3162 (let ((head (and org-export-highlight-first-table-line
3164 (lambda (x) (string-match "^[ \t]*|-" x
))
3167 tbopen line fields html gr colgropen
)
3168 (if splice
(setq head nil
))
3169 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3171 (while (setq line
(pop lines
))
3173 (if (string-match "^[ \t]*|-" line
)
3176 (push (if head
"</thead>" "</tbody>") html
)
3177 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3178 (setq head nil
) ;; head ends here, first time around
3180 (throw 'next-line t
)))
3181 ;; Break the line into fields
3182 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3183 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3184 (setq nlines
(1+ nlines
) i -
1)
3185 (push (concat "<tr>"
3189 (if (and (< i nlines
)
3190 (string-match org-table-number-regexp x
))
3191 (incf (aref fnum i
)))
3193 (concat (car org-export-table-header-tags
) x
3194 (cdr org-export-table-header-tags
))
3195 (concat (car org-export-table-data-tags
) x
3196 (cdr org-export-table-data-tags
))))
3200 (unless splice
(if tbopen
(push "</tbody>" html
)))
3201 (unless splice
(push "</table>\n" html
))
3202 (setq html
(nreverse html
))
3204 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3207 (setq gr
(pop org-table-colgroup-info
))
3208 (format "%s<col align=\"%s\"></col>%s"
3209 (if (memq gr
'(:start
:startend
))
3211 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3214 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3216 (if (memq gr
'(:end
:startend
))
3217 (progn (setq colgropen nil
) "</colgroup>")
3221 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3222 (push html-table-tag html
))
3223 (concat (mapconcat 'identity html
"\n") "\n")))
3225 (defun org-table-clean-before-export (lines)
3226 "Check if the table has a marking column.
3227 If yes remove the column and the special lines."
3228 (setq org-table-colgroup-info nil
)
3231 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3232 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3235 (setq org-table-clean-did-remove-column nil
)
3240 ((string-match "^[ \t]*| */ *|" x
)
3241 (setq org-table-colgroup-info
3243 (cond ((member x
'("<" "<")) :start
)
3244 ((member x
'(">" ">")) :end
)
3245 ((member x
'("<>" "<>")) :startend
)
3247 (org-split-string x
"[ \t]*|[ \t]*")))
3251 (setq org-table-clean-did-remove-column t
)
3256 ((string-match "^[ \t]*| */ *|" x
)
3257 (setq org-table-colgroup-info
3259 (cond ((member x
'("<" "<")) :start
)
3260 ((member x
'(">" ">")) :end
)
3261 ((member x
'("<>" "<>")) :startend
)
3263 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3265 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3266 nil
) ; ignore this line
3267 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3268 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3269 ;; remove the first column
3270 (replace-match "\\1|" t nil x
))))
3273 (defun org-format-table-table-html (lines)
3274 "Format a table generated by table.el into HTML.
3275 This conversion does *not* use `table-generate-source' from table.el.
3276 This has the advantage that Org-mode's HTML conversions can be used.
3277 But it has the disadvantage, that no cell- or row-spanning is allowed."
3278 (let (line field-buffer
3279 (head org-export-highlight-first-table-line
)
3281 (setq html
(concat html-table-tag
"\n"))
3282 (while (setq line
(pop lines
))
3283 (setq empty
" ")
3285 (if (string-match "^[ \t]*\\+-" line
)
3296 (if (equal x
"") (setq x empty
))
3298 (concat (car org-export-table-header-tags
) x
3299 (cdr org-export-table-header-tags
))
3300 (concat (car org-export-table-data-tags
) x
3301 (cdr org-export-table-data-tags
))))
3305 (setq field-buffer nil
)))
3307 (throw 'next-line t
)))
3308 ;; Break the line into fields and store the fields
3309 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3311 (setq field-buffer
(mapcar
3313 (concat x
"<br/>" (pop fields
)))
3315 (setq field-buffer fields
))))
3316 (setq html
(concat html
"</table>\n"))
3319 (defun org-format-table-table-html-using-table-generate-source (lines)
3320 "Format a table into html, using `table-generate-source' from table.el.
3321 This has the advantage that cell- or row-spanning is allowed.
3322 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3324 (with-current-buffer (get-buffer-create " org-tmp1 ")
3326 (insert (mapconcat 'identity lines
"\n"))
3327 (goto-char (point-min))
3328 (if (not (re-search-forward "|[^+]" nil t
))
3329 (error "Error processing table"))
3330 (table-recognize-table)
3331 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3332 (table-generate-source 'html
" org-tmp2 ")
3333 (set-buffer " org-tmp2 ")
3334 (buffer-substring (point-min) (point-max))))
3336 (defun org-html-handle-time-stamps (s)
3337 "Format time stamps in string S, or remove them."
3340 (while (string-match org-maybe-keyword-time-regexp s
)
3341 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3342 ;; never export CLOCK
3344 (or b
(setq b
(substring s
0 (match-beginning 0))))
3345 (if (not org-export-with-timestamps
)
3346 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3347 s
(substring s
(match-end 0)))
3349 r
(substring s
0 (match-beginning 0))
3351 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3352 (match-string 1 s
)))
3353 (format " @<span class=\"timestamp\">%s@</span>"
3355 (org-translate-time (match-string 3 s
)) 1 -
1)))
3356 s
(substring s
(match-end 0)))))
3357 ;; Line break if line started and ended with time stamp stuff
3360 (setq r
(concat r s
))
3361 (unless (string-match "\\S-" (concat b s
))
3362 (setq r
(concat r
"@<br/>")))
3365 (defun org-export-htmlize-region-for-paste (beg end
)
3366 "Convert the region to HTML, using htmlize.el.
3367 This is much like `htmlize-region-for-paste', only that it uses
3368 the settings define in the org-... variables."
3369 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3370 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3371 (htmlbuf (htmlize-region beg end
)))
3373 (with-current-buffer htmlbuf
3374 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3375 (plist-get htmlize-buffer-places
'content-end
)))
3376 (kill-buffer htmlbuf
))))
3379 (defun org-export-htmlize-generate-css ()
3380 "Create the CSS for all font definitions in the current Emacs session.
3381 Use this to create face definitions in your CSS style file that can then
3382 be used by code snippets transformed by htmlize.
3383 This command just produces a buffer that contains class definitions for all
3384 faces used in the current Emacs session. You can copy and paste the ones you
3385 need into your CSS file.
3387 If you then set `org-export-htmlize-output-type' to `css', calls to
3388 the function `org-export-htmlize-region-for-paste' will produce code
3389 that uses these same face definitions."
3392 (and (get-buffer "*html*") (kill-buffer "*html*"))
3394 (let ((fl (face-list))
3395 (htmlize-css-name-prefix "org-")
3396 (htmlize-output-type 'css
)
3398 (while (setq f
(pop fl
)
3399 i
(and f
(face-attribute f
:inherit
)))
3400 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3401 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3402 (htmlize-region (point-min) (point-max))))
3403 (switch-to-buffer "*html*")
3404 (goto-char (point-min))
3405 (if (re-search-forward "<style" nil t
)
3406 (delete-region (point-min) (match-beginning 0)))
3407 (if (re-search-forward "</style>" nil t
)
3408 (delete-region (1+ (match-end 0)) (point-max)))
3409 (beginning-of-line 1)
3410 (if (looking-at " +") (replace-match ""))
3411 (goto-char (point-min)))
3413 (defun org-html-protect (s)
3414 ;; convert & to &, < to < and > to >
3416 (while (string-match "&" s start
)
3417 (setq s
(replace-match "&" t t s
)
3418 start
(1+ (match-beginning 0))))
3419 (while (string-match "<" s
)
3420 (setq s
(replace-match "<" t t s
)))
3421 (while (string-match ">" s
)
3422 (setq s
(replace-match ">" t t s
))))
3425 (defun org-export-cleanup-toc-line (s)
3426 "Remove tags and time staps from lines going into the toc."
3427 (when (memq org-export-with-tags
'(not-in-toc nil
))
3428 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3429 (setq s
(replace-match "" t t s
))))
3430 (when org-export-remove-timestamps-from-toc
3431 (while (string-match org-maybe-keyword-time-regexp s
)
3432 (setq s
(replace-match "" t t s
))))
3433 (while (string-match org-bracket-link-regexp s
)
3434 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3438 (defun org-html-expand (string)
3439 "Prepare STRING for HTML export. Applies all active conversions.
3440 If there are links in the string, don't modify these."
3441 (let* ((re (concat org-bracket-link-regexp
"\\|"
3442 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3444 (while (setq m
(string-match re string
))
3445 (setq s
(substring string
0 m
)
3446 l
(match-string 0 string
)
3447 string
(substring string
(match-end 0)))
3448 (push (org-html-do-expand s
) res
)
3450 (push (org-html-do-expand string
) res
)
3451 (apply 'concat
(nreverse res
))))
3453 (defun org-html-do-expand (s)
3454 "Apply all active conversions to translate special ASCII to HTML."
3455 (setq s
(org-html-protect s
))
3456 (if org-export-html-expand
3458 (while (string-match "@<\\([^&]*\\)>" s
)
3459 (setq s
(replace-match "<\\1>" t nil s
)))))
3460 (if org-export-with-emphasize
3461 (setq s
(org-export-html-convert-emphasize s
)))
3462 (if org-export-with-special-strings
3463 (setq s
(org-export-html-convert-special-strings s
)))
3464 (if org-export-with-sub-superscripts
3465 (setq s
(org-export-html-convert-sub-super s
)))
3466 (if org-export-with-TeX-macros
3467 (let ((start 0) wd ass
)
3468 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3469 (if (get-text-property (match-beginning 0) 'org-protected s
)
3470 (setq start
(match-end 0))
3471 (setq wd
(match-string 1 s
))
3472 (if (setq ass
(assoc wd org-html-entities
))
3473 (setq s
(replace-match (or (cdr ass
)
3474 (concat "&" (car ass
) ";"))
3476 (setq start
(+ start
(length wd
))))))))
3479 (defun org-create-multibrace-regexp (left right n
)
3480 "Create a regular expression which will match a balanced sexp.
3481 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3482 as single character strings.
3483 The regexp returned will match the entire expression including the
3484 delimiters. It will also define a single group which contains the
3485 match except for the outermost delimiters. The maximum depth of
3486 stacked delimiters is N. Escaping delimiters is not possible."
3487 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3490 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3493 re
(concat re or next
)
3494 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3495 (concat left
"\\(" re
"\\)" right
)))
3497 (defvar org-match-substring-regexp
3499 "\\([^\\]\\)\\([_^]\\)\\("
3500 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3502 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3504 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3505 "The regular expression matching a sub- or superscript.")
3507 (defvar org-match-substring-with-braces-regexp
3509 "\\([^\\]\\)\\([_^]\\)\\("
3510 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3512 "The regular expression matching a sub- or superscript, forcing braces.")
3514 (defconst org-export-html-special-string-regexps
3515 '(("\\\\-" .
"­")
3516 ("---\\([^-]\\)" .
"—\\1")
3517 ("--\\([^-]\\)" .
"–\\1")
3518 ("\\.\\.\\." .
"…"))
3519 "Regular expressions for special string conversion.")
3521 (defun org-export-html-convert-special-strings (string)
3522 "Convert special characters in STRING to HTML."
3523 (let ((all org-export-html-special-string-regexps
)
3525 (while (setq a
(pop all
))
3526 (setq re
(car a
) rpl
(cdr a
) start
0)
3527 (while (string-match re string start
)
3528 (if (get-text-property (match-beginning 0) 'org-protected string
)
3529 (setq start
(match-end 0))
3530 (setq string
(replace-match rpl t nil string
)))))
3533 (defun org-export-html-convert-sub-super (string)
3534 "Convert sub- and superscripts in STRING to HTML."
3535 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3536 (while (string-match org-match-substring-regexp string s
)
3538 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3539 ((get-text-property (match-beginning 2) 'org-protected string
)
3540 (setq s
(match-end 2)))
3542 (setq s
(match-end 1)
3543 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3544 c
(or (match-string 8 string
)
3545 (match-string 6 string
)
3546 (match-string 5 string
))
3547 string
(replace-match
3548 (concat (match-string 1 string
)
3549 "<" key
">" c
"</" key
">")
3551 (while (string-match "\\\\\\([_^]\\)" string
)
3552 (setq string
(replace-match (match-string 1 string
) t t string
)))
3555 (defun org-export-html-convert-emphasize (string)
3558 (while (string-match org-emph-re string s
)
3560 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3561 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3562 (setq s
(match-beginning 0)
3565 (match-string 1 string
)
3566 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3567 (match-string 4 string
)
3568 (nth 3 (assoc (match-string 3 string
)
3569 org-emphasis-alist
))
3570 (match-string 5 string
))
3571 string
(replace-match rpl t t string
)
3572 s
(+ s
(- (length rpl
) 2)))
3576 (defvar org-par-open nil
)
3577 (defun org-open-par ()
3578 "Insert <p>, but first close previous paragraph if any."
3579 (org-close-par-maybe)
3581 (setq org-par-open t
))
3582 (defun org-close-par-maybe ()
3583 "Close paragraph if there is one open."
3586 (setq org-par-open nil
)))
3587 (defun org-close-li (&optional type
)
3588 "Close <li> if necessary."
3589 (org-close-par-maybe)
3590 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3592 (defvar body-only
) ; dynamically scoped into this.
3593 (defun org-html-level-start (level title umax with-toc head-count
)
3594 "Insert a new level in HTML export.
3595 When TITLE is nil, just close all open levels."
3596 (org-close-par-maybe)
3597 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3601 (if (aref org-levels-open
(1- l
))
3603 (org-html-level-close l umax
)
3604 (aset org-levels-open
(1- l
) nil
)))
3607 ;; If title is nil, this means this function is called to close
3608 ;; all levels, so the rest is done only if title is given
3609 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3610 (setq title
(replace-match
3611 (if org-export-with-tags
3614 " <span class=\"tag\">"
3615 (mapconcat 'identity
(org-split-string
3616 (match-string 1 title
) ":")
3623 (if (aref org-levels-open
(1- level
))
3627 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3628 (insert "<li>" title
"<br/>\n")))
3629 (aset org-levels-open
(1- level
) t
)
3630 (org-close-par-maybe)
3632 (insert (format "<ul>\n<li id=\"%s\">" target
)
3634 (insert "<ul>\n<li>" title
"<br/>\n"))))
3635 (aset org-levels-open
(1- level
) t
)
3636 (setq snumber
(org-section-number level
))
3637 (if (and org-export-with-section-numbers
(not body-only
))
3638 (setq title
(concat snumber
" " title
)))
3639 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3640 (unless (= head-count
1) (insert "\n</div>\n"))
3641 (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"
3642 snumber level level snumber title level snumber
))
3645 (defun org-get-text-property-any (pos prop
&optional object
)
3646 (or (get-text-property pos prop object
)
3647 (and (setq pos
(next-single-property-change pos prop object
))
3648 (get-text-property pos prop object
))))
3650 (defun org-html-level-close (level max-outline-level
)
3651 "Terminate one level in HTML export."
3652 (if (<= level max-outline-level
)
3655 (insert "</ul>\n")))
3657 ;;; iCalendar export
3660 (defun org-export-icalendar-this-file ()
3661 "Export current file as an iCalendar file.
3662 The iCalendar file will be located in the same directory as the Org-mode
3663 file, but with extension `.ics'."
3665 (org-export-icalendar nil buffer-file-name
))
3668 (defun org-export-icalendar-all-agenda-files ()
3669 "Export all files in `org-agenda-files' to iCalendar .ics files.
3670 Each iCalendar file will be located in the same directory as the Org-mode
3671 file, but with extension `.ics'."
3673 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3676 (defun org-export-icalendar-combine-agenda-files ()
3677 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3678 The file is stored under the name `org-combined-agenda-icalendar-file'."
3680 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3682 (defun org-export-icalendar (combine &rest files
)
3683 "Create iCalendar files for all elements of FILES.
3684 If COMBINE is non-nil, combine all calendar entries into a single large
3685 file and store it under the name `org-combined-agenda-icalendar-file'."
3687 (org-prepare-agenda-buffers files
)
3688 (let* ((dir (org-export-directory
3689 :ical
(list :publishing-directory
3690 org-export-publishing-directory
)))
3691 file ical-file ical-buffer category started org-agenda-new-buffers
)
3692 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3695 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3696 org-combined-agenda-icalendar-file
3697 (expand-file-name org-combined-agenda-icalendar-file dir
))
3698 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3699 (set-buffer ical-buffer
) (erase-buffer))
3700 (while (setq file
(pop files
))
3702 (org-check-agenda-file file
)
3703 (set-buffer (org-get-agenda-file-buffer file
))
3705 (setq ical-file
(concat (file-name-as-directory dir
)
3706 (file-name-sans-extension
3707 (file-name-nondirectory buffer-file-name
))
3709 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3710 (with-current-buffer ical-buffer
(erase-buffer)))
3711 (setq category
(or org-category
3712 (file-name-sans-extension
3713 (file-name-nondirectory buffer-file-name
))))
3714 (if (symbolp category
) (setq category
(symbol-name category
)))
3715 (let ((standard-output ical-buffer
))
3717 (and (not started
) (setq started t
)
3718 (org-start-icalendar-file org-icalendar-combined-name
))
3719 (org-start-icalendar-file category
))
3720 (org-print-icalendar-entries combine
)
3721 (when (or (and combine
(not files
)) (not combine
))
3722 (org-finish-icalendar-file)
3723 (set-buffer ical-buffer
)
3725 (run-hooks 'org-after-save-iCalendar-file-hook
)
3726 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3728 (org-release-buffers org-agenda-new-buffers
))))
3730 (defvar org-after-save-iCalendar-file-hook nil
3731 "Hook run after an iCalendar file has been saved.
3732 The iCalendar buffer is still current when this hook is run.
3733 A good way to use this is to tell a desktop calenndar application to re-read
3734 the iCalendar file.")
3736 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3737 (defun org-print-icalendar-entries (&optional combine
)
3738 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3739 When COMBINE is non nil, add the category to each line."
3740 (require 'org-agenda
)
3741 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3742 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3743 (dts (org-ical-ts-to-string
3744 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3746 hd ts ts2 state status
(inc t
) pos b sexp rrule
3747 scheduledp deadlinep prefix
3748 tmp pri category entry location summary desc uid
3749 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3750 (org-refresh-category-properties)
3752 (goto-char (point-min))
3753 (while (re-search-forward re1 nil t
)
3756 (when (boundp 'org-icalendar-verify-function
)
3757 (unless (funcall org-icalendar-verify-function
)
3758 (outline-next-heading)
3761 (setq pos
(match-beginning 0)
3764 hd
(condition-case nil
3765 (org-icalendar-cleanup-string
3767 (error (throw :skip nil
)))
3768 summary
(org-icalendar-cleanup-string
3769 (org-entry-get nil
"SUMMARY"))
3770 desc
(org-icalendar-cleanup-string
3771 (or (org-entry-get nil
"DESCRIPTION")
3772 (and org-icalendar-include-body
(org-get-entry)))
3773 t org-icalendar-include-body
)
3774 location
(org-icalendar-cleanup-string
3775 (org-entry-get nil
"LOCATION"))
3776 uid
(if org-icalendar-store-UID
3778 (or (org-id-get) (org-id-new)))
3779 category
(org-get-category)
3780 deadlinep nil scheduledp nil
)
3781 (if (looking-at re2
)
3783 (goto-char (match-end 0))
3784 (setq ts2
(match-string 1)
3785 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
3786 (setq tmp
(buffer-substring (max (point-min)
3787 (- pos org-ds-keyword-length
))
3789 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3792 (replace-match "\\1" t nil ts
))
3794 deadlinep
(string-match org-deadline-regexp tmp
)
3795 scheduledp
(string-match org-scheduled-regexp tmp
)
3796 ;; donep (org-entry-is-done-p)
3798 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
3799 (if (or (string-match org-tr-regexp hd
)
3800 (string-match org-ts-regexp hd
))
3801 (setq hd
(replace-match "" t t hd
)))
3802 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3804 (concat "\nRRULE:FREQ="
3807 '(("d" .
"DAILY")("w" .
"WEEKLY")
3808 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3809 ";INTERVAL=" (match-string 1 ts
)))
3811 (setq summary
(or summary hd
))
3812 (if (string-match org-bracket-link-regexp summary
)
3814 (replace-match (if (match-end 3)
3815 (match-string 3 summary
)
3816 (match-string 1 summary
))
3818 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3819 (if scheduledp
(setq summary
(concat "S: " summary
)))
3820 (if (string-match "\\`<%%" ts
)
3821 (with-current-buffer sexp-buffer
3822 (insert (substring ts
1 -
1) " " summary
"\n"))
3823 (princ (format "BEGIN:VEVENT
3831 (org-ical-ts-to-string ts
"DTSTART")
3832 (org-ical-ts-to-string ts2
"DTEND" inc
)
3834 (if (and desc
(string-match "\\S-" desc
))
3835 (concat "\nDESCRIPTION: " desc
) "")
3836 (if (and location
(string-match "\\S-" location
))
3837 (concat "\nLOCATION: " location
) "")
3839 (when (and org-icalendar-include-sexps
3840 (condition-case nil
(require 'icalendar
) (error nil
))
3841 (fboundp 'icalendar-export-region
))
3842 ;; Get all the literal sexps
3843 (goto-char (point-min))
3844 (while (re-search-forward "^&?%%(" nil t
)
3847 (setq b
(match-beginning 0))
3848 (goto-char (1- (match-end 0)))
3851 (setq sexp
(buffer-substring b
(point)))
3852 (with-current-buffer sexp-buffer
3854 (princ (org-diary-to-ical-string sexp-buffer
)))))
3856 (when org-icalendar-include-todo
3857 (setq prefix
"TODO-")
3858 (goto-char (point-min))
3859 (while (re-search-forward org-todo-line-regexp nil t
)
3862 (when (boundp 'org-icalendar-verify-function
)
3863 (unless (funcall org-icalendar-verify-function
)
3864 (outline-next-heading)
3867 (setq state
(match-string 2))
3868 (setq status
(if (member state org-done-keywords
)
3869 "COMPLETED" "NEEDS-ACTION"))
3871 (or (not (member state org-done-keywords
))
3872 (eq org-icalendar-include-todo
'all
))
3873 (not (member org-archive-tag
(org-get-tags-at)))
3875 (setq hd
(match-string 3)
3876 summary
(org-icalendar-cleanup-string
3877 (org-entry-get nil
"SUMMARY"))
3878 desc
(org-icalendar-cleanup-string
3879 (or (org-entry-get nil
"DESCRIPTION")
3880 (and org-icalendar-include-body
(org-get-entry)))
3881 t org-icalendar-include-body
)
3882 location
(org-icalendar-cleanup-string
3883 (org-entry-get nil
"LOCATION"))
3884 uid
(if org-icalendar-store-UID
3886 (or (org-id-get) (org-id-new))))
3887 (if (string-match org-bracket-link-regexp hd
)
3888 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3889 (match-string 1 hd
))
3891 (if (string-match org-priority-regexp hd
)
3892 (setq pri
(string-to-char (match-string 2 hd
))
3893 hd
(concat (substring hd
0 (match-beginning 1))
3894 (substring hd
(match-end 1))))
3895 (setq pri org-default-priority
))
3896 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3897 (- org-lowest-priority org-highest-priority
))))))
3899 (princ (format "BEGIN:VTODO
3911 (if (and location
(string-match "\\S-" location
))
3912 (concat "\nLOCATION: " location
) "")
3913 (if (and desc
(string-match "\\S-" desc
))
3914 (concat "\nDESCRIPTION: " desc
) "")
3918 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3919 "Take out stuff and quote what needs to be quoted.
3920 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3921 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3926 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3927 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3928 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3929 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3931 (while (string-match "\\([,;]\\)" s start
)
3932 (setq start
(+ (match-beginning 0) 2)
3933 s
(replace-match "\\\\\\1" nil nil s
))))
3935 (while (string-match "[ \t]*\n[ \t]*" s
)
3936 (setq s
(replace-match "\\n" t t s
))))
3937 (setq s
(org-trim s
))
3940 (if (and (numberp maxlength
)
3941 (> (length s
) maxlength
))
3942 (setq s
(substring s
0 maxlength
)))))
3945 (defun org-get-entry ()
3946 "Clean-up description string."
3948 (org-back-to-heading t
)
3949 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3951 (defun org-start-icalendar-file (name)
3952 "Start an iCalendar file by inserting the header."
3953 (let ((user user-full-name
)
3954 (name (or name
"unknown"))
3955 (timezone (cadr (current-time-zone))))
3957 (format "BEGIN:VCALENDAR
3960 PRODID:-//%s//Emacs with Org-mode//EN
3962 CALSCALE:GREGORIAN\n" name user timezone
))))
3964 (defun org-finish-icalendar-file ()
3965 "Finish an iCalendar file by inserting the END statement."
3966 (princ "END:VCALENDAR\n"))
3968 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3969 "Take a time string S and convert it to iCalendar format.
3970 KEYWORD is added in front, to make a complete line like DTSTART....
3971 When INC is non-nil, increase the hour by two (if time string contains
3972 a time), or the day by one (if it does not contain a time)."
3973 (let ((t1 (org-parse-time-string s
'nodefault
))
3974 t2 fmt have-time time
)
3975 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3976 (setq t2 t1 have-time t
)
3977 (setq t2
(org-parse-time-string s
)))
3978 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3979 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3982 (if org-agenda-default-appointment-duration
3983 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3986 (setq time
(encode-time s mi h d m y
)))
3987 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3988 (concat keyword
(format-time-string fmt time
))))
3992 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3993 (with-current-buffer buffer
3994 (apply 'insert output
)))
3995 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3998 (defun org-export-as-xoxo (&optional buffer
)
3999 "Export the org buffer as XOXO.
4000 The XOXO buffer is named *xoxo-<source buffer name>*"
4001 (interactive (list (current-buffer)))
4002 ;; A quickie abstraction
4004 ;; Output everything as XOXO
4005 (with-current-buffer (get-buffer buffer
)
4006 (let* ((pos (point))
4007 (opt-plist (org-combine-plists (org-default-export-plist)
4008 (org-infile-export-plist)))
4009 (filename (concat (file-name-as-directory
4010 (org-export-directory :xoxo opt-plist
))
4011 (file-name-sans-extension
4012 (file-name-nondirectory buffer-file-name
))
4014 (out (find-file-noselect filename
))
4017 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4018 ;; Check the output buffer is empty.
4019 (with-current-buffer out
(erase-buffer))
4020 ;; Kick off the output
4021 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4022 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4023 (let* ((hd (match-string-no-properties 1))
4026 (match-string-no-properties 2)
4028 (goto-char (match-end 0))
4033 (if (looking-at "^[ \t]\\(.*\\)")
4034 (setq str
(concat str
(match-string-no-properties 1)))
4035 (throw 'loop str
)))))))))
4037 ;; Handle level rendering
4039 ((> level last-level
)
4040 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4042 ((< level last-level
)
4043 (dotimes (- (- last-level level
) 1)
4045 (org-export-as-xoxo-insert-into out
"</li>\n"))
4046 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4048 (org-export-as-xoxo-insert-into out
"</li>\n")
4049 (setq hanging-li nil
)))
4051 ((equal level last-level
)
4053 (org-export-as-xoxo-insert-into out
"</li>\n")))
4056 (setq last-level level
)
4058 ;; And output the new li
4059 (setq hanging-li
't
)
4060 (if (equal ?
+ (elt text
0))
4061 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4062 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4064 ;; Finally finish off the ol
4065 (dotimes (- last-level
1)
4067 (org-export-as-xoxo-insert-into out
"</li>\n"))
4068 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4071 ;; Finish the buffer off and clean it up.
4072 (switch-to-buffer-other-window out
)
4073 (indent-region (point-min) (point-max) nil
)
4075 (goto-char (point-min))
4080 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4082 ;;; org-exp.el ends here