1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (declare-function org-export-latex-preprocess
"org-export-latex" ())
35 (declare-function org-agenda-skip
"org-agenda" ())
36 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
37 (declare-function htmlize-region
"ext:htmlize" (beg end
))
38 (declare-function org-id-find-id-file
"org-id" (id))
39 (defvar htmlize-buffer-places
) ; from htmlize.el
41 (defgroup org-export nil
42 "Options for exporting org-listings."
46 (defgroup org-export-general nil
47 "General options for exporting Org-mode files."
48 :tag
"Org Export General"
52 (defvar org-export-publishing-directory nil
)
54 (defcustom org-export-run-in-background nil
55 "Non-nil means export and publishing commands will run in background.
56 This works by starting up a separate Emacs process visiting the same file
57 and doing the export from there.
58 Not all export commands are affected by this - only the ones which
59 actually write to a file, and that do not depend on the buffer state.
61 If this option is nil, you can still get background export by calling
62 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
64 If this option is t, the double prefix can be used to exceptionally
65 force an export command into the current process."
66 :group
'org-export-general
70 (defcustom org-export-select-tags
'("export")
71 "Tags that select a tree for export.
72 If any such tag is found in a buffer, all trees that do not carry one
73 of these tags will be deleted before export.
74 Inside trees that are selected like this, you can still deselect a
75 subtree by tagging it with one of the `org-export-exclude-tags'."
76 :group
'org-export-general
77 :type
'(repeat (string :tag
"Tag")))
79 (defcustom org-export-exclude-tags
'("noexport")
80 "Tags that exclude a tree from export.
81 All trees carrying any of these tags will be excluded from export.
82 This is without condition, so even subtrees inside that carry one of the
83 `org-export-select-tags' will be removed."
84 :group
'org-export-general
85 :type
'(repeat (string :tag
"Tag")))
87 (defcustom org-export-with-special-strings t
88 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
89 When this option is turned on, these strings will be exported as:
92 -----+----------+--------
98 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
99 :group
'org-export-translation
102 (defcustom org-export-language-setup
103 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
104 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
105 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
106 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
107 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
108 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
109 ("es" "Autor" "Fecha" "Índice" "Pies de página")
110 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
111 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
112 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
113 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
114 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
115 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
116 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
117 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
118 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
119 ("pl" "Autor" "Data" "Spis treści" "Przypis")
120 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
121 "Terms used in export text, translated to different languages.
122 Use the variable `org-export-default-language' to set the language,
123 or use the +OPTION lines for a per-file setting."
124 :group
'org-export-general
127 (string :tag
"HTML language tag")
128 (string :tag
"Author")
130 (string :tag
"Table of Contents")
131 (string :tag
"Footnotes"))))
133 (defcustom org-export-default-language
"en"
134 "The default language of HTML export, as a string.
135 This should have an association in `org-export-language-setup'."
136 :group
'org-export-general
139 (defcustom org-export-skip-text-before-1st-heading nil
140 "Non-nil means, skip all text before the first headline when exporting.
141 When nil, that text is exported as well."
142 :group
'org-export-general
145 (defcustom org-export-headline-levels
3
146 "The last level which is still exported as a headline.
147 Inferior levels will produce itemize lists when exported.
148 Note that a numeric prefix argument to an exporter function overrides
151 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
152 :group
'org-export-general
155 (defcustom org-export-with-section-numbers t
156 "Non-nil means, add section numbers to headlines when exporting.
158 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
159 :group
'org-export-general
162 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
163 "Format of section numbers for export.
164 The variable has two components.
165 1. A list of lists, each indicating a counter type and a separator.
166 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
167 It causes causes numeric, alphabetic, or roman counters, respectively.
168 The separator is only used if another counter for a subsection is being
170 If there are more numbered section levels than entries in this lists,
171 then the last entry will be reused.
172 2. A terminator string that will be added after the entire
174 :group
'org-export-general
178 (string :tag
"Counter Type")
179 (string :tag
"Separator ")))
180 (string :tag
"Terminator")))
182 (defcustom org-export-with-toc t
183 "Non-nil means, create a table of contents in exported files.
184 The TOC contains headlines with levels up to`org-export-headline-levels'.
185 When an integer, include levels up to N in the toc, this may then be
186 different from `org-export-headline-levels', but it will not be allowed
187 to be larger than the number of headline levels.
188 When nil, no table of contents is made.
190 Headlines which contain any TODO items will be marked with \"(*)\" in
191 ASCII export, and with red color in HTML output, if the option
192 `org-export-mark-todo-in-toc' is set.
194 In HTML output, the TOC will be clickable.
196 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
198 :group
'org-export-general
200 (const :tag
"No Table of Contents" nil
)
201 (const :tag
"Full Table of Contents" t
)
202 (integer :tag
"TOC to level")))
204 (defcustom org-export-mark-todo-in-toc nil
205 "Non-nil means, mark TOC lines that contain any open TODO items."
206 :group
'org-export-general
209 (defcustom org-export-with-todo-keywords t
210 "Non-nil means, include TODO keywords in export.
211 When nil, remove all these keywords from the export."
212 :group
'org-export-general
215 (defcustom org-export-with-priority nil
216 "Non-nil means, include priority cookies in export.
217 When nil, remove priority cookies for export."
218 :group
'org-export-general
221 (defcustom org-export-preserve-breaks nil
222 "Non-nil means, preserve all line breaks when exporting.
223 Normally, in HTML output paragraphs will be reformatted. In ASCII
224 export, line breaks will always be preserved, regardless of this variable.
226 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
227 :group
'org-export-general
230 (defcustom org-export-with-archived-trees
'headline
231 "Whether subtrees with the ARCHIVE tag should be exported.
232 This can have three different values
233 nil Do not export, pretend this tree is not present
234 t Do export the entire tree
235 headline Only export the headline, but skip the tree below it."
236 :group
'org-export-general
239 (const :tag
"not at all" nil
)
240 (const :tag
"headline only" 'headline
)
241 (const :tag
"entirely" t
)))
243 (defcustom org-export-author-info t
244 "Non-nil means, insert author name and email into the exported file.
246 This option can also be set with the +OPTIONS line,
247 e.g. \"author-info:nil\"."
248 :group
'org-export-general
251 (defcustom org-export-creator-info t
252 "Non-nil means, the postamble should contain a creator sentence.
253 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
254 :group
'org-export-general
257 (defcustom org-export-time-stamp-file t
258 "Non-nil means, insert a time stamp into the exported file.
259 The time stamp shows when the file was created.
261 This option can also be set with the +OPTIONS line,
262 e.g. \"timestamp:nil\"."
263 :group
'org-export-general
266 (defcustom org-export-with-timestamps t
267 "If nil, do not export time stamps and associated keywords."
268 :group
'org-export-general
271 (defcustom org-export-remove-timestamps-from-toc t
272 "If nil, remove timestamps from the table of contents entries."
273 :group
'org-export-general
276 (defcustom org-export-with-tags
'not-in-toc
277 "If nil, do not export tags, just remove them from headlines.
278 If this is the symbol `not-in-toc', tags will be removed from table of
279 contents entries, but still be shown in the headlines of the document.
281 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
282 :group
'org-export-general
284 (const :tag
"Off" nil
)
285 (const :tag
"Not in TOC" not-in-toc
)
286 (const :tag
"On" t
)))
288 (defcustom org-export-with-drawers nil
289 "Non-nil means, export with drawers like the property drawer.
290 When t, all drawers are exported. This may also be a list of
291 drawer names to export."
292 :group
'org-export-general
294 (const :tag
"All drawers" t
)
295 (const :tag
"None" nil
)
296 (repeat :tag
"Selected drawers"
297 (string :tag
"Drawer name"))))
299 (defvar org-export-preprocess-hook nil
300 "Hook for preprocessing an export buffer.
301 Pretty much the first thing when exporting is running this hook.")
303 (defvar org-export-preprocess-after-include-files-hook nil
304 "Hook for preprocessing an export buffer.
305 This is run after the contents of included files have been inserted.")
307 (defvar org-export-preprocess-after-tree-selection-hook nil
308 "Hook for preprocessing an export buffer.
309 This is run after selection of trees to be exported has happened.
310 This selection includes tags-based selection, as well as removal
311 of commented and archived trees.")
313 (defvar org-export-preprocess-before-backend-specifics-hook nil
314 "Hook run before backend-specific functions are called during preprocessing.")
316 (defvar org-export-preprocess-final-hook nil
317 "Hook for preprocessing an export buffer.
318 This is run as the last thing in the preprocessing buffer, just before
319 returning the buffer string to the backend.")
321 (defgroup org-export-translation nil
322 "Options for translating special ascii sequences for the export backends."
323 :tag
"Org Export Translation"
326 (defcustom org-export-with-emphasize t
327 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
328 If the export target supports emphasizing text, the word will be
329 typeset in bold, italic, or underlined, respectively. Works only for
330 single words, but you can say: I *really* *mean* *this*.
331 Not all export backends support this.
333 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
334 :group
'org-export-translation
337 (defcustom org-export-with-footnotes t
338 "If nil, export [1] as a footnote marker.
339 Lines starting with [1] will be formatted as footnotes.
341 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
342 :group
'org-export-translation
345 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
346 <h2 class=\"footnotes\">%s: </h2>
347 <div id=\"footnotes-text\">
351 "Format for the footnotes section.
352 Should contain a two instances of %s. The first will be replaced with the
353 language-specific word for \"Footnotes\", the second one will be replaced
354 by the footnotes themselves."
355 :group
'org-export-html
358 (defcustom org-export-with-sub-superscripts t
359 "Non-nil means, interpret \"_\" and \"^\" for export.
360 When this option is turned on, you can use TeX-like syntax for sub- and
361 superscripts. Several characters after \"_\" or \"^\" will be
362 considered as a single item - so grouping with {} is normally not
363 needed. For example, the following things will be parsed as single
364 sub- or superscripts.
366 10^24 or 10^tau several digits will be considered 1 item.
367 10^-12 or 10^-tau a leading sign with digits or a word
368 x^2-y^3 will be read as x^2 - y^3, because items are
369 terminated by almost any nonword/nondigit char.
370 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
372 Still, ambiguity is possible - so when in doubt use {} to enclose the
373 sub/superscript. If you set this variable to the symbol `{}',
374 the braces are *required* in order to trigger interpretations as
375 sub/superscript. This can be helpful in documents that need \"_\"
376 frequently in plain text.
378 Not all export backends support this, but HTML does.
380 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
381 :group
'org-export-translation
383 (const :tag
"Always interpret" t
)
384 (const :tag
"Only with braces" {})
385 (const :tag
"Never interpret" nil
)))
387 (defcustom org-export-with-TeX-macros t
388 "Non-nil means, interpret simple TeX-like macros when exporting.
389 For example, HTML export converts \\alpha to α and \\AA to Å.
390 Not only real TeX macros will work here, but the standard HTML entities
391 for math can be used as macro names as well. For a list of supported
392 names in HTML export, see the constant `org-html-entities'.
393 Not all export backends support this.
395 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
396 :group
'org-export-translation
397 :group
'org-export-latex
400 (defcustom org-export-with-LaTeX-fragments nil
401 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
402 When set, the exporter will find LaTeX environments if the \\begin line is
403 the first non-white thing on a line. It will also find the math delimiters
404 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
407 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
408 :group
'org-export-translation
409 :group
'org-export-latex
412 (defcustom org-export-with-fixed-width t
413 "Non-nil means, lines starting with \":\" will be in fixed width font.
414 This can be used to have pre-formatted text, fragments of code etc. For
416 : ;; Some Lisp examples
419 will be looking just like this in also HTML. See also the QUOTE keyword.
420 Not all export backends support this.
422 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
423 :group
'org-export-translation
426 (defcustom org-match-sexp-depth
3
427 "Number of stacked braces for sub/superscript matching.
428 This has to be set before loading org.el to be effective."
429 :group
'org-export-translation
432 (defgroup org-export-tables nil
433 "Options for exporting tables in Org-mode."
434 :tag
"Org Export Tables"
437 (defcustom org-export-with-tables t
438 "If non-nil, lines starting with \"|\" define a table.
441 | Name | Address | Birthday |
442 |-------------+----------+-----------|
443 | Arthur Dent | England | 29.2.2100 |
445 Not all export backends support this.
447 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
448 :group
'org-export-tables
451 (defcustom org-export-highlight-first-table-line t
452 "Non-nil means, highlight the first table line.
453 In HTML export, this means use <th> instead of <td>.
454 In tables created with table.el, this applies to the first table line.
455 In Org-mode tables, all lines before the first horizontal separator
456 line will be formatted with <th> tags."
457 :group
'org-export-tables
460 (defcustom org-export-table-remove-special-lines t
461 "Remove special lines and marking characters in calculating tables.
462 This removes the special marking character column from tables that are set
463 up for spreadsheet calculations. It also removes the entire lines
464 marked with `!', `_', or `^'. The lines with `$' are kept, because
465 the values of constants may be useful to have."
466 :group
'org-export-tables
469 (defcustom org-export-prefer-native-exporter-for-tables nil
470 "Non-nil means, always export tables created with table.el natively.
471 Natively means, use the HTML code generator in table.el.
472 When nil, Org-mode's own HTML generator is used when possible (i.e. if
473 the table does not use row- or column-spanning). This has the
474 advantage, that the automatic HTML conversions for math symbols and
475 sub/superscripts can be applied. Org-mode's HTML generator is also
477 :group
'org-export-tables
480 (defgroup org-export-ascii nil
481 "Options specific for ASCII export of Org-mode files."
482 :tag
"Org Export ASCII"
485 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
486 "Characters for underlining headings in ASCII export.
487 In the given sequence, these characters will be used for level 1, 2, ..."
488 :group
'org-export-ascii
489 :type
'(repeat character
))
491 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
492 "Bullet characters for headlines converted to lists in ASCII export.
493 The first character is used for the first lest level generated in this
494 way, and so on. If there are more levels than characters given here,
495 the list will be repeated.
496 Note that plain lists will keep the same bullets as the have in the
498 :group
'org-export-ascii
499 :type
'(repeat character
))
501 (defgroup org-export-xml nil
502 "Options specific for XML export of Org-mode files."
503 :tag
"Org Export XML"
506 (defgroup org-export-html nil
507 "Options specific for HTML export of Org-mode files."
508 :tag
"Org Export HTML"
511 (defcustom org-export-html-coding-system nil
512 "Coding system for HTML export, defaults to buffer-file-coding-system."
513 :group
'org-export-html
514 :type
'coding-system
)
516 (defcustom org-export-html-extension
"html"
517 "The extension for exported HTML files."
518 :group
'org-export-html
521 (defcustom org-export-html-link-up
""
522 "Where should the \"UP\" link of exported HTML pages lead?"
523 :group
'org-export-html
524 :type
'(string :tag
"File or URL"))
526 (defcustom org-export-html-link-home
""
527 "Where should the \"HOME\" link of exported HTML pages lead?"
528 :group
'org-export-html
529 :type
'(string :tag
"File or URL"))
531 (defconst org-export-html-scripts
532 "<script type=\"text/javascript\">
533 <!--/*--><![CDATA[/*><!--*/
534 function CodeHighlightOn(elem, id)
536 var target = document.getElementById(id);
538 elem.cacheClassElem = elem.className;
539 elem.cacheClassTarget = target.className;
540 target.className = \"code-highlighted\";
541 elem.className = \"code-highlighted\";
544 function CodeHighlightOff(elem, id)
546 var target = document.getElementById(id);
547 if(elem.cacheClassElem)
548 elem.className = elem.cacheClassElem;
549 if(elem.cacheClassTarget)
550 target.className = elem.cacheClassTarget;
554 "Basic javascript that is needed by HTML files produced by Org-mode.")
556 (defconst org-export-html-style-default
557 "<style type=\"text/css\">
558 <!--/*--><![CDATA[/*><!--*/
559 html { font-family: Times, serif; font-size: 12pt; }
560 .title { text-align: center; }
561 .todo { color: red; }
562 .done { color: green; }
563 .tag { background-color:lightblue; font-weight:normal }
565 .timestamp { color: grey }
566 .timestamp-kwd { color: CadetBlue }
567 p.verse { margin-left: 3% }
569 border: 1pt solid #AEBDCC;
570 background-color: #F3F5F7;
572 font-family: courier, monospace;
576 table { border-collapse: collapse; }
577 td, th { vertical-align: top; }
578 dt { font-weight: bold; }
579 div.figure { padding: 0.5em; }
580 div.figure p { text-align: center; }
581 .linenr { font-size:smaller }
582 .code-highlighted {background-color:#ffff00;}
583 .org-info-js_info-navigation { border-style:none; }
584 #org-info-js_console-label { font-size:10px; font-weight:bold;
585 white-space:nowrap; }
586 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
590 "The default style specification for exported HTML files.
591 Please use the variables `org-export-html-style' and
592 `org-export-html-style-extra' to add to this style. If you wish to not
593 have the default style included, customize the variable
594 `org-export-html-style-include-default'.")
596 (defcustom org-export-html-style-include-default t
597 "Non-nil means, include the default style in exported HTML files.
598 The actual style is defined in `org-export-html-style-default' and should
599 not be modified. Use the variables `org-export-html-style' to add
600 your own style information."
601 :group
'org-export-html
604 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
606 (defcustom org-export-html-style
""
607 "Org-wide style definitions for exported HTML files.
609 This variable needs to contain the full HTML structure to provide a style,
610 including the surrounding HTML tags. If you set the value of this variable,
611 you should consider to include definitions for the following classes:
612 title, todo, done, timestamp, timestamp-kwd, tag, target.
614 For example, a valid value would be:
616 <style type=\"text/css\">
618 p { font-weight: normal; color: gray; }
620 .title { text-align: center; }
621 .todo, .timestamp-kwd { color: red; }
622 .done { color: green; }
626 If you'd like to refer to en external style file, use something like
628 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
630 As the value of this option simply gets inserted into the HTML <head> header,
631 you can \"misuse\" it to add arbitrary text to the header.
632 See also the variable `org-export-html-style-extra'."
633 :group
'org-export-html
636 (put 'org-export-html-style
'safe-local-variable
'stringp
)
638 (defcustom org-export-html-style-extra
""
639 "Additional style information for HTML export.
640 The value of this variable is inserted into the HTML buffer right after
641 the value of `org-export-html-style'. Use this variable for per-file
642 settings of style information, and do not forget to surround the style
643 settings with <style>...</style> tags."
644 :group
'org-export-html
647 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
650 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
651 "Format for typesetting the document title in HTML export."
652 :group
'org-export-html
655 (defcustom org-export-html-toplevel-hlevel
2
656 "The <H> level for level 1 headings in HTML export."
657 :group
'org-export-html
660 (defcustom org-export-html-link-org-files-as-html t
661 "Non-nil means, make file links to `file.org' point to `file.html'.
662 When org-mode is exporting an org-mode file to HTML, links to
663 non-html files are directly put into a href tag in HTML.
664 However, links to other Org-mode files (recognized by the
665 extension `.org.) should become links to the corresponding html
666 file, assuming that the linked org-mode file will also be
668 When nil, the links still point to the plain `.org' file."
669 :group
'org-export-html
672 (defcustom org-export-html-inline-images
'maybe
673 "Non-nil means, inline images into exported HTML pages.
674 This is done using an <img> tag. When nil, an anchor with href is used to
675 link to the image. If this option is `maybe', then images in links with
676 an empty description will be inlined, while images with a description will
678 :group
'org-export-html
679 :type
'(choice (const :tag
"Never" nil
)
680 (const :tag
"Always" t
)
681 (const :tag
"When there is no description" maybe
)))
683 (defcustom org-export-html-inline-image-extensions
684 '("png" "jpeg" "jpg" "gif")
685 "Extensions of image files that can be inlined into HTML."
686 :group
'org-export-html
687 :type
'(repeat (string :tag
"Extension")))
690 (defcustom org-export-html-expand t
691 "Non-nil means, for HTML export, treat @<...> as HTML tag.
692 When nil, these tags will be exported as plain text and therefore
693 not be interpreted by a browser.
695 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
696 :group
'org-export-html
699 (defcustom org-export-html-table-tag
700 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
701 "The HTML tag that is used to start a table.
702 This must be a <table> tag, but you may change the options like
703 borders and spacing."
704 :group
'org-export-html
707 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
708 "The opening tag for table header fields.
709 This is customizable so that alignment options can be specified."
710 :group
'org-export-tables
711 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
713 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
714 "The opening tag for table data fields.
715 This is customizable so that alignment options can be specified."
716 :group
'org-export-tables
717 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
719 (defcustom org-export-html-with-timestamp nil
720 "If non-nil, write `org-export-html-html-helper-timestamp'
721 into the exported HTML text. Otherwise, the buffer will just be saved
723 :group
'org-export-html
726 (defcustom org-export-html-html-helper-timestamp
727 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
728 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
729 :group
'org-export-html
732 (defgroup org-export-htmlize nil
733 "Options for processing examples with htmlize.el."
734 :tag
"Org Export Htmlize"
735 :group
'org-export-html
)
737 (defcustom org-export-htmlize-output-type
'inline-css
738 "Output type to be used by htmlize when formatting code snippets.
739 Normally this is `inline-css', but if you have defined to appropriate
740 classes in your css style file, setting this to `css' means that the
741 fontification will use the class names.
742 See also the function `org-export-htmlize-generate-css'."
743 :group
'org-export-htmlize
744 :type
'(choice (const css
) (const inline-css
)))
746 (defcustom org-export-htmlize-css-font-prefix
"org-"
747 "The prefix for CSS class names for htmlize font specifications."
748 :group
'org-export-htmlize
751 (defgroup org-export-icalendar nil
752 "Options specific for iCalendar export of Org-mode files."
753 :tag
"Org Export iCalendar"
756 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
757 "The file name for the iCalendar file covering all agenda files.
758 This file is created with the command \\[org-export-icalendar-all-agenda-files].
759 The file name should be absolute, the file will be overwritten without warning."
760 :group
'org-export-icalendar
763 (defcustom org-icalendar-combined-name
"OrgMode"
764 "Calendar name for the combined iCalendar representing all agenda files."
765 :group
'org-export-icalendar
768 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
769 "Contexts where iCalendar export should use a deadline time stamp.
770 This is a list with several symbols in it. Valid symbol are:
772 event-if-todo Deadlines in TODO entries become calendar events.
773 event-if-not-todo Deadlines in non-TODO entries become calendar events.
774 todo-due Use deadlines in TODO entries as due-dates"
775 :group
'org-export-icalendar
776 :type
'(set :greedy t
777 (const :tag
"Deadlines in non-TODO entries become events"
779 (const :tag
"Deadline in TODO entries become events"
781 (const :tag
"Deadlines in TODO entries become due-dates"
784 (defcustom org-icalendar-use-scheduled
'(todo-start)
785 "Contexts where iCalendar export should use a scheduling time stamp.
786 This is a list with several symbols in it. Valid symbol are:
788 event-if-todo Scheduling time stamps in TODO entries become an event.
789 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
790 todo-start Scheduling time stamps in TODO entries become start date.
791 Some calendar applications show TODO entries only after
793 :group
'org-export-icalendar
794 :type
'(set :greedy t
796 "SCHEDULED timestamps in non-TODO entries become events"
798 (const :tag
"SCHEDULED timestamps in TODO entries become events"
800 (const :tag
"SCHEDULED in TODO entries become start date"
803 (defcustom org-icalendar-categories
'(local-tags category
)
804 "Items that should be entered into the categories field.
805 This is a list of symbols, the following are valid:
807 category The Org-mode category of the current file or tree
808 todo-state The todo state, if any
809 local-tags The tags, defined in the current line
810 all-tags All tags, including inherited ones."
811 :group
'org-export-icalendar
814 (const :tag
"The file or tree category" category
)
815 (const :tag
"The TODO state" todo-state
)
816 (const :tag
"Tags defined in current line" local-tags
)
817 (const :tag
"All tags, including inherited ones" all-tags
))))
819 (defcustom org-icalendar-include-todo nil
820 "Non-nil means, export to iCalendar files should also cover TODO items."
821 :group
'org-export-icalendar
823 (const :tag
"None" nil
)
824 (const :tag
"Unfinished" t
)
825 (const :tag
"All" all
)))
827 (defcustom org-icalendar-include-sexps t
828 "Non-nil means, export to iCalendar files should also cover sexp entries.
829 These are entries like in the diary, but directly in an Org-mode file."
830 :group
'org-export-icalendar
833 (defcustom org-icalendar-include-body
100
834 "Amount of text below headline to be included in iCalendar export.
835 This is a number of characters that should maximally be included.
836 Properties, scheduling and clocking lines will always be removed.
837 The text will be inserted into the DESCRIPTION field."
838 :group
'org-export-icalendar
840 (const :tag
"Nothing" nil
)
841 (const :tag
"Everything" t
)
842 (integer :tag
"Max characters")))
844 (defcustom org-icalendar-store-UID nil
845 "Non-nil means, store any created UIDs in properties.
846 The iCalendar standard requires that all entries have a unique identifier.
847 Org will create these identifiers as needed. When this variable is non-nil,
848 the created UIDs will be stored in the ID property of the entry. Then the
849 next time this entry is exported, it will be exported with the same UID,
850 superceding the previous form of it. This is essential for
851 synchronization services.
852 This variable is not turned on by default because we want to avoid creating
853 a property drawer in every entry if people are only playing with this feature,
854 or if they are only using it locally."
855 :group
'org-export-icalendar
860 ;;; Variables, constants, and parameter plists
862 (defconst org-level-max
20)
864 (defvar org-export-html-preamble nil
865 "Preamble, to be inserted just before <body>. Set by publishing functions.")
866 (defvar org-export-html-postamble nil
867 "Preamble, to be inserted just after </body>. Set by publishing functions.")
868 (defvar org-export-html-auto-preamble t
869 "Should default preamble be inserted? Set by publishing functions.")
870 (defvar org-export-html-auto-postamble t
871 "Should default postamble be inserted? Set by publishing functions.")
872 (defvar org-current-export-file nil
) ; dynamically scoped parameter
873 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
875 (defconst org-export-plist-vars
876 '((:link-up nil org-export-html-link-up
)
877 (:link-home nil org-export-html-link-home
)
878 (:language nil org-export-default-language
)
879 (:customtime nil org-display-custom-times
)
880 (:headline-levels
"H" org-export-headline-levels
)
881 (:section-numbers
"num" org-export-with-section-numbers
)
882 (:section-number-format nil org-export-section-number-format
)
883 (:table-of-contents
"toc" org-export-with-toc
)
884 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
885 (:archived-trees nil org-export-with-archived-trees
)
886 (:emphasize
"*" org-export-with-emphasize
)
887 (:sub-superscript
"^" org-export-with-sub-superscripts
)
888 (:special-strings
"-" org-export-with-special-strings
)
889 (:footnotes
"f" org-export-with-footnotes
)
890 (:drawers
"d" org-export-with-drawers
)
891 (:tags
"tags" org-export-with-tags
)
892 (:todo-keywords
"todo" org-export-with-todo-keywords
)
893 (:priority
"pri" org-export-with-priority
)
894 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
895 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
896 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
897 (:fixed-width
":" org-export-with-fixed-width
)
898 (:timestamps
"<" org-export-with-timestamps
)
899 (:author-info
"author" org-export-author-info
)
900 (:creator-info
"creator" org-export-creator-info
)
901 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
902 (:tables
"|" org-export-with-tables
)
903 (:table-auto-headline nil org-export-highlight-first-table-line
)
904 (:style-include-default nil org-export-html-style-include-default
)
905 (:style nil org-export-html-style
)
906 (:style-extra nil org-export-html-style-extra
)
907 (:agenda-style nil org-agenda-export-html-style
)
908 (:convert-org-links nil org-export-html-link-org-files-as-html
)
909 (:inline-images nil org-export-html-inline-images
)
910 (:html-extension nil org-export-html-extension
)
911 (:html-table-tag nil org-export-html-table-tag
)
912 (:expand-quoted-html
"@" org-export-html-expand
)
913 (:timestamp nil org-export-html-with-timestamp
)
914 (:publishing-directory nil org-export-publishing-directory
)
915 (:preamble nil org-export-html-preamble
)
916 (:postamble nil org-export-html-postamble
)
917 (:auto-preamble nil org-export-html-auto-preamble
)
918 (:auto-postamble nil org-export-html-auto-postamble
)
919 (:author nil user-full-name
)
920 (:email nil user-mail-address
)
921 (:select-tags nil org-export-select-tags
)
922 (:exclude-tags nil org-export-exclude-tags
))
923 "List of properties that represent export/publishing variables.
924 Each element is a list of 3 items:
925 1. The property that is used internally, and also for org-publish-project-alist
926 2. The string that can be used in the OPTION lines to set this option,
927 or nil if this option cannot be changed in this way
928 3. The customization variable that sets the default for this option."
932 (defun org-default-export-plist ()
933 "Return the property list with default settings for the export variables."
934 (let ((l org-export-plist-vars
) rtn e
)
935 (while (setq e
(pop l
))
936 (setq rtn
(cons (car e
) (cons (symbol-value (nth 2 e
)) rtn
))))
939 (defvar org-export-inbuffer-options-extra nil
940 "List of additional in-buffer options that should be detected.
941 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
942 etc. Extensions can add to this list to get their options detected, and they
943 can then add a function to `org-export-options-filters' to process these
945 Each element in this list must be a list, with the in-buffer keyword as car,
946 and a property (a symbol) as the next element. All occurrences of the
947 keyword will be found, the values concatenated with a space character
948 in between, and the result stored in the export options property list.")
950 (defvar org-export-options-filters nil
951 "Functions to be called to finalize the export/publishing options.
952 All these options are stored in a property list, and each of the functions
953 in this hook gets a chance to modify this property list. Each function
954 must accept the property list as an argument, and must return the (possibly
957 ;; FIXME: should we fold case here?
958 (defun org-infile-export-plist ()
959 "Return the property list with file-local settings for export."
963 (goto-char (point-min))
964 (let ((re (org-make-options-regexp
966 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
967 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
968 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
969 (mapcar 'car org-export-inbuffer-options-extra
))))
970 p key val text options a pr style
972 ext-setup-or-nil setup-contents
(start 0))
973 (while (or (and ext-setup-or-nil
974 (string-match re ext-setup-or-nil start
)
975 (setq start
(match-end 0)))
976 (and (setq ext-setup-or-nil nil start
0)
977 (re-search-forward re nil t
)))
978 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
979 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
981 ((setq a
(assoc key org-export-inbuffer-options-extra
))
983 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
984 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
985 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
986 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
987 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
988 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
989 ((string-equal key
"STYLE")
990 (setq style
(concat style
"\n" val
)))
991 ((string-equal key
"LATEX_HEADER")
992 (setq latex-header
(concat latex-header
"\n" val
)))
993 ((string-equal key
"TEXT")
994 (setq text
(if text
(concat text
"\n" val
) val
)))
995 ((string-equal key
"OPTIONS")
996 (setq options
(concat val
" " options
)))
997 ((string-equal key
"LINK_UP")
998 (setq p
(plist-put p
:link-up val
)))
999 ((string-equal key
"LINK_HOME")
1000 (setq p
(plist-put p
:link-home val
)))
1001 ((string-equal key
"EXPORT_SELECT_TAGS")
1002 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
1003 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
1004 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
1005 ((equal key
"SETUPFILE")
1006 (setq setup-contents
(org-file-contents
1008 (org-remove-double-quotes
1011 (if (not ext-setup-or-nil
)
1012 (setq ext-setup-or-nil setup-contents start
0)
1013 (setq ext-setup-or-nil
1014 (concat (substring ext-setup-or-nil
0 start
)
1015 "\n" setup-contents
"\n"
1016 (substring ext-setup-or-nil start
)))))))
1017 (setq p
(plist-put p
:text text
))
1018 (when style
(setq p
(plist-put p
:style-extra style
)))
1020 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
1022 (setq p
(org-export-add-options-to-plist p options
)))
1025 (defun org-export-add-options-to-plist (p options
)
1026 "Parse an OPTIONS line and set values in the property list P."
1029 (let ((op org-export-plist-vars
))
1030 (while (setq o
(pop op
))
1032 (string-match (concat (regexp-quote (nth 1 o
))
1033 ":\\([^ \t\n\r;,.]*\\)")
1035 (setq p
(plist-put p
(car o
)
1036 (car (read-from-string
1037 (match-string 1 options
))))))))))
1040 (defun org-export-add-subtree-options (p pos
)
1041 "Add options in subtree at position POS to property list P."
1044 (when (org-at-heading-p)
1046 ;; This is actually read in `org-export-get-title-from-subtree'
1047 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1048 ;; (setq p (plist-put p :title a)))
1049 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
1050 (setq p
(plist-put p
:text a
)))
1051 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
1052 (setq p
(org-export-add-options-to-plist p a
)))))
1055 (defun org-export-directory (type plist
)
1056 (let* ((val (plist-get plist
:publishing-directory
))
1057 (dir (if (listp val
)
1058 (or (cdr (assoc type val
)) ".")
1062 (defun org-export-process-option-filters (plist)
1063 (let ((functions org-export-options-filters
) f
)
1064 (while (setq f
(pop functions
))
1065 (setq plist
(funcall f plist
))))
1069 (defun org-export (&optional arg
)
1070 "Export dispatcher for Org-mode.
1071 When `org-export-run-in-background' is non-nil, try to run the command
1072 in the background. This will be done only for commands that write
1073 to a file. For details see the docstring of `org-export-run-in-background'.
1075 The prefix argument ARG will be passed to the exporter. However, if
1076 ARG is a double universal prefix `C-u C-u', that means to inverse the
1077 value of `org-export-run-in-background'."
1079 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1080 (help "[t] insert the export option template
1081 \[v] limit export to visible part of outline tree
1083 \[a] export as ASCII
1086 \[H] export as HTML to temporary buffer
1087 \[R] export region as HTML
1088 \[b] export as HTML and browse immediately
1091 \[l] export as LaTeX
1092 \[p] export as LaTeX and process to PDF
1093 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1094 \[L] export as LaTeX to temporary buffer
1096 \[i] export current file as iCalendar file
1097 \[I] export all agenda files as iCalendar files
1098 \[c] export agenda files into combined iCalendar file
1100 \[F] publish current file
1101 \[P] publish current project
1102 \[X] publish... (project will be prompted for)
1103 \[A] publish all projects")
1105 '((?t org-insert-export-options-template nil
)
1106 (?v org-export-visible nil
)
1107 (?a org-export-as-ascii t
)
1108 (?h org-export-as-html t
)
1109 (?b org-export-as-html-and-open t
)
1110 (?H org-export-as-html-to-buffer nil
)
1111 (?R org-export-region-as-html nil
)
1112 (?x org-export-as-xoxo t
)
1113 (?l org-export-as-latex t
)
1114 (?p org-export-as-pdf t
)
1115 (?d org-export-as-pdf-and-open t
)
1116 (?L org-export-as-latex-to-buffer nil
)
1117 (?i org-export-icalendar-this-file t
)
1118 (?I org-export-icalendar-all-agenda-files t
)
1119 (?c org-export-icalendar-combine-agenda-files t
)
1120 (?F org-publish-current-file t
)
1121 (?P org-publish-current-project t
)
1123 (?A org-publish-all t
)))
1125 (save-window-excursion
1126 (delete-other-windows)
1127 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1129 (org-fit-window-to-buffer (get-buffer-window
1130 "*Org Export/Publishing Help*"))
1131 (message "Select command: ")
1132 (setq r1
(read-char-exclusive)))
1133 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1134 (unless (setq ass
(assq r2 cmds
))
1135 (error "No command associated with key %c" r1
))
1136 (if (and bg
(nth 2 ass
)
1137 (not (buffer-base-buffer))
1138 (not (org-region-active-p)))
1139 ;; execute in background
1140 (let ((p (start-process
1141 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1143 (expand-file-name invocation-name invocation-directory
)
1146 "--eval" "(require 'org-exp)"
1147 "--eval" "(setq org-wait .2)"
1149 "-f" (symbol-name (nth 1 ass
)))))
1150 (set-process-sentinel p
'org-export-process-sentinel
)
1151 (message "Background process \"%s\": started" p
))
1152 ;; background processing not requested, or not possible
1153 (call-interactively (nth 1 ass
)))))
1155 (defun org-export-process-sentinel (process status
)
1156 (if (string-match "\n+\\'" status
)
1157 (setq status
(substring status
0 -
1)))
1158 (message "Background process \"%s\": %s" process status
))
1160 (defconst org-html-entities
1201 ("Aring") ("AA".
"Å")
1290 ("varepsilon".
"ε")
1303 ("sigmaf") ("varsigma".
"ς")
1311 ("thetasym") ("vartheta".
"ϑ")
1314 ("bull") ("bullet".
"•")
1315 ("hellip") ("dots".
"…")
1325 ("larr") ("leftarrow".
"←") ("gets".
"←")
1326 ("uarr") ("uparrow".
"↑")
1327 ("rarr") ("to".
"→") ("rightarrow".
"→")
1328 ("darr")("downarrow".
"↓")
1329 ("harr") ("leftrightarrow".
"↔")
1330 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1331 ("lArr") ("Leftarrow".
"⇐")
1332 ("uArr") ("Uparrow".
"⇑")
1333 ("rArr") ("Rightarrow".
"⇒")
1334 ("dArr") ("Downarrow".
"⇓")
1335 ("hArr") ("Leftrightarrow".
"⇔")
1337 ("part") ("partial".
"∂")
1338 ("exist") ("exists".
"∃")
1339 ("empty") ("emptyset".
"∅")
1341 ("isin") ("in".
"∈")
1347 ("lowast") ("ast".
"∗")
1349 ("prop") ("proptp".
"∝")
1350 ("infin") ("infty".
"∞")
1351 ("ang") ("angle".
"∠")
1352 ("and") ("wedge".
"∧")
1353 ("or") ("vee".
"∨")
1359 ("cong") ("simeq".
"≅")
1360 ("asymp")("approx".
"≈")
1361 ("ne") ("neq".
"≠")
1365 ("sub") ("subset".
"⊂")
1366 ("sup") ("supset".
"⊃")
1373 ("sdot") ("cdot".
"⋅")
1380 ("loz") ("Diamond".
"◊")
1381 ("spades") ("spadesuit".
"♠")
1382 ("clubs") ("clubsuit".
"♣")
1383 ("hearts") ("diamondsuit".
"♥")
1384 ("diams") ("diamondsuit".
"♦")
1385 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1452 "Entities for TeX->HTML translation.
1453 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1454 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1455 In that case, \"\\ent\" will be translated to \"&other;\".
1456 The list contains HTML entities for Latin-1, Greek and other symbols.
1457 It is supplemented by a number of commonly used TeX macros with appropriate
1458 translations. There is currently no way for users to extend this.")
1460 ;;; General functions for all backends
1462 (defvar org-export-target-aliases nil
1463 "Alist of targets with invisible aliases.")
1464 (defvar org-export-code-refs nil
1465 "Alist of code references and line numbers")
1467 (defun org-export-preprocess-string (string &rest parameters
)
1468 "Cleanup STRING so that that the true exported has a more consistent source.
1469 This function takes STRING, which should be a buffer-string of an org-file
1470 to export. It then creates a temporary buffer where it does its job.
1471 The result is then again returned as a string, and the exporter works
1472 on this string to produce the exported version."
1474 (let* ((htmlp (plist-get parameters
:for-html
))
1475 (asciip (plist-get parameters
:for-ascii
))
1476 (latexp (plist-get parameters
:for-LaTeX
))
1477 (backend (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1479 (archived-trees (plist-get parameters
:archived-trees
))
1480 (inhibit-read-only t
)
1481 (drawers org-drawers
)
1482 (outline-regexp "\\*+ ")
1485 (setq org-export-target-aliases nil
)
1486 (setq org-export-code-refs nil
)
1488 (with-current-buffer (get-buffer-create " org-mode-tmp")
1491 (setq case-fold-search t
)
1493 ;; Remove license-to-kill stuff
1494 ;; The caller marks some stuff for killing, stuff that has been
1495 ;; used to create the page title, for example.
1496 (org-export-kill-licensed-text)
1498 (let ((org-inhibit-startup t
)) (org-mode))
1499 (setq case-fold-search t
)
1502 (run-hooks 'org-export-preprocess-hook
)
1504 (untabify (point-min) (point-max))
1506 ;; Handle include files, and call a hook
1507 (org-export-handle-include-files)
1508 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1510 ;; Get rid of archived trees
1511 (org-export-remove-archived-trees archived-trees
)
1513 ;; Remove comment environment and comment subtrees
1514 (org-export-remove-comment-blocks-and-subtrees)
1516 ;; Get rid of excluded trees, and call a hook
1517 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1518 (plist-get parameters
:exclude-tags
))
1519 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1521 ;; Handle source code snippets
1522 (org-export-replace-src-segments-and-examples backend
)
1524 ;; Protect short examples marked by a leading colon
1525 (org-export-protect-colon-examples)
1527 ;; Normalize footnotes
1528 (when (plist-get parameters
:footnotes
)
1529 (org-footnote-normalize nil t
))
1531 ;; Find all headings and compute the targets for them
1532 (setq target-alist
(org-export-define-heading-targets target-alist
))
1534 ;; Get rid of drawers
1535 (org-export-remove-or-extract-drawers drawers
1536 (plist-get parameters
:drawers
))
1538 ;; Get the correct stuff before the first headline
1539 (when (plist-get parameters
:skip-before-1st-heading
)
1540 (goto-char (point-min))
1541 (when (re-search-forward "\\(^#.*\n\\)^\\*+[ \t]" nil t
)
1542 (delete-region (point-min) (match-beginning 0))
1543 (goto-char (point-min))
1545 (when (plist-get parameters
:add-text
)
1546 (goto-char (point-min))
1547 (insert (plist-get parameters
:add-text
) "\n"))
1549 ;; Remove todo-keywords before exporting, if the user has requested so
1550 (org-export-remove-headline-metadata parameters
)
1552 ;; Find targets in comments and move them out of comments,
1553 ;; but mark them as targets that should be invisible
1554 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1556 ;; Select and protect backend specific stuff, throw away stuff
1557 ;; that is specific for other backends
1558 (org-export-select-backend-specific-text backend
)
1560 ;; Protect quoted subtrees
1561 (org-export-protect-quoted-subtrees)
1563 ;; Protect verbatim elements
1564 (org-export-protect-verbatim)
1566 ;; Blockquotes and verse
1567 (org-export-mark-blockquote-and-verse)
1569 ;; Remove timestamps, if the user has requested so
1570 (org-export-remove-clock-lines)
1571 (unless (plist-get parameters
:timestamps
)
1572 (org-export-remove-timestamps))
1574 ;; Attach captions to the correct object
1575 (setq target-alist
(org-export-attach-captions-and-attributes
1576 backend target-alist
))
1578 ;; Find matches for radio targets and turn them into internal links
1579 (org-export-mark-radio-links)
1581 ;; Find all links that contain a newline and put them into a single line
1582 (org-export-concatenate-multiline-links)
1584 ;; Normalize links: Convert angle and plain links into bracket links
1585 ;; and expand link abbreviations
1586 (org-export-normalize-links)
1588 ;; Find all internal links. If they have a fuzzy match (i.e. not
1589 ;; a *dedicated* target match, let the link point to the
1590 ;; corresponding section.
1591 (org-export-target-internal-links target-alist
)
1593 ;; Find multiline emphasis and put them into single line
1594 (when (plist-get parameters
:emph-multiline
)
1595 (org-export-concatenate-multiline-emphasis))
1597 ;; Remove special table lines
1598 (when org-export-table-remove-special-lines
1599 (org-export-remove-special-table-lines))
1602 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1604 ;; LaTeX-specific preprocessing
1606 (require 'org-export-latex nil
)
1607 (org-export-latex-preprocess))
1609 ;; ASCII-specific preprocessing
1611 (org-export-ascii-preprocess))
1613 ;; HTML-specific preprocessing
1615 (org-export-html-preprocess parameters
))
1617 ;; Remove or replace comments
1618 (org-export-handle-comments (plist-get parameters
:comments
))
1620 ;; Run the final hook
1621 (run-hooks 'org-export-preprocess-final-hook
)
1623 (setq rtn
(buffer-string)))
1624 (kill-buffer " org-mode-tmp")
1627 (defun org-export-kill-licensed-text ()
1628 "Remove all text that is marked with a :org-license-to-kill property."
1630 (while (setq p
(text-property-any (point-min) (point-max)
1631 :org-license-to-kill t
))
1633 p
(or (next-single-property-change p
:org-license-to-kill
)
1636 (defun org-export-define-heading-targets (target-alist)
1637 "Find all headings and define the targets for them.
1638 The new targets are added to TARGET-ALIST, which is also returned."
1639 (goto-char (point-min))
1640 (org-init-section-numbers)
1641 (let ((re (concat "^" org-outline-regexp
1642 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1643 level target last-section-target a
)
1644 (while (re-search-forward re nil t
)
1647 (push (cons (org-match-string-no-properties 1)
1648 target
) target-alist
)
1649 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1651 (push (list last-section-target
)
1652 org-export-target-aliases
)
1653 (car org-export-target-aliases
))))
1654 (push (caar target-alist
) (cdr a
)))
1655 (setq level
(org-reduced-level
1656 (save-excursion (goto-char (point-at-bol))
1657 (org-outline-level))))
1658 (setq target
(org-solidify-link-text
1659 (format "sec-%s" (org-section-number level
))))
1660 (setq last-section-target target
)
1661 (push (cons target target
) target-alist
)
1662 (add-text-properties
1663 (point-at-bol) (point-at-eol)
1664 (list 'target target
)))))
1667 (defun org-export-handle-invisible-targets (target-alist)
1668 "Find targets in comments and move them out of comments.
1669 Mark them as invisible targets."
1671 (goto-char (point-min))
1672 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1673 ;; Check if the line before or after is a headline with a target
1674 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1675 (get-text-property (point-at-bol 2) 'target
)))
1677 ;; use the existing target in a neighboring line
1678 (setq tmp
(match-string 2))
1680 (and (looking-at "\n") (delete-char 1))
1681 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1683 (setq a
(or (assoc target org-export-target-aliases
)
1685 (push (list target
) org-export-target-aliases
)
1686 (car org-export-target-aliases
))))
1688 ;; Make an invisible target
1689 (replace-match "\\1(INVISIBLE)"))))
1692 (defun org-export-target-internal-links (target-alist)
1693 "Find all internal links and assign targets to them.
1694 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1695 let the link point to the corresponding section.
1696 This function also handles the id links, if they have a match in
1698 (goto-char (point-min))
1699 (while (re-search-forward org-bracket-link-regexp nil t
)
1701 (let* ((md (match-data))
1702 (desc (match-end 2))
1703 (link (org-link-unescape (match-string 1)))
1704 (slink (org-solidify-link-text link
))
1705 found props pos cref
1708 ((cdr (assoc slink target-alist
)))
1709 ((and (string-match "^id:" link
)
1710 (cdr (assoc (substring link
3) target-alist
))))
1711 ((string-match "^(\\(.*\\))$" link
)
1712 (setq cref
(match-string 1 link
))
1713 (concat "coderef:" cref
))
1714 ((string-match org-link-types-re link
) nil
)
1715 ((or (file-name-absolute-p link
)
1716 (string-match "^\\." link
))
1720 (setq found
(condition-case nil
(org-link-search link
)
1723 (or (org-on-heading-p)
1724 (not (eq found
'dedicated
))))
1725 (or (get-text-property (point) 'target
)
1728 (1- (or (previous-single-property-change
1729 (point) 'target
) 0)))
1733 (goto-char (match-beginning 1))
1734 (setq props
(text-properties-at (point)))
1735 (delete-region (match-beginning 1) (match-end 1))
1738 (unless desc
(insert "][" link
))
1739 (add-text-properties pos
(point) props
))))))
1741 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1742 "Remove drawers, or extract the content.
1743 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1744 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1745 whose content to keep."
1746 (unless (eq t exp-drawers
)
1747 (goto-char (point-min))
1748 (let ((re (concat "^[ \t]*:\\("
1751 (org-delete-all exp-drawers
1752 (copy-sequence all-drawers
))
1754 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1755 (while (re-search-forward re nil t
)
1757 (replace-match ""))))))
1759 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1760 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1761 Both arguments are lists of tags.
1762 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1764 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1766 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1767 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1770 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1774 (goto-char (point-min))
1775 (when (and select-tags
1777 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1778 ;; At least one tree is marked for export, this means
1779 ;; all the unmarked stuff needs to go.
1780 ;; Dig out the trees that should be exported
1781 (goto-char (point-min))
1782 (outline-next-heading)
1784 (put-text-property beg
(point-max) :org-delete t
)
1785 (while (re-search-forward re-sel nil t
)
1786 (when (org-on-heading-p)
1787 (org-back-to-heading)
1788 (remove-text-properties
1789 (max (1- (point)) (point-min))
1790 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1792 (while (and (org-up-heading-safe)
1793 (get-text-property (point) :org-delete
))
1794 (remove-text-properties (max (1- (point)) (point-min))
1795 (point-at-eol) '(:org-delete t
)))
1797 ;; Remove the trees explicitly marked for noexport
1799 (goto-char (point-min))
1800 (while (re-search-forward re-excl nil t
)
1801 (when (org-at-heading-p)
1802 (org-back-to-heading t
)
1804 (org-end-of-subtree t
)
1805 (delete-region beg
(point)))))
1806 ;; Remove everything that is now still marked for deletion
1807 (goto-char (point-min))
1808 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1809 (setq end
(or (next-single-property-change beg
:org-delete
)
1811 (delete-region beg end
))))
1813 (defun org-export-remove-archived-trees (export-archived-trees)
1814 "Remove archived trees.
1815 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1816 When it is t, the entire archived tree will be exported.
1817 When it is nil the entire tree including the headline will be removed
1819 (let ((re-archive (concat ":" org-archive-tag
":"))
1821 (when (not (eq export-archived-trees t
))
1822 (goto-char (point-min))
1823 (while (re-search-forward re-archive nil t
)
1824 (if (not (org-on-heading-p t
))
1825 (org-end-of-subtree t
)
1826 (beginning-of-line 1)
1827 (setq a
(if export-archived-trees
1828 (1+ (point-at-eol)) (point))
1829 b
(org-end-of-subtree t
))
1830 (if (> b a
) (delete-region a b
)))))))
1832 (defun org-export-remove-headline-metadata (opts)
1833 "Remove meta data from the headline, according to user options."
1834 (let ((re org-complex-heading-regexp
)
1835 (todo (plist-get opts
:todo-keywords
))
1836 (tags (plist-get opts
:tags
))
1837 (pri (plist-get opts
:priority
))
1840 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1841 (when (or (not todo
) (not tags
) (not pri
))
1842 (goto-char (point-min))
1843 (while (re-search-forward re nil t
)
1845 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1847 (replace-match rpl t t
))))))
1849 (defun org-export-remove-timestamps ()
1850 "Remove timestamps and keywords for export."
1851 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1854 (unless (save-match-data (org-at-table-p))
1856 (beginning-of-line 1)
1857 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1858 (replace-match ""))))))
1860 (defun org-export-remove-clock-lines ()
1861 "Remove timestamps and keywords for export."
1862 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1863 (while (re-search-forward re nil t
)
1865 (replace-match "")))))
1867 (defun org-export-protect-quoted-subtrees ()
1868 "Mark quoted subtrees with the protection property."
1869 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1870 (goto-char (point-min))
1871 (while (re-search-forward re-quote nil t
)
1872 (goto-char (match-beginning 0))
1874 (add-text-properties (point) (org-end-of-subtree t
)
1875 '(org-protected t
)))))
1877 (defun org-export-protect-verbatim ()
1878 "Mark verbatim snippets with the protection property."
1879 (goto-char (point-min))
1880 (while (re-search-forward org-verbatim-re nil t
)
1881 (add-text-properties (match-beginning 4) (match-end 4)
1883 (goto-char (1+ (match-end 4)))))
1885 (defun org-export-protect-colon-examples ()
1886 "Protect lines starting with a colon."
1887 (goto-char (point-min))
1888 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1889 (while (re-search-forward re nil t
)
1890 (beginning-of-line 1)
1892 (while (looking-at re
)
1894 (or (eobp) (forward-char 1)))
1895 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1896 '(org-protected t
)))))
1898 (defun org-export-select-backend-specific-text (backend)
1900 '((html "HTML" "BEGIN_HTML" "END_HTML")
1901 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1902 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1903 (case-fold-search t
)
1907 (setq fmt
(pop formatters
))
1908 (when (eq (car fmt
) backend
)
1909 ;; This is selected code, put it into the file for real
1910 (goto-char (point-min))
1911 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1912 ":[ \t]*\\(.*\\)") nil t
)
1913 (replace-match "\\1" t
)
1914 (add-text-properties
1915 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1916 '(org-protected t
))))
1917 (goto-char (point-min))
1918 (while (re-search-forward
1920 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1921 (cadddr fmt
) "\\>.*\n?") nil t
)
1922 (if (eq (car fmt
) backend
)
1924 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1926 ;; No, this is for a different backend, kill it
1927 (delete-region (match-beginning 0) (match-end 0)))))))
1929 (defun org-export-mark-blockquote-and-verse ()
1930 "Mark block quote and verse environments with special cookies.
1931 These special cookies will later be interpreted by the backend."
1933 (goto-char (point-min))
1934 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1936 (replace-match (if (equal (downcase (match-string 1)) "end")
1937 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1940 (goto-char (point-min))
1941 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1942 (replace-match (if (equal (downcase (match-string 1)) "end")
1943 "ORG-VERSE-END" "ORG-VERSE-START")
1946 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1947 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1948 If the next thing following is a table, add the text properties to the first
1949 table line. If it is a link, add it to the line containing the link."
1950 (goto-char (point-min))
1951 (remove-text-properties (point-min) (point-max)
1952 '(org-caption nil org-attributes nil
))
1953 (let ((case-fold-search t
)
1954 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1956 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1958 "^#\\+label:[ \t]+\\(.*\\)"
1962 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1964 (while (re-search-forward re nil t
)
1967 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1969 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1971 (setq label
(org-trim (match-string 3))))
1973 (add-text-properties (point-at-bol) (point-at-eol)
1974 (list 'org-caption cap
1975 'org-attributes attr
1977 (if label
(push (cons label label
) target-alist
))
1978 (setq cap nil attr nil label nil
)))))
1981 (defun org-export-remove-comment-blocks-and-subtrees ()
1982 "Remove the comment environment, and also commented subtrees."
1983 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1984 (case-fold-search nil
))
1985 ;; Remove comment environment
1986 (goto-char (point-min))
1987 (while (re-search-forward
1988 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1989 (replace-match "" t t
))
1990 ;; Remove subtrees that are commented
1991 (goto-char (point-min))
1992 (while (re-search-forward re-commented nil t
)
1993 (goto-char (match-beginning 0))
1994 (delete-region (point) (org-end-of-subtree t
)))))
1996 (defun org-export-handle-comments (commentsp)
1997 "Remove comments, or convert to backend-specific format.
1998 COMMENTSP can be a format string for publishing comments.
1999 When it is nil, all comments will be removed."
2000 (let ((re "^#\\(.*\n?\\)")
2002 (goto-char (point-min))
2003 (while (or (looking-at re
)
2004 (re-search-forward re nil t
))
2005 (setq pos
(match-beginning 0))
2007 (progn (add-text-properties
2008 (match-beginning 0) (match-end 0) '(org-protected t
))
2009 (replace-match (format commentsp
(match-string 1)) t t
))
2010 (goto-char (1+ pos
))
2013 (goto-char (max (point-min) (1- pos
))))))))
2015 (defun org-export-mark-radio-links ()
2016 "Find all matches for radio targets and turn them into internal links."
2017 (let ((re-radio (and org-target-link-regexp
2018 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
2019 (goto-char (point-min))
2021 (while (re-search-forward re-radio nil t
)
2023 (replace-match "\\1[[\\2]]"))))))
2025 (defun org-export-remove-special-table-lines ()
2026 "Remove tables lines that are used for internal purposes."
2027 (goto-char (point-min))
2028 (while (re-search-forward "^[ \t]*|" nil t
)
2029 (beginning-of-line 1)
2030 (if (or (looking-at "[ \t]*| *[!_^] *|")
2031 (and (looking-at ".*?| *<[0-9]+> *|")
2032 (not (looking-at ".*?| *[^ <|]"))))
2033 (delete-region (max (point-min) (1- (point-at-bol)))
2037 (defun org-export-normalize-links ()
2038 "Convert all links to bracket links, and expand link abbreviations."
2039 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2040 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
2041 (goto-char (point-min))
2042 (while (re-search-forward re-plain-link nil t
)
2043 (goto-char (1- (match-end 0)))
2045 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2046 ":" (match-string 3) "]]")))
2047 ;; added 'org-link face to links
2048 (put-text-property 0 (length s
) 'face
'org-link s
)
2049 (replace-match s t t
))))
2050 (goto-char (point-min))
2051 (while (re-search-forward re-angle-link nil t
)
2052 (goto-char (1- (match-end 0)))
2054 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2055 ":" (match-string 3) "]]")))
2056 (put-text-property 0 (length s
) 'face
'org-link s
)
2057 (replace-match s t t
))))
2058 (goto-char (point-min))
2059 (while (re-search-forward org-bracket-link-regexp nil t
)
2060 (goto-char (1- (match-end 0)))
2062 (let* ((xx (save-match-data
2064 (org-link-expand-abbrev (match-string 1)))))
2066 "[[" (org-add-props (copy-sequence xx
)
2067 nil
'org-protected t
)
2071 (concat "[" (org-add-props
2076 (put-text-property 0 (length s
) 'face
'org-link s
)
2077 (replace-match s t t
))))))
2079 (defun org-export-concatenate-multiline-links ()
2080 "Find multi-line links and put it all into a single line.
2081 This is to make sure that the line-processing export backends
2082 can work correctly."
2083 (goto-char (point-min))
2084 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2086 (replace-match "\\1 \\3")
2087 (goto-char (match-beginning 0)))))
2089 (defun org-export-concatenate-multiline-emphasis ()
2090 "Find multi-line emphasis and put it all into a single line.
2091 This is to make sure that the line-processing export backends
2092 can work correctly."
2093 (goto-char (point-min))
2094 (while (re-search-forward org-emph-re nil t
)
2095 (if (and (not (= (char-after (match-beginning 3))
2096 (char-after (match-beginning 4))))
2097 (save-excursion (goto-char (match-beginning 0))
2098 (save-match-data (not (org-at-table-p)))))
2100 (subst-char-in-region (match-beginning 0) (match-end 0)
2102 (goto-char (1- (match-end 0))))
2103 (goto-char (1+ (match-beginning 0))))))
2105 (defun org-export-grab-title-from-buffer ()
2106 "Get a title for the current document, from looking at the buffer."
2107 (let ((inhibit-read-only t
))
2109 (goto-char (point-min))
2110 (let ((end (if (looking-at org-outline-regexp
)
2112 (save-excursion (outline-next-heading) (point)))))
2113 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2114 ;; Mark the line so that it will not be exported as normal text.
2116 (add-text-properties (match-beginning 0) (match-end 0)
2117 (list :org-license-to-kill t
)))
2118 ;; Return the title string
2119 (org-trim (match-string 0)))))))
2121 (defun org-export-get-title-from-subtree ()
2122 "Return subtree title and exclude it from export."
2123 (let (title (rbeg (region-beginning)) (rend (region-end)))
2126 (when (and (org-at-heading-p)
2127 (>= (org-end-of-subtree t t
) rend
))
2128 ;; This is a subtree, we take the title from the first heading
2130 (looking-at org-todo-line-regexp
)
2131 (setq title
(match-string 3))
2133 (add-text-properties (point) (1+ (point-at-eol))
2134 (list :org-license-to-kill t
)))
2135 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2138 (defun org-solidify-link-text (s &optional alist
)
2139 "Take link text and make a safe target out of it."
2144 (org-split-string s
"[ \t\r\n]+") "=="))
2145 (a (assoc rtn alist
)))
2148 (defun org-get-min-level (lines)
2149 "Get the minimum level in LINES."
2150 (let ((re "^\\(\\*+\\) ") l
)
2152 (while (setq l
(pop lines
))
2153 (if (string-match re l
)
2154 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
2157 ;; Variable holding the vector with section numbers
2158 (defvar org-section-numbers
(make-vector org-level-max
0))
2160 (defun org-init-section-numbers ()
2161 "Initialize the vector for the section numbers."
2163 (numbers (nreverse (org-split-string "" "\\.")))
2164 (depth (1- (length org-section-numbers
)))
2165 (i depth
) number-string
)
2168 (aset org-section-numbers i
0)
2169 (setq number-string
(or (car numbers
) "0"))
2170 (if (string-match "\\`[A-Z]\\'" number-string
)
2171 (aset org-section-numbers i
2172 (- (string-to-char number-string
) ?A -
1))
2173 (aset org-section-numbers i
(string-to-number number-string
)))
2177 (defun org-section-number (&optional level
)
2178 "Return a string with the current section number.
2179 When LEVEL is non-nil, increase section numbers on that level."
2180 (let* ((depth (1- (length org-section-numbers
)))
2182 (fmts (car org-export-section-number-format
))
2183 (term (cdr org-export-section-number-format
))
2188 (aset org-section-numbers
2189 level
(1+ (aref org-section-numbers level
))))
2190 (setq idx
(1+ level
))
2191 (while (<= idx depth
)
2193 (aset org-section-numbers idx
0))
2194 (setq idx
(1+ idx
))))
2196 (while (<= idx depth
)
2197 (when (> (aref org-section-numbers idx
) 0)
2198 (setq fmt
(or (pop fmts
) fmt
)
2200 n
(aref org-section-numbers idx
)
2202 (concat string sep
(org-number-to-counter n ctype
))
2203 (concat string
".0"))
2205 (setq idx
(1+ idx
)))
2207 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2208 (setq string
(replace-match "" t nil string
)))
2209 (if (string-match "\\(\\.0\\)+\\'" string
)
2210 (setq string
(replace-match "" t nil string
))))
2211 (concat string term
)))
2213 (defun org-number-to-counter (n type
)
2214 "Concert number N to a string counter, according to TYPE.
2215 TYPE must be a string, any of:
2219 I upper case roman numeral
2220 i lower case roman numeral"
2222 ((equal type
"1") (number-to-string n
))
2223 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2224 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2225 ((equal type
"I") (org-number-to-roman n
))
2226 ((equal type
"i") (downcase (org-number-to-roman n
)))
2227 (t (error "Invalid counter type `%s'" type
))))
2229 (defun org-number-to-roman (n)
2230 "Convert integer N into a roman numeral."
2231 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2232 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2233 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2237 (number-to-string n
)
2239 (if (>= n
(caar roman
))
2240 (setq n
(- n
(caar roman
))
2241 res
(concat res
(cdar roman
)))
2245 (org-number-to-roman 1961)
2250 (defun org-export-handle-include-files ()
2251 "Include the contents of include files, with proper formatting."
2252 (let ((case-fold-search t
)
2253 params file markup lang start end prefix prefix1 switches
)
2254 (goto-char (point-min))
2255 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2256 (setq params
(read (concat "(" (match-string 1) ")"))
2257 prefix
(org-get-and-remove-property 'params
:prefix
)
2258 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2259 file
(org-symname-or-string (pop params
))
2260 markup
(org-symname-or-string (pop params
))
2261 lang
(and (member markup
'("src" "SRC"))
2262 (org-symname-or-string (pop params
)))
2263 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2264 (delete-region (match-beginning 0) (match-end 0))
2266 (not (file-exists-p file
))
2267 (not (file-readable-p file
)))
2268 (insert (format "CANNOT INCLUDE FILE %s" file
))
2270 (if (equal (downcase markup
) "src")
2271 (setq start
(format "#+begin_src %s %s\n"
2272 (or lang
"fundamental")
2275 (setq start
(format "#+begin_%s %s\n" markup switches
)
2276 end
(format "#+end_%s" markup
))))
2277 (insert (or start
""))
2278 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2279 (or (bolp) (newline))
2280 (insert (or end
""))))))
2282 (defun org-get-file-contents (file &optional prefix prefix1
)
2283 "Get the contents of FILE and return them as a string.
2284 If PREFIX is a string, prepend it to each line. If PREFIX1
2285 is a string, prepend it to the first line instead of PREFIX."
2287 (insert-file-contents file
)
2288 (when (or prefix prefix1
)
2289 (goto-char (point-min))
2291 (insert (or prefix1 prefix
))
2293 (beginning-of-line 2)))
2296 (defun org-get-and-remove-property (listvar prop
)
2297 "Check if the value of LISTVAR contains PROP as a property.
2298 If yes, return the value of that property (i.e. the element following
2299 in the list) and remove property and value from the list in LISTVAR."
2300 (let ((list (symbol-value listvar
)) m v
)
2301 (when (setq m
(member prop list
))
2303 (if (equal (car list
) prop
)
2304 (set listvar
(cddr list
))
2305 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2307 (set listvar list
)))
2310 (defun org-symname-or-string (s)
2312 (if s
(symbol-name s
) s
)
2315 ;;; Fontification and line numbers for code examples
2317 (defvar org-export-last-code-line-counter-value
0)
2319 (defun org-export-replace-src-segments-and-examples (backend)
2320 "Replace source code segments with special code for export."
2321 (setq org-export-last-code-line-counter-value
0)
2322 (let ((case-fold-search t
)
2323 lang code trans opts
)
2324 (goto-char (point-min))
2325 (while (re-search-forward
2326 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2330 (setq lang
(match-string 2)
2331 opts
(match-string 3)
2332 code
(match-string 4))
2334 opts
(match-string 6)
2335 code
(match-string 7)))
2337 (setq trans
(org-export-format-source-code-or-example
2338 backend lang code opts
))
2339 (replace-match trans t t
))))
2341 (defvar htmlp
) ;; dynamically scoped
2342 (defvar latexp
) ;; dynamically scoped
2344 (defun org-export-format-source-code-or-example (backend
2345 lang code
&optional opts
)
2346 "Format CODE from language LANG and return it formatted for export.
2347 If LANG is nil, do not add any fontification.
2348 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2349 and `+n' for continuing previous numering.
2350 Code formatting according to language currently only works for HTML.
2351 Numbering lines works for all three major backends (html, latex, and ascii)."
2353 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2354 (setq opts
(or opts
"")
2355 num
(string-match "[-+]n\\>" opts
)
2356 cont
(string-match "\\+n\\>" opts
)
2357 rpllbl
(string-match "-r\\>" opts
)
2358 keepp
(string-match "-k\\>" opts
)
2359 textareap
(string-match "-t\\>" opts
)
2360 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2361 (string-to-number (match-string 1 opts
))
2363 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2364 (string-to-number (match-string 1 opts
))
2365 (org-count-lines code
))
2366 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2367 (match-string 1 opts
)))
2368 (when (and textareap
(eq backend
'html
))
2369 ;; we cannot use numbering or highlighting.
2370 (setq num nil cont nil lang nil
))
2371 (if keepp
(setq rpllbl
'keep
))
2373 (when (equal lang
"org")
2374 (setq rtn
(with-temp-buffer
2376 ;; Free up the protected lines
2377 (goto-char (point-min))
2378 (while (re-search-forward "^," nil t
)
2382 ;; Now backend-specific coding
2385 ;; We are exporting to HTML
2387 (require 'htmlize nil t
)
2388 (when (not (fboundp 'htmlize-region-for-paste
))
2389 ;; we do not have htmlize.el, or an old version of it
2392 "htmlize.el 1.34 or later is needed for source code formatting")))
2395 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2396 (org-inhibit-startup t
)
2397 (org-startup-folded nil
))
2401 (if (functionp mode
)
2404 (font-lock-fontify-buffer)
2405 (org-export-htmlize-region-for-paste
2406 (point-min) (point-max))))
2407 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2408 (setq rtn
(replace-match
2409 (format "<pre class=\"src src-%s\">\n" lang
)
2413 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2415 rtn
"</textarea>\n</p>\n"))
2418 (goto-char (point-min))
2419 (while (re-search-forward "[<>&]" nil t
)
2420 (replace-match (cdr (assq (char-before)
2421 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2423 (setq rtn
(buffer-string)))
2424 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2426 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2428 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2429 ((eq backend
'latex
)
2430 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2431 (concat "\n#+BEGIN_LaTeX\n"
2432 (org-add-props (concat "\\begin{verbatim}\n" rtn
"\n\\end{verbatim}\n")
2435 ((eq backend
'ascii
)
2436 ;; This is not HTML or LaTeX, so just make it an example.
2437 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2438 (concat "#+BEGIN_ASCII\n"
2442 (lambda (l) (concat " " l
))
2443 (org-split-string rtn
"\n")
2447 "#+END_ASCII\n"))))))
2449 (defun org-export-number-lines (text backend
2450 &optional skip1 skip2 number cont
2451 replace-labels label-format
)
2452 (if (and (not number
) (not (eq replace-labels
'keep
)))
2453 (setq replace-labels nil
)) ;; must use names if no numbers
2454 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2455 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2458 (goto-char (point-max))
2459 (skip-chars-backward " \t\n\r")
2460 (delete-region (point) (point-max))
2461 (beginning-of-line (- 1 skip2
))
2462 (let* ((last (org-current-line))
2463 (n org-export-last-code-line-counter-value
)
2464 (nmax (+ n
(- last skip1
)))
2465 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2468 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2470 ((eq backend
'ascii
) fmt
)
2471 ((eq backend
'latex
) fmt
)
2473 (label-format (or label-format org-coderef-label-format
))
2474 (label-pre (if (string-match "%s" label-format
)
2475 (substring label-format
0 (match-beginning 0))
2477 (label-post (if (string-match "%s" label-format
)
2478 (substring label-format
(match-end 0))
2482 ".*?\\S-.*?\\([ \t]*\\("
2483 (regexp-quote label-pre
)
2484 "\\([-a-zA-Z0-9_]+\\)"
2485 (regexp-quote label-post
)
2489 (goto-line (1+ skip1
))
2490 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2492 (insert (format fm
(incf n
)))
2494 (when (and (not (eq replace-labels
'keep
))
2495 (looking-at lbl-re
))
2496 (setq ref
(match-string 3))
2499 (delete-region (match-beginning 1) (match-end 1))
2500 (push (cons ref n
) org-export-code-refs
))
2501 (goto-char (match-beginning 2))
2502 (delete-region (match-beginning 2) (match-end 2))
2503 (insert "(" ref
")")
2504 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2505 (when (eq backend
'html
)
2507 (beginning-of-line 1)
2508 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2511 (insert "</span>")))))
2512 (setq org-export-last-code-line-counter-value n
)
2513 (goto-char (point-max))
2519 (defvar org-last-level nil
) ; dynamically scoped variable
2520 (defvar org-min-level nil
) ; dynamically scoped variable
2521 (defvar org-levels-open nil
) ; dynamically scoped parameter
2522 (defvar org-ascii-current-indentation nil
) ; For communication
2525 (defun org-export-as-ascii (arg)
2526 "Export the outline as a pretty ASCII file.
2527 If there is an active region, export only the region.
2528 The prefix ARG specifies how many levels of the outline should become
2529 underlined headlines. The default is 3."
2531 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2532 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2533 (org-infile-export-plist)))
2534 (region-p (org-region-active-p))
2535 (rbeg (and region-p
(region-beginning)))
2536 (rend (and region-p
(region-end)))
2541 (and (org-at-heading-p)
2542 (>= (org-end-of-subtree t t
) rend
)))))
2543 (opt-plist (if subtree-p
2544 (org-export-add-subtree-options opt-plist rbeg
)
2546 (custom-times org-display-custom-times
)
2547 (org-ascii-current-indentation '(0 .
0))
2551 (case-fold-search nil
)
2552 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2553 (filename (concat (file-name-as-directory
2554 (org-export-directory :ascii opt-plist
))
2555 (file-name-sans-extension
2557 (org-entry-get (region-beginning)
2558 "EXPORT_FILE_NAME" t
))
2559 (file-name-nondirectory bfname
)))
2561 (filename (if (equal (file-truename filename
)
2562 (file-truename bfname
))
2563 (concat filename
".txt")
2565 (buffer (find-file-noselect filename
))
2566 (org-levels-open (make-vector org-level-max nil
))
2567 (odd org-odd-levels-only
)
2568 (date (plist-get opt-plist
:date
))
2569 (author (plist-get opt-plist
:author
))
2570 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2571 (plist-get opt-plist
:title
)
2573 (plist-get opt-plist
:skip-before-1st-heading
))
2574 (org-export-grab-title-from-buffer))
2575 (file-name-sans-extension
2576 (file-name-nondirectory bfname
))))
2577 (email (plist-get opt-plist
:email
))
2578 (language (plist-get opt-plist
:language
))
2579 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2580 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2585 (if (org-region-active-p) (region-beginning) (point-min))
2586 (if (org-region-active-p) (region-end) (point-max))))
2587 (lines (org-split-string
2588 (org-export-preprocess-string
2591 :skip-before-1st-heading
2592 (plist-get opt-plist
:skip-before-1st-heading
)
2593 :drawers
(plist-get opt-plist
:drawers
)
2594 :tags
(plist-get opt-plist
:tags
)
2595 :priority
(plist-get opt-plist
:priority
)
2596 :footnotes
(plist-get opt-plist
:footnotes
)
2597 :timestamps
(plist-get opt-plist
:timestamps
)
2598 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
2599 :verbatim-multiline t
2600 :select-tags
(plist-get opt-plist
:select-tags
)
2601 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2603 (plist-get opt-plist
:archived-trees
)
2604 :add-text
(plist-get opt-plist
:text
))
2606 thetoc have-headings first-heading-pos
2607 table-open table-buffer link desc
)
2608 (let ((inhibit-read-only t
))
2610 (remove-text-properties (point-min) (point-max)
2611 '(:org-license-to-kill t
))))
2613 (setq org-min-level
(org-get-min-level lines
))
2614 (setq org-last-level org-min-level
)
2615 (org-init-section-numbers)
2617 (find-file-noselect filename
)
2619 (setq lang-words
(or (assoc language org-export-language-setup
)
2620 (assoc "en" org-export-language-setup
)))
2621 (switch-to-buffer-other-window buffer
)
2624 ;; create local variables for all options, to make sure all called
2625 ;; functions get the correct information
2627 (set (make-local-variable (nth 2 x
))
2628 (plist-get opt-plist
(car x
))))
2629 org-export-plist-vars
)
2630 (org-set-local 'org-odd-levels-only odd
)
2631 (setq umax
(if arg
(prefix-numeric-value arg
)
2632 org-export-headline-levels
))
2633 (setq umax-toc
(if (integerp org-export-with-toc
)
2634 (min org-export-with-toc umax
)
2638 (if title
(org-insert-centered title ?
=))
2640 (if (and (or author email
)
2641 org-export-author-info
)
2642 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2643 (if email
(concat " <" email
">") "")
2647 ((and date
(string-match "%" date
))
2648 (setq date
(format-time-string date
)))
2650 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2652 (if (and date org-export-time-stamp-file
)
2653 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2657 (if org-export-with-toc
2659 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2660 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2662 (mapc '(lambda (line)
2663 (if (string-match org-todo-line-regexp
2665 ;; This is a headline
2667 (setq have-headings t
)
2668 (setq level
(- (match-end 1) (match-beginning 1))
2669 level
(org-tr-level level
)
2670 txt
(match-string 3 line
)
2672 (or (and org-export-mark-todo-in-toc
2674 (not (member (match-string 2 line
)
2675 org-done-keywords
)))
2677 (and org-export-mark-todo-in-toc
2679 (org-search-todo-below
2680 line lines level
))))
2681 (setq txt
(org-html-expand-for-ascii txt
))
2683 (while (string-match org-bracket-link-regexp txt
)
2686 (match-string (if (match-end 2) 3 1) txt
)
2689 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2691 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2693 (setq txt
(replace-match "" t t txt
)))
2694 (if (string-match quote-re0 txt
)
2695 (setq txt
(replace-match "" t t txt
)))
2697 (if org-export-with-section-numbers
2698 (setq txt
(concat (org-section-number level
)
2700 (if (<= level umax-toc
)
2705 (* (max 0 (- level org-min-level
)) 4) ?\
)
2706 (format (if todo
"%s (*)\n" "%s\n") txt
))
2708 (setq org-last-level level
))
2711 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2713 (org-init-section-numbers)
2714 (while (setq line
(pop lines
))
2715 ;; Remove the quoted HTML tags.
2716 (setq line
(org-html-expand-for-ascii line
))
2717 ;; Replace links with the description when possible
2718 (while (string-match org-bracket-link-regexp line
)
2719 (setq link
(match-string 1 line
)
2720 desc
(match-string (if (match-end 3) 3 1) line
))
2721 (if (and (> (length link
) 8)
2722 (equal (substring link
0 8) "coderef:"))
2723 (setq line
(replace-match
2724 (format (org-export-get-coderef-format (substring link
8) desc
)
2727 org-export-code-refs
)))
2729 (setq line
(replace-match
2730 (if (match-end 3) "[\\3]" "[\\1]")
2733 (setq line
(org-translate-time line
)))
2735 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2737 (setq first-heading-pos
(or first-heading-pos
(point)))
2738 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2739 txt
(match-string 2 line
))
2740 (org-ascii-level-start level txt umax lines
))
2742 ((and org-export-with-tables
2743 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2744 (if (not table-open
)
2746 (setq table-open t table-buffer nil
))
2748 (setq table-buffer
(cons line table-buffer
))
2749 (when (or (not lines
)
2750 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2752 (setq table-open nil
2753 table-buffer
(nreverse table-buffer
))
2756 (org-fix-indentation x org-ascii-current-indentation
))
2757 (org-format-table-ascii table-buffer
)
2760 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2761 ;; Remove forced line breaks
2762 (if (string-match "\\\\\\\\[ \t]*$" line
)
2763 (setq line
(replace-match "" t t line
)))
2764 (if (and org-export-with-fixed-width
2765 (string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line
))
2766 (setq line
(replace-match "\\1" nil nil line
)))
2767 (insert line
"\n"))))
2771 ;; insert the table of contents
2773 (goto-char (point-min))
2774 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2776 (goto-char (match-beginning 0))
2778 (goto-char first-heading-pos
))
2779 (mapc 'insert thetoc
)
2780 (or (looking-at "[ \t]*\n[ \t]*\n")
2783 ;; Convert whitespace place holders
2784 (goto-char (point-min))
2786 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2787 (setq end
(next-single-property-change beg
'org-whitespace
))
2789 (delete-region beg end
)
2790 (insert (make-string (- end beg
) ?\
))))
2793 ;; remove display and invisible chars
2795 (goto-char (point-min))
2796 (while (setq beg
(next-single-property-change (point) 'display
))
2797 (setq end
(next-single-property-change beg
'display
))
2798 (delete-region beg end
)
2801 (goto-char (point-min))
2802 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2803 (setq end
(next-single-property-change beg
'org-cwidth
))
2804 (delete-region beg end
)
2806 (goto-char (point-min))))
2808 (defun org-export-ascii-preprocess ()
2809 "Do extra work for ASCII export"
2810 ;; Put quotes around verbatim text
2811 (goto-char (point-min))
2812 (while (re-search-forward org-verbatim-re nil t
)
2813 (goto-char (match-end 2))
2814 (backward-delete-char 1) (insert "'")
2815 (goto-char (match-beginning 2))
2816 (delete-char 1) (insert "`")
2817 (goto-char (match-end 2)))
2818 (goto-char (point-min))
2819 ;; Remove target markers
2820 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t
)
2821 (replace-match "\\1\\2")))
2823 (defun org-search-todo-below (line lines level
)
2824 "Search the subtree below LINE for any TODO entries."
2825 (let ((rest (cdr (memq line lines
)))
2826 (re org-todo-line-regexp
)
2829 (while (setq line
(pop rest
))
2830 (if (string-match re line
)
2832 (setq lv
(- (match-end 1) (match-beginning 1))
2833 todo
(and (match-beginning 2)
2834 (not (member (match-string 2 line
)
2835 org-done-keywords
))))
2837 (if (<= lv level
) (throw 'exit nil
))
2838 (if todo
(throw 'exit t
))))))))
2840 (defun org-html-expand-for-ascii (line)
2841 "Handle quoted HTML for ASCII export."
2842 (if org-export-html-expand
2843 (while (string-match "@<[^<>\n]*>" line
)
2844 ;; We just remove the tags for now.
2845 (setq line
(replace-match "" nil nil line
))))
2848 (defun org-insert-centered (s &optional underline
)
2849 "Insert the string S centered and underline it with character UNDERLINE."
2850 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2851 (insert (make-string ind ?\
) s
"\n")
2853 (insert (make-string ind ?\
)
2854 (make-string (string-width s
) underline
)
2857 (defun org-ascii-level-start (level title umax
&optional lines
)
2858 "Insert a new level in ASCII export."
2859 (let (char (n (- level umax
1)) (ind 0))
2862 (insert (make-string (* 2 n
) ?\
)
2863 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2864 org-export-ascii-bullets
))
2866 ;; find the indentation of the next non-empty line
2869 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2870 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2871 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2873 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2874 (if (or (not (equal (char-before) ?
\n))
2875 (not (equal (char-before (1- (point))) ?
\n)))
2877 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2878 (unless org-export-with-tags
2879 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2880 (setq title
(replace-match "" t t title
))))
2881 (if org-export-with-section-numbers
2882 (setq title
(concat (org-section-number level
) " " title
)))
2883 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2884 (setq org-ascii-current-indentation
'(0 .
0)))))
2887 (defun org-export-visible (type arg
)
2888 "Create a copy of the visible part of the current buffer, and export it.
2889 The copy is created in a temporary buffer and removed after use.
2890 TYPE is the final key (as a string) that also select the export command in
2891 the `C-c C-e' export dispatcher.
2892 As a special case, if the you type SPC at the prompt, the temporary
2893 org-mode file will not be removed but presented to you so that you can
2894 continue to use it. The prefix arg ARG is passed through to the exporting
2898 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2899 (read-char-exclusive))
2900 current-prefix-arg
))
2901 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2902 (error "Invalid export key"))
2903 (let* ((binding (cdr (assoc type
2904 '((?a . org-export-as-ascii
)
2905 (?\C-a . org-export-as-ascii
)
2906 (?b . org-export-as-html-and-open
)
2907 (?\C-b . org-export-as-html-and-open
)
2908 (?h . org-export-as-html
)
2909 (?H . org-export-as-html-to-buffer
)
2910 (?R . org-export-region-as-html
)
2911 (?x . org-export-as-xoxo
)))))
2912 (keepp (equal type ?\
))
2913 (file buffer-file-name
)
2914 (buffer (get-buffer-create "*Org Export Visible*"))
2916 ;; Need to hack the drawers here.
2918 (goto-char (point-min))
2919 (while (re-search-forward org-drawer-regexp nil t
)
2920 (goto-char (match-beginning 1))
2921 (or (org-invisible-p) (org-flag-drawer nil
))))
2922 (with-current-buffer buffer
(erase-buffer))
2924 (setq s
(goto-char (point-min)))
2925 (while (not (= (point) (point-max)))
2926 (goto-char (org-find-invisible))
2927 (append-to-buffer buffer s
(point))
2928 (setq s
(goto-char (org-find-visible))))
2929 (org-cycle-hide-drawers 'all
)
2930 (goto-char (point-min))
2932 ;; Copy all comment lines to the end, to make sure #+ settings are
2933 ;; still available for the second export step. Kind of a hack, but
2934 ;; does do the trick.
2935 (if (looking-at "#[^\r\n]*")
2936 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2937 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2938 (append-to-buffer buffer
(1+ (match-beginning 0))
2939 (min (point-max) (1+ (match-end 0))))))
2941 (let ((buffer-file-name file
)
2942 (org-inhibit-startup t
))
2945 (unless keepp
(funcall binding arg
))))
2947 (kill-buffer buffer
)
2948 (switch-to-buffer-other-window buffer
)
2949 (goto-char (point-min)))))
2951 (defun org-find-visible ()
2953 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2954 (get-char-property s
'invisible
)))
2956 (defun org-find-invisible ()
2958 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2959 (not (get-char-property s
'invisible
))))
2964 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2965 (defun org-get-current-options ()
2966 "Return a string with current options as keyword options.
2967 Does include HTML export options as well as TODO and CATEGORY stuff."
2968 (require 'org-archive
)
2975 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2976 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2978 #+EXPORT_SELECT_TAGS: %s
2979 #+EXPORT_EXCLUDE_TAGS: %s
2985 #+PRIORITIES: %c %c %c
2987 #+STARTUP: %s %s %s %s %s
2993 (buffer-name) (user-full-name) user-mail-address
2994 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2995 org-export-default-language
2996 org-export-headline-levels
2997 org-export-with-section-numbers
2999 org-export-preserve-breaks
3000 org-export-html-expand
3001 org-export-with-fixed-width
3002 org-export-with-tables
3003 org-export-with-sub-superscripts
3004 org-export-with-special-strings
3005 org-export-with-footnotes
3006 org-export-with-emphasize
3007 org-export-with-timestamps
3008 org-export-with-TeX-macros
3009 org-export-with-LaTeX-fragments
3010 org-export-skip-text-before-1st-heading
3011 org-export-with-drawers
3012 org-export-with-todo-keywords
3013 org-export-with-priority
3014 org-export-with-tags
3015 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
3016 (mapconcat 'identity org-export-select-tags
" ")
3017 (mapconcat 'identity org-export-exclude-tags
" ")
3018 org-export-html-link-up
3019 org-export-html-link-home
3021 (file-name-sans-extension
3022 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3024 "TODO FEEDBACK VERIFY DONE"
3025 "Me Jason Marie DONE"
3026 org-highest-priority org-lowest-priority org-default-priority
3027 (mapconcat 'identity org-drawers
" ")
3028 (cdr (assoc org-startup-folded
3029 '((nil .
"showall") (t .
"overview") (content .
"content"))))
3030 (if org-odd-levels-only
"odd" "oddeven")
3031 (if org-hide-leading-stars
"hidestars" "showstars")
3032 (if org-startup-align-all-tables
"align" "noalign")
3033 (cond ((eq org-log-done t
) "logdone")
3034 ((equal org-log-done
'note
) "lognotedone")
3035 ((not org-log-done
) "nologdone"))
3036 (or (mapconcat (lambda (x)
3038 ((equal '(:startgroup
) x
) "{")
3039 ((equal '(:endgroup
) x
) "}")
3040 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
3042 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
3043 (mapconcat 'identity org-file-tags
" ")
3044 org-archive-location
3045 "org file:~/org/%s.org"
3048 (defun org-export-html-preprocess (parameters)
3049 ;; Convert LaTeX fragments to images
3050 (when (plist-get parameters
:LaTeX-fragments
)
3052 (concat "ltxpng/" (file-name-sans-extension
3053 (file-name-nondirectory
3054 org-current-export-file
)))
3055 org-current-export-dir nil
"Creating LaTeX image %s"))
3056 (message "Exporting..."))
3059 (defun org-insert-export-options-template ()
3060 "Insert into the buffer a template with information for exporting."
3062 (if (not (bolp)) (newline))
3063 (let ((s (org-get-current-options)))
3064 (and (string-match "#\\+CATEGORY" s
)
3065 (setq s
(substring s
0 (match-beginning 0))))
3069 (defun org-export-as-html-and-open (arg)
3070 "Export the outline as HTML and immediately open it with a browser.
3071 If there is an active region, export only the region.
3072 The prefix ARG specifies how many levels of the outline should become
3073 headlines. The default is 3. Lower levels will become bulleted lists."
3075 (org-export-as-html arg
'hidden
)
3076 (org-open-file buffer-file-name
))
3079 (defun org-export-as-html-batch ()
3080 "Call `org-export-as-html', may be used in batch processing as
3082 --load=$HOME/lib/emacs/org.el
3083 --eval \"(setq org-export-headline-levels 2)\"
3084 --visit=MyFile --funcall org-export-as-html-batch"
3085 (org-export-as-html org-export-headline-levels
'hidden
))
3088 (defun org-export-as-html-to-buffer (arg)
3089 "Call `org-export-as-html` with output to a temporary buffer.
3090 No file is created. The prefix ARG is passed through to `org-export-as-html'."
3092 (org-export-as-html arg nil nil
"*Org HTML Export*")
3093 (switch-to-buffer-other-window "*Org HTML Export*"))
3096 (defun org-replace-region-by-html (beg end
)
3097 "Assume the current region has org-mode syntax, and convert it to HTML.
3098 This can be used in any buffer. For example, you could write an
3099 itemized list in org-mode syntax in an HTML buffer and then use this
3100 command to convert it."
3102 (let (reg html buf pop-up-frames
)
3103 (save-window-excursion
3105 (setq html
(org-export-region-as-html
3107 (setq reg
(buffer-substring beg end
)
3108 buf
(get-buffer-create "*Org tmp*"))
3109 (with-current-buffer buf
3113 (setq html
(org-export-region-as-html
3114 (point-min) (point-max) t
'string
)))
3116 (delete-region beg end
)
3120 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
3121 "Convert region from BEG to END in org-mode buffer to HTML.
3122 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
3123 contents, and only produce the region of converted text, useful for
3124 cut-and-paste operations.
3125 If BUFFER is a buffer or a string, use/create that buffer as a target
3126 of the converted HTML. If BUFFER is the symbol `string', return the
3127 produced HTML as a string and leave not buffer behind. For example,
3128 a Lisp program could call this function in the following way:
3130 (setq html (org-export-region-as-html beg end t 'string))
3132 When called interactively, the output buffer is selected, and shown
3133 in a window. A non-interactive call will only return the buffer."
3134 (interactive "r\nP")
3135 (when (interactive-p)
3136 (setq buffer
"*Org HTML Export*"))
3137 (let ((transient-mark-mode t
) (zmacs-regions t
)
3139 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
3141 (set-mark (point)) ;; to activate the region
3143 (setq rtn
(org-export-as-html
3146 (if (fboundp 'deactivate-mark
) (deactivate-mark))
3147 (if (and (interactive-p) (bufferp rtn
))
3148 (switch-to-buffer-other-window rtn
)
3151 (defvar html-table-tag nil
) ; dynamically scoped into this.
3152 (defvar org-par-open nil
)
3154 (defun org-export-as-html (arg &optional hidden ext-plist
3155 to-buffer body-only pub-dir
)
3156 "Export the outline as a pretty HTML file.
3157 If there is an active region, export only the region. The prefix
3158 ARG specifies how many levels of the outline should become
3159 headlines. The default is 3. Lower levels will become bulleted
3160 lists. When HIDDEN is non-nil, don't display the HTML buffer.
3161 EXT-PLIST is a property list with external parameters overriding
3162 org-mode's default settings, but still inferior to file-local
3163 settings. When TO-BUFFER is non-nil, create a buffer with that
3164 name and export to that buffer. If TO-BUFFER is the symbol
3165 `string', don't leave any buffer behind but just return the
3166 resulting HTML as a string. When BODY-ONLY is set, don't produce
3167 the file header and footer, simply return the content of
3168 <body>...</body>, without even the body tags themselves. When
3169 PUB-DIR is set, use this as the publishing directory."
3172 ;; Make sure we have a file name when we need it.
3173 (when (and (not (or to-buffer body-only
))
3174 (not buffer-file-name
))
3175 (if (buffer-base-buffer)
3176 (org-set-local 'buffer-file-name
3177 (with-current-buffer (buffer-base-buffer)
3179 (error "Need a file name to be able to export.")))
3181 (message "Exporting...")
3182 (setq-default org-todo-line-regexp org-todo-line-regexp
)
3183 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
3184 (setq-default org-done-keywords org-done-keywords
)
3185 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
3187 (org-export-process-option-filters
3188 (org-combine-plists (org-default-export-plist)
3190 (org-infile-export-plist))))
3191 (style (concat (if (plist-get opt-plist
:style-include-default
)
3192 org-export-html-style-default
)
3193 (plist-get opt-plist
:style
)
3194 (plist-get opt-plist
:style-extra
)
3195 "\n" org-export-html-scripts
))
3196 (html-extension (plist-get opt-plist
:html-extension
))
3197 (link-validate (plist-get opt-plist
:link-validation-function
))
3198 valid thetoc have-headings first-heading-pos
3199 (odd org-odd-levels-only
)
3200 (region-p (org-region-active-p))
3201 (rbeg (and region-p
(region-beginning)))
3202 (rend (and region-p
(region-end)))
3204 (if (plist-get opt-plist
:ignore-subree-p
)
3209 (and (org-at-heading-p)
3210 (>= (org-end-of-subtree t t
) rend
))))))
3211 (opt-plist (if subtree-p
3212 (org-export-add-subtree-options opt-plist rbeg
)
3214 ;; The following two are dynamically scoped into other
3216 (org-current-export-dir
3217 (or pub-dir
(org-export-directory :html opt-plist
)))
3218 (org-current-export-file buffer-file-name
)
3219 (level 0) (line "") (origline "") txt todo
3222 (filename (if to-buffer nil
3225 (file-name-sans-extension
3227 (org-entry-get (region-beginning)
3228 "EXPORT_FILE_NAME" t
))
3229 (file-name-nondirectory buffer-file-name
)))
3231 (file-name-as-directory
3232 (or pub-dir
(org-export-directory :html opt-plist
))))))
3233 (current-dir (if buffer-file-name
3234 (file-name-directory buffer-file-name
)
3236 (buffer (if to-buffer
3238 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
3239 (t (get-buffer-create to-buffer
)))
3240 (find-file-noselect filename
)))
3241 (org-levels-open (make-vector org-level-max nil
))
3242 (date (plist-get opt-plist
:date
))
3243 (author (plist-get opt-plist
:author
))
3244 (title (or (and subtree-p
(org-export-get-title-from-subtree))
3245 (plist-get opt-plist
:title
)
3247 (plist-get opt-plist
:skip-before-1st-heading
))
3248 (org-export-grab-title-from-buffer))
3249 (and buffer-file-name
3250 (file-name-sans-extension
3251 (file-name-nondirectory buffer-file-name
)))
3253 (html-table-tag (plist-get opt-plist
:html-table-tag
))
3254 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
3255 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
3260 (local-list-type nil
)
3261 (local-list-indent nil
)
3262 (llt org-plain-list-ordered-item-terminator
)
3263 (email (plist-get opt-plist
:email
))
3264 (language (plist-get opt-plist
:language
))
3268 (coding-system (and (boundp 'buffer-file-coding-system
)
3269 buffer-file-coding-system
))
3270 (coding-system-for-write (or org-export-html-coding-system
3272 (save-buffer-coding-system (or org-export-html-coding-system
3274 (charset (and coding-system-for-write
3275 (fboundp 'coding-system-get
)
3276 (coding-system-get coding-system-for-write
3280 (if region-p
(region-beginning) (point-min))
3281 (if region-p
(region-end) (point-max))))
3284 (org-export-preprocess-string
3288 :skip-before-1st-heading
3289 (plist-get opt-plist
:skip-before-1st-heading
)
3290 :drawers
(plist-get opt-plist
:drawers
)
3291 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
3292 :tags
(plist-get opt-plist
:tags
)
3293 :priority
(plist-get opt-plist
:priority
)
3294 :footnotes
(plist-get opt-plist
:footnotes
)
3295 :timestamps
(plist-get opt-plist
:timestamps
)
3297 (plist-get opt-plist
:archived-trees
)
3298 :select-tags
(plist-get opt-plist
:select-tags
)
3299 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
3301 (plist-get opt-plist
:text
)
3303 (plist-get opt-plist
:LaTeX-fragments
))
3306 table-buffer table-orig-buffer
3307 ind item-type starter didclose
3308 rpl path attr desc descp desc1 desc2 link
3309 snumber fnc item-tag
3310 footnotes footref-seen
3314 (let ((inhibit-read-only t
))
3316 (remove-text-properties (point-min) (point-max)
3317 '(:org-license-to-kill t
))))
3319 (message "Exporting...")
3321 (setq org-min-level
(org-get-min-level lines
))
3322 (setq org-last-level org-min-level
)
3323 (org-init-section-numbers)
3326 ((and date
(string-match "%" date
))
3327 (setq date
(format-time-string date
)))
3329 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
3331 ;; Get the language-dependent settings
3332 (setq lang-words
(or (assoc language org-export-language-setup
)
3333 (assoc "en" org-export-language-setup
)))
3335 ;; Switch to the output buffer
3337 (let ((inhibit-read-only t
)) (erase-buffer))
3340 (and (fboundp 'set-buffer-file-coding-system
)
3341 (set-buffer-file-coding-system coding-system-for-write
))
3343 (let ((case-fold-search nil
)
3344 (org-odd-levels-only odd
))
3345 ;; create local variables for all options, to make sure all called
3346 ;; functions get the correct information
3348 (set (make-local-variable (nth 2 x
))
3349 (plist-get opt-plist
(car x
))))
3350 org-export-plist-vars
)
3351 (setq umax
(if arg
(prefix-numeric-value arg
)
3352 org-export-headline-levels
))
3353 (setq umax-toc
(if (integerp org-export-with-toc
)
3354 (min org-export-with-toc umax
)
3359 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3360 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3361 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3362 lang=\"%s\" xml:lang=\"%s\">
3365 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3366 <meta name=\"generator\" content=\"Org-mode\"/>
3367 <meta name=\"generated\" content=\"%s\"/>
3368 <meta name=\"author\" content=\"%s\"/>
3372 language language
(org-html-expand title
)
3373 (or charset
"iso-8859-1") date author style
))
3375 (insert (or (plist-get opt-plist
:preamble
) ""))
3377 (when (plist-get opt-plist
:auto-preamble
)
3378 (if title
(insert (format org-export-html-title-format
3379 (org-html-expand title
))))))
3381 (if (and org-export-with-toc
(not body-only
))
3383 (push (format "<h%d>%s</h%d>\n"
3384 org-export-html-toplevel-hlevel
3386 org-export-html-toplevel-hlevel
)
3388 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3389 (push "<ul>\n<li>" thetoc
)
3391 (mapcar '(lambda (line)
3392 (if (string-match org-todo-line-regexp line
)
3393 ;; This is a headline
3395 (setq have-headings t
)
3396 (setq level
(- (match-end 1) (match-beginning 1))
3397 level
(org-tr-level level
)
3398 txt
(save-match-data
3400 (org-export-cleanup-toc-line
3401 (match-string 3 line
))))
3403 (or (and org-export-mark-todo-in-toc
3405 (not (member (match-string 2 line
)
3406 org-done-keywords
)))
3408 (and org-export-mark-todo-in-toc
3410 (org-search-todo-below
3411 line lines level
))))
3413 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3414 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3415 (if (string-match quote-re0 txt
)
3416 (setq txt
(replace-match "" t t txt
)))
3417 (setq snumber
(org-section-number level
))
3418 (if org-export-with-section-numbers
3419 (setq txt
(concat snumber
" " txt
)))
3420 (if (<= level
(max umax umax-toc
))
3421 (setq head-count
(+ head-count
1)))
3422 (if (<= level umax-toc
)
3424 (if (> level org-last-level
)
3426 (setq cnt
(- level org-last-level
))
3427 (while (>= (setq cnt
(1- cnt
)) 0)
3428 (push "\n<ul>\n<li>" thetoc
))
3429 (push "\n" thetoc
)))
3430 (if (< level org-last-level
)
3432 (setq cnt
(- org-last-level level
))
3433 (while (>= (setq cnt
(1- cnt
)) 0)
3434 (push "</li>\n</ul>" thetoc
))
3435 (push "\n" thetoc
)))
3436 ;; Check for targets
3437 (while (string-match org-any-target-regexp line
)
3438 (setq line
(replace-match
3439 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3441 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3442 (setq txt
(replace-match "" t t txt
)))
3446 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3447 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3448 snumber txt
) thetoc
)
3450 (setq org-last-level level
))
3454 (while (> org-last-level
(1- org-min-level
))
3455 (setq org-last-level
(1- org-last-level
))
3456 (push "</li>\n</ul>\n" thetoc
))
3457 (push "</div>\n" thetoc
)
3458 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3461 (org-init-section-numbers)
3465 (while (setq line
(pop lines
) origline line
)
3468 ;; end of quote section?
3469 (when (and inquote
(string-match "^\\*+ " line
))
3472 ;; inside a quote section?
3474 (insert (org-html-protect line
) "\n")
3475 (throw 'nextline nil
))
3477 ;; Fixed-width, verbatim lines (examples)
3478 (when (and org-export-with-fixed-width
3479 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
3482 (org-close-par-maybe)
3483 (insert "<pre class=\"example\">\n"))
3484 (insert (org-html-protect (match-string 3 line
)) "\n")
3485 (when (or (not lines
)
3486 (not (string-match "^[ \t]*\\(:.*\\)"
3489 (insert "</pre>\n"))
3490 (throw 'nextline nil
))
3493 (when (get-text-property 0 'org-protected line
)
3495 (when (re-search-backward
3496 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3497 (setq par
(match-string 1))
3498 (replace-match "\\2\n"))
3501 (or (= (length (car lines
)) 0)
3502 (get-text-property 0 'org-protected
(car lines
))))
3503 (insert (pop lines
) "\n"))
3504 (and par
(insert "<p>\n")))
3505 (throw 'nextline nil
))
3508 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3510 (insert "\n</p>\n<hr/>\n<p>\n")
3511 (insert "\n<hr/>\n"))
3512 (throw 'nextline nil
))
3514 ;; Blockquotes and verse
3515 (when (equal "ORG-BLOCKQUOTE-START" line
)
3516 (org-close-par-maybe)
3517 (insert "<blockquote>\n<p>\n")
3518 (throw 'nextline nil
))
3519 (when (equal "ORG-BLOCKQUOTE-END" line
)
3520 (insert "</p>\n</blockquote>\n")
3521 (throw 'nextline nil
))
3522 (when (equal "ORG-VERSE-START" line
)
3523 (org-close-par-maybe)
3524 (insert "\n<p class=\"verse\">\n")
3526 (throw 'nextline nil
))
3527 (when (equal "ORG-VERSE-END" line
)
3530 (throw 'nextline nil
))
3532 (let ((i (org-get-string-indentation line
)))
3534 (setq line
(concat (mapconcat 'identity
3535 (make-list (* 2 i
) "\\nbsp") "")
3536 " " (org-trim line
))))
3537 (setq line
(concat line
"\\\\"))))
3539 ;; make targets to anchors
3540 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3543 (setq line
(replace-match
3545 "@<a name=\"%s\" id=\"%s\">@</a>"
3546 (org-solidify-link-text (match-string 1 line
))
3547 (org-solidify-link-text (match-string 1 line
)))
3549 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3550 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3551 (setq line
(replace-match
3552 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3553 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3556 (setq line
(replace-match
3557 (concat "@<a name=\""
3558 (org-solidify-link-text (match-string 1 line
))
3559 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3562 (setq line
(org-html-handle-time-stamps line
))
3564 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3565 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3566 ;; Also handle sub_superscripts and checkboxes
3567 (or (string-match org-table-hline-regexp line
)
3568 (setq line
(org-html-expand line
)))
3572 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
3573 (setq start
(match-beginning 0))
3574 (setq path
(save-match-data (org-link-unescape
3575 (match-string 3 line
))))
3577 ((match-end 2) (match-string 2 line
))
3579 (or (file-name-absolute-p path
)
3580 (string-match "^\\.\\.?/" path
)))
3583 (setq path
(org-extract-attributes (org-link-unescape path
)))
3584 (setq attr
(get-text-property 0 'org-attributes path
))
3585 (setq desc1
(if (match-end 5) (match-string 5 line
))
3586 desc2
(if (match-end 2) (concat type
":" path
) path
)
3587 descp
(and desc1
(not (equal desc1 desc2
)))
3588 desc
(or desc1 desc2
))
3589 ;; Make an image out of the description if that is so wanted
3590 (when (and descp
(org-file-image-p
3591 desc org-export-html-inline-image-extensions
))
3593 (if (string-match "^file:" desc
)
3594 (setq desc
(substring desc
(match-end 0)))))
3595 (setq desc
(org-add-props
3596 (concat "<img src=\"" desc
"\"/>")
3597 '(org-protected t
))))
3598 ;; FIXME: do we need to unescape here somewhere?
3600 ((equal type
"internal")
3604 (org-solidify-link-text
3605 (save-match-data (org-link-unescape path
)) nil
)
3607 (org-export-html-format-desc desc
)
3609 ((and (equal type
"id")
3610 (setq id-file
(org-id-find-id-file path
)))
3611 ;; This is an id: link to another file (if it was the same file,
3612 ;; it would have become an internal link...)
3613 (setq id-file
(file-relative-name
3614 id-file
(file-name-directory org-current-export-file
)))
3615 (setq id-file
(concat (file-name-sans-extension id-file
)
3616 "." html-extension
))
3617 (setq rpl
(concat "<a href=\"" id-file
"#" path
"\""
3619 (org-export-html-format-desc desc
)
3621 ((member type
'("http" "https"))
3622 ;; standard URL, just check if we need to inline an image
3623 (if (and (or (eq t org-export-html-inline-images
)
3624 (and org-export-html-inline-images
(not descp
)))
3626 path org-export-html-inline-image-extensions
))
3627 (setq rpl
(org-export-html-format-image
3628 (concat type
":" path
)))
3629 (setq link
(concat type
":" path
))
3630 (setq rpl
(concat "<a href=\""
3631 (org-export-html-format-href link
)
3633 (org-export-html-format-desc desc
)
3635 ((member type
'("ftp" "mailto" "news"))
3637 (setq link
(concat type
":" path
))
3638 (setq rpl
(concat "<a href=\""
3639 (org-export-html-format-href link
)
3641 (org-export-html-format-desc desc
)
3644 ((string= type
"coderef")
3646 (setq rpl
(format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3648 (format (org-export-get-coderef-format path
(and descp desc
))
3649 (cdr (assoc path org-export-code-refs
))))))
3651 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3652 ;; The link protocol has a function for format the link
3655 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3657 ((string= type
"file")
3659 (let* ((filename path
)
3660 (abs-p (file-name-absolute-p filename
))
3661 thefile file-is-image-p search
)
3663 (if (string-match "::\\(.*\\)" filename
)
3664 (setq search
(match-string 1 filename
)
3665 filename
(replace-match "" t nil filename
)))
3667 (if (functionp link-validate
)
3668 (funcall link-validate filename current-dir
)
3670 (setq file-is-image-p
3672 filename org-export-html-inline-image-extensions
))
3673 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3674 (when (and org-export-html-link-org-files-as-html
3675 (string-match "\\.org$" thefile
))
3676 (setq thefile
(concat (substring thefile
0
3677 (match-beginning 0))
3678 "." html-extension
))
3680 ;; make sure this is can be used as target search
3681 (not (string-match "^[0-9]*$" search
))
3682 (not (string-match "^\\*" search
))
3683 (not (string-match "^/.*/$" search
)))
3684 (setq thefile
(concat thefile
"#"
3685 (org-solidify-link-text
3686 (org-link-unescape search
)))))
3687 (when (string-match "^file:" desc
)
3688 (setq desc
(replace-match "" t t desc
))
3689 (if (string-match "\\.org$" desc
)
3690 (setq desc
(replace-match "" t t desc
))))))
3691 (setq rpl
(if (and file-is-image-p
3692 (or (eq t org-export-html-inline-images
)
3693 (and org-export-html-inline-images
3695 (org-export-html-format-image thefile
)
3696 (concat "<a href=\"" thefile
"\"" attr
">"
3697 (org-export-html-format-desc desc
)
3699 (if (not valid
) (setq rpl desc
))))
3702 ;; just publish the path, as default
3703 (setq rpl
(concat "<i><" type
":"
3704 (save-match-data (org-link-unescape path
))
3706 (setq line
(replace-match rpl t t line
)
3707 start
(+ start
(length rpl
))))
3710 (if (and (string-match org-todo-line-regexp line
)
3711 (match-beginning 2))
3714 (concat (substring line
0 (match-beginning 2))
3716 (if (member (match-string 2 line
)
3719 "\">" (match-string 2 line
)
3720 "</span>" (substring line
(match-end 2)))))
3722 ;; Does this contain a reference to a footnote?
3723 (when org-export-with-footnotes
3725 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3726 (if (get-text-property (match-beginning 2) 'org-protected line
)
3727 (setq start
(match-end 2))
3728 (let ((n (match-string 2 line
)) extra a
)
3729 (if (setq a
(assoc n footref-seen
))
3731 (setcdr a
(1+ (cdr a
)))
3732 (setq extra
(format ".%d" (cdr a
))))
3734 (push (cons n
1) footref-seen
))
3738 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
3739 (match-string 1 line
) n extra n n
)
3743 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3744 ;; This is a headline
3745 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3746 txt
(match-string 2 line
))
3747 (if (string-match quote-re0 txt
)
3748 (setq txt
(replace-match "" t t txt
)))
3749 (if (<= level
(max umax umax-toc
))
3750 (setq head-count
(+ head-count
1)))
3752 ;; Close any local lists before inserting a new header line
3753 (while local-list-type
3754 (org-close-li (car local-list-type
))
3755 (insert (format "</%sl>\n" (car local-list-type
)))
3756 (pop local-list-type
))
3757 (setq local-list-indent nil
3759 (setq first-heading-pos
(or first-heading-pos
(point)))
3760 (org-html-level-start level txt umax
3761 (and org-export-with-toc
(<= level umax
))
3764 (when (string-match quote-re line
)
3765 (org-close-par-maybe)
3769 ((and org-export-with-tables
3770 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3771 (if (not table-open
)
3773 (setq table-open t table-buffer nil table-orig-buffer nil
))
3775 (setq table-buffer
(cons line table-buffer
)
3776 table-orig-buffer
(cons origline table-orig-buffer
))
3777 (when (or (not lines
)
3778 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3780 (setq table-open nil
3781 table-buffer
(nreverse table-buffer
)
3782 table-orig-buffer
(nreverse table-orig-buffer
))
3783 (org-close-par-maybe)
3784 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3789 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3790 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3791 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3792 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3794 (setq ind
(org-get-string-indentation line
)
3795 item-type
(if (match-beginning 4) "o" "u")
3796 starter
(if (match-beginning 2)
3797 (substring (match-string 2 line
) 0 -
1))
3798 line
(substring line
(match-beginning 5))
3800 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3802 item-tag
(match-string 1 line
)
3803 line
(substring line
(match-end 0))))
3804 (when (and (not (equal item-type
"d"))
3805 (not (string-match "[^ \t]" line
)))
3806 ;; empty line. Pretend indentation is large.
3807 (setq ind
(if org-empty-line-terminates-plain-lists
3809 (1+ (or (car local-list-indent
) 1)))))
3811 (while (and in-local-list
3812 (or (and (= ind
(car local-list-indent
))
3814 (< ind
(car local-list-indent
))))
3816 (org-close-li (car local-list-type
))
3817 (insert (format "</%sl>\n" (car local-list-type
)))
3818 (pop local-list-type
) (pop local-list-indent
)
3819 (setq in-local-list local-list-indent
))
3822 (or (not in-local-list
)
3823 (> ind
(car local-list-indent
))))
3824 ;; Start new (level of) list
3825 (org-close-par-maybe)
3827 ((equal item-type
"u") "<ul>\n<li>\n")
3828 ((equal item-type
"o") "<ol>\n<li>\n")
3829 ((equal item-type
"d")
3830 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3831 (push item-type local-list-type
)
3832 (push ind local-list-indent
)
3833 (setq in-local-list t
))
3835 ;; continue current list
3836 (org-close-li (car local-list-type
))
3838 ((equal (car local-list-type
) "d")
3839 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3842 ;; we did close a list, normal text follows: need <p>
3844 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3847 (if (equal (match-string 1 line
) "X")
3849 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3852 ;; Empty lines start a new paragraph. If hand-formatted lists
3853 ;; are not fully interpreted, lines starting with "-", "+", "*"
3854 ;; also start a new paragraph.
3855 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3857 ;; Is this the start of a footnote?
3858 (when org-export-with-footnotes
3859 (when (and (boundp 'footnote-section-tag-regexp
)
3860 (string-match (concat "^" footnote-section-tag-regexp
)
3863 (throw 'nextline nil
))
3864 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3865 (org-close-par-maybe)
3866 (let ((n (match-string 1 line
)))
3867 (setq org-par-open t
3869 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
3871 ;; Check if the line break needs to be conserved
3873 ((string-match "\\\\\\\\[ \t]*$" line
)
3874 (setq line
(replace-match "<br/>" t t line
)))
3875 (org-export-preserve-breaks
3876 (setq line
(concat line
"<br/>"))))
3878 ;; Check if a paragraph should be started
3880 (while (and org-par-open
3881 (string-match "\\\\par\\>" line start
))
3882 ;; Leave a space in the </p> so that the footnote matcher
3883 ;; does not see this.
3884 (if (not (get-text-property (match-beginning 0)
3885 'org-protected line
))
3886 (setq line
(replace-match "</p ><p >" t t line
)))
3887 (setq start
(match-end 0))))
3889 (insert line
"\n")))))
3891 ;; Properly close all local lists and other lists
3896 ;; Close any local lists before inserting a new header line
3897 (while local-list-type
3898 (org-close-li (car local-list-type
))
3899 (insert (format "</%sl>\n" (car local-list-type
)))
3900 (pop local-list-type
))
3901 (setq local-list-indent nil
3903 (org-html-level-start 1 nil umax
3904 (and org-export-with-toc
(<= level umax
))
3906 ;; the </div> to close the last text-... div.
3907 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
3910 (goto-char (point-min))
3911 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
3912 (push (match-string 0) footnotes
)
3913 (replace-match "" t t
)))
3915 (insert (format org-export-html-footnotes-section
3916 (or (nth 4 lang-words
) "Footnotes")
3917 (mapconcat 'identity
(nreverse footnotes
) "\n"))
3920 (when (plist-get opt-plist
:auto-postamble
)
3921 (insert "<div id=\"postamble\">")
3922 (when (and org-export-author-info author
)
3923 (insert "<p class=\"author\"> "
3924 (nth 1 lang-words
) ": " author
"\n")
3926 (if (listp (split-string email
",+ *"))
3928 (insert "<a href=\"mailto:" e
"\"><"
3930 (split-string email
",+ *"))
3931 (insert "<a href=\"mailto:" email
"\"><"
3932 email
"></a>\n")))
3934 (when (and date org-export-time-stamp-file
)
3935 (insert "<p class=\"date\"> "
3936 (nth 2 lang-words
) ": "
3938 (when org-export-creator-info
3939 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3940 org-version emacs-major-version
)))
3943 (if org-export-html-with-timestamp
3944 (insert org-export-html-html-helper-timestamp
))
3945 (insert (or (plist-get opt-plist
:postamble
) ""))
3946 (insert "</body>\n</html>\n"))
3948 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3950 (if (eq major-mode default-major-mode
) (html-mode)))
3952 ;; insert the table of contents
3953 (goto-char (point-min))
3955 (if (or (re-search-forward
3956 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3958 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3960 (goto-char (match-beginning 0))
3962 (goto-char first-heading-pos
)
3963 (when (looking-at "\\s-*</p>")
3964 (goto-char (match-end 0))
3966 (insert "<div id=\"table-of-contents\">\n")
3967 (mapc 'insert thetoc
)
3968 (insert "</div>\n"))
3969 ;; remove empty paragraphs and lists
3970 (goto-char (point-min))
3971 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3973 (goto-char (point-min))
3974 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3976 (goto-char (point-min))
3977 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3979 ;; Convert whitespace place holders
3980 (goto-char (point-min))
3982 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3983 (setq n
(get-text-property beg
'org-whitespace
)
3984 end
(next-single-property-change beg
'org-whitespace
))
3986 (delete-region beg end
)
3987 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3988 (make-string n ?x
)))))
3989 (or to-buffer
(save-buffer))
3990 (goto-char (point-min))
3991 (message "Exporting... done")
3992 (if (eq to-buffer
'string
)
3993 (prog1 (buffer-substring (point-min) (point-max))
3994 (kill-buffer (current-buffer)))
3995 (current-buffer)))))
3997 (defun org-export-get-coderef-format (path desc
)
3999 (if (and desc
(string-match
4000 (regexp-quote (concat "(" path
")"))
4002 (replace-match "%s" t t desc
)
4006 (defun org-export-html-format-href (s)
4007 "Make sure the S is valid as a href reference in an XHTML document."
4010 (while (string-match "&" s start
)
4011 (setq start
(+ (match-beginning 0) 3)
4012 s
(replace-match "&" t t s
)))))
4015 (defun org-export-html-format-desc (s)
4016 "Make sure the S is valid as a description in a link."
4017 (if (and s
(not (get-text-property 1 'org-protected s
)))
4019 (org-html-do-expand s
))
4022 (defun org-export-html-format-image (src)
4023 "Create image tag with source and attributes."
4025 (if (string-match "^ltxpng/" src
)
4026 (format "<img src=\"%s\"/>" src
)
4027 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
4028 (attr (org-find-text-property-in-string 'org-attributes src
))
4029 (label (org-find-text-property-in-string 'org-label src
)))
4030 (format "<div %sclass=\"figure\">
4031 <p><img src=\"%s\"%s /></p>%s
4033 (if label
(format "id=\"%s\" " label
) "")
4035 (if (string-match "\\<alt=" (or attr
""))
4037 (concat " " attr
" alt=\"" src
"\""))
4038 (if caption
(concat "\n<p>" caption
"</p>") ""))))))
4040 (defvar org-table-colgroup-info nil
)
4041 (defun org-format-table-ascii (lines)
4042 "Format a table for ascii export."
4044 (setq lines
(org-split-string lines
"\n")))
4045 (if (not (string-match "^[ \t]*|" (car lines
)))
4046 ;; Table made by table.el - test for spanning
4049 ;; A normal org table
4050 ;; Get rid of hlines at beginning and end
4051 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4052 (setq lines
(nreverse lines
))
4053 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4054 (setq lines
(nreverse lines
))
4055 (when org-export-table-remove-special-lines
4056 ;; Check if the table has a marking column. If yes remove the
4057 ;; column and the special lines
4058 (setq lines
(org-table-clean-before-export lines
)))
4059 ;; Get rid of the vertical lines except for grouping
4060 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
4062 (while (setq line
(pop lines
))
4063 (if (string-match org-table-hline-regexp line
)
4064 (and (string-match "|\\(.*\\)|" line
)
4065 (setq line
(replace-match " \\1" t nil line
)))
4066 (setq start
0 vl1 vl
)
4067 (while (string-match "|" line start
)
4068 (setq start
(match-end 0))
4069 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
4073 (defun org-colgroup-info-to-vline-list (info)
4076 (setq last new new
(pop info
))
4077 (if (or (memq last
'(:end
:startend
))
4078 (memq new
'(:start
:startend
)))
4081 (setq vl
(nreverse vl
))
4082 (and vl
(setcar vl nil
))
4085 (defvar org-table-number-regexp
) ; defined in org-table.el
4086 (defun org-format-table-html (lines olines
)
4087 "Find out which HTML converter to use and return the HTML code."
4089 (setq lines
(org-split-string lines
"\n")))
4090 (if (string-match "^[ \t]*|" (car lines
))
4091 ;; A normal org table
4092 (org-format-org-table-html lines
)
4093 ;; Table made by table.el - test for spanning
4094 (let* ((hlines (delq nil
(mapcar
4096 (if (string-match "^[ \t]*\\+-" x
) x
4099 (first (car hlines
))
4100 (ll (and (string-match "\\S-+" first
)
4101 (match-string 0 first
)))
4102 (re (concat "^[ \t]*" (regexp-quote ll
)))
4103 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
4105 (if (and (not spanning
)
4106 (not org-export-prefer-native-exporter-for-tables
))
4107 ;; We can use my own converter with HTML conversions
4108 (org-format-table-table-html lines
)
4109 ;; Need to use the code generator in table.el, with the original text.
4110 (org-format-table-table-html-using-table-generate-source olines
)))))
4112 (defvar org-table-number-fraction
) ; defined in org-table.el
4113 (defun org-format-org-table-html (lines &optional splice
)
4114 "Format a table into HTML."
4115 (require 'org-table
)
4116 ;; Get rid of hlines at beginning and end
4117 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4118 (setq lines
(nreverse lines
))
4119 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4120 (setq lines
(nreverse lines
))
4121 (when org-export-table-remove-special-lines
4122 ;; Check if the table has a marking column. If yes remove the
4123 ;; column and the special lines
4124 (setq lines
(org-table-clean-before-export lines
)))
4126 (let ((caption (or (get-text-property 0 'org-caption
(car lines
))
4127 (get-text-property (or (next-single-property-change
4128 0 'org-caption
(car lines
))
4130 'org-caption
(car lines
))))
4131 (head (and org-export-highlight-first-table-line
4133 (lambda (x) (string-match "^[ \t]*|-" x
))
4137 tbopen line fields html gr colgropen
)
4138 (if splice
(setq head nil
))
4139 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
4141 (while (setq line
(pop lines
))
4143 (if (string-match "^[ \t]*|-" line
)
4146 (push (if head
"</thead>" "</tbody>") html
)
4147 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
4148 (setq head nil
) ;; head ends here, first time around
4150 (throw 'next-line t
)))
4151 ;; Break the line into fields
4152 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4153 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
4154 (setq nlines
(1+ nlines
) i -
1)
4155 (push (concat "<tr>"
4159 (if (and (< i nlines
)
4160 (string-match org-table-number-regexp x
))
4161 (incf (aref fnum i
)))
4163 (concat (car org-export-table-header-tags
) x
4164 (cdr org-export-table-header-tags
))
4165 (concat (car org-export-table-data-tags
) x
4166 (cdr org-export-table-data-tags
))))
4170 (unless splice
(if tbopen
(push "</tbody>" html
)))
4171 (unless splice
(push "</table>\n" html
))
4172 (setq html
(nreverse html
))
4174 ;; Put in col tags with the alignment (unfortunately often ignored...)
4177 (setq gr
(pop org-table-colgroup-info
))
4178 (format "%s<col align=\"%s\"></col>%s"
4179 (if (memq gr
'(:start
:startend
))
4181 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
4184 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
4186 (if (memq gr
'(:end
:startend
))
4187 (progn (setq colgropen nil
) "</colgroup>")
4191 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
4192 (if caption
(push (format "<caption>%s</caption>" caption
) html
))
4193 (push html-table-tag html
))
4194 (concat (mapconcat 'identity html
"\n") "\n")))
4196 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
4197 "Check if the table has a marking column.
4198 If yes remove the column and the special lines."
4199 (setq org-table-colgroup-info nil
)
4202 (lambda (x) (or (string-match "^[ \t]*|-" x
)
4205 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
4206 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
4210 (setq org-table-clean-did-remove-column nil
)
4215 ((string-match "^[ \t]*| */ *|" x
)
4216 (setq org-table-colgroup-info
4218 (cond ((member x
'("<" "<")) :start
)
4219 ((member x
'(">" ">")) :end
)
4220 ((member x
'("<>" "<>")) :startend
)
4222 (org-split-string x
"[ \t]*|[ \t]*")))
4226 (setq org-table-clean-did-remove-column t
)
4231 ((string-match "^[ \t]*| */ *|" x
)
4232 (setq org-table-colgroup-info
4234 (cond ((member x
'("<" "<")) :start
)
4235 ((member x
'(">" ">")) :end
)
4236 ((member x
'("<>" "<>")) :startend
)
4238 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
4240 ((string-match "^[ \t]*| *[!_^/] *|" x
)
4241 nil
) ; ignore this line
4242 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
4243 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
4244 ;; remove the first column
4245 (replace-match "\\1|" t nil x
))))
4248 (defun org-format-table-table-html (lines)
4249 "Format a table generated by table.el into HTML.
4250 This conversion does *not* use `table-generate-source' from table.el.
4251 This has the advantage that Org-mode's HTML conversions can be used.
4252 But it has the disadvantage, that no cell- or row-spanning is allowed."
4253 (let (line field-buffer
4254 (head org-export-highlight-first-table-line
)
4256 (setq html
(concat html-table-tag
"\n"))
4257 (while (setq line
(pop lines
))
4258 (setq empty
" ")
4260 (if (string-match "^[ \t]*\\+-" line
)
4271 (if (equal x
"") (setq x empty
))
4273 (concat (car org-export-table-header-tags
) x
4274 (cdr org-export-table-header-tags
))
4275 (concat (car org-export-table-data-tags
) x
4276 (cdr org-export-table-data-tags
))))
4280 (setq field-buffer nil
)))
4282 (throw 'next-line t
)))
4283 ;; Break the line into fields and store the fields
4284 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4286 (setq field-buffer
(mapcar
4288 (concat x
"<br/>" (pop fields
)))
4290 (setq field-buffer fields
))))
4291 (setq html
(concat html
"</table>\n"))
4294 (defun org-format-table-table-html-using-table-generate-source (lines)
4295 "Format a table into html, using `table-generate-source' from table.el.
4296 This has the advantage that cell- or row-spanning is allowed.
4297 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4299 (with-current-buffer (get-buffer-create " org-tmp1 ")
4301 (insert (mapconcat 'identity lines
"\n"))
4302 (goto-char (point-min))
4303 (if (not (re-search-forward "|[^+]" nil t
))
4304 (error "Error processing table"))
4305 (table-recognize-table)
4306 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4307 (table-generate-source 'html
" org-tmp2 ")
4308 (set-buffer " org-tmp2 ")
4309 (buffer-substring (point-min) (point-max))))
4311 (defun org-export-splice-style (style extra
)
4312 "Splice EXTRA into STYLE, just before \"</style>\"."
4313 (if (and (stringp extra
)
4314 (string-match "\\S-" extra
)
4315 (string-match "</style>" style
))
4316 (concat (substring style
0 (match-beginning 0))
4318 (substring style
(match-beginning 0)))
4321 (defun org-html-handle-time-stamps (s)
4322 "Format time stamps in string S, or remove them."
4325 (while (string-match org-maybe-keyword-time-regexp s
)
4326 (or b
(setq b
(substring s
0 (match-beginning 0))))
4328 r
(substring s
0 (match-beginning 0))
4330 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4331 (match-string 1 s
)))
4332 (format " @<span class=\"timestamp\">%s@</span>"
4334 (org-translate-time (match-string 3 s
)) 1 -
1)))
4335 s
(substring s
(match-end 0))))
4336 ;; Line break if line started and ended with time stamp stuff
4339 (setq r
(concat r s
))
4340 (unless (string-match "\\S-" (concat b s
))
4341 (setq r
(concat r
"@<br/>")))
4344 (defun org-export-htmlize-region-for-paste (beg end
)
4345 "Convert the region to HTML, using htmlize.el.
4346 This is much like `htmlize-region-for-paste', only that it uses
4347 the settings define in the org-... variables."
4348 (let* ((htmlize-output-type org-export-htmlize-output-type
)
4349 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
4350 (htmlbuf (htmlize-region beg end
)))
4352 (with-current-buffer htmlbuf
4353 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
4354 (plist-get htmlize-buffer-places
'content-end
)))
4355 (kill-buffer htmlbuf
))))
4358 (defun org-export-htmlize-generate-css ()
4359 "Create the CSS for all font definitions in the current Emacs session.
4360 Use this to create face definitions in your CSS style file that can then
4361 be used by code snippets transformed by htmlize.
4362 This command just produces a buffer that contains class definitions for all
4363 faces used in the current Emacs session. You can copy and paste the ones you
4364 need into your CSS file.
4366 If you then set `org-export-htmlize-output-type' to `css', calls to
4367 the function `org-export-htmlize-region-for-paste' will produce code
4368 that uses these same face definitions."
4371 (and (get-buffer "*html*") (kill-buffer "*html*"))
4373 (let ((fl (face-list))
4374 (htmlize-css-name-prefix "org-")
4375 (htmlize-output-type 'css
)
4377 (while (setq f
(pop fl
)
4378 i
(and f
(face-attribute f
:inherit
)))
4379 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
4380 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
4381 (htmlize-region (point-min) (point-max))))
4382 (switch-to-buffer "*html*")
4383 (goto-char (point-min))
4384 (if (re-search-forward "<style" nil t
)
4385 (delete-region (point-min) (match-beginning 0)))
4386 (if (re-search-forward "</style>" nil t
)
4387 (delete-region (1+ (match-end 0)) (point-max)))
4388 (beginning-of-line 1)
4389 (if (looking-at " +") (replace-match ""))
4390 (goto-char (point-min)))
4392 (defun org-html-protect (s)
4393 ;; convert & to &, < to < and > to >
4395 (while (string-match "&" s start
)
4396 (setq s
(replace-match "&" t t s
)
4397 start
(1+ (match-beginning 0))))
4398 (while (string-match "<" s
)
4399 (setq s
(replace-match "<" t t s
)))
4400 (while (string-match ">" s
)
4401 (setq s
(replace-match ">" t t s
)))
4402 ; (while (string-match "\"" s)
4403 ; (setq s (replace-match """ t t s)))
4407 (defun org-export-cleanup-toc-line (s)
4408 "Remove tags and timestamps from lines going into the toc."
4409 (when (memq org-export-with-tags
'(not-in-toc nil
))
4410 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
4411 (setq s
(replace-match "" t t s
))))
4412 (when org-export-remove-timestamps-from-toc
4413 (while (string-match org-maybe-keyword-time-regexp s
)
4414 (setq s
(replace-match "" t t s
))))
4415 (while (string-match org-bracket-link-regexp s
)
4416 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
4420 (defun org-html-expand (string)
4421 "Prepare STRING for HTML export. Applies all active conversions.
4422 If there are links in the string, don't modify these."
4423 (let* ((re (concat org-bracket-link-regexp
"\\|"
4424 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4426 (while (setq m
(string-match re string
))
4427 (setq s
(substring string
0 m
)
4428 l
(match-string 0 string
)
4429 string
(substring string
(match-end 0)))
4430 (push (org-html-do-expand s
) res
)
4432 (push (org-html-do-expand string
) res
)
4433 (apply 'concat
(nreverse res
))))
4435 (defun org-html-do-expand (s)
4436 "Apply all active conversions to translate special ASCII to HTML."
4437 (setq s
(org-html-protect s
))
4438 (if org-export-html-expand
4439 (while (string-match "@<\\([^&]*\\)>" s
)
4440 (setq s
(replace-match "<\\1>" t nil s
))))
4441 (if org-export-with-emphasize
4442 (setq s
(org-export-html-convert-emphasize s
)))
4443 (if org-export-with-special-strings
4444 (setq s
(org-export-html-convert-special-strings s
)))
4445 (if org-export-with-sub-superscripts
4446 (setq s
(org-export-html-convert-sub-super s
)))
4447 (if org-export-with-TeX-macros
4448 (let ((start 0) wd ass
)
4449 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4451 (if (get-text-property (match-beginning 0) 'org-protected s
)
4452 (setq start
(match-end 0))
4453 (setq wd
(match-string 1 s
))
4454 (if (setq ass
(assoc wd org-html-entities
))
4455 (setq s
(replace-match (or (cdr ass
)
4456 (concat "&" (car ass
) ";"))
4458 (setq start
(+ start
(length wd
))))))))
4461 (defun org-create-multibrace-regexp (left right n
)
4462 "Create a regular expression which will match a balanced sexp.
4463 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4464 as single character strings.
4465 The regexp returned will match the entire expression including the
4466 delimiters. It will also define a single group which contains the
4467 match except for the outermost delimiters. The maximum depth of
4468 stacked delimiters is N. Escaping delimiters is not possible."
4469 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4472 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4475 re
(concat re or next
)
4476 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4477 (concat left
"\\(" re
"\\)" right
)))
4479 (defvar org-match-substring-regexp
4481 "\\([^\\]\\)\\([_^]\\)\\("
4482 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4484 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4486 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4487 "The regular expression matching a sub- or superscript.")
4489 (defvar org-match-substring-with-braces-regexp
4491 "\\([^\\]\\)\\([_^]\\)\\("
4492 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4494 "The regular expression matching a sub- or superscript, forcing braces.")
4496 (defconst org-export-html-special-string-regexps
4497 '(("\\\\-" .
"­")
4498 ("---\\([^-]\\)" .
"—\\1")
4499 ("--\\([^-]\\)" .
"–\\1")
4500 ("\\.\\.\\." .
"…"))
4501 "Regular expressions for special string conversion.")
4503 (defun org-export-html-convert-special-strings (string)
4504 "Convert special characters in STRING to HTML."
4505 (let ((all org-export-html-special-string-regexps
)
4507 (while (setq a
(pop all
))
4508 (setq re
(car a
) rpl
(cdr a
) start
0)
4509 (while (string-match re string start
)
4510 (if (get-text-property (match-beginning 0) 'org-protected string
)
4511 (setq start
(match-end 0))
4512 (setq string
(replace-match rpl t nil string
)))))
4515 (defun org-export-html-convert-sub-super (string)
4516 "Convert sub- and superscripts in STRING to HTML."
4517 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4518 (while (string-match org-match-substring-regexp string s
)
4520 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4521 ((get-text-property (match-beginning 2) 'org-protected string
)
4522 (setq s
(match-end 2)))
4524 (setq s
(match-end 1)
4525 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4526 c
(or (match-string 8 string
)
4527 (match-string 6 string
)
4528 (match-string 5 string
))
4529 string
(replace-match
4530 (concat (match-string 1 string
)
4531 "<" key
">" c
"</" key
">")
4533 (while (string-match "\\\\\\([_^]\\)" string
)
4534 (setq string
(replace-match (match-string 1 string
) t t string
)))
4537 (defun org-export-html-convert-emphasize (string)
4540 (while (string-match org-emph-re string s
)
4542 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4543 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4544 (setq s
(match-beginning 0)
4547 (match-string 1 string
)
4548 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4549 (match-string 4 string
)
4550 (nth 3 (assoc (match-string 3 string
)
4551 org-emphasis-alist
))
4552 (match-string 5 string
))
4553 string
(replace-match rpl t t string
)
4554 s
(+ s
(- (length rpl
) 2)))
4558 (defun org-open-par ()
4559 "Insert <p>, but first close previous paragraph if any."
4560 (org-close-par-maybe)
4562 (setq org-par-open t
))
4563 (defun org-close-par-maybe ()
4564 "Close paragraph if there is one open."
4567 (setq org-par-open nil
)))
4568 (defun org-close-li (&optional type
)
4569 "Close <li> if necessary."
4570 (org-close-par-maybe)
4571 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4573 (defvar body-only
) ; dynamically scoped into this.
4574 (defun org-html-level-start (level title umax with-toc head-count
)
4575 "Insert a new level in HTML export.
4576 When TITLE is nil, just close all open levels."
4577 (org-close-par-maybe)
4578 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
4580 (mapconcat (lambda (x)
4581 (format "<a name=\"%s\" id=\"%s\"></a>"
4583 (cdr (assoc target org-export-target-aliases
))
4588 (if (aref org-levels-open
(1- l
))
4590 (org-html-level-close l umax
)
4591 (aset org-levels-open
(1- l
) nil
)))
4594 ;; If title is nil, this means this function is called to close
4595 ;; all levels, so the rest is done only if title is given
4596 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4597 (setq title
(replace-match
4598 (if org-export-with-tags
4601 " <span class=\"tag\">"
4602 (mapconcat 'identity
(org-split-string
4603 (match-string 1 title
) ":")
4610 (if (aref org-levels-open
(1- level
))
4614 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
4615 (insert "<li>" title
"<br/>\n")))
4616 (aset org-levels-open
(1- level
) t
)
4617 (org-close-par-maybe)
4619 (insert (format "<ul>\n<li id=\"%s\">" target
)
4620 extra-targets title
"<br/>\n")
4621 (insert "<ul>\n<li>" title
"<br/>\n"))))
4622 (aset org-levels-open
(1- level
) t
)
4623 (setq snumber
(org-section-number level
))
4624 (if (and org-export-with-section-numbers
(not body-only
))
4625 (setq title
(concat snumber
" " title
)))
4626 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4627 (unless (= head-count
1) (insert "\n</div>\n"))
4628 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div id=\"text-%s\">\n"
4629 snumber level level snumber extra-targets title level snumber
))
4632 (defun org-get-text-property-any (pos prop
&optional object
)
4633 (or (get-text-property pos prop object
)
4634 (and (setq pos
(next-single-property-change pos prop object
))
4635 (get-text-property pos prop object
))))
4637 (defun org-html-level-close (level max-outline-level
)
4638 "Terminate one level in HTML export."
4639 (if (<= level max-outline-level
)
4642 (insert "</ul>\n")))
4644 ;;; iCalendar export
4647 (defun org-export-icalendar-this-file ()
4648 "Export current file as an iCalendar file.
4649 The iCalendar file will be located in the same directory as the Org-mode
4650 file, but with extension `.ics'."
4652 (org-export-icalendar nil buffer-file-name
))
4655 (defun org-export-icalendar-all-agenda-files ()
4656 "Export all files in `org-agenda-files' to iCalendar .ics files.
4657 Each iCalendar file will be located in the same directory as the Org-mode
4658 file, but with extension `.ics'."
4660 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4663 (defun org-export-icalendar-combine-agenda-files ()
4664 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4665 The file is stored under the name `org-combined-agenda-icalendar-file'."
4667 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4669 (defun org-export-icalendar (combine &rest files
)
4670 "Create iCalendar files for all elements of FILES.
4671 If COMBINE is non-nil, combine all calendar entries into a single large
4672 file and store it under the name `org-combined-agenda-icalendar-file'."
4674 (org-prepare-agenda-buffers files
)
4675 (let* ((dir (org-export-directory
4676 :ical
(list :publishing-directory
4677 org-export-publishing-directory
)))
4678 file ical-file ical-buffer category started org-agenda-new-buffers
)
4679 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4682 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4683 org-combined-agenda-icalendar-file
4684 (expand-file-name org-combined-agenda-icalendar-file dir
))
4685 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4686 (set-buffer ical-buffer
) (erase-buffer))
4687 (while (setq file
(pop files
))
4689 (org-check-agenda-file file
)
4690 (set-buffer (org-get-agenda-file-buffer file
))
4692 (setq ical-file
(concat (file-name-as-directory dir
)
4693 (file-name-sans-extension
4694 (file-name-nondirectory buffer-file-name
))
4696 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4697 (with-current-buffer ical-buffer
(erase-buffer)))
4698 (setq category
(or org-category
4699 (file-name-sans-extension
4700 (file-name-nondirectory buffer-file-name
))))
4701 (if (symbolp category
) (setq category
(symbol-name category
)))
4702 (let ((standard-output ical-buffer
))
4704 (and (not started
) (setq started t
)
4705 (org-start-icalendar-file org-icalendar-combined-name
))
4706 (org-start-icalendar-file category
))
4707 (org-print-icalendar-entries combine
)
4708 (when (or (and combine
(not files
)) (not combine
))
4709 (org-finish-icalendar-file)
4710 (set-buffer ical-buffer
)
4711 (run-hooks 'org-before-save-iCalendar-file-hook
)
4713 (run-hooks 'org-after-save-iCalendar-file-hook
)
4714 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4716 (org-release-buffers org-agenda-new-buffers
))))
4718 (defvar org-before-save-iCalendar-file-hook nil
4719 "Hook run before an iCalendar file has been saved.
4720 This can be used to modify the result of the export.")
4722 (defvar org-after-save-iCalendar-file-hook nil
4723 "Hook run after an iCalendar file has been saved.
4724 The iCalendar buffer is still current when this hook is run.
4725 A good way to use this is to tell a desktop calendar application to re-read
4726 the iCalendar file.")
4728 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4729 (defun org-print-icalendar-entries (&optional combine
)
4730 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4731 When COMBINE is non nil, add the category to each line."
4732 (require 'org-agenda
)
4733 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4734 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4735 (dts (org-ical-ts-to-string
4736 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4738 hd ts ts2 state status
(inc t
) pos b sexp rrule
4739 scheduledp deadlinep todo prefix due start
4740 tmp pri categories location summary desc uid
4741 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4742 (org-refresh-category-properties)
4744 (goto-char (point-min))
4745 (while (re-search-forward re1 nil t
)
4748 (when (boundp 'org-icalendar-verify-function
)
4749 (unless (funcall org-icalendar-verify-function
)
4750 (outline-next-heading)
4753 (setq pos
(match-beginning 0)
4756 hd
(condition-case nil
4757 (org-icalendar-cleanup-string
4759 (error (throw :skip nil
)))
4760 summary
(org-icalendar-cleanup-string
4761 (org-entry-get nil
"SUMMARY"))
4762 desc
(org-icalendar-cleanup-string
4763 (or (org-entry-get nil
"DESCRIPTION")
4764 (and org-icalendar-include-body
(org-get-entry)))
4765 t org-icalendar-include-body
)
4766 location
(org-icalendar-cleanup-string
4767 (org-entry-get nil
"LOCATION" 'selective
))
4768 uid
(if org-icalendar-store-UID
4770 (or (org-id-get) (org-id-new)))
4771 categories
(org-export-get-categories)
4772 deadlinep nil scheduledp nil
)
4773 (if (looking-at re2
)
4775 (goto-char (match-end 0))
4776 (setq ts2
(match-string 1)
4777 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4778 (setq tmp
(buffer-substring (max (point-min)
4779 (- pos org-ds-keyword-length
))
4781 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4784 (replace-match "\\1" t nil ts
))
4786 deadlinep
(string-match org-deadline-regexp tmp
)
4787 scheduledp
(string-match org-scheduled-regexp tmp
)
4788 todo
(org-get-todo-state)
4789 ;; donep (org-entry-is-done-p)
4794 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4795 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4800 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4801 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4803 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4804 (if (or (string-match org-tr-regexp hd
)
4805 (string-match org-ts-regexp hd
))
4806 (setq hd
(replace-match "" t t hd
)))
4807 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4809 (concat "\nRRULE:FREQ="
4812 '(("d" .
"DAILY")("w" .
"WEEKLY")
4813 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4814 ";INTERVAL=" (match-string 1 ts
)))
4816 (setq summary
(or summary hd
))
4817 (if (string-match org-bracket-link-regexp summary
)
4819 (replace-match (if (match-end 3)
4820 (match-string 3 summary
)
4821 (match-string 1 summary
))
4823 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4824 (if scheduledp
(setq summary
(concat "S: " summary
)))
4825 (if (string-match "\\`<%%" ts
)
4826 (with-current-buffer sexp-buffer
4827 (insert (substring ts
1 -
1) " " summary
"\n"))
4828 (princ (format "BEGIN:VEVENT
4836 (org-ical-ts-to-string ts
"DTSTART")
4837 (org-ical-ts-to-string ts2
"DTEND" inc
)
4839 (if (and desc
(string-match "\\S-" desc
))
4840 (concat "\nDESCRIPTION: " desc
) "")
4841 (if (and location
(string-match "\\S-" location
))
4842 (concat "\nLOCATION: " location
) "")
4844 (when (and org-icalendar-include-sexps
4845 (condition-case nil
(require 'icalendar
) (error nil
))
4846 (fboundp 'icalendar-export-region
))
4847 ;; Get all the literal sexps
4848 (goto-char (point-min))
4849 (while (re-search-forward "^&?%%(" nil t
)
4852 (setq b
(match-beginning 0))
4853 (goto-char (1- (match-end 0)))
4856 (setq sexp
(buffer-substring b
(point)))
4857 (with-current-buffer sexp-buffer
4858 (insert sexp
"\n"))))
4859 (princ (org-diary-to-ical-string sexp-buffer
))
4860 (kill-buffer sexp-buffer
))
4862 (when org-icalendar-include-todo
4863 (setq prefix
"TODO-")
4864 (goto-char (point-min))
4865 (while (re-search-forward org-todo-line-regexp nil t
)
4868 (when (boundp 'org-icalendar-verify-function
)
4869 (unless (funcall org-icalendar-verify-function
)
4870 (outline-next-heading)
4873 (setq state
(match-string 2))
4874 (setq status
(if (member state org-done-keywords
)
4875 "COMPLETED" "NEEDS-ACTION"))
4877 (or (not (member state org-done-keywords
))
4878 (eq org-icalendar-include-todo
'all
))
4879 (not (member org-archive-tag
(org-get-tags-at)))
4881 (setq hd
(match-string 3)
4882 summary
(org-icalendar-cleanup-string
4883 (org-entry-get nil
"SUMMARY"))
4884 desc
(org-icalendar-cleanup-string
4885 (or (org-entry-get nil
"DESCRIPTION")
4886 (and org-icalendar-include-body
(org-get-entry)))
4887 t org-icalendar-include-body
)
4888 location
(org-icalendar-cleanup-string
4889 (org-entry-get nil
"LOCATION" 'selective
))
4890 due
(and (member 'todo-due org-icalendar-use-deadline
)
4891 (org-entry-get nil
"DEADLINE"))
4892 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4893 (org-entry-get nil
"SCHEDULED"))
4894 categories
(org-export-get-categories)
4895 uid
(if org-icalendar-store-UID
4897 (or (org-id-get) (org-id-new))))
4898 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4899 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4901 (if (string-match org-bracket-link-regexp hd
)
4902 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4903 (match-string 1 hd
))
4905 (if (string-match org-priority-regexp hd
)
4906 (setq pri
(string-to-char (match-string 2 hd
))
4907 hd
(concat (substring hd
0 (match-beginning 1))
4908 (substring hd
(match-end 1))))
4909 (setq pri org-default-priority
))
4910 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4911 (- org-lowest-priority org-highest-priority
))))))
4913 (princ (format "BEGIN:VTODO
4925 (if (and location
(string-match "\\S-" location
))
4926 (concat "\nLOCATION: " location
) "")
4927 (if (and desc
(string-match "\\S-" desc
))
4928 (concat "\nDESCRIPTION: " desc
) "")
4929 (if due
(concat "\n" due
) "")
4933 (defun org-export-get-categories ()
4934 "Get categories according to `org-icalendar-categories'."
4935 (let ((cs org-icalendar-categories
) c rtn tmp
)
4936 (while (setq c
(pop cs
))
4938 ((eq c
'category
) (push (org-get-category) rtn
))
4940 (setq tmp
(org-get-todo-state))
4941 (and tmp
(push tmp rtn
)))
4943 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4945 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4946 (mapconcat 'identity
(nreverse rtn
) ",")))
4948 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4949 "Take out stuff and quote what needs to be quoted.
4950 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4951 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4956 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4957 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4958 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4959 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4961 (while (string-match "\\([,;]\\)" s start
)
4962 (setq start
(+ (match-beginning 0) 2)
4963 s
(replace-match "\\\\\\1" nil nil s
))))
4964 (setq s
(org-trim s
))
4966 (while (string-match "[ \t]*\n[ \t]*" s
)
4967 (setq s
(replace-match "\\n" t t s
))))
4970 (if (and (numberp maxlength
)
4971 (> (length s
) maxlength
))
4972 (setq s
(substring s
0 maxlength
)))))
4975 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength
)
4976 "Take out stuff and quote what needs to be quoted.
4977 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4978 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4980 This seems to be more like RFC 2455, but it causes problems, so it is
4981 not used right now."
4985 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4986 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4987 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4988 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))
4989 (setq s
(org-trim s
))
4990 (while (string-match "[ \t]*\n[ \t]*" s
)
4991 (setq s
(replace-match "\\n" t t s
)))
4993 (if (and (numberp maxlength
)
4994 (> (length s
) maxlength
))
4995 (setq s
(substring s
0 maxlength
)))))
4996 (setq s
(org-trim s
)))
4997 (while (string-match "\"" s
) (setq s
(replace-match "''" t t s
)))
4998 (when (string-match "[;,:]" s
) (setq s
(concat "\"" s
"\"")))
5001 (defun org-get-entry ()
5002 "Clean-up description string."
5004 (org-back-to-heading t
)
5005 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
5007 (defun org-start-icalendar-file (name)
5008 "Start an iCalendar file by inserting the header."
5009 (let ((user user-full-name
)
5010 (name (or name
"unknown"))
5011 (timezone (cadr (current-time-zone))))
5013 (format "BEGIN:VCALENDAR
5016 PRODID:-//%s//Emacs with Org-mode//EN
5018 CALSCALE:GREGORIAN\n" name user timezone
))))
5020 (defun org-finish-icalendar-file ()
5021 "Finish an iCalendar file by inserting the END statement."
5022 (princ "END:VCALENDAR\n"))
5024 (defun org-ical-ts-to-string (s keyword
&optional inc
)
5025 "Take a time string S and convert it to iCalendar format.
5026 KEYWORD is added in front, to make a complete line like DTSTART....
5027 When INC is non-nil, increase the hour by two (if time string contains
5028 a time), or the day by one (if it does not contain a time)."
5029 (let ((t1 (org-parse-time-string s
'nodefault
))
5030 t2 fmt have-time time
)
5031 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
5032 (setq t2 t1 have-time t
)
5033 (setq t2
(org-parse-time-string s
)))
5034 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
5035 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
5038 (if org-agenda-default-appointment-duration
5039 (setq mi
(+ org-agenda-default-appointment-duration mi
))
5042 (setq time
(encode-time s mi h d m y
)))
5043 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
5044 (concat keyword
(format-time-string fmt time
))))
5048 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
5049 (with-current-buffer buffer
5050 (apply 'insert output
)))
5051 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
5054 (defun org-export-as-xoxo (&optional buffer
)
5055 "Export the org buffer as XOXO.
5056 The XOXO buffer is named *xoxo-<source buffer name>*"
5057 (interactive (list (current-buffer)))
5058 ;; A quickie abstraction
5060 ;; Output everything as XOXO
5061 (with-current-buffer (get-buffer buffer
)
5062 (let* ((pos (point))
5063 (opt-plist (org-combine-plists (org-default-export-plist)
5064 (org-infile-export-plist)))
5065 (filename (concat (file-name-as-directory
5066 (org-export-directory :xoxo opt-plist
))
5067 (file-name-sans-extension
5068 (file-name-nondirectory buffer-file-name
))
5070 (out (find-file-noselect filename
))
5073 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
5074 ;; Check the output buffer is empty.
5075 (with-current-buffer out
(erase-buffer))
5076 ;; Kick off the output
5077 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
5078 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
5079 (let* ((hd (match-string-no-properties 1))
5082 (match-string-no-properties 2)
5084 (goto-char (match-end 0))
5089 (if (looking-at "^[ \t]\\(.*\\)")
5090 (setq str
(concat str
(match-string-no-properties 1)))
5091 (throw 'loop str
)))))))))
5093 ;; Handle level rendering
5095 ((> level last-level
)
5096 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
5098 ((< level last-level
)
5099 (dotimes (- (- last-level level
) 1)
5101 (org-export-as-xoxo-insert-into out
"</li>\n"))
5102 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5104 (org-export-as-xoxo-insert-into out
"</li>\n")
5105 (setq hanging-li nil
)))
5107 ((equal level last-level
)
5109 (org-export-as-xoxo-insert-into out
"</li>\n")))
5112 (setq last-level level
)
5114 ;; And output the new li
5115 (setq hanging-li
't
)
5116 (if (equal ?
+ (elt text
0))
5117 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
5118 (org-export-as-xoxo-insert-into out
"<li>" text
))))
5120 ;; Finally finish off the ol
5121 (dotimes (- last-level
1)
5123 (org-export-as-xoxo-insert-into out
"</li>\n"))
5124 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5127 ;; Finish the buffer off and clean it up.
5128 (switch-to-buffer-other-window out
)
5129 (indent-region (point-min) (point-max) nil
)
5131 (goto-char (point-min))
5136 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
5138 ;;; org-exp.el ends here