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;
469 table { border-collapse: collapse; }
472 <!--border: 1pt solid #ADB9CC;-->
474 dt { font-weight: bold; }
476 "The default style specification for exported HTML files.
477 Since there are different ways of setting style information, this variable
478 needs to contain the full HTML structure to provide a style, including the
479 surrounding HTML tags. The style specifications should include definitions
480 for new classes todo, done, title, and deadline. For example, valid values
483 <style type=\"text/css\">
484 p { font-weight: normal; color: gray; }
486 .title { text-align: center; }
487 .todo, .deadline { color: red; }
488 .done { color: green; }
491 or, if you want to keep the style in a file,
493 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
495 As the value of this option simply gets inserted into the HTML <head> header,
496 you can \"misuse\" it to add arbitrary text to the header."
497 :group
'org-export-html
501 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
502 "Format for typesetting the document title in HTML export."
503 :group
'org-export-html
506 (defcustom org-export-html-toplevel-hlevel
2
507 "The <H> level for level 1 headings in HTML export."
508 :group
'org-export-html
511 (defcustom org-export-html-link-org-files-as-html t
512 "Non-nil means, make file links to `file.org' point to `file.html'.
513 When org-mode is exporting an org-mode file to HTML, links to
514 non-html files are directly put into a href tag in HTML.
515 However, links to other Org-mode files (recognized by the
516 extension `.org.) should become links to the corresponding html
517 file, assuming that the linked org-mode file will also be
519 When nil, the links still point to the plain `.org' file."
520 :group
'org-export-html
523 (defcustom org-export-html-inline-images
'maybe
524 "Non-nil means, inline images into exported HTML pages.
525 This is done using an <img> tag. When nil, an anchor with href is used to
526 link to the image. If this option is `maybe', then images in links with
527 an empty description will be inlined, while images with a description will
529 :group
'org-export-html
530 :type
'(choice (const :tag
"Never" nil
)
531 (const :tag
"Always" t
)
532 (const :tag
"When there is no description" maybe
)))
535 (defcustom org-export-html-expand t
536 "Non-nil means, for HTML export, treat @<...> as HTML tag.
537 When nil, these tags will be exported as plain text and therefore
538 not be interpreted by a browser.
540 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
541 :group
'org-export-html
544 (defcustom org-export-html-table-tag
545 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
546 "The HTML tag that is used to start a table.
547 This must be a <table> tag, but you may change the options like
548 borders and spacing."
549 :group
'org-export-html
552 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
553 "The opening tag for table header fields.
554 This is customizable so that alignment options can be specified."
555 :group
'org-export-tables
556 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
558 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
559 "The opening tag for table data fields.
560 This is customizable so that alignment options can be specified."
561 :group
'org-export-tables
562 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
564 (defcustom org-export-html-with-timestamp nil
565 "If non-nil, write `org-export-html-html-helper-timestamp'
566 into the exported HTML text. Otherwise, the buffer will just be saved
568 :group
'org-export-html
571 (defcustom org-export-html-html-helper-timestamp
572 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
573 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
574 :group
'org-export-html
577 (defgroup org-export-htmlize nil
578 "Options for processing examples with htmlize.el."
579 :tag
"Org Export Htmlize"
580 :group
'org-export-html
)
582 (defcustom org-export-htmlize-output-type
'inline-css
583 "Output type to be used by htmlize when formatting code snippets.
584 Normally this is `inline-css', but if you have defined to appropriate
585 classes in your css style file, setting this to `css' means that the
586 fontification will use the class names.
587 See also the function `org-export-htmlize-generate-css'."
588 :group
'org-export-htmlize
589 :type
'(choice (const css
) (const inline-css
)))
591 (defcustom org-export-htmlize-css-font-prefix
"org-"
592 "The prefix for CSS class names for htmlize font specifications."
593 :group
'org-export-htmlize
596 (defgroup org-export-icalendar nil
597 "Options specific for iCalendar export of Org-mode files."
598 :tag
"Org Export iCalendar"
601 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
602 "The file name for the iCalendar file covering all agenda files.
603 This file is created with the command \\[org-export-icalendar-all-agenda-files].
604 The file name should be absolute, the file will be overwritten without warning."
605 :group
'org-export-icalendar
608 (defcustom org-icalendar-include-todo nil
609 "Non-nil means, export to iCalendar files should also cover TODO items."
610 :group
'org-export-icalendar
612 (const :tag
"None" nil
)
613 (const :tag
"Unfinished" t
)
614 (const :tag
"All" all
)))
616 (defcustom org-icalendar-include-sexps t
617 "Non-nil means, export to iCalendar files should also cover sexp entries.
618 These are entries like in the diary, but directly in an Org-mode file."
619 :group
'org-export-icalendar
622 (defcustom org-icalendar-include-body
100
623 "Amount of text below headline to be included in iCalendar export.
624 This is a number of characters that should maximally be included.
625 Properties, scheduling and clocking lines will always be removed.
626 The text will be inserted into the DESCRIPTION field."
627 :group
'org-export-icalendar
629 (const :tag
"Nothing" nil
)
630 (const :tag
"Everything" t
)
631 (integer :tag
"Max characters")))
633 (defcustom org-icalendar-combined-name
"OrgMode"
634 "Calendar name for the combined iCalendar representing all agenda files."
635 :group
'org-export-icalendar
638 (defcustom org-icalendar-store-UID nil
639 "Non-nil means, store any created UIDs in properties.
640 The iCalendar standard requires that all entries have a unique identifyer.
641 Org will create these identifiers as needed. When this variable is non-nil,
642 the created UIDs will be stored in the ID property of the entry. Then the
643 next time this entry is exported, it will be exported with the same UID,
644 superceeding the previous form of it. This is essential for
645 synchronization services.
646 This variable is not turned on by default because we want to avoid creating
647 a property drawer in every entry if people are only playing with this feature,
648 or if they are only using it locally."
649 :group
'org-export-icalendar
654 ;;; Variables, constants, and parameter plists
656 (defconst org-level-max
20)
658 (defvar org-export-html-preamble nil
659 "Preamble, to be inserted just after <body>. Set by publishing functions.")
660 (defvar org-export-html-postamble nil
661 "Preamble, to be inserted just before </body>. Set by publishing functions.")
662 (defvar org-export-html-auto-preamble t
663 "Should default preamble be inserted? Set by publishing functions.")
664 (defvar org-export-html-auto-postamble t
665 "Should default postamble be inserted? Set by publishing functions.")
666 (defvar org-current-export-file nil
) ; dynamically scoped parameter
667 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
669 (defconst org-export-plist-vars
670 '((:link-up . org-export-html-link-up
)
671 (:link-home . org-export-html-link-home
)
672 (:language . org-export-default-language
)
673 (:customtime . org-display-custom-times
)
674 (:headline-levels . org-export-headline-levels
)
675 (:section-numbers . org-export-with-section-numbers
)
676 (:table-of-contents . org-export-with-toc
)
677 (:preserve-breaks . org-export-preserve-breaks
)
678 (:archived-trees . org-export-with-archived-trees
)
679 (:emphasize . org-export-with-emphasize
)
680 (:sub-superscript . org-export-with-sub-superscripts
)
681 (:special-strings . org-export-with-special-strings
)
682 (:footnotes . org-export-with-footnotes
)
683 (:drawers . org-export-with-drawers
)
684 (:tags . org-export-with-tags
)
685 (:TeX-macros . org-export-with-TeX-macros
)
686 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
687 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
688 (:fixed-width . org-export-with-fixed-width
)
689 (:timestamps . org-export-with-timestamps
)
690 (:author-info . org-export-author-info
)
691 (:time-stamp-file . org-export-time-stamp-file
)
692 (:tables . org-export-with-tables
)
693 (:table-auto-headline . org-export-highlight-first-table-line
)
694 (:style . org-export-html-style
)
695 (:agenda-style . org-agenda-export-html-style
)
696 (:convert-org-links . org-export-html-link-org-files-as-html
)
697 (:inline-images . org-export-html-inline-images
)
698 (:html-extension . org-export-html-extension
)
699 (:html-table-tag . org-export-html-table-tag
)
700 (:expand-quoted-html . org-export-html-expand
)
701 (:timestamp . org-export-html-with-timestamp
)
702 (:publishing-directory . org-export-publishing-directory
)
703 (:preamble . org-export-html-preamble
)
704 (:postamble . org-export-html-postamble
)
705 (:auto-preamble . org-export-html-auto-preamble
)
706 (:auto-postamble . org-export-html-auto-postamble
)
707 (:author . user-full-name
)
708 (:email . user-mail-address
)))
710 (defun org-default-export-plist ()
711 "Return the property list with default settings for the export variables."
712 (let ((l org-export-plist-vars
) rtn e
)
713 (while (setq e
(pop l
))
714 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
717 (defvar org-export-inbuffer-options-extra nil
718 "List of additional in-buffer options that should be detected.
719 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
720 etc. Extensions can add to this list to get their options detected, and they
721 can then add a function to `org-export-options-filters' to process these
723 Each element in this list must be a list, with the in-buffer keyword as car,
724 and a property (a symbol) as the next element. All occurences of the
725 keyword will be found, the values concatenated with a space character
726 in between, and the result stored in the export options property list.")
728 (defvar org-export-options-filters nil
729 "Functions to be called to finalize the export/publishing options.
730 All these options are stored in a property list, and each of the functions
731 in this hook gets a chance to modify this property list. Each function
732 must accept the property list as an argument, and must return the (possibly
735 (defun org-infile-export-plist ()
736 "Return the property list with file-local settings for export."
740 (goto-char (point-min))
741 (let ((re (org-make-options-regexp
743 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
744 "LINK_UP" "LINK_HOME" "SETUPFILE")
745 (mapcar 'car org-export-inbuffer-options-extra
))))
746 p key val text options js-up js-main js-css js-opt a pr
747 ext-setup-or-nil setup-contents
(start 0))
748 (while (or (and ext-setup-or-nil
749 (string-match re ext-setup-or-nil start
)
750 (setq start
(match-end 0)))
751 (and (setq ext-setup-or-nil nil start
0)
752 (re-search-forward re nil t
)))
753 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
754 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
756 ((setq a
(assoc key org-export-inbuffer-options-extra
))
758 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
759 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
760 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
761 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
762 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
763 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
764 ((string-equal key
"TEXT")
765 (setq text
(if text
(concat text
"\n" val
) val
)))
766 ((string-equal key
"OPTIONS")
767 (setq options
(concat val
" " options
)))
768 ((string-equal key
"LINK_UP")
769 (setq p
(plist-put p
:link-up val
)))
770 ((string-equal key
"LINK_HOME")
771 (setq p
(plist-put p
:link-home val
)))
772 ((equal key
"SETUPFILE")
773 (setq setup-contents
(org-file-contents
775 (org-remove-double-quotes
778 (if (not ext-setup-or-nil
)
779 (setq ext-setup-or-nil setup-contents start
0)
780 (setq ext-setup-or-nil
781 (concat (substring ext-setup-or-nil
0 start
)
782 "\n" setup-contents
"\n"
783 (substring ext-setup-or-nil start
)))))))
784 (setq p
(plist-put p
:text text
))
786 (setq p
(org-export-add-options-to-plist p options
)))
789 (defun org-export-add-options-to-plist (p options
)
790 "Parse an OPTONS line and set values in the property list P."
793 (let ((op '(("H" .
:headline-levels
)
794 ("num" .
:section-numbers
)
795 ("toc" .
:table-of-contents
)
796 ("\\n" .
:preserve-breaks
)
797 ("@" .
:expand-quoted-html
)
800 ("^" .
:sub-superscript
)
801 ("-" .
:special-strings
)
806 ("TeX" .
:TeX-macros
)
807 ("LaTeX" .
:LaTeX-fragments
)
808 ("skip" .
:skip-before-1st-heading
)
809 ("author" .
:author-info
)
810 ("timestamp" .
:time-stamp-file
)))
812 (while (setq o
(pop op
))
813 (if (string-match (concat (regexp-quote (car o
))
814 ":\\([^ \t\n\r;,.]*\\)")
816 (setq p
(plist-put p
(cdr o
)
817 (car (read-from-string
818 (match-string 1 options
))))))))))
821 (defun org-export-add-subtree-options (p pos
)
822 "Add options in subtree at position POS to property list P."
825 (when (org-at-heading-p)
827 ;; This is actually read in `org-export-get-title-from-subtree'
828 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
829 ;; (setq p (plist-put p :title a)))
830 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
831 (setq p
(plist-put p
:text a
)))
832 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
833 (setq p
(org-export-add-options-to-plist p a
)))))
836 (defun org-export-directory (type plist
)
837 (let* ((val (plist-get plist
:publishing-directory
))
839 (or (cdr (assoc type val
)) ".")
843 (defun org-export-process-option-filters (plist)
844 (let ((functions org-export-options-filters
) f
)
845 (while (setq f
(pop functions
))
846 (setq plist
(funcall f plist
))))
850 (defun org-export (&optional arg
)
851 "Export dispatcher for Org-mode.
852 When `org-export-run-in-background' is non-nil, try to run the command
853 in the background. This will be done only for commands that write
854 to a file. For details see the docstring of `org-export-run-in-background'.
856 The prefix argument ARG will be passed to the exporter. However, if
857 ARG is a double universal prefix `C-u C-u', that means to inverse the
858 value of `org-export-run-in-background'."
860 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
861 (help "[t] insert the export option template
862 \[v] limit export to visible part of outline tree
867 \[H] export as HTML to temporary buffer
868 \[R] export region as HTML
869 \[b] export as HTML and browse immediately
873 \[L] export as LaTeX to temporary buffer
875 \[i] export current file as iCalendar file
876 \[I] export all agenda files as iCalendar files
877 \[c] export agenda files into combined iCalendar file
879 \[F] publish current file
880 \[P] publish current project
881 \[X] publish... (project will be prompted for)
882 \[A] publish all projects")
884 '((?t org-insert-export-options-template nil
)
885 (?v org-export-visible nil
)
886 (?a org-export-as-ascii t
)
887 (?h org-export-as-html t
)
888 (?b org-export-as-html-and-open t
)
889 (?H org-export-as-html-to-buffer nil
)
890 (?R org-export-region-as-html nil
)
891 (?x org-export-as-xoxo t
)
892 (?l org-export-as-latex t
)
893 (?L org-export-as-latex-to-buffer nil
)
894 (?i org-export-icalendar-this-file t
)
895 (?I org-export-icalendar-all-agenda-files t
)
896 (?c org-export-icalendar-combine-agenda-files t
)
897 (?F org-publish-current-file t
)
898 (?P org-publish-current-project t
)
900 (?A org-publish-all t
)))
902 (save-window-excursion
903 (delete-other-windows)
904 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
906 (message "Select command: ")
907 (setq r1
(read-char-exclusive)))
908 (setq r2
(if (< r1
27) (+ r1
96) r1
))
909 (unless (setq ass
(assq r2 cmds
))
910 (error "No command associated with key %c" r1
))
911 (if (and bg
(nth 2 ass
))
912 ;; execute in background
913 (let ((p (start-process
914 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
916 (expand-file-name invocation-name invocation-directory
)
919 "--eval" "(require 'org-exp)"
920 "--eval" "(setq org-wait .2)"
922 "-f" (symbol-name (nth 1 ass
)))))
923 (set-process-sentinel p
'org-export-process-sentinel
)
924 (message "Background process \"%s\": started" p
))
925 ;; background processing not requested, or not possible
926 (call-interactively (nth 1 ass
)))))
928 (defun org-export-process-sentinel (process status
)
929 (if (string-match "\n+\\'" status
)
930 (setq status
(substring status
0 -
1)))
931 (message "Background process \"%s\": %s" process status
))
933 (defconst org-html-entities
974 ("Aring") ("AA".
"Å")
1063 ("varepsilon".
"ε")
1076 ("sigmaf") ("varsigma".
"ς")
1084 ("thetasym") ("vartheta".
"ϑ")
1087 ("bull") ("bullet".
"•")
1088 ("hellip") ("dots".
"…")
1098 ("larr") ("leftarrow".
"←") ("gets".
"←")
1099 ("uarr") ("uparrow".
"↑")
1100 ("rarr") ("to".
"→") ("rightarrow".
"→")
1101 ("darr")("downarrow".
"↓")
1102 ("harr") ("leftrightarrow".
"↔")
1103 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1104 ("lArr") ("Leftarrow".
"⇐")
1105 ("uArr") ("Uparrow".
"⇑")
1106 ("rArr") ("Rightarrow".
"⇒")
1107 ("dArr") ("Downarrow".
"⇓")
1108 ("hArr") ("Leftrightarrow".
"⇔")
1110 ("part") ("partial".
"∂")
1111 ("exist") ("exists".
"∃")
1112 ("empty") ("emptyset".
"∅")
1114 ("isin") ("in".
"∈")
1120 ("lowast") ("ast".
"∗")
1122 ("prop") ("proptp".
"∝")
1123 ("infin") ("infty".
"∞")
1124 ("ang") ("angle".
"∠")
1125 ("and") ("wedge".
"∧")
1126 ("or") ("vee".
"∨")
1132 ("cong") ("simeq".
"≅")
1133 ("asymp")("approx".
"≈")
1134 ("ne") ("neq".
"≠")
1138 ("sub") ("subset".
"⊂")
1139 ("sup") ("supset".
"⊃")
1146 ("sdot") ("cdot".
"⋅")
1153 ("loz") ("Diamond".
"◊")
1154 ("spades") ("spadesuit".
"♠")
1155 ("clubs") ("clubsuit".
"♣")
1156 ("hearts") ("diamondsuit".
"♥")
1157 ("diams") ("diamondsuit".
"♦")
1158 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1225 "Entities for TeX->HTML translation.
1226 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1227 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1228 In that case, \"\\ent\" will be translated to \"&other;\".
1229 The list contains HTML entities for Latin-1, Greek and other symbols.
1230 It is supplemented by a number of commonly used TeX macros with appropriate
1231 translations. There is currently no way for users to extend this.")
1233 ;;; General functions for all backends
1235 (defun org-export-preprocess-string (string &rest parameters
)
1236 "Cleanup STRING so that that the true exported has a more consistent source.
1237 This function takes STRING, which should be a buffer-string of an org-file
1238 to export. It then creates a temporary buffer where it does its job.
1239 The result is then again returned as a string, and the exporter works
1240 on this string to produce the exported version."
1242 (let* ((re-radio (and org-target-link-regexp
1243 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1244 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1245 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1246 (re-archive (concat ":" org-archive-tag
":"))
1247 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1248 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1249 (htmlp (plist-get parameters
:for-html
))
1250 (asciip (plist-get parameters
:for-ascii
))
1251 (latexp (plist-get parameters
:for-LaTeX
))
1252 (commentsp (plist-get parameters
:comments
))
1253 (archived-trees (plist-get parameters
:archived-trees
))
1254 (inhibit-read-only t
)
1255 (drawers org-drawers
)
1256 (exp-drawers (plist-get parameters
:drawers
))
1257 (outline-regexp "\\*+ ")
1258 target-alist tmp target level
1261 (with-current-buffer (get-buffer-create " org-mode-tmp")
1264 (setq case-fold-search t
)
1266 (run-hooks 'org-export-preprocess-hook
)
1268 ;; Remove license-to-kill stuff
1269 ;; The caller markes some stuff fo killing, stuff that has been
1270 ;; used to create the page title, for example.
1271 (while (setq p
(text-property-any (point-min) (point-max)
1272 :org-license-to-kill t
))
1273 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1275 (let ((org-inhibit-startup t
)) (org-mode))
1276 (setq case-fold-search t
)
1277 (untabify (point-min) (point-max))
1279 ;; Handle incude files
1280 (org-export-handle-include-files)
1282 ;; Handle source code snippets
1283 (org-export-replace-src-segments)
1285 ;; Get rid of drawers
1286 (unless (eq t exp-drawers
)
1287 (goto-char (point-min))
1288 (let ((re (concat "^[ \t]*:\\("
1291 (org-delete-all exp-drawers
1292 (copy-sequence drawers
))
1294 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1295 (while (re-search-forward re nil t
)
1296 (replace-match ""))))
1298 ;; Get the correct stuff before the first headline
1299 (when (plist-get parameters
:skip-before-1st-heading
)
1300 (goto-char (point-min))
1301 (when (re-search-forward "^\\*+[ \t]" nil t
)
1302 (delete-region (point-min) (match-beginning 0))
1303 (goto-char (point-min))
1305 (when (plist-get parameters
:add-text
)
1306 (goto-char (point-min))
1307 (insert (plist-get parameters
:add-text
) "\n"))
1309 ;; Get rid of archived trees
1310 (when (not (eq archived-trees t
))
1311 (goto-char (point-min))
1312 (while (re-search-forward re-archive nil t
)
1313 (if (not (org-on-heading-p t
))
1314 (org-end-of-subtree t
)
1315 (beginning-of-line 1)
1316 (setq a
(if archived-trees
1317 (1+ (point-at-eol)) (point))
1318 b
(org-end-of-subtree t
))
1319 (if (> b a
) (delete-region a b
)))))
1321 ;; Find all headings and compute the targets for them
1322 (goto-char (point-min))
1323 (org-init-section-numbers)
1324 (let ((re (concat "^" org-outline-regexp
)))
1325 (while (re-search-forward re nil t
)
1326 (setq level
(org-reduced-level
1327 (save-excursion (goto-char (point-at-bol))
1328 (org-outline-level))))
1329 (setq target
(org-solidify-link-text
1330 (format "sec-%s" (org-section-number level
))))
1331 (push (cons target target
) target-alist
)
1332 (add-text-properties
1333 (point-at-bol) (point-at-eol)
1334 (list 'target target
))))
1336 ;; Find targets in comments and move them out of comments,
1337 ;; but mark them as targets that should be invisible
1338 (goto-char (point-min))
1339 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1340 ;; Check if the line before or after is a headline with a target
1341 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1342 (get-text-property (point-at-bol 2) 'target
)))
1344 ;; use the existing target in a neighboring line
1345 (setq tmp
(match-string 2))
1347 (and (looking-at "\n") (delete-char 1))
1348 (push (cons (org-solidify-link-text tmp
) target
)
1350 ;; Make an invisible target
1351 (replace-match "\\1(INVISIBLE)")))
1353 ;; Protect backend specific stuff, throw away the others.
1355 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1356 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1357 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1359 (goto-char (point-min))
1360 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1361 (goto-char (match-end 0))
1362 (while (not (looking-at "#\\+END_EXAMPLE"))
1364 (beginning-of-line 2)))
1365 (goto-char (point-min))
1366 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1367 (add-text-properties (match-beginning 0) (match-end 0)
1368 '(org-protected t
)))
1370 (setq fmt
(pop formatters
))
1372 (goto-char (point-min))
1373 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1374 ":[ \t]*\\(.*\\)") nil t
)
1375 (replace-match "\\1" t
)
1376 (add-text-properties
1377 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1378 '(org-protected t
))))
1379 (goto-char (point-min))
1380 (while (re-search-forward
1382 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1383 (cadddr fmt
) "\\>.*\n?") nil t
)
1385 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1387 (delete-region (match-beginning 0) (match-end 0))))))
1389 ;; Protect quoted subtrees
1390 (goto-char (point-min))
1391 (while (re-search-forward re-quote nil t
)
1392 (goto-char (match-beginning 0))
1394 (add-text-properties (point) (org-end-of-subtree t
)
1395 '(org-protected t
)))
1397 ;; Protect verbatim elements
1398 (goto-char (point-min))
1399 (while (re-search-forward org-verbatim-re nil t
)
1400 (add-text-properties (match-beginning 4) (match-end 4)
1402 (goto-char (1+ (match-end 4))))
1405 (goto-char (point-min))
1406 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*" nil t
)
1407 (replace-match (if (equal (downcase (match-string 1)) "end")
1408 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1411 (goto-char (point-min))
1412 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1413 (replace-match (if (equal (downcase (match-string 1)) "end")
1414 "ORG-VERSE-END" "ORG-VERSE-START")
1417 ;; Remove comment environment
1418 (goto-char (point-min))
1419 (while (re-search-forward
1420 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1421 (replace-match "" t t
))
1423 ;; Remove subtrees that are commented
1424 (goto-char (point-min))
1425 (while (re-search-forward re-commented nil t
)
1426 (goto-char (match-beginning 0))
1427 (delete-region (point) (org-end-of-subtree t
)))
1429 ;; Remove special table lines
1430 (when org-export-table-remove-special-lines
1431 (goto-char (point-min))
1432 (while (re-search-forward "^[ \t]*|" nil t
)
1433 (beginning-of-line 1)
1434 (if (or (looking-at "[ \t]*| *[!_^] *|")
1435 (and (looking-at ".*?| *<[0-9]+> *|")
1436 (not (looking-at ".*?| *[^ <|]"))))
1437 (delete-region (max (point-min) (1- (point-at-bol)))
1441 ;; Specific LaTeX stuff
1443 (require 'org-export-latex nil
)
1444 (org-export-latex-preprocess))
1447 (org-export-ascii-clean-string))
1449 ;; Specific HTML stuff
1451 ;; Convert LaTeX fragments to images
1452 (when (plist-get parameters
:LaTeX-fragments
)
1454 (concat "ltxpng/" (file-name-sans-extension
1455 (file-name-nondirectory
1456 org-current-export-file
)))
1457 org-current-export-dir nil
"Creating LaTeX image %s"))
1458 (message "Exporting..."))
1460 ;; Remove or replace comments
1461 (goto-char (point-min))
1462 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1463 (setq pos
(match-beginning 0))
1465 (progn (add-text-properties
1466 (match-beginning 0) (match-end 0) '(org-protected t
))
1467 (replace-match (format commentsp
(match-string 1)) t t
))
1468 (goto-char (1+ pos
))
1471 (goto-char (max (point-min) (1- pos
))))
1474 ;; Find matches for radio targets and turn them into internal links
1475 (goto-char (point-min))
1477 (while (re-search-forward re-radio nil t
)
1479 (replace-match "\\1[[\\2]]"))))
1481 ;; Find all links that contain a newline and put them into a single line
1482 (goto-char (point-min))
1483 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1485 (replace-match "\\1 \\3")
1486 (goto-char (match-beginning 0))))
1488 ;; Find all internal links. If they have a fuzzy match (i.e. not
1489 ;; a *dedicated* target match, let the link point to the
1490 ;; correspinding section.
1492 (goto-char (point-min))
1493 (while (re-search-forward org-bracket-link-regexp nil t
)
1495 (let* ((md (match-data))
1496 (desc (match-end 2))
1497 (link (org-link-unescape (match-string 1)))
1498 (slink (org-solidify-link-text link
))
1501 (or (cdr (assoc slink target-alist
))
1503 (unless (string-match org-link-types-re link
)
1504 (setq found
(condition-case nil
(org-link-search link
)
1507 (or (org-on-heading-p)
1508 (not (eq found
'dedicated
))))
1509 (or (get-text-property (point) 'target
)
1512 (1- (previous-single-property-change
1517 (goto-char (match-beginning 1))
1518 (setq props
(text-properties-at (point)))
1519 (delete-region (match-beginning 1) (match-end 1))
1522 (unless desc
(insert "][" link
))
1523 (add-text-properties pos
(point) props
)))))
1525 ;; Normalize links: Convert angle and plain links into bracket links
1526 ;; Expand link abbreviations
1527 (goto-char (point-min))
1528 (while (re-search-forward re-plain-link nil t
)
1529 (goto-char (1- (match-end 0)))
1531 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1532 ":" (match-string 3) "]]")))
1533 ;; added 'org-link face to links
1534 (put-text-property 0 (length s
) 'face
'org-link s
)
1535 (replace-match s t t
))))
1536 (goto-char (point-min))
1537 (while (re-search-forward re-angle-link nil t
)
1538 (goto-char (1- (match-end 0)))
1540 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1541 ":" (match-string 3) "]]")))
1542 (put-text-property 0 (length s
) 'face
'org-link s
)
1543 (replace-match s t t
))))
1544 (goto-char (point-min))
1545 (while (re-search-forward org-bracket-link-regexp nil t
)
1547 (let* ((s (concat "[[" (setq xx
(save-match-data
1548 (org-link-expand-abbrev (match-string 1))))
1552 (concat "[" xx
"]"))
1554 (put-text-property 0 (length s
) 'face
'org-link s
)
1555 (replace-match s t t
))))
1557 ;; Find multiline emphasis and put them into single line
1558 (when (plist-get parameters
:emph-multiline
)
1559 (goto-char (point-min))
1560 (while (re-search-forward org-emph-re nil t
)
1561 (if (not (= (char-after (match-beginning 3))
1562 (char-after (match-beginning 4))))
1564 (subst-char-in-region (match-beginning 0) (match-end 0)
1566 (goto-char (1- (match-end 0))))
1567 (goto-char (1+ (match-beginning 0))))))
1569 (setq rtn
(buffer-string)))
1570 (kill-buffer " org-mode-tmp")
1573 (defun org-export-grab-title-from-buffer ()
1574 "Get a title for the current document, from looking at the buffer."
1575 (let ((inhibit-read-only t
))
1577 (goto-char (point-min))
1578 (let ((end (save-excursion (outline-next-heading) (point))))
1579 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1580 ;; Mark the line so that it will not be exported as normal text.
1582 (add-text-properties (match-beginning 0) (match-end 0)
1583 (list :org-license-to-kill t
)))
1584 ;; Return the title string
1585 (org-trim (match-string 0)))))))
1587 (defun org-export-get-title-from-subtree ()
1588 "Return subtree title and exclude it from export."
1589 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1592 (when (and (org-at-heading-p)
1593 (>= (org-end-of-subtree t t
) rend
))
1594 ;; This is a subtree, we take the title from the first heading
1596 (looking-at org-todo-line-regexp
)
1597 (setq title
(match-string 3))
1599 (add-text-properties (point) (1+ (point-at-eol))
1600 (list :org-license-to-kill t
)))
1601 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1604 (defun org-solidify-link-text (s &optional alist
)
1605 "Take link text and make a safe target out of it."
1610 (org-split-string s
"[ \t\r\n]+") "=="))
1611 (a (assoc rtn alist
)))
1614 (defun org-get-min-level (lines)
1615 "Get the minimum level in LINES."
1616 (let ((re "^\\(\\*+\\) ") l min
)
1618 (while (setq l
(pop lines
))
1619 (if (string-match re l
)
1620 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1623 ;; Variable holding the vector with section numbers
1624 (defvar org-section-numbers
(make-vector org-level-max
0))
1626 (defun org-init-section-numbers ()
1627 "Initialize the vector for the section numbers."
1629 (numbers (nreverse (org-split-string "" "\\.")))
1630 (depth (1- (length org-section-numbers
)))
1631 (i depth
) number-string
)
1634 (aset org-section-numbers i
0)
1635 (setq number-string
(or (car numbers
) "0"))
1636 (if (string-match "\\`[A-Z]\\'" number-string
)
1637 (aset org-section-numbers i
1638 (- (string-to-char number-string
) ?A -
1))
1639 (aset org-section-numbers i
(string-to-number number-string
)))
1643 (defun org-section-number (&optional level
)
1644 "Return a string with the current section number.
1645 When LEVEL is non-nil, increase section numbers on that level."
1646 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1649 (aset org-section-numbers
1650 level
(1+ (aref org-section-numbers level
))))
1651 (setq idx
(1+ level
))
1652 (while (<= idx depth
)
1654 (aset org-section-numbers idx
0))
1655 (setq idx
(1+ idx
))))
1657 (while (<= idx depth
)
1658 (setq n
(aref org-section-numbers idx
))
1659 (setq string
(concat string
(if (not (string= string
"")) "." "")
1661 (setq idx
(1+ idx
)))
1663 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1664 (setq string
(replace-match "" t nil string
)))
1665 (if (string-match "\\(\\.0\\)+\\'" string
)
1666 (setq string
(replace-match "" t nil string
))))
1671 (defun org-export-handle-include-files ()
1672 "Include the contents of include files, with proper formatting."
1673 (let ((case-fold-search t
)
1674 params file markup lang start end
)
1675 (goto-char (point-min))
1676 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1677 (setq params
(read (concat "(" (match-string 1) ")"))
1678 file
(org-symname-or-string (pop params
))
1679 markup
(org-symname-or-string (pop params
))
1680 lang
(org-symname-or-string (pop params
)))
1681 (delete-region (match-beginning 0) (match-end 0))
1683 (not (file-exists-p file
))
1684 (not (file-readable-p file
)))
1685 (insert (format "CANNOT INCLUDE FILE %s" file
))
1687 (if (equal (downcase markup
) "src")
1688 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1690 (setq start
(format "#+begin_%s\n" markup
)
1691 end
(format "#+end_%s" markup
))))
1692 (insert (or start
""))
1693 (forward-char (nth 1 (insert-file-contents (expand-file-name file
))))
1694 (or (bolp) (newline))
1695 (insert (or end
""))))))
1697 (defun org-symname-or-string (s)
1699 (if s
(symbol-name s
) s
)
1702 ;;; Fontification of code
1703 ;; Currently only for th HTML backend, but who knows....
1704 (defun org-export-replace-src-segments ()
1705 "Replace source code segments with special code for export."
1706 (let ((case-fold-search t
)
1708 (goto-char (point-min))
1709 (while (re-search-forward
1710 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1712 (setq lang
(match-string 1) code
(match-string 2)
1713 trans
(org-export-format-source-code lang code
))
1714 (replace-match trans t t
))))
1716 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1718 (defun org-export-format-source-code (lang code
)
1719 "Format CODE from language LANG and return it formatted for export.
1720 Currently, this only does something for HTML export, for all other
1721 backends, it converts the segment into an EXAMPLE segment."
1725 ;; We are exporting to HTML
1726 (condition-case nil
(require 'htmlize
) (nil t
))
1727 (if (not (fboundp 'htmlize-region-for-paste
))
1729 ;; we do not have htmlize.el, or an old version of it
1731 "htmlize.el 1.34 or later is needed for source code formatting")
1732 (concat "#+BEGIN_EXAMPLE\n" code
1733 (if (string-match "\n\\'" code
) "" "\n")
1735 ;; ok, we are good to go
1736 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1737 (org-inhibit-startup t
)
1738 (org-startup-folded nil
)
1742 ;; Free up the protected stuff
1743 (goto-char (point-min))
1744 (while (re-search-forward "^," nil t
)
1747 (if (functionp mode
)
1750 (font-lock-fontify-buffer)
1751 (org-export-htmlize-region-for-paste
1752 (point-min) (point-max)))))
1753 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1754 (setq htmltext
(replace-match "<pre class=\"src\">"
1756 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1758 ;; This is not HTML, so just make it an example.
1759 (when (equal lang
"org")
1760 (while (string-match "^," code
)
1761 (setq code
(replace-match "" t t code
))))
1762 (concat "#+BEGIN_EXAMPLE\n" code
1763 (if (string-match "\n\\'" code
) "" "\n")
1764 "#+END_EXAMPLE\n")))))
1768 (defvar org-last-level nil
) ; dynamically scoped variable
1769 (defvar org-min-level nil
) ; dynamically scoped variable
1770 (defvar org-levels-open nil
) ; dynamically scoped parameter
1771 (defvar org-ascii-current-indentation nil
) ; For communication
1774 (defun org-export-as-ascii (arg)
1775 "Export the outline as a pretty ASCII file.
1776 If there is an active region, export only the region.
1777 The prefix ARG specifies how many levels of the outline should become
1778 underlined headlines. The default is 3."
1780 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1781 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1782 (org-infile-export-plist)))
1783 (region-p (org-region-active-p))
1784 (rbeg (and region-p
(region-beginning)))
1785 (rend (and region-p
(region-end)))
1790 (and (org-at-heading-p)
1791 (>= (org-end-of-subtree t t
) rend
)))))
1792 (opt-plist (if subtree-p
1793 (org-export-add-subtree-options opt-plist rbeg
)
1795 (custom-times org-display-custom-times
)
1796 (org-ascii-current-indentation '(0 .
0))
1800 (case-fold-search nil
)
1801 (filename (concat (file-name-as-directory
1802 (org-export-directory :ascii opt-plist
))
1803 (file-name-sans-extension
1805 (org-entry-get (region-beginning)
1806 "EXPORT_FILE_NAME" t
))
1807 (file-name-nondirectory buffer-file-name
)))
1809 (filename (if (equal (file-truename filename
)
1810 (file-truename buffer-file-name
))
1811 (concat filename
".txt")
1813 (buffer (find-file-noselect filename
))
1814 (org-levels-open (make-vector org-level-max nil
))
1815 (odd org-odd-levels-only
)
1816 (date (plist-get opt-plist
:date
))
1817 (author (plist-get opt-plist
:author
))
1818 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1819 (plist-get opt-plist
:title
)
1821 (plist-get opt-plist
:skip-before-1st-heading
))
1822 (org-export-grab-title-from-buffer))
1823 (file-name-sans-extension
1824 (file-name-nondirectory buffer-file-name
))))
1825 (email (plist-get opt-plist
:email
))
1826 (language (plist-get opt-plist
:language
))
1827 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1828 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1833 (if (org-region-active-p) (region-beginning) (point-min))
1834 (if (org-region-active-p) (region-end) (point-max))))
1835 (lines (org-split-string
1836 (org-export-preprocess-string
1839 :skip-before-1st-heading
1840 (plist-get opt-plist
:skip-before-1st-heading
)
1841 :drawers
(plist-get opt-plist
:drawers
)
1842 :verbatim-multiline t
1844 (plist-get opt-plist
:archived-trees
)
1845 :add-text
(plist-get opt-plist
:text
))
1847 thetoc have-headings first-heading-pos
1848 table-open table-buffer
)
1850 (let ((inhibit-read-only t
))
1852 (remove-text-properties (point-min) (point-max)
1853 '(:org-license-to-kill t
))))
1855 (setq org-min-level
(org-get-min-level lines
))
1856 (setq org-last-level org-min-level
)
1857 (org-init-section-numbers)
1859 (find-file-noselect filename
)
1861 (setq lang-words
(or (assoc language org-export-language-setup
)
1862 (assoc "en" org-export-language-setup
)))
1863 (switch-to-buffer-other-window buffer
)
1866 ;; create local variables for all options, to make sure all called
1867 ;; functions get the correct information
1869 (set (make-local-variable (cdr x
))
1870 (plist-get opt-plist
(car x
))))
1871 org-export-plist-vars
)
1872 (org-set-local 'org-odd-levels-only odd
)
1873 (setq umax
(if arg
(prefix-numeric-value arg
)
1874 org-export-headline-levels
))
1875 (setq umax-toc
(if (integerp org-export-with-toc
)
1876 (min org-export-with-toc umax
)
1880 (if title
(org-insert-centered title ?
=))
1882 (if (and (or author email
)
1883 org-export-author-info
)
1884 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1885 (if email
(concat " <" email
">") "")
1889 ((and date
(string-match "%" date
))
1890 (setq date
(format-time-string date
)))
1892 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1894 (if (and date org-export-time-stamp-file
)
1895 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1899 (if org-export-with-toc
1901 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1902 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1903 (mapc '(lambda (line)
1904 (if (string-match org-todo-line-regexp
1906 ;; This is a headline
1908 (setq have-headings t
)
1909 (setq level
(- (match-end 1) (match-beginning 1))
1910 level
(org-tr-level level
)
1911 txt
(match-string 3 line
)
1913 (or (and org-export-mark-todo-in-toc
1915 (not (member (match-string 2 line
)
1916 org-done-keywords
)))
1918 (and org-export-mark-todo-in-toc
1920 (org-search-todo-below
1921 line lines level
))))
1922 (setq txt
(org-html-expand-for-ascii txt
))
1924 (while (string-match org-bracket-link-regexp txt
)
1927 (match-string (if (match-end 2) 3 1) txt
)
1930 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1932 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1934 (setq txt
(replace-match "" t t txt
)))
1935 (if (string-match quote-re0 txt
)
1936 (setq txt
(replace-match "" t t txt
)))
1938 (if org-export-with-section-numbers
1939 (setq txt
(concat (org-section-number level
)
1941 (if (<= level umax-toc
)
1946 (* (max 0 (- level org-min-level
)) 4) ?\
)
1947 (format (if todo
"%s (*)\n" "%s\n") txt
))
1949 (setq org-last-level level
))
1952 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1954 (org-init-section-numbers)
1955 (while (setq line
(pop lines
))
1956 ;; Remove the quoted HTML tags.
1957 (setq line
(org-html-expand-for-ascii line
))
1959 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1960 (setq line
(replace-match "" t t line
)))
1961 ;; Replace internal links
1962 (while (string-match org-bracket-link-regexp line
)
1963 (setq line
(replace-match
1964 (if (match-end 3) "[\\3]" "[\\1]")
1967 (setq line
(org-translate-time line
)))
1969 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1971 (setq first-heading-pos
(or first-heading-pos
(point)))
1972 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1973 txt
(match-string 2 line
))
1974 (org-ascii-level-start level txt umax lines
))
1976 ((and org-export-with-tables
1977 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1978 (if (not table-open
)
1980 (setq table-open t table-buffer nil
))
1982 (setq table-buffer
(cons line table-buffer
))
1983 (when (or (not lines
)
1984 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1986 (setq table-open nil
1987 table-buffer
(nreverse table-buffer
))
1990 (org-fix-indentation x org-ascii-current-indentation
))
1991 (org-format-table-ascii table-buffer
)
1994 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1995 (if (and org-export-with-fixed-width
1996 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1997 (setq line
(replace-match "\\1" nil nil line
)))
1998 (insert line
"\n"))))
2002 ;; insert the table of contents
2004 (goto-char (point-min))
2005 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2007 (goto-char (match-beginning 0))
2009 (goto-char first-heading-pos
))
2010 (mapc 'insert thetoc
)
2011 (or (looking-at "[ \t]*\n[ \t]*\n")
2014 ;; Convert whitespace place holders
2015 (goto-char (point-min))
2017 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2018 (setq end
(next-single-property-change beg
'org-whitespace
))
2020 (delete-region beg end
)
2021 (insert (make-string (- end beg
) ?\
))))
2024 ;; remove display and invisible chars
2026 (goto-char (point-min))
2027 (while (setq beg
(next-single-property-change (point) 'display
))
2028 (setq end
(next-single-property-change beg
'display
))
2029 (delete-region beg end
)
2032 (goto-char (point-min))
2033 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2034 (setq end
(next-single-property-change beg
'org-cwidth
))
2035 (delete-region beg end
)
2037 (goto-char (point-min))))
2039 (defun org-export-ascii-clean-string ()
2040 "Do extra work for ASCII export"
2041 (goto-char (point-min))
2042 (while (re-search-forward org-verbatim-re nil t
)
2043 (goto-char (match-end 2))
2044 (backward-delete-char 1) (insert "'")
2045 (goto-char (match-beginning 2))
2046 (delete-char 1) (insert "`")
2047 (goto-char (match-end 2))))
2049 (defun org-search-todo-below (line lines level
)
2050 "Search the subtree below LINE for any TODO entries."
2051 (let ((rest (cdr (memq line lines
)))
2052 (re org-todo-line-regexp
)
2055 (while (setq line
(pop rest
))
2056 (if (string-match re line
)
2058 (setq lv
(- (match-end 1) (match-beginning 1))
2059 todo
(and (match-beginning 2)
2060 (not (member (match-string 2 line
)
2061 org-done-keywords
))))
2063 (if (<= lv level
) (throw 'exit nil
))
2064 (if todo
(throw 'exit t
))))))))
2066 (defun org-html-expand-for-ascii (line)
2067 "Handle quoted HTML for ASCII export."
2068 (if org-export-html-expand
2069 (while (string-match "@<[^<>\n]*>" line
)
2070 ;; We just remove the tags for now.
2071 (setq line
(replace-match "" nil nil line
))))
2074 (defun org-insert-centered (s &optional underline
)
2075 "Insert the string S centered and underline it with character UNDERLINE."
2076 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
2077 (insert (make-string ind ?\
) s
"\n")
2079 (insert (make-string ind ?\
)
2080 (make-string (string-width s
) underline
)
2083 (defun org-ascii-level-start (level title umax
&optional lines
)
2084 "Insert a new level in ASCII export."
2085 (let (char (n (- level umax
1)) (ind 0))
2088 (insert (make-string (* 2 n
) ?\
)
2089 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2090 org-export-ascii-bullets
))
2092 ;; find the indentation of the next non-empty line
2095 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2096 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2097 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2099 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2100 (if (or (not (equal (char-before) ?
\n))
2101 (not (equal (char-before (1- (point))) ?
\n)))
2103 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2104 (unless org-export-with-tags
2105 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2106 (setq title
(replace-match "" t t title
))))
2107 (if org-export-with-section-numbers
2108 (setq title
(concat (org-section-number level
) " " title
)))
2109 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2110 (setq org-ascii-current-indentation
'(0 .
0)))))
2113 (defun org-export-visible (type arg
)
2114 "Create a copy of the visible part of the current buffer, and export it.
2115 The copy is created in a temporary buffer and removed after use.
2116 TYPE is the final key (as a string) that also select the export command in
2117 the `C-c C-e' export dispatcher.
2118 As a special case, if the you type SPC at the prompt, the temporary
2119 org-mode file will not be removed but presented to you so that you can
2120 continue to use it. The prefix arg ARG is passed through to the exporting
2124 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2125 (read-char-exclusive))
2126 current-prefix-arg
))
2127 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2128 (error "Invalid export key"))
2129 (let* ((binding (cdr (assoc type
2130 '((?a . org-export-as-ascii
)
2131 (?\C-a . org-export-as-ascii
)
2132 (?b . org-export-as-html-and-open
)
2133 (?\C-b . org-export-as-html-and-open
)
2134 (?h . org-export-as-html
)
2135 (?H . org-export-as-html-to-buffer
)
2136 (?R . org-export-region-as-html
)
2137 (?x . org-export-as-xoxo
)))))
2138 (keepp (equal type ?\
))
2139 (file buffer-file-name
)
2140 (buffer (get-buffer-create "*Org Export Visible*"))
2142 ;; Need to hack the drawers here.
2144 (goto-char (point-min))
2145 (while (re-search-forward org-drawer-regexp nil t
)
2146 (goto-char (match-beginning 1))
2147 (or (org-invisible-p) (org-flag-drawer nil
))))
2148 (with-current-buffer buffer
(erase-buffer))
2150 (setq s
(goto-char (point-min)))
2151 (while (not (= (point) (point-max)))
2152 (goto-char (org-find-invisible))
2153 (append-to-buffer buffer s
(point))
2154 (setq s
(goto-char (org-find-visible))))
2155 (org-cycle-hide-drawers 'all
)
2156 (goto-char (point-min))
2158 ;; Copy all comment lines to the end, to make sure #+ settings are
2159 ;; still available for the second export step. Kind of a hack, but
2160 ;; does do the trick.
2161 (if (looking-at "#[^\r\n]*")
2162 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2163 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2164 (append-to-buffer buffer
(1+ (match-beginning 0))
2165 (min (point-max) (1+ (match-end 0))))))
2167 (let ((buffer-file-name file
)
2168 (org-inhibit-startup t
))
2171 (unless keepp
(funcall binding arg
))))
2173 (kill-buffer buffer
)
2174 (switch-to-buffer-other-window buffer
)
2175 (goto-char (point-min)))))
2177 (defun org-find-visible ()
2179 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2180 (get-char-property s
'invisible
)))
2182 (defun org-find-invisible ()
2184 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2185 (not (get-char-property s
'invisible
))))
2190 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2191 (defun org-get-current-options ()
2192 "Return a string with current options as keyword options.
2193 Does include HTML export options as well as TODO and CATEGORY stuff."
2194 (require 'org-archive
)
2201 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2202 #+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
2209 #+PRIORITIES: %c %c %c
2211 #+STARTUP: %s %s %s %s %s
2216 (buffer-name) (user-full-name) user-mail-address
2217 (format-time-string (car org-time-stamp-formats
))
2218 org-export-default-language
2219 org-export-headline-levels
2220 org-export-with-section-numbers
2222 org-export-preserve-breaks
2223 org-export-html-expand
2224 org-export-with-fixed-width
2225 org-export-with-tables
2226 org-export-with-sub-superscripts
2227 org-export-with-special-strings
2228 org-export-with-footnotes
2229 org-export-with-emphasize
2230 org-export-with-TeX-macros
2231 org-export-with-LaTeX-fragments
2232 org-export-skip-text-before-1st-heading
2233 org-export-with-drawers
2234 org-export-with-tags
2235 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2236 org-export-html-link-up
2237 org-export-html-link-home
2238 (file-name-nondirectory buffer-file-name
)
2239 "TODO FEEDBACK VERIFY DONE"
2240 "Me Jason Marie DONE"
2241 org-highest-priority org-lowest-priority org-default-priority
2242 (mapconcat 'identity org-drawers
" ")
2243 (cdr (assoc org-startup-folded
2244 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2245 (if org-odd-levels-only
"odd" "oddeven")
2246 (if org-hide-leading-stars
"hidestars" "showstars")
2247 (if org-startup-align-all-tables
"align" "noalign")
2248 (cond ((eq org-log-done t
) "logdone")
2249 ((equal org-log-done
'note
) "lognotedone")
2250 ((not org-log-done
) "nologdone"))
2251 (or (mapconcat (lambda (x)
2253 ((equal '(:startgroup
) x
) "{")
2254 ((equal '(:endgroup
) x
) "}")
2255 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2257 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2258 org-archive-location
2259 "org file:~/org/%s.org"
2263 (defun org-insert-export-options-template ()
2264 "Insert into the buffer a template with information for exporting."
2266 (if (not (bolp)) (newline))
2267 (let ((s (org-get-current-options)))
2268 (and (string-match "#\\+CATEGORY" s
)
2269 (setq s
(substring s
0 (match-beginning 0))))
2273 (defun org-export-as-html-and-open (arg)
2274 "Export the outline as HTML and immediately open it with a browser.
2275 If there is an active region, export only the region.
2276 The prefix ARG specifies how many levels of the outline should become
2277 headlines. The default is 3. Lower levels will become bulleted lists."
2279 (org-export-as-html arg
'hidden
)
2280 (org-open-file buffer-file-name
))
2283 (defun org-export-as-html-batch ()
2284 "Call `org-export-as-html', may be used in batch processing as
2286 --load=$HOME/lib/emacs/org.el
2287 --eval \"(setq org-export-headline-levels 2)\"
2288 --visit=MyFile --funcall org-export-as-html-batch"
2289 (org-export-as-html org-export-headline-levels
'hidden
))
2292 (defun org-export-as-html-to-buffer (arg)
2293 "Call `org-exort-as-html` with output to a temporary buffer.
2294 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2296 (org-export-as-html arg nil nil
"*Org HTML Export*")
2297 (switch-to-buffer-other-window "*Org HTML Export*"))
2300 (defun org-replace-region-by-html (beg end
)
2301 "Assume the current region has org-mode syntax, and convert it to HTML.
2302 This can be used in any buffer. For example, you could write an
2303 itemized list in org-mode syntax in an HTML buffer and then use this
2304 command to convert it."
2306 (let (reg html buf pop-up-frames
)
2307 (save-window-excursion
2309 (setq html
(org-export-region-as-html
2311 (setq reg
(buffer-substring beg end
)
2312 buf
(get-buffer-create "*Org tmp*"))
2313 (with-current-buffer buf
2317 (setq html
(org-export-region-as-html
2318 (point-min) (point-max) t
'string
)))
2320 (delete-region beg end
)
2324 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2325 "Convert region from BEG to END in org-mode buffer to HTML.
2326 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2327 contents, and only produce the region of converted text, useful for
2328 cut-and-paste operations.
2329 If BUFFER is a buffer or a string, use/create that buffer as a target
2330 of the converted HTML. If BUFFER is the symbol `string', return the
2331 produced HTML as a string and leave not buffer behind. For example,
2332 a Lisp program could call this function in the following way:
2334 (setq html (org-export-region-as-html beg end t 'string))
2336 When called interactively, the output buffer is selected, and shown
2337 in a window. A non-interactive call will only return the buffer."
2338 (interactive "r\nP")
2339 (when (interactive-p)
2340 (setq buffer
"*Org HTML Export*"))
2341 (let ((transient-mark-mode t
) (zmacs-regions t
)
2344 (set-mark (point)) ;; to activate the region
2346 (setq rtn
(org-export-as-html
2349 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2350 (if (and (interactive-p) (bufferp rtn
))
2351 (switch-to-buffer-other-window rtn
)
2354 (defvar html-table-tag nil
) ; dynamically scoped into this.
2356 (defun org-export-as-html (arg &optional hidden ext-plist
2357 to-buffer body-only pub-dir
)
2358 "Export the outline as a pretty HTML file.
2359 If there is an active region, export only the region. The prefix
2360 ARG specifies how many levels of the outline should become
2361 headlines. The default is 3. Lower levels will become bulleted
2362 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2363 EXT-PLIST is a property list with external parameters overriding
2364 org-mode's default settings, but still inferior to file-local
2365 settings. When TO-BUFFER is non-nil, create a buffer with that
2366 name and export to that buffer. If TO-BUFFER is the symbol
2367 `string', don't leave any buffer behind but just return the
2368 resulting HTML as a string. When BODY-ONLY is set, don't produce
2369 the file header and footer, simply return the content of
2370 <body>...</body>, without even the body tags themselves. When
2371 PUB-DIR is set, use this as the publishing directory."
2374 ;; Make sure we have a file name when we need it.
2375 (when (and (not (or to-buffer body-only
))
2376 (not buffer-file-name
))
2377 (if (buffer-base-buffer)
2378 (org-set-local 'buffer-file-name
2379 (with-current-buffer (buffer-base-buffer)
2381 (error "Need a file name to be able to export.")))
2383 (message "Exporting...")
2384 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2385 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2386 (setq-default org-done-keywords org-done-keywords
)
2387 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2389 (org-export-process-option-filters
2390 (org-combine-plists (org-default-export-plist)
2392 (org-infile-export-plist))))
2394 (style (plist-get opt-plist
:style
))
2395 (html-extension (plist-get opt-plist
:html-extension
))
2396 (link-validate (plist-get opt-plist
:link-validation-function
))
2397 valid thetoc have-headings first-heading-pos
2398 (odd org-odd-levels-only
)
2399 (region-p (org-region-active-p))
2400 (rbeg (and region-p
(region-beginning)))
2401 (rend (and region-p
(region-end)))
2406 (and (org-at-heading-p)
2407 (>= (org-end-of-subtree t t
) rend
)))))
2408 (opt-plist (if subtree-p
2409 (org-export-add-subtree-options opt-plist rbeg
)
2411 ;; The following two are dynamically scoped into other
2413 (org-current-export-dir
2414 (or pub-dir
(org-export-directory :html opt-plist
)))
2415 (org-current-export-file buffer-file-name
)
2416 (level 0) (line "") (origline "") txt todo
2419 (filename (if to-buffer nil
2422 (file-name-sans-extension
2424 (org-entry-get (region-beginning)
2425 "EXPORT_FILE_NAME" t
))
2426 (file-name-nondirectory buffer-file-name
)))
2428 (file-name-as-directory
2429 (or pub-dir
(org-export-directory :html opt-plist
))))))
2430 (current-dir (if buffer-file-name
2431 (file-name-directory buffer-file-name
)
2433 (buffer (if to-buffer
2435 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2436 (t (get-buffer-create to-buffer
)))
2437 (find-file-noselect filename
)))
2438 (org-levels-open (make-vector org-level-max nil
))
2439 (date (plist-get opt-plist
:date
))
2440 (author (plist-get opt-plist
:author
))
2441 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2442 (plist-get opt-plist
:title
)
2444 (plist-get opt-plist
:skip-before-1st-heading
))
2445 (org-export-grab-title-from-buffer))
2446 (and buffer-file-name
2447 (file-name-sans-extension
2448 (file-name-nondirectory buffer-file-name
)))
2450 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2451 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2452 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2456 (local-list-type nil
)
2457 (local-list-indent nil
)
2458 (llt org-plain-list-ordered-item-terminator
)
2459 (email (plist-get opt-plist
:email
))
2460 (language (plist-get opt-plist
:language
))
2464 (coding-system (and (boundp 'buffer-file-coding-system
)
2465 buffer-file-coding-system
))
2466 (coding-system-for-write (or org-export-html-coding-system
2468 (save-buffer-coding-system (or org-export-html-coding-system
2470 (charset (and coding-system-for-write
2471 (fboundp 'coding-system-get
)
2472 (coding-system-get coding-system-for-write
2476 (if region-p
(region-beginning) (point-min))
2477 (if region-p
(region-end) (point-max))))
2480 (org-export-preprocess-string
2484 :skip-before-1st-heading
2485 (plist-get opt-plist
:skip-before-1st-heading
)
2486 :drawers
(plist-get opt-plist
:drawers
)
2488 (plist-get opt-plist
:archived-trees
)
2490 (plist-get opt-plist
:text
)
2492 (plist-get opt-plist
:LaTeX-fragments
))
2495 table-buffer table-orig-buffer
2496 ind item-type starter didclose
2497 rpl path desc descp desc1 desc2 link
2498 snumber fnc item-tag
2501 (let ((inhibit-read-only t
))
2503 (remove-text-properties (point-min) (point-max)
2504 '(:org-license-to-kill t
))))
2506 (message "Exporting...")
2508 (setq org-min-level
(org-get-min-level lines
))
2509 (setq org-last-level org-min-level
)
2510 (org-init-section-numbers)
2513 ((and date
(string-match "%" date
))
2514 (setq date
(format-time-string date
)))
2516 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2518 ;; Get the language-dependent settings
2519 (setq lang-words
(or (assoc language org-export-language-setup
)
2520 (assoc "en" org-export-language-setup
)))
2522 ;; Switch to the output buffer
2524 (let ((inhibit-read-only t
)) (erase-buffer))
2527 (and (fboundp 'set-buffer-file-coding-system
)
2528 (set-buffer-file-coding-system coding-system-for-write
))
2530 (let ((case-fold-search nil
)
2531 (org-odd-levels-only odd
))
2532 ;; create local variables for all options, to make sure all called
2533 ;; functions get the correct information
2535 (set (make-local-variable (cdr x
))
2536 (plist-get opt-plist
(car x
))))
2537 org-export-plist-vars
)
2538 (setq umax
(if arg
(prefix-numeric-value arg
)
2539 org-export-headline-levels
))
2540 (setq umax-toc
(if (integerp org-export-with-toc
)
2541 (min org-export-with-toc umax
)
2546 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2547 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2548 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2549 lang=\"%s\" xml:lang=\"%s\">
2552 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2553 <meta name=\"generator\" content=\"Org-mode\"/>
2554 <meta name=\"generated\" content=\"%s\"/>
2555 <meta name=\"author\" content=\"%s\"/>
2559 language language
(org-html-expand title
)
2560 (or charset
"iso-8859-1") date author style
))
2562 (insert (or (plist-get opt-plist
:preamble
) ""))
2564 (when (plist-get opt-plist
:auto-preamble
)
2565 (if title
(insert (format org-export-html-title-format
2566 (org-html-expand title
))))))
2568 (if (and org-export-with-toc
(not body-only
))
2570 (push (format "<h%d>%s</h%d>\n"
2571 org-export-html-toplevel-hlevel
2573 org-export-html-toplevel-hlevel
)
2575 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2576 (push "<ul>\n<li>" thetoc
)
2578 (mapcar '(lambda (line)
2579 (if (string-match org-todo-line-regexp line
)
2580 ;; This is a headline
2582 (setq have-headings t
)
2583 (setq level
(- (match-end 1) (match-beginning 1))
2584 level
(org-tr-level level
)
2585 txt
(save-match-data
2587 (org-export-cleanup-toc-line
2588 (match-string 3 line
))))
2590 (or (and org-export-mark-todo-in-toc
2592 (not (member (match-string 2 line
)
2593 org-done-keywords
)))
2595 (and org-export-mark-todo-in-toc
2597 (org-search-todo-below
2598 line lines level
))))
2600 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2601 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2602 (if (string-match quote-re0 txt
)
2603 (setq txt
(replace-match "" t t txt
)))
2604 (setq snumber
(org-section-number level
))
2605 (if org-export-with-section-numbers
2606 (setq txt
(concat snumber
" " txt
)))
2607 (if (<= level
(max umax umax-toc
))
2608 (setq head-count
(+ head-count
1)))
2609 (if (<= level umax-toc
)
2611 (if (> level org-last-level
)
2613 (setq cnt
(- level org-last-level
))
2614 (while (>= (setq cnt
(1- cnt
)) 0)
2615 (push "\n<ul>\n<li>" thetoc
))
2616 (push "\n" thetoc
)))
2617 (if (< level org-last-level
)
2619 (setq cnt
(- org-last-level level
))
2620 (while (>= (setq cnt
(1- cnt
)) 0)
2621 (push "</li>\n</ul>" thetoc
))
2622 (push "\n" thetoc
)))
2623 ;; Check for targets
2624 (while (string-match org-any-target-regexp line
)
2625 (setq line
(replace-match
2626 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2628 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2629 (setq txt
(replace-match "" t t txt
)))
2633 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2634 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2635 snumber txt
) thetoc
)
2637 (setq org-last-level level
))
2641 (while (> org-last-level
(1- org-min-level
))
2642 (setq org-last-level
(1- org-last-level
))
2643 (push "</li>\n</ul>\n" thetoc
))
2644 (push "</div>\n" thetoc
)
2645 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2648 (org-init-section-numbers)
2650 (while (setq line
(pop lines
) origline line
)
2653 ;; end of quote section?
2654 (when (and inquote
(string-match "^\\*+ " line
))
2657 ;; inside a quote section?
2659 (insert (org-html-protect line
) "\n")
2660 (throw 'nextline nil
))
2663 (when (and org-export-with-fixed-width
2664 (string-match "^[ \t]*:\\(.*\\)" line
))
2668 (insert (org-html-protect (match-string 1 line
)) "\n")
2670 (not (string-match "^[ \t]*\\(:.*\\)"
2673 (insert "</pre>\n"))
2674 (throw 'nextline nil
))
2677 (when (get-text-property 0 'org-protected line
)
2679 (when (re-search-backward
2680 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2681 (setq par
(match-string 1))
2682 (replace-match "\\2\n"))
2685 (not (string-match "^[ \t]*:" (car lines
)))
2686 (or (= (length (car lines
)) 0)
2687 (get-text-property 0 'org-protected
(car lines
))))
2688 (insert (pop lines
) "\n"))
2689 (and par
(insert "<p>\n")))
2690 (throw 'nextline nil
))
2693 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2694 (insert "\n<hr/>\n")
2695 (throw 'nextline nil
))
2697 ;; Blockquotes and verse
2698 (when (equal "ORG-BLOCKQUOTE-START" line
)
2699 (insert "<blockquote>\n<p>\n")
2700 (throw 'nextline nil
))
2701 (when (equal "ORG-BLOCKQUOTE-END" line
)
2702 (insert "</p>\n</blockquote>\n")
2703 (throw 'nextline nil
))
2704 (when (equal "ORG-VERSE-START" line
)
2705 (insert "<verse>\n<p>\n")
2706 (throw 'nextline nil
))
2707 (when (equal "ORG-VERSE-END" line
)
2708 (insert "</p>\n</verse>\n")
2709 (throw 'nextline nil
))
2711 ;; make targets to anchors
2712 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2715 (setq line
(replace-match
2716 (concat "@<a name=\""
2717 (org-solidify-link-text (match-string 1 line
))
2720 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2721 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2722 (setq line
(replace-match
2723 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2724 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2727 (setq line
(replace-match
2728 (concat "@<a name=\""
2729 (org-solidify-link-text (match-string 1 line
))
2730 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2733 (setq line
(org-html-handle-time-stamps line
))
2735 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2736 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2737 ;; Also handle sub_superscripts and checkboxes
2738 (or (string-match org-table-hline-regexp line
)
2739 (setq line
(org-html-expand line
)))
2743 (while (string-match org-bracket-link-analytic-regexp line start
)
2744 (setq start
(match-beginning 0))
2745 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2746 (setq path
(match-string 3 line
))
2747 (setq desc1
(if (match-end 5) (match-string 5 line
))
2748 desc2
(if (match-end 2) (concat type
":" path
) path
)
2749 descp
(and desc1
(not (equal desc1 desc2
)))
2750 desc
(or desc1 desc2
))
2751 ;; Make an image out of the description if that is so wanted
2752 (when (and descp
(org-file-image-p desc
))
2754 (if (string-match "^file:" desc
)
2755 (setq desc
(substring desc
(match-end 0)))))
2756 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2757 ;; FIXME: do we need to unescape here somewhere?
2759 ((equal type
"internal")
2763 (org-solidify-link-text
2764 (save-match-data (org-link-unescape path
)) nil
)
2765 "\">" desc
"</a>")))
2766 ((member type
'("http" "https"))
2767 ;; standard URL, just check if we need to inline an image
2768 (if (and (or (eq t org-export-html-inline-images
)
2769 (and org-export-html-inline-images
(not descp
)))
2770 (org-file-image-p path
))
2771 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2772 (setq link
(concat type
":" path
))
2773 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2774 ((member type
'("ftp" "mailto" "news"))
2776 (setq link
(concat type
":" path
))
2777 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2778 ((string= type
"file")
2780 (let* ((filename path
)
2781 (abs-p (file-name-absolute-p filename
))
2782 thefile file-is-image-p search
)
2784 (if (string-match "::\\(.*\\)" filename
)
2785 (setq search
(match-string 1 filename
)
2786 filename
(replace-match "" t nil filename
)))
2788 (if (functionp link-validate
)
2789 (funcall link-validate filename current-dir
)
2791 (setq file-is-image-p
(org-file-image-p filename
))
2792 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2793 (when (and org-export-html-link-org-files-as-html
2794 (string-match "\\.org$" thefile
))
2795 (setq thefile
(concat (substring thefile
0
2796 (match-beginning 0))
2797 "." html-extension
))
2799 ;; make sure this is can be used as target search
2800 (not (string-match "^[0-9]*$" search
))
2801 (not (string-match "^\\*" search
))
2802 (not (string-match "^/.*/$" search
)))
2803 (setq thefile
(concat thefile
"#"
2804 (org-solidify-link-text
2805 (org-link-unescape search
)))))
2806 (when (string-match "^file:" desc
)
2807 (setq desc
(replace-match "" t t desc
))
2808 (if (string-match "\\.org$" desc
)
2809 (setq desc
(replace-match "" t t desc
))))))
2810 (setq rpl
(if (and file-is-image-p
2811 (or (eq t org-export-html-inline-images
)
2812 (and org-export-html-inline-images
2814 (concat "<img src=\"" thefile
"\"/>")
2815 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2816 (if (not valid
) (setq rpl desc
))))
2818 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2821 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2824 ;; just publish the path, as default
2825 (setq rpl
(concat "<i><" type
":"
2826 (save-match-data (org-link-unescape path
))
2828 (setq line
(replace-match rpl t t line
)
2829 start
(+ start
(length rpl
))))
2832 (if (and (string-match org-todo-line-regexp line
)
2833 (match-beginning 2))
2836 (concat (substring line
0 (match-beginning 2))
2838 (if (member (match-string 2 line
)
2841 "\">" (match-string 2 line
)
2842 "</span>" (substring line
(match-end 2)))))
2844 ;; Does this contain a reference to a footnote?
2845 (when org-export-with-footnotes
2847 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2848 (if (get-text-property (match-beginning 2) 'org-protected line
)
2849 (setq start
(match-end 2))
2850 (let ((n (match-string 2 line
)))
2854 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2855 (match-string 1 line
) n n n
)
2859 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2860 ;; This is a headline
2861 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2862 txt
(match-string 2 line
))
2863 (if (string-match quote-re0 txt
)
2864 (setq txt
(replace-match "" t t txt
)))
2865 (if (<= level
(max umax umax-toc
))
2866 (setq head-count
(+ head-count
1)))
2868 ;; Close any local lists before inserting a new header line
2869 (while local-list-type
2870 (org-close-li (car local-list-type
))
2871 (insert (format "</%sl>\n" (car local-list-type
)))
2872 (pop local-list-type
))
2873 (setq local-list-indent nil
2875 (setq first-heading-pos
(or first-heading-pos
(point)))
2876 (org-html-level-start level txt umax
2877 (and org-export-with-toc
(<= level umax
))
2880 (when (string-match quote-re line
)
2884 ((and org-export-with-tables
2885 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2886 (if (not table-open
)
2888 (setq table-open t table-buffer nil table-orig-buffer nil
))
2890 (setq table-buffer
(cons line table-buffer
)
2891 table-orig-buffer
(cons origline table-orig-buffer
))
2892 (when (or (not lines
)
2893 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2895 (setq table-open nil
2896 table-buffer
(nreverse table-buffer
)
2897 table-orig-buffer
(nreverse table-orig-buffer
))
2898 (org-close-par-maybe)
2899 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2904 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2905 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2906 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2907 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2909 (setq ind
(org-get-string-indentation line
)
2910 item-type
(if (match-beginning 4) "o" "u")
2911 starter
(if (match-beginning 2)
2912 (substring (match-string 2 line
) 0 -
1))
2913 line
(substring line
(match-beginning 5))
2915 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
2917 item-tag
(match-string 1 line
)
2918 line
(substring line
(match-end 0))))
2919 (when (and (not (equal item-type
"d"))
2920 (not (string-match "[^ \t]" line
)))
2921 ;; empty line. Pretend indentation is large.
2922 (setq ind
(if org-empty-line-terminates-plain-lists
2924 (1+ (or (car local-list-indent
) 1)))))
2926 (while (and in-local-list
2927 (or (and (= ind
(car local-list-indent
))
2929 (< ind
(car local-list-indent
))))
2931 (org-close-li (car local-list-type
))
2932 (insert (format "</%sl>\n" (car local-list-type
)))
2933 (pop local-list-type
) (pop local-list-indent
)
2934 (setq in-local-list local-list-indent
))
2937 (or (not in-local-list
)
2938 (> ind
(car local-list-indent
))))
2939 ;; Start new (level of) list
2940 (org-close-par-maybe)
2942 ((equal item-type
"u") "<ul>\n<li>\n")
2943 ((equal item-type
"o") "<ol>\n<li>\n")
2944 ((equal item-type
"d")
2945 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
2946 (push item-type local-list-type
)
2947 (push ind local-list-indent
)
2948 (setq in-local-list t
))
2950 ;; continue current list
2951 (org-close-li (car local-list-type
))
2953 ((equal (car local-list-type
) "d")
2954 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
2957 ;; we did close a list, normal text follows: need <p>
2959 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2962 (if (equal (match-string 1 line
) "X")
2964 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2967 ;; Empty lines start a new paragraph. If hand-formatted lists
2968 ;; are not fully interpreted, lines starting with "-", "+", "*"
2969 ;; also start a new paragraph.
2970 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2972 ;; Is this the start of a footnote?
2973 (when org-export-with-footnotes
2974 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2975 (org-close-par-maybe)
2976 (let ((n (match-string 1 line
)))
2977 (setq line
(replace-match
2978 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
))
2979 (setq line
(concat line
"</p>")))))
2981 ;; Check if the line break needs to be conserved
2983 ((string-match "\\\\\\\\[ \t]*$" line
)
2984 (setq line
(replace-match "<br/>" t t line
)))
2985 (org-export-preserve-breaks
2986 (setq line
(concat line
"<br/>"))))
2988 (insert line
"\n")))))
2990 ;; Properly close all local lists and other lists
2991 (when inquote
(insert "</pre>\n"))
2993 ;; Close any local lists before inserting a new header line
2994 (while local-list-type
2995 (org-close-li (car local-list-type
))
2996 (insert (format "</%sl>\n" (car local-list-type
)))
2997 (pop local-list-type
))
2998 (setq local-list-indent nil
3000 (org-html-level-start 1 nil umax
3001 (and org-export-with-toc
(<= level umax
))
3003 ;; the </div> to lose the last text-... div.
3007 (when (plist-get opt-plist
:auto-postamble
)
3008 (insert "<div id=\"postamble\">")
3009 (when (and org-export-author-info author
)
3010 (insert "<p class=\"author\"> "
3011 (nth 1 lang-words
) ": " author
"\n")
3013 (if (listp (split-string email
",+ *"))
3015 (insert "<a href=\"mailto:" e
"\"><"
3017 (split-string email
",+ *"))
3018 (insert "<a href=\"mailto:" email
"\"><"
3019 email
"></a>\n")))
3021 (when (and date org-export-time-stamp-file
)
3022 (insert "<p class=\"date\"> "
3023 (nth 2 lang-words
) ": "
3027 (if org-export-html-with-timestamp
3028 (insert org-export-html-html-helper-timestamp
))
3029 (insert (or (plist-get opt-plist
:postamble
) ""))
3030 (insert "</body>\n</html>\n"))
3033 (if (eq major-mode default-major-mode
) (html-mode))
3035 ;; insert the table of contents
3036 (goto-char (point-min))
3038 (if (or (re-search-forward
3039 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3041 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3043 (goto-char (match-beginning 0))
3045 (goto-char first-heading-pos
)
3046 (when (looking-at "\\s-*</p>")
3047 (goto-char (match-end 0))
3049 (insert "<div id=\"table-of-contents\">\n")
3050 (mapc 'insert thetoc
)
3051 (insert "</div>\n"))
3052 ;; remove empty paragraphs and lists
3053 (goto-char (point-min))
3054 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3056 (goto-char (point-min))
3057 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3059 (goto-char (point-min))
3060 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3062 ;; Convert whitespace place holders
3063 (goto-char (point-min))
3065 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3066 (setq n
(get-text-property beg
'org-whitespace
)
3067 end
(next-single-property-change beg
'org-whitespace
))
3069 (delete-region beg end
)
3070 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3071 (make-string n ?x
)))))
3072 (or to-buffer
(save-buffer))
3073 (goto-char (point-min))
3074 (message "Exporting... done")
3075 (if (eq to-buffer
'string
)
3076 (prog1 (buffer-substring (point-min) (point-max))
3077 (kill-buffer (current-buffer)))
3078 (current-buffer)))))
3080 (defvar org-table-colgroup-info nil
)
3081 (defun org-format-table-ascii (lines)
3082 "Format a table for ascii export."
3084 (setq lines
(org-split-string lines
"\n")))
3085 (if (not (string-match "^[ \t]*|" (car lines
)))
3086 ;; Table made by table.el - test for spanning
3089 ;; A normal org table
3090 ;; Get rid of hlines at beginning and end
3091 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3092 (setq lines
(nreverse lines
))
3093 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3094 (setq lines
(nreverse lines
))
3095 (when org-export-table-remove-special-lines
3096 ;; Check if the table has a marking column. If yes remove the
3097 ;; column and the special lines
3098 (setq lines
(org-table-clean-before-export lines
)))
3099 ;; Get rid of the vertical lines except for grouping
3100 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3102 (while (setq line
(pop lines
))
3103 (if (string-match org-table-hline-regexp line
)
3104 (and (string-match "|\\(.*\\)|" line
)
3105 (setq line
(replace-match " \\1" t nil line
)))
3106 (setq start
0 vl1 vl
)
3107 (while (string-match "|" line start
)
3108 (setq start
(match-end 0))
3109 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3113 (defun org-colgroup-info-to-vline-list (info)
3116 (setq last new new
(pop info
))
3117 (if (or (memq last
'(:end
:startend
))
3118 (memq new
'(:start
:startend
)))
3121 (setq vl
(nreverse vl
))
3122 (and vl
(setcar vl nil
))
3125 (defvar org-table-number-regexp
) ; defined in org-table.el
3126 (defun org-format-table-html (lines olines
)
3127 "Find out which HTML converter to use and return the HTML code."
3129 (setq lines
(org-split-string lines
"\n")))
3130 (if (string-match "^[ \t]*|" (car lines
))
3131 ;; A normal org table
3132 (org-format-org-table-html lines
)
3133 ;; Table made by table.el - test for spanning
3134 (let* ((hlines (delq nil
(mapcar
3136 (if (string-match "^[ \t]*\\+-" x
) x
3139 (first (car hlines
))
3140 (ll (and (string-match "\\S-+" first
)
3141 (match-string 0 first
)))
3142 (re (concat "^[ \t]*" (regexp-quote ll
)))
3143 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3145 (if (and (not spanning
)
3146 (not org-export-prefer-native-exporter-for-tables
))
3147 ;; We can use my own converter with HTML conversions
3148 (org-format-table-table-html lines
)
3149 ;; Need to use the code generator in table.el, with the original text.
3150 (org-format-table-table-html-using-table-generate-source olines
)))))
3152 (defvar org-table-number-fraction
) ; defined in org-table.el
3153 (defun org-format-org-table-html (lines &optional splice
)
3154 "Format a table into HTML."
3155 (require 'org-table
)
3156 ;; Get rid of hlines at beginning and end
3157 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3158 (setq lines
(nreverse lines
))
3159 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3160 (setq lines
(nreverse lines
))
3161 (when org-export-table-remove-special-lines
3162 ;; Check if the table has a marking column. If yes remove the
3163 ;; column and the special lines
3164 (setq lines
(org-table-clean-before-export lines
)))
3166 (let ((head (and org-export-highlight-first-table-line
3168 (lambda (x) (string-match "^[ \t]*|-" x
))
3171 tbopen line fields html gr colgropen
)
3172 (if splice
(setq head nil
))
3173 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3175 (while (setq line
(pop lines
))
3177 (if (string-match "^[ \t]*|-" line
)
3180 (push (if head
"</thead>" "</tbody>") html
)
3181 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3182 (setq head nil
) ;; head ends here, first time around
3184 (throw 'next-line t
)))
3185 ;; Break the line into fields
3186 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3187 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3188 (setq nlines
(1+ nlines
) i -
1)
3189 (push (concat "<tr>"
3193 (if (and (< i nlines
)
3194 (string-match org-table-number-regexp x
))
3195 (incf (aref fnum i
)))
3197 (concat (car org-export-table-header-tags
) x
3198 (cdr org-export-table-header-tags
))
3199 (concat (car org-export-table-data-tags
) x
3200 (cdr org-export-table-data-tags
))))
3204 (unless splice
(if tbopen
(push "</tbody>" html
)))
3205 (unless splice
(push "</table>\n" html
))
3206 (setq html
(nreverse html
))
3208 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3211 (setq gr
(pop org-table-colgroup-info
))
3212 (format "%s<col align=\"%s\"></col>%s"
3213 (if (memq gr
'(:start
:startend
))
3215 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3218 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3220 (if (memq gr
'(:end
:startend
))
3221 (progn (setq colgropen nil
) "</colgroup>")
3225 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3226 (push html-table-tag html
))
3227 (concat (mapconcat 'identity html
"\n") "\n")))
3229 (defun org-table-clean-before-export (lines)
3230 "Check if the table has a marking column.
3231 If yes remove the column and the special lines."
3232 (setq org-table-colgroup-info nil
)
3235 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3236 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3239 (setq org-table-clean-did-remove-column nil
)
3244 ((string-match "^[ \t]*| */ *|" x
)
3245 (setq org-table-colgroup-info
3247 (cond ((member x
'("<" "<")) :start
)
3248 ((member x
'(">" ">")) :end
)
3249 ((member x
'("<>" "<>")) :startend
)
3251 (org-split-string x
"[ \t]*|[ \t]*")))
3255 (setq org-table-clean-did-remove-column t
)
3260 ((string-match "^[ \t]*| */ *|" x
)
3261 (setq org-table-colgroup-info
3263 (cond ((member x
'("<" "<")) :start
)
3264 ((member x
'(">" ">")) :end
)
3265 ((member x
'("<>" "<>")) :startend
)
3267 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3269 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3270 nil
) ; ignore this line
3271 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3272 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3273 ;; remove the first column
3274 (replace-match "\\1|" t nil x
))))
3277 (defun org-format-table-table-html (lines)
3278 "Format a table generated by table.el into HTML.
3279 This conversion does *not* use `table-generate-source' from table.el.
3280 This has the advantage that Org-mode's HTML conversions can be used.
3281 But it has the disadvantage, that no cell- or row-spanning is allowed."
3282 (let (line field-buffer
3283 (head org-export-highlight-first-table-line
)
3285 (setq html
(concat html-table-tag
"\n"))
3286 (while (setq line
(pop lines
))
3287 (setq empty
" ")
3289 (if (string-match "^[ \t]*\\+-" line
)
3300 (if (equal x
"") (setq x empty
))
3302 (concat (car org-export-table-header-tags
) x
3303 (cdr org-export-table-header-tags
))
3304 (concat (car org-export-table-data-tags
) x
3305 (cdr org-export-table-data-tags
))))
3309 (setq field-buffer nil
)))
3311 (throw 'next-line t
)))
3312 ;; Break the line into fields and store the fields
3313 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3315 (setq field-buffer
(mapcar
3317 (concat x
"<br/>" (pop fields
)))
3319 (setq field-buffer fields
))))
3320 (setq html
(concat html
"</table>\n"))
3323 (defun org-format-table-table-html-using-table-generate-source (lines)
3324 "Format a table into html, using `table-generate-source' from table.el.
3325 This has the advantage that cell- or row-spanning is allowed.
3326 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3328 (with-current-buffer (get-buffer-create " org-tmp1 ")
3330 (insert (mapconcat 'identity lines
"\n"))
3331 (goto-char (point-min))
3332 (if (not (re-search-forward "|[^+]" nil t
))
3333 (error "Error processing table"))
3334 (table-recognize-table)
3335 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3336 (table-generate-source 'html
" org-tmp2 ")
3337 (set-buffer " org-tmp2 ")
3338 (buffer-substring (point-min) (point-max))))
3340 (defun org-html-handle-time-stamps (s)
3341 "Format time stamps in string S, or remove them."
3344 (while (string-match org-maybe-keyword-time-regexp s
)
3345 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3346 ;; never export CLOCK
3348 (or b
(setq b
(substring s
0 (match-beginning 0))))
3349 (if (not org-export-with-timestamps
)
3350 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3351 s
(substring s
(match-end 0)))
3353 r
(substring s
0 (match-beginning 0))
3355 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3356 (match-string 1 s
)))
3357 (format " @<span class=\"timestamp\">%s@</span>"
3359 (org-translate-time (match-string 3 s
)) 1 -
1)))
3360 s
(substring s
(match-end 0)))))
3361 ;; Line break if line started and ended with time stamp stuff
3364 (setq r
(concat r s
))
3365 (unless (string-match "\\S-" (concat b s
))
3366 (setq r
(concat r
"@<br/>")))
3369 (defun org-export-htmlize-region-for-paste (beg end
)
3370 "Convert the region to HTML, using htmlize.el.
3371 This is much like `htmlize-region-for-paste', only that it uses
3372 the settings define in the org-... variables."
3373 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3374 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3375 (htmlbuf (htmlize-region beg end
)))
3377 (with-current-buffer htmlbuf
3378 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3379 (plist-get htmlize-buffer-places
'content-end
)))
3380 (kill-buffer htmlbuf
))))
3383 (defun org-export-htmlize-generate-css ()
3384 "Create the CSS for all font definitions in the current Emacs session.
3385 Use this to create face definitions in your CSS style file that can then
3386 be used by code snippets transformed by htmlize.
3387 This command just produces a buffer that contains class definitions for all
3388 faces used in the current Emacs session. You can copy and paste the ones you
3389 need into your CSS file.
3391 If you then set `org-export-htmlize-output-type' to `css', calls to
3392 the function `org-export-htmlize-region-for-paste' will produce code
3393 that uses these same face definitions."
3396 (and (get-buffer "*html*") (kill-buffer "*html*"))
3398 (let ((fl (face-list))
3399 (htmlize-css-name-prefix "org-")
3400 (htmlize-output-type 'css
)
3402 (while (setq f
(pop fl
)
3403 i
(and f
(face-attribute f
:inherit
)))
3404 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3405 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3406 (htmlize-region (point-min) (point-max))))
3407 (switch-to-buffer "*html*")
3408 (goto-char (point-min))
3409 (if (re-search-forward "<style" nil t
)
3410 (delete-region (point-min) (match-beginning 0)))
3411 (if (re-search-forward "</style>" nil t
)
3412 (delete-region (1+ (match-end 0)) (point-max)))
3413 (beginning-of-line 1)
3414 (if (looking-at " +") (replace-match ""))
3415 (goto-char (point-min)))
3417 (defun org-html-protect (s)
3418 ;; convert & to &, < to < and > to >
3420 (while (string-match "&" s start
)
3421 (setq s
(replace-match "&" t t s
)
3422 start
(1+ (match-beginning 0))))
3423 (while (string-match "<" s
)
3424 (setq s
(replace-match "<" t t s
)))
3425 (while (string-match ">" s
)
3426 (setq s
(replace-match ">" t t s
))))
3429 (defun org-export-cleanup-toc-line (s)
3430 "Remove tags and time staps from lines going into the toc."
3431 (when (memq org-export-with-tags
'(not-in-toc nil
))
3432 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3433 (setq s
(replace-match "" t t s
))))
3434 (when org-export-remove-timestamps-from-toc
3435 (while (string-match org-maybe-keyword-time-regexp s
)
3436 (setq s
(replace-match "" t t s
))))
3437 (while (string-match org-bracket-link-regexp s
)
3438 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3442 (defun org-html-expand (string)
3443 "Prepare STRING for HTML export. Applies all active conversions.
3444 If there are links in the string, don't modify these."
3445 (let* ((re (concat org-bracket-link-regexp
"\\|"
3446 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3448 (while (setq m
(string-match re string
))
3449 (setq s
(substring string
0 m
)
3450 l
(match-string 0 string
)
3451 string
(substring string
(match-end 0)))
3452 (push (org-html-do-expand s
) res
)
3454 (push (org-html-do-expand string
) res
)
3455 (apply 'concat
(nreverse res
))))
3457 (defun org-html-do-expand (s)
3458 "Apply all active conversions to translate special ASCII to HTML."
3459 (setq s
(org-html-protect s
))
3460 (if org-export-html-expand
3462 (while (string-match "@<\\([^&]*\\)>" s
)
3463 (setq s
(replace-match "<\\1>" t nil s
)))))
3464 (if org-export-with-emphasize
3465 (setq s
(org-export-html-convert-emphasize s
)))
3466 (if org-export-with-special-strings
3467 (setq s
(org-export-html-convert-special-strings s
)))
3468 (if org-export-with-sub-superscripts
3469 (setq s
(org-export-html-convert-sub-super s
)))
3470 (if org-export-with-TeX-macros
3471 (let ((start 0) wd ass
)
3472 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3473 (if (get-text-property (match-beginning 0) 'org-protected s
)
3474 (setq start
(match-end 0))
3475 (setq wd
(match-string 1 s
))
3476 (if (setq ass
(assoc wd org-html-entities
))
3477 (setq s
(replace-match (or (cdr ass
)
3478 (concat "&" (car ass
) ";"))
3480 (setq start
(+ start
(length wd
))))))))
3483 (defun org-create-multibrace-regexp (left right n
)
3484 "Create a regular expression which will match a balanced sexp.
3485 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3486 as single character strings.
3487 The regexp returned will match the entire expression including the
3488 delimiters. It will also define a single group which contains the
3489 match except for the outermost delimiters. The maximum depth of
3490 stacked delimiters is N. Escaping delimiters is not possible."
3491 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3494 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3497 re
(concat re or next
)
3498 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3499 (concat left
"\\(" re
"\\)" right
)))
3501 (defvar org-match-substring-regexp
3503 "\\([^\\]\\)\\([_^]\\)\\("
3504 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3506 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3508 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3509 "The regular expression matching a sub- or superscript.")
3511 (defvar org-match-substring-with-braces-regexp
3513 "\\([^\\]\\)\\([_^]\\)\\("
3514 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3516 "The regular expression matching a sub- or superscript, forcing braces.")
3518 (defconst org-export-html-special-string-regexps
3519 '(("\\\\-" .
"­")
3520 ("---\\([^-]\\)" .
"—\\1")
3521 ("--\\([^-]\\)" .
"–\\1")
3522 ("\\.\\.\\." .
"…"))
3523 "Regular expressions for special string conversion.")
3525 (defun org-export-html-convert-special-strings (string)
3526 "Convert special characters in STRING to HTML."
3527 (let ((all org-export-html-special-string-regexps
)
3529 (while (setq a
(pop all
))
3530 (setq re
(car a
) rpl
(cdr a
) start
0)
3531 (while (string-match re string start
)
3532 (if (get-text-property (match-beginning 0) 'org-protected string
)
3533 (setq start
(match-end 0))
3534 (setq string
(replace-match rpl t nil string
)))))
3537 (defun org-export-html-convert-sub-super (string)
3538 "Convert sub- and superscripts in STRING to HTML."
3539 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3540 (while (string-match org-match-substring-regexp string s
)
3542 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3543 ((get-text-property (match-beginning 2) 'org-protected string
)
3544 (setq s
(match-end 2)))
3546 (setq s
(match-end 1)
3547 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3548 c
(or (match-string 8 string
)
3549 (match-string 6 string
)
3550 (match-string 5 string
))
3551 string
(replace-match
3552 (concat (match-string 1 string
)
3553 "<" key
">" c
"</" key
">")
3555 (while (string-match "\\\\\\([_^]\\)" string
)
3556 (setq string
(replace-match (match-string 1 string
) t t string
)))
3559 (defun org-export-html-convert-emphasize (string)
3562 (while (string-match org-emph-re string s
)
3564 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3565 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3566 (setq s
(match-beginning 0)
3569 (match-string 1 string
)
3570 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3571 (match-string 4 string
)
3572 (nth 3 (assoc (match-string 3 string
)
3573 org-emphasis-alist
))
3574 (match-string 5 string
))
3575 string
(replace-match rpl t t string
)
3576 s
(+ s
(- (length rpl
) 2)))
3580 (defvar org-par-open nil
)
3581 (defun org-open-par ()
3582 "Insert <p>, but first close previous paragraph if any."
3583 (org-close-par-maybe)
3585 (setq org-par-open t
))
3586 (defun org-close-par-maybe ()
3587 "Close paragraph if there is one open."
3590 (setq org-par-open nil
)))
3591 (defun org-close-li (&optional type
)
3592 "Close <li> if necessary."
3593 (org-close-par-maybe)
3594 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3596 (defvar body-only
) ; dynamically scoped into this.
3597 (defun org-html-level-start (level title umax with-toc head-count
)
3598 "Insert a new level in HTML export.
3599 When TITLE is nil, just close all open levels."
3600 (org-close-par-maybe)
3601 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3605 (if (aref org-levels-open
(1- l
))
3607 (org-html-level-close l umax
)
3608 (aset org-levels-open
(1- l
) nil
)))
3611 ;; If title is nil, this means this function is called to close
3612 ;; all levels, so the rest is done only if title is given
3613 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3614 (setq title
(replace-match
3615 (if org-export-with-tags
3618 " <span class=\"tag\">"
3619 (mapconcat 'identity
(org-split-string
3620 (match-string 1 title
) ":")
3627 (if (aref org-levels-open
(1- level
))
3631 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3632 (insert "<li>" title
"<br/>\n")))
3633 (aset org-levels-open
(1- level
) t
)
3634 (org-close-par-maybe)
3636 (insert (format "<ul>\n<li id=\"%s\">" target
)
3638 (insert "<ul>\n<li>" title
"<br/>\n"))))
3639 (aset org-levels-open
(1- level
) t
)
3640 (setq snumber
(org-section-number level
))
3641 (if (and org-export-with-section-numbers
(not body-only
))
3642 (setq title
(concat snumber
" " title
)))
3643 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3644 (unless (= head-count
1) (insert "\n</div>\n"))
3645 (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"
3646 snumber level level snumber title level snumber
))
3649 (defun org-get-text-property-any (pos prop
&optional object
)
3650 (or (get-text-property pos prop object
)
3651 (and (setq pos
(next-single-property-change pos prop object
))
3652 (get-text-property pos prop object
))))
3654 (defun org-html-level-close (level max-outline-level
)
3655 "Terminate one level in HTML export."
3656 (if (<= level max-outline-level
)
3659 (insert "</ul>\n")))
3661 ;;; iCalendar export
3664 (defun org-export-icalendar-this-file ()
3665 "Export current file as an iCalendar file.
3666 The iCalendar file will be located in the same directory as the Org-mode
3667 file, but with extension `.ics'."
3669 (org-export-icalendar nil buffer-file-name
))
3672 (defun org-export-icalendar-all-agenda-files ()
3673 "Export all files in `org-agenda-files' to iCalendar .ics files.
3674 Each iCalendar file will be located in the same directory as the Org-mode
3675 file, but with extension `.ics'."
3677 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3680 (defun org-export-icalendar-combine-agenda-files ()
3681 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3682 The file is stored under the name `org-combined-agenda-icalendar-file'."
3684 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3686 (defun org-export-icalendar (combine &rest files
)
3687 "Create iCalendar files for all elements of FILES.
3688 If COMBINE is non-nil, combine all calendar entries into a single large
3689 file and store it under the name `org-combined-agenda-icalendar-file'."
3691 (org-prepare-agenda-buffers files
)
3692 (let* ((dir (org-export-directory
3693 :ical
(list :publishing-directory
3694 org-export-publishing-directory
)))
3695 file ical-file ical-buffer category started org-agenda-new-buffers
)
3696 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3699 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3700 org-combined-agenda-icalendar-file
3701 (expand-file-name org-combined-agenda-icalendar-file dir
))
3702 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3703 (set-buffer ical-buffer
) (erase-buffer))
3704 (while (setq file
(pop files
))
3706 (org-check-agenda-file file
)
3707 (set-buffer (org-get-agenda-file-buffer file
))
3709 (setq ical-file
(concat (file-name-as-directory dir
)
3710 (file-name-sans-extension
3711 (file-name-nondirectory buffer-file-name
))
3713 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3714 (with-current-buffer ical-buffer
(erase-buffer)))
3715 (setq category
(or org-category
3716 (file-name-sans-extension
3717 (file-name-nondirectory buffer-file-name
))))
3718 (if (symbolp category
) (setq category
(symbol-name category
)))
3719 (let ((standard-output ical-buffer
))
3721 (and (not started
) (setq started t
)
3722 (org-start-icalendar-file org-icalendar-combined-name
))
3723 (org-start-icalendar-file category
))
3724 (org-print-icalendar-entries combine
)
3725 (when (or (and combine
(not files
)) (not combine
))
3726 (org-finish-icalendar-file)
3727 (set-buffer ical-buffer
)
3729 (run-hooks 'org-after-save-iCalendar-file-hook
)
3730 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3732 (org-release-buffers org-agenda-new-buffers
))))
3734 (defvar org-after-save-iCalendar-file-hook nil
3735 "Hook run after an iCalendar file has been saved.
3736 The iCalendar buffer is still current when this hook is run.
3737 A good way to use this is to tell a desktop calenndar application to re-read
3738 the iCalendar file.")
3740 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3741 (defun org-print-icalendar-entries (&optional combine
)
3742 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3743 When COMBINE is non nil, add the category to each line."
3744 (require 'org-agenda
)
3745 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3746 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3747 (dts (org-ical-ts-to-string
3748 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3750 hd ts ts2 state status
(inc t
) pos b sexp rrule
3751 scheduledp deadlinep prefix
3752 tmp pri category entry location summary desc uid
3753 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3754 (org-refresh-category-properties)
3756 (goto-char (point-min))
3757 (while (re-search-forward re1 nil t
)
3760 (when (boundp 'org-icalendar-verify-function
)
3761 (unless (funcall org-icalendar-verify-function
)
3762 (outline-next-heading)
3765 (setq pos
(match-beginning 0)
3768 hd
(condition-case nil
3769 (org-icalendar-cleanup-string
3771 (error (throw :skip nil
)))
3772 summary
(org-icalendar-cleanup-string
3773 (org-entry-get nil
"SUMMARY"))
3774 desc
(org-icalendar-cleanup-string
3775 (or (org-entry-get nil
"DESCRIPTION")
3776 (and org-icalendar-include-body
(org-get-entry)))
3777 t org-icalendar-include-body
)
3778 location
(org-icalendar-cleanup-string
3779 (org-entry-get nil
"LOCATION"))
3780 uid
(if org-icalendar-store-UID
3782 (or (org-id-get) (org-id-new)))
3783 category
(org-get-category)
3784 deadlinep nil scheduledp nil
)
3785 (if (looking-at re2
)
3787 (goto-char (match-end 0))
3788 (setq ts2
(match-string 1)
3789 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
3790 (setq tmp
(buffer-substring (max (point-min)
3791 (- pos org-ds-keyword-length
))
3793 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3796 (replace-match "\\1" t nil ts
))
3798 deadlinep
(string-match org-deadline-regexp tmp
)
3799 scheduledp
(string-match org-scheduled-regexp tmp
)
3800 ;; donep (org-entry-is-done-p)
3802 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
3803 (if (or (string-match org-tr-regexp hd
)
3804 (string-match org-ts-regexp hd
))
3805 (setq hd
(replace-match "" t t hd
)))
3806 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3808 (concat "\nRRULE:FREQ="
3811 '(("d" .
"DAILY")("w" .
"WEEKLY")
3812 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3813 ";INTERVAL=" (match-string 1 ts
)))
3815 (setq summary
(or summary hd
))
3816 (if (string-match org-bracket-link-regexp summary
)
3818 (replace-match (if (match-end 3)
3819 (match-string 3 summary
)
3820 (match-string 1 summary
))
3822 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3823 (if scheduledp
(setq summary
(concat "S: " summary
)))
3824 (if (string-match "\\`<%%" ts
)
3825 (with-current-buffer sexp-buffer
3826 (insert (substring ts
1 -
1) " " summary
"\n"))
3827 (princ (format "BEGIN:VEVENT
3835 (org-ical-ts-to-string ts
"DTSTART")
3836 (org-ical-ts-to-string ts2
"DTEND" inc
)
3838 (if (and desc
(string-match "\\S-" desc
))
3839 (concat "\nDESCRIPTION: " desc
) "")
3840 (if (and location
(string-match "\\S-" location
))
3841 (concat "\nLOCATION: " location
) "")
3843 (when (and org-icalendar-include-sexps
3844 (condition-case nil
(require 'icalendar
) (error nil
))
3845 (fboundp 'icalendar-export-region
))
3846 ;; Get all the literal sexps
3847 (goto-char (point-min))
3848 (while (re-search-forward "^&?%%(" nil t
)
3851 (setq b
(match-beginning 0))
3852 (goto-char (1- (match-end 0)))
3855 (setq sexp
(buffer-substring b
(point)))
3856 (with-current-buffer sexp-buffer
3858 (princ (org-diary-to-ical-string sexp-buffer
)))))
3860 (when org-icalendar-include-todo
3861 (setq prefix
"TODO-")
3862 (goto-char (point-min))
3863 (while (re-search-forward org-todo-line-regexp nil t
)
3866 (when (boundp 'org-icalendar-verify-function
)
3867 (unless (funcall org-icalendar-verify-function
)
3868 (outline-next-heading)
3871 (setq state
(match-string 2))
3872 (setq status
(if (member state org-done-keywords
)
3873 "COMPLETED" "NEEDS-ACTION"))
3875 (or (not (member state org-done-keywords
))
3876 (eq org-icalendar-include-todo
'all
))
3877 (not (member org-archive-tag
(org-get-tags-at)))
3879 (setq hd
(match-string 3)
3880 summary
(org-icalendar-cleanup-string
3881 (org-entry-get nil
"SUMMARY"))
3882 desc
(org-icalendar-cleanup-string
3883 (or (org-entry-get nil
"DESCRIPTION")
3884 (and org-icalendar-include-body
(org-get-entry)))
3885 t org-icalendar-include-body
)
3886 location
(org-icalendar-cleanup-string
3887 (org-entry-get nil
"LOCATION"))
3888 uid
(if org-icalendar-store-UID
3890 (or (org-id-get) (org-id-new))))
3891 (if (string-match org-bracket-link-regexp hd
)
3892 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3893 (match-string 1 hd
))
3895 (if (string-match org-priority-regexp hd
)
3896 (setq pri
(string-to-char (match-string 2 hd
))
3897 hd
(concat (substring hd
0 (match-beginning 1))
3898 (substring hd
(match-end 1))))
3899 (setq pri org-default-priority
))
3900 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3901 (- org-lowest-priority org-highest-priority
))))))
3903 (princ (format "BEGIN:VTODO
3915 (if (and location
(string-match "\\S-" location
))
3916 (concat "\nLOCATION: " location
) "")
3917 (if (and desc
(string-match "\\S-" desc
))
3918 (concat "\nDESCRIPTION: " desc
) "")
3922 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3923 "Take out stuff and quote what needs to be quoted.
3924 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3925 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3930 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3931 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3932 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3933 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3935 (while (string-match "\\([,;]\\)" s start
)
3936 (setq start
(+ (match-beginning 0) 2)
3937 s
(replace-match "\\\\\\1" nil nil s
))))
3939 (while (string-match "[ \t]*\n[ \t]*" s
)
3940 (setq s
(replace-match "\\n" t t s
))))
3941 (setq s
(org-trim s
))
3944 (if (and (numberp maxlength
)
3945 (> (length s
) maxlength
))
3946 (setq s
(substring s
0 maxlength
)))))
3949 (defun org-get-entry ()
3950 "Clean-up description string."
3952 (org-back-to-heading t
)
3953 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3955 (defun org-start-icalendar-file (name)
3956 "Start an iCalendar file by inserting the header."
3957 (let ((user user-full-name
)
3958 (name (or name
"unknown"))
3959 (timezone (cadr (current-time-zone))))
3961 (format "BEGIN:VCALENDAR
3964 PRODID:-//%s//Emacs with Org-mode//EN
3966 CALSCALE:GREGORIAN\n" name user timezone
))))
3968 (defun org-finish-icalendar-file ()
3969 "Finish an iCalendar file by inserting the END statement."
3970 (princ "END:VCALENDAR\n"))
3972 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3973 "Take a time string S and convert it to iCalendar format.
3974 KEYWORD is added in front, to make a complete line like DTSTART....
3975 When INC is non-nil, increase the hour by two (if time string contains
3976 a time), or the day by one (if it does not contain a time)."
3977 (let ((t1 (org-parse-time-string s
'nodefault
))
3978 t2 fmt have-time time
)
3979 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3980 (setq t2 t1 have-time t
)
3981 (setq t2
(org-parse-time-string s
)))
3982 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3983 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3986 (if org-agenda-default-appointment-duration
3987 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3990 (setq time
(encode-time s mi h d m y
)))
3991 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3992 (concat keyword
(format-time-string fmt time
))))
3996 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3997 (with-current-buffer buffer
3998 (apply 'insert output
)))
3999 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4002 (defun org-export-as-xoxo (&optional buffer
)
4003 "Export the org buffer as XOXO.
4004 The XOXO buffer is named *xoxo-<source buffer name>*"
4005 (interactive (list (current-buffer)))
4006 ;; A quickie abstraction
4008 ;; Output everything as XOXO
4009 (with-current-buffer (get-buffer buffer
)
4010 (let* ((pos (point))
4011 (opt-plist (org-combine-plists (org-default-export-plist)
4012 (org-infile-export-plist)))
4013 (filename (concat (file-name-as-directory
4014 (org-export-directory :xoxo opt-plist
))
4015 (file-name-sans-extension
4016 (file-name-nondirectory buffer-file-name
))
4018 (out (find-file-noselect filename
))
4021 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4022 ;; Check the output buffer is empty.
4023 (with-current-buffer out
(erase-buffer))
4024 ;; Kick off the output
4025 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4026 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4027 (let* ((hd (match-string-no-properties 1))
4030 (match-string-no-properties 2)
4032 (goto-char (match-end 0))
4037 (if (looking-at "^[ \t]\\(.*\\)")
4038 (setq str
(concat str
(match-string-no-properties 1)))
4039 (throw 'loop str
)))))))))
4041 ;; Handle level rendering
4043 ((> level last-level
)
4044 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4046 ((< level last-level
)
4047 (dotimes (- (- last-level level
) 1)
4049 (org-export-as-xoxo-insert-into out
"</li>\n"))
4050 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4052 (org-export-as-xoxo-insert-into out
"</li>\n")
4053 (setq hanging-li nil
)))
4055 ((equal level last-level
)
4057 (org-export-as-xoxo-insert-into out
"</li>\n")))
4060 (setq last-level level
)
4062 ;; And output the new li
4063 (setq hanging-li
't
)
4064 (if (equal ?
+ (elt text
0))
4065 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4066 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4068 ;; Finally finish off the ol
4069 (dotimes (- last-level
1)
4071 (org-export-as-xoxo-insert-into out
"</li>\n"))
4072 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4075 ;; Finish the buffer off and clean it up.
4076 (switch-to-buffer-other-window out
)
4077 (indent-region (point-min) (point-max) nil
)
4079 (goto-char (point-min))
4084 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4086 ;;; org-exp.el ends here