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=\"text-footnotes\">
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: #add8e6; font-weight:normal }
565 .timestamp { color: #bebebe; }
566 .timestamp-kwd { color: #5f9ea0; }
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 This is also important for the classes that will be wrapped around headlines
658 and outline structure. If this variable is 1, the top-level headlines will
659 be <h1>, and the corresponding classes will be outline-1, section-number-1,
660 and outline-text-1. If this is 2, all of these will get a 2 instead.
661 The default for this variable is 2, because we use <h1> for formatting the
663 :group
'org-export-html
666 (defcustom org-export-html-link-org-files-as-html t
667 "Non-nil means, make file links to `file.org' point to `file.html'.
668 When org-mode is exporting an org-mode file to HTML, links to
669 non-html files are directly put into a href tag in HTML.
670 However, links to other Org-mode files (recognized by the
671 extension `.org.) should become links to the corresponding html
672 file, assuming that the linked org-mode file will also be
674 When nil, the links still point to the plain `.org' file."
675 :group
'org-export-html
678 (defcustom org-export-html-inline-images
'maybe
679 "Non-nil means, inline images into exported HTML pages.
680 This is done using an <img> tag. When nil, an anchor with href is used to
681 link to the image. If this option is `maybe', then images in links with
682 an empty description will be inlined, while images with a description will
684 :group
'org-export-html
685 :type
'(choice (const :tag
"Never" nil
)
686 (const :tag
"Always" t
)
687 (const :tag
"When there is no description" maybe
)))
689 (defcustom org-export-html-inline-image-extensions
690 '("png" "jpeg" "jpg" "gif")
691 "Extensions of image files that can be inlined into HTML."
692 :group
'org-export-html
693 :type
'(repeat (string :tag
"Extension")))
696 (defcustom org-export-html-expand t
697 "Non-nil means, for HTML export, treat @<...> as HTML tag.
698 When nil, these tags will be exported as plain text and therefore
699 not be interpreted by a browser.
701 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
702 :group
'org-export-html
705 (defcustom org-export-html-table-tag
706 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
707 "The HTML tag that is used to start a table.
708 This must be a <table> tag, but you may change the options like
709 borders and spacing."
710 :group
'org-export-html
713 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
714 "The opening tag for table header 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-table-data-tags
'("<td>" .
"</td>")
720 "The opening tag for table data fields.
721 This is customizable so that alignment options can be specified."
722 :group
'org-export-tables
723 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
725 (defcustom org-export-html-with-timestamp nil
726 "If non-nil, write `org-export-html-html-helper-timestamp'
727 into the exported HTML text. Otherwise, the buffer will just be saved
729 :group
'org-export-html
732 (defcustom org-export-html-html-helper-timestamp
733 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
734 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
735 :group
'org-export-html
738 (defgroup org-export-htmlize nil
739 "Options for processing examples with htmlize.el."
740 :tag
"Org Export Htmlize"
741 :group
'org-export-html
)
743 (defcustom org-export-htmlize-output-type
'inline-css
744 "Output type to be used by htmlize when formatting code snippets.
745 Normally this is `inline-css', but if you have defined to appropriate
746 classes in your css style file, setting this to `css' means that the
747 fontification will use the class names.
748 See also the function `org-export-htmlize-generate-css'."
749 :group
'org-export-htmlize
750 :type
'(choice (const css
) (const inline-css
)))
752 (defcustom org-export-htmlize-css-font-prefix
"org-"
753 "The prefix for CSS class names for htmlize font specifications."
754 :group
'org-export-htmlize
757 (defgroup org-export-icalendar nil
758 "Options specific for iCalendar export of Org-mode files."
759 :tag
"Org Export iCalendar"
762 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
763 "The file name for the iCalendar file covering all agenda files.
764 This file is created with the command \\[org-export-icalendar-all-agenda-files].
765 The file name should be absolute, the file will be overwritten without warning."
766 :group
'org-export-icalendar
769 (defcustom org-icalendar-combined-name
"OrgMode"
770 "Calendar name for the combined iCalendar representing all agenda files."
771 :group
'org-export-icalendar
774 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
775 "Contexts where iCalendar export should use a deadline time stamp.
776 This is a list with several symbols in it. Valid symbol are:
778 event-if-todo Deadlines in TODO entries become calendar events.
779 event-if-not-todo Deadlines in non-TODO entries become calendar events.
780 todo-due Use deadlines in TODO entries as due-dates"
781 :group
'org-export-icalendar
782 :type
'(set :greedy t
783 (const :tag
"Deadlines in non-TODO entries become events"
785 (const :tag
"Deadline in TODO entries become events"
787 (const :tag
"Deadlines in TODO entries become due-dates"
790 (defcustom org-icalendar-use-scheduled
'(todo-start)
791 "Contexts where iCalendar export should use a scheduling time stamp.
792 This is a list with several symbols in it. Valid symbol are:
794 event-if-todo Scheduling time stamps in TODO entries become an event.
795 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
796 todo-start Scheduling time stamps in TODO entries become start date.
797 Some calendar applications show TODO entries only after
799 :group
'org-export-icalendar
800 :type
'(set :greedy t
802 "SCHEDULED timestamps in non-TODO entries become events"
804 (const :tag
"SCHEDULED timestamps in TODO entries become events"
806 (const :tag
"SCHEDULED in TODO entries become start date"
809 (defcustom org-icalendar-categories
'(local-tags category
)
810 "Items that should be entered into the categories field.
811 This is a list of symbols, the following are valid:
813 category The Org-mode category of the current file or tree
814 todo-state The todo state, if any
815 local-tags The tags, defined in the current line
816 all-tags All tags, including inherited ones."
817 :group
'org-export-icalendar
820 (const :tag
"The file or tree category" category
)
821 (const :tag
"The TODO state" todo-state
)
822 (const :tag
"Tags defined in current line" local-tags
)
823 (const :tag
"All tags, including inherited ones" all-tags
))))
825 (defcustom org-icalendar-include-todo nil
826 "Non-nil means, export to iCalendar files should also cover TODO items."
827 :group
'org-export-icalendar
829 (const :tag
"None" nil
)
830 (const :tag
"Unfinished" t
)
831 (const :tag
"All" all
)))
833 (defcustom org-icalendar-include-sexps t
834 "Non-nil means, export to iCalendar files should also cover sexp entries.
835 These are entries like in the diary, but directly in an Org-mode file."
836 :group
'org-export-icalendar
839 (defcustom org-icalendar-include-body
100
840 "Amount of text below headline to be included in iCalendar export.
841 This is a number of characters that should maximally be included.
842 Properties, scheduling and clocking lines will always be removed.
843 The text will be inserted into the DESCRIPTION field."
844 :group
'org-export-icalendar
846 (const :tag
"Nothing" nil
)
847 (const :tag
"Everything" t
)
848 (integer :tag
"Max characters")))
850 (defcustom org-icalendar-store-UID nil
851 "Non-nil means, store any created UIDs in properties.
852 The iCalendar standard requires that all entries have a unique identifier.
853 Org will create these identifiers as needed. When this variable is non-nil,
854 the created UIDs will be stored in the ID property of the entry. Then the
855 next time this entry is exported, it will be exported with the same UID,
856 superceding the previous form of it. This is essential for
857 synchronization services.
858 This variable is not turned on by default because we want to avoid creating
859 a property drawer in every entry if people are only playing with this feature,
860 or if they are only using it locally."
861 :group
'org-export-icalendar
866 ;;; Variables, constants, and parameter plists
868 (defconst org-level-max
20)
870 (defvar org-export-html-preamble nil
871 "Preamble, to be inserted just before <body>. Set by publishing functions.")
872 (defvar org-export-html-postamble nil
873 "Preamble, to be inserted just after </body>. Set by publishing functions.")
874 (defvar org-export-html-auto-preamble t
875 "Should default preamble be inserted? Set by publishing functions.")
876 (defvar org-export-html-auto-postamble t
877 "Should default postamble be inserted? Set by publishing functions.")
878 (defvar org-current-export-file nil
) ; dynamically scoped parameter
879 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
881 (defconst org-export-plist-vars
882 '((:link-up nil org-export-html-link-up
)
883 (:link-home nil org-export-html-link-home
)
884 (:language nil org-export-default-language
)
885 (:customtime nil org-display-custom-times
)
886 (:headline-levels
"H" org-export-headline-levels
)
887 (:section-numbers
"num" org-export-with-section-numbers
)
888 (:section-number-format nil org-export-section-number-format
)
889 (:table-of-contents
"toc" org-export-with-toc
)
890 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
891 (:archived-trees nil org-export-with-archived-trees
)
892 (:emphasize
"*" org-export-with-emphasize
)
893 (:sub-superscript
"^" org-export-with-sub-superscripts
)
894 (:special-strings
"-" org-export-with-special-strings
)
895 (:footnotes
"f" org-export-with-footnotes
)
896 (:drawers
"d" org-export-with-drawers
)
897 (:tags
"tags" org-export-with-tags
)
898 (:todo-keywords
"todo" org-export-with-todo-keywords
)
899 (:priority
"pri" org-export-with-priority
)
900 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
901 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
902 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
903 (:fixed-width
":" org-export-with-fixed-width
)
904 (:timestamps
"<" org-export-with-timestamps
)
905 (:author-info
"author" org-export-author-info
)
906 (:creator-info
"creator" org-export-creator-info
)
907 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
908 (:tables
"|" org-export-with-tables
)
909 (:table-auto-headline nil org-export-highlight-first-table-line
)
910 (:style-include-default nil org-export-html-style-include-default
)
911 (:style nil org-export-html-style
)
912 (:style-extra nil org-export-html-style-extra
)
913 (:agenda-style nil org-agenda-export-html-style
)
914 (:convert-org-links nil org-export-html-link-org-files-as-html
)
915 (:inline-images nil org-export-html-inline-images
)
916 (:html-extension nil org-export-html-extension
)
917 (:html-table-tag nil org-export-html-table-tag
)
918 (:expand-quoted-html
"@" org-export-html-expand
)
919 (:timestamp nil org-export-html-with-timestamp
)
920 (:publishing-directory nil org-export-publishing-directory
)
921 (:preamble nil org-export-html-preamble
)
922 (:postamble nil org-export-html-postamble
)
923 (:auto-preamble nil org-export-html-auto-preamble
)
924 (:auto-postamble nil org-export-html-auto-postamble
)
925 (:author nil user-full-name
)
926 (:email nil user-mail-address
)
927 (:select-tags nil org-export-select-tags
)
928 (:exclude-tags nil org-export-exclude-tags
))
929 "List of properties that represent export/publishing variables.
930 Each element is a list of 3 items:
931 1. The property that is used internally, and also for org-publish-project-alist
932 2. The string that can be used in the OPTION lines to set this option,
933 or nil if this option cannot be changed in this way
934 3. The customization variable that sets the default for this option."
938 (defun org-default-export-plist ()
939 "Return the property list with default settings for the export variables."
940 (let ((l org-export-plist-vars
) rtn e
)
941 (while (setq e
(pop l
))
942 (setq rtn
(cons (car e
) (cons (symbol-value (nth 2 e
)) rtn
))))
945 (defvar org-export-inbuffer-options-extra nil
946 "List of additional in-buffer options that should be detected.
947 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
948 etc. Extensions can add to this list to get their options detected, and they
949 can then add a function to `org-export-options-filters' to process these
951 Each element in this list must be a list, with the in-buffer keyword as car,
952 and a property (a symbol) as the next element. All occurrences of the
953 keyword will be found, the values concatenated with a space character
954 in between, and the result stored in the export options property list.")
956 (defvar org-export-options-filters nil
957 "Functions to be called to finalize the export/publishing options.
958 All these options are stored in a property list, and each of the functions
959 in this hook gets a chance to modify this property list. Each function
960 must accept the property list as an argument, and must return the (possibly
963 ;; FIXME: should we fold case here?
964 (defun org-infile-export-plist ()
965 "Return the property list with file-local settings for export."
969 (goto-char (point-min))
970 (let ((re (org-make-options-regexp
972 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
973 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
974 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
975 (mapcar 'car org-export-inbuffer-options-extra
))))
976 p key val text options a pr style
978 ext-setup-or-nil setup-contents
(start 0))
979 (while (or (and ext-setup-or-nil
980 (string-match re ext-setup-or-nil start
)
981 (setq start
(match-end 0)))
982 (and (setq ext-setup-or-nil nil start
0)
983 (re-search-forward re nil t
)))
984 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
985 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
987 ((setq a
(assoc key org-export-inbuffer-options-extra
))
989 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
990 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
991 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
992 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
993 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
994 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
995 ((string-equal key
"STYLE")
996 (setq style
(concat style
"\n" val
)))
997 ((string-equal key
"LATEX_HEADER")
998 (setq latex-header
(concat latex-header
"\n" val
)))
999 ((string-equal key
"TEXT")
1000 (setq text
(if text
(concat text
"\n" val
) val
)))
1001 ((string-equal key
"OPTIONS")
1002 (setq options
(concat val
" " options
)))
1003 ((string-equal key
"LINK_UP")
1004 (setq p
(plist-put p
:link-up val
)))
1005 ((string-equal key
"LINK_HOME")
1006 (setq p
(plist-put p
:link-home val
)))
1007 ((string-equal key
"EXPORT_SELECT_TAGS")
1008 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
1009 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
1010 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
1011 ((equal key
"SETUPFILE")
1012 (setq setup-contents
(org-file-contents
1014 (org-remove-double-quotes
1017 (if (not ext-setup-or-nil
)
1018 (setq ext-setup-or-nil setup-contents start
0)
1019 (setq ext-setup-or-nil
1020 (concat (substring ext-setup-or-nil
0 start
)
1021 "\n" setup-contents
"\n"
1022 (substring ext-setup-or-nil start
)))))))
1023 (setq p
(plist-put p
:text text
))
1024 (when style
(setq p
(plist-put p
:style-extra style
)))
1026 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
1028 (setq p
(org-export-add-options-to-plist p options
)))
1031 (defun org-export-add-options-to-plist (p options
)
1032 "Parse an OPTIONS line and set values in the property list P."
1035 (let ((op org-export-plist-vars
))
1036 (while (setq o
(pop op
))
1038 (string-match (concat (regexp-quote (nth 1 o
))
1039 ":\\([^ \t\n\r;,.]*\\)")
1041 (setq p
(plist-put p
(car o
)
1042 (car (read-from-string
1043 (match-string 1 options
))))))))))
1046 (defun org-export-add-subtree-options (p pos
)
1047 "Add options in subtree at position POS to property list P."
1050 (when (org-at-heading-p)
1052 ;; This is actually read in `org-export-get-title-from-subtree'
1053 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1054 ;; (setq p (plist-put p :title a)))
1055 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
1056 (setq p
(plist-put p
:text a
)))
1057 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
1058 (setq p
(org-export-add-options-to-plist p a
)))))
1061 (defun org-export-directory (type plist
)
1062 (let* ((val (plist-get plist
:publishing-directory
))
1063 (dir (if (listp val
)
1064 (or (cdr (assoc type val
)) ".")
1068 (defun org-export-process-option-filters (plist)
1069 (let ((functions org-export-options-filters
) f
)
1070 (while (setq f
(pop functions
))
1071 (setq plist
(funcall f plist
))))
1075 (defun org-export (&optional arg
)
1076 "Export dispatcher for Org-mode.
1077 When `org-export-run-in-background' is non-nil, try to run the command
1078 in the background. This will be done only for commands that write
1079 to a file. For details see the docstring of `org-export-run-in-background'.
1081 The prefix argument ARG will be passed to the exporter. However, if
1082 ARG is a double universal prefix `C-u C-u', that means to inverse the
1083 value of `org-export-run-in-background'."
1085 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1086 (help "[t] insert the export option template
1087 \[v] limit export to visible part of outline tree
1089 \[a] export as ASCII
1092 \[H] export as HTML to temporary buffer
1093 \[R] export region as HTML
1094 \[b] export as HTML and browse immediately
1097 \[l] export as LaTeX
1098 \[p] export as LaTeX and process to PDF
1099 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1100 \[L] export as LaTeX to temporary buffer
1102 \[i] export current file as iCalendar file
1103 \[I] export all agenda files as iCalendar files
1104 \[c] export agenda files into combined iCalendar file
1106 \[F] publish current file
1107 \[P] publish current project
1108 \[X] publish... (project will be prompted for)
1109 \[A] publish all projects")
1111 '((?t org-insert-export-options-template nil
)
1112 (?v org-export-visible nil
)
1113 (?a org-export-as-ascii t
)
1114 (?h org-export-as-html t
)
1115 (?b org-export-as-html-and-open t
)
1116 (?H org-export-as-html-to-buffer nil
)
1117 (?R org-export-region-as-html nil
)
1118 (?x org-export-as-xoxo t
)
1119 (?l org-export-as-latex t
)
1120 (?p org-export-as-pdf t
)
1121 (?d org-export-as-pdf-and-open t
)
1122 (?L org-export-as-latex-to-buffer nil
)
1123 (?i org-export-icalendar-this-file t
)
1124 (?I org-export-icalendar-all-agenda-files t
)
1125 (?c org-export-icalendar-combine-agenda-files t
)
1126 (?F org-publish-current-file t
)
1127 (?P org-publish-current-project t
)
1129 (?A org-publish-all t
)))
1132 (save-window-excursion
1133 (delete-other-windows)
1134 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1136 (org-fit-window-to-buffer (get-buffer-window
1137 "*Org Export/Publishing Help*"))
1138 (message "Select command: ")
1139 (setq r1
(read-char-exclusive))))
1140 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1141 (unless (setq ass
(assq r2 cmds
))
1142 (error "No command associated with key %c" r1
))
1143 (if (and bg
(nth 2 ass
)
1144 (not (buffer-base-buffer))
1145 (not (org-region-active-p)))
1146 ;; execute in background
1147 (let ((p (start-process
1148 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1150 (expand-file-name invocation-name invocation-directory
)
1153 "--eval" "(require 'org-exp)"
1154 "--eval" "(setq org-wait .2)"
1156 "-f" (symbol-name (nth 1 ass
)))))
1157 (set-process-sentinel p
'org-export-process-sentinel
)
1158 (message "Background process \"%s\": started" p
))
1159 ;; background processing not requested, or not possible
1160 (call-interactively (nth 1 ass
)))))
1162 (defun org-export-process-sentinel (process status
)
1163 (if (string-match "\n+\\'" status
)
1164 (setq status
(substring status
0 -
1)))
1165 (message "Background process \"%s\": %s" process status
))
1167 (defconst org-html-entities
1208 ("Aring") ("AA".
"Å")
1297 ("varepsilon".
"ε")
1310 ("sigmaf") ("varsigma".
"ς")
1318 ("thetasym") ("vartheta".
"ϑ")
1321 ("bull") ("bullet".
"•")
1322 ("hellip") ("dots".
"…")
1332 ("larr") ("leftarrow".
"←") ("gets".
"←")
1333 ("uarr") ("uparrow".
"↑")
1334 ("rarr") ("to".
"→") ("rightarrow".
"→")
1335 ("darr")("downarrow".
"↓")
1336 ("harr") ("leftrightarrow".
"↔")
1337 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1338 ("lArr") ("Leftarrow".
"⇐")
1339 ("uArr") ("Uparrow".
"⇑")
1340 ("rArr") ("Rightarrow".
"⇒")
1341 ("dArr") ("Downarrow".
"⇓")
1342 ("hArr") ("Leftrightarrow".
"⇔")
1344 ("part") ("partial".
"∂")
1345 ("exist") ("exists".
"∃")
1346 ("empty") ("emptyset".
"∅")
1348 ("isin") ("in".
"∈")
1354 ("lowast") ("ast".
"∗")
1356 ("prop") ("proptp".
"∝")
1357 ("infin") ("infty".
"∞")
1358 ("ang") ("angle".
"∠")
1359 ("and") ("wedge".
"∧")
1360 ("or") ("vee".
"∨")
1366 ("cong") ("simeq".
"≅")
1367 ("asymp")("approx".
"≈")
1368 ("ne") ("neq".
"≠")
1372 ("sub") ("subset".
"⊂")
1373 ("sup") ("supset".
"⊃")
1380 ("sdot") ("cdot".
"⋅")
1387 ("loz") ("Diamond".
"◊")
1388 ("spades") ("spadesuit".
"♠")
1389 ("clubs") ("clubsuit".
"♣")
1390 ("hearts") ("diamondsuit".
"♥")
1391 ("diams") ("diamondsuit".
"♦")
1392 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1459 "Entities for TeX->HTML translation.
1460 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1461 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1462 In that case, \"\\ent\" will be translated to \"&other;\".
1463 The list contains HTML entities for Latin-1, Greek and other symbols.
1464 It is supplemented by a number of commonly used TeX macros with appropriate
1465 translations. There is currently no way for users to extend this.")
1467 ;;; General functions for all backends
1469 (defvar org-export-target-aliases nil
1470 "Alist of targets with invisible aliases.")
1471 (defvar org-export-code-refs nil
1472 "Alist of code references and line numbers")
1474 (defun org-export-preprocess-string (string &rest parameters
)
1475 "Cleanup STRING so that that the true exported has a more consistent source.
1476 This function takes STRING, which should be a buffer-string of an org-file
1477 to export. It then creates a temporary buffer where it does its job.
1478 The result is then again returned as a string, and the exporter works
1479 on this string to produce the exported version."
1481 (let* ((htmlp (plist-get parameters
:for-html
))
1482 (asciip (plist-get parameters
:for-ascii
))
1483 (latexp (plist-get parameters
:for-LaTeX
))
1484 (backend (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1486 (archived-trees (plist-get parameters
:archived-trees
))
1487 (inhibit-read-only t
)
1488 (drawers org-drawers
)
1489 (outline-regexp "\\*+ ")
1492 (setq org-export-target-aliases nil
)
1493 (setq org-export-code-refs nil
)
1495 (with-current-buffer (get-buffer-create " org-mode-tmp")
1498 (setq case-fold-search t
)
1500 ;; Remove license-to-kill stuff
1501 ;; The caller marks some stuff for killing, stuff that has been
1502 ;; used to create the page title, for example.
1503 (org-export-kill-licensed-text)
1505 (let ((org-inhibit-startup t
)) (org-mode))
1506 (setq case-fold-search t
)
1509 (run-hooks 'org-export-preprocess-hook
)
1511 (untabify (point-min) (point-max))
1513 ;; Handle include files, and call a hook
1514 (org-export-handle-include-files)
1515 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1517 ;; Get rid of archived trees
1518 (org-export-remove-archived-trees archived-trees
)
1520 ;; Remove comment environment and comment subtrees
1521 (org-export-remove-comment-blocks-and-subtrees)
1523 ;; Get rid of excluded trees, and call a hook
1524 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1525 (plist-get parameters
:exclude-tags
))
1526 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1528 ;; Handle source code snippets
1529 (org-export-replace-src-segments-and-examples backend
)
1531 ;; Protect short examples marked by a leading colon
1532 (org-export-protect-colon-examples)
1534 ;; Normalize footnotes
1535 (when (plist-get parameters
:footnotes
)
1536 (org-footnote-normalize nil t
))
1538 ;; Find all headings and compute the targets for them
1539 (setq target-alist
(org-export-define-heading-targets target-alist
))
1541 ;; Get rid of drawers
1542 (org-export-remove-or-extract-drawers drawers
1543 (plist-get parameters
:drawers
))
1545 ;; Get the correct stuff before the first headline
1546 (when (plist-get parameters
:skip-before-1st-heading
)
1547 (goto-char (point-min))
1548 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1549 (delete-region (point-min) (match-beginning 0))
1550 (goto-char (point-min))
1552 (when (plist-get parameters
:add-text
)
1553 (goto-char (point-min))
1554 (insert (plist-get parameters
:add-text
) "\n"))
1556 ;; Remove todo-keywords before exporting, if the user has requested so
1557 (org-export-remove-headline-metadata parameters
)
1559 ;; Find targets in comments and move them out of comments,
1560 ;; but mark them as targets that should be invisible
1561 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1563 ;; Select and protect backend specific stuff, throw away stuff
1564 ;; that is specific for other backends
1565 (org-export-select-backend-specific-text backend
)
1567 ;; Protect quoted subtrees
1568 (org-export-protect-quoted-subtrees)
1570 ;; Remove clock lines
1571 (org-export-remove-clock-lines)
1573 ;; Protect verbatim elements
1574 (org-export-protect-verbatim)
1576 ;; Blockquotes and verse
1577 (org-export-mark-blockquote-and-verse)
1579 ;; Remove timestamps, if the user has requested so
1580 (unless (plist-get parameters
:timestamps
)
1581 (org-export-remove-timestamps))
1583 ;; Attach captions to the correct object
1584 (setq target-alist
(org-export-attach-captions-and-attributes
1585 backend target-alist
))
1587 ;; Find matches for radio targets and turn them into internal links
1588 (org-export-mark-radio-links)
1590 ;; Find all links that contain a newline and put them into a single line
1591 (org-export-concatenate-multiline-links)
1593 ;; Normalize links: Convert angle and plain links into bracket links
1594 ;; and expand link abbreviations
1595 (org-export-normalize-links)
1597 ;; Find all internal links. If they have a fuzzy match (i.e. not
1598 ;; a *dedicated* target match, let the link point to the
1599 ;; corresponding section.
1600 (org-export-target-internal-links target-alist
)
1602 ;; Find multiline emphasis and put them into single line
1603 (when (plist-get parameters
:emph-multiline
)
1604 (org-export-concatenate-multiline-emphasis))
1606 ;; Remove special table lines
1607 (when org-export-table-remove-special-lines
1608 (org-export-remove-special-table-lines))
1611 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1613 ;; LaTeX-specific preprocessing
1615 (require 'org-export-latex nil
)
1616 (org-export-latex-preprocess))
1618 ;; ASCII-specific preprocessing
1620 (org-export-ascii-preprocess))
1622 ;; HTML-specific preprocessing
1624 (org-export-html-preprocess parameters
))
1626 ;; Remove or replace comments
1627 (org-export-handle-comments (plist-get parameters
:comments
))
1629 ;; Run the final hook
1630 (run-hooks 'org-export-preprocess-final-hook
)
1632 (setq rtn
(buffer-string)))
1633 (kill-buffer " org-mode-tmp")
1636 (defun org-export-kill-licensed-text ()
1637 "Remove all text that is marked with a :org-license-to-kill property."
1639 (while (setq p
(text-property-any (point-min) (point-max)
1640 :org-license-to-kill t
))
1642 p
(or (next-single-property-change p
:org-license-to-kill
)
1645 (defun org-export-define-heading-targets (target-alist)
1646 "Find all headings and define the targets for them.
1647 The new targets are added to TARGET-ALIST, which is also returned."
1648 (goto-char (point-min))
1649 (org-init-section-numbers)
1650 (let ((re (concat "^" org-outline-regexp
1651 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1652 level target last-section-target a
)
1653 (while (re-search-forward re nil t
)
1656 (push (cons (org-match-string-no-properties 1)
1657 target
) target-alist
)
1658 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1660 (push (list last-section-target
)
1661 org-export-target-aliases
)
1662 (car org-export-target-aliases
))))
1663 (push (caar target-alist
) (cdr a
)))
1664 (setq level
(org-reduced-level
1665 (save-excursion (goto-char (point-at-bol))
1666 (org-outline-level))))
1667 (setq target
(org-solidify-link-text
1668 (format "sec-%s" (org-section-number level
))))
1669 (setq last-section-target target
)
1670 (push (cons target target
) target-alist
)
1671 (add-text-properties
1672 (point-at-bol) (point-at-eol)
1673 (list 'target target
)))))
1676 (defun org-export-handle-invisible-targets (target-alist)
1677 "Find targets in comments and move them out of comments.
1678 Mark them as invisible targets."
1680 (goto-char (point-min))
1681 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1682 ;; Check if the line before or after is a headline with a target
1683 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1684 (get-text-property (point-at-bol 2) 'target
)))
1686 ;; use the existing target in a neighboring line
1687 (setq tmp
(match-string 2))
1689 (and (looking-at "\n") (delete-char 1))
1690 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1692 (setq a
(or (assoc target org-export-target-aliases
)
1694 (push (list target
) org-export-target-aliases
)
1695 (car org-export-target-aliases
))))
1697 ;; Make an invisible target
1698 (replace-match "\\1(INVISIBLE)"))))
1701 (defun org-export-target-internal-links (target-alist)
1702 "Find all internal links and assign targets to them.
1703 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1704 let the link point to the corresponding section.
1705 This function also handles the id links, if they have a match in
1707 (goto-char (point-min))
1708 (while (re-search-forward org-bracket-link-regexp nil t
)
1710 (let* ((md (match-data))
1711 (desc (match-end 2))
1712 (link (org-link-unescape (match-string 1)))
1713 (slink (org-solidify-link-text link
))
1714 found props pos cref
1717 ((cdr (assoc slink target-alist
)))
1718 ((and (string-match "^id:" link
)
1719 (cdr (assoc (substring link
3) target-alist
))))
1720 ((string-match "^(\\(.*\\))$" link
)
1721 (setq cref
(match-string 1 link
))
1722 (concat "coderef:" cref
))
1723 ((string-match org-link-types-re link
) nil
)
1724 ((or (file-name-absolute-p link
)
1725 (string-match "^\\." link
))
1729 (setq found
(condition-case nil
(org-link-search link
)
1732 (or (org-on-heading-p)
1733 (not (eq found
'dedicated
))))
1734 (or (get-text-property (point) 'target
)
1737 (1- (or (previous-single-property-change
1738 (point) 'target
) 0)))
1742 (goto-char (match-beginning 1))
1743 (setq props
(text-properties-at (point)))
1744 (delete-region (match-beginning 1) (match-end 1))
1747 (unless desc
(insert "][" link
))
1748 (add-text-properties pos
(point) props
))))))
1750 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1751 "Remove drawers, or extract the content.
1752 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1753 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1754 whose content to keep."
1755 (unless (eq t exp-drawers
)
1756 (goto-char (point-min))
1757 (let ((re (concat "^[ \t]*:\\("
1760 (org-delete-all exp-drawers
1761 (copy-sequence all-drawers
))
1763 "\\):[ \t]*\n\\([^\000]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1764 (while (re-search-forward re nil t
)
1766 (replace-match ""))))))
1768 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1769 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1770 Both arguments are lists of tags.
1771 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1773 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1775 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1776 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1779 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1783 (goto-char (point-min))
1784 (when (and select-tags
1786 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1787 ;; At least one tree is marked for export, this means
1788 ;; all the unmarked stuff needs to go.
1789 ;; Dig out the trees that should be exported
1790 (goto-char (point-min))
1791 (outline-next-heading)
1793 (put-text-property beg
(point-max) :org-delete t
)
1794 (while (re-search-forward re-sel nil t
)
1795 (when (org-on-heading-p)
1796 (org-back-to-heading)
1797 (remove-text-properties
1798 (max (1- (point)) (point-min))
1799 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1801 (while (and (org-up-heading-safe)
1802 (get-text-property (point) :org-delete
))
1803 (remove-text-properties (max (1- (point)) (point-min))
1804 (point-at-eol) '(:org-delete t
)))
1806 ;; Remove the trees explicitly marked for noexport
1808 (goto-char (point-min))
1809 (while (re-search-forward re-excl nil t
)
1810 (when (org-at-heading-p)
1811 (org-back-to-heading t
)
1813 (org-end-of-subtree t
)
1814 (delete-region beg
(point)))))
1815 ;; Remove everything that is now still marked for deletion
1816 (goto-char (point-min))
1817 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1818 (setq end
(or (next-single-property-change beg
:org-delete
)
1820 (delete-region beg end
))))
1822 (defun org-export-remove-archived-trees (export-archived-trees)
1823 "Remove archived trees.
1824 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1825 When it is t, the entire archived tree will be exported.
1826 When it is nil the entire tree including the headline will be removed
1828 (let ((re-archive (concat ":" org-archive-tag
":"))
1830 (when (not (eq export-archived-trees t
))
1831 (goto-char (point-min))
1832 (while (re-search-forward re-archive nil t
)
1833 (if (not (org-on-heading-p t
))
1834 (org-end-of-subtree t
)
1835 (beginning-of-line 1)
1836 (setq a
(if export-archived-trees
1837 (1+ (point-at-eol)) (point))
1838 b
(org-end-of-subtree t
))
1839 (if (> b a
) (delete-region a b
)))))))
1841 (defun org-export-remove-headline-metadata (opts)
1842 "Remove meta data from the headline, according to user options."
1843 (let ((re org-complex-heading-regexp
)
1844 (todo (plist-get opts
:todo-keywords
))
1845 (tags (plist-get opts
:tags
))
1846 (pri (plist-get opts
:priority
))
1849 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1850 (when (or (not todo
) (not tags
) (not pri
))
1851 (goto-char (point-min))
1852 (while (re-search-forward re nil t
)
1854 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1856 (replace-match rpl t t
))))))
1858 (defun org-export-remove-timestamps ()
1859 "Remove timestamps and keywords for export."
1860 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1863 (unless (save-match-data (org-at-table-p))
1865 (beginning-of-line 1)
1866 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1867 (replace-match ""))))))
1869 (defun org-export-remove-clock-lines ()
1870 "Remove clock lines for export."
1871 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1872 (while (re-search-forward re nil t
)
1874 (replace-match "")))))
1876 (defun org-export-protect-quoted-subtrees ()
1877 "Mark quoted subtrees with the protection property."
1878 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1879 (goto-char (point-min))
1880 (while (re-search-forward re-quote nil t
)
1881 (goto-char (match-beginning 0))
1883 (add-text-properties (point) (org-end-of-subtree t
)
1884 '(org-protected t
)))))
1886 (defun org-export-protect-verbatim ()
1887 "Mark verbatim snippets with the protection property."
1888 (goto-char (point-min))
1889 (while (re-search-forward org-verbatim-re nil t
)
1890 (add-text-properties (match-beginning 4) (match-end 4)
1892 (goto-char (1+ (match-end 4)))))
1894 (defun org-export-protect-colon-examples ()
1895 "Protect lines starting with a colon."
1896 (goto-char (point-min))
1897 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1898 (while (re-search-forward re nil t
)
1899 (beginning-of-line 1)
1901 (while (looking-at re
)
1903 (or (eobp) (forward-char 1)))
1904 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1905 '(org-protected t
)))))
1907 (defun org-export-select-backend-specific-text (backend)
1909 '((html "HTML" "BEGIN_HTML" "END_HTML")
1910 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1911 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1912 (case-fold-search t
)
1916 (setq fmt
(pop formatters
))
1917 (when (eq (car fmt
) backend
)
1918 ;; This is selected code, put it into the file for real
1919 (goto-char (point-min))
1920 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1921 ":[ \t]*\\(.*\\)") nil t
)
1922 (replace-match "\\1" t
)
1923 (add-text-properties
1924 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1925 '(org-protected t
))))
1926 (goto-char (point-min))
1927 (while (re-search-forward
1929 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1930 (cadddr fmt
) "\\>.*\n?") nil t
)
1931 (if (eq (car fmt
) backend
)
1933 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1935 ;; No, this is for a different backend, kill it
1936 (delete-region (match-beginning 0) (match-end 0)))))))
1938 (defun org-export-mark-blockquote-and-verse ()
1939 "Mark block quote and verse environments with special cookies.
1940 These special cookies will later be interpreted by the backend."
1942 (goto-char (point-min))
1943 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1945 (replace-match (if (equal (downcase (match-string 1)) "end")
1946 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1949 (goto-char (point-min))
1950 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1951 (replace-match (if (equal (downcase (match-string 1)) "end")
1952 "ORG-VERSE-END" "ORG-VERSE-START")
1955 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1956 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1957 If the next thing following is a table, add the text properties to the first
1958 table line. If it is a link, add it to the line containing the link."
1959 (goto-char (point-min))
1960 (remove-text-properties (point-min) (point-max)
1961 '(org-caption nil org-attributes nil
))
1962 (let ((case-fold-search t
)
1963 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1965 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1967 "^#\\+label:[ \t]+\\(.*\\)"
1971 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1973 (while (re-search-forward re nil t
)
1976 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1978 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1980 (setq label
(org-trim (match-string 3))))
1982 (add-text-properties (point-at-bol) (point-at-eol)
1983 (list 'org-caption cap
1984 'org-attributes attr
1986 (if label
(push (cons label label
) target-alist
))
1987 (setq cap nil attr nil label nil
)))))
1990 (defun org-export-remove-comment-blocks-and-subtrees ()
1991 "Remove the comment environment, and also commented subtrees."
1992 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1993 (case-fold-search nil
))
1994 ;; Remove comment environment
1995 (goto-char (point-min))
1996 (while (re-search-forward
1997 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1998 (replace-match "" t t
))
1999 ;; Remove subtrees that are commented
2000 (goto-char (point-min))
2001 (while (re-search-forward re-commented nil t
)
2002 (goto-char (match-beginning 0))
2003 (delete-region (point) (org-end-of-subtree t
)))))
2005 (defun org-export-handle-comments (commentsp)
2006 "Remove comments, or convert to backend-specific format.
2007 COMMENTSP can be a format string for publishing comments.
2008 When it is nil, all comments will be removed."
2009 (let ((re "^#\\(.*\n?\\)")
2011 (goto-char (point-min))
2012 (while (or (looking-at re
)
2013 (re-search-forward re nil t
))
2014 (setq pos
(match-beginning 0))
2016 (progn (add-text-properties
2017 (match-beginning 0) (match-end 0) '(org-protected t
))
2018 (replace-match (format commentsp
(match-string 1)) t t
))
2019 (goto-char (1+ pos
))
2022 (goto-char (max (point-min) (1- pos
))))))))
2024 (defun org-export-mark-radio-links ()
2025 "Find all matches for radio targets and turn them into internal links."
2026 (let ((re-radio (and org-target-link-regexp
2027 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
2028 (goto-char (point-min))
2030 (while (re-search-forward re-radio nil t
)
2032 (replace-match "\\1[[\\2]]"))))))
2034 (defun org-export-remove-special-table-lines ()
2035 "Remove tables lines that are used for internal purposes."
2036 (goto-char (point-min))
2037 (while (re-search-forward "^[ \t]*|" nil t
)
2038 (beginning-of-line 1)
2039 (if (or (looking-at "[ \t]*| *[!_^] *|")
2040 (and (looking-at ".*?| *<[0-9]+> *|")
2041 (not (looking-at ".*?| *[^ <|]"))))
2042 (delete-region (max (point-min) (1- (point-at-bol)))
2046 (defun org-export-normalize-links ()
2047 "Convert all links to bracket links, and expand link abbreviations."
2048 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2049 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
2050 (goto-char (point-min))
2051 (while (re-search-forward re-plain-link nil t
)
2052 (goto-char (1- (match-end 0)))
2053 (org-if-unprotected-at (1+ (match-beginning 0))
2054 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2055 ":" (match-string 3) "]]")))
2056 ;; added 'org-link face to links
2057 (put-text-property 0 (length s
) 'face
'org-link s
)
2058 (replace-match s t t
))))
2059 (goto-char (point-min))
2060 (while (re-search-forward re-angle-link nil t
)
2061 (goto-char (1- (match-end 0)))
2063 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2064 ":" (match-string 3) "]]")))
2065 (put-text-property 0 (length s
) 'face
'org-link s
)
2066 (replace-match s t t
))))
2067 (goto-char (point-min))
2068 (while (re-search-forward org-bracket-link-regexp nil t
)
2069 (goto-char (1- (match-end 0)))
2071 (let* ((xx (save-match-data
2073 (org-link-expand-abbrev (match-string 1)))))
2075 "[[" (org-add-props (copy-sequence xx
)
2076 nil
'org-protected t
)
2080 (concat "[" (org-add-props
2085 (put-text-property 0 (length s
) 'face
'org-link s
)
2086 (replace-match s t t
))))))
2088 (defun org-export-concatenate-multiline-links ()
2089 "Find multi-line links and put it all into a single line.
2090 This is to make sure that the line-processing export backends
2091 can work correctly."
2092 (goto-char (point-min))
2093 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2095 (replace-match "\\1 \\3")
2096 (goto-char (match-beginning 0)))))
2098 (defun org-export-concatenate-multiline-emphasis ()
2099 "Find multi-line emphasis and put it all into a single line.
2100 This is to make sure that the line-processing export backends
2101 can work correctly."
2102 (goto-char (point-min))
2103 (while (re-search-forward org-emph-re nil t
)
2104 (if (and (not (= (char-after (match-beginning 3))
2105 (char-after (match-beginning 4))))
2106 (save-excursion (goto-char (match-beginning 0))
2107 (save-match-data (not (org-at-table-p)))))
2109 (subst-char-in-region (match-beginning 0) (match-end 0)
2111 (goto-char (1- (match-end 0))))
2112 (goto-char (1+ (match-beginning 0))))))
2114 (defun org-export-grab-title-from-buffer ()
2115 "Get a title for the current document, from looking at the buffer."
2116 (let ((inhibit-read-only t
))
2118 (goto-char (point-min))
2119 (let ((end (if (looking-at org-outline-regexp
)
2121 (save-excursion (outline-next-heading) (point)))))
2122 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2123 ;; Mark the line so that it will not be exported as normal text.
2125 (add-text-properties (match-beginning 0) (match-end 0)
2126 (list :org-license-to-kill t
)))
2127 ;; Return the title string
2128 (org-trim (match-string 0)))))))
2130 (defun org-export-get-title-from-subtree ()
2131 "Return subtree title and exclude it from export."
2132 (let (title (rbeg (region-beginning)) (rend (region-end)))
2135 (when (and (org-at-heading-p)
2136 (>= (org-end-of-subtree t t
) rend
))
2137 ;; This is a subtree, we take the title from the first heading
2139 (looking-at org-todo-line-regexp
)
2140 (setq title
(match-string 3))
2142 (add-text-properties (point) (1+ (point-at-eol))
2143 (list :org-license-to-kill t
)))
2144 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2147 (defun org-solidify-link-text (s &optional alist
)
2148 "Take link text and make a safe target out of it."
2153 (org-split-string s
"[ \t\r\n]+") "=="))
2154 (a (assoc rtn alist
)))
2157 (defun org-get-min-level (lines &optional offset
)
2158 "Get the minimum level in LINES."
2159 (let ((re "^\\(\\*+\\) ") l
)
2161 (while (setq l
(pop lines
))
2162 (if (string-match re l
)
2163 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2167 ;; Variable holding the vector with section numbers
2168 (defvar org-section-numbers
(make-vector org-level-max
0))
2170 (defun org-init-section-numbers ()
2171 "Initialize the vector for the section numbers."
2173 (numbers (nreverse (org-split-string "" "\\.")))
2174 (depth (1- (length org-section-numbers
)))
2175 (i depth
) number-string
)
2178 (aset org-section-numbers i
0)
2179 (setq number-string
(or (car numbers
) "0"))
2180 (if (string-match "\\`[A-Z]\\'" number-string
)
2181 (aset org-section-numbers i
2182 (- (string-to-char number-string
) ?A -
1))
2183 (aset org-section-numbers i
(string-to-number number-string
)))
2187 (defun org-section-number (&optional level
)
2188 "Return a string with the current section number.
2189 When LEVEL is non-nil, increase section numbers on that level."
2190 (let* ((depth (1- (length org-section-numbers
)))
2192 (fmts (car org-export-section-number-format
))
2193 (term (cdr org-export-section-number-format
))
2198 (aset org-section-numbers
2199 level
(1+ (aref org-section-numbers level
))))
2200 (setq idx
(1+ level
))
2201 (while (<= idx depth
)
2203 (aset org-section-numbers idx
0))
2204 (setq idx
(1+ idx
))))
2206 (while (<= idx depth
)
2207 (when (> (aref org-section-numbers idx
) 0)
2208 (setq fmt
(or (pop fmts
) fmt
)
2210 n
(aref org-section-numbers idx
)
2212 (concat string sep
(org-number-to-counter n ctype
))
2213 (concat string
".0"))
2215 (setq idx
(1+ idx
)))
2217 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2218 (setq string
(replace-match "" t nil string
)))
2219 (if (string-match "\\(\\.0\\)+\\'" string
)
2220 (setq string
(replace-match "" t nil string
))))
2221 (concat string term
)))
2223 (defun org-number-to-counter (n type
)
2224 "Concert number N to a string counter, according to TYPE.
2225 TYPE must be a string, any of:
2229 I upper case roman numeral
2230 i lower case roman numeral"
2232 ((equal type
"1") (number-to-string n
))
2233 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2234 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2235 ((equal type
"I") (org-number-to-roman n
))
2236 ((equal type
"i") (downcase (org-number-to-roman n
)))
2237 (t (error "Invalid counter type `%s'" type
))))
2239 (defun org-number-to-roman (n)
2240 "Convert integer N into a roman numeral."
2241 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2242 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2243 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2247 (number-to-string n
)
2249 (if (>= n
(caar roman
))
2250 (setq n
(- n
(caar roman
))
2251 res
(concat res
(cdar roman
)))
2255 (org-number-to-roman 1961)
2260 (defun org-export-handle-include-files ()
2261 "Include the contents of include files, with proper formatting."
2262 (let ((case-fold-search t
)
2263 params file markup lang start end prefix prefix1 switches
)
2264 (goto-char (point-min))
2265 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2266 (setq params
(read (concat "(" (match-string 1) ")"))
2267 prefix
(org-get-and-remove-property 'params
:prefix
)
2268 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2269 file
(org-symname-or-string (pop params
))
2270 markup
(org-symname-or-string (pop params
))
2271 lang
(and (member markup
'("src" "SRC"))
2272 (org-symname-or-string (pop params
)))
2273 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2274 (delete-region (match-beginning 0) (match-end 0))
2276 (not (file-exists-p file
))
2277 (not (file-readable-p file
)))
2278 (insert (format "CANNOT INCLUDE FILE %s" file
))
2280 (if (equal (downcase markup
) "src")
2281 (setq start
(format "#+begin_src %s %s\n"
2282 (or lang
"fundamental")
2285 (setq start
(format "#+begin_%s %s\n" markup switches
)
2286 end
(format "#+end_%s" markup
))))
2287 (insert (or start
""))
2288 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2289 (or (bolp) (newline))
2290 (insert (or end
""))))))
2292 (defun org-get-file-contents (file &optional prefix prefix1
)
2293 "Get the contents of FILE and return them as a string.
2294 If PREFIX is a string, prepend it to each line. If PREFIX1
2295 is a string, prepend it to the first line instead of PREFIX."
2297 (insert-file-contents file
)
2298 (when (or prefix prefix1
)
2299 (goto-char (point-min))
2301 (insert (or prefix1 prefix
))
2303 (beginning-of-line 2)))
2306 (defun org-get-and-remove-property (listvar prop
)
2307 "Check if the value of LISTVAR contains PROP as a property.
2308 If yes, return the value of that property (i.e. the element following
2309 in the list) and remove property and value from the list in LISTVAR."
2310 (let ((list (symbol-value listvar
)) m v
)
2311 (when (setq m
(member prop list
))
2313 (if (equal (car list
) prop
)
2314 (set listvar
(cddr list
))
2315 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2317 (set listvar list
)))
2320 (defun org-symname-or-string (s)
2322 (if s
(symbol-name s
) s
)
2325 ;;; Fontification and line numbers for code examples
2327 (defvar org-export-last-code-line-counter-value
0)
2329 (defun org-export-replace-src-segments-and-examples (backend)
2330 "Replace source code segments with special code for export."
2331 (setq org-export-last-code-line-counter-value
0)
2332 (let ((case-fold-search t
)
2333 lang code trans opts
)
2334 (goto-char (point-min))
2335 (while (re-search-forward
2336 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2340 (setq lang
(match-string 2)
2341 opts
(match-string 3)
2342 code
(match-string 4))
2344 opts
(match-string 6)
2345 code
(match-string 7)))
2347 (setq trans
(org-export-format-source-code-or-example
2348 backend lang code opts
))
2349 (replace-match trans t t
))))
2351 (defvar htmlp
) ;; dynamically scoped
2352 (defvar latexp
) ;; dynamically scoped
2354 (defun org-export-format-source-code-or-example (backend
2355 lang code
&optional opts
)
2356 "Format CODE from language LANG and return it formatted for export.
2357 If LANG is nil, do not add any fontification.
2358 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2359 and `+n' for continuing previous numering.
2360 Code formatting according to language currently only works for HTML.
2361 Numbering lines works for all three major backends (html, latex, and ascii)."
2363 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2364 (setq opts
(or opts
"")
2365 num
(string-match "[-+]n\\>" opts
)
2366 cont
(string-match "\\+n\\>" opts
)
2367 rpllbl
(string-match "-r\\>" opts
)
2368 keepp
(string-match "-k\\>" opts
)
2369 textareap
(string-match "-t\\>" opts
)
2370 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2371 (string-to-number (match-string 1 opts
))
2373 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2374 (string-to-number (match-string 1 opts
))
2375 (org-count-lines code
))
2376 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2377 (match-string 1 opts
)))
2378 (when (and textareap
(eq backend
'html
))
2379 ;; we cannot use numbering or highlighting.
2380 (setq num nil cont nil lang nil
))
2381 (if keepp
(setq rpllbl
'keep
))
2383 (when (equal lang
"org")
2384 (setq rtn
(with-temp-buffer
2386 ;; Free up the protected lines
2387 (goto-char (point-min))
2388 (while (re-search-forward "^," nil t
)
2392 ;; Now backend-specific coding
2395 ;; We are exporting to HTML
2397 (require 'htmlize nil t
)
2398 (when (not (fboundp 'htmlize-region-for-paste
))
2399 ;; we do not have htmlize.el, or an old version of it
2402 "htmlize.el 1.34 or later is needed for source code formatting")))
2405 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2406 (org-inhibit-startup t
)
2407 (org-startup-folded nil
))
2411 (if (functionp mode
)
2414 (font-lock-fontify-buffer)
2415 (org-export-htmlize-region-for-paste
2416 (point-min) (point-max))))
2417 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2418 (setq rtn
(replace-match
2419 (format "<pre class=\"src src-%s\">\n" lang
)
2423 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2425 rtn
"</textarea>\n</p>\n"))
2428 (goto-char (point-min))
2429 (while (re-search-forward "[<>&]" nil t
)
2430 (replace-match (cdr (assq (char-before)
2431 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2433 (setq rtn
(buffer-string)))
2434 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2436 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2438 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2439 ((eq backend
'latex
)
2440 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2441 (concat "\n#+BEGIN_LaTeX\n"
2442 (org-add-props (concat "\\begin{verbatim}\n" rtn
"\n\\end{verbatim}\n")
2445 ((eq backend
'ascii
)
2446 ;; This is not HTML or LaTeX, so just make it an example.
2447 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2448 (concat "#+BEGIN_ASCII\n"
2452 (lambda (l) (concat " " l
))
2453 (org-split-string rtn
"\n")
2457 "#+END_ASCII\n"))))))
2459 (defun org-export-number-lines (text backend
2460 &optional skip1 skip2 number cont
2461 replace-labels label-format
)
2462 (if (and (not number
) (not (eq replace-labels
'keep
)))
2463 (setq replace-labels nil
)) ;; must use names if no numbers
2464 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2465 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2468 (goto-char (point-max))
2469 (skip-chars-backward " \t\n\r")
2470 (delete-region (point) (point-max))
2471 (beginning-of-line (- 1 skip2
))
2472 (let* ((last (org-current-line))
2473 (n org-export-last-code-line-counter-value
)
2474 (nmax (+ n
(- last skip1
)))
2475 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2478 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2480 ((eq backend
'ascii
) fmt
)
2481 ((eq backend
'latex
) fmt
)
2483 (label-format (or label-format org-coderef-label-format
))
2484 (label-pre (if (string-match "%s" label-format
)
2485 (substring label-format
0 (match-beginning 0))
2487 (label-post (if (string-match "%s" label-format
)
2488 (substring label-format
(match-end 0))
2492 ".*?\\S-.*?\\([ \t]*\\("
2493 (regexp-quote label-pre
)
2494 "\\([-a-zA-Z0-9_]+\\)"
2495 (regexp-quote label-post
)
2499 (goto-line (1+ skip1
))
2500 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2502 (insert (format fm
(incf n
)))
2504 (when (and (not (eq replace-labels
'keep
))
2505 (looking-at lbl-re
))
2506 (setq ref
(match-string 3))
2509 (delete-region (match-beginning 1) (match-end 1))
2510 (push (cons ref n
) org-export-code-refs
))
2511 (goto-char (match-beginning 2))
2512 (delete-region (match-beginning 2) (match-end 2))
2513 (insert "(" ref
")")
2514 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2515 (when (eq backend
'html
)
2517 (beginning-of-line 1)
2518 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2521 (insert "</span>")))))
2522 (setq org-export-last-code-line-counter-value n
)
2523 (goto-char (point-max))
2529 (defvar org-last-level nil
) ; dynamically scoped variable
2530 (defvar org-min-level nil
) ; dynamically scoped variable
2531 (defvar org-levels-open nil
) ; dynamically scoped parameter
2532 (defvar org-ascii-current-indentation nil
) ; For communication
2535 (defun org-export-as-ascii (arg)
2536 "Export the outline as a pretty ASCII file.
2537 If there is an active region, export only the region.
2538 The prefix ARG specifies how many levels of the outline should become
2539 underlined headlines. The default is 3."
2541 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2542 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2543 (org-infile-export-plist)))
2544 (region-p (org-region-active-p))
2545 (rbeg (and region-p
(region-beginning)))
2546 (rend (and region-p
(region-end)))
2551 (and (org-at-heading-p)
2552 (>= (org-end-of-subtree t t
) rend
)))))
2553 (level-offset (if subtree-p
2556 (+ (funcall outline-level
)
2557 (if org-odd-levels-only
1 0)))
2559 (opt-plist (if subtree-p
2560 (org-export-add-subtree-options opt-plist rbeg
)
2562 (custom-times org-display-custom-times
)
2563 (org-ascii-current-indentation '(0 .
0))
2567 (case-fold-search nil
)
2568 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2569 (filename (concat (file-name-as-directory
2570 (org-export-directory :ascii opt-plist
))
2571 (file-name-sans-extension
2573 (org-entry-get (region-beginning)
2574 "EXPORT_FILE_NAME" t
))
2575 (file-name-nondirectory bfname
)))
2577 (filename (if (equal (file-truename filename
)
2578 (file-truename bfname
))
2579 (concat filename
".txt")
2581 (buffer (find-file-noselect filename
))
2582 (org-levels-open (make-vector org-level-max nil
))
2583 (odd org-odd-levels-only
)
2584 (date (plist-get opt-plist
:date
))
2585 (author (plist-get opt-plist
:author
))
2586 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2587 (plist-get opt-plist
:title
)
2589 (plist-get opt-plist
:skip-before-1st-heading
))
2590 (org-export-grab-title-from-buffer))
2591 (file-name-sans-extension
2592 (file-name-nondirectory bfname
))))
2593 (email (plist-get opt-plist
:email
))
2594 (language (plist-get opt-plist
:language
))
2595 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2596 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2601 (if (org-region-active-p) (region-beginning) (point-min))
2602 (if (org-region-active-p) (region-end) (point-max))))
2603 (lines (org-split-string
2604 (org-export-preprocess-string
2607 :skip-before-1st-heading
2608 (plist-get opt-plist
:skip-before-1st-heading
)
2609 :drawers
(plist-get opt-plist
:drawers
)
2610 :tags
(plist-get opt-plist
:tags
)
2611 :priority
(plist-get opt-plist
:priority
)
2612 :footnotes
(plist-get opt-plist
:footnotes
)
2613 :timestamps
(plist-get opt-plist
:timestamps
)
2614 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
2615 :verbatim-multiline t
2616 :select-tags
(plist-get opt-plist
:select-tags
)
2617 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2619 (plist-get opt-plist
:archived-trees
)
2620 :add-text
(plist-get opt-plist
:text
))
2622 thetoc have-headings first-heading-pos
2623 table-open table-buffer link desc
)
2624 (let ((inhibit-read-only t
))
2626 (remove-text-properties (point-min) (point-max)
2627 '(:org-license-to-kill t
))))
2629 (setq org-min-level
(org-get-min-level lines level-offset
))
2630 (setq org-last-level org-min-level
)
2631 (org-init-section-numbers)
2633 (find-file-noselect filename
)
2635 (setq lang-words
(or (assoc language org-export-language-setup
)
2636 (assoc "en" org-export-language-setup
)))
2637 (switch-to-buffer-other-window buffer
)
2640 ;; create local variables for all options, to make sure all called
2641 ;; functions get the correct information
2643 (set (make-local-variable (nth 2 x
))
2644 (plist-get opt-plist
(car x
))))
2645 org-export-plist-vars
)
2646 (org-set-local 'org-odd-levels-only odd
)
2647 (setq umax
(if arg
(prefix-numeric-value arg
)
2648 org-export-headline-levels
))
2649 (setq umax-toc
(if (integerp org-export-with-toc
)
2650 (min org-export-with-toc umax
)
2654 (if title
(org-insert-centered title ?
=))
2656 (if (and (or author email
)
2657 org-export-author-info
)
2658 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2659 (if email
(concat " <" email
">") "")
2663 ((and date
(string-match "%" date
))
2664 (setq date
(format-time-string date
)))
2666 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2668 (if (and date org-export-time-stamp-file
)
2669 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2673 (if org-export-with-toc
2675 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2676 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2678 (mapc '(lambda (line)
2679 (if (string-match org-todo-line-regexp
2681 ;; This is a headline
2683 (setq have-headings t
)
2684 (setq level
(- (match-end 1) (match-beginning 1)
2686 level
(org-tr-level level
)
2687 txt
(match-string 3 line
)
2689 (or (and org-export-mark-todo-in-toc
2691 (not (member (match-string 2 line
)
2692 org-done-keywords
)))
2694 (and org-export-mark-todo-in-toc
2696 (org-search-todo-below
2697 line lines level
))))
2698 (setq txt
(org-html-expand-for-ascii txt
))
2700 (while (string-match org-bracket-link-regexp txt
)
2703 (match-string (if (match-end 2) 3 1) txt
)
2706 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2708 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2710 (setq txt
(replace-match "" t t txt
)))
2711 (if (string-match quote-re0 txt
)
2712 (setq txt
(replace-match "" t t txt
)))
2714 (if org-export-with-section-numbers
2715 (setq txt
(concat (org-section-number level
)
2717 (if (<= level umax-toc
)
2722 (* (max 0 (- level org-min-level
)) 4) ?\
)
2723 (format (if todo
"%s (*)\n" "%s\n") txt
))
2725 (setq org-last-level level
))
2728 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2730 (org-init-section-numbers)
2731 (while (setq line
(pop lines
))
2732 ;; Remove the quoted HTML tags.
2733 (setq line
(org-html-expand-for-ascii line
))
2734 ;; Replace links with the description when possible
2735 (while (string-match org-bracket-link-regexp line
)
2736 (setq link
(match-string 1 line
)
2737 desc
(match-string (if (match-end 3) 3 1) line
))
2738 (if (and (> (length link
) 8)
2739 (equal (substring link
0 8) "coderef:"))
2740 (setq line
(replace-match
2741 (format (org-export-get-coderef-format (substring link
8) desc
)
2744 org-export-code-refs
)))
2746 (setq line
(replace-match
2747 (if (match-end 3) "[\\3]" "[\\1]")
2750 (setq line
(org-translate-time line
)))
2752 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2754 (setq first-heading-pos
(or first-heading-pos
(point)))
2755 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
2757 txt
(match-string 2 line
))
2758 (org-ascii-level-start level txt umax lines
))
2760 ((and org-export-with-tables
2761 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2762 (if (not table-open
)
2764 (setq table-open t table-buffer nil
))
2766 (setq table-buffer
(cons line table-buffer
))
2767 (when (or (not lines
)
2768 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2770 (setq table-open nil
2771 table-buffer
(nreverse table-buffer
))
2774 (org-fix-indentation x org-ascii-current-indentation
))
2775 (org-format-table-ascii table-buffer
)
2778 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2779 ;; Remove forced line breaks
2780 (if (string-match "\\\\\\\\[ \t]*$" line
)
2781 (setq line
(replace-match "" t t line
)))
2782 (if (and org-export-with-fixed-width
2783 (string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line
))
2784 (setq line
(replace-match "\\1" nil nil line
)))
2785 (insert line
"\n"))))
2789 ;; insert the table of contents
2791 (goto-char (point-min))
2792 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2794 (goto-char (match-beginning 0))
2796 (goto-char first-heading-pos
))
2797 (mapc 'insert thetoc
)
2798 (or (looking-at "[ \t]*\n[ \t]*\n")
2801 ;; Convert whitespace place holders
2802 (goto-char (point-min))
2804 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2805 (setq end
(next-single-property-change beg
'org-whitespace
))
2807 (delete-region beg end
)
2808 (insert (make-string (- end beg
) ?\
))))
2811 ;; remove display and invisible chars
2813 (goto-char (point-min))
2814 (while (setq beg
(next-single-property-change (point) 'display
))
2815 (setq end
(next-single-property-change beg
'display
))
2816 (delete-region beg end
)
2819 (goto-char (point-min))
2820 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2821 (setq end
(next-single-property-change beg
'org-cwidth
))
2822 (delete-region beg end
)
2824 (goto-char (point-min))))
2826 (defun org-export-ascii-preprocess ()
2827 "Do extra work for ASCII export"
2828 ;; Put quotes around verbatim text
2829 (goto-char (point-min))
2830 (while (re-search-forward org-verbatim-re nil t
)
2831 (goto-char (match-end 2))
2832 (backward-delete-char 1) (insert "'")
2833 (goto-char (match-beginning 2))
2834 (delete-char 1) (insert "`")
2835 (goto-char (match-end 2)))
2836 (goto-char (point-min))
2837 ;; Remove target markers
2838 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t
)
2839 (replace-match "\\1\\2")))
2841 (defun org-search-todo-below (line lines level
)
2842 "Search the subtree below LINE for any TODO entries."
2843 (let ((rest (cdr (memq line lines
)))
2844 (re org-todo-line-regexp
)
2847 (while (setq line
(pop rest
))
2848 (if (string-match re line
)
2850 (setq lv
(- (match-end 1) (match-beginning 1))
2851 todo
(and (match-beginning 2)
2852 (not (member (match-string 2 line
)
2853 org-done-keywords
))))
2855 (if (<= lv level
) (throw 'exit nil
))
2856 (if todo
(throw 'exit t
))))))))
2858 (defun org-html-expand-for-ascii (line)
2859 "Handle quoted HTML for ASCII export."
2860 (if org-export-html-expand
2861 (while (string-match "@<[^<>\n]*>" line
)
2862 ;; We just remove the tags for now.
2863 (setq line
(replace-match "" nil nil line
))))
2866 (defun org-insert-centered (s &optional underline
)
2867 "Insert the string S centered and underline it with character UNDERLINE."
2868 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2869 (insert (make-string ind ?\
) s
"\n")
2871 (insert (make-string ind ?\
)
2872 (make-string (string-width s
) underline
)
2875 (defun org-ascii-level-start (level title umax
&optional lines
)
2876 "Insert a new level in ASCII export."
2877 (let (char (n (- level umax
1)) (ind 0))
2880 (insert (make-string (* 2 n
) ?\
)
2881 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2882 org-export-ascii-bullets
))
2884 ;; find the indentation of the next non-empty line
2887 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2888 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2889 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2891 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2892 (if (or (not (equal (char-before) ?
\n))
2893 (not (equal (char-before (1- (point))) ?
\n)))
2895 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2896 (unless org-export-with-tags
2897 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2898 (setq title
(replace-match "" t t title
))))
2899 (if org-export-with-section-numbers
2900 (setq title
(concat (org-section-number level
) " " title
)))
2901 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2902 (setq org-ascii-current-indentation
'(0 .
0)))))
2905 (defun org-export-visible (type arg
)
2906 "Create a copy of the visible part of the current buffer, and export it.
2907 The copy is created in a temporary buffer and removed after use.
2908 TYPE is the final key (as a string) that also select the export command in
2909 the `C-c C-e' export dispatcher.
2910 As a special case, if the you type SPC at the prompt, the temporary
2911 org-mode file will not be removed but presented to you so that you can
2912 continue to use it. The prefix arg ARG is passed through to the exporting
2916 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2917 (read-char-exclusive))
2918 current-prefix-arg
))
2919 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2920 (error "Invalid export key"))
2921 (let* ((binding (cdr (assoc type
2922 '((?a . org-export-as-ascii
)
2923 (?\C-a . org-export-as-ascii
)
2924 (?b . org-export-as-html-and-open
)
2925 (?\C-b . org-export-as-html-and-open
)
2926 (?h . org-export-as-html
)
2927 (?H . org-export-as-html-to-buffer
)
2928 (?R . org-export-region-as-html
)
2929 (?x . org-export-as-xoxo
)))))
2930 (keepp (equal type ?\
))
2931 (file buffer-file-name
)
2932 (buffer (get-buffer-create "*Org Export Visible*"))
2934 ;; Need to hack the drawers here.
2936 (goto-char (point-min))
2937 (while (re-search-forward org-drawer-regexp nil t
)
2938 (goto-char (match-beginning 1))
2939 (or (org-invisible-p) (org-flag-drawer nil
))))
2940 (with-current-buffer buffer
(erase-buffer))
2942 (setq s
(goto-char (point-min)))
2943 (while (not (= (point) (point-max)))
2944 (goto-char (org-find-invisible))
2945 (append-to-buffer buffer s
(point))
2946 (setq s
(goto-char (org-find-visible))))
2947 (org-cycle-hide-drawers 'all
)
2948 (goto-char (point-min))
2950 ;; Copy all comment lines to the end, to make sure #+ settings are
2951 ;; still available for the second export step. Kind of a hack, but
2952 ;; does do the trick.
2953 (if (looking-at "#[^\r\n]*")
2954 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2955 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2956 (append-to-buffer buffer
(1+ (match-beginning 0))
2957 (min (point-max) (1+ (match-end 0))))))
2959 (let ((buffer-file-name file
)
2960 (org-inhibit-startup t
))
2963 (unless keepp
(funcall binding arg
))))
2965 (kill-buffer buffer
)
2966 (switch-to-buffer-other-window buffer
)
2967 (goto-char (point-min)))))
2969 (defun org-find-visible ()
2971 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2972 (get-char-property s
'invisible
)))
2974 (defun org-find-invisible ()
2976 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2977 (not (get-char-property s
'invisible
))))
2982 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2983 (defun org-get-current-options ()
2984 "Return a string with current options as keyword options.
2985 Does include HTML export options as well as TODO and CATEGORY stuff."
2986 (require 'org-archive
)
2993 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2994 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2996 #+EXPORT_SELECT_TAGS: %s
2997 #+EXPORT_EXCLUDE_TAGS: %s
3003 #+PRIORITIES: %c %c %c
3005 #+STARTUP: %s %s %s %s %s
3011 (buffer-name) (user-full-name) user-mail-address
3012 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
3013 org-export-default-language
3014 org-export-headline-levels
3015 org-export-with-section-numbers
3017 org-export-preserve-breaks
3018 org-export-html-expand
3019 org-export-with-fixed-width
3020 org-export-with-tables
3021 org-export-with-sub-superscripts
3022 org-export-with-special-strings
3023 org-export-with-footnotes
3024 org-export-with-emphasize
3025 org-export-with-timestamps
3026 org-export-with-TeX-macros
3027 org-export-with-LaTeX-fragments
3028 org-export-skip-text-before-1st-heading
3029 org-export-with-drawers
3030 org-export-with-todo-keywords
3031 org-export-with-priority
3032 org-export-with-tags
3033 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
3034 (mapconcat 'identity org-export-select-tags
" ")
3035 (mapconcat 'identity org-export-exclude-tags
" ")
3036 org-export-html-link-up
3037 org-export-html-link-home
3039 (file-name-sans-extension
3040 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3042 "TODO FEEDBACK VERIFY DONE"
3043 "Me Jason Marie DONE"
3044 org-highest-priority org-lowest-priority org-default-priority
3045 (mapconcat 'identity org-drawers
" ")
3046 (cdr (assoc org-startup-folded
3047 '((nil .
"showall") (t .
"overview") (content .
"content"))))
3048 (if org-odd-levels-only
"odd" "oddeven")
3049 (if org-hide-leading-stars
"hidestars" "showstars")
3050 (if org-startup-align-all-tables
"align" "noalign")
3051 (cond ((eq org-log-done t
) "logdone")
3052 ((equal org-log-done
'note
) "lognotedone")
3053 ((not org-log-done
) "nologdone"))
3054 (or (mapconcat (lambda (x)
3056 ((equal '(:startgroup
) x
) "{")
3057 ((equal '(:endgroup
) x
) "}")
3058 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
3060 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
3061 (mapconcat 'identity org-file-tags
" ")
3062 org-archive-location
3063 "org file:~/org/%s.org"
3066 (defun org-export-html-preprocess (parameters)
3067 ;; Convert LaTeX fragments to images
3068 (when (plist-get parameters
:LaTeX-fragments
)
3070 (concat "ltxpng/" (file-name-sans-extension
3071 (file-name-nondirectory
3072 org-current-export-file
)))
3073 org-current-export-dir nil
"Creating LaTeX image %s"))
3074 (message "Exporting..."))
3077 (defun org-insert-export-options-template ()
3078 "Insert into the buffer a template with information for exporting."
3080 (if (not (bolp)) (newline))
3081 (let ((s (org-get-current-options)))
3082 (and (string-match "#\\+CATEGORY" s
)
3083 (setq s
(substring s
0 (match-beginning 0))))
3087 (defun org-export-as-html-and-open (arg)
3088 "Export the outline as HTML and immediately open it with a browser.
3089 If there is an active region, export only the region.
3090 The prefix ARG specifies how many levels of the outline should become
3091 headlines. The default is 3. Lower levels will become bulleted lists."
3093 (org-export-as-html arg
'hidden
)
3094 (org-open-file buffer-file-name
))
3097 (defun org-export-as-html-batch ()
3098 "Call `org-export-as-html', may be used in batch processing as
3100 --load=$HOME/lib/emacs/org.el
3101 --eval \"(setq org-export-headline-levels 2)\"
3102 --visit=MyFile --funcall org-export-as-html-batch"
3103 (org-export-as-html org-export-headline-levels
'hidden
))
3106 (defun org-export-as-html-to-buffer (arg)
3107 "Call `org-export-as-html` with output to a temporary buffer.
3108 No file is created. The prefix ARG is passed through to `org-export-as-html'."
3110 (org-export-as-html arg nil nil
"*Org HTML Export*")
3111 (switch-to-buffer-other-window "*Org HTML Export*"))
3114 (defun org-replace-region-by-html (beg end
)
3115 "Assume the current region has org-mode syntax, and convert it to HTML.
3116 This can be used in any buffer. For example, you could write an
3117 itemized list in org-mode syntax in an HTML buffer and then use this
3118 command to convert it."
3120 (let (reg html buf pop-up-frames
)
3121 (save-window-excursion
3123 (setq html
(org-export-region-as-html
3125 (setq reg
(buffer-substring beg end
)
3126 buf
(get-buffer-create "*Org tmp*"))
3127 (with-current-buffer buf
3131 (setq html
(org-export-region-as-html
3132 (point-min) (point-max) t
'string
)))
3134 (delete-region beg end
)
3138 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
3139 "Convert region from BEG to END in org-mode buffer to HTML.
3140 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
3141 contents, and only produce the region of converted text, useful for
3142 cut-and-paste operations.
3143 If BUFFER is a buffer or a string, use/create that buffer as a target
3144 of the converted HTML. If BUFFER is the symbol `string', return the
3145 produced HTML as a string and leave not buffer behind. For example,
3146 a Lisp program could call this function in the following way:
3148 (setq html (org-export-region-as-html beg end t 'string))
3150 When called interactively, the output buffer is selected, and shown
3151 in a window. A non-interactive call will only return the buffer."
3152 (interactive "r\nP")
3153 (when (interactive-p)
3154 (setq buffer
"*Org HTML Export*"))
3155 (let ((transient-mark-mode t
) (zmacs-regions t
)
3157 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
3159 (set-mark (point)) ;; to activate the region
3161 (setq rtn
(org-export-as-html
3164 (if (fboundp 'deactivate-mark
) (deactivate-mark))
3165 (if (and (interactive-p) (bufferp rtn
))
3166 (switch-to-buffer-other-window rtn
)
3169 (defvar html-table-tag nil
) ; dynamically scoped into this.
3170 (defvar org-par-open nil
)
3172 (defun org-export-as-html (arg &optional hidden ext-plist
3173 to-buffer body-only pub-dir
)
3174 "Export the outline as a pretty HTML file.
3175 If there is an active region, export only the region. The prefix
3176 ARG specifies how many levels of the outline should become
3177 headlines. The default is 3. Lower levels will become bulleted
3178 lists. When HIDDEN is non-nil, don't display the HTML buffer.
3179 EXT-PLIST is a property list with external parameters overriding
3180 org-mode's default settings, but still inferior to file-local
3181 settings. When TO-BUFFER is non-nil, create a buffer with that
3182 name and export to that buffer. If TO-BUFFER is the symbol
3183 `string', don't leave any buffer behind but just return the
3184 resulting HTML as a string. When BODY-ONLY is set, don't produce
3185 the file header and footer, simply return the content of
3186 <body>...</body>, without even the body tags themselves. When
3187 PUB-DIR is set, use this as the publishing directory."
3190 ;; Make sure we have a file name when we need it.
3191 (when (and (not (or to-buffer body-only
))
3192 (not buffer-file-name
))
3193 (if (buffer-base-buffer)
3194 (org-set-local 'buffer-file-name
3195 (with-current-buffer (buffer-base-buffer)
3197 (error "Need a file name to be able to export.")))
3199 (message "Exporting...")
3200 (setq-default org-todo-line-regexp org-todo-line-regexp
)
3201 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
3202 (setq-default org-done-keywords org-done-keywords
)
3203 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
3205 (org-export-process-option-filters
3206 (org-combine-plists (org-default-export-plist)
3208 (org-infile-export-plist))))
3209 (style (concat (if (plist-get opt-plist
:style-include-default
)
3210 org-export-html-style-default
)
3211 (plist-get opt-plist
:style
)
3212 (plist-get opt-plist
:style-extra
)
3213 "\n" org-export-html-scripts
))
3214 (html-extension (plist-get opt-plist
:html-extension
))
3215 (link-validate (plist-get opt-plist
:link-validation-function
))
3216 valid thetoc have-headings first-heading-pos
3217 (odd org-odd-levels-only
)
3218 (region-p (org-region-active-p))
3219 (rbeg (and region-p
(region-beginning)))
3220 (rend (and region-p
(region-end)))
3222 (if (plist-get opt-plist
:ignore-subree-p
)
3227 (and (org-at-heading-p)
3228 (>= (org-end-of-subtree t t
) rend
))))))
3229 (level-offset (if subtree-p
3232 (+ (funcall outline-level
)
3233 (if org-odd-levels-only
1 0)))
3235 (opt-plist (if subtree-p
3236 (org-export-add-subtree-options opt-plist rbeg
)
3238 ;; The following two are dynamically scoped into other
3240 (org-current-export-dir
3241 (or pub-dir
(org-export-directory :html opt-plist
)))
3242 (org-current-export-file buffer-file-name
)
3243 (level 0) (line "") (origline "") txt todo
3246 (filename (if to-buffer nil
3249 (file-name-sans-extension
3251 (org-entry-get (region-beginning)
3252 "EXPORT_FILE_NAME" t
))
3253 (file-name-nondirectory buffer-file-name
)))
3255 (file-name-as-directory
3256 (or pub-dir
(org-export-directory :html opt-plist
))))))
3257 (current-dir (if buffer-file-name
3258 (file-name-directory buffer-file-name
)
3260 (buffer (if to-buffer
3262 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
3263 (t (get-buffer-create to-buffer
)))
3264 (find-file-noselect filename
)))
3265 (org-levels-open (make-vector org-level-max nil
))
3266 (date (plist-get opt-plist
:date
))
3267 (author (plist-get opt-plist
:author
))
3268 (title (or (and subtree-p
(org-export-get-title-from-subtree))
3269 (plist-get opt-plist
:title
)
3271 (plist-get opt-plist
:skip-before-1st-heading
))
3272 (org-export-grab-title-from-buffer))
3273 (and buffer-file-name
3274 (file-name-sans-extension
3275 (file-name-nondirectory buffer-file-name
)))
3277 (html-table-tag (plist-get opt-plist
:html-table-tag
))
3278 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
3279 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
3284 (local-list-type nil
)
3285 (local-list-indent nil
)
3286 (llt org-plain-list-ordered-item-terminator
)
3287 (email (plist-get opt-plist
:email
))
3288 (language (plist-get opt-plist
:language
))
3292 (coding-system (and (boundp 'buffer-file-coding-system
)
3293 buffer-file-coding-system
))
3294 (coding-system-for-write (or org-export-html-coding-system
3296 (save-buffer-coding-system (or org-export-html-coding-system
3298 (charset (and coding-system-for-write
3299 (fboundp 'coding-system-get
)
3300 (coding-system-get coding-system-for-write
3304 (if region-p
(region-beginning) (point-min))
3305 (if region-p
(region-end) (point-max))))
3308 (org-export-preprocess-string
3312 :skip-before-1st-heading
3313 (plist-get opt-plist
:skip-before-1st-heading
)
3314 :drawers
(plist-get opt-plist
:drawers
)
3315 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
3316 :tags
(plist-get opt-plist
:tags
)
3317 :priority
(plist-get opt-plist
:priority
)
3318 :footnotes
(plist-get opt-plist
:footnotes
)
3319 :timestamps
(plist-get opt-plist
:timestamps
)
3321 (plist-get opt-plist
:archived-trees
)
3322 :select-tags
(plist-get opt-plist
:select-tags
)
3323 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
3325 (plist-get opt-plist
:text
)
3327 (plist-get opt-plist
:LaTeX-fragments
))
3330 table-buffer table-orig-buffer
3331 ind item-type starter didclose
3332 rpl path attr desc descp desc1 desc2 link
3333 snumber fnc item-tag
3334 footnotes footref-seen
3338 (let ((inhibit-read-only t
))
3340 (remove-text-properties (point-min) (point-max)
3341 '(:org-license-to-kill t
))))
3343 (message "Exporting...")
3345 (setq org-min-level
(org-get-min-level lines level-offset
))
3346 (setq org-last-level org-min-level
)
3347 (org-init-section-numbers)
3350 ((and date
(string-match "%" date
))
3351 (setq date
(format-time-string date
)))
3353 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
3355 ;; Get the language-dependent settings
3356 (setq lang-words
(or (assoc language org-export-language-setup
)
3357 (assoc "en" org-export-language-setup
)))
3359 ;; Switch to the output buffer
3361 (let ((inhibit-read-only t
)) (erase-buffer))
3364 (and (fboundp 'set-buffer-file-coding-system
)
3365 (set-buffer-file-coding-system coding-system-for-write
))
3367 (let ((case-fold-search nil
)
3368 (org-odd-levels-only odd
))
3369 ;; create local variables for all options, to make sure all called
3370 ;; functions get the correct information
3372 (set (make-local-variable (nth 2 x
))
3373 (plist-get opt-plist
(car x
))))
3374 org-export-plist-vars
)
3375 (setq umax
(if arg
(prefix-numeric-value arg
)
3376 org-export-headline-levels
))
3377 (setq umax-toc
(if (integerp org-export-with-toc
)
3378 (min org-export-with-toc umax
)
3383 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3384 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3385 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3386 lang=\"%s\" xml:lang=\"%s\">
3389 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3390 <meta name=\"generator\" content=\"Org-mode\"/>
3391 <meta name=\"generated\" content=\"%s\"/>
3392 <meta name=\"author\" content=\"%s\"/>
3396 language language
(org-html-expand title
)
3397 (or charset
"iso-8859-1") date author style
))
3399 (insert (or (plist-get opt-plist
:preamble
) ""))
3401 (when (plist-get opt-plist
:auto-preamble
)
3402 (if title
(insert (format org-export-html-title-format
3403 (org-html-expand title
))))))
3405 (if (and org-export-with-toc
(not body-only
))
3407 (push (format "<h%d>%s</h%d>\n"
3408 org-export-html-toplevel-hlevel
3410 org-export-html-toplevel-hlevel
)
3412 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3413 (push "<ul>\n<li>" thetoc
)
3415 (mapcar '(lambda (line)
3416 (if (string-match org-todo-line-regexp line
)
3417 ;; This is a headline
3419 (setq have-headings t
)
3420 (setq level
(- (match-end 1) (match-beginning 1)
3422 level
(org-tr-level level
)
3423 txt
(save-match-data
3425 (org-export-cleanup-toc-line
3426 (match-string 3 line
))))
3428 (or (and org-export-mark-todo-in-toc
3430 (not (member (match-string 2 line
)
3431 org-done-keywords
)))
3433 (and org-export-mark-todo-in-toc
3435 (org-search-todo-below
3436 line lines level
))))
3438 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3439 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3440 (if (string-match quote-re0 txt
)
3441 (setq txt
(replace-match "" t t txt
)))
3442 (setq snumber
(org-section-number level
))
3443 (if org-export-with-section-numbers
3444 (setq txt
(concat snumber
" " txt
)))
3445 (if (<= level
(max umax umax-toc
))
3446 (setq head-count
(+ head-count
1)))
3447 (if (<= level umax-toc
)
3449 (if (> level org-last-level
)
3451 (setq cnt
(- level org-last-level
))
3452 (while (>= (setq cnt
(1- cnt
)) 0)
3453 (push "\n<ul>\n<li>" thetoc
))
3454 (push "\n" thetoc
)))
3455 (if (< level org-last-level
)
3457 (setq cnt
(- org-last-level level
))
3458 (while (>= (setq cnt
(1- cnt
)) 0)
3459 (push "</li>\n</ul>" thetoc
))
3460 (push "\n" thetoc
)))
3461 ;; Check for targets
3462 (while (string-match org-any-target-regexp line
)
3463 (setq line
(replace-match
3464 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3466 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3467 (setq txt
(replace-match "" t t txt
)))
3471 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3472 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3473 snumber txt
) thetoc
)
3475 (setq org-last-level level
))
3479 (while (> org-last-level
(1- org-min-level
))
3480 (setq org-last-level
(1- org-last-level
))
3481 (push "</li>\n</ul>\n" thetoc
))
3482 (push "</div>\n" thetoc
)
3483 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3486 (org-init-section-numbers)
3490 (while (setq line
(pop lines
) origline line
)
3493 ;; end of quote section?
3494 (when (and inquote
(string-match "^\\*+ " line
))
3497 ;; inside a quote section?
3499 (insert (org-html-protect line
) "\n")
3500 (throw 'nextline nil
))
3502 ;; Fixed-width, verbatim lines (examples)
3503 (when (and org-export-with-fixed-width
3504 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
3507 (org-close-par-maybe)
3508 (insert "<pre class=\"example\">\n"))
3509 (insert (org-html-protect (match-string 3 line
)) "\n")
3510 (when (or (not lines
)
3511 (not (string-match "^[ \t]*\\(:.*\\)"
3514 (insert "</pre>\n"))
3515 (throw 'nextline nil
))
3518 (when (get-text-property 0 'org-protected line
)
3520 (when (re-search-backward
3521 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3522 (setq par
(match-string 1))
3523 (replace-match "\\2\n"))
3526 (or (= (length (car lines
)) 0)
3527 (get-text-property 0 'org-protected
(car lines
))))
3528 (insert (pop lines
) "\n"))
3529 (and par
(insert "<p>\n")))
3530 (throw 'nextline nil
))
3533 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3535 (insert "\n</p>\n<hr/>\n<p>\n")
3536 (insert "\n<hr/>\n"))
3537 (throw 'nextline nil
))
3539 ;; Blockquotes and verse
3540 (when (equal "ORG-BLOCKQUOTE-START" line
)
3541 (org-close-par-maybe)
3542 (insert "<blockquote>\n<p>\n")
3543 (throw 'nextline nil
))
3544 (when (equal "ORG-BLOCKQUOTE-END" line
)
3545 (insert "</p>\n</blockquote>\n")
3546 (throw 'nextline nil
))
3547 (when (equal "ORG-VERSE-START" line
)
3548 (org-close-par-maybe)
3549 (insert "\n<p class=\"verse\">\n")
3551 (throw 'nextline nil
))
3552 (when (equal "ORG-VERSE-END" line
)
3555 (throw 'nextline nil
))
3557 (let ((i (org-get-string-indentation line
)))
3559 (setq line
(concat (mapconcat 'identity
3560 (make-list (* 2 i
) "\\nbsp") "")
3561 " " (org-trim line
))))
3562 (setq line
(concat line
"\\\\"))))
3564 ;; make targets to anchors
3565 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3568 (setq line
(replace-match
3570 "@<a name=\"%s\" id=\"%s\">@</a>"
3571 (org-solidify-link-text (match-string 1 line
))
3572 (org-solidify-link-text (match-string 1 line
)))
3574 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3575 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3576 (setq line
(replace-match
3577 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3578 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3581 (setq line
(replace-match
3582 (concat "@<a name=\""
3583 (org-solidify-link-text (match-string 1 line
))
3584 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3587 (setq line
(org-html-handle-time-stamps line
))
3589 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3590 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3591 ;; Also handle sub_superscripts and checkboxes
3592 (or (string-match org-table-hline-regexp line
)
3593 (setq line
(org-html-expand line
)))
3597 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
3598 (setq start
(match-beginning 0))
3599 (setq path
(save-match-data (org-link-unescape
3600 (match-string 3 line
))))
3602 ((match-end 2) (match-string 2 line
))
3604 (or (file-name-absolute-p path
)
3605 (string-match "^\\.\\.?/" path
)))
3608 (setq path
(org-extract-attributes (org-link-unescape path
)))
3609 (setq attr
(get-text-property 0 'org-attributes path
))
3610 (setq desc1
(if (match-end 5) (match-string 5 line
))
3611 desc2
(if (match-end 2) (concat type
":" path
) path
)
3612 descp
(and desc1
(not (equal desc1 desc2
)))
3613 desc
(or desc1 desc2
))
3614 ;; Make an image out of the description if that is so wanted
3615 (when (and descp
(org-file-image-p
3616 desc org-export-html-inline-image-extensions
))
3618 (if (string-match "^file:" desc
)
3619 (setq desc
(substring desc
(match-end 0)))))
3620 (setq desc
(org-add-props
3621 (concat "<img src=\"" desc
"\"/>")
3622 '(org-protected t
))))
3623 ;; FIXME: do we need to unescape here somewhere?
3625 ((equal type
"internal")
3629 (org-solidify-link-text
3630 (save-match-data (org-link-unescape path
)) nil
)
3632 (org-export-html-format-desc desc
)
3634 ((and (equal type
"id")
3635 (setq id-file
(org-id-find-id-file path
)))
3636 ;; This is an id: link to another file (if it was the same file,
3637 ;; it would have become an internal link...)
3638 (setq id-file
(file-relative-name
3639 id-file
(file-name-directory org-current-export-file
)))
3640 (setq id-file
(concat (file-name-sans-extension id-file
)
3641 "." html-extension
))
3642 (setq rpl
(concat "<a href=\"" id-file
"#" path
"\""
3644 (org-export-html-format-desc desc
)
3646 ((member type
'("http" "https"))
3647 ;; standard URL, just check if we need to inline an image
3648 (if (and (or (eq t org-export-html-inline-images
)
3649 (and org-export-html-inline-images
(not descp
)))
3651 path org-export-html-inline-image-extensions
))
3652 (setq rpl
(org-export-html-format-image
3653 (concat type
":" path
) org-par-open
))
3654 (setq link
(concat type
":" path
))
3655 (setq rpl
(concat "<a href=\""
3656 (org-export-html-format-href link
)
3658 (org-export-html-format-desc desc
)
3660 ((member type
'("ftp" "mailto" "news"))
3662 (setq link
(concat type
":" path
))
3663 (setq rpl
(concat "<a href=\""
3664 (org-export-html-format-href link
)
3666 (org-export-html-format-desc desc
)
3669 ((string= type
"coderef")
3671 (setq rpl
(format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3673 (format (org-export-get-coderef-format path
(and descp desc
))
3674 (cdr (assoc path org-export-code-refs
))))))
3676 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3677 ;; The link protocol has a function for format the link
3680 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3682 ((string= type
"file")
3684 (let* ((filename path
)
3685 (abs-p (file-name-absolute-p filename
))
3686 thefile file-is-image-p search
)
3688 (if (string-match "::\\(.*\\)" filename
)
3689 (setq search
(match-string 1 filename
)
3690 filename
(replace-match "" t nil filename
)))
3692 (if (functionp link-validate
)
3693 (funcall link-validate filename current-dir
)
3695 (setq file-is-image-p
3697 filename org-export-html-inline-image-extensions
))
3698 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3699 (when (and org-export-html-link-org-files-as-html
3700 (string-match "\\.org$" thefile
))
3701 (setq thefile
(concat (substring thefile
0
3702 (match-beginning 0))
3703 "." html-extension
))
3705 ;; make sure this is can be used as target search
3706 (not (string-match "^[0-9]*$" search
))
3707 (not (string-match "^\\*" search
))
3708 (not (string-match "^/.*/$" search
)))
3709 (setq thefile
(concat thefile
"#"
3710 (org-solidify-link-text
3711 (org-link-unescape search
)))))
3712 (when (string-match "^file:" desc
)
3713 (setq desc
(replace-match "" t t desc
))
3714 (if (string-match "\\.org$" desc
)
3715 (setq desc
(replace-match "" t t desc
))))))
3716 (setq rpl
(if (and file-is-image-p
3717 (or (eq t org-export-html-inline-images
)
3718 (and org-export-html-inline-images
3721 (message "image %s %s" thefile org-par-open
)
3722 (org-export-html-format-image thefile org-par-open
))
3723 (concat "<a href=\"" thefile
"\"" attr
">"
3724 (org-export-html-format-desc desc
)
3726 (if (not valid
) (setq rpl desc
))))
3729 ;; just publish the path, as default
3730 (setq rpl
(concat "<i><" type
":"
3731 (save-match-data (org-link-unescape path
))
3733 (setq line
(replace-match rpl t t line
)
3734 start
(+ start
(length rpl
))))
3737 (if (and (string-match org-todo-line-regexp line
)
3738 (match-beginning 2))
3741 (concat (substring line
0 (match-beginning 2))
3743 (if (member (match-string 2 line
)
3746 " " (match-string 2 line
)
3747 "\"> " (match-string 2 line
)
3748 "</span>" (substring line
(match-end 2)))))
3750 ;; Does this contain a reference to a footnote?
3751 (when org-export-with-footnotes
3753 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3754 (if (get-text-property (match-beginning 2) 'org-protected line
)
3755 (setq start
(match-end 2))
3756 (let ((n (match-string 2 line
)) extra a
)
3757 (if (setq a
(assoc n footref-seen
))
3759 (setcdr a
(1+ (cdr a
)))
3760 (setq extra
(format ".%d" (cdr a
))))
3762 (push (cons n
1) footref-seen
))
3766 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
3767 (match-string 1 line
) n extra n n
)
3771 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3772 ;; This is a headline
3773 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
3775 txt
(match-string 2 line
))
3776 (if (string-match quote-re0 txt
)
3777 (setq txt
(replace-match "" t t txt
)))
3778 (if (<= level
(max umax umax-toc
))
3779 (setq head-count
(+ head-count
1)))
3781 ;; Close any local lists before inserting a new header line
3782 (while local-list-type
3783 (org-close-li (car local-list-type
))
3784 (insert (format "</%sl>\n" (car local-list-type
)))
3785 (pop local-list-type
))
3786 (setq local-list-indent nil
3788 (setq first-heading-pos
(or first-heading-pos
(point)))
3789 (org-html-level-start level txt umax
3790 (and org-export-with-toc
(<= level umax
))
3793 (when (string-match quote-re line
)
3794 (org-close-par-maybe)
3798 ((and org-export-with-tables
3799 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3800 (if (not table-open
)
3802 (setq table-open t table-buffer nil table-orig-buffer nil
))
3804 (setq table-buffer
(cons line table-buffer
)
3805 table-orig-buffer
(cons origline table-orig-buffer
))
3806 (when (or (not lines
)
3807 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3809 (setq table-open nil
3810 table-buffer
(nreverse table-buffer
)
3811 table-orig-buffer
(nreverse table-orig-buffer
))
3812 (org-close-par-maybe)
3813 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3818 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3819 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3820 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3821 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3823 (setq ind
(org-get-string-indentation line
)
3824 item-type
(if (match-beginning 4) "o" "u")
3825 starter
(if (match-beginning 2)
3826 (substring (match-string 2 line
) 0 -
1))
3827 line
(substring line
(match-beginning 5))
3829 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3831 item-tag
(match-string 1 line
)
3832 line
(substring line
(match-end 0))))
3833 (when (and (not (equal item-type
"d"))
3834 (not (string-match "[^ \t]" line
)))
3835 ;; empty line. Pretend indentation is large.
3836 (setq ind
(if org-empty-line-terminates-plain-lists
3838 (1+ (or (car local-list-indent
) 1)))))
3840 (while (and in-local-list
3841 (or (and (= ind
(car local-list-indent
))
3843 (< ind
(car local-list-indent
))))
3845 (org-close-li (car local-list-type
))
3846 (insert (format "</%sl>\n" (car local-list-type
)))
3847 (pop local-list-type
) (pop local-list-indent
)
3848 (setq in-local-list local-list-indent
))
3851 (or (not in-local-list
)
3852 (> ind
(car local-list-indent
))))
3853 ;; Start new (level of) list
3854 (org-close-par-maybe)
3856 ((equal item-type
"u") "<ul>\n<li>\n")
3857 ((equal item-type
"o") "<ol>\n<li>\n")
3858 ((equal item-type
"d")
3859 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3860 (push item-type local-list-type
)
3861 (push ind local-list-indent
)
3862 (setq in-local-list t
))
3864 ;; continue current list
3865 (org-close-li (car local-list-type
))
3867 ((equal (car local-list-type
) "d")
3868 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3871 ;; we did close a list, normal text follows: need <p>
3873 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3876 (if (equal (match-string 1 line
) "X")
3878 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3881 ;; Empty lines start a new paragraph. If hand-formatted lists
3882 ;; are not fully interpreted, lines starting with "-", "+", "*"
3883 ;; also start a new paragraph.
3884 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3886 ;; Is this the start of a footnote?
3887 (when org-export-with-footnotes
3888 (when (and (boundp 'footnote-section-tag-regexp
)
3889 (string-match (concat "^" footnote-section-tag-regexp
)
3892 (throw 'nextline nil
))
3893 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3894 (org-close-par-maybe)
3895 (let ((n (match-string 1 line
)))
3896 (setq org-par-open t
3898 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
3900 ;; Check if the line break needs to be conserved
3902 ((string-match "\\\\\\\\[ \t]*$" line
)
3903 (setq line
(replace-match "<br/>" t t line
)))
3904 (org-export-preserve-breaks
3905 (setq line
(concat line
"<br/>"))))
3907 ;; Check if a paragraph should be started
3909 (while (and org-par-open
3910 (string-match "\\\\par\\>" line start
))
3911 ;; Leave a space in the </p> so that the footnote matcher
3912 ;; does not see this.
3913 (if (not (get-text-property (match-beginning 0)
3914 'org-protected line
))
3915 (setq line
(replace-match "</p ><p >" t t line
)))
3916 (setq start
(match-end 0))))
3918 (insert line
"\n")))))
3920 ;; Properly close all local lists and other lists
3925 ;; Close any local lists before inserting a new header line
3926 (while local-list-type
3927 (org-close-li (car local-list-type
))
3928 (insert (format "</%sl>\n" (car local-list-type
)))
3929 (pop local-list-type
))
3930 (setq local-list-indent nil
3932 (org-html-level-start 1 nil umax
3933 (and org-export-with-toc
(<= level umax
))
3935 ;; the </div> to close the last text-... div.
3936 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
3939 (goto-char (point-min))
3940 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
3941 (push (match-string 0) footnotes
)
3942 (replace-match "" t t
)))
3944 (insert (format org-export-html-footnotes-section
3945 (or (nth 4 lang-words
) "Footnotes")
3946 (mapconcat 'identity
(nreverse footnotes
) "\n"))
3949 (when (plist-get opt-plist
:auto-postamble
)
3950 (insert "<div id=\"postamble\">")
3951 (when (and org-export-author-info author
)
3952 (insert "<p class=\"author\"> "
3953 (nth 1 lang-words
) ": " author
"\n")
3955 (if (listp (split-string email
",+ *"))
3957 (insert "<a href=\"mailto:" e
"\"><"
3959 (split-string email
",+ *"))
3960 (insert "<a href=\"mailto:" email
"\"><"
3961 email
"></a>\n")))
3963 (when (and date org-export-time-stamp-file
)
3964 (insert "<p class=\"date\"> "
3965 (nth 2 lang-words
) ": "
3967 (when org-export-creator-info
3968 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3969 org-version emacs-major-version
)))
3972 (if org-export-html-with-timestamp
3973 (insert org-export-html-html-helper-timestamp
))
3974 (insert (or (plist-get opt-plist
:postamble
) ""))
3975 (insert "</body>\n</html>\n"))
3977 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3979 (if (eq major-mode default-major-mode
) (html-mode)))
3981 ;; insert the table of contents
3982 (goto-char (point-min))
3984 (if (or (re-search-forward
3985 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3987 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3989 (goto-char (match-beginning 0))
3991 (goto-char first-heading-pos
)
3992 (when (looking-at "\\s-*</p>")
3993 (goto-char (match-end 0))
3995 (insert "<div id=\"table-of-contents\">\n")
3996 (mapc 'insert thetoc
)
3997 (insert "</div>\n"))
3998 ;; remove empty paragraphs and lists
3999 (goto-char (point-min))
4000 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
4002 (goto-char (point-min))
4003 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
4005 (goto-char (point-min))
4006 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
4008 ;; Convert whitespace place holders
4009 (goto-char (point-min))
4011 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
4012 (setq n
(get-text-property beg
'org-whitespace
)
4013 end
(next-single-property-change beg
'org-whitespace
))
4015 (delete-region beg end
)
4016 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
4017 (make-string n ?x
)))))
4018 (or to-buffer
(save-buffer))
4019 (goto-char (point-min))
4020 (message "Exporting... done")
4021 (if (eq to-buffer
'string
)
4022 (prog1 (buffer-substring (point-min) (point-max))
4023 (kill-buffer (current-buffer)))
4024 (current-buffer)))))
4026 (defun org-export-get-coderef-format (path desc
)
4028 (if (and desc
(string-match
4029 (regexp-quote (concat "(" path
")"))
4031 (replace-match "%s" t t desc
)
4035 (defun org-export-html-format-href (s)
4036 "Make sure the S is valid as a href reference in an XHTML document."
4039 (while (string-match "&" s start
)
4040 (setq start
(+ (match-beginning 0) 3)
4041 s
(replace-match "&" t t s
)))))
4044 (defun org-export-html-format-desc (s)
4045 "Make sure the S is valid as a description in a link."
4046 (if (and s
(not (get-text-property 1 'org-protected s
)))
4048 (org-html-do-expand s
))
4051 (defun org-export-html-format-image (src par-open
)
4052 "Create image tag with source and attributes."
4054 (if (string-match "^ltxpng/" src
)
4055 (format "<img src=\"%s\"/>" src
)
4056 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
4057 (attr (org-find-text-property-in-string 'org-attributes src
))
4058 (label (org-find-text-property-in-string 'org-label src
)))
4059 (format "%s<div %sclass=\"figure\">
4060 <p><img src=\"%s\"%s /></p>%s
4062 (if org-par-open
"</p>\n" "")
4063 (if label
(format "id=\"%s\" " label
) "")
4065 (if (string-match "\\<alt=" (or attr
""))
4067 (concat " " attr
" alt=\"" src
"\""))
4068 (if caption
(concat "\n<p>" caption
"</p>") "")
4069 (if org-par-open
"\n<p>" ""))))))
4072 (defvar org-table-colgroup-info nil
)
4073 (defun org-format-table-ascii (lines)
4074 "Format a table for ascii export."
4076 (setq lines
(org-split-string lines
"\n")))
4077 (if (not (string-match "^[ \t]*|" (car lines
)))
4078 ;; Table made by table.el - test for spanning
4081 ;; A normal org table
4082 ;; Get rid of hlines at beginning and end
4083 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4084 (setq lines
(nreverse lines
))
4085 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4086 (setq lines
(nreverse lines
))
4087 (when org-export-table-remove-special-lines
4088 ;; Check if the table has a marking column. If yes remove the
4089 ;; column and the special lines
4090 (setq lines
(org-table-clean-before-export lines
)))
4091 ;; Get rid of the vertical lines except for grouping
4092 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
4094 (while (setq line
(pop lines
))
4095 (if (string-match org-table-hline-regexp line
)
4096 (and (string-match "|\\(.*\\)|" line
)
4097 (setq line
(replace-match " \\1" t nil line
)))
4098 (setq start
0 vl1 vl
)
4099 (while (string-match "|" line start
)
4100 (setq start
(match-end 0))
4101 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
4105 (defun org-colgroup-info-to-vline-list (info)
4108 (setq last new new
(pop info
))
4109 (if (or (memq last
'(:end
:startend
))
4110 (memq new
'(:start
:startend
)))
4113 (setq vl
(nreverse vl
))
4114 (and vl
(setcar vl nil
))
4117 (defvar org-table-number-regexp
) ; defined in org-table.el
4118 (defun org-format-table-html (lines olines
)
4119 "Find out which HTML converter to use and return the HTML code."
4121 (setq lines
(org-split-string lines
"\n")))
4122 (if (string-match "^[ \t]*|" (car lines
))
4123 ;; A normal org table
4124 (org-format-org-table-html lines
)
4125 ;; Table made by table.el - test for spanning
4126 (let* ((hlines (delq nil
(mapcar
4128 (if (string-match "^[ \t]*\\+-" x
) x
4131 (first (car hlines
))
4132 (ll (and (string-match "\\S-+" first
)
4133 (match-string 0 first
)))
4134 (re (concat "^[ \t]*" (regexp-quote ll
)))
4135 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
4137 (if (and (not spanning
)
4138 (not org-export-prefer-native-exporter-for-tables
))
4139 ;; We can use my own converter with HTML conversions
4140 (org-format-table-table-html lines
)
4141 ;; Need to use the code generator in table.el, with the original text.
4142 (org-format-table-table-html-using-table-generate-source olines
)))))
4144 (defvar org-table-number-fraction
) ; defined in org-table.el
4145 (defun org-format-org-table-html (lines &optional splice
)
4146 "Format a table into HTML."
4147 (require 'org-table
)
4148 ;; Get rid of hlines at beginning and end
4149 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4150 (setq lines
(nreverse lines
))
4151 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4152 (setq lines
(nreverse lines
))
4153 (when org-export-table-remove-special-lines
4154 ;; Check if the table has a marking column. If yes remove the
4155 ;; column and the special lines
4156 (setq lines
(org-table-clean-before-export lines
)))
4158 (let ((caption (or (get-text-property 0 'org-caption
(car lines
))
4159 (get-text-property (or (next-single-property-change
4160 0 'org-caption
(car lines
))
4162 'org-caption
(car lines
))))
4163 (head (and org-export-highlight-first-table-line
4165 (lambda (x) (string-match "^[ \t]*|-" x
))
4169 tbopen line fields html gr colgropen
)
4170 (if splice
(setq head nil
))
4171 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
4173 (while (setq line
(pop lines
))
4175 (if (string-match "^[ \t]*|-" line
)
4178 (push (if head
"</thead>" "</tbody>") html
)
4179 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
4180 (setq head nil
) ;; head ends here, first time around
4182 (throw 'next-line t
)))
4183 ;; Break the line into fields
4184 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4185 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
4186 (setq nlines
(1+ nlines
) i -
1)
4187 (push (concat "<tr>"
4191 (if (and (< i nlines
)
4192 (string-match org-table-number-regexp x
))
4193 (incf (aref fnum i
)))
4195 (concat (car org-export-table-header-tags
) x
4196 (cdr org-export-table-header-tags
))
4197 (concat (car org-export-table-data-tags
) x
4198 (cdr org-export-table-data-tags
))))
4202 (unless splice
(if tbopen
(push "</tbody>" html
)))
4203 (unless splice
(push "</table>\n" html
))
4204 (setq html
(nreverse html
))
4206 ;; Put in col tags with the alignment (unfortunately often ignored...)
4209 (setq gr
(pop org-table-colgroup-info
))
4210 (format "%s<col align=\"%s\"></col>%s"
4211 (if (memq gr
'(:start
:startend
))
4213 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
4216 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
4218 (if (memq gr
'(:end
:startend
))
4219 (progn (setq colgropen nil
) "</colgroup>")
4223 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
4224 (if caption
(push (format "<caption>%s</caption>" caption
) html
))
4225 (push html-table-tag html
))
4226 (concat (mapconcat 'identity html
"\n") "\n")))
4228 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
4229 "Check if the table has a marking column.
4230 If yes remove the column and the special lines."
4231 (setq org-table-colgroup-info nil
)
4234 (lambda (x) (or (string-match "^[ \t]*|-" x
)
4237 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
4238 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
4242 (setq org-table-clean-did-remove-column nil
)
4247 ((string-match "^[ \t]*| */ *|" x
)
4248 (setq org-table-colgroup-info
4250 (cond ((member x
'("<" "<")) :start
)
4251 ((member x
'(">" ">")) :end
)
4252 ((member x
'("<>" "<>")) :startend
)
4254 (org-split-string x
"[ \t]*|[ \t]*")))
4258 (setq org-table-clean-did-remove-column t
)
4263 ((string-match "^[ \t]*| */ *|" x
)
4264 (setq org-table-colgroup-info
4266 (cond ((member x
'("<" "<")) :start
)
4267 ((member x
'(">" ">")) :end
)
4268 ((member x
'("<>" "<>")) :startend
)
4270 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
4272 ((string-match "^[ \t]*| *[!_^/] *|" x
)
4273 nil
) ; ignore this line
4274 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
4275 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
4276 ;; remove the first column
4277 (replace-match "\\1|" t nil x
))))
4280 (defun org-format-table-table-html (lines)
4281 "Format a table generated by table.el into HTML.
4282 This conversion does *not* use `table-generate-source' from table.el.
4283 This has the advantage that Org-mode's HTML conversions can be used.
4284 But it has the disadvantage, that no cell- or row-spanning is allowed."
4285 (let (line field-buffer
4286 (head org-export-highlight-first-table-line
)
4288 (setq html
(concat html-table-tag
"\n"))
4289 (while (setq line
(pop lines
))
4290 (setq empty
" ")
4292 (if (string-match "^[ \t]*\\+-" line
)
4303 (if (equal x
"") (setq x empty
))
4305 (concat (car org-export-table-header-tags
) x
4306 (cdr org-export-table-header-tags
))
4307 (concat (car org-export-table-data-tags
) x
4308 (cdr org-export-table-data-tags
))))
4312 (setq field-buffer nil
)))
4314 (throw 'next-line t
)))
4315 ;; Break the line into fields and store the fields
4316 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4318 (setq field-buffer
(mapcar
4320 (concat x
"<br/>" (pop fields
)))
4322 (setq field-buffer fields
))))
4323 (setq html
(concat html
"</table>\n"))
4326 (defun org-format-table-table-html-using-table-generate-source (lines)
4327 "Format a table into html, using `table-generate-source' from table.el.
4328 This has the advantage that cell- or row-spanning is allowed.
4329 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4331 (with-current-buffer (get-buffer-create " org-tmp1 ")
4333 (insert (mapconcat 'identity lines
"\n"))
4334 (goto-char (point-min))
4335 (if (not (re-search-forward "|[^+]" nil t
))
4336 (error "Error processing table"))
4337 (table-recognize-table)
4338 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4339 (table-generate-source 'html
" org-tmp2 ")
4340 (set-buffer " org-tmp2 ")
4341 (buffer-substring (point-min) (point-max))))
4343 (defun org-export-splice-style (style extra
)
4344 "Splice EXTRA into STYLE, just before \"</style>\"."
4345 (if (and (stringp extra
)
4346 (string-match "\\S-" extra
)
4347 (string-match "</style>" style
))
4348 (concat (substring style
0 (match-beginning 0))
4350 (substring style
(match-beginning 0)))
4353 (defun org-html-handle-time-stamps (s)
4354 "Format time stamps in string S, or remove them."
4357 (while (string-match org-maybe-keyword-time-regexp s
)
4358 (or b
(setq b
(substring s
0 (match-beginning 0))))
4360 r
(substring s
0 (match-beginning 0))
4362 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4363 (match-string 1 s
)))
4364 (format " @<span class=\"timestamp\">%s@</span>"
4366 (org-translate-time (match-string 3 s
)) 1 -
1)))
4367 s
(substring s
(match-end 0))))
4368 ;; Line break if line started and ended with time stamp stuff
4371 (setq r
(concat r s
))
4372 (unless (string-match "\\S-" (concat b s
))
4373 (setq r
(concat r
"@<br/>")))
4376 (defun org-export-htmlize-region-for-paste (beg end
)
4377 "Convert the region to HTML, using htmlize.el.
4378 This is much like `htmlize-region-for-paste', only that it uses
4379 the settings define in the org-... variables."
4380 (let* ((htmlize-output-type org-export-htmlize-output-type
)
4381 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
4382 (htmlbuf (htmlize-region beg end
)))
4384 (with-current-buffer htmlbuf
4385 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
4386 (plist-get htmlize-buffer-places
'content-end
)))
4387 (kill-buffer htmlbuf
))))
4390 (defun org-export-htmlize-generate-css ()
4391 "Create the CSS for all font definitions in the current Emacs session.
4392 Use this to create face definitions in your CSS style file that can then
4393 be used by code snippets transformed by htmlize.
4394 This command just produces a buffer that contains class definitions for all
4395 faces used in the current Emacs session. You can copy and paste the ones you
4396 need into your CSS file.
4398 If you then set `org-export-htmlize-output-type' to `css', calls to
4399 the function `org-export-htmlize-region-for-paste' will produce code
4400 that uses these same face definitions."
4403 (and (get-buffer "*html*") (kill-buffer "*html*"))
4405 (let ((fl (face-list))
4406 (htmlize-css-name-prefix "org-")
4407 (htmlize-output-type 'css
)
4409 (while (setq f
(pop fl
)
4410 i
(and f
(face-attribute f
:inherit
)))
4411 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
4412 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
4413 (htmlize-region (point-min) (point-max))))
4414 (switch-to-buffer "*html*")
4415 (goto-char (point-min))
4416 (if (re-search-forward "<style" nil t
)
4417 (delete-region (point-min) (match-beginning 0)))
4418 (if (re-search-forward "</style>" nil t
)
4419 (delete-region (1+ (match-end 0)) (point-max)))
4420 (beginning-of-line 1)
4421 (if (looking-at " +") (replace-match ""))
4422 (goto-char (point-min)))
4424 (defun org-html-protect (s)
4425 ;; convert & to &, < to < and > to >
4427 (while (string-match "&" s start
)
4428 (setq s
(replace-match "&" t t s
)
4429 start
(1+ (match-beginning 0))))
4430 (while (string-match "<" s
)
4431 (setq s
(replace-match "<" t t s
)))
4432 (while (string-match ">" s
)
4433 (setq s
(replace-match ">" t t s
)))
4434 ; (while (string-match "\"" s)
4435 ; (setq s (replace-match """ t t s)))
4439 (defun org-export-cleanup-toc-line (s)
4440 "Remove tags and timestamps from lines going into the toc."
4441 (when (memq org-export-with-tags
'(not-in-toc nil
))
4442 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
4443 (setq s
(replace-match "" t t s
))))
4444 (when org-export-remove-timestamps-from-toc
4445 (while (string-match org-maybe-keyword-time-regexp s
)
4446 (setq s
(replace-match "" t t s
))))
4447 (while (string-match org-bracket-link-regexp s
)
4448 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
4452 (defun org-html-expand (string)
4453 "Prepare STRING for HTML export. Applies all active conversions.
4454 If there are links in the string, don't modify these."
4455 (let* ((re (concat org-bracket-link-regexp
"\\|"
4456 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4458 (while (setq m
(string-match re string
))
4459 (setq s
(substring string
0 m
)
4460 l
(match-string 0 string
)
4461 string
(substring string
(match-end 0)))
4462 (push (org-html-do-expand s
) res
)
4464 (push (org-html-do-expand string
) res
)
4465 (apply 'concat
(nreverse res
))))
4467 (defun org-html-do-expand (s)
4468 "Apply all active conversions to translate special ASCII to HTML."
4469 (setq s
(org-html-protect s
))
4470 (if org-export-html-expand
4471 (while (string-match "@<\\([^&]*\\)>" s
)
4472 (setq s
(replace-match "<\\1>" t nil s
))))
4473 (if org-export-with-emphasize
4474 (setq s
(org-export-html-convert-emphasize s
)))
4475 (if org-export-with-special-strings
4476 (setq s
(org-export-html-convert-special-strings s
)))
4477 (if org-export-with-sub-superscripts
4478 (setq s
(org-export-html-convert-sub-super s
)))
4479 (if org-export-with-TeX-macros
4480 (let ((start 0) wd ass
)
4481 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4483 (if (get-text-property (match-beginning 0) 'org-protected s
)
4484 (setq start
(match-end 0))
4485 (setq wd
(match-string 1 s
))
4486 (if (setq ass
(assoc wd org-html-entities
))
4487 (setq s
(replace-match (or (cdr ass
)
4488 (concat "&" (car ass
) ";"))
4490 (setq start
(+ start
(length wd
))))))))
4493 (defun org-create-multibrace-regexp (left right n
)
4494 "Create a regular expression which will match a balanced sexp.
4495 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4496 as single character strings.
4497 The regexp returned will match the entire expression including the
4498 delimiters. It will also define a single group which contains the
4499 match except for the outermost delimiters. The maximum depth of
4500 stacked delimiters is N. Escaping delimiters is not possible."
4501 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4504 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4507 re
(concat re or next
)
4508 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4509 (concat left
"\\(" re
"\\)" right
)))
4511 (defvar org-match-substring-regexp
4513 "\\([^\\]\\)\\([_^]\\)\\("
4514 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4516 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4518 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4519 "The regular expression matching a sub- or superscript.")
4521 (defvar org-match-substring-with-braces-regexp
4523 "\\([^\\]\\)\\([_^]\\)\\("
4524 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4526 "The regular expression matching a sub- or superscript, forcing braces.")
4528 (defconst org-export-html-special-string-regexps
4529 '(("\\\\-" .
"­")
4530 ("---\\([^-]\\)" .
"—\\1")
4531 ("--\\([^-]\\)" .
"–\\1")
4532 ("\\.\\.\\." .
"…"))
4533 "Regular expressions for special string conversion.")
4535 (defun org-export-html-convert-special-strings (string)
4536 "Convert special characters in STRING to HTML."
4537 (let ((all org-export-html-special-string-regexps
)
4539 (while (setq a
(pop all
))
4540 (setq re
(car a
) rpl
(cdr a
) start
0)
4541 (while (string-match re string start
)
4542 (if (get-text-property (match-beginning 0) 'org-protected string
)
4543 (setq start
(match-end 0))
4544 (setq string
(replace-match rpl t nil string
)))))
4547 (defun org-export-html-convert-sub-super (string)
4548 "Convert sub- and superscripts in STRING to HTML."
4549 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4550 (while (string-match org-match-substring-regexp string s
)
4552 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4553 ((get-text-property (match-beginning 2) 'org-protected string
)
4554 (setq s
(match-end 2)))
4556 (setq s
(match-end 1)
4557 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4558 c
(or (match-string 8 string
)
4559 (match-string 6 string
)
4560 (match-string 5 string
))
4561 string
(replace-match
4562 (concat (match-string 1 string
)
4563 "<" key
">" c
"</" key
">")
4565 (while (string-match "\\\\\\([_^]\\)" string
)
4566 (setq string
(replace-match (match-string 1 string
) t t string
)))
4569 (defun org-export-html-convert-emphasize (string)
4572 (while (string-match org-emph-re string s
)
4574 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4575 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4576 (setq s
(match-beginning 0)
4579 (match-string 1 string
)
4580 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4581 (match-string 4 string
)
4582 (nth 3 (assoc (match-string 3 string
)
4583 org-emphasis-alist
))
4584 (match-string 5 string
))
4585 string
(replace-match rpl t t string
)
4586 s
(+ s
(- (length rpl
) 2)))
4590 (defun org-open-par ()
4591 "Insert <p>, but first close previous paragraph if any."
4592 (org-close-par-maybe)
4594 (setq org-par-open t
))
4595 (defun org-close-par-maybe ()
4596 "Close paragraph if there is one open."
4599 (setq org-par-open nil
)))
4600 (defun org-close-li (&optional type
)
4601 "Close <li> if necessary."
4602 (org-close-par-maybe)
4603 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4605 (defvar body-only
) ; dynamically scoped into this.
4606 (defun org-html-level-start (level title umax with-toc head-count
)
4607 "Insert a new level in HTML export.
4608 When TITLE is nil, just close all open levels."
4609 (org-close-par-maybe)
4610 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
4612 (mapconcat (lambda (x)
4613 (format "<a name=\"%s\" id=\"%s\"></a>"
4615 (cdr (assoc target org-export-target-aliases
))
4620 (if (aref org-levels-open
(1- l
))
4622 (org-html-level-close l umax
)
4623 (aset org-levels-open
(1- l
) nil
)))
4626 ;; If title is nil, this means this function is called to close
4627 ;; all levels, so the rest is done only if title is given
4628 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4629 (setq title
(replace-match
4630 (if org-export-with-tags
4633 " <span class=\"tag\">"
4634 (mapconcat 'identity
(org-split-string
4635 (match-string 1 title
) ":")
4642 (if (aref org-levels-open
(1- level
))
4646 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
4647 (insert "<li>" title
"<br/>\n")))
4648 (aset org-levels-open
(1- level
) t
)
4649 (org-close-par-maybe)
4651 (insert (format "<ul>\n<li id=\"%s\">" target
)
4652 extra-targets title
"<br/>\n")
4653 (insert "<ul>\n<li>" title
"<br/>\n"))))
4654 (aset org-levels-open
(1- level
) t
)
4655 (setq snumber
(org-section-number level
))
4656 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4657 (if (and org-export-with-section-numbers
(not body-only
))
4659 (format "<span class=\"section-number-%d\">%s</span>"
4662 (unless (= head-count
1) (insert "\n</div>\n"))
4663 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
4664 snumber level level snumber extra-targets
4665 title level level snumber
))
4668 (defun org-get-text-property-any (pos prop
&optional object
)
4669 (or (get-text-property pos prop object
)
4670 (and (setq pos
(next-single-property-change pos prop object
))
4671 (get-text-property pos prop object
))))
4673 (defun org-html-level-close (level max-outline-level
)
4674 "Terminate one level in HTML export."
4675 (if (<= level max-outline-level
)
4678 (insert "</ul>\n")))
4680 ;;; iCalendar export
4683 (defun org-export-icalendar-this-file ()
4684 "Export current file as an iCalendar file.
4685 The iCalendar file will be located in the same directory as the Org-mode
4686 file, but with extension `.ics'."
4688 (org-export-icalendar nil buffer-file-name
))
4691 (defun org-export-icalendar-all-agenda-files ()
4692 "Export all files in `org-agenda-files' to iCalendar .ics files.
4693 Each iCalendar file will be located in the same directory as the Org-mode
4694 file, but with extension `.ics'."
4696 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4699 (defun org-export-icalendar-combine-agenda-files ()
4700 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4701 The file is stored under the name `org-combined-agenda-icalendar-file'."
4703 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4705 (defun org-export-icalendar (combine &rest files
)
4706 "Create iCalendar files for all elements of FILES.
4707 If COMBINE is non-nil, combine all calendar entries into a single large
4708 file and store it under the name `org-combined-agenda-icalendar-file'."
4710 (org-prepare-agenda-buffers files
)
4711 (let* ((dir (org-export-directory
4712 :ical
(list :publishing-directory
4713 org-export-publishing-directory
)))
4714 file ical-file ical-buffer category started org-agenda-new-buffers
)
4715 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4718 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4719 org-combined-agenda-icalendar-file
4720 (expand-file-name org-combined-agenda-icalendar-file dir
))
4721 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4722 (set-buffer ical-buffer
) (erase-buffer))
4723 (while (setq file
(pop files
))
4725 (org-check-agenda-file file
)
4726 (set-buffer (org-get-agenda-file-buffer file
))
4728 (setq ical-file
(concat (file-name-as-directory dir
)
4729 (file-name-sans-extension
4730 (file-name-nondirectory buffer-file-name
))
4732 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4733 (with-current-buffer ical-buffer
(erase-buffer)))
4734 (setq category
(or org-category
4735 (file-name-sans-extension
4736 (file-name-nondirectory buffer-file-name
))))
4737 (if (symbolp category
) (setq category
(symbol-name category
)))
4738 (let ((standard-output ical-buffer
))
4740 (and (not started
) (setq started t
)
4741 (org-start-icalendar-file org-icalendar-combined-name
))
4742 (org-start-icalendar-file category
))
4743 (org-print-icalendar-entries combine
)
4744 (when (or (and combine
(not files
)) (not combine
))
4745 (org-finish-icalendar-file)
4746 (set-buffer ical-buffer
)
4747 (run-hooks 'org-before-save-iCalendar-file-hook
)
4749 (run-hooks 'org-after-save-iCalendar-file-hook
)
4750 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4752 (org-release-buffers org-agenda-new-buffers
))))
4754 (defvar org-before-save-iCalendar-file-hook nil
4755 "Hook run before an iCalendar file has been saved.
4756 This can be used to modify the result of the export.")
4758 (defvar org-after-save-iCalendar-file-hook nil
4759 "Hook run after an iCalendar file has been saved.
4760 The iCalendar buffer is still current when this hook is run.
4761 A good way to use this is to tell a desktop calendar application to re-read
4762 the iCalendar file.")
4764 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4765 (defun org-print-icalendar-entries (&optional combine
)
4766 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4767 When COMBINE is non nil, add the category to each line."
4768 (require 'org-agenda
)
4769 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4770 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4771 (dts (org-ical-ts-to-string
4772 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4774 hd ts ts2 state status
(inc t
) pos b sexp rrule
4775 scheduledp deadlinep todo prefix due start
4776 tmp pri categories location summary desc uid
4777 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4778 (org-refresh-category-properties)
4780 (goto-char (point-min))
4781 (while (re-search-forward re1 nil t
)
4784 (when (boundp 'org-icalendar-verify-function
)
4785 (unless (funcall org-icalendar-verify-function
)
4786 (outline-next-heading)
4789 (setq pos
(match-beginning 0)
4792 hd
(condition-case nil
4793 (org-icalendar-cleanup-string
4795 (error (throw :skip nil
)))
4796 summary
(org-icalendar-cleanup-string
4797 (org-entry-get nil
"SUMMARY"))
4798 desc
(org-icalendar-cleanup-string
4799 (or (org-entry-get nil
"DESCRIPTION")
4800 (and org-icalendar-include-body
(org-get-entry)))
4801 t org-icalendar-include-body
)
4802 location
(org-icalendar-cleanup-string
4803 (org-entry-get nil
"LOCATION" 'selective
))
4804 uid
(if org-icalendar-store-UID
4806 (or (org-id-get) (org-id-new)))
4807 categories
(org-export-get-categories)
4808 deadlinep nil scheduledp nil
)
4809 (if (looking-at re2
)
4811 (goto-char (match-end 0))
4812 (setq ts2
(match-string 1)
4813 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4814 (setq tmp
(buffer-substring (max (point-min)
4815 (- pos org-ds-keyword-length
))
4817 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4820 (replace-match "\\1" t nil ts
))
4822 deadlinep
(string-match org-deadline-regexp tmp
)
4823 scheduledp
(string-match org-scheduled-regexp tmp
)
4824 todo
(org-get-todo-state)
4825 ;; donep (org-entry-is-done-p)
4830 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4831 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4836 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4837 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4839 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4840 (if (or (string-match org-tr-regexp hd
)
4841 (string-match org-ts-regexp hd
))
4842 (setq hd
(replace-match "" t t hd
)))
4843 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4845 (concat "\nRRULE:FREQ="
4848 '(("d" .
"DAILY")("w" .
"WEEKLY")
4849 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4850 ";INTERVAL=" (match-string 1 ts
)))
4852 (setq summary
(or summary hd
))
4853 (if (string-match org-bracket-link-regexp summary
)
4855 (replace-match (if (match-end 3)
4856 (match-string 3 summary
)
4857 (match-string 1 summary
))
4859 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4860 (if scheduledp
(setq summary
(concat "S: " summary
)))
4861 (if (string-match "\\`<%%" ts
)
4862 (with-current-buffer sexp-buffer
4863 (insert (substring ts
1 -
1) " " summary
"\n"))
4864 (princ (format "BEGIN:VEVENT
4872 (org-ical-ts-to-string ts
"DTSTART")
4873 (org-ical-ts-to-string ts2
"DTEND" inc
)
4875 (if (and desc
(string-match "\\S-" desc
))
4876 (concat "\nDESCRIPTION: " desc
) "")
4877 (if (and location
(string-match "\\S-" location
))
4878 (concat "\nLOCATION: " location
) "")
4880 (when (and org-icalendar-include-sexps
4881 (condition-case nil
(require 'icalendar
) (error nil
))
4882 (fboundp 'icalendar-export-region
))
4883 ;; Get all the literal sexps
4884 (goto-char (point-min))
4885 (while (re-search-forward "^&?%%(" nil t
)
4888 (setq b
(match-beginning 0))
4889 (goto-char (1- (match-end 0)))
4892 (setq sexp
(buffer-substring b
(point)))
4893 (with-current-buffer sexp-buffer
4894 (insert sexp
"\n"))))
4895 (princ (org-diary-to-ical-string sexp-buffer
))
4896 (kill-buffer sexp-buffer
))
4898 (when org-icalendar-include-todo
4899 (setq prefix
"TODO-")
4900 (goto-char (point-min))
4901 (while (re-search-forward org-todo-line-regexp nil t
)
4904 (when (boundp 'org-icalendar-verify-function
)
4905 (unless (funcall org-icalendar-verify-function
)
4906 (outline-next-heading)
4909 (setq state
(match-string 2))
4910 (setq status
(if (member state org-done-keywords
)
4911 "COMPLETED" "NEEDS-ACTION"))
4913 (or (not (member state org-done-keywords
))
4914 (eq org-icalendar-include-todo
'all
))
4915 (not (member org-archive-tag
(org-get-tags-at)))
4917 (setq hd
(match-string 3)
4918 summary
(org-icalendar-cleanup-string
4919 (org-entry-get nil
"SUMMARY"))
4920 desc
(org-icalendar-cleanup-string
4921 (or (org-entry-get nil
"DESCRIPTION")
4922 (and org-icalendar-include-body
(org-get-entry)))
4923 t org-icalendar-include-body
)
4924 location
(org-icalendar-cleanup-string
4925 (org-entry-get nil
"LOCATION" 'selective
))
4926 due
(and (member 'todo-due org-icalendar-use-deadline
)
4927 (org-entry-get nil
"DEADLINE"))
4928 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4929 (org-entry-get nil
"SCHEDULED"))
4930 categories
(org-export-get-categories)
4931 uid
(if org-icalendar-store-UID
4933 (or (org-id-get) (org-id-new))))
4934 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4935 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4937 (if (string-match org-bracket-link-regexp hd
)
4938 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4939 (match-string 1 hd
))
4941 (if (string-match org-priority-regexp hd
)
4942 (setq pri
(string-to-char (match-string 2 hd
))
4943 hd
(concat (substring hd
0 (match-beginning 1))
4944 (substring hd
(match-end 1))))
4945 (setq pri org-default-priority
))
4946 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4947 (- org-lowest-priority org-highest-priority
))))))
4949 (princ (format "BEGIN:VTODO
4961 (if (and location
(string-match "\\S-" location
))
4962 (concat "\nLOCATION: " location
) "")
4963 (if (and desc
(string-match "\\S-" desc
))
4964 (concat "\nDESCRIPTION: " desc
) "")
4965 (if due
(concat "\n" due
) "")
4969 (defun org-export-get-categories ()
4970 "Get categories according to `org-icalendar-categories'."
4971 (let ((cs org-icalendar-categories
) c rtn tmp
)
4972 (while (setq c
(pop cs
))
4974 ((eq c
'category
) (push (org-get-category) rtn
))
4976 (setq tmp
(org-get-todo-state))
4977 (and tmp
(push tmp rtn
)))
4979 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4981 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4982 (mapconcat 'identity
(nreverse rtn
) ",")))
4984 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4985 "Take out stuff and quote what needs to be quoted.
4986 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4987 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4992 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4993 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4994 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4995 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4997 (while (string-match "\\([,;]\\)" s start
)
4998 (setq start
(+ (match-beginning 0) 2)
4999 s
(replace-match "\\\\\\1" nil nil s
))))
5000 (setq s
(org-trim s
))
5002 (while (string-match "[ \t]*\n[ \t]*" s
)
5003 (setq s
(replace-match "\\n" t t s
))))
5006 (if (and (numberp maxlength
)
5007 (> (length s
) maxlength
))
5008 (setq s
(substring s
0 maxlength
)))))
5011 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength
)
5012 "Take out stuff and quote what needs to be quoted.
5013 When IS-BODY is non-nil, assume that this is the body of an item, clean up
5014 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
5016 This seems to be more like RFC 2455, but it causes problems, so it is
5017 not used right now."
5021 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
5022 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
5023 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
5024 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))
5025 (setq s
(org-trim s
))
5026 (while (string-match "[ \t]*\n[ \t]*" s
)
5027 (setq s
(replace-match "\\n" t t s
)))
5029 (if (and (numberp maxlength
)
5030 (> (length s
) maxlength
))
5031 (setq s
(substring s
0 maxlength
)))))
5032 (setq s
(org-trim s
)))
5033 (while (string-match "\"" s
) (setq s
(replace-match "''" t t s
)))
5034 (when (string-match "[;,:]" s
) (setq s
(concat "\"" s
"\"")))
5037 (defun org-get-entry ()
5038 "Clean-up description string."
5040 (org-back-to-heading t
)
5041 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
5043 (defun org-start-icalendar-file (name)
5044 "Start an iCalendar file by inserting the header."
5045 (let ((user user-full-name
)
5046 (name (or name
"unknown"))
5047 (timezone (cadr (current-time-zone))))
5049 (format "BEGIN:VCALENDAR
5052 PRODID:-//%s//Emacs with Org-mode//EN
5054 CALSCALE:GREGORIAN\n" name user timezone
))))
5056 (defun org-finish-icalendar-file ()
5057 "Finish an iCalendar file by inserting the END statement."
5058 (princ "END:VCALENDAR\n"))
5060 (defun org-ical-ts-to-string (s keyword
&optional inc
)
5061 "Take a time string S and convert it to iCalendar format.
5062 KEYWORD is added in front, to make a complete line like DTSTART....
5063 When INC is non-nil, increase the hour by two (if time string contains
5064 a time), or the day by one (if it does not contain a time)."
5065 (let ((t1 (org-parse-time-string s
'nodefault
))
5066 t2 fmt have-time time
)
5067 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
5068 (setq t2 t1 have-time t
)
5069 (setq t2
(org-parse-time-string s
)))
5070 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
5071 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
5074 (if org-agenda-default-appointment-duration
5075 (setq mi
(+ org-agenda-default-appointment-duration mi
))
5078 (setq time
(encode-time s mi h d m y
)))
5079 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
5080 (concat keyword
(format-time-string fmt time
))))
5084 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
5085 (with-current-buffer buffer
5086 (apply 'insert output
)))
5087 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
5090 (defun org-export-as-xoxo (&optional buffer
)
5091 "Export the org buffer as XOXO.
5092 The XOXO buffer is named *xoxo-<source buffer name>*"
5093 (interactive (list (current-buffer)))
5094 ;; A quickie abstraction
5096 ;; Output everything as XOXO
5097 (with-current-buffer (get-buffer buffer
)
5098 (let* ((pos (point))
5099 (opt-plist (org-combine-plists (org-default-export-plist)
5100 (org-infile-export-plist)))
5101 (filename (concat (file-name-as-directory
5102 (org-export-directory :xoxo opt-plist
))
5103 (file-name-sans-extension
5104 (file-name-nondirectory buffer-file-name
))
5106 (out (find-file-noselect filename
))
5109 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
5110 ;; Check the output buffer is empty.
5111 (with-current-buffer out
(erase-buffer))
5112 ;; Kick off the output
5113 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
5114 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
5115 (let* ((hd (match-string-no-properties 1))
5118 (match-string-no-properties 2)
5120 (goto-char (match-end 0))
5125 (if (looking-at "^[ \t]\\(.*\\)")
5126 (setq str
(concat str
(match-string-no-properties 1)))
5127 (throw 'loop str
)))))))))
5129 ;; Handle level rendering
5131 ((> level last-level
)
5132 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
5134 ((< level last-level
)
5135 (dotimes (- (- last-level level
) 1)
5137 (org-export-as-xoxo-insert-into out
"</li>\n"))
5138 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5140 (org-export-as-xoxo-insert-into out
"</li>\n")
5141 (setq hanging-li nil
)))
5143 ((equal level last-level
)
5145 (org-export-as-xoxo-insert-into out
"</li>\n")))
5148 (setq last-level level
)
5150 ;; And output the new li
5151 (setq hanging-li
't
)
5152 (if (equal ?
+ (elt text
0))
5153 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
5154 (org-export-as-xoxo-insert-into out
"<li>" text
))))
5156 ;; Finally finish off the ol
5157 (dotimes (- last-level
1)
5159 (org-export-as-xoxo-insert-into out
"</li>\n"))
5160 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5163 ;; Finish the buffer off and clean it up.
5164 (switch-to-buffer-other-window out
)
5165 (indent-region (point-min) (point-max) nil
)
5167 (goto-char (point-min))
5172 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
5174 ;;; org-exp.el ends here