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-section-number-format
'((("1" ".")) .
"")
136 "Format of section numbers for export.
137 The variable has two components.
138 1. A list of lists, each indicating a counter type and a separator.
139 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
140 It causes causes numeric, alphabetic, or roman counters, respectively.
141 The separator is only used if another counter for a subsection is being
143 If there are more numbered section levels than entries in this lists,
144 then the last entry will be reused.
145 2. A terminator string that will be added after the entire
147 :group
'org-export-general
151 (string :tag
"Counter Type")
152 (string :tag
"Separator ")))
153 (string :tag
"Terminator")))
155 (defcustom org-export-with-toc t
156 "Non-nil means, create a table of contents in exported files.
157 The TOC contains headlines with levels up to`org-export-headline-levels'.
158 When an integer, include levels up to N in the toc, this may then be
159 different from `org-export-headline-levels', but it will not be allowed
160 to be larger than the number of headline levels.
161 When nil, no table of contents is made.
163 Headlines which contain any TODO items will be marked with \"(*)\" in
164 ASCII export, and with red color in HTML output, if the option
165 `org-export-mark-todo-in-toc' is set.
167 In HTML output, the TOC will be clickable.
169 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
171 :group
'org-export-general
173 (const :tag
"No Table of Contents" nil
)
174 (const :tag
"Full Table of Contents" t
)
175 (integer :tag
"TOC to level")))
177 (defcustom org-export-mark-todo-in-toc nil
178 "Non-nil means, mark TOC lines that contain any open TODO items."
179 :group
'org-export-general
182 (defcustom org-export-preserve-breaks nil
183 "Non-nil means, preserve all line breaks when exporting.
184 Normally, in HTML output paragraphs will be reformatted. In ASCII
185 export, line breaks will always be preserved, regardless of this variable.
187 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
188 :group
'org-export-general
191 (defcustom org-export-with-archived-trees
'headline
192 "Whether subtrees with the ARCHIVE tag should be exported.
193 This can have three different values
194 nil Do not export, pretend this tree is not present
195 t Do export the entire tree
196 headline Only export the headline, but skip the tree below it."
197 :group
'org-export-general
200 (const :tag
"not at all" nil
)
201 (const :tag
"headline only" 'headline
)
202 (const :tag
"entirely" t
)))
204 (defcustom org-export-author-info t
205 "Non-nil means, insert author name and email into the exported file.
207 This option can also be set with the +OPTIONS line,
208 e.g. \"author-info:nil\"."
209 :group
'org-export-general
212 (defcustom org-export-time-stamp-file t
213 "Non-nil means, insert a time stamp into the exported file.
214 The time stamp shows when the file was created.
216 This option can also be set with the +OPTIONS line,
217 e.g. \"timestamp:nil\"."
218 :group
'org-export-general
221 (defcustom org-export-with-timestamps t
222 "If nil, do not export time stamps and associated keywords."
223 :group
'org-export-general
226 (defcustom org-export-remove-timestamps-from-toc t
227 "If nil, remove timestamps from the table of contents entries."
228 :group
'org-export-general
231 (defcustom org-export-with-tags
'not-in-toc
232 "If nil, do not export tags, just remove them from headlines.
233 If this is the symbol `not-in-toc', tags will be removed from table of
234 contents entries, but still be shown in the headlines of the document.
236 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
237 :group
'org-export-general
239 (const :tag
"Off" nil
)
240 (const :tag
"Not in TOC" not-in-toc
)
241 (const :tag
"On" t
)))
243 (defcustom org-export-with-drawers nil
244 "Non-nil means, export with drawers like the property drawer.
245 When t, all drawers are exported. This may also be a list of
246 drawer names to export."
247 :group
'org-export-general
249 (const :tag
"All drawers" t
)
250 (const :tag
"None" nil
)
251 (repeat :tag
"Selected drawers"
252 (string :tag
"Drawer name"))))
254 (defvar org-export-preprocess-hook nil
255 "Hook for preprocessing an export buffer.
256 Pretty much the first thing when exporting is running this hook.")
258 (defgroup org-export-translation nil
259 "Options for translating special ascii sequences for the export backends."
260 :tag
"Org Export Translation"
263 (defcustom org-export-with-emphasize t
264 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
265 If the export target supports emphasizing text, the word will be
266 typeset in bold, italic, or underlined, respectively. Works only for
267 single words, but you can say: I *really* *mean* *this*.
268 Not all export backends support this.
270 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
271 :group
'org-export-translation
274 (defcustom org-export-with-footnotes t
275 "If nil, export [1] as a footnote marker.
276 Lines starting with [1] will be formatted as footnotes.
278 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
279 :group
'org-export-translation
282 (defcustom org-export-with-sub-superscripts t
283 "Non-nil means, interpret \"_\" and \"^\" for export.
284 When this option is turned on, you can use TeX-like syntax for sub- and
285 superscripts. Several characters after \"_\" or \"^\" will be
286 considered as a single item - so grouping with {} is normally not
287 needed. For example, the following things will be parsed as single
288 sub- or superscripts.
290 10^24 or 10^tau several digits will be considered 1 item.
291 10^-12 or 10^-tau a leading sign with digits or a word
292 x^2-y^3 will be read as x^2 - y^3, because items are
293 terminated by almost any nonword/nondigit char.
294 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
296 Still, ambiguity is possible - so when in doubt use {} to enclose the
297 sub/superscript. If you set this variable to the symbol `{}',
298 the braces are *required* in order to trigger interpretations as
299 sub/superscript. This can be helpful in documents that need \"_\"
300 frequently in plain text.
302 Not all export backends support this, but HTML does.
304 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
305 :group
'org-export-translation
307 (const :tag
"Always interpret" t
)
308 (const :tag
"Only with braces" {})
309 (const :tag
"Never interpret" nil
)))
311 (defcustom org-export-with-special-strings t
312 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
313 When this option is turned on, these strings will be exported as:
319 Not all export backends support this, but HTML does.
321 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
322 :group
'org-export-translation
325 (defcustom org-export-with-TeX-macros t
326 "Non-nil means, interpret simple TeX-like macros when exporting.
327 For example, HTML export converts \\alpha to α and \\AA to Å.
328 No only real TeX macros will work here, but the standard HTML entities
329 for math can be used as macro names as well. For a list of supported
330 names in HTML export, see the constant `org-html-entities'.
331 Not all export backends support this.
333 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
334 :group
'org-export-translation
335 :group
'org-export-latex
338 (defcustom org-export-with-LaTeX-fragments nil
339 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
340 When set, the exporter will find LaTeX environments if the \\begin line is
341 the first non-white thing on a line. It will also find the math delimiters
342 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
345 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
346 :group
'org-export-translation
347 :group
'org-export-latex
350 (defcustom org-export-with-fixed-width t
351 "Non-nil means, lines starting with \":\" will be in fixed width font.
352 This can be used to have pre-formatted text, fragments of code etc. For
354 : ;; Some Lisp examples
357 will be looking just like this in also HTML. See also the QUOTE keyword.
358 Not all export backends support this.
360 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
361 :group
'org-export-translation
364 (defcustom org-match-sexp-depth
3
365 "Number of stacked braces for sub/superscript matching.
366 This has to be set before loading org.el to be effective."
367 :group
'org-export-translation
370 (defgroup org-export-tables nil
371 "Options for exporting tables in Org-mode."
372 :tag
"Org Export Tables"
375 (defcustom org-export-with-tables t
376 "If non-nil, lines starting with \"|\" define a table.
379 | Name | Address | Birthday |
380 |-------------+----------+-----------|
381 | Arthur Dent | England | 29.2.2100 |
383 Not all export backends support this.
385 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
386 :group
'org-export-tables
389 (defcustom org-export-highlight-first-table-line t
390 "Non-nil means, highlight the first table line.
391 In HTML export, this means use <th> instead of <td>.
392 In tables created with table.el, this applies to the first table line.
393 In Org-mode tables, all lines before the first horizontal separator
394 line will be formatted with <th> tags."
395 :group
'org-export-tables
398 (defcustom org-export-table-remove-special-lines t
399 "Remove special lines and marking characters in calculating tables.
400 This removes the special marking character column from tables that are set
401 up for spreadsheet calculations. It also removes the entire lines
402 marked with `!', `_', or `^'. The lines with `$' are kept, because
403 the values of constants may be useful to have."
404 :group
'org-export-tables
407 (defcustom org-export-prefer-native-exporter-for-tables nil
408 "Non-nil means, always export tables created with table.el natively.
409 Natively means, use the HTML code generator in table.el.
410 When nil, Org-mode's own HTML generator is used when possible (i.e. if
411 the table does not use row- or column-spanning). This has the
412 advantage, that the automatic HTML conversions for math symbols and
413 sub/superscripts can be applied. Org-mode's HTML generator is also
415 :group
'org-export-tables
418 (defgroup org-export-ascii nil
419 "Options specific for ASCII export of Org-mode files."
420 :tag
"Org Export ASCII"
423 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
424 "Characters for underlining headings in ASCII export.
425 In the given sequence, these characters will be used for level 1, 2, ..."
426 :group
'org-export-ascii
427 :type
'(repeat character
))
429 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
430 "Bullet characters for headlines converted to lists in ASCII export.
431 The first character is used for the first lest level generated in this
432 way, and so on. If there are more levels than characters given here,
433 the list will be repeated.
434 Note that plain lists will keep the same bullets as the have in the
436 :group
'org-export-ascii
437 :type
'(repeat character
))
439 (defgroup org-export-xml nil
440 "Options specific for XML export of Org-mode files."
441 :tag
"Org Export XML"
444 (defgroup org-export-html nil
445 "Options specific for HTML export of Org-mode files."
446 :tag
"Org Export HTML"
449 (defcustom org-export-html-coding-system nil
450 "Coding system for HTML export, defaults to buffer-file-coding-system."
451 :group
'org-export-html
452 :type
'coding-system
)
454 (defcustom org-export-html-extension
"html"
455 "The extension for exported HTML files."
456 :group
'org-export-html
459 (defcustom org-export-html-link-up
""
460 "Where should the \"UP\" link of exported HTML pages lead?"
461 :group
'org-export-html
462 :type
'(string :tag
"File or URL"))
464 (defcustom org-export-html-link-home
""
465 "Where should the \"HOME\" link of exported HTML pages lead?"
466 :group
'org-export-html
467 :type
'(string :tag
"File or URL"))
469 (defcustom org-export-html-style
470 "<style type=\"text/css\">
472 font-family: Times, serif;
475 .title { text-align: center; }
476 .todo { color: red; }
477 .done { color: green; }
478 .timestamp { color: grey }
479 .timestamp-kwd { color: CadetBlue }
480 .tag { background-color:lightblue; font-weight:normal }
483 border: 1pt solid #AEBDCC;
484 background-color: #F3F5F7;
486 font-family: courier, monospace;
489 table { border-collapse: collapse; }
492 <!--border: 1pt solid #ADB9CC;-->
494 dt { font-weight: bold; }
496 "The default style specification for exported HTML files.
497 Since there are different ways of setting style information, this variable
498 needs to contain the full HTML structure to provide a style, including the
499 surrounding HTML tags. The style specifications should include definitions
500 for new classes todo, done, title, and deadline. For example, valid values
503 <style type=\"text/css\">
504 p { font-weight: normal; color: gray; }
506 .title { text-align: center; }
507 .todo, .deadline { color: red; }
508 .done { color: green; }
511 or, if you want to keep the style in a file,
513 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
515 As the value of this option simply gets inserted into the HTML <head> header,
516 you can \"misuse\" it to add arbitrary text to the header."
517 :group
'org-export-html
521 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
522 "Format for typesetting the document title in HTML export."
523 :group
'org-export-html
526 (defcustom org-export-html-toplevel-hlevel
2
527 "The <H> level for level 1 headings in HTML export."
528 :group
'org-export-html
531 (defcustom org-export-html-link-org-files-as-html t
532 "Non-nil means, make file links to `file.org' point to `file.html'.
533 When org-mode is exporting an org-mode file to HTML, links to
534 non-html files are directly put into a href tag in HTML.
535 However, links to other Org-mode files (recognized by the
536 extension `.org.) should become links to the corresponding html
537 file, assuming that the linked org-mode file will also be
539 When nil, the links still point to the plain `.org' file."
540 :group
'org-export-html
543 (defcustom org-export-html-inline-images
'maybe
544 "Non-nil means, inline images into exported HTML pages.
545 This is done using an <img> tag. When nil, an anchor with href is used to
546 link to the image. If this option is `maybe', then images in links with
547 an empty description will be inlined, while images with a description will
549 :group
'org-export-html
550 :type
'(choice (const :tag
"Never" nil
)
551 (const :tag
"Always" t
)
552 (const :tag
"When there is no description" maybe
)))
555 (defcustom org-export-html-expand t
556 "Non-nil means, for HTML export, treat @<...> as HTML tag.
557 When nil, these tags will be exported as plain text and therefore
558 not be interpreted by a browser.
560 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
561 :group
'org-export-html
564 (defcustom org-export-html-table-tag
565 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
566 "The HTML tag that is used to start a table.
567 This must be a <table> tag, but you may change the options like
568 borders and spacing."
569 :group
'org-export-html
572 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
573 "The opening tag for table header fields.
574 This is customizable so that alignment options can be specified."
575 :group
'org-export-tables
576 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
578 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
579 "The opening tag for table data fields.
580 This is customizable so that alignment options can be specified."
581 :group
'org-export-tables
582 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
584 (defcustom org-export-html-with-timestamp nil
585 "If non-nil, write `org-export-html-html-helper-timestamp'
586 into the exported HTML text. Otherwise, the buffer will just be saved
588 :group
'org-export-html
591 (defcustom org-export-html-html-helper-timestamp
592 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
593 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
594 :group
'org-export-html
597 (defgroup org-export-htmlize nil
598 "Options for processing examples with htmlize.el."
599 :tag
"Org Export Htmlize"
600 :group
'org-export-html
)
602 (defcustom org-export-htmlize-output-type
'inline-css
603 "Output type to be used by htmlize when formatting code snippets.
604 Normally this is `inline-css', but if you have defined to appropriate
605 classes in your css style file, setting this to `css' means that the
606 fontification will use the class names.
607 See also the function `org-export-htmlize-generate-css'."
608 :group
'org-export-htmlize
609 :type
'(choice (const css
) (const inline-css
)))
611 (defcustom org-export-htmlize-css-font-prefix
"org-"
612 "The prefix for CSS class names for htmlize font specifications."
613 :group
'org-export-htmlize
616 (defgroup org-export-icalendar nil
617 "Options specific for iCalendar export of Org-mode files."
618 :tag
"Org Export iCalendar"
621 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
622 "The file name for the iCalendar file covering all agenda files.
623 This file is created with the command \\[org-export-icalendar-all-agenda-files].
624 The file name should be absolute, the file will be overwritten without warning."
625 :group
'org-export-icalendar
628 (defcustom org-icalendar-include-todo nil
629 "Non-nil means, export to iCalendar files should also cover TODO items."
630 :group
'org-export-icalendar
632 (const :tag
"None" nil
)
633 (const :tag
"Unfinished" t
)
634 (const :tag
"All" all
)))
636 (defcustom org-icalendar-include-sexps t
637 "Non-nil means, export to iCalendar files should also cover sexp entries.
638 These are entries like in the diary, but directly in an Org-mode file."
639 :group
'org-export-icalendar
642 (defcustom org-icalendar-include-body
100
643 "Amount of text below headline to be included in iCalendar export.
644 This is a number of characters that should maximally be included.
645 Properties, scheduling and clocking lines will always be removed.
646 The text will be inserted into the DESCRIPTION field."
647 :group
'org-export-icalendar
649 (const :tag
"Nothing" nil
)
650 (const :tag
"Everything" t
)
651 (integer :tag
"Max characters")))
653 (defcustom org-icalendar-combined-name
"OrgMode"
654 "Calendar name for the combined iCalendar representing all agenda files."
655 :group
'org-export-icalendar
658 (defcustom org-icalendar-store-UID nil
659 "Non-nil means, store any created UIDs in properties.
660 The iCalendar standard requires that all entries have a unique identifyer.
661 Org will create these identifiers as needed. When this variable is non-nil,
662 the created UIDs will be stored in the ID property of the entry. Then the
663 next time this entry is exported, it will be exported with the same UID,
664 superceeding the previous form of it. This is essential for
665 synchronization services.
666 This variable is not turned on by default because we want to avoid creating
667 a property drawer in every entry if people are only playing with this feature,
668 or if they are only using it locally."
669 :group
'org-export-icalendar
674 ;;; Variables, constants, and parameter plists
676 (defconst org-level-max
20)
678 (defvar org-export-html-preamble nil
679 "Preamble, to be inserted just after <body>. Set by publishing functions.")
680 (defvar org-export-html-postamble nil
681 "Preamble, to be inserted just before </body>. Set by publishing functions.")
682 (defvar org-export-html-auto-preamble t
683 "Should default preamble be inserted? Set by publishing functions.")
684 (defvar org-export-html-auto-postamble t
685 "Should default postamble be inserted? Set by publishing functions.")
686 (defvar org-current-export-file nil
) ; dynamically scoped parameter
687 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
689 (defconst org-export-plist-vars
690 '((:link-up . org-export-html-link-up
)
691 (:link-home . org-export-html-link-home
)
692 (:language . org-export-default-language
)
693 (:customtime . org-display-custom-times
)
694 (:headline-levels . org-export-headline-levels
)
695 (:section-numbers . org-export-with-section-numbers
)
696 (:section-number-format . org-export-section-number-format
)
697 (:table-of-contents . org-export-with-toc
)
698 (:preserve-breaks . org-export-preserve-breaks
)
699 (:archived-trees . org-export-with-archived-trees
)
700 (:emphasize . org-export-with-emphasize
)
701 (:sub-superscript . org-export-with-sub-superscripts
)
702 (:special-strings . org-export-with-special-strings
)
703 (:footnotes . org-export-with-footnotes
)
704 (:drawers . org-export-with-drawers
)
705 (:tags . org-export-with-tags
)
706 (:TeX-macros . org-export-with-TeX-macros
)
707 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
708 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
709 (:fixed-width . org-export-with-fixed-width
)
710 (:timestamps . org-export-with-timestamps
)
711 (:author-info . org-export-author-info
)
712 (:time-stamp-file . org-export-time-stamp-file
)
713 (:tables . org-export-with-tables
)
714 (:table-auto-headline . org-export-highlight-first-table-line
)
715 (:style . org-export-html-style
)
716 (:agenda-style . org-agenda-export-html-style
)
717 (:convert-org-links . org-export-html-link-org-files-as-html
)
718 (:inline-images . org-export-html-inline-images
)
719 (:html-extension . org-export-html-extension
)
720 (:html-table-tag . org-export-html-table-tag
)
721 (:expand-quoted-html . org-export-html-expand
)
722 (:timestamp . org-export-html-with-timestamp
)
723 (:publishing-directory . org-export-publishing-directory
)
724 (:preamble . org-export-html-preamble
)
725 (:postamble . org-export-html-postamble
)
726 (:auto-preamble . org-export-html-auto-preamble
)
727 (:auto-postamble . org-export-html-auto-postamble
)
728 (:author . user-full-name
)
729 (:email . user-mail-address
)))
731 (defun org-default-export-plist ()
732 "Return the property list with default settings for the export variables."
733 (let ((l org-export-plist-vars
) rtn e
)
734 (while (setq e
(pop l
))
735 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
738 (defvar org-export-inbuffer-options-extra nil
739 "List of additional in-buffer options that should be detected.
740 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
741 etc. Extensions can add to this list to get their options detected, and they
742 can then add a function to `org-export-options-filters' to process these
744 Each element in this list must be a list, with the in-buffer keyword as car,
745 and a property (a symbol) as the next element. All occurences of the
746 keyword will be found, the values concatenated with a space character
747 in between, and the result stored in the export options property list.")
749 (defvar org-export-options-filters nil
750 "Functions to be called to finalize the export/publishing options.
751 All these options are stored in a property list, and each of the functions
752 in this hook gets a chance to modify this property list. Each function
753 must accept the property list as an argument, and must return the (possibly
756 (defun org-infile-export-plist ()
757 "Return the property list with file-local settings for export."
761 (goto-char (point-min))
762 (let ((re (org-make-options-regexp
764 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
765 "LINK_UP" "LINK_HOME" "SETUPFILE")
766 (mapcar 'car org-export-inbuffer-options-extra
))))
767 p key val text options js-up js-main js-css js-opt a pr
768 ext-setup-or-nil setup-contents
(start 0))
769 (while (or (and ext-setup-or-nil
770 (string-match re ext-setup-or-nil start
)
771 (setq start
(match-end 0)))
772 (and (setq ext-setup-or-nil nil start
0)
773 (re-search-forward re nil t
)))
774 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
775 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
777 ((setq a
(assoc key org-export-inbuffer-options-extra
))
779 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
780 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
781 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
782 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
783 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
784 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
785 ((string-equal key
"TEXT")
786 (setq text
(if text
(concat text
"\n" val
) val
)))
787 ((string-equal key
"OPTIONS")
788 (setq options
(concat val
" " options
)))
789 ((string-equal key
"LINK_UP")
790 (setq p
(plist-put p
:link-up val
)))
791 ((string-equal key
"LINK_HOME")
792 (setq p
(plist-put p
:link-home val
)))
793 ((equal key
"SETUPFILE")
794 (setq setup-contents
(org-file-contents
796 (org-remove-double-quotes
799 (if (not ext-setup-or-nil
)
800 (setq ext-setup-or-nil setup-contents start
0)
801 (setq ext-setup-or-nil
802 (concat (substring ext-setup-or-nil
0 start
)
803 "\n" setup-contents
"\n"
804 (substring ext-setup-or-nil start
)))))))
805 (setq p
(plist-put p
:text text
))
807 (setq p
(org-export-add-options-to-plist p options
)))
810 (defun org-export-add-options-to-plist (p options
)
811 "Parse an OPTONS line and set values in the property list P."
814 (let ((op '(("H" .
:headline-levels
)
815 ("num" .
:section-numbers
)
816 ("toc" .
:table-of-contents
)
817 ("\\n" .
:preserve-breaks
)
818 ("@" .
:expand-quoted-html
)
821 ("^" .
:sub-superscript
)
822 ("-" .
:special-strings
)
827 ("TeX" .
:TeX-macros
)
828 ("LaTeX" .
:LaTeX-fragments
)
829 ("skip" .
:skip-before-1st-heading
)
830 ("author" .
:author-info
)
831 ("timestamp" .
:time-stamp-file
)))
833 (while (setq o
(pop op
))
834 (if (string-match (concat (regexp-quote (car o
))
835 ":\\([^ \t\n\r;,.]*\\)")
837 (setq p
(plist-put p
(cdr o
)
838 (car (read-from-string
839 (match-string 1 options
))))))))))
842 (defun org-export-add-subtree-options (p pos
)
843 "Add options in subtree at position POS to property list P."
846 (when (org-at-heading-p)
848 ;; This is actually read in `org-export-get-title-from-subtree'
849 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
850 ;; (setq p (plist-put p :title a)))
851 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
852 (setq p
(plist-put p
:text a
)))
853 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
854 (setq p
(org-export-add-options-to-plist p a
)))))
857 (defun org-export-directory (type plist
)
858 (let* ((val (plist-get plist
:publishing-directory
))
860 (or (cdr (assoc type val
)) ".")
864 (defun org-export-process-option-filters (plist)
865 (let ((functions org-export-options-filters
) f
)
866 (while (setq f
(pop functions
))
867 (setq plist
(funcall f plist
))))
871 (defun org-export (&optional arg
)
872 "Export dispatcher for Org-mode.
873 When `org-export-run-in-background' is non-nil, try to run the command
874 in the background. This will be done only for commands that write
875 to a file. For details see the docstring of `org-export-run-in-background'.
877 The prefix argument ARG will be passed to the exporter. However, if
878 ARG is a double universal prefix `C-u C-u', that means to inverse the
879 value of `org-export-run-in-background'."
881 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
882 (help "[t] insert the export option template
883 \[v] limit export to visible part of outline tree
888 \[H] export as HTML to temporary buffer
889 \[R] export region as HTML
890 \[b] export as HTML and browse immediately
894 \[L] export as LaTeX to temporary buffer
896 \[i] export current file as iCalendar file
897 \[I] export all agenda files as iCalendar files
898 \[c] export agenda files into combined iCalendar file
900 \[F] publish current file
901 \[P] publish current project
902 \[X] publish... (project will be prompted for)
903 \[A] publish all projects")
905 '((?t org-insert-export-options-template nil
)
906 (?v org-export-visible nil
)
907 (?a org-export-as-ascii t
)
908 (?h org-export-as-html t
)
909 (?b org-export-as-html-and-open t
)
910 (?H org-export-as-html-to-buffer nil
)
911 (?R org-export-region-as-html nil
)
912 (?x org-export-as-xoxo t
)
913 (?l org-export-as-latex t
)
914 (?L org-export-as-latex-to-buffer nil
)
915 (?i org-export-icalendar-this-file t
)
916 (?I org-export-icalendar-all-agenda-files t
)
917 (?c org-export-icalendar-combine-agenda-files t
)
918 (?F org-publish-current-file t
)
919 (?P org-publish-current-project t
)
921 (?A org-publish-all t
)))
923 (save-window-excursion
924 (delete-other-windows)
925 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
927 (message "Select command: ")
928 (setq r1
(read-char-exclusive)))
929 (setq r2
(if (< r1
27) (+ r1
96) r1
))
930 (unless (setq ass
(assq r2 cmds
))
931 (error "No command associated with key %c" r1
))
932 (if (and bg
(nth 2 ass
))
933 ;; execute in background
934 (let ((p (start-process
935 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
937 (expand-file-name invocation-name invocation-directory
)
940 "--eval" "(require 'org-exp)"
941 "--eval" "(setq org-wait .2)"
943 "-f" (symbol-name (nth 1 ass
)))))
944 (set-process-sentinel p
'org-export-process-sentinel
)
945 (message "Background process \"%s\": started" p
))
946 ;; background processing not requested, or not possible
947 (call-interactively (nth 1 ass
)))))
949 (defun org-export-process-sentinel (process status
)
950 (if (string-match "\n+\\'" status
)
951 (setq status
(substring status
0 -
1)))
952 (message "Background process \"%s\": %s" process status
))
954 (defconst org-html-entities
995 ("Aring") ("AA".
"Å")
1084 ("varepsilon".
"ε")
1097 ("sigmaf") ("varsigma".
"ς")
1105 ("thetasym") ("vartheta".
"ϑ")
1108 ("bull") ("bullet".
"•")
1109 ("hellip") ("dots".
"…")
1119 ("larr") ("leftarrow".
"←") ("gets".
"←")
1120 ("uarr") ("uparrow".
"↑")
1121 ("rarr") ("to".
"→") ("rightarrow".
"→")
1122 ("darr")("downarrow".
"↓")
1123 ("harr") ("leftrightarrow".
"↔")
1124 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1125 ("lArr") ("Leftarrow".
"⇐")
1126 ("uArr") ("Uparrow".
"⇑")
1127 ("rArr") ("Rightarrow".
"⇒")
1128 ("dArr") ("Downarrow".
"⇓")
1129 ("hArr") ("Leftrightarrow".
"⇔")
1131 ("part") ("partial".
"∂")
1132 ("exist") ("exists".
"∃")
1133 ("empty") ("emptyset".
"∅")
1135 ("isin") ("in".
"∈")
1141 ("lowast") ("ast".
"∗")
1143 ("prop") ("proptp".
"∝")
1144 ("infin") ("infty".
"∞")
1145 ("ang") ("angle".
"∠")
1146 ("and") ("wedge".
"∧")
1147 ("or") ("vee".
"∨")
1153 ("cong") ("simeq".
"≅")
1154 ("asymp")("approx".
"≈")
1155 ("ne") ("neq".
"≠")
1159 ("sub") ("subset".
"⊂")
1160 ("sup") ("supset".
"⊃")
1167 ("sdot") ("cdot".
"⋅")
1174 ("loz") ("Diamond".
"◊")
1175 ("spades") ("spadesuit".
"♠")
1176 ("clubs") ("clubsuit".
"♣")
1177 ("hearts") ("diamondsuit".
"♥")
1178 ("diams") ("diamondsuit".
"♦")
1179 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1246 "Entities for TeX->HTML translation.
1247 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1248 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1249 In that case, \"\\ent\" will be translated to \"&other;\".
1250 The list contains HTML entities for Latin-1, Greek and other symbols.
1251 It is supplemented by a number of commonly used TeX macros with appropriate
1252 translations. There is currently no way for users to extend this.")
1254 ;;; General functions for all backends
1256 (defun org-export-preprocess-string (string &rest parameters
)
1257 "Cleanup STRING so that that the true exported has a more consistent source.
1258 This function takes STRING, which should be a buffer-string of an org-file
1259 to export. It then creates a temporary buffer where it does its job.
1260 The result is then again returned as a string, and the exporter works
1261 on this string to produce the exported version."
1263 (let* ((htmlp (plist-get parameters
:for-html
))
1264 (asciip (plist-get parameters
:for-ascii
))
1265 (latexp (plist-get parameters
:for-LaTeX
))
1266 (archived-trees (plist-get parameters
:archived-trees
))
1267 (inhibit-read-only t
)
1268 (drawers org-drawers
)
1269 (outline-regexp "\\*+ ")
1272 (with-current-buffer (get-buffer-create " org-mode-tmp")
1275 (setq case-fold-search t
)
1277 (run-hooks 'org-export-preprocess-hook
)
1279 ;; Remove license-to-kill stuff
1280 ;; The caller markes some stuff fo killing, stuff that has been
1281 ;; used to create the page title, for example.
1282 (org-export-kill-licensed-text)
1284 (let ((org-inhibit-startup t
)) (org-mode))
1285 (setq case-fold-search t
)
1286 (untabify (point-min) (point-max))
1288 ;; Handle incude files
1289 (org-export-handle-include-files)
1291 ;; Handle source code snippets
1292 (org-export-replace-src-segments)
1294 ;; Get rid of drawers
1295 (org-export-remove-or-extract-drawers drawers
1296 (plist-get parameters
:drawers
))
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 (org-export-remove-archived-trees archived-trees
)
1312 ;; Find all headings and compute the targets for them
1313 (setq target-alist
(org-export-define-heading-targets target-alist
))
1315 ;; Find targets in comments and move them out of comments,
1316 ;; but mark them as targets that should be invisible
1317 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1320 (org-export-protect-examples)
1322 ;; Protect backend specific stuff, throw away the others.
1323 (org-export-select-backend-specific-text
1324 (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1326 ;; Protect quoted subtrees
1327 (org-export-protect-quoted-subtrees)
1329 ;; Protect verbatim elements
1330 (org-export-protect-verbatim)
1332 ;; Blockquotes and verse
1333 (org-export-mark-blockquote-and-verse)
1335 ;; Remove comment environment and comment subtrees
1336 (org-export-remove-comment-blocks-and-subtrees)
1338 ;; Remove special table lines
1339 (when org-export-table-remove-special-lines
1340 (org-export-remove-special-table-lines))
1342 ;; Specific LaTeX stuff
1344 (require 'org-export-latex nil
)
1345 (org-export-latex-preprocess))
1347 ;; Specific ASCII stuff
1349 (org-export-ascii-preprocess))
1351 ;; Specific HTML stuff
1353 (org-export-html-preprocess parameters
))
1355 ;; Remove or replace comments
1356 (org-export-handle-comments (plist-get parameters
:comments
))
1358 ;; Find matches for radio targets and turn them into internal links
1359 (org-export-mark-radio-links)
1361 ;; Find all links that contain a newline and put them into a single line
1362 (org-export-concatenate-multiline-links)
1364 ;; Find all internal links. If they have a fuzzy match (i.e. not
1365 ;; a *dedicated* target match, let the link point to the
1366 ;; corresponding section.
1367 (org-export-target-internal-links target-alist
)
1369 ;; Normalize links: Convert angle and plain links into bracket links
1370 ;; and expand link abbreviations
1371 (org-export-normalize-links)
1373 ;; Find multiline emphasis and put them into single line
1374 (when (plist-get parameters
:emph-multiline
)
1375 (org-export-concatenate-multiline-emphasis))
1377 (setq rtn
(buffer-string)))
1378 (kill-buffer " org-mode-tmp")
1381 (defun org-export-kill-licensed-text ()
1382 "Remove all text that is marked with a :org-license-to-kill property."
1384 (while (setq p
(text-property-any (point-min) (point-max)
1385 :org-license-to-kill t
))
1386 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))))
1388 (defun org-export-define-heading-targets (target-alist)
1389 "Find all headings and define the targets for them.
1390 The new targets are added to TARGET-ALIST, which is also returned."
1391 (goto-char (point-min))
1392 (org-init-section-numbers)
1393 (let ((re (concat "^" org-outline-regexp
))
1395 (while (re-search-forward re nil t
)
1396 (setq level
(org-reduced-level
1397 (save-excursion (goto-char (point-at-bol))
1398 (org-outline-level))))
1399 (setq target
(org-solidify-link-text
1400 (format "sec-%s" (org-section-number level
))))
1401 (push (cons target target
) target-alist
)
1402 (add-text-properties
1403 (point-at-bol) (point-at-eol)
1404 (list 'target target
))))
1407 (defun org-export-handle-invisible-targets (target-alist)
1408 "Find targets in comments and move them out of comments.
1409 Mark them as invisible targets."
1411 (goto-char (point-min))
1412 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1413 ;; Check if the line before or after is a headline with a target
1414 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1415 (get-text-property (point-at-bol 2) 'target
)))
1417 ;; use the existing target in a neighboring line
1418 (setq tmp
(match-string 2))
1420 (and (looking-at "\n") (delete-char 1))
1421 (push (cons (org-solidify-link-text tmp
) target
)
1423 ;; Make an invisible target
1424 (replace-match "\\1(INVISIBLE)"))))
1427 (defun org-export-target-internal-links (target-alist)
1428 "Find all internal links and assign target to them.
1429 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1430 let the link point to the corresponding section."
1431 (goto-char (point-min))
1432 (while (re-search-forward org-bracket-link-regexp nil t
)
1434 (let* ((md (match-data))
1435 (desc (match-end 2))
1436 (link (org-link-unescape (match-string 1)))
1437 (slink (org-solidify-link-text link
))
1440 (or (cdr (assoc slink target-alist
))
1442 (unless (string-match org-link-types-re link
)
1443 (setq found
(condition-case nil
(org-link-search link
)
1446 (or (org-on-heading-p)
1447 (not (eq found
'dedicated
))))
1448 (or (get-text-property (point) 'target
)
1451 (1- (previous-single-property-change
1456 (goto-char (match-beginning 1))
1457 (setq props
(text-properties-at (point)))
1458 (delete-region (match-beginning 1) (match-end 1))
1461 (unless desc
(insert "][" link
))
1462 (add-text-properties pos
(point) props
))))))
1464 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1465 "Remove drawers, or extract the content.
1466 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1467 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1468 whose content to keep."
1469 (unless (eq t exp-drawers
)
1470 (goto-char (point-min))
1471 (let ((re (concat "^[ \t]*:\\("
1474 (org-delete-all exp-drawers
1475 (copy-sequence all-drawers
))
1477 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1478 (while (re-search-forward re nil t
)
1479 (replace-match "")))))
1481 (defun org-export-remove-archived-trees (export-archived-trees)
1482 "Remove archived trees.
1483 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1484 When it is t, the entire archived tree will be exported.
1485 When it is nil the entire tree including the headline will be removed
1487 (let ((re-archive (concat ":" org-archive-tag
":"))
1489 (when (not (eq export-archived-trees t
))
1490 (goto-char (point-min))
1491 (while (re-search-forward re-archive nil t
)
1492 (if (not (org-on-heading-p t
))
1493 (org-end-of-subtree t
)
1494 (beginning-of-line 1)
1495 (setq a
(if export-archived-trees
1496 (1+ (point-at-eol)) (point))
1497 b
(org-end-of-subtree t
))
1498 (if (> b a
) (delete-region a b
)))))))
1500 (defun org-export-protect-quoted-subtrees ()
1501 "Mark quoted subtrees with the protection property."
1502 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1503 (goto-char (point-min))
1504 (while (re-search-forward re-quote nil t
)
1505 (goto-char (match-beginning 0))
1507 (add-text-properties (point) (org-end-of-subtree t
)
1508 '(org-protected t
)))))
1510 (defun org-export-protect-verbatim ()
1511 "Mark verbatim snippets with the protection property."
1512 (goto-char (point-min))
1513 (while (re-search-forward org-verbatim-re nil t
)
1514 (add-text-properties (match-beginning 4) (match-end 4)
1516 (goto-char (1+ (match-end 4)))))
1518 (defun org-export-protect-examples ()
1519 "Protect code that should be exported as monospaced examples."
1520 (goto-char (point-min))
1521 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1522 (goto-char (match-end 0))
1523 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1525 (beginning-of-line 2)))
1526 (goto-char (point-min))
1527 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1528 (add-text-properties (match-beginning 0) (match-end 0)
1529 '(org-protected t
))))
1531 (defun org-export-select-backend-specific-text (backend)
1533 '((html "HTML" "BEGIN_HTML" "END_HTML")
1534 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1535 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1539 (setq fmt
(pop formatters
))
1540 (when (eq (car fmt
) backend
)
1541 ;; This is selected code, put it into the file for real
1542 (goto-char (point-min))
1543 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1544 ":[ \t]*\\(.*\\)") nil t
)
1545 (replace-match "\\1" t
)
1546 (add-text-properties
1547 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1548 '(org-protected t
))))
1549 (goto-char (point-min))
1550 (while (re-search-forward
1552 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1553 (cadddr fmt
) "\\>.*\n?") nil t
)
1554 (if (eq (car fmt
) backend
)
1556 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1558 ;; No, this is for a different backend, kill it
1559 (delete-region (match-beginning 0) (match-end 0)))))))
1561 (defun org-export-mark-blockquote-and-verse ()
1562 "Mark block quote and verse environments with special cookies.
1563 These special cookies will later be interpreted by the backend."
1565 (goto-char (point-min))
1566 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1568 (replace-match (if (equal (downcase (match-string 1)) "end")
1569 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1572 (goto-char (point-min))
1573 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1574 (replace-match (if (equal (downcase (match-string 1)) "end")
1575 "ORG-VERSE-END" "ORG-VERSE-START")
1578 (defun org-export-remove-comment-blocks-and-subtrees ()
1579 "Remove the comment environment, and also commented subtrees."
1580 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>")))
1581 ;; Remove comment environment
1582 (goto-char (point-min))
1583 (while (re-search-forward
1584 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1585 (replace-match "" t t
))
1586 ;; Remove subtrees that are commented
1587 (goto-char (point-min))
1588 (while (re-search-forward re-commented nil t
)
1589 (goto-char (match-beginning 0))
1590 (delete-region (point) (org-end-of-subtree t
)))))
1592 (defun org-export-handle-comments (commentsp)
1593 "Remove comments, or convert to backend-specific format.
1594 COMMENTSP can be a format string for publishing comments.
1595 When it is nil, all comments will be removed."
1596 (let ((re "^#\\(.*\n?\\)")
1598 (goto-char (point-min))
1599 (while (or (looking-at re
)
1600 (re-search-forward re nil t
))
1601 (setq pos
(match-beginning 0))
1603 (progn (add-text-properties
1604 (match-beginning 0) (match-end 0) '(org-protected t
))
1605 (replace-match (format commentsp
(match-string 1)) t t
))
1606 (goto-char (1+ pos
))
1609 (goto-char (max (point-min) (1- pos
))))))))
1611 (defun org-export-mark-radio-links ()
1612 "Find all matches for radio targets and turn them into internal links."
1613 (let ((re-radio (and org-target-link-regexp
1614 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1615 (goto-char (point-min))
1617 (while (re-search-forward re-radio nil t
)
1619 (replace-match "\\1[[\\2]]"))))))
1621 (defun org-export-remove-special-table-lines ()
1622 "Remove tables lines that are used for internal purposes."
1623 (goto-char (point-min))
1624 (while (re-search-forward "^[ \t]*|" nil t
)
1625 (beginning-of-line 1)
1626 (if (or (looking-at "[ \t]*| *[!_^] *|")
1627 (and (looking-at ".*?| *<[0-9]+> *|")
1628 (not (looking-at ".*?| *[^ <|]"))))
1629 (delete-region (max (point-min) (1- (point-at-bol)))
1633 (defun org-export-normalize-links ()
1634 "Convert all links to bracket links, and expand link abbreviations."
1635 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1636 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1637 (goto-char (point-min))
1638 (while (re-search-forward re-plain-link nil t
)
1639 (goto-char (1- (match-end 0)))
1641 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1642 ":" (match-string 3) "]]")))
1643 ;; added 'org-link face to links
1644 (put-text-property 0 (length s
) 'face
'org-link s
)
1645 (replace-match s t t
))))
1646 (goto-char (point-min))
1647 (while (re-search-forward re-angle-link nil t
)
1648 (goto-char (1- (match-end 0)))
1650 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1651 ":" (match-string 3) "]]")))
1652 (put-text-property 0 (length s
) 'face
'org-link s
)
1653 (replace-match s t t
))))
1654 (goto-char (point-min))
1655 (while (re-search-forward org-bracket-link-regexp nil t
)
1657 (let* ((xx (save-match-data
1658 (org-link-expand-abbrev (match-string 1))))
1663 (concat "[" xx
"]"))
1665 (put-text-property 0 (length s
) 'face
'org-link s
)
1666 (replace-match s t t
))))))
1668 (defun org-export-concatenate-multiline-links ()
1669 "Find multi-line links and put it all into a single line.
1670 This is to make sure that the line-processing export backends
1671 can work correctly."
1672 (goto-char (point-min))
1673 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1675 (replace-match "\\1 \\3")
1676 (goto-char (match-beginning 0)))))
1678 (defun org-export-concatenate-multiline-emphasis ()
1679 "Find multi-line emphasis and put it all into a single line.
1680 This is to make sure that the line-processing export backends
1681 can work correctly."
1682 (goto-char (point-min))
1683 (while (re-search-forward org-emph-re nil t
)
1684 (if (not (= (char-after (match-beginning 3))
1685 (char-after (match-beginning 4))))
1687 (subst-char-in-region (match-beginning 0) (match-end 0)
1689 (goto-char (1- (match-end 0))))
1690 (goto-char (1+ (match-beginning 0))))))
1692 (defun org-export-grab-title-from-buffer ()
1693 "Get a title for the current document, from looking at the buffer."
1694 (let ((inhibit-read-only t
))
1696 (goto-char (point-min))
1697 (let ((end (save-excursion (outline-next-heading) (point))))
1698 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1699 ;; Mark the line so that it will not be exported as normal text.
1701 (add-text-properties (match-beginning 0) (match-end 0)
1702 (list :org-license-to-kill t
)))
1703 ;; Return the title string
1704 (org-trim (match-string 0)))))))
1706 (defun org-export-get-title-from-subtree ()
1707 "Return subtree title and exclude it from export."
1708 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1711 (when (and (org-at-heading-p)
1712 (>= (org-end-of-subtree t t
) rend
))
1713 ;; This is a subtree, we take the title from the first heading
1715 (looking-at org-todo-line-regexp
)
1716 (setq title
(match-string 3))
1718 (add-text-properties (point) (1+ (point-at-eol))
1719 (list :org-license-to-kill t
)))
1720 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1723 (defun org-solidify-link-text (s &optional alist
)
1724 "Take link text and make a safe target out of it."
1729 (org-split-string s
"[ \t\r\n]+") "=="))
1730 (a (assoc rtn alist
)))
1733 (defun org-get-min-level (lines)
1734 "Get the minimum level in LINES."
1735 (let ((re "^\\(\\*+\\) ") l min
)
1737 (while (setq l
(pop lines
))
1738 (if (string-match re l
)
1739 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1742 ;; Variable holding the vector with section numbers
1743 (defvar org-section-numbers
(make-vector org-level-max
0))
1745 (defun org-init-section-numbers ()
1746 "Initialize the vector for the section numbers."
1748 (numbers (nreverse (org-split-string "" "\\.")))
1749 (depth (1- (length org-section-numbers
)))
1750 (i depth
) number-string
)
1753 (aset org-section-numbers i
0)
1754 (setq number-string
(or (car numbers
) "0"))
1755 (if (string-match "\\`[A-Z]\\'" number-string
)
1756 (aset org-section-numbers i
1757 (- (string-to-char number-string
) ?A -
1))
1758 (aset org-section-numbers i
(string-to-number number-string
)))
1762 (defun org-section-number (&optional level
)
1763 "Return a string with the current section number.
1764 When LEVEL is non-nil, increase section numbers on that level."
1765 (let* ((depth (1- (length org-section-numbers
)))
1767 (fmts (car org-export-section-number-format
))
1768 (term (cdr org-export-section-number-format
))
1773 (aset org-section-numbers
1774 level
(1+ (aref org-section-numbers level
))))
1775 (setq idx
(1+ level
))
1776 (while (<= idx depth
)
1778 (aset org-section-numbers idx
0))
1779 (setq idx
(1+ idx
))))
1781 (while (<= idx depth
)
1782 (when (> (aref org-section-numbers idx
) 0)
1783 (setq fmt
(or (pop fmts
) fmt
)
1785 n
(aref org-section-numbers idx
)
1787 (concat string sep
(org-number-to-counter n ctype
))
1788 (concat string
".0"))
1790 (setq idx
(1+ idx
)))
1792 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1793 (setq string
(replace-match "" t nil string
)))
1794 (if (string-match "\\(\\.0\\)+\\'" string
)
1795 (setq string
(replace-match "" t nil string
))))
1796 (concat string term
)))
1798 (defun org-number-to-counter (n type
)
1799 "Concert number N to a string counter, according to TYPE.
1800 TYPE must be a string, any of:
1804 I uppper case roman numeral
1805 i lower case roman numeral"
1807 ((equal type
"1") (number-to-string n
))
1808 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1809 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1810 ((equal type
"I") (org-number-to-roman n
))
1811 ((equal type
"i") (downcase (org-number-to-roman n
)))
1812 (t (error "Invalid counter type `%s'" type
))))
1814 (defun org-number-to-roman (n)
1815 "Convert integer N into a roman numeral."
1816 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1817 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1818 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1822 (number-to-string n
)
1824 (if (>= n
(caar roman
))
1825 (setq n
(- n
(caar roman
))
1826 res
(concat res
(cdar roman
)))
1830 (org-number-to-roman 1961)
1835 (defun org-export-handle-include-files ()
1836 "Include the contents of include files, with proper formatting."
1837 (let ((case-fold-search t
)
1838 params file markup lang start end
)
1839 (goto-char (point-min))
1840 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1841 (setq params
(read (concat "(" (match-string 1) ")"))
1842 file
(org-symname-or-string (pop params
))
1843 markup
(org-symname-or-string (pop params
))
1844 lang
(org-symname-or-string (pop params
)))
1845 (delete-region (match-beginning 0) (match-end 0))
1847 (not (file-exists-p file
))
1848 (not (file-readable-p file
)))
1849 (insert (format "CANNOT INCLUDE FILE %s" file
))
1851 (if (equal (downcase markup
) "src")
1852 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1854 (setq start
(format "#+begin_%s\n" markup
)
1855 end
(format "#+end_%s" markup
))))
1856 (insert (or start
""))
1857 (forward-char (nth 1 (insert-file-contents (expand-file-name file
))))
1858 (or (bolp) (newline))
1859 (insert (or end
""))))))
1861 (defun org-symname-or-string (s)
1863 (if s
(symbol-name s
) s
)
1866 ;;; Fontification of code
1867 ;; Currently only for th HTML backend, but who knows....
1868 (defun org-export-replace-src-segments ()
1869 "Replace source code segments with special code for export."
1870 (let ((case-fold-search t
)
1872 (goto-char (point-min))
1873 (while (re-search-forward
1874 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1876 (setq lang
(match-string 1) code
(match-string 2)
1877 trans
(org-export-format-source-code lang code
))
1878 (replace-match trans t t
))))
1880 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1882 (defun org-export-format-source-code (lang code
)
1883 "Format CODE from language LANG and return it formatted for export.
1884 Currently, this only does something for HTML export, for all other
1885 backends, it converts the segment into an EXAMPLE segment."
1889 ;; We are exporting to HTML
1890 (condition-case nil
(require 'htmlize
) (nil t
))
1891 (if (not (fboundp 'htmlize-region-for-paste
))
1893 ;; we do not have htmlize.el, or an old version of it
1895 "htmlize.el 1.34 or later is needed for source code formatting")
1896 (concat "#+BEGIN_EXAMPLE\n" code
1897 (if (string-match "\n\\'" code
) "" "\n")
1899 ;; ok, we are good to go
1900 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1901 (org-inhibit-startup t
)
1902 (org-startup-folded nil
)
1906 ;; Free up the protected stuff
1907 (goto-char (point-min))
1908 (while (re-search-forward "^," nil t
)
1911 (if (functionp mode
)
1914 (font-lock-fontify-buffer)
1915 (org-export-htmlize-region-for-paste
1916 (point-min) (point-max)))))
1917 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1918 (setq htmltext
(replace-match "<pre class=\"src\">"
1920 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1922 ;; This is not HTML, so just make it an example.
1923 (when (equal lang
"org")
1924 (while (string-match "^," code
)
1925 (setq code
(replace-match "" t t code
))))
1926 (concat "#+BEGIN_EXAMPLE\n" code
1927 (if (string-match "\n\\'" code
) "" "\n")
1928 "#+END_EXAMPLE\n")))))
1932 (defvar org-last-level nil
) ; dynamically scoped variable
1933 (defvar org-min-level nil
) ; dynamically scoped variable
1934 (defvar org-levels-open nil
) ; dynamically scoped parameter
1935 (defvar org-ascii-current-indentation nil
) ; For communication
1938 (defun org-export-as-ascii (arg)
1939 "Export the outline as a pretty ASCII file.
1940 If there is an active region, export only the region.
1941 The prefix ARG specifies how many levels of the outline should become
1942 underlined headlines. The default is 3."
1944 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1945 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1946 (org-infile-export-plist)))
1947 (region-p (org-region-active-p))
1948 (rbeg (and region-p
(region-beginning)))
1949 (rend (and region-p
(region-end)))
1954 (and (org-at-heading-p)
1955 (>= (org-end-of-subtree t t
) rend
)))))
1956 (opt-plist (if subtree-p
1957 (org-export-add-subtree-options opt-plist rbeg
)
1959 (custom-times org-display-custom-times
)
1960 (org-ascii-current-indentation '(0 .
0))
1964 (case-fold-search nil
)
1965 (filename (concat (file-name-as-directory
1966 (org-export-directory :ascii opt-plist
))
1967 (file-name-sans-extension
1969 (org-entry-get (region-beginning)
1970 "EXPORT_FILE_NAME" t
))
1971 (file-name-nondirectory buffer-file-name
)))
1973 (filename (if (equal (file-truename filename
)
1974 (file-truename buffer-file-name
))
1975 (concat filename
".txt")
1977 (buffer (find-file-noselect filename
))
1978 (org-levels-open (make-vector org-level-max nil
))
1979 (odd org-odd-levels-only
)
1980 (date (plist-get opt-plist
:date
))
1981 (author (plist-get opt-plist
:author
))
1982 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1983 (plist-get opt-plist
:title
)
1985 (plist-get opt-plist
:skip-before-1st-heading
))
1986 (org-export-grab-title-from-buffer))
1987 (file-name-sans-extension
1988 (file-name-nondirectory buffer-file-name
))))
1989 (email (plist-get opt-plist
:email
))
1990 (language (plist-get opt-plist
:language
))
1991 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1992 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1997 (if (org-region-active-p) (region-beginning) (point-min))
1998 (if (org-region-active-p) (region-end) (point-max))))
1999 (lines (org-split-string
2000 (org-export-preprocess-string
2003 :skip-before-1st-heading
2004 (plist-get opt-plist
:skip-before-1st-heading
)
2005 :drawers
(plist-get opt-plist
:drawers
)
2006 :verbatim-multiline t
2008 (plist-get opt-plist
:archived-trees
)
2009 :add-text
(plist-get opt-plist
:text
))
2011 thetoc have-headings first-heading-pos
2012 table-open table-buffer
)
2014 (let ((inhibit-read-only t
))
2016 (remove-text-properties (point-min) (point-max)
2017 '(:org-license-to-kill t
))))
2019 (setq org-min-level
(org-get-min-level lines
))
2020 (setq org-last-level org-min-level
)
2021 (org-init-section-numbers)
2023 (find-file-noselect filename
)
2025 (setq lang-words
(or (assoc language org-export-language-setup
)
2026 (assoc "en" org-export-language-setup
)))
2027 (switch-to-buffer-other-window buffer
)
2030 ;; create local variables for all options, to make sure all called
2031 ;; functions get the correct information
2033 (set (make-local-variable (cdr x
))
2034 (plist-get opt-plist
(car x
))))
2035 org-export-plist-vars
)
2036 (org-set-local 'org-odd-levels-only odd
)
2037 (setq umax
(if arg
(prefix-numeric-value arg
)
2038 org-export-headline-levels
))
2039 (setq umax-toc
(if (integerp org-export-with-toc
)
2040 (min org-export-with-toc umax
)
2044 (if title
(org-insert-centered title ?
=))
2046 (if (and (or author email
)
2047 org-export-author-info
)
2048 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2049 (if email
(concat " <" email
">") "")
2053 ((and date
(string-match "%" date
))
2054 (setq date
(format-time-string date
)))
2056 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2058 (if (and date org-export-time-stamp-file
)
2059 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2063 (if org-export-with-toc
2065 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2066 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
2067 (mapc '(lambda (line)
2068 (if (string-match org-todo-line-regexp
2070 ;; This is a headline
2072 (setq have-headings t
)
2073 (setq level
(- (match-end 1) (match-beginning 1))
2074 level
(org-tr-level level
)
2075 txt
(match-string 3 line
)
2077 (or (and org-export-mark-todo-in-toc
2079 (not (member (match-string 2 line
)
2080 org-done-keywords
)))
2082 (and org-export-mark-todo-in-toc
2084 (org-search-todo-below
2085 line lines level
))))
2086 (setq txt
(org-html-expand-for-ascii txt
))
2088 (while (string-match org-bracket-link-regexp txt
)
2091 (match-string (if (match-end 2) 3 1) txt
)
2094 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2096 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2098 (setq txt
(replace-match "" t t txt
)))
2099 (if (string-match quote-re0 txt
)
2100 (setq txt
(replace-match "" t t txt
)))
2102 (if org-export-with-section-numbers
2103 (setq txt
(concat (org-section-number level
)
2105 (if (<= level umax-toc
)
2110 (* (max 0 (- level org-min-level
)) 4) ?\
)
2111 (format (if todo
"%s (*)\n" "%s\n") txt
))
2113 (setq org-last-level level
))
2116 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2118 (org-init-section-numbers)
2119 (while (setq line
(pop lines
))
2120 ;; Remove the quoted HTML tags.
2121 (setq line
(org-html-expand-for-ascii line
))
2123 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
2124 (setq line
(replace-match "" t t line
)))
2125 ;; Replace internal links
2126 (while (string-match org-bracket-link-regexp line
)
2127 (setq line
(replace-match
2128 (if (match-end 3) "[\\3]" "[\\1]")
2131 (setq line
(org-translate-time line
)))
2133 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2135 (setq first-heading-pos
(or first-heading-pos
(point)))
2136 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2137 txt
(match-string 2 line
))
2138 (org-ascii-level-start level txt umax lines
))
2140 ((and org-export-with-tables
2141 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2142 (if (not table-open
)
2144 (setq table-open t table-buffer nil
))
2146 (setq table-buffer
(cons line table-buffer
))
2147 (when (or (not lines
)
2148 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2150 (setq table-open nil
2151 table-buffer
(nreverse table-buffer
))
2154 (org-fix-indentation x org-ascii-current-indentation
))
2155 (org-format-table-ascii table-buffer
)
2158 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2159 (if (and org-export-with-fixed-width
2160 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2161 (setq line
(replace-match "\\1" nil nil line
)))
2162 (insert line
"\n"))))
2166 ;; insert the table of contents
2168 (goto-char (point-min))
2169 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2171 (goto-char (match-beginning 0))
2173 (goto-char first-heading-pos
))
2174 (mapc 'insert thetoc
)
2175 (or (looking-at "[ \t]*\n[ \t]*\n")
2178 ;; Convert whitespace place holders
2179 (goto-char (point-min))
2181 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2182 (setq end
(next-single-property-change beg
'org-whitespace
))
2184 (delete-region beg end
)
2185 (insert (make-string (- end beg
) ?\
))))
2188 ;; remove display and invisible chars
2190 (goto-char (point-min))
2191 (while (setq beg
(next-single-property-change (point) 'display
))
2192 (setq end
(next-single-property-change beg
'display
))
2193 (delete-region beg end
)
2196 (goto-char (point-min))
2197 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2198 (setq end
(next-single-property-change beg
'org-cwidth
))
2199 (delete-region beg end
)
2201 (goto-char (point-min))))
2203 (defun org-export-ascii-preprocess ()
2204 "Do extra work for ASCII export"
2205 (goto-char (point-min))
2206 (while (re-search-forward org-verbatim-re nil t
)
2207 (goto-char (match-end 2))
2208 (backward-delete-char 1) (insert "'")
2209 (goto-char (match-beginning 2))
2210 (delete-char 1) (insert "`")
2211 (goto-char (match-end 2))))
2213 (defun org-search-todo-below (line lines level
)
2214 "Search the subtree below LINE for any TODO entries."
2215 (let ((rest (cdr (memq line lines
)))
2216 (re org-todo-line-regexp
)
2219 (while (setq line
(pop rest
))
2220 (if (string-match re line
)
2222 (setq lv
(- (match-end 1) (match-beginning 1))
2223 todo
(and (match-beginning 2)
2224 (not (member (match-string 2 line
)
2225 org-done-keywords
))))
2227 (if (<= lv level
) (throw 'exit nil
))
2228 (if todo
(throw 'exit t
))))))))
2230 (defun org-html-expand-for-ascii (line)
2231 "Handle quoted HTML for ASCII export."
2232 (if org-export-html-expand
2233 (while (string-match "@<[^<>\n]*>" line
)
2234 ;; We just remove the tags for now.
2235 (setq line
(replace-match "" nil nil line
))))
2238 (defun org-insert-centered (s &optional underline
)
2239 "Insert the string S centered and underline it with character UNDERLINE."
2240 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
2241 (insert (make-string ind ?\
) s
"\n")
2243 (insert (make-string ind ?\
)
2244 (make-string (string-width s
) underline
)
2247 (defun org-ascii-level-start (level title umax
&optional lines
)
2248 "Insert a new level in ASCII export."
2249 (let (char (n (- level umax
1)) (ind 0))
2252 (insert (make-string (* 2 n
) ?\
)
2253 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2254 org-export-ascii-bullets
))
2256 ;; find the indentation of the next non-empty line
2259 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2260 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2261 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2263 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2264 (if (or (not (equal (char-before) ?
\n))
2265 (not (equal (char-before (1- (point))) ?
\n)))
2267 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2268 (unless org-export-with-tags
2269 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2270 (setq title
(replace-match "" t t title
))))
2271 (if org-export-with-section-numbers
2272 (setq title
(concat (org-section-number level
) " " title
)))
2273 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2274 (setq org-ascii-current-indentation
'(0 .
0)))))
2277 (defun org-export-visible (type arg
)
2278 "Create a copy of the visible part of the current buffer, and export it.
2279 The copy is created in a temporary buffer and removed after use.
2280 TYPE is the final key (as a string) that also select the export command in
2281 the `C-c C-e' export dispatcher.
2282 As a special case, if the you type SPC at the prompt, the temporary
2283 org-mode file will not be removed but presented to you so that you can
2284 continue to use it. The prefix arg ARG is passed through to the exporting
2288 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2289 (read-char-exclusive))
2290 current-prefix-arg
))
2291 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2292 (error "Invalid export key"))
2293 (let* ((binding (cdr (assoc type
2294 '((?a . org-export-as-ascii
)
2295 (?\C-a . org-export-as-ascii
)
2296 (?b . org-export-as-html-and-open
)
2297 (?\C-b . org-export-as-html-and-open
)
2298 (?h . org-export-as-html
)
2299 (?H . org-export-as-html-to-buffer
)
2300 (?R . org-export-region-as-html
)
2301 (?x . org-export-as-xoxo
)))))
2302 (keepp (equal type ?\
))
2303 (file buffer-file-name
)
2304 (buffer (get-buffer-create "*Org Export Visible*"))
2306 ;; Need to hack the drawers here.
2308 (goto-char (point-min))
2309 (while (re-search-forward org-drawer-regexp nil t
)
2310 (goto-char (match-beginning 1))
2311 (or (org-invisible-p) (org-flag-drawer nil
))))
2312 (with-current-buffer buffer
(erase-buffer))
2314 (setq s
(goto-char (point-min)))
2315 (while (not (= (point) (point-max)))
2316 (goto-char (org-find-invisible))
2317 (append-to-buffer buffer s
(point))
2318 (setq s
(goto-char (org-find-visible))))
2319 (org-cycle-hide-drawers 'all
)
2320 (goto-char (point-min))
2322 ;; Copy all comment lines to the end, to make sure #+ settings are
2323 ;; still available for the second export step. Kind of a hack, but
2324 ;; does do the trick.
2325 (if (looking-at "#[^\r\n]*")
2326 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2327 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2328 (append-to-buffer buffer
(1+ (match-beginning 0))
2329 (min (point-max) (1+ (match-end 0))))))
2331 (let ((buffer-file-name file
)
2332 (org-inhibit-startup t
))
2335 (unless keepp
(funcall binding arg
))))
2337 (kill-buffer buffer
)
2338 (switch-to-buffer-other-window buffer
)
2339 (goto-char (point-min)))))
2341 (defun org-find-visible ()
2343 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2344 (get-char-property s
'invisible
)))
2346 (defun org-find-invisible ()
2348 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2349 (not (get-char-property s
'invisible
))))
2354 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2355 (defun org-get-current-options ()
2356 "Return a string with current options as keyword options.
2357 Does include HTML export options as well as TODO and CATEGORY stuff."
2358 (require 'org-archive
)
2365 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2366 #+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
2373 #+PRIORITIES: %c %c %c
2375 #+STARTUP: %s %s %s %s %s
2381 (buffer-name) (user-full-name) user-mail-address
2382 (format-time-string (car org-time-stamp-formats
))
2383 org-export-default-language
2384 org-export-headline-levels
2385 org-export-with-section-numbers
2387 org-export-preserve-breaks
2388 org-export-html-expand
2389 org-export-with-fixed-width
2390 org-export-with-tables
2391 org-export-with-sub-superscripts
2392 org-export-with-special-strings
2393 org-export-with-footnotes
2394 org-export-with-emphasize
2395 org-export-with-TeX-macros
2396 org-export-with-LaTeX-fragments
2397 org-export-skip-text-before-1st-heading
2398 org-export-with-drawers
2399 org-export-with-tags
2400 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2401 org-export-html-link-up
2402 org-export-html-link-home
2403 (file-name-nondirectory buffer-file-name
)
2404 "TODO FEEDBACK VERIFY DONE"
2405 "Me Jason Marie DONE"
2406 org-highest-priority org-lowest-priority org-default-priority
2407 (mapconcat 'identity org-drawers
" ")
2408 (cdr (assoc org-startup-folded
2409 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2410 (if org-odd-levels-only
"odd" "oddeven")
2411 (if org-hide-leading-stars
"hidestars" "showstars")
2412 (if org-startup-align-all-tables
"align" "noalign")
2413 (cond ((eq org-log-done t
) "logdone")
2414 ((equal org-log-done
'note
) "lognotedone")
2415 ((not org-log-done
) "nologdone"))
2416 (or (mapconcat (lambda (x)
2418 ((equal '(:startgroup
) x
) "{")
2419 ((equal '(:endgroup
) x
) "}")
2420 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2422 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2423 (mapconcat 'identity org-file-tags
" ")
2424 org-archive-location
2425 "org file:~/org/%s.org"
2428 (defun org-export-html-preprocess (parameters)
2429 ;; Convert LaTeX fragments to images
2430 (when (plist-get parameters
:LaTeX-fragments
)
2432 (concat "ltxpng/" (file-name-sans-extension
2433 (file-name-nondirectory
2434 org-current-export-file
)))
2435 org-current-export-dir nil
"Creating LaTeX image %s"))
2436 (message "Exporting..."))
2439 (defun org-insert-export-options-template ()
2440 "Insert into the buffer a template with information for exporting."
2442 (if (not (bolp)) (newline))
2443 (let ((s (org-get-current-options)))
2444 (and (string-match "#\\+CATEGORY" s
)
2445 (setq s
(substring s
0 (match-beginning 0))))
2449 (defun org-export-as-html-and-open (arg)
2450 "Export the outline as HTML and immediately open it with a browser.
2451 If there is an active region, export only the region.
2452 The prefix ARG specifies how many levels of the outline should become
2453 headlines. The default is 3. Lower levels will become bulleted lists."
2455 (org-export-as-html arg
'hidden
)
2456 (org-open-file buffer-file-name
))
2459 (defun org-export-as-html-batch ()
2460 "Call `org-export-as-html', may be used in batch processing as
2462 --load=$HOME/lib/emacs/org.el
2463 --eval \"(setq org-export-headline-levels 2)\"
2464 --visit=MyFile --funcall org-export-as-html-batch"
2465 (org-export-as-html org-export-headline-levels
'hidden
))
2468 (defun org-export-as-html-to-buffer (arg)
2469 "Call `org-exort-as-html` with output to a temporary buffer.
2470 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2472 (org-export-as-html arg nil nil
"*Org HTML Export*")
2473 (switch-to-buffer-other-window "*Org HTML Export*"))
2476 (defun org-replace-region-by-html (beg end
)
2477 "Assume the current region has org-mode syntax, and convert it to HTML.
2478 This can be used in any buffer. For example, you could write an
2479 itemized list in org-mode syntax in an HTML buffer and then use this
2480 command to convert it."
2482 (let (reg html buf pop-up-frames
)
2483 (save-window-excursion
2485 (setq html
(org-export-region-as-html
2487 (setq reg
(buffer-substring beg end
)
2488 buf
(get-buffer-create "*Org tmp*"))
2489 (with-current-buffer buf
2493 (setq html
(org-export-region-as-html
2494 (point-min) (point-max) t
'string
)))
2496 (delete-region beg end
)
2500 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2501 "Convert region from BEG to END in org-mode buffer to HTML.
2502 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2503 contents, and only produce the region of converted text, useful for
2504 cut-and-paste operations.
2505 If BUFFER is a buffer or a string, use/create that buffer as a target
2506 of the converted HTML. If BUFFER is the symbol `string', return the
2507 produced HTML as a string and leave not buffer behind. For example,
2508 a Lisp program could call this function in the following way:
2510 (setq html (org-export-region-as-html beg end t 'string))
2512 When called interactively, the output buffer is selected, and shown
2513 in a window. A non-interactive call will only return the buffer."
2514 (interactive "r\nP")
2515 (when (interactive-p)
2516 (setq buffer
"*Org HTML Export*"))
2517 (let ((transient-mark-mode t
) (zmacs-regions t
)
2520 (set-mark (point)) ;; to activate the region
2522 (setq rtn
(org-export-as-html
2525 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2526 (if (and (interactive-p) (bufferp rtn
))
2527 (switch-to-buffer-other-window rtn
)
2530 (defvar html-table-tag nil
) ; dynamically scoped into this.
2532 (defun org-export-as-html (arg &optional hidden ext-plist
2533 to-buffer body-only pub-dir
)
2534 "Export the outline as a pretty HTML file.
2535 If there is an active region, export only the region. The prefix
2536 ARG specifies how many levels of the outline should become
2537 headlines. The default is 3. Lower levels will become bulleted
2538 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2539 EXT-PLIST is a property list with external parameters overriding
2540 org-mode's default settings, but still inferior to file-local
2541 settings. When TO-BUFFER is non-nil, create a buffer with that
2542 name and export to that buffer. If TO-BUFFER is the symbol
2543 `string', don't leave any buffer behind but just return the
2544 resulting HTML as a string. When BODY-ONLY is set, don't produce
2545 the file header and footer, simply return the content of
2546 <body>...</body>, without even the body tags themselves. When
2547 PUB-DIR is set, use this as the publishing directory."
2550 ;; Make sure we have a file name when we need it.
2551 (when (and (not (or to-buffer body-only
))
2552 (not buffer-file-name
))
2553 (if (buffer-base-buffer)
2554 (org-set-local 'buffer-file-name
2555 (with-current-buffer (buffer-base-buffer)
2557 (error "Need a file name to be able to export.")))
2559 (message "Exporting...")
2560 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2561 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2562 (setq-default org-done-keywords org-done-keywords
)
2563 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2565 (org-export-process-option-filters
2566 (org-combine-plists (org-default-export-plist)
2568 (org-infile-export-plist))))
2570 (style (plist-get opt-plist
:style
))
2571 (html-extension (plist-get opt-plist
:html-extension
))
2572 (link-validate (plist-get opt-plist
:link-validation-function
))
2573 valid thetoc have-headings first-heading-pos
2574 (odd org-odd-levels-only
)
2575 (region-p (org-region-active-p))
2576 (rbeg (and region-p
(region-beginning)))
2577 (rend (and region-p
(region-end)))
2582 (and (org-at-heading-p)
2583 (>= (org-end-of-subtree t t
) rend
)))))
2584 (opt-plist (if subtree-p
2585 (org-export-add-subtree-options opt-plist rbeg
)
2587 ;; The following two are dynamically scoped into other
2589 (org-current-export-dir
2590 (or pub-dir
(org-export-directory :html opt-plist
)))
2591 (org-current-export-file buffer-file-name
)
2592 (level 0) (line "") (origline "") txt todo
2595 (filename (if to-buffer nil
2598 (file-name-sans-extension
2600 (org-entry-get (region-beginning)
2601 "EXPORT_FILE_NAME" t
))
2602 (file-name-nondirectory buffer-file-name
)))
2604 (file-name-as-directory
2605 (or pub-dir
(org-export-directory :html opt-plist
))))))
2606 (current-dir (if buffer-file-name
2607 (file-name-directory buffer-file-name
)
2609 (buffer (if to-buffer
2611 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2612 (t (get-buffer-create to-buffer
)))
2613 (find-file-noselect filename
)))
2614 (org-levels-open (make-vector org-level-max nil
))
2615 (date (plist-get opt-plist
:date
))
2616 (author (plist-get opt-plist
:author
))
2617 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2618 (plist-get opt-plist
:title
)
2620 (plist-get opt-plist
:skip-before-1st-heading
))
2621 (org-export-grab-title-from-buffer))
2622 (and buffer-file-name
2623 (file-name-sans-extension
2624 (file-name-nondirectory buffer-file-name
)))
2626 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2627 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2628 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2632 (local-list-type nil
)
2633 (local-list-indent nil
)
2634 (llt org-plain-list-ordered-item-terminator
)
2635 (email (plist-get opt-plist
:email
))
2636 (language (plist-get opt-plist
:language
))
2640 (coding-system (and (boundp 'buffer-file-coding-system
)
2641 buffer-file-coding-system
))
2642 (coding-system-for-write (or org-export-html-coding-system
2644 (save-buffer-coding-system (or org-export-html-coding-system
2646 (charset (and coding-system-for-write
2647 (fboundp 'coding-system-get
)
2648 (coding-system-get coding-system-for-write
2652 (if region-p
(region-beginning) (point-min))
2653 (if region-p
(region-end) (point-max))))
2656 (org-export-preprocess-string
2660 :skip-before-1st-heading
2661 (plist-get opt-plist
:skip-before-1st-heading
)
2662 :drawers
(plist-get opt-plist
:drawers
)
2664 (plist-get opt-plist
:archived-trees
)
2666 (plist-get opt-plist
:text
)
2668 (plist-get opt-plist
:LaTeX-fragments
))
2671 table-buffer table-orig-buffer
2672 ind item-type starter didclose
2673 rpl path desc descp desc1 desc2 link
2674 snumber fnc item-tag
2677 (let ((inhibit-read-only t
))
2679 (remove-text-properties (point-min) (point-max)
2680 '(:org-license-to-kill t
))))
2682 (message "Exporting...")
2684 (setq org-min-level
(org-get-min-level lines
))
2685 (setq org-last-level org-min-level
)
2686 (org-init-section-numbers)
2689 ((and date
(string-match "%" date
))
2690 (setq date
(format-time-string date
)))
2692 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2694 ;; Get the language-dependent settings
2695 (setq lang-words
(or (assoc language org-export-language-setup
)
2696 (assoc "en" org-export-language-setup
)))
2698 ;; Switch to the output buffer
2700 (let ((inhibit-read-only t
)) (erase-buffer))
2703 (and (fboundp 'set-buffer-file-coding-system
)
2704 (set-buffer-file-coding-system coding-system-for-write
))
2706 (let ((case-fold-search nil
)
2707 (org-odd-levels-only odd
))
2708 ;; create local variables for all options, to make sure all called
2709 ;; functions get the correct information
2711 (set (make-local-variable (cdr x
))
2712 (plist-get opt-plist
(car x
))))
2713 org-export-plist-vars
)
2714 (setq umax
(if arg
(prefix-numeric-value arg
)
2715 org-export-headline-levels
))
2716 (setq umax-toc
(if (integerp org-export-with-toc
)
2717 (min org-export-with-toc umax
)
2722 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2723 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2724 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2725 lang=\"%s\" xml:lang=\"%s\">
2728 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2729 <meta name=\"generator\" content=\"Org-mode\"/>
2730 <meta name=\"generated\" content=\"%s\"/>
2731 <meta name=\"author\" content=\"%s\"/>
2735 language language
(org-html-expand title
)
2736 (or charset
"iso-8859-1") date author style
))
2738 (insert (or (plist-get opt-plist
:preamble
) ""))
2740 (when (plist-get opt-plist
:auto-preamble
)
2741 (if title
(insert (format org-export-html-title-format
2742 (org-html-expand title
))))))
2744 (if (and org-export-with-toc
(not body-only
))
2746 (push (format "<h%d>%s</h%d>\n"
2747 org-export-html-toplevel-hlevel
2749 org-export-html-toplevel-hlevel
)
2751 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2752 (push "<ul>\n<li>" thetoc
)
2754 (mapcar '(lambda (line)
2755 (if (string-match org-todo-line-regexp line
)
2756 ;; This is a headline
2758 (setq have-headings t
)
2759 (setq level
(- (match-end 1) (match-beginning 1))
2760 level
(org-tr-level level
)
2761 txt
(save-match-data
2763 (org-export-cleanup-toc-line
2764 (match-string 3 line
))))
2766 (or (and org-export-mark-todo-in-toc
2768 (not (member (match-string 2 line
)
2769 org-done-keywords
)))
2771 (and org-export-mark-todo-in-toc
2773 (org-search-todo-below
2774 line lines level
))))
2776 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2777 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2778 (if (string-match quote-re0 txt
)
2779 (setq txt
(replace-match "" t t txt
)))
2780 (setq snumber
(org-section-number level
))
2781 (if org-export-with-section-numbers
2782 (setq txt
(concat snumber
" " txt
)))
2783 (if (<= level
(max umax umax-toc
))
2784 (setq head-count
(+ head-count
1)))
2785 (if (<= level umax-toc
)
2787 (if (> level org-last-level
)
2789 (setq cnt
(- level org-last-level
))
2790 (while (>= (setq cnt
(1- cnt
)) 0)
2791 (push "\n<ul>\n<li>" thetoc
))
2792 (push "\n" thetoc
)))
2793 (if (< level org-last-level
)
2795 (setq cnt
(- org-last-level level
))
2796 (while (>= (setq cnt
(1- cnt
)) 0)
2797 (push "</li>\n</ul>" thetoc
))
2798 (push "\n" thetoc
)))
2799 ;; Check for targets
2800 (while (string-match org-any-target-regexp line
)
2801 (setq line
(replace-match
2802 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2804 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2805 (setq txt
(replace-match "" t t txt
)))
2809 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2810 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2811 snumber txt
) thetoc
)
2813 (setq org-last-level level
))
2817 (while (> org-last-level
(1- org-min-level
))
2818 (setq org-last-level
(1- org-last-level
))
2819 (push "</li>\n</ul>\n" thetoc
))
2820 (push "</div>\n" thetoc
)
2821 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2824 (org-init-section-numbers)
2826 (while (setq line
(pop lines
) origline line
)
2829 ;; end of quote section?
2830 (when (and inquote
(string-match "^\\*+ " line
))
2833 ;; inside a quote section?
2835 (insert (org-html-protect line
) "\n")
2836 (throw 'nextline nil
))
2839 (when (and org-export-with-fixed-width
2840 (string-match "^[ \t]*:\\(.*\\)" line
))
2844 (insert (org-html-protect (match-string 1 line
)) "\n")
2845 (when (or (not lines
)
2846 (not (string-match "^[ \t]*\\(:.*\\)"
2849 (insert "</pre>\n"))
2850 (throw 'nextline nil
))
2853 (when (get-text-property 0 'org-protected line
)
2855 (when (re-search-backward
2856 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2857 (setq par
(match-string 1))
2858 (replace-match "\\2\n"))
2861 (not (string-match "^[ \t]*:" (car lines
)))
2862 (or (= (length (car lines
)) 0)
2863 (get-text-property 0 'org-protected
(car lines
))))
2864 (insert (pop lines
) "\n"))
2865 (and par
(insert "<p>\n")))
2866 (throw 'nextline nil
))
2869 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2870 (insert "\n<hr/>\n")
2871 (throw 'nextline nil
))
2873 ;; Blockquotes and verse
2874 (when (equal "ORG-BLOCKQUOTE-START" line
)
2875 (insert "<blockquote>\n<p>\n")
2876 (throw 'nextline nil
))
2877 (when (equal "ORG-BLOCKQUOTE-END" line
)
2878 (insert "</p>\n</blockquote>\n")
2879 (throw 'nextline nil
))
2880 (when (equal "ORG-VERSE-START" line
)
2881 (insert "<verse>\n<p>\n")
2882 (throw 'nextline nil
))
2883 (when (equal "ORG-VERSE-END" line
)
2884 (insert "</p>\n</verse>\n")
2885 (throw 'nextline nil
))
2887 ;; make targets to anchors
2888 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2891 (setq line
(replace-match
2892 (concat "@<a name=\""
2893 (org-solidify-link-text (match-string 1 line
))
2896 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2897 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2898 (setq line
(replace-match
2899 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2900 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2903 (setq line
(replace-match
2904 (concat "@<a name=\""
2905 (org-solidify-link-text (match-string 1 line
))
2906 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2909 (setq line
(org-html-handle-time-stamps line
))
2911 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2912 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2913 ;; Also handle sub_superscripts and checkboxes
2914 (or (string-match org-table-hline-regexp line
)
2915 (setq line
(org-html-expand line
)))
2919 (while (string-match org-bracket-link-analytic-regexp line start
)
2920 (setq start
(match-beginning 0))
2921 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2922 (setq path
(match-string 3 line
))
2923 (setq desc1
(if (match-end 5) (match-string 5 line
))
2924 desc2
(if (match-end 2) (concat type
":" path
) path
)
2925 descp
(and desc1
(not (equal desc1 desc2
)))
2926 desc
(or desc1 desc2
))
2927 ;; Make an image out of the description if that is so wanted
2928 (when (and descp
(org-file-image-p desc
))
2930 (if (string-match "^file:" desc
)
2931 (setq desc
(substring desc
(match-end 0)))))
2932 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2933 ;; FIXME: do we need to unescape here somewhere?
2935 ((equal type
"internal")
2939 (org-solidify-link-text
2940 (save-match-data (org-link-unescape path
)) nil
)
2941 "\">" desc
"</a>")))
2942 ((member type
'("http" "https"))
2943 ;; standard URL, just check if we need to inline an image
2944 (if (and (or (eq t org-export-html-inline-images
)
2945 (and org-export-html-inline-images
(not descp
)))
2946 (org-file-image-p path
))
2947 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2948 (setq link
(concat type
":" path
))
2949 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2950 ((member type
'("ftp" "mailto" "news"))
2952 (setq link
(concat type
":" path
))
2953 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2954 ((string= type
"file")
2956 (let* ((filename path
)
2957 (abs-p (file-name-absolute-p filename
))
2958 thefile file-is-image-p search
)
2960 (if (string-match "::\\(.*\\)" filename
)
2961 (setq search
(match-string 1 filename
)
2962 filename
(replace-match "" t nil filename
)))
2964 (if (functionp link-validate
)
2965 (funcall link-validate filename current-dir
)
2967 (setq file-is-image-p
(org-file-image-p filename
))
2968 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2969 (when (and org-export-html-link-org-files-as-html
2970 (string-match "\\.org$" thefile
))
2971 (setq thefile
(concat (substring thefile
0
2972 (match-beginning 0))
2973 "." html-extension
))
2975 ;; make sure this is can be used as target search
2976 (not (string-match "^[0-9]*$" search
))
2977 (not (string-match "^\\*" search
))
2978 (not (string-match "^/.*/$" search
)))
2979 (setq thefile
(concat thefile
"#"
2980 (org-solidify-link-text
2981 (org-link-unescape search
)))))
2982 (when (string-match "^file:" desc
)
2983 (setq desc
(replace-match "" t t desc
))
2984 (if (string-match "\\.org$" desc
)
2985 (setq desc
(replace-match "" t t desc
))))))
2986 (setq rpl
(if (and file-is-image-p
2987 (or (eq t org-export-html-inline-images
)
2988 (and org-export-html-inline-images
2990 (concat "<img src=\"" thefile
"\"/>")
2991 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2992 (if (not valid
) (setq rpl desc
))))
2994 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2997 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3000 ;; just publish the path, as default
3001 (setq rpl
(concat "<i><" type
":"
3002 (save-match-data (org-link-unescape path
))
3004 (setq line
(replace-match rpl t t line
)
3005 start
(+ start
(length rpl
))))
3008 (if (and (string-match org-todo-line-regexp line
)
3009 (match-beginning 2))
3012 (concat (substring line
0 (match-beginning 2))
3014 (if (member (match-string 2 line
)
3017 "\">" (match-string 2 line
)
3018 "</span>" (substring line
(match-end 2)))))
3020 ;; Does this contain a reference to a footnote?
3021 (when org-export-with-footnotes
3023 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3024 (if (get-text-property (match-beginning 2) 'org-protected line
)
3025 (setq start
(match-end 2))
3026 (let ((n (match-string 2 line
)))
3030 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3031 (match-string 1 line
) n n n
)
3035 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3036 ;; This is a headline
3037 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3038 txt
(match-string 2 line
))
3039 (if (string-match quote-re0 txt
)
3040 (setq txt
(replace-match "" t t txt
)))
3041 (if (<= level
(max umax umax-toc
))
3042 (setq head-count
(+ head-count
1)))
3044 ;; Close any local lists before inserting a new header line
3045 (while local-list-type
3046 (org-close-li (car local-list-type
))
3047 (insert (format "</%sl>\n" (car local-list-type
)))
3048 (pop local-list-type
))
3049 (setq local-list-indent nil
3051 (setq first-heading-pos
(or first-heading-pos
(point)))
3052 (org-html-level-start level txt umax
3053 (and org-export-with-toc
(<= level umax
))
3056 (when (string-match quote-re line
)
3060 ((and org-export-with-tables
3061 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3062 (if (not table-open
)
3064 (setq table-open t table-buffer nil table-orig-buffer nil
))
3066 (setq table-buffer
(cons line table-buffer
)
3067 table-orig-buffer
(cons origline table-orig-buffer
))
3068 (when (or (not lines
)
3069 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3071 (setq table-open nil
3072 table-buffer
(nreverse table-buffer
)
3073 table-orig-buffer
(nreverse table-orig-buffer
))
3074 (org-close-par-maybe)
3075 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3080 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3081 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3082 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3083 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3085 (setq ind
(org-get-string-indentation line
)
3086 item-type
(if (match-beginning 4) "o" "u")
3087 starter
(if (match-beginning 2)
3088 (substring (match-string 2 line
) 0 -
1))
3089 line
(substring line
(match-beginning 5))
3091 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3093 item-tag
(match-string 1 line
)
3094 line
(substring line
(match-end 0))))
3095 (when (and (not (equal item-type
"d"))
3096 (not (string-match "[^ \t]" line
)))
3097 ;; empty line. Pretend indentation is large.
3098 (setq ind
(if org-empty-line-terminates-plain-lists
3100 (1+ (or (car local-list-indent
) 1)))))
3102 (while (and in-local-list
3103 (or (and (= ind
(car local-list-indent
))
3105 (< ind
(car local-list-indent
))))
3107 (org-close-li (car local-list-type
))
3108 (insert (format "</%sl>\n" (car local-list-type
)))
3109 (pop local-list-type
) (pop local-list-indent
)
3110 (setq in-local-list local-list-indent
))
3113 (or (not in-local-list
)
3114 (> ind
(car local-list-indent
))))
3115 ;; Start new (level of) list
3116 (org-close-par-maybe)
3118 ((equal item-type
"u") "<ul>\n<li>\n")
3119 ((equal item-type
"o") "<ol>\n<li>\n")
3120 ((equal item-type
"d")
3121 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3122 (push item-type local-list-type
)
3123 (push ind local-list-indent
)
3124 (setq in-local-list t
))
3126 ;; continue current list
3127 (org-close-li (car local-list-type
))
3129 ((equal (car local-list-type
) "d")
3130 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3133 ;; we did close a list, normal text follows: need <p>
3135 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3138 (if (equal (match-string 1 line
) "X")
3140 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3143 ;; Empty lines start a new paragraph. If hand-formatted lists
3144 ;; are not fully interpreted, lines starting with "-", "+", "*"
3145 ;; also start a new paragraph.
3146 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3148 ;; Is this the start of a footnote?
3149 (when org-export-with-footnotes
3150 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3151 (org-close-par-maybe)
3152 (let ((n (match-string 1 line
)))
3153 (setq line
(replace-match
3154 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
))
3155 (setq line
(concat line
"</p>")))))
3157 ;; Check if the line break needs to be conserved
3159 ((string-match "\\\\\\\\[ \t]*$" line
)
3160 (setq line
(replace-match "<br/>" t t line
)))
3161 (org-export-preserve-breaks
3162 (setq line
(concat line
"<br/>"))))
3164 (insert line
"\n")))))
3166 ;; Properly close all local lists and other lists
3167 (when inquote
(insert "</pre>\n"))
3169 ;; Close any local lists before inserting a new header line
3170 (while local-list-type
3171 (org-close-li (car local-list-type
))
3172 (insert (format "</%sl>\n" (car local-list-type
)))
3173 (pop local-list-type
))
3174 (setq local-list-indent nil
3176 (org-html-level-start 1 nil umax
3177 (and org-export-with-toc
(<= level umax
))
3179 ;; the </div> to lose the last text-... div.
3183 (when (plist-get opt-plist
:auto-postamble
)
3184 (insert "<div id=\"postamble\">")
3185 (when (and org-export-author-info author
)
3186 (insert "<p class=\"author\"> "
3187 (nth 1 lang-words
) ": " author
"\n")
3189 (if (listp (split-string email
",+ *"))
3191 (insert "<a href=\"mailto:" e
"\"><"
3193 (split-string email
",+ *"))
3194 (insert "<a href=\"mailto:" email
"\"><"
3195 email
"></a>\n")))
3197 (when (and date org-export-time-stamp-file
)
3198 (insert "<p class=\"date\"> "
3199 (nth 2 lang-words
) ": "
3203 (if org-export-html-with-timestamp
3204 (insert org-export-html-html-helper-timestamp
))
3205 (insert (or (plist-get opt-plist
:postamble
) ""))
3206 (insert "</body>\n</html>\n"))
3209 (if (eq major-mode default-major-mode
) (html-mode))
3211 ;; insert the table of contents
3212 (goto-char (point-min))
3214 (if (or (re-search-forward
3215 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3217 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3219 (goto-char (match-beginning 0))
3221 (goto-char first-heading-pos
)
3222 (when (looking-at "\\s-*</p>")
3223 (goto-char (match-end 0))
3225 (insert "<div id=\"table-of-contents\">\n")
3226 (mapc 'insert thetoc
)
3227 (insert "</div>\n"))
3228 ;; remove empty paragraphs and lists
3229 (goto-char (point-min))
3230 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3232 (goto-char (point-min))
3233 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3235 (goto-char (point-min))
3236 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3238 ;; Convert whitespace place holders
3239 (goto-char (point-min))
3241 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3242 (setq n
(get-text-property beg
'org-whitespace
)
3243 end
(next-single-property-change beg
'org-whitespace
))
3245 (delete-region beg end
)
3246 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3247 (make-string n ?x
)))))
3248 (or to-buffer
(save-buffer))
3249 (goto-char (point-min))
3250 (message "Exporting... done")
3251 (if (eq to-buffer
'string
)
3252 (prog1 (buffer-substring (point-min) (point-max))
3253 (kill-buffer (current-buffer)))
3254 (current-buffer)))))
3256 (defvar org-table-colgroup-info nil
)
3257 (defun org-format-table-ascii (lines)
3258 "Format a table for ascii export."
3260 (setq lines
(org-split-string lines
"\n")))
3261 (if (not (string-match "^[ \t]*|" (car lines
)))
3262 ;; Table made by table.el - test for spanning
3265 ;; A normal org table
3266 ;; Get rid of hlines at beginning and end
3267 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3268 (setq lines
(nreverse lines
))
3269 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3270 (setq lines
(nreverse lines
))
3271 (when org-export-table-remove-special-lines
3272 ;; Check if the table has a marking column. If yes remove the
3273 ;; column and the special lines
3274 (setq lines
(org-table-clean-before-export lines
)))
3275 ;; Get rid of the vertical lines except for grouping
3276 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3278 (while (setq line
(pop lines
))
3279 (if (string-match org-table-hline-regexp line
)
3280 (and (string-match "|\\(.*\\)|" line
)
3281 (setq line
(replace-match " \\1" t nil line
)))
3282 (setq start
0 vl1 vl
)
3283 (while (string-match "|" line start
)
3284 (setq start
(match-end 0))
3285 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3289 (defun org-colgroup-info-to-vline-list (info)
3292 (setq last new new
(pop info
))
3293 (if (or (memq last
'(:end
:startend
))
3294 (memq new
'(:start
:startend
)))
3297 (setq vl
(nreverse vl
))
3298 (and vl
(setcar vl nil
))
3301 (defvar org-table-number-regexp
) ; defined in org-table.el
3302 (defun org-format-table-html (lines olines
)
3303 "Find out which HTML converter to use and return the HTML code."
3305 (setq lines
(org-split-string lines
"\n")))
3306 (if (string-match "^[ \t]*|" (car lines
))
3307 ;; A normal org table
3308 (org-format-org-table-html lines
)
3309 ;; Table made by table.el - test for spanning
3310 (let* ((hlines (delq nil
(mapcar
3312 (if (string-match "^[ \t]*\\+-" x
) x
3315 (first (car hlines
))
3316 (ll (and (string-match "\\S-+" first
)
3317 (match-string 0 first
)))
3318 (re (concat "^[ \t]*" (regexp-quote ll
)))
3319 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3321 (if (and (not spanning
)
3322 (not org-export-prefer-native-exporter-for-tables
))
3323 ;; We can use my own converter with HTML conversions
3324 (org-format-table-table-html lines
)
3325 ;; Need to use the code generator in table.el, with the original text.
3326 (org-format-table-table-html-using-table-generate-source olines
)))))
3328 (defvar org-table-number-fraction
) ; defined in org-table.el
3329 (defun org-format-org-table-html (lines &optional splice
)
3330 "Format a table into HTML."
3331 (require 'org-table
)
3332 ;; Get rid of hlines at beginning and end
3333 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3334 (setq lines
(nreverse lines
))
3335 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3336 (setq lines
(nreverse lines
))
3337 (when org-export-table-remove-special-lines
3338 ;; Check if the table has a marking column. If yes remove the
3339 ;; column and the special lines
3340 (setq lines
(org-table-clean-before-export lines
)))
3342 (let ((head (and org-export-highlight-first-table-line
3344 (lambda (x) (string-match "^[ \t]*|-" x
))
3347 tbopen line fields html gr colgropen
)
3348 (if splice
(setq head nil
))
3349 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3351 (while (setq line
(pop lines
))
3353 (if (string-match "^[ \t]*|-" line
)
3356 (push (if head
"</thead>" "</tbody>") html
)
3357 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3358 (setq head nil
) ;; head ends here, first time around
3360 (throw 'next-line t
)))
3361 ;; Break the line into fields
3362 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3363 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3364 (setq nlines
(1+ nlines
) i -
1)
3365 (push (concat "<tr>"
3369 (if (and (< i nlines
)
3370 (string-match org-table-number-regexp x
))
3371 (incf (aref fnum i
)))
3373 (concat (car org-export-table-header-tags
) x
3374 (cdr org-export-table-header-tags
))
3375 (concat (car org-export-table-data-tags
) x
3376 (cdr org-export-table-data-tags
))))
3380 (unless splice
(if tbopen
(push "</tbody>" html
)))
3381 (unless splice
(push "</table>\n" html
))
3382 (setq html
(nreverse html
))
3384 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3387 (setq gr
(pop org-table-colgroup-info
))
3388 (format "%s<col align=\"%s\"></col>%s"
3389 (if (memq gr
'(:start
:startend
))
3391 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3394 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3396 (if (memq gr
'(:end
:startend
))
3397 (progn (setq colgropen nil
) "</colgroup>")
3401 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3402 (push html-table-tag html
))
3403 (concat (mapconcat 'identity html
"\n") "\n")))
3405 (defun org-table-clean-before-export (lines)
3406 "Check if the table has a marking column.
3407 If yes remove the column and the special lines."
3408 (setq org-table-colgroup-info nil
)
3411 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3412 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3415 (setq org-table-clean-did-remove-column nil
)
3420 ((string-match "^[ \t]*| */ *|" x
)
3421 (setq org-table-colgroup-info
3423 (cond ((member x
'("<" "<")) :start
)
3424 ((member x
'(">" ">")) :end
)
3425 ((member x
'("<>" "<>")) :startend
)
3427 (org-split-string x
"[ \t]*|[ \t]*")))
3431 (setq org-table-clean-did-remove-column t
)
3436 ((string-match "^[ \t]*| */ *|" x
)
3437 (setq org-table-colgroup-info
3439 (cond ((member x
'("<" "<")) :start
)
3440 ((member x
'(">" ">")) :end
)
3441 ((member x
'("<>" "<>")) :startend
)
3443 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3445 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3446 nil
) ; ignore this line
3447 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3448 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3449 ;; remove the first column
3450 (replace-match "\\1|" t nil x
))))
3453 (defun org-format-table-table-html (lines)
3454 "Format a table generated by table.el into HTML.
3455 This conversion does *not* use `table-generate-source' from table.el.
3456 This has the advantage that Org-mode's HTML conversions can be used.
3457 But it has the disadvantage, that no cell- or row-spanning is allowed."
3458 (let (line field-buffer
3459 (head org-export-highlight-first-table-line
)
3461 (setq html
(concat html-table-tag
"\n"))
3462 (while (setq line
(pop lines
))
3463 (setq empty
" ")
3465 (if (string-match "^[ \t]*\\+-" line
)
3476 (if (equal x
"") (setq x empty
))
3478 (concat (car org-export-table-header-tags
) x
3479 (cdr org-export-table-header-tags
))
3480 (concat (car org-export-table-data-tags
) x
3481 (cdr org-export-table-data-tags
))))
3485 (setq field-buffer nil
)))
3487 (throw 'next-line t
)))
3488 ;; Break the line into fields and store the fields
3489 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3491 (setq field-buffer
(mapcar
3493 (concat x
"<br/>" (pop fields
)))
3495 (setq field-buffer fields
))))
3496 (setq html
(concat html
"</table>\n"))
3499 (defun org-format-table-table-html-using-table-generate-source (lines)
3500 "Format a table into html, using `table-generate-source' from table.el.
3501 This has the advantage that cell- or row-spanning is allowed.
3502 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3504 (with-current-buffer (get-buffer-create " org-tmp1 ")
3506 (insert (mapconcat 'identity lines
"\n"))
3507 (goto-char (point-min))
3508 (if (not (re-search-forward "|[^+]" nil t
))
3509 (error "Error processing table"))
3510 (table-recognize-table)
3511 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3512 (table-generate-source 'html
" org-tmp2 ")
3513 (set-buffer " org-tmp2 ")
3514 (buffer-substring (point-min) (point-max))))
3516 (defun org-html-handle-time-stamps (s)
3517 "Format time stamps in string S, or remove them."
3520 (while (string-match org-maybe-keyword-time-regexp s
)
3521 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3522 ;; never export CLOCK
3524 (or b
(setq b
(substring s
0 (match-beginning 0))))
3525 (if (not org-export-with-timestamps
)
3526 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3527 s
(substring s
(match-end 0)))
3529 r
(substring s
0 (match-beginning 0))
3531 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3532 (match-string 1 s
)))
3533 (format " @<span class=\"timestamp\">%s@</span>"
3535 (org-translate-time (match-string 3 s
)) 1 -
1)))
3536 s
(substring s
(match-end 0)))))
3537 ;; Line break if line started and ended with time stamp stuff
3540 (setq r
(concat r s
))
3541 (unless (string-match "\\S-" (concat b s
))
3542 (setq r
(concat r
"@<br/>")))
3545 (defun org-export-htmlize-region-for-paste (beg end
)
3546 "Convert the region to HTML, using htmlize.el.
3547 This is much like `htmlize-region-for-paste', only that it uses
3548 the settings define in the org-... variables."
3549 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3550 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3551 (htmlbuf (htmlize-region beg end
)))
3553 (with-current-buffer htmlbuf
3554 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3555 (plist-get htmlize-buffer-places
'content-end
)))
3556 (kill-buffer htmlbuf
))))
3559 (defun org-export-htmlize-generate-css ()
3560 "Create the CSS for all font definitions in the current Emacs session.
3561 Use this to create face definitions in your CSS style file that can then
3562 be used by code snippets transformed by htmlize.
3563 This command just produces a buffer that contains class definitions for all
3564 faces used in the current Emacs session. You can copy and paste the ones you
3565 need into your CSS file.
3567 If you then set `org-export-htmlize-output-type' to `css', calls to
3568 the function `org-export-htmlize-region-for-paste' will produce code
3569 that uses these same face definitions."
3572 (and (get-buffer "*html*") (kill-buffer "*html*"))
3574 (let ((fl (face-list))
3575 (htmlize-css-name-prefix "org-")
3576 (htmlize-output-type 'css
)
3578 (while (setq f
(pop fl
)
3579 i
(and f
(face-attribute f
:inherit
)))
3580 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3581 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3582 (htmlize-region (point-min) (point-max))))
3583 (switch-to-buffer "*html*")
3584 (goto-char (point-min))
3585 (if (re-search-forward "<style" nil t
)
3586 (delete-region (point-min) (match-beginning 0)))
3587 (if (re-search-forward "</style>" nil t
)
3588 (delete-region (1+ (match-end 0)) (point-max)))
3589 (beginning-of-line 1)
3590 (if (looking-at " +") (replace-match ""))
3591 (goto-char (point-min)))
3593 (defun org-html-protect (s)
3594 ;; convert & to &, < to < and > to >
3596 (while (string-match "&" s start
)
3597 (setq s
(replace-match "&" t t s
)
3598 start
(1+ (match-beginning 0))))
3599 (while (string-match "<" s
)
3600 (setq s
(replace-match "<" t t s
)))
3601 (while (string-match ">" s
)
3602 (setq s
(replace-match ">" t t s
))))
3605 (defun org-export-cleanup-toc-line (s)
3606 "Remove tags and time staps from lines going into the toc."
3607 (when (memq org-export-with-tags
'(not-in-toc nil
))
3608 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3609 (setq s
(replace-match "" t t s
))))
3610 (when org-export-remove-timestamps-from-toc
3611 (while (string-match org-maybe-keyword-time-regexp s
)
3612 (setq s
(replace-match "" t t s
))))
3613 (while (string-match org-bracket-link-regexp s
)
3614 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3618 (defun org-html-expand (string)
3619 "Prepare STRING for HTML export. Applies all active conversions.
3620 If there are links in the string, don't modify these."
3621 (let* ((re (concat org-bracket-link-regexp
"\\|"
3622 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3624 (while (setq m
(string-match re string
))
3625 (setq s
(substring string
0 m
)
3626 l
(match-string 0 string
)
3627 string
(substring string
(match-end 0)))
3628 (push (org-html-do-expand s
) res
)
3630 (push (org-html-do-expand string
) res
)
3631 (apply 'concat
(nreverse res
))))
3633 (defun org-html-do-expand (s)
3634 "Apply all active conversions to translate special ASCII to HTML."
3635 (setq s
(org-html-protect s
))
3636 (if org-export-html-expand
3638 (while (string-match "@<\\([^&]*\\)>" s
)
3639 (setq s
(replace-match "<\\1>" t nil s
)))))
3640 (if org-export-with-emphasize
3641 (setq s
(org-export-html-convert-emphasize s
)))
3642 (if org-export-with-special-strings
3643 (setq s
(org-export-html-convert-special-strings s
)))
3644 (if org-export-with-sub-superscripts
3645 (setq s
(org-export-html-convert-sub-super s
)))
3646 (if org-export-with-TeX-macros
3647 (let ((start 0) wd ass
)
3648 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3649 (if (get-text-property (match-beginning 0) 'org-protected s
)
3650 (setq start
(match-end 0))
3651 (setq wd
(match-string 1 s
))
3652 (if (setq ass
(assoc wd org-html-entities
))
3653 (setq s
(replace-match (or (cdr ass
)
3654 (concat "&" (car ass
) ";"))
3656 (setq start
(+ start
(length wd
))))))))
3659 (defun org-create-multibrace-regexp (left right n
)
3660 "Create a regular expression which will match a balanced sexp.
3661 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3662 as single character strings.
3663 The regexp returned will match the entire expression including the
3664 delimiters. It will also define a single group which contains the
3665 match except for the outermost delimiters. The maximum depth of
3666 stacked delimiters is N. Escaping delimiters is not possible."
3667 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3670 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3673 re
(concat re or next
)
3674 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3675 (concat left
"\\(" re
"\\)" right
)))
3677 (defvar org-match-substring-regexp
3679 "\\([^\\]\\)\\([_^]\\)\\("
3680 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3682 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3684 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3685 "The regular expression matching a sub- or superscript.")
3687 (defvar org-match-substring-with-braces-regexp
3689 "\\([^\\]\\)\\([_^]\\)\\("
3690 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3692 "The regular expression matching a sub- or superscript, forcing braces.")
3694 (defconst org-export-html-special-string-regexps
3695 '(("\\\\-" .
"­")
3696 ("---\\([^-]\\)" .
"—\\1")
3697 ("--\\([^-]\\)" .
"–\\1")
3698 ("\\.\\.\\." .
"…"))
3699 "Regular expressions for special string conversion.")
3701 (defun org-export-html-convert-special-strings (string)
3702 "Convert special characters in STRING to HTML."
3703 (let ((all org-export-html-special-string-regexps
)
3705 (while (setq a
(pop all
))
3706 (setq re
(car a
) rpl
(cdr a
) start
0)
3707 (while (string-match re string start
)
3708 (if (get-text-property (match-beginning 0) 'org-protected string
)
3709 (setq start
(match-end 0))
3710 (setq string
(replace-match rpl t nil string
)))))
3713 (defun org-export-html-convert-sub-super (string)
3714 "Convert sub- and superscripts in STRING to HTML."
3715 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3716 (while (string-match org-match-substring-regexp string s
)
3718 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3719 ((get-text-property (match-beginning 2) 'org-protected string
)
3720 (setq s
(match-end 2)))
3722 (setq s
(match-end 1)
3723 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3724 c
(or (match-string 8 string
)
3725 (match-string 6 string
)
3726 (match-string 5 string
))
3727 string
(replace-match
3728 (concat (match-string 1 string
)
3729 "<" key
">" c
"</" key
">")
3731 (while (string-match "\\\\\\([_^]\\)" string
)
3732 (setq string
(replace-match (match-string 1 string
) t t string
)))
3735 (defun org-export-html-convert-emphasize (string)
3738 (while (string-match org-emph-re string s
)
3740 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3741 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3742 (setq s
(match-beginning 0)
3745 (match-string 1 string
)
3746 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3747 (match-string 4 string
)
3748 (nth 3 (assoc (match-string 3 string
)
3749 org-emphasis-alist
))
3750 (match-string 5 string
))
3751 string
(replace-match rpl t t string
)
3752 s
(+ s
(- (length rpl
) 2)))
3756 (defvar org-par-open nil
)
3757 (defun org-open-par ()
3758 "Insert <p>, but first close previous paragraph if any."
3759 (org-close-par-maybe)
3761 (setq org-par-open t
))
3762 (defun org-close-par-maybe ()
3763 "Close paragraph if there is one open."
3766 (setq org-par-open nil
)))
3767 (defun org-close-li (&optional type
)
3768 "Close <li> if necessary."
3769 (org-close-par-maybe)
3770 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3772 (defvar body-only
) ; dynamically scoped into this.
3773 (defun org-html-level-start (level title umax with-toc head-count
)
3774 "Insert a new level in HTML export.
3775 When TITLE is nil, just close all open levels."
3776 (org-close-par-maybe)
3777 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3781 (if (aref org-levels-open
(1- l
))
3783 (org-html-level-close l umax
)
3784 (aset org-levels-open
(1- l
) nil
)))
3787 ;; If title is nil, this means this function is called to close
3788 ;; all levels, so the rest is done only if title is given
3789 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3790 (setq title
(replace-match
3791 (if org-export-with-tags
3794 " <span class=\"tag\">"
3795 (mapconcat 'identity
(org-split-string
3796 (match-string 1 title
) ":")
3803 (if (aref org-levels-open
(1- level
))
3807 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3808 (insert "<li>" title
"<br/>\n")))
3809 (aset org-levels-open
(1- level
) t
)
3810 (org-close-par-maybe)
3812 (insert (format "<ul>\n<li id=\"%s\">" target
)
3814 (insert "<ul>\n<li>" title
"<br/>\n"))))
3815 (aset org-levels-open
(1- level
) t
)
3816 (setq snumber
(org-section-number level
))
3817 (if (and org-export-with-section-numbers
(not body-only
))
3818 (setq title
(concat snumber
" " title
)))
3819 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3820 (unless (= head-count
1) (insert "\n</div>\n"))
3821 (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"
3822 snumber level level snumber title level snumber
))
3825 (defun org-get-text-property-any (pos prop
&optional object
)
3826 (or (get-text-property pos prop object
)
3827 (and (setq pos
(next-single-property-change pos prop object
))
3828 (get-text-property pos prop object
))))
3830 (defun org-html-level-close (level max-outline-level
)
3831 "Terminate one level in HTML export."
3832 (if (<= level max-outline-level
)
3835 (insert "</ul>\n")))
3837 ;;; iCalendar export
3840 (defun org-export-icalendar-this-file ()
3841 "Export current file as an iCalendar file.
3842 The iCalendar file will be located in the same directory as the Org-mode
3843 file, but with extension `.ics'."
3845 (org-export-icalendar nil buffer-file-name
))
3848 (defun org-export-icalendar-all-agenda-files ()
3849 "Export all files in `org-agenda-files' to iCalendar .ics files.
3850 Each iCalendar file will be located in the same directory as the Org-mode
3851 file, but with extension `.ics'."
3853 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3856 (defun org-export-icalendar-combine-agenda-files ()
3857 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3858 The file is stored under the name `org-combined-agenda-icalendar-file'."
3860 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3862 (defun org-export-icalendar (combine &rest files
)
3863 "Create iCalendar files for all elements of FILES.
3864 If COMBINE is non-nil, combine all calendar entries into a single large
3865 file and store it under the name `org-combined-agenda-icalendar-file'."
3867 (org-prepare-agenda-buffers files
)
3868 (let* ((dir (org-export-directory
3869 :ical
(list :publishing-directory
3870 org-export-publishing-directory
)))
3871 file ical-file ical-buffer category started org-agenda-new-buffers
)
3872 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3875 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3876 org-combined-agenda-icalendar-file
3877 (expand-file-name org-combined-agenda-icalendar-file dir
))
3878 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3879 (set-buffer ical-buffer
) (erase-buffer))
3880 (while (setq file
(pop files
))
3882 (org-check-agenda-file file
)
3883 (set-buffer (org-get-agenda-file-buffer file
))
3885 (setq ical-file
(concat (file-name-as-directory dir
)
3886 (file-name-sans-extension
3887 (file-name-nondirectory buffer-file-name
))
3889 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3890 (with-current-buffer ical-buffer
(erase-buffer)))
3891 (setq category
(or org-category
3892 (file-name-sans-extension
3893 (file-name-nondirectory buffer-file-name
))))
3894 (if (symbolp category
) (setq category
(symbol-name category
)))
3895 (let ((standard-output ical-buffer
))
3897 (and (not started
) (setq started t
)
3898 (org-start-icalendar-file org-icalendar-combined-name
))
3899 (org-start-icalendar-file category
))
3900 (org-print-icalendar-entries combine
)
3901 (when (or (and combine
(not files
)) (not combine
))
3902 (org-finish-icalendar-file)
3903 (set-buffer ical-buffer
)
3905 (run-hooks 'org-after-save-iCalendar-file-hook
)
3906 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3908 (org-release-buffers org-agenda-new-buffers
))))
3910 (defvar org-after-save-iCalendar-file-hook nil
3911 "Hook run after an iCalendar file has been saved.
3912 The iCalendar buffer is still current when this hook is run.
3913 A good way to use this is to tell a desktop calenndar application to re-read
3914 the iCalendar file.")
3916 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3917 (defun org-print-icalendar-entries (&optional combine
)
3918 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3919 When COMBINE is non nil, add the category to each line."
3920 (require 'org-agenda
)
3921 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3922 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3923 (dts (org-ical-ts-to-string
3924 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3926 hd ts ts2 state status
(inc t
) pos b sexp rrule
3927 scheduledp deadlinep prefix
3928 tmp pri category entry location summary desc uid
3929 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3930 (org-refresh-category-properties)
3932 (goto-char (point-min))
3933 (while (re-search-forward re1 nil t
)
3936 (when (boundp 'org-icalendar-verify-function
)
3937 (unless (funcall org-icalendar-verify-function
)
3938 (outline-next-heading)
3941 (setq pos
(match-beginning 0)
3944 hd
(condition-case nil
3945 (org-icalendar-cleanup-string
3947 (error (throw :skip nil
)))
3948 summary
(org-icalendar-cleanup-string
3949 (org-entry-get nil
"SUMMARY"))
3950 desc
(org-icalendar-cleanup-string
3951 (or (org-entry-get nil
"DESCRIPTION")
3952 (and org-icalendar-include-body
(org-get-entry)))
3953 t org-icalendar-include-body
)
3954 location
(org-icalendar-cleanup-string
3955 (org-entry-get nil
"LOCATION"))
3956 uid
(if org-icalendar-store-UID
3958 (or (org-id-get) (org-id-new)))
3959 category
(org-get-category)
3960 deadlinep nil scheduledp nil
)
3961 (if (looking-at re2
)
3963 (goto-char (match-end 0))
3964 (setq ts2
(match-string 1)
3965 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
3966 (setq tmp
(buffer-substring (max (point-min)
3967 (- pos org-ds-keyword-length
))
3969 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3972 (replace-match "\\1" t nil ts
))
3974 deadlinep
(string-match org-deadline-regexp tmp
)
3975 scheduledp
(string-match org-scheduled-regexp tmp
)
3976 ;; donep (org-entry-is-done-p)
3978 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
3979 (if (or (string-match org-tr-regexp hd
)
3980 (string-match org-ts-regexp hd
))
3981 (setq hd
(replace-match "" t t hd
)))
3982 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3984 (concat "\nRRULE:FREQ="
3987 '(("d" .
"DAILY")("w" .
"WEEKLY")
3988 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3989 ";INTERVAL=" (match-string 1 ts
)))
3991 (setq summary
(or summary hd
))
3992 (if (string-match org-bracket-link-regexp summary
)
3994 (replace-match (if (match-end 3)
3995 (match-string 3 summary
)
3996 (match-string 1 summary
))
3998 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3999 (if scheduledp
(setq summary
(concat "S: " summary
)))
4000 (if (string-match "\\`<%%" ts
)
4001 (with-current-buffer sexp-buffer
4002 (insert (substring ts
1 -
1) " " summary
"\n"))
4003 (princ (format "BEGIN:VEVENT
4011 (org-ical-ts-to-string ts
"DTSTART")
4012 (org-ical-ts-to-string ts2
"DTEND" inc
)
4014 (if (and desc
(string-match "\\S-" desc
))
4015 (concat "\nDESCRIPTION: " desc
) "")
4016 (if (and location
(string-match "\\S-" location
))
4017 (concat "\nLOCATION: " location
) "")
4019 (when (and org-icalendar-include-sexps
4020 (condition-case nil
(require 'icalendar
) (error nil
))
4021 (fboundp 'icalendar-export-region
))
4022 ;; Get all the literal sexps
4023 (goto-char (point-min))
4024 (while (re-search-forward "^&?%%(" nil t
)
4027 (setq b
(match-beginning 0))
4028 (goto-char (1- (match-end 0)))
4031 (setq sexp
(buffer-substring b
(point)))
4032 (with-current-buffer sexp-buffer
4033 (insert sexp
"\n"))))
4034 (princ (org-diary-to-ical-string sexp-buffer
))
4035 (kill-buffer sexp-buffer
))
4037 (when org-icalendar-include-todo
4038 (setq prefix
"TODO-")
4039 (goto-char (point-min))
4040 (while (re-search-forward org-todo-line-regexp nil t
)
4043 (when (boundp 'org-icalendar-verify-function
)
4044 (unless (funcall org-icalendar-verify-function
)
4045 (outline-next-heading)
4048 (setq state
(match-string 2))
4049 (setq status
(if (member state org-done-keywords
)
4050 "COMPLETED" "NEEDS-ACTION"))
4052 (or (not (member state org-done-keywords
))
4053 (eq org-icalendar-include-todo
'all
))
4054 (not (member org-archive-tag
(org-get-tags-at)))
4056 (setq hd
(match-string 3)
4057 summary
(org-icalendar-cleanup-string
4058 (org-entry-get nil
"SUMMARY"))
4059 desc
(org-icalendar-cleanup-string
4060 (or (org-entry-get nil
"DESCRIPTION")
4061 (and org-icalendar-include-body
(org-get-entry)))
4062 t org-icalendar-include-body
)
4063 location
(org-icalendar-cleanup-string
4064 (org-entry-get nil
"LOCATION"))
4065 uid
(if org-icalendar-store-UID
4067 (or (org-id-get) (org-id-new))))
4068 (if (string-match org-bracket-link-regexp hd
)
4069 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4070 (match-string 1 hd
))
4072 (if (string-match org-priority-regexp hd
)
4073 (setq pri
(string-to-char (match-string 2 hd
))
4074 hd
(concat (substring hd
0 (match-beginning 1))
4075 (substring hd
(match-end 1))))
4076 (setq pri org-default-priority
))
4077 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
4078 (- org-lowest-priority org-highest-priority
))))))
4080 (princ (format "BEGIN:VTODO
4092 (if (and location
(string-match "\\S-" location
))
4093 (concat "\nLOCATION: " location
) "")
4094 (if (and desc
(string-match "\\S-" desc
))
4095 (concat "\nDESCRIPTION: " desc
) "")
4099 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4100 "Take out stuff and quote what needs to be quoted.
4101 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4102 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4107 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4108 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4109 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4110 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4112 (while (string-match "\\([,;]\\)" s start
)
4113 (setq start
(+ (match-beginning 0) 2)
4114 s
(replace-match "\\\\\\1" nil nil s
))))
4116 (while (string-match "[ \t]*\n[ \t]*" s
)
4117 (setq s
(replace-match "\\n" t t s
))))
4118 (setq s
(org-trim s
))
4121 (if (and (numberp maxlength
)
4122 (> (length s
) maxlength
))
4123 (setq s
(substring s
0 maxlength
)))))
4126 (defun org-get-entry ()
4127 "Clean-up description string."
4129 (org-back-to-heading t
)
4130 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4132 (defun org-start-icalendar-file (name)
4133 "Start an iCalendar file by inserting the header."
4134 (let ((user user-full-name
)
4135 (name (or name
"unknown"))
4136 (timezone (cadr (current-time-zone))))
4138 (format "BEGIN:VCALENDAR
4141 PRODID:-//%s//Emacs with Org-mode//EN
4143 CALSCALE:GREGORIAN\n" name user timezone
))))
4145 (defun org-finish-icalendar-file ()
4146 "Finish an iCalendar file by inserting the END statement."
4147 (princ "END:VCALENDAR\n"))
4149 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4150 "Take a time string S and convert it to iCalendar format.
4151 KEYWORD is added in front, to make a complete line like DTSTART....
4152 When INC is non-nil, increase the hour by two (if time string contains
4153 a time), or the day by one (if it does not contain a time)."
4154 (let ((t1 (org-parse-time-string s
'nodefault
))
4155 t2 fmt have-time time
)
4156 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4157 (setq t2 t1 have-time t
)
4158 (setq t2
(org-parse-time-string s
)))
4159 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4160 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4163 (if org-agenda-default-appointment-duration
4164 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4167 (setq time
(encode-time s mi h d m y
)))
4168 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4169 (concat keyword
(format-time-string fmt time
))))
4173 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
4174 (with-current-buffer buffer
4175 (apply 'insert output
)))
4176 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4179 (defun org-export-as-xoxo (&optional buffer
)
4180 "Export the org buffer as XOXO.
4181 The XOXO buffer is named *xoxo-<source buffer name>*"
4182 (interactive (list (current-buffer)))
4183 ;; A quickie abstraction
4185 ;; Output everything as XOXO
4186 (with-current-buffer (get-buffer buffer
)
4187 (let* ((pos (point))
4188 (opt-plist (org-combine-plists (org-default-export-plist)
4189 (org-infile-export-plist)))
4190 (filename (concat (file-name-as-directory
4191 (org-export-directory :xoxo opt-plist
))
4192 (file-name-sans-extension
4193 (file-name-nondirectory buffer-file-name
))
4195 (out (find-file-noselect filename
))
4198 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4199 ;; Check the output buffer is empty.
4200 (with-current-buffer out
(erase-buffer))
4201 ;; Kick off the output
4202 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4203 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4204 (let* ((hd (match-string-no-properties 1))
4207 (match-string-no-properties 2)
4209 (goto-char (match-end 0))
4214 (if (looking-at "^[ \t]\\(.*\\)")
4215 (setq str
(concat str
(match-string-no-properties 1)))
4216 (throw 'loop str
)))))))))
4218 ;; Handle level rendering
4220 ((> level last-level
)
4221 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4223 ((< level last-level
)
4224 (dotimes (- (- last-level level
) 1)
4226 (org-export-as-xoxo-insert-into out
"</li>\n"))
4227 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4229 (org-export-as-xoxo-insert-into out
"</li>\n")
4230 (setq hanging-li nil
)))
4232 ((equal level last-level
)
4234 (org-export-as-xoxo-insert-into out
"</li>\n")))
4237 (setq last-level level
)
4239 ;; And output the new li
4240 (setq hanging-li
't
)
4241 (if (equal ?
+ (elt text
0))
4242 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4243 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4245 ;; Finally finish off the ol
4246 (dotimes (- last-level
1)
4248 (org-export-as-xoxo-insert-into out
"</li>\n"))
4249 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4252 ;; Finish the buffer off and clean it up.
4253 (switch-to-buffer-other-window out
)
4254 (indent-region (point-min) (point-max) nil
)
4256 (goto-char (point-min))
4261 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4263 ;;; org-exp.el ends here