1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (declare-function org-export-latex-preprocess
"org-export-latex" ())
34 (declare-function org-agenda-skip
"org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
36 (declare-function htmlize-region
"ext:htmlize" (beg end
))
37 (defvar htmlize-buffer-places
) ; from htmlize.el
39 (defgroup org-export nil
40 "Options for exporting org-listings."
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag
"Org Export General"
50 (defvar org-export-publishing-directory nil
)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group
'org-export-general
68 (defcustom org-export-select-tags
'("export")
69 "Tags that select a tree for export.
70 If any such tag is found in a buffer, all trees that do not carry one
71 of these tags will be deleted before export.
72 Inside trees that are selected like this, you can still deselect a
73 subtree by tagging it with one of the `org-export-exclude-tags'."
74 :group
'org-export-general
75 :type
'(repeat (string :tag
"Tag")))
77 (defcustom org-export-exclude-tags
'("noexport")
78 "Tags that exclude a tree from export.
79 All trees carrying any of these tags will be excluded from export.
80 This is without condition, so even subtrees inside that carry one of the
81 `org-export-select-tags' will be removed."
82 :group
'org-export-general
83 :type
'(repeat (string :tag
"Tag")))
85 (defcustom org-export-with-special-strings t
86 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
87 When this option is turned on, these strings will be exported as:
90 -----+----------+--------
96 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
97 :group
'org-export-translation
100 (defcustom org-export-language-setup
101 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
102 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
103 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
104 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
105 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
106 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
107 ("es" "Autor" "Fecha" "Índice" "Pies de página")
108 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
109 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
110 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
111 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
112 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
113 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
114 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
115 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
116 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
117 ("pl" "Autor" "Data" "Spis treści" "Przypis")
118 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
119 "Terms used in export text, translated to different languages.
120 Use the variable `org-export-default-language' to set the language,
121 or use the +OPTION lines for a per-file setting."
122 :group
'org-export-general
125 (string :tag
"HTML language tag")
126 (string :tag
"Author")
128 (string :tag
"Table of Contents")
129 (string :tag
"Footnotes"))))
131 (defcustom org-export-default-language
"en"
132 "The default language of HTML export, as a string.
133 This should have an association in `org-export-language-setup'."
134 :group
'org-export-general
137 (defcustom org-export-skip-text-before-1st-heading nil
138 "Non-nil means, skip all text before the first headline when exporting.
139 When nil, that text is exported as well."
140 :group
'org-export-general
143 (defcustom org-export-headline-levels
3
144 "The last level which is still exported as a headline.
145 Inferior levels will produce itemize lists when exported.
146 Note that a numeric prefix argument to an exporter function overrides
149 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
150 :group
'org-export-general
153 (defcustom org-export-with-section-numbers t
154 "Non-nil means, add section numbers to headlines when exporting.
156 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
157 :group
'org-export-general
160 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
161 "Format of section numbers for export.
162 The variable has two components.
163 1. A list of lists, each indicating a counter type and a separator.
164 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
165 It causes causes numeric, alphabetic, or roman counters, respectively.
166 The separator is only used if another counter for a subsection is being
168 If there are more numbered section levels than entries in this lists,
169 then the last entry will be reused.
170 2. A terminator string that will be added after the entire
172 :group
'org-export-general
176 (string :tag
"Counter Type")
177 (string :tag
"Separator ")))
178 (string :tag
"Terminator")))
180 (defcustom org-export-with-toc t
181 "Non-nil means, create a table of contents in exported files.
182 The TOC contains headlines with levels up to`org-export-headline-levels'.
183 When an integer, include levels up to N in the toc, this may then be
184 different from `org-export-headline-levels', but it will not be allowed
185 to be larger than the number of headline levels.
186 When nil, no table of contents is made.
188 Headlines which contain any TODO items will be marked with \"(*)\" in
189 ASCII export, and with red color in HTML output, if the option
190 `org-export-mark-todo-in-toc' is set.
192 In HTML output, the TOC will be clickable.
194 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
196 :group
'org-export-general
198 (const :tag
"No Table of Contents" nil
)
199 (const :tag
"Full Table of Contents" t
)
200 (integer :tag
"TOC to level")))
202 (defcustom org-export-mark-todo-in-toc nil
203 "Non-nil means, mark TOC lines that contain any open TODO items."
204 :group
'org-export-general
207 (defcustom org-export-with-todo-keywords t
208 "Non-nil means, include TODO keywords in export.
209 When nil, remove all these keywords from the export."
210 :group
'org-export-general
213 (defcustom org-export-with-priority nil
214 "Non-nil means, include priority cookies in export.
215 When nil, remove priority cookies for export."
216 :group
'org-export-general
219 (defcustom org-export-preserve-breaks nil
220 "Non-nil means, preserve all line breaks when exporting.
221 Normally, in HTML output paragraphs will be reformatted. In ASCII
222 export, line breaks will always be preserved, regardless of this variable.
224 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
225 :group
'org-export-general
228 (defcustom org-export-with-archived-trees
'headline
229 "Whether subtrees with the ARCHIVE tag should be exported.
230 This can have three different values
231 nil Do not export, pretend this tree is not present
232 t Do export the entire tree
233 headline Only export the headline, but skip the tree below it."
234 :group
'org-export-general
237 (const :tag
"not at all" nil
)
238 (const :tag
"headline only" 'headline
)
239 (const :tag
"entirely" t
)))
241 (defcustom org-export-author-info t
242 "Non-nil means, insert author name and email into the exported file.
244 This option can also be set with the +OPTIONS line,
245 e.g. \"author-info:nil\"."
246 :group
'org-export-general
249 (defcustom org-export-creator-info t
250 "Non-nil means, the postamble should contain a creator sentence.
251 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
252 :group
'org-export-general
255 (defcustom org-export-time-stamp-file t
256 "Non-nil means, insert a time stamp into the exported file.
257 The time stamp shows when the file was created.
259 This option can also be set with the +OPTIONS line,
260 e.g. \"timestamp:nil\"."
261 :group
'org-export-general
264 (defcustom org-export-with-timestamps t
265 "If nil, do not export time stamps and associated keywords."
266 :group
'org-export-general
269 (defcustom org-export-remove-timestamps-from-toc t
270 "If nil, remove timestamps from the table of contents entries."
271 :group
'org-export-general
274 (defcustom org-export-with-tags
'not-in-toc
275 "If nil, do not export tags, just remove them from headlines.
276 If this is the symbol `not-in-toc', tags will be removed from table of
277 contents entries, but still be shown in the headlines of the document.
279 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
280 :group
'org-export-general
282 (const :tag
"Off" nil
)
283 (const :tag
"Not in TOC" not-in-toc
)
284 (const :tag
"On" t
)))
286 (defcustom org-export-with-drawers nil
287 "Non-nil means, export with drawers like the property drawer.
288 When t, all drawers are exported. This may also be a list of
289 drawer names to export."
290 :group
'org-export-general
292 (const :tag
"All drawers" t
)
293 (const :tag
"None" nil
)
294 (repeat :tag
"Selected drawers"
295 (string :tag
"Drawer name"))))
297 (defvar org-export-preprocess-hook nil
298 "Hook for preprocessing an export buffer.
299 Pretty much the first thing when exporting is running this hook.")
301 (defvar org-export-preprocess-after-include-files-hook nil
302 "Hook for preprocessing an export buffer.
303 This is run after the contents of included files have been inserted.")
305 (defvar org-export-preprocess-after-tree-selection-hook nil
306 "Hook for preprocessing an export buffer.
307 This is run after selection of trees to be exported has happened.
308 This selection includes tags-based selection, as well as removal
309 of commented and archived trees.")
311 (defvar org-export-preprocess-before-backend-specifics-hook nil
312 "Hook run before backend-specific functions are called during preprocessing.")
314 (defvar org-export-preprocess-final-hook nil
315 "Hook for preprocessing an export buffer.
316 This is run as the last thing in the preprocessing buffer, just before
317 returning the buffer string to the backend.")
319 (defgroup org-export-translation nil
320 "Options for translating special ascii sequences for the export backends."
321 :tag
"Org Export Translation"
324 (defcustom org-export-with-emphasize t
325 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
326 If the export target supports emphasizing text, the word will be
327 typeset in bold, italic, or underlined, respectively. Works only for
328 single words, but you can say: I *really* *mean* *this*.
329 Not all export backends support this.
331 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
332 :group
'org-export-translation
335 (defcustom org-export-with-footnotes t
336 "If nil, export [1] as a footnote marker.
337 Lines starting with [1] will be formatted as footnotes.
339 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
340 :group
'org-export-translation
343 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
344 <h2 class=\"footnotes\">%s: </h2>
345 <div id=\"footnotes-text\">
349 "Format for the footnotes section.
350 Should contain a two instances of %s. The first will be replaced with the
351 language-specific word for \"Footnotes\", the second one will be replaced
352 by the footnotes themselves."
353 :group
'org-export-html
356 (defcustom org-export-with-sub-superscripts t
357 "Non-nil means, interpret \"_\" and \"^\" for export.
358 When this option is turned on, you can use TeX-like syntax for sub- and
359 superscripts. Several characters after \"_\" or \"^\" will be
360 considered as a single item - so grouping with {} is normally not
361 needed. For example, the following things will be parsed as single
362 sub- or superscripts.
364 10^24 or 10^tau several digits will be considered 1 item.
365 10^-12 or 10^-tau a leading sign with digits or a word
366 x^2-y^3 will be read as x^2 - y^3, because items are
367 terminated by almost any nonword/nondigit char.
368 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
370 Still, ambiguity is possible - so when in doubt use {} to enclose the
371 sub/superscript. If you set this variable to the symbol `{}',
372 the braces are *required* in order to trigger interpretations as
373 sub/superscript. This can be helpful in documents that need \"_\"
374 frequently in plain text.
376 Not all export backends support this, but HTML does.
378 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
379 :group
'org-export-translation
381 (const :tag
"Always interpret" t
)
382 (const :tag
"Only with braces" {})
383 (const :tag
"Never interpret" nil
)))
385 (defcustom org-export-with-special-strings t
386 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
387 When this option is turned on, these strings will be exported as:
393 Not all export backends support this, but HTML does.
395 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
396 :group
'org-export-translation
399 (defcustom org-export-with-TeX-macros t
400 "Non-nil means, interpret simple TeX-like macros when exporting.
401 For example, HTML export converts \\alpha to α and \\AA to Å.
402 Not only real TeX macros will work here, but the standard HTML entities
403 for math can be used as macro names as well. For a list of supported
404 names in HTML export, see the constant `org-html-entities'.
405 Not all export backends support this.
407 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
408 :group
'org-export-translation
409 :group
'org-export-latex
412 (defcustom org-export-with-LaTeX-fragments nil
413 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
414 When set, the exporter will find LaTeX environments if the \\begin line is
415 the first non-white thing on a line. It will also find the math delimiters
416 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
419 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
420 :group
'org-export-translation
421 :group
'org-export-latex
424 (defcustom org-export-with-fixed-width t
425 "Non-nil means, lines starting with \":\" will be in fixed width font.
426 This can be used to have pre-formatted text, fragments of code etc. For
428 : ;; Some Lisp examples
431 will be looking just like this in also HTML. See also the QUOTE keyword.
432 Not all export backends support this.
434 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
435 :group
'org-export-translation
438 (defcustom org-match-sexp-depth
3
439 "Number of stacked braces for sub/superscript matching.
440 This has to be set before loading org.el to be effective."
441 :group
'org-export-translation
444 (defgroup org-export-tables nil
445 "Options for exporting tables in Org-mode."
446 :tag
"Org Export Tables"
449 (defcustom org-export-with-tables t
450 "If non-nil, lines starting with \"|\" define a table.
453 | Name | Address | Birthday |
454 |-------------+----------+-----------|
455 | Arthur Dent | England | 29.2.2100 |
457 Not all export backends support this.
459 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
460 :group
'org-export-tables
463 (defcustom org-export-highlight-first-table-line t
464 "Non-nil means, highlight the first table line.
465 In HTML export, this means use <th> instead of <td>.
466 In tables created with table.el, this applies to the first table line.
467 In Org-mode tables, all lines before the first horizontal separator
468 line will be formatted with <th> tags."
469 :group
'org-export-tables
472 (defcustom org-export-table-remove-special-lines t
473 "Remove special lines and marking characters in calculating tables.
474 This removes the special marking character column from tables that are set
475 up for spreadsheet calculations. It also removes the entire lines
476 marked with `!', `_', or `^'. The lines with `$' are kept, because
477 the values of constants may be useful to have."
478 :group
'org-export-tables
481 (defcustom org-export-prefer-native-exporter-for-tables nil
482 "Non-nil means, always export tables created with table.el natively.
483 Natively means, use the HTML code generator in table.el.
484 When nil, Org-mode's own HTML generator is used when possible (i.e. if
485 the table does not use row- or column-spanning). This has the
486 advantage, that the automatic HTML conversions for math symbols and
487 sub/superscripts can be applied. Org-mode's HTML generator is also
489 :group
'org-export-tables
492 (defgroup org-export-ascii nil
493 "Options specific for ASCII export of Org-mode files."
494 :tag
"Org Export ASCII"
497 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
498 "Characters for underlining headings in ASCII export.
499 In the given sequence, these characters will be used for level 1, 2, ..."
500 :group
'org-export-ascii
501 :type
'(repeat character
))
503 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
504 "Bullet characters for headlines converted to lists in ASCII export.
505 The first character is used for the first lest level generated in this
506 way, and so on. If there are more levels than characters given here,
507 the list will be repeated.
508 Note that plain lists will keep the same bullets as the have in the
510 :group
'org-export-ascii
511 :type
'(repeat character
))
513 (defgroup org-export-xml nil
514 "Options specific for XML export of Org-mode files."
515 :tag
"Org Export XML"
518 (defgroup org-export-html nil
519 "Options specific for HTML export of Org-mode files."
520 :tag
"Org Export HTML"
523 (defcustom org-export-html-coding-system nil
524 "Coding system for HTML export, defaults to buffer-file-coding-system."
525 :group
'org-export-html
526 :type
'coding-system
)
528 (defcustom org-export-html-extension
"html"
529 "The extension for exported HTML files."
530 :group
'org-export-html
533 (defcustom org-export-html-link-up
""
534 "Where should the \"UP\" link of exported HTML pages lead?"
535 :group
'org-export-html
536 :type
'(string :tag
"File or URL"))
538 (defcustom org-export-html-link-home
""
539 "Where should the \"HOME\" link of exported HTML pages lead?"
540 :group
'org-export-html
541 :type
'(string :tag
"File or URL"))
543 (defconst org-export-html-scripts
544 "<script language=\"javascript\" type=\"text/javascript\">
545 <!--/*--><![CDATA[/*><!--*/
546 function CodeHighlightOn(elem, id)
548 var target = document.getElementById(id);
550 elem.cacheClassElem = elem.className;
551 elem.cacheClassTarget = target.className;
552 target.className = \"code-highlighted\";
553 elem.className = \"code-highlighted\";
556 function CodeHighlightOff(elem, id)
558 var target = document.getElementById(id);
559 if(elem.cacheClassElem)
560 elem.className = elem.cacheClassElem;
561 if(elem.cacheClassTarget)
562 target.className = elem.cacheClassTarget;
566 "Basic javascript that is needed by HTML files produced by Org-mode.")
568 (defconst org-export-html-style-default
569 "<style type=\"text/css\">
570 <!--/*--><![CDATA[/*><!--*/
571 html { font-family: Times, serif; font-size: 12pt; }
572 .title { text-align: center; }
573 .todo { color: red; }
574 .done { color: green; }
575 .tag { background-color:lightblue; font-weight:normal }
577 .timestamp { color: grey }
578 .timestamp-kwd { color: CadetBlue }
579 p.verse { margin-left: 3% }
581 border: 1pt solid #AEBDCC;
582 background-color: #F3F5F7;
584 font-family: courier, monospace;
588 table { border-collapse: collapse; }
589 td, th { vertical-align: top; }
590 dt { font-weight: bold; }
591 div.figure { padding: 0.5em; }
592 div.figure p { text-align: center; }
593 .linenr { font-size:smaller }
594 .code-highlighted {background-color:#ffff00;}
595 .org-info-js_info-navigation { border-style:none; }
596 #org-info-js_console-label { font-size:10px; font-weight:bold;
597 white-space:nowrap; }
598 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
602 "The default style specification for exported HTML files.
603 Please use the variables `org-export-html-style' and
604 `org-export-html-style-extra' to add to this style. If you wish to not
605 have the default style included, customize the variable
606 `org-export-html-style-include-default'.")
608 (defcustom org-export-html-style-include-default t
609 "Non-nil means, include the default style in exported HTML files.
610 The actual style is defined in `org-export-html-style-default' and should
611 not be modified. Use the variables `org-export-html-style' to add
612 your own style information."
613 :group
'org-export-html
616 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
618 (defcustom org-export-html-style
""
619 "Org-wide style definitions for exported HTML files.
621 This variable needs to contain the full HTML structure to provide a style,
622 including the surrounding HTML tags. If you set the value of this variable,
623 you should consider to include definitions for the following classes:
624 title, todo, done, timestamp, timestamp-kwd, tag, target.
626 For example, a valid value would be:
628 <style type=\"text/css\">
630 p { font-weight: normal; color: gray; }
632 .title { text-align: center; }
633 .todo, .timestamp-kwd { color: red; }
634 .done { color: green; }
638 If you'd like to refer to en external style file, use something like
640 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
642 As the value of this option simply gets inserted into the HTML <head> header,
643 you can \"misuse\" it to add arbitrary text to the header.
644 See also the variable `org-export-html-style-extra'."
645 :group
'org-export-html
648 (put 'org-export-html-style
'safe-local-variable
'stringp
)
650 (defcustom org-export-html-style-extra
""
651 "Additional style information for HTML export.
652 The value of this variable is inserted into the HTML buffer right after
653 the value of `org-export-html-style'. Use this variable for per-file
654 settings of style information, and do not forget to surround the style
655 settings with <style>...</style> tags."
656 :group
'org-export-html
659 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
662 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
663 "Format for typesetting the document title in HTML export."
664 :group
'org-export-html
667 (defcustom org-export-html-toplevel-hlevel
2
668 "The <H> level for level 1 headings in HTML export."
669 :group
'org-export-html
672 (defcustom org-export-html-link-org-files-as-html t
673 "Non-nil means, make file links to `file.org' point to `file.html'.
674 When org-mode is exporting an org-mode file to HTML, links to
675 non-html files are directly put into a href tag in HTML.
676 However, links to other Org-mode files (recognized by the
677 extension `.org.) should become links to the corresponding html
678 file, assuming that the linked org-mode file will also be
680 When nil, the links still point to the plain `.org' file."
681 :group
'org-export-html
684 (defcustom org-export-html-inline-images
'maybe
685 "Non-nil means, inline images into exported HTML pages.
686 This is done using an <img> tag. When nil, an anchor with href is used to
687 link to the image. If this option is `maybe', then images in links with
688 an empty description will be inlined, while images with a description will
690 :group
'org-export-html
691 :type
'(choice (const :tag
"Never" nil
)
692 (const :tag
"Always" t
)
693 (const :tag
"When there is no description" maybe
)))
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 js-up js-main js-css js-opt 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
) a
)
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
)))
1131 (save-window-excursion
1132 (delete-other-windows)
1133 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1135 (org-fit-window-to-buffer (get-buffer-window
1136 "*Org Export/Publishing Help*"))
1137 (message "Select command: ")
1138 (setq r1
(read-char-exclusive)))
1139 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1140 (unless (setq ass
(assq r2 cmds
))
1141 (error "No command associated with key %c" r1
))
1142 (if (and bg
(nth 2 ass
)
1143 (not (buffer-base-buffer))
1144 (not (org-region-active-p)))
1145 ;; execute in background
1146 (let ((p (start-process
1147 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1149 (expand-file-name invocation-name invocation-directory
)
1152 "--eval" "(require 'org-exp)"
1153 "--eval" "(setq org-wait .2)"
1155 "-f" (symbol-name (nth 1 ass
)))))
1156 (set-process-sentinel p
'org-export-process-sentinel
)
1157 (message "Background process \"%s\": started" p
))
1158 ;; background processing not requested, or not possible
1159 (call-interactively (nth 1 ass
)))))
1161 (defun org-export-process-sentinel (process status
)
1162 (if (string-match "\n+\\'" status
)
1163 (setq status
(substring status
0 -
1)))
1164 (message "Background process \"%s\": %s" process status
))
1166 (defconst org-html-entities
1207 ("Aring") ("AA".
"Å")
1296 ("varepsilon".
"ε")
1309 ("sigmaf") ("varsigma".
"ς")
1317 ("thetasym") ("vartheta".
"ϑ")
1320 ("bull") ("bullet".
"•")
1321 ("hellip") ("dots".
"…")
1331 ("larr") ("leftarrow".
"←") ("gets".
"←")
1332 ("uarr") ("uparrow".
"↑")
1333 ("rarr") ("to".
"→") ("rightarrow".
"→")
1334 ("darr")("downarrow".
"↓")
1335 ("harr") ("leftrightarrow".
"↔")
1336 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1337 ("lArr") ("Leftarrow".
"⇐")
1338 ("uArr") ("Uparrow".
"⇑")
1339 ("rArr") ("Rightarrow".
"⇒")
1340 ("dArr") ("Downarrow".
"⇓")
1341 ("hArr") ("Leftrightarrow".
"⇔")
1343 ("part") ("partial".
"∂")
1344 ("exist") ("exists".
"∃")
1345 ("empty") ("emptyset".
"∅")
1347 ("isin") ("in".
"∈")
1353 ("lowast") ("ast".
"∗")
1355 ("prop") ("proptp".
"∝")
1356 ("infin") ("infty".
"∞")
1357 ("ang") ("angle".
"∠")
1358 ("and") ("wedge".
"∧")
1359 ("or") ("vee".
"∨")
1365 ("cong") ("simeq".
"≅")
1366 ("asymp")("approx".
"≈")
1367 ("ne") ("neq".
"≠")
1371 ("sub") ("subset".
"⊂")
1372 ("sup") ("supset".
"⊃")
1379 ("sdot") ("cdot".
"⋅")
1386 ("loz") ("Diamond".
"◊")
1387 ("spades") ("spadesuit".
"♠")
1388 ("clubs") ("clubsuit".
"♣")
1389 ("hearts") ("diamondsuit".
"♥")
1390 ("diams") ("diamondsuit".
"♦")
1391 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1458 "Entities for TeX->HTML translation.
1459 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1460 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1461 In that case, \"\\ent\" will be translated to \"&other;\".
1462 The list contains HTML entities for Latin-1, Greek and other symbols.
1463 It is supplemented by a number of commonly used TeX macros with appropriate
1464 translations. There is currently no way for users to extend this.")
1466 ;;; General functions for all backends
1468 (defvar org-export-target-aliases nil
1469 "Alist of targets with invisible aliases.")
1470 (defvar org-export-code-refs nil
1471 "Alist of code references and line numbers")
1473 (defun org-export-preprocess-string (string &rest parameters
)
1474 "Cleanup STRING so that that the true exported has a more consistent source.
1475 This function takes STRING, which should be a buffer-string of an org-file
1476 to export. It then creates a temporary buffer where it does its job.
1477 The result is then again returned as a string, and the exporter works
1478 on this string to produce the exported version."
1480 (let* ((htmlp (plist-get parameters
:for-html
))
1481 (asciip (plist-get parameters
:for-ascii
))
1482 (latexp (plist-get parameters
:for-LaTeX
))
1483 (backend (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1485 (archived-trees (plist-get parameters
:archived-trees
))
1486 (inhibit-read-only t
)
1487 (drawers org-drawers
)
1488 (outline-regexp "\\*+ ")
1491 (setq org-export-target-aliases nil
)
1492 (setq org-export-code-refs nil
)
1494 (with-current-buffer (get-buffer-create " org-mode-tmp")
1497 (setq case-fold-search t
)
1499 ;; Remove license-to-kill stuff
1500 ;; The caller marks some stuff for killing, stuff that has been
1501 ;; used to create the page title, for example.
1502 (org-export-kill-licensed-text)
1504 (let ((org-inhibit-startup t
)) (org-mode))
1505 (setq case-fold-search t
)
1508 (run-hooks 'org-export-preprocess-hook
)
1510 (untabify (point-min) (point-max))
1512 ;; Handle include files, and call a hook
1513 (org-export-handle-include-files)
1514 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1516 ;; Get rid of archived trees
1517 (org-export-remove-archived-trees archived-trees
)
1519 ;; Remove comment environment and comment subtrees
1520 (org-export-remove-comment-blocks-and-subtrees)
1522 ;; Get rid of excluded trees, and call a hook
1523 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1524 (plist-get parameters
:exclude-tags
))
1525 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1527 ;; Handle source code snippets
1528 (org-export-replace-src-segments-and-examples backend
)
1530 ;; Protect short examples marked by a leading colon
1531 (org-export-protect-colon-examples)
1533 ;; Normalize footnotes
1534 (when (plist-get parameters
:footnotes
)
1535 (org-footnote-normalize nil t
))
1537 ;; Find all headings and compute the targets for them
1538 (setq target-alist
(org-export-define-heading-targets target-alist
))
1540 ;; Get rid of drawers
1541 (org-export-remove-or-extract-drawers drawers
1542 (plist-get parameters
:drawers
))
1544 ;; Get the correct stuff before the first headline
1545 (when (plist-get parameters
:skip-before-1st-heading
)
1546 (goto-char (point-min))
1547 (when (re-search-forward "\\(^#.*\n\\)^\\*+[ \t]" nil t
)
1548 (delete-region (point-min) (match-beginning 0))
1549 (goto-char (point-min))
1551 (when (plist-get parameters
:add-text
)
1552 (goto-char (point-min))
1553 (insert (plist-get parameters
:add-text
) "\n"))
1555 ;; Remove todo-keywords before exporting, if the user has requested so
1556 (org-export-remove-headline-metadata parameters
)
1558 ;; Find targets in comments and move them out of comments,
1559 ;; but mark them as targets that should be invisible
1560 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1562 ;; Select and protect backend specific stuff, throw away stuff
1563 ;; that is specific for other backends
1564 (org-export-select-backend-specific-text backend
)
1566 ;; Protect quoted subtrees
1567 (org-export-protect-quoted-subtrees)
1569 ;; Protect verbatim elements
1570 (org-export-protect-verbatim)
1572 ;; Blockquotes and verse
1573 (org-export-mark-blockquote-and-verse)
1575 ;; Remove timestamps, if the user has requested so
1576 (org-export-remove-clock-lines)
1577 (unless (plist-get parameters
:timestamps
)
1578 (org-export-remove-timestamps))
1580 ;; Attach captions to the correct object
1581 (setq target-alist
(org-export-attach-captions-and-attributes
1582 backend target-alist
))
1584 ;; Find matches for radio targets and turn them into internal links
1585 (org-export-mark-radio-links)
1587 ;; Find all links that contain a newline and put them into a single line
1588 (org-export-concatenate-multiline-links)
1590 ;; Normalize links: Convert angle and plain links into bracket links
1591 ;; and expand link abbreviations
1592 (org-export-normalize-links)
1594 ;; Find all internal links. If they have a fuzzy match (i.e. not
1595 ;; a *dedicated* target match, let the link point to the
1596 ;; corresponding section.
1597 (org-export-target-internal-links target-alist
)
1599 ;; Find multiline emphasis and put them into single line
1600 (when (plist-get parameters
:emph-multiline
)
1601 (org-export-concatenate-multiline-emphasis))
1603 ;; Remove special table lines
1604 (when org-export-table-remove-special-lines
1605 (org-export-remove-special-table-lines))
1608 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1610 ;; LaTeX-specific preprocessing
1612 (require 'org-export-latex nil
)
1613 (org-export-latex-preprocess))
1615 ;; ASCII-specific preprocessing
1617 (org-export-ascii-preprocess))
1619 ;; HTML-specific preprocessing
1621 (org-export-html-preprocess parameters
))
1623 ;; Remove or replace comments
1624 (org-export-handle-comments (plist-get parameters
:comments
))
1626 ;; Run the final hook
1627 (run-hooks 'org-export-preprocess-final-hook
)
1629 (setq rtn
(buffer-string)))
1630 (kill-buffer " org-mode-tmp")
1633 (defun org-export-kill-licensed-text ()
1634 "Remove all text that is marked with a :org-license-to-kill property."
1636 (while (setq p
(text-property-any (point-min) (point-max)
1637 :org-license-to-kill t
))
1639 p
(or (next-single-property-change p
:org-license-to-kill
)
1642 (defun org-export-define-heading-targets (target-alist)
1643 "Find all headings and define the targets for them.
1644 The new targets are added to TARGET-ALIST, which is also returned."
1645 (goto-char (point-min))
1646 (org-init-section-numbers)
1647 (let ((re (concat "^" org-outline-regexp
1648 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1649 level target last-section-target a
)
1650 (while (re-search-forward re nil t
)
1653 (push (cons (org-match-string-no-properties 1)
1654 target
) target-alist
)
1655 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1657 (push (list last-section-target
)
1658 org-export-target-aliases
)
1659 (car org-export-target-aliases
))))
1660 (push (caar target-alist
) (cdr a
)))
1661 (setq level
(org-reduced-level
1662 (save-excursion (goto-char (point-at-bol))
1663 (org-outline-level))))
1664 (setq target
(org-solidify-link-text
1665 (format "sec-%s" (org-section-number level
))))
1666 (setq last-section-target target
)
1667 (push (cons target target
) target-alist
)
1668 (add-text-properties
1669 (point-at-bol) (point-at-eol)
1670 (list 'target target
)))))
1673 (defun org-export-handle-invisible-targets (target-alist)
1674 "Find targets in comments and move them out of comments.
1675 Mark them as invisible targets."
1677 (goto-char (point-min))
1678 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1679 ;; Check if the line before or after is a headline with a target
1680 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1681 (get-text-property (point-at-bol 2) 'target
)))
1683 ;; use the existing target in a neighboring line
1684 (setq tmp
(match-string 2))
1686 (and (looking-at "\n") (delete-char 1))
1687 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1689 (setq a
(or (assoc target org-export-target-aliases
)
1691 (push (list target
) org-export-target-aliases
)
1692 (car org-export-target-aliases
))))
1694 ;; Make an invisible target
1695 (replace-match "\\1(INVISIBLE)"))))
1698 (defun org-export-target-internal-links (target-alist)
1699 "Find all internal links and assign targets to them.
1700 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1701 let the link point to the corresponding section.
1702 This function also handles the id links, if they have a match in
1704 (goto-char (point-min))
1705 (while (re-search-forward org-bracket-link-regexp nil t
)
1707 (let* ((md (match-data))
1708 (desc (match-end 2))
1709 (link (org-link-unescape (match-string 1)))
1710 (slink (org-solidify-link-text link
))
1711 found props pos cref
1714 ((cdr (assoc slink target-alist
)))
1715 ((and (string-match "^id:" link
)
1716 (cdr (assoc (substring link
3) target-alist
))))
1717 ((string-match "^(\\(.*\\))$" link
)
1718 (setq cref
(match-string 1 link
))
1719 (concat "coderef:" cref
))
1720 ((string-match org-link-types-re link
) nil
)
1721 ((or (file-name-absolute-p link
)
1722 (string-match "^\\." link
))
1726 (setq found
(condition-case nil
(org-link-search link
)
1729 (or (org-on-heading-p)
1730 (not (eq found
'dedicated
))))
1731 (or (get-text-property (point) 'target
)
1734 (1- (or (previous-single-property-change
1735 (point) 'target
) 0)))
1739 (goto-char (match-beginning 1))
1740 (setq props
(text-properties-at (point)))
1741 (delete-region (match-beginning 1) (match-end 1))
1744 (unless desc
(insert "][" link
))
1745 (add-text-properties pos
(point) props
))))))
1747 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1748 "Remove drawers, or extract the content.
1749 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1750 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1751 whose content to keep."
1752 (unless (eq t exp-drawers
)
1753 (goto-char (point-min))
1754 (let ((re (concat "^[ \t]*:\\("
1757 (org-delete-all exp-drawers
1758 (copy-sequence all-drawers
))
1760 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1761 (while (re-search-forward re nil t
)
1762 (replace-match "")))))
1764 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1765 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1766 Both arguments are lists of tags.
1767 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1769 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1771 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1772 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1775 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1779 (goto-char (point-min))
1780 (when (and select-tags
1782 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1783 ;; At least one tree is marked for export, this means
1784 ;; all the unmarked stuff needs to go.
1785 ;; Dig out the trees that should be exported
1786 (goto-char (point-min))
1787 (outline-next-heading)
1789 (put-text-property beg
(point-max) :org-delete t
)
1790 (while (re-search-forward re-sel nil t
)
1791 (when (org-on-heading-p)
1792 (org-back-to-heading)
1793 (remove-text-properties
1794 (max (1- (point)) (point-min))
1795 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1797 (while (and (org-up-heading-safe)
1798 (get-text-property (point) :org-delete
))
1799 (remove-text-properties (max (1- (point)) (point-min))
1800 (point-at-eol) '(:org-delete t
)))
1802 ;; Remove the trees explicitly marked for noexport
1804 (goto-char (point-min))
1805 (while (re-search-forward re-excl nil t
)
1806 (when (org-at-heading-p)
1807 (org-back-to-heading t
)
1809 (org-end-of-subtree t
)
1810 (delete-region beg
(point)))))
1811 ;; Remove everything that is now still marked for deletion
1812 (goto-char (point-min))
1813 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1814 (setq end
(or (next-single-property-change beg
:org-delete
)
1816 (delete-region beg end
))))
1818 (defun org-export-remove-archived-trees (export-archived-trees)
1819 "Remove archived trees.
1820 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1821 When it is t, the entire archived tree will be exported.
1822 When it is nil the entire tree including the headline will be removed
1824 (let ((re-archive (concat ":" org-archive-tag
":"))
1826 (when (not (eq export-archived-trees t
))
1827 (goto-char (point-min))
1828 (while (re-search-forward re-archive nil t
)
1829 (if (not (org-on-heading-p t
))
1830 (org-end-of-subtree t
)
1831 (beginning-of-line 1)
1832 (setq a
(if export-archived-trees
1833 (1+ (point-at-eol)) (point))
1834 b
(org-end-of-subtree t
))
1835 (if (> b a
) (delete-region a b
)))))))
1837 (defun org-export-remove-headline-metadata (opts)
1838 "Remove meta data from the headline, according to user options."
1839 (let ((re org-complex-heading-regexp
)
1840 (todo (plist-get opts
:todo-keywords
))
1841 (tags (plist-get opts
:tags
))
1842 (pri (plist-get opts
:priority
))
1845 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1846 (when (or (not todo
) (not tags
) (not pri
))
1847 (goto-char (point-min))
1848 (while (re-search-forward re nil t
)
1850 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1852 (replace-match rpl t t
))))))
1854 (defun org-export-remove-timestamps ()
1855 "Remove timestamps and keywords for export."
1856 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1860 (beginning-of-line 1)
1861 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1862 (replace-match "")))))
1864 (defun org-export-remove-clock-lines ()
1865 "Remove timestamps and keywords for export."
1866 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1867 (while (re-search-forward re nil t
)
1869 (replace-match "")))))
1871 (defun org-export-protect-quoted-subtrees ()
1872 "Mark quoted subtrees with the protection property."
1873 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1874 (goto-char (point-min))
1875 (while (re-search-forward re-quote nil t
)
1876 (goto-char (match-beginning 0))
1878 (add-text-properties (point) (org-end-of-subtree t
)
1879 '(org-protected t
)))))
1881 (defun org-export-protect-verbatim ()
1882 "Mark verbatim snippets with the protection property."
1883 (goto-char (point-min))
1884 (while (re-search-forward org-verbatim-re nil t
)
1885 (add-text-properties (match-beginning 4) (match-end 4)
1887 (goto-char (1+ (match-end 4)))))
1889 (defun org-export-protect-colon-examples ()
1890 "Protect lines starting with a colon."
1891 (goto-char (point-min))
1892 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg end
)
1893 (while (re-search-forward re nil t
)
1894 (beginning-of-line 1)
1896 (while (looking-at re
)
1898 (or (eobp) (forward-char 1)))
1899 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1900 '(org-protected t
)))))
1902 (defun org-export-select-backend-specific-text (backend)
1904 '((html "HTML" "BEGIN_HTML" "END_HTML")
1905 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1906 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1907 (case-fold-search t
)
1911 (setq fmt
(pop formatters
))
1912 (when (eq (car fmt
) backend
)
1913 ;; This is selected code, put it into the file for real
1914 (goto-char (point-min))
1915 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1916 ":[ \t]*\\(.*\\)") nil t
)
1917 (replace-match "\\1" t
)
1918 (add-text-properties
1919 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1920 '(org-protected t
))))
1921 (goto-char (point-min))
1922 (while (re-search-forward
1924 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1925 (cadddr fmt
) "\\>.*\n?") nil t
)
1926 (if (eq (car fmt
) backend
)
1928 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1930 ;; No, this is for a different backend, kill it
1931 (delete-region (match-beginning 0) (match-end 0)))))))
1933 (defun org-export-mark-blockquote-and-verse ()
1934 "Mark block quote and verse environments with special cookies.
1935 These special cookies will later be interpreted by the backend."
1937 (goto-char (point-min))
1938 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1940 (replace-match (if (equal (downcase (match-string 1)) "end")
1941 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1944 (goto-char (point-min))
1945 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1946 (replace-match (if (equal (downcase (match-string 1)) "end")
1947 "ORG-VERSE-END" "ORG-VERSE-START")
1950 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1951 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1952 If the next thing following is a table, add the text properties to the first
1953 table line. If it is a link, add it to the line containing the link."
1954 (goto-char (point-min))
1955 (remove-text-properties (point-min) (point-max)
1956 '(org-caption nil org-attributes nil
))
1957 (let ((case-fold-search t
)
1958 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1960 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1962 "^#\\+label:[ \t]+\\(.*\\)"
1966 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1968 (while (re-search-forward re nil t
)
1971 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1973 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1975 (setq label
(org-trim (match-string 3))))
1977 (add-text-properties (point-at-bol) (point-at-eol)
1978 (list 'org-caption cap
1979 'org-attributes attr
1981 (if label
(push (cons label label
) target-alist
))
1982 (setq cap nil attr nil label nil
)))))
1985 (defun org-export-remove-comment-blocks-and-subtrees ()
1986 "Remove the comment environment, and also commented subtrees."
1987 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1988 (case-fold-search nil
))
1989 ;; Remove comment environment
1990 (goto-char (point-min))
1991 (while (re-search-forward
1992 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1993 (replace-match "" t t
))
1994 ;; Remove subtrees that are commented
1995 (goto-char (point-min))
1996 (while (re-search-forward re-commented nil t
)
1997 (goto-char (match-beginning 0))
1998 (delete-region (point) (org-end-of-subtree t
)))))
2000 (defun org-export-handle-comments (commentsp)
2001 "Remove comments, or convert to backend-specific format.
2002 COMMENTSP can be a format string for publishing comments.
2003 When it is nil, all comments will be removed."
2004 (let ((re "^#\\(.*\n?\\)")
2006 (goto-char (point-min))
2007 (while (or (looking-at re
)
2008 (re-search-forward re nil t
))
2009 (setq pos
(match-beginning 0))
2011 (progn (add-text-properties
2012 (match-beginning 0) (match-end 0) '(org-protected t
))
2013 (replace-match (format commentsp
(match-string 1)) t t
))
2014 (goto-char (1+ pos
))
2017 (goto-char (max (point-min) (1- pos
))))))))
2019 (defun org-export-mark-radio-links ()
2020 "Find all matches for radio targets and turn them into internal links."
2021 (let ((re-radio (and org-target-link-regexp
2022 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
2023 (goto-char (point-min))
2025 (while (re-search-forward re-radio nil t
)
2027 (replace-match "\\1[[\\2]]"))))))
2029 (defun org-export-remove-special-table-lines ()
2030 "Remove tables lines that are used for internal purposes."
2031 (goto-char (point-min))
2032 (while (re-search-forward "^[ \t]*|" nil t
)
2033 (beginning-of-line 1)
2034 (if (or (looking-at "[ \t]*| *[!_^] *|")
2035 (and (looking-at ".*?| *<[0-9]+> *|")
2036 (not (looking-at ".*?| *[^ <|]"))))
2037 (delete-region (max (point-min) (1- (point-at-bol)))
2041 (defun org-export-normalize-links ()
2042 "Convert all links to bracket links, and expand link abbreviations."
2043 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2044 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
2045 (goto-char (point-min))
2046 (while (re-search-forward re-plain-link nil t
)
2047 (goto-char (1- (match-end 0)))
2049 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2050 ":" (match-string 3) "]]")))
2051 ;; added 'org-link face to links
2052 (put-text-property 0 (length s
) 'face
'org-link s
)
2053 (replace-match s t t
))))
2054 (goto-char (point-min))
2055 (while (re-search-forward re-angle-link nil t
)
2056 (goto-char (1- (match-end 0)))
2058 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2059 ":" (match-string 3) "]]")))
2060 (put-text-property 0 (length s
) 'face
'org-link s
)
2061 (replace-match s t t
))))
2062 (goto-char (point-min))
2063 (while (re-search-forward org-bracket-link-regexp nil t
)
2064 (goto-char (1- (match-end 0)))
2066 (let* ((xx (save-match-data
2068 (org-link-expand-abbrev (match-string 1)))))
2070 "[[" (org-add-props (copy-sequence xx
)
2071 nil
'org-protected t
)
2075 (concat "[" (org-add-props
2080 (put-text-property 0 (length s
) 'face
'org-link s
)
2081 (replace-match s t t
))))))
2083 (defun org-export-concatenate-multiline-links ()
2084 "Find multi-line links and put it all into a single line.
2085 This is to make sure that the line-processing export backends
2086 can work correctly."
2087 (goto-char (point-min))
2088 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2090 (replace-match "\\1 \\3")
2091 (goto-char (match-beginning 0)))))
2093 (defun org-export-concatenate-multiline-emphasis ()
2094 "Find multi-line emphasis and put it all into a single line.
2095 This is to make sure that the line-processing export backends
2096 can work correctly."
2097 (goto-char (point-min))
2098 (while (re-search-forward org-emph-re nil t
)
2099 (if (not (= (char-after (match-beginning 3))
2100 (char-after (match-beginning 4))))
2102 (subst-char-in-region (match-beginning 0) (match-end 0)
2104 (goto-char (1- (match-end 0))))
2105 (goto-char (1+ (match-beginning 0))))))
2107 (defun org-export-grab-title-from-buffer ()
2108 "Get a title for the current document, from looking at the buffer."
2109 (let ((inhibit-read-only t
))
2111 (goto-char (point-min))
2112 (let ((end (if (looking-at org-outline-regexp
)
2114 (save-excursion (outline-next-heading) (point)))))
2115 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2116 ;; Mark the line so that it will not be exported as normal text.
2118 (add-text-properties (match-beginning 0) (match-end 0)
2119 (list :org-license-to-kill t
)))
2120 ;; Return the title string
2121 (org-trim (match-string 0)))))))
2123 (defun org-export-get-title-from-subtree ()
2124 "Return subtree title and exclude it from export."
2125 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
2128 (when (and (org-at-heading-p)
2129 (>= (org-end-of-subtree t t
) rend
))
2130 ;; This is a subtree, we take the title from the first heading
2132 (looking-at org-todo-line-regexp
)
2133 (setq title
(match-string 3))
2135 (add-text-properties (point) (1+ (point-at-eol))
2136 (list :org-license-to-kill t
)))
2137 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2140 (defun org-solidify-link-text (s &optional alist
)
2141 "Take link text and make a safe target out of it."
2146 (org-split-string s
"[ \t\r\n]+") "=="))
2147 (a (assoc rtn alist
)))
2150 (defun org-get-min-level (lines)
2151 "Get the minimum level in LINES."
2152 (let ((re "^\\(\\*+\\) ") l min
)
2154 (while (setq l
(pop lines
))
2155 (if (string-match re l
)
2156 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
2159 ;; Variable holding the vector with section numbers
2160 (defvar org-section-numbers
(make-vector org-level-max
0))
2162 (defun org-init-section-numbers ()
2163 "Initialize the vector for the section numbers."
2165 (numbers (nreverse (org-split-string "" "\\.")))
2166 (depth (1- (length org-section-numbers
)))
2167 (i depth
) number-string
)
2170 (aset org-section-numbers i
0)
2171 (setq number-string
(or (car numbers
) "0"))
2172 (if (string-match "\\`[A-Z]\\'" number-string
)
2173 (aset org-section-numbers i
2174 (- (string-to-char number-string
) ?A -
1))
2175 (aset org-section-numbers i
(string-to-number number-string
)))
2179 (defun org-section-number (&optional level
)
2180 "Return a string with the current section number.
2181 When LEVEL is non-nil, increase section numbers on that level."
2182 (let* ((depth (1- (length org-section-numbers
)))
2184 (fmts (car org-export-section-number-format
))
2185 (term (cdr org-export-section-number-format
))
2190 (aset org-section-numbers
2191 level
(1+ (aref org-section-numbers level
))))
2192 (setq idx
(1+ level
))
2193 (while (<= idx depth
)
2195 (aset org-section-numbers idx
0))
2196 (setq idx
(1+ idx
))))
2198 (while (<= idx depth
)
2199 (when (> (aref org-section-numbers idx
) 0)
2200 (setq fmt
(or (pop fmts
) fmt
)
2202 n
(aref org-section-numbers idx
)
2204 (concat string sep
(org-number-to-counter n ctype
))
2205 (concat string
".0"))
2207 (setq idx
(1+ idx
)))
2209 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2210 (setq string
(replace-match "" t nil string
)))
2211 (if (string-match "\\(\\.0\\)+\\'" string
)
2212 (setq string
(replace-match "" t nil string
))))
2213 (concat string term
)))
2215 (defun org-number-to-counter (n type
)
2216 "Concert number N to a string counter, according to TYPE.
2217 TYPE must be a string, any of:
2221 I upper case roman numeral
2222 i lower case roman numeral"
2224 ((equal type
"1") (number-to-string n
))
2225 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2226 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2227 ((equal type
"I") (org-number-to-roman n
))
2228 ((equal type
"i") (downcase (org-number-to-roman n
)))
2229 (t (error "Invalid counter type `%s'" type
))))
2231 (defun org-number-to-roman (n)
2232 "Convert integer N into a roman numeral."
2233 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2234 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2235 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2239 (number-to-string n
)
2241 (if (>= n
(caar roman
))
2242 (setq n
(- n
(caar roman
))
2243 res
(concat res
(cdar roman
)))
2247 (org-number-to-roman 1961)
2252 (defun org-export-handle-include-files ()
2253 "Include the contents of include files, with proper formatting."
2254 (let ((case-fold-search t
)
2255 params file markup lang start end prefix prefix1 switches
)
2256 (goto-char (point-min))
2257 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2258 (setq params
(read (concat "(" (match-string 1) ")"))
2259 prefix
(org-get-and-remove-property 'params
:prefix
)
2260 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2261 file
(org-symname-or-string (pop params
))
2262 markup
(org-symname-or-string (pop params
))
2263 lang
(and (member markup
'("src" "SRC"))
2264 (org-symname-or-string (pop params
)))
2265 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2266 (delete-region (match-beginning 0) (match-end 0))
2268 (not (file-exists-p file
))
2269 (not (file-readable-p file
)))
2270 (insert (format "CANNOT INCLUDE FILE %s" file
))
2272 (if (equal (downcase markup
) "src")
2273 (setq start
(format "#+begin_src %s %s\n"
2274 (or lang
"fundamental")
2277 (setq start
(format "#+begin_%s %s\n" markup switches
)
2278 end
(format "#+end_%s" markup
))))
2279 (insert (or start
""))
2280 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2281 (or (bolp) (newline))
2282 (insert (or end
""))))))
2284 (defun org-get-file-contents (file &optional prefix prefix1
)
2285 "Get the contents of FILE and return them as a string.
2286 If PREFIX is a string, prepend it to each line. If PREFIX1
2287 is a string, prepend it to the first line instead of PREFIX."
2289 (insert-file-contents file
)
2290 (when (or prefix prefix1
)
2291 (goto-char (point-min))
2293 (insert (or prefix1 prefix
))
2295 (beginning-of-line 2)))
2298 (defun org-get-and-remove-property (listvar prop
)
2299 "Check if the value of LISTVAR contains PROP as a property.
2300 If yes, return the value of that property (i.e. the element following
2301 in the list) and remove property and value from the list in LISTVAR."
2302 (let ((list (symbol-value listvar
)) m v
)
2303 (when (setq m
(member prop list
))
2305 (if (equal (car list
) prop
)
2306 (set listvar
(cddr list
))
2307 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2309 (set listvar list
)))
2312 (defun org-symname-or-string (s)
2314 (if s
(symbol-name s
) s
)
2317 ;;; Fontification and line numbers for code examples
2319 (defvar org-export-last-code-line-counter-value
0)
2321 (defun org-export-replace-src-segments-and-examples (backend)
2322 "Replace source code segments with special code for export."
2323 (setq org-export-last-code-line-counter-value
0)
2324 (let ((case-fold-search t
)
2325 lang code trans opts
)
2326 (goto-char (point-min))
2327 (while (re-search-forward
2328 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2332 (setq lang
(match-string 2)
2333 opts
(match-string 3)
2334 code
(match-string 4))
2336 opts
(match-string 6)
2337 code
(match-string 7)))
2339 (setq trans
(org-export-format-source-code-or-example
2340 backend lang code opts
))
2341 (replace-match trans t t
))))
2343 (defvar htmlp
) ;; dynamically scoped
2344 (defvar latexp
) ;; dynamically scoped
2346 (defun org-export-format-source-code-or-example (backend
2347 lang code
&optional opts
)
2348 "Format CODE from language LANG and return it formatted for export.
2349 If LANG is nil, do not add any fontification.
2350 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2351 and `+n' for continuing previous numering.
2352 Code formatting according to language currently only works for HTML.
2353 Numbering lines works for all three major backends (html, latex, and ascii)."
2355 (let (num cont rtn named rpllbl keepp fmt
)
2356 (setq opts
(or opts
"")
2357 num
(string-match "[-+]n\\>" opts
)
2358 cont
(string-match "\\+n\\>" opts
)
2359 rpllbl
(string-match "-r\\>" opts
)
2360 keepp
(string-match "-k\\>" opts
)
2361 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2362 (match-string 1 opts
)))
2363 (if keepp
(setq rpllbl
'keep
))
2365 (when (equal lang
"org")
2366 (setq rtn
(with-temp-buffer
2368 ;; Free up the protected lines
2369 (goto-char (point-min))
2370 (while (re-search-forward "^," nil t
)
2374 ;; Now backend-specific coding
2377 ;; We are exporting to HTML
2379 (require 'htmlize nil t
)
2380 (when (not (fboundp 'htmlize-region-for-paste
))
2381 ;; we do not have htmlize.el, or an old version of it
2383 "htmlize.el 1.34 or later is needed for source code formatting")))
2386 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2387 (org-inhibit-startup t
)
2388 (org-startup-folded nil
))
2392 (if (functionp mode
)
2395 (font-lock-fontify-buffer)
2396 (org-export-htmlize-region-for-paste
2397 (point-min) (point-max))))
2398 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2399 (setq rtn
(replace-match
2400 (format "<pre class=\"src src-%s\">\n" lang
)
2402 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n")))
2403 (setq rtn
(org-export-number-lines rtn
'html
1 1 num cont rpllbl fmt
))
2404 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2405 ((eq backend
'latex
)
2406 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2407 (concat "\n#+BEGIN_LaTeX\n"
2408 (org-add-props (concat "\\begin{verbatim}\n" rtn
"\n\\end{verbatim}\n")
2411 ((eq backend
'ascii
)
2412 ;; This is not HTML or LaTeX, so just make it an example.
2413 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2414 (concat "#+BEGIN_ASCII\n"
2418 (lambda (l) (concat " " l
))
2419 (org-split-string rtn
"\n")
2423 "#+END_ASCII\n"))))))
2425 (defun org-export-number-lines (text backend
2426 &optional skip1 skip2 number cont
2427 replace-labels label-format
)
2428 (if (and (not number
) (not (eq replace-labels
'keep
)))
2429 (setq replace-labels nil
)) ;; must use names if no numbers
2430 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2431 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2434 (goto-char (point-max))
2435 (skip-chars-backward " \t\n\r")
2436 (delete-region (point) (point-max))
2437 (beginning-of-line (- 1 skip2
))
2438 (let* ((last (org-current-line))
2439 (n org-export-last-code-line-counter-value
)
2440 (nmax (+ n
(- last skip1
)))
2441 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2444 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2446 ((eq backend
'ascii
) fmt
)
2447 ((eq backend
'latex
) fmt
)
2449 (label-format (or label-format org-coderef-label-format
))
2450 (label-pre (if (string-match "%s" label-format
)
2451 (substring label-format
0 (match-beginning 0))
2453 (label-post (if (string-match "%s" label-format
)
2454 (substring label-format
(match-end 0))
2458 ".*?\\S-.*?\\([ \t]*\\("
2459 (regexp-quote label-pre
)
2460 "\\([-a-zA-Z0-9_]+\\)"
2461 (regexp-quote label-post
)
2465 (goto-line (1+ skip1
))
2466 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2468 (insert (format fm
(incf n
)))
2470 (when (and (not (eq replace-labels
'keep
))
2471 (looking-at lbl-re
))
2472 (setq ref
(match-string 3))
2475 (delete-region (match-beginning 1) (match-end 1))
2476 (push (cons ref n
) org-export-code-refs
))
2477 (goto-char (match-beginning 2))
2478 (delete-region (match-beginning 2) (match-end 2))
2479 (insert "(" ref
")")
2480 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2481 (when (eq backend
'html
)
2483 (beginning-of-line 1)
2484 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2487 (insert "</span>")))))
2488 (setq org-export-last-code-line-counter-value n
)
2489 (goto-char (point-max))
2495 (defvar org-last-level nil
) ; dynamically scoped variable
2496 (defvar org-min-level nil
) ; dynamically scoped variable
2497 (defvar org-levels-open nil
) ; dynamically scoped parameter
2498 (defvar org-ascii-current-indentation nil
) ; For communication
2501 (defun org-export-as-ascii (arg)
2502 "Export the outline as a pretty ASCII file.
2503 If there is an active region, export only the region.
2504 The prefix ARG specifies how many levels of the outline should become
2505 underlined headlines. The default is 3."
2507 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2508 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2509 (org-infile-export-plist)))
2510 (region-p (org-region-active-p))
2511 (rbeg (and region-p
(region-beginning)))
2512 (rend (and region-p
(region-end)))
2517 (and (org-at-heading-p)
2518 (>= (org-end-of-subtree t t
) rend
)))))
2519 (opt-plist (if subtree-p
2520 (org-export-add-subtree-options opt-plist rbeg
)
2522 (custom-times org-display-custom-times
)
2523 (org-ascii-current-indentation '(0 .
0))
2527 (case-fold-search nil
)
2528 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2529 (filename (concat (file-name-as-directory
2530 (org-export-directory :ascii opt-plist
))
2531 (file-name-sans-extension
2533 (org-entry-get (region-beginning)
2534 "EXPORT_FILE_NAME" t
))
2535 (file-name-nondirectory bfname
)))
2537 (filename (if (equal (file-truename filename
)
2538 (file-truename bfname
))
2539 (concat filename
".txt")
2541 (buffer (find-file-noselect filename
))
2542 (org-levels-open (make-vector org-level-max nil
))
2543 (odd org-odd-levels-only
)
2544 (date (plist-get opt-plist
:date
))
2545 (author (plist-get opt-plist
:author
))
2546 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2547 (plist-get opt-plist
:title
)
2549 (plist-get opt-plist
:skip-before-1st-heading
))
2550 (org-export-grab-title-from-buffer))
2551 (file-name-sans-extension
2552 (file-name-nondirectory bfname
))))
2553 (email (plist-get opt-plist
:email
))
2554 (language (plist-get opt-plist
:language
))
2555 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2556 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2561 (if (org-region-active-p) (region-beginning) (point-min))
2562 (if (org-region-active-p) (region-end) (point-max))))
2563 (lines (org-split-string
2564 (org-export-preprocess-string
2567 :skip-before-1st-heading
2568 (plist-get opt-plist
:skip-before-1st-heading
)
2569 :drawers
(plist-get opt-plist
:drawers
)
2570 :tags
(plist-get opt-plist
:tags
)
2571 :priority
(plist-get opt-plist
:priority
)
2572 :footnotes
(plist-get opt-plist
:footnotes
)
2573 :timestamps
(plist-get opt-plist
:timestamps
)
2574 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
2575 :verbatim-multiline t
2576 :select-tags
(plist-get opt-plist
:select-tags
)
2577 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2579 (plist-get opt-plist
:archived-trees
)
2580 :add-text
(plist-get opt-plist
:text
))
2582 thetoc have-headings first-heading-pos
2583 table-open table-buffer link desc
)
2585 (let ((inhibit-read-only t
))
2587 (remove-text-properties (point-min) (point-max)
2588 '(:org-license-to-kill t
))))
2590 (setq org-min-level
(org-get-min-level lines
))
2591 (setq org-last-level org-min-level
)
2592 (org-init-section-numbers)
2594 (find-file-noselect filename
)
2596 (setq lang-words
(or (assoc language org-export-language-setup
)
2597 (assoc "en" org-export-language-setup
)))
2598 (switch-to-buffer-other-window buffer
)
2601 ;; create local variables for all options, to make sure all called
2602 ;; functions get the correct information
2604 (set (make-local-variable (nth 2 x
))
2605 (plist-get opt-plist
(car x
))))
2606 org-export-plist-vars
)
2607 (org-set-local 'org-odd-levels-only odd
)
2608 (setq umax
(if arg
(prefix-numeric-value arg
)
2609 org-export-headline-levels
))
2610 (setq umax-toc
(if (integerp org-export-with-toc
)
2611 (min org-export-with-toc umax
)
2615 (if title
(org-insert-centered title ?
=))
2617 (if (and (or author email
)
2618 org-export-author-info
)
2619 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2620 (if email
(concat " <" email
">") "")
2624 ((and date
(string-match "%" date
))
2625 (setq date
(format-time-string date
)))
2627 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2629 (if (and date org-export-time-stamp-file
)
2630 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2634 (if org-export-with-toc
2636 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2637 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2639 (mapc '(lambda (line)
2640 (if (string-match org-todo-line-regexp
2642 ;; This is a headline
2644 (setq have-headings t
)
2645 (setq level
(- (match-end 1) (match-beginning 1))
2646 level
(org-tr-level level
)
2647 txt
(match-string 3 line
)
2649 (or (and org-export-mark-todo-in-toc
2651 (not (member (match-string 2 line
)
2652 org-done-keywords
)))
2654 (and org-export-mark-todo-in-toc
2656 (org-search-todo-below
2657 line lines level
))))
2658 (setq txt
(org-html-expand-for-ascii txt
))
2660 (while (string-match org-bracket-link-regexp txt
)
2663 (match-string (if (match-end 2) 3 1) txt
)
2666 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2668 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2670 (setq txt
(replace-match "" t t txt
)))
2671 (if (string-match quote-re0 txt
)
2672 (setq txt
(replace-match "" t t txt
)))
2674 (if org-export-with-section-numbers
2675 (setq txt
(concat (org-section-number level
)
2677 (if (<= level umax-toc
)
2682 (* (max 0 (- level org-min-level
)) 4) ?\
)
2683 (format (if todo
"%s (*)\n" "%s\n") txt
))
2685 (setq org-last-level level
))
2688 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2690 (org-init-section-numbers)
2691 (while (setq line
(pop lines
))
2692 ;; Remove the quoted HTML tags.
2693 (setq line
(org-html-expand-for-ascii line
))
2694 ;; Replace links with the description when possible
2695 (while (string-match org-bracket-link-regexp line
)
2696 (setq link
(match-string 1 line
)
2697 desc
(match-string (if (match-end 3) 3 1) line
))
2698 (if (and (> (length link
) 8)
2699 (equal (substring link
0 8) "coderef:"))
2700 (setq line
(replace-match
2701 (format (org-export-get-coderef-format (substring link
8) desc
)
2704 org-export-code-refs
)))
2706 (setq line
(replace-match
2707 (if (match-end 3) "[\\3]" "[\\1]")
2710 (setq line
(org-translate-time line
)))
2712 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2714 (setq first-heading-pos
(or first-heading-pos
(point)))
2715 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2716 txt
(match-string 2 line
))
2717 (org-ascii-level-start level txt umax lines
))
2719 ((and org-export-with-tables
2720 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2721 (if (not table-open
)
2723 (setq table-open t table-buffer nil
))
2725 (setq table-buffer
(cons line table-buffer
))
2726 (when (or (not lines
)
2727 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2729 (setq table-open nil
2730 table-buffer
(nreverse table-buffer
))
2733 (org-fix-indentation x org-ascii-current-indentation
))
2734 (org-format-table-ascii table-buffer
)
2737 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2738 ;; Remove forced line breaks
2739 (if (string-match "\\\\\\\\[ \t]*$" line
)
2740 (setq line
(replace-match "" t t line
)))
2741 (if (and org-export-with-fixed-width
2742 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2743 (setq line
(replace-match "\\1" nil nil line
)))
2744 (insert line
"\n"))))
2748 ;; insert the table of contents
2750 (goto-char (point-min))
2751 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2753 (goto-char (match-beginning 0))
2755 (goto-char first-heading-pos
))
2756 (mapc 'insert thetoc
)
2757 (or (looking-at "[ \t]*\n[ \t]*\n")
2760 ;; Convert whitespace place holders
2761 (goto-char (point-min))
2763 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2764 (setq end
(next-single-property-change beg
'org-whitespace
))
2766 (delete-region beg end
)
2767 (insert (make-string (- end beg
) ?\
))))
2770 ;; remove display and invisible chars
2772 (goto-char (point-min))
2773 (while (setq beg
(next-single-property-change (point) 'display
))
2774 (setq end
(next-single-property-change beg
'display
))
2775 (delete-region beg end
)
2778 (goto-char (point-min))
2779 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2780 (setq end
(next-single-property-change beg
'org-cwidth
))
2781 (delete-region beg end
)
2783 (goto-char (point-min))))
2785 (defun org-export-ascii-preprocess ()
2786 "Do extra work for ASCII export"
2787 ;; Put quotes around verbatim text
2788 (goto-char (point-min))
2789 (while (re-search-forward org-verbatim-re nil t
)
2790 (goto-char (match-end 2))
2791 (backward-delete-char 1) (insert "'")
2792 (goto-char (match-beginning 2))
2793 (delete-char 1) (insert "`")
2794 (goto-char (match-end 2)))
2795 (goto-char (point-min))
2796 ;; Remove target markers
2797 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t
)
2798 (replace-match "\\1\\2")))
2800 (defun org-search-todo-below (line lines level
)
2801 "Search the subtree below LINE for any TODO entries."
2802 (let ((rest (cdr (memq line lines
)))
2803 (re org-todo-line-regexp
)
2806 (while (setq line
(pop rest
))
2807 (if (string-match re line
)
2809 (setq lv
(- (match-end 1) (match-beginning 1))
2810 todo
(and (match-beginning 2)
2811 (not (member (match-string 2 line
)
2812 org-done-keywords
))))
2814 (if (<= lv level
) (throw 'exit nil
))
2815 (if todo
(throw 'exit t
))))))))
2817 (defun org-html-expand-for-ascii (line)
2818 "Handle quoted HTML for ASCII export."
2819 (if org-export-html-expand
2820 (while (string-match "@<[^<>\n]*>" line
)
2821 ;; We just remove the tags for now.
2822 (setq line
(replace-match "" nil nil line
))))
2825 (defun org-insert-centered (s &optional underline
)
2826 "Insert the string S centered and underline it with character UNDERLINE."
2827 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2828 (insert (make-string ind ?\
) s
"\n")
2830 (insert (make-string ind ?\
)
2831 (make-string (string-width s
) underline
)
2834 (defun org-ascii-level-start (level title umax
&optional lines
)
2835 "Insert a new level in ASCII export."
2836 (let (char (n (- level umax
1)) (ind 0))
2839 (insert (make-string (* 2 n
) ?\
)
2840 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2841 org-export-ascii-bullets
))
2843 ;; find the indentation of the next non-empty line
2846 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2847 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2848 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2850 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2851 (if (or (not (equal (char-before) ?
\n))
2852 (not (equal (char-before (1- (point))) ?
\n)))
2854 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2855 (unless org-export-with-tags
2856 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2857 (setq title
(replace-match "" t t title
))))
2858 (if org-export-with-section-numbers
2859 (setq title
(concat (org-section-number level
) " " title
)))
2860 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2861 (setq org-ascii-current-indentation
'(0 .
0)))))
2864 (defun org-export-visible (type arg
)
2865 "Create a copy of the visible part of the current buffer, and export it.
2866 The copy is created in a temporary buffer and removed after use.
2867 TYPE is the final key (as a string) that also select the export command in
2868 the `C-c C-e' export dispatcher.
2869 As a special case, if the you type SPC at the prompt, the temporary
2870 org-mode file will not be removed but presented to you so that you can
2871 continue to use it. The prefix arg ARG is passed through to the exporting
2875 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2876 (read-char-exclusive))
2877 current-prefix-arg
))
2878 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2879 (error "Invalid export key"))
2880 (let* ((binding (cdr (assoc type
2881 '((?a . org-export-as-ascii
)
2882 (?\C-a . org-export-as-ascii
)
2883 (?b . org-export-as-html-and-open
)
2884 (?\C-b . org-export-as-html-and-open
)
2885 (?h . org-export-as-html
)
2886 (?H . org-export-as-html-to-buffer
)
2887 (?R . org-export-region-as-html
)
2888 (?x . org-export-as-xoxo
)))))
2889 (keepp (equal type ?\
))
2890 (file buffer-file-name
)
2891 (buffer (get-buffer-create "*Org Export Visible*"))
2893 ;; Need to hack the drawers here.
2895 (goto-char (point-min))
2896 (while (re-search-forward org-drawer-regexp nil t
)
2897 (goto-char (match-beginning 1))
2898 (or (org-invisible-p) (org-flag-drawer nil
))))
2899 (with-current-buffer buffer
(erase-buffer))
2901 (setq s
(goto-char (point-min)))
2902 (while (not (= (point) (point-max)))
2903 (goto-char (org-find-invisible))
2904 (append-to-buffer buffer s
(point))
2905 (setq s
(goto-char (org-find-visible))))
2906 (org-cycle-hide-drawers 'all
)
2907 (goto-char (point-min))
2909 ;; Copy all comment lines to the end, to make sure #+ settings are
2910 ;; still available for the second export step. Kind of a hack, but
2911 ;; does do the trick.
2912 (if (looking-at "#[^\r\n]*")
2913 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2914 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2915 (append-to-buffer buffer
(1+ (match-beginning 0))
2916 (min (point-max) (1+ (match-end 0))))))
2918 (let ((buffer-file-name file
)
2919 (org-inhibit-startup t
))
2922 (unless keepp
(funcall binding arg
))))
2924 (kill-buffer buffer
)
2925 (switch-to-buffer-other-window buffer
)
2926 (goto-char (point-min)))))
2928 (defun org-find-visible ()
2930 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2931 (get-char-property s
'invisible
)))
2933 (defun org-find-invisible ()
2935 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2936 (not (get-char-property s
'invisible
))))
2941 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2942 (defun org-get-current-options ()
2943 "Return a string with current options as keyword options.
2944 Does include HTML export options as well as TODO and CATEGORY stuff."
2945 (require 'org-archive
)
2952 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2954 #+EXPORT_SELECT_TAGS: %s
2955 #+EXPORT_EXCLUDE_TAGS: %s
2961 #+PRIORITIES: %c %c %c
2963 #+STARTUP: %s %s %s %s %s
2969 (buffer-name) (user-full-name) user-mail-address
2970 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2971 org-export-default-language
2972 org-export-headline-levels
2973 org-export-with-section-numbers
2975 org-export-preserve-breaks
2976 org-export-html-expand
2977 org-export-with-fixed-width
2978 org-export-with-tables
2979 org-export-with-sub-superscripts
2980 org-export-with-special-strings
2981 org-export-with-footnotes
2982 org-export-with-emphasize
2983 org-export-with-TeX-macros
2984 org-export-with-LaTeX-fragments
2985 org-export-skip-text-before-1st-heading
2986 org-export-with-drawers
2987 org-export-with-todo-keywords
2988 org-export-with-priority
2989 org-export-with-tags
2990 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2991 (mapconcat 'identity org-export-select-tags
" ")
2992 (mapconcat 'identity org-export-exclude-tags
" ")
2993 org-export-html-link-up
2994 org-export-html-link-home
2995 (file-name-nondirectory buffer-file-name
)
2996 "TODO FEEDBACK VERIFY DONE"
2997 "Me Jason Marie DONE"
2998 org-highest-priority org-lowest-priority org-default-priority
2999 (mapconcat 'identity org-drawers
" ")
3000 (cdr (assoc org-startup-folded
3001 '((nil .
"showall") (t .
"overview") (content .
"content"))))
3002 (if org-odd-levels-only
"odd" "oddeven")
3003 (if org-hide-leading-stars
"hidestars" "showstars")
3004 (if org-startup-align-all-tables
"align" "noalign")
3005 (cond ((eq org-log-done t
) "logdone")
3006 ((equal org-log-done
'note
) "lognotedone")
3007 ((not org-log-done
) "nologdone"))
3008 (or (mapconcat (lambda (x)
3010 ((equal '(:startgroup
) x
) "{")
3011 ((equal '(:endgroup
) x
) "}")
3012 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
3014 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
3015 (mapconcat 'identity org-file-tags
" ")
3016 org-archive-location
3017 "org file:~/org/%s.org"
3020 (defun org-export-html-preprocess (parameters)
3021 ;; Convert LaTeX fragments to images
3022 (when (plist-get parameters
:LaTeX-fragments
)
3024 (concat "ltxpng/" (file-name-sans-extension
3025 (file-name-nondirectory
3026 org-current-export-file
)))
3027 org-current-export-dir nil
"Creating LaTeX image %s"))
3028 (message "Exporting..."))
3031 (defun org-insert-export-options-template ()
3032 "Insert into the buffer a template with information for exporting."
3034 (if (not (bolp)) (newline))
3035 (let ((s (org-get-current-options)))
3036 (and (string-match "#\\+CATEGORY" s
)
3037 (setq s
(substring s
0 (match-beginning 0))))
3041 (defun org-export-as-html-and-open (arg)
3042 "Export the outline as HTML and immediately open it with a browser.
3043 If there is an active region, export only the region.
3044 The prefix ARG specifies how many levels of the outline should become
3045 headlines. The default is 3. Lower levels will become bulleted lists."
3047 (org-export-as-html arg
'hidden
)
3048 (org-open-file buffer-file-name
))
3051 (defun org-export-as-html-batch ()
3052 "Call `org-export-as-html', may be used in batch processing as
3054 --load=$HOME/lib/emacs/org.el
3055 --eval \"(setq org-export-headline-levels 2)\"
3056 --visit=MyFile --funcall org-export-as-html-batch"
3057 (org-export-as-html org-export-headline-levels
'hidden
))
3060 (defun org-export-as-html-to-buffer (arg)
3061 "Call `org-export-as-html` with output to a temporary buffer.
3062 No file is created. The prefix ARG is passed through to `org-export-as-html'."
3064 (org-export-as-html arg nil nil
"*Org HTML Export*")
3065 (switch-to-buffer-other-window "*Org HTML Export*"))
3068 (defun org-replace-region-by-html (beg end
)
3069 "Assume the current region has org-mode syntax, and convert it to HTML.
3070 This can be used in any buffer. For example, you could write an
3071 itemized list in org-mode syntax in an HTML buffer and then use this
3072 command to convert it."
3074 (let (reg html buf pop-up-frames
)
3075 (save-window-excursion
3077 (setq html
(org-export-region-as-html
3079 (setq reg
(buffer-substring beg end
)
3080 buf
(get-buffer-create "*Org tmp*"))
3081 (with-current-buffer buf
3085 (setq html
(org-export-region-as-html
3086 (point-min) (point-max) t
'string
)))
3088 (delete-region beg end
)
3092 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
3093 "Convert region from BEG to END in org-mode buffer to HTML.
3094 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
3095 contents, and only produce the region of converted text, useful for
3096 cut-and-paste operations.
3097 If BUFFER is a buffer or a string, use/create that buffer as a target
3098 of the converted HTML. If BUFFER is the symbol `string', return the
3099 produced HTML as a string and leave not buffer behind. For example,
3100 a Lisp program could call this function in the following way:
3102 (setq html (org-export-region-as-html beg end t 'string))
3104 When called interactively, the output buffer is selected, and shown
3105 in a window. A non-interactive call will only return the buffer."
3106 (interactive "r\nP")
3107 (when (interactive-p)
3108 (setq buffer
"*Org HTML Export*"))
3109 (let ((transient-mark-mode t
) (zmacs-regions t
)
3111 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
3113 (set-mark (point)) ;; to activate the region
3115 (setq rtn
(org-export-as-html
3118 (if (fboundp 'deactivate-mark
) (deactivate-mark))
3119 (if (and (interactive-p) (bufferp rtn
))
3120 (switch-to-buffer-other-window rtn
)
3123 (defvar html-table-tag nil
) ; dynamically scoped into this.
3124 (defvar org-par-open nil
)
3126 (defun org-export-as-html (arg &optional hidden ext-plist
3127 to-buffer body-only pub-dir
)
3128 "Export the outline as a pretty HTML file.
3129 If there is an active region, export only the region. The prefix
3130 ARG specifies how many levels of the outline should become
3131 headlines. The default is 3. Lower levels will become bulleted
3132 lists. When HIDDEN is non-nil, don't display the HTML buffer.
3133 EXT-PLIST is a property list with external parameters overriding
3134 org-mode's default settings, but still inferior to file-local
3135 settings. When TO-BUFFER is non-nil, create a buffer with that
3136 name and export to that buffer. If TO-BUFFER is the symbol
3137 `string', don't leave any buffer behind but just return the
3138 resulting HTML as a string. When BODY-ONLY is set, don't produce
3139 the file header and footer, simply return the content of
3140 <body>...</body>, without even the body tags themselves. When
3141 PUB-DIR is set, use this as the publishing directory."
3144 ;; Make sure we have a file name when we need it.
3145 (when (and (not (or to-buffer body-only
))
3146 (not buffer-file-name
))
3147 (if (buffer-base-buffer)
3148 (org-set-local 'buffer-file-name
3149 (with-current-buffer (buffer-base-buffer)
3151 (error "Need a file name to be able to export.")))
3153 (message "Exporting...")
3154 (setq-default org-todo-line-regexp org-todo-line-regexp
)
3155 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
3156 (setq-default org-done-keywords org-done-keywords
)
3157 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
3159 (org-export-process-option-filters
3160 (org-combine-plists (org-default-export-plist)
3162 (org-infile-export-plist))))
3163 (style (concat (if (plist-get opt-plist
:style-include-default
)
3164 org-export-html-style-default
)
3165 (plist-get opt-plist
:style
)
3166 (plist-get opt-plist
:style-extra
)
3167 "\n" org-export-html-scripts
))
3168 (html-extension (plist-get opt-plist
:html-extension
))
3169 (link-validate (plist-get opt-plist
:link-validation-function
))
3170 valid thetoc have-headings first-heading-pos
3171 (odd org-odd-levels-only
)
3172 (region-p (org-region-active-p))
3173 (rbeg (and region-p
(region-beginning)))
3174 (rend (and region-p
(region-end)))
3176 (if (plist-get opt-plist
:ignore-subree-p
)
3181 (and (org-at-heading-p)
3182 (>= (org-end-of-subtree t t
) rend
))))))
3183 (opt-plist (if subtree-p
3184 (org-export-add-subtree-options opt-plist rbeg
)
3186 ;; The following two are dynamically scoped into other
3188 (org-current-export-dir
3189 (or pub-dir
(org-export-directory :html opt-plist
)))
3190 (org-current-export-file buffer-file-name
)
3191 (level 0) (line "") (origline "") txt todo
3194 (filename (if to-buffer nil
3197 (file-name-sans-extension
3199 (org-entry-get (region-beginning)
3200 "EXPORT_FILE_NAME" t
))
3201 (file-name-nondirectory buffer-file-name
)))
3203 (file-name-as-directory
3204 (or pub-dir
(org-export-directory :html opt-plist
))))))
3205 (current-dir (if buffer-file-name
3206 (file-name-directory buffer-file-name
)
3208 (buffer (if to-buffer
3210 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
3211 (t (get-buffer-create to-buffer
)))
3212 (find-file-noselect filename
)))
3213 (org-levels-open (make-vector org-level-max nil
))
3214 (date (plist-get opt-plist
:date
))
3215 (author (plist-get opt-plist
:author
))
3216 (title (or (and subtree-p
(org-export-get-title-from-subtree))
3217 (plist-get opt-plist
:title
)
3219 (plist-get opt-plist
:skip-before-1st-heading
))
3220 (org-export-grab-title-from-buffer))
3221 (and buffer-file-name
3222 (file-name-sans-extension
3223 (file-name-nondirectory buffer-file-name
)))
3225 (html-table-tag (plist-get opt-plist
:html-table-tag
))
3226 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
3227 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
3232 (local-list-type nil
)
3233 (local-list-indent nil
)
3234 (llt org-plain-list-ordered-item-terminator
)
3235 (email (plist-get opt-plist
:email
))
3236 (language (plist-get opt-plist
:language
))
3240 (coding-system (and (boundp 'buffer-file-coding-system
)
3241 buffer-file-coding-system
))
3242 (coding-system-for-write (or org-export-html-coding-system
3244 (save-buffer-coding-system (or org-export-html-coding-system
3246 (charset (and coding-system-for-write
3247 (fboundp 'coding-system-get
)
3248 (coding-system-get coding-system-for-write
3252 (if region-p
(region-beginning) (point-min))
3253 (if region-p
(region-end) (point-max))))
3256 (org-export-preprocess-string
3260 :skip-before-1st-heading
3261 (plist-get opt-plist
:skip-before-1st-heading
)
3262 :drawers
(plist-get opt-plist
:drawers
)
3263 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
3264 :tags
(plist-get opt-plist
:tags
)
3265 :priority
(plist-get opt-plist
:priority
)
3266 :footnotes
(plist-get opt-plist
:footnotes
)
3267 :timestamps
(plist-get opt-plist
:timestamps
)
3269 (plist-get opt-plist
:archived-trees
)
3270 :select-tags
(plist-get opt-plist
:select-tags
)
3271 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
3273 (plist-get opt-plist
:text
)
3275 (plist-get opt-plist
:LaTeX-fragments
))
3278 table-buffer table-orig-buffer
3279 ind item-type starter didclose
3280 rpl path attr desc descp desc1 desc2 link
3281 snumber fnc item-tag
3282 footnotes footref-seen
3286 (let ((inhibit-read-only t
))
3288 (remove-text-properties (point-min) (point-max)
3289 '(:org-license-to-kill t
))))
3291 (message "Exporting...")
3293 (setq org-min-level
(org-get-min-level lines
))
3294 (setq org-last-level org-min-level
)
3295 (org-init-section-numbers)
3298 ((and date
(string-match "%" date
))
3299 (setq date
(format-time-string date
)))
3301 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
3303 ;; Get the language-dependent settings
3304 (setq lang-words
(or (assoc language org-export-language-setup
)
3305 (assoc "en" org-export-language-setup
)))
3307 ;; Switch to the output buffer
3309 (let ((inhibit-read-only t
)) (erase-buffer))
3312 (and (fboundp 'set-buffer-file-coding-system
)
3313 (set-buffer-file-coding-system coding-system-for-write
))
3315 (let ((case-fold-search nil
)
3316 (org-odd-levels-only odd
))
3317 ;; create local variables for all options, to make sure all called
3318 ;; functions get the correct information
3320 (set (make-local-variable (nth 2 x
))
3321 (plist-get opt-plist
(car x
))))
3322 org-export-plist-vars
)
3323 (setq umax
(if arg
(prefix-numeric-value arg
)
3324 org-export-headline-levels
))
3325 (setq umax-toc
(if (integerp org-export-with-toc
)
3326 (min org-export-with-toc umax
)
3331 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3332 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3333 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3334 lang=\"%s\" xml:lang=\"%s\">
3337 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3338 <meta name=\"generator\" content=\"Org-mode\"/>
3339 <meta name=\"generated\" content=\"%s\"/>
3340 <meta name=\"author\" content=\"%s\"/>
3344 language language
(org-html-expand title
)
3345 (or charset
"iso-8859-1") date author style
))
3347 (insert (or (plist-get opt-plist
:preamble
) ""))
3349 (when (plist-get opt-plist
:auto-preamble
)
3350 (if title
(insert (format org-export-html-title-format
3351 (org-html-expand title
))))))
3353 (if (and org-export-with-toc
(not body-only
))
3355 (push (format "<h%d>%s</h%d>\n"
3356 org-export-html-toplevel-hlevel
3358 org-export-html-toplevel-hlevel
)
3360 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3361 (push "<ul>\n<li>" thetoc
)
3363 (mapcar '(lambda (line)
3364 (if (string-match org-todo-line-regexp line
)
3365 ;; This is a headline
3367 (setq have-headings t
)
3368 (setq level
(- (match-end 1) (match-beginning 1))
3369 level
(org-tr-level level
)
3370 txt
(save-match-data
3372 (org-export-cleanup-toc-line
3373 (match-string 3 line
))))
3375 (or (and org-export-mark-todo-in-toc
3377 (not (member (match-string 2 line
)
3378 org-done-keywords
)))
3380 (and org-export-mark-todo-in-toc
3382 (org-search-todo-below
3383 line lines level
))))
3385 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3386 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3387 (if (string-match quote-re0 txt
)
3388 (setq txt
(replace-match "" t t txt
)))
3389 (setq snumber
(org-section-number level
))
3390 (if org-export-with-section-numbers
3391 (setq txt
(concat snumber
" " txt
)))
3392 (if (<= level
(max umax umax-toc
))
3393 (setq head-count
(+ head-count
1)))
3394 (if (<= level umax-toc
)
3396 (if (> level org-last-level
)
3398 (setq cnt
(- level org-last-level
))
3399 (while (>= (setq cnt
(1- cnt
)) 0)
3400 (push "\n<ul>\n<li>" thetoc
))
3401 (push "\n" thetoc
)))
3402 (if (< level org-last-level
)
3404 (setq cnt
(- org-last-level level
))
3405 (while (>= (setq cnt
(1- cnt
)) 0)
3406 (push "</li>\n</ul>" thetoc
))
3407 (push "\n" thetoc
)))
3408 ;; Check for targets
3409 (while (string-match org-any-target-regexp line
)
3410 (setq line
(replace-match
3411 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3413 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3414 (setq txt
(replace-match "" t t txt
)))
3418 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3419 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3420 snumber txt
) thetoc
)
3422 (setq org-last-level level
))
3426 (while (> org-last-level
(1- org-min-level
))
3427 (setq org-last-level
(1- org-last-level
))
3428 (push "</li>\n</ul>\n" thetoc
))
3429 (push "</div>\n" thetoc
)
3430 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3433 (org-init-section-numbers)
3437 (while (setq line
(pop lines
) origline line
)
3440 ;; end of quote section?
3441 (when (and inquote
(string-match "^\\*+ " line
))
3444 ;; inside a quote section?
3446 (insert (org-html-protect line
) "\n")
3447 (throw 'nextline nil
))
3449 ;; Fixed-width, verbatim lines (examples)
3450 (when (and org-export-with-fixed-width
3451 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\).*\\)" line
))
3454 (org-close-par-maybe)
3455 (insert "<pre class=\"example\">\n"))
3456 (insert (org-html-protect (match-string 1 line
)) "\n")
3457 (when (or (not lines
)
3458 (not (string-match "^[ \t]*\\(:.*\\)"
3461 (insert "</pre>\n"))
3462 (throw 'nextline nil
))
3465 (when (get-text-property 0 'org-protected line
)
3467 (when (re-search-backward
3468 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3469 (setq par
(match-string 1))
3470 (replace-match "\\2\n"))
3473 (or (= (length (car lines
)) 0)
3474 (get-text-property 0 'org-protected
(car lines
))))
3475 (insert (pop lines
) "\n"))
3476 (and par
(insert "<p>\n")))
3477 (throw 'nextline nil
))
3480 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3482 (insert "\n</p>\n<hr/>\n<p>\n")
3483 (insert "\n<hr/>\n"))
3484 (throw 'nextline nil
))
3486 ;; Blockquotes and verse
3487 (when (equal "ORG-BLOCKQUOTE-START" line
)
3488 (org-close-par-maybe)
3489 (insert "<blockquote>\n<p>\n")
3490 (throw 'nextline nil
))
3491 (when (equal "ORG-BLOCKQUOTE-END" line
)
3492 (insert "</p>\n</blockquote>\n")
3493 (throw 'nextline nil
))
3494 (when (equal "ORG-VERSE-START" line
)
3495 (org-close-par-maybe)
3496 (insert "\n<p class=\"verse\">\n")
3498 (throw 'nextline nil
))
3499 (when (equal "ORG-VERSE-END" line
)
3502 (throw 'nextline nil
))
3504 (let ((i (org-get-string-indentation line
)))
3506 (setq line
(concat (mapconcat 'identity
3507 (make-list (* 2 i
) "\\nbsp") "")
3508 " " (org-trim line
))))
3509 (setq line
(concat line
"\\\\"))))
3511 ;; make targets to anchors
3512 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3515 (setq line
(replace-match
3517 "@<a name=\"%s\" id=\"%s\">@</a>"
3518 (org-solidify-link-text (match-string 1 line
))
3519 (org-solidify-link-text (match-string 1 line
)))
3521 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3522 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3523 (setq line
(replace-match
3524 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3525 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3528 (setq line
(replace-match
3529 (concat "@<a name=\""
3530 (org-solidify-link-text (match-string 1 line
))
3531 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3534 (setq line
(org-html-handle-time-stamps line
))
3536 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3537 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3538 ;; Also handle sub_superscripts and checkboxes
3539 (or (string-match org-table-hline-regexp line
)
3540 (setq line
(org-html-expand line
)))
3544 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
3545 (setq start
(match-beginning 0))
3546 (setq path
(save-match-data (org-link-unescape
3547 (match-string 3 line
))))
3549 ((match-end 2) (match-string 2 line
))
3551 (or (file-name-absolute-p path
)
3552 (string-match "^\\.\\.?/" path
)))
3555 (setq path
(org-extract-attributes (org-link-unescape path
)))
3556 (setq attr
(get-text-property 0 'org-attributes path
))
3557 (setq desc1
(if (match-end 5) (match-string 5 line
))
3558 desc2
(if (match-end 2) (concat type
":" path
) path
)
3559 descp
(and desc1
(not (equal desc1 desc2
)))
3560 desc
(or desc1 desc2
))
3561 ;; Make an image out of the description if that is so wanted
3562 (when (and descp
(org-file-image-p desc
))
3564 (if (string-match "^file:" desc
)
3565 (setq desc
(substring desc
(match-end 0)))))
3566 (setq desc
(org-add-props
3567 (concat "<img src=\"" desc
"\"/>")
3568 '(org-protected t
))))
3569 ;; FIXME: do we need to unescape here somewhere?
3571 ((equal type
"internal")
3575 (org-solidify-link-text
3576 (save-match-data (org-link-unescape path
)) nil
)
3578 (org-export-html-format-desc desc
)
3580 ((and (equal type
"id")
3581 (setq id-file
(org-id-find-id-file path
)))
3582 ;; This is an id: link to another file (if it was the same file,
3583 ;; it would have become an internal link...)
3584 (setq id-file
(file-relative-name
3585 id-file
(file-name-directory org-current-export-file
)))
3586 (setq id-file
(concat (file-name-sans-extension id-file
)
3587 "." html-extension
))
3588 (setq rpl
(concat "<a href=\"" id-file
"#" path
"\""
3590 (org-export-html-format-desc desc
)
3592 ((member type
'("http" "https"))
3593 ;; standard URL, just check if we need to inline an image
3594 (if (and (or (eq t org-export-html-inline-images
)
3595 (and org-export-html-inline-images
(not descp
)))
3596 (org-file-image-p path
))
3597 (setq rpl
(org-export-html-format-image
3598 (concat type
":" path
)))
3599 (setq link
(concat type
":" path
))
3600 (setq rpl
(concat "<a href=\""
3601 (org-export-html-format-href link
)
3603 (org-export-html-format-desc desc
)
3605 ((member type
'("ftp" "mailto" "news"))
3607 (setq link
(concat type
":" path
))
3608 (setq rpl
(concat "<a href=\""
3609 (org-export-html-format-href link
)
3611 (org-export-html-format-desc desc
)
3614 ((string= type
"coderef")
3616 (setq rpl
(format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3618 (format (org-export-get-coderef-format path
(and descp desc
))
3619 (cdr (assoc path org-export-code-refs
))))))
3621 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3622 ;; The link protocol has a function for format the link
3625 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3627 ((string= type
"file")
3629 (let* ((filename path
)
3630 (abs-p (file-name-absolute-p filename
))
3631 thefile file-is-image-p search
)
3633 (if (string-match "::\\(.*\\)" filename
)
3634 (setq search
(match-string 1 filename
)
3635 filename
(replace-match "" t nil filename
)))
3637 (if (functionp link-validate
)
3638 (funcall link-validate filename current-dir
)
3640 (setq file-is-image-p
(org-file-image-p filename
))
3641 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3642 (when (and org-export-html-link-org-files-as-html
3643 (string-match "\\.org$" thefile
))
3644 (setq thefile
(concat (substring thefile
0
3645 (match-beginning 0))
3646 "." html-extension
))
3648 ;; make sure this is can be used as target search
3649 (not (string-match "^[0-9]*$" search
))
3650 (not (string-match "^\\*" search
))
3651 (not (string-match "^/.*/$" search
)))
3652 (setq thefile
(concat thefile
"#"
3653 (org-solidify-link-text
3654 (org-link-unescape search
)))))
3655 (when (string-match "^file:" desc
)
3656 (setq desc
(replace-match "" t t desc
))
3657 (if (string-match "\\.org$" desc
)
3658 (setq desc
(replace-match "" t t desc
))))))
3659 (setq rpl
(if (and file-is-image-p
3660 (or (eq t org-export-html-inline-images
)
3661 (and org-export-html-inline-images
3663 (org-export-html-format-image thefile
)
3664 (concat "<a href=\"" thefile
"\"" attr
">"
3665 (org-export-html-format-desc desc
)
3667 (if (not valid
) (setq rpl desc
))))
3670 ;; just publish the path, as default
3671 (setq rpl
(concat "<i><" type
":"
3672 (save-match-data (org-link-unescape path
))
3674 (setq line
(replace-match rpl t t line
)
3675 start
(+ start
(length rpl
))))
3678 (if (and (string-match org-todo-line-regexp line
)
3679 (match-beginning 2))
3682 (concat (substring line
0 (match-beginning 2))
3684 (if (member (match-string 2 line
)
3687 "\">" (match-string 2 line
)
3688 "</span>" (substring line
(match-end 2)))))
3690 ;; Does this contain a reference to a footnote?
3691 (when org-export-with-footnotes
3693 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3694 (if (get-text-property (match-beginning 2) 'org-protected line
)
3695 (setq start
(match-end 2))
3696 (let ((n (match-string 2 line
)) extra a
)
3697 (if (setq a
(assoc n footref-seen
))
3699 (setcdr a
(1+ (cdr a
)))
3700 (setq extra
(format ".%d" (cdr a
))))
3702 (push (cons n
1) footref-seen
))
3706 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
3707 (match-string 1 line
) n extra n n
)
3711 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3712 ;; This is a headline
3713 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3714 txt
(match-string 2 line
))
3715 (if (string-match quote-re0 txt
)
3716 (setq txt
(replace-match "" t t txt
)))
3717 (if (<= level
(max umax umax-toc
))
3718 (setq head-count
(+ head-count
1)))
3720 ;; Close any local lists before inserting a new header line
3721 (while local-list-type
3722 (org-close-li (car local-list-type
))
3723 (insert (format "</%sl>\n" (car local-list-type
)))
3724 (pop local-list-type
))
3725 (setq local-list-indent nil
3727 (setq first-heading-pos
(or first-heading-pos
(point)))
3728 (org-html-level-start level txt umax
3729 (and org-export-with-toc
(<= level umax
))
3732 (when (string-match quote-re line
)
3733 (org-close-par-maybe)
3737 ((and org-export-with-tables
3738 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3739 (if (not table-open
)
3741 (setq table-open t table-buffer nil table-orig-buffer nil
))
3743 (setq table-buffer
(cons line table-buffer
)
3744 table-orig-buffer
(cons origline table-orig-buffer
))
3745 (when (or (not lines
)
3746 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3748 (setq table-open nil
3749 table-buffer
(nreverse table-buffer
)
3750 table-orig-buffer
(nreverse table-orig-buffer
))
3751 (org-close-par-maybe)
3752 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3757 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3758 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3759 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3760 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3762 (setq ind
(org-get-string-indentation line
)
3763 item-type
(if (match-beginning 4) "o" "u")
3764 starter
(if (match-beginning 2)
3765 (substring (match-string 2 line
) 0 -
1))
3766 line
(substring line
(match-beginning 5))
3768 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3770 item-tag
(match-string 1 line
)
3771 line
(substring line
(match-end 0))))
3772 (when (and (not (equal item-type
"d"))
3773 (not (string-match "[^ \t]" line
)))
3774 ;; empty line. Pretend indentation is large.
3775 (setq ind
(if org-empty-line-terminates-plain-lists
3777 (1+ (or (car local-list-indent
) 1)))))
3779 (while (and in-local-list
3780 (or (and (= ind
(car local-list-indent
))
3782 (< ind
(car local-list-indent
))))
3784 (org-close-li (car local-list-type
))
3785 (insert (format "</%sl>\n" (car local-list-type
)))
3786 (pop local-list-type
) (pop local-list-indent
)
3787 (setq in-local-list local-list-indent
))
3790 (or (not in-local-list
)
3791 (> ind
(car local-list-indent
))))
3792 ;; Start new (level of) list
3793 (org-close-par-maybe)
3795 ((equal item-type
"u") "<ul>\n<li>\n")
3796 ((equal item-type
"o") "<ol>\n<li>\n")
3797 ((equal item-type
"d")
3798 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3799 (push item-type local-list-type
)
3800 (push ind local-list-indent
)
3801 (setq in-local-list t
))
3803 ;; continue current list
3804 (org-close-li (car local-list-type
))
3806 ((equal (car local-list-type
) "d")
3807 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3810 ;; we did close a list, normal text follows: need <p>
3812 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3815 (if (equal (match-string 1 line
) "X")
3817 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3820 ;; Empty lines start a new paragraph. If hand-formatted lists
3821 ;; are not fully interpreted, lines starting with "-", "+", "*"
3822 ;; also start a new paragraph.
3823 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3825 ;; Is this the start of a footnote?
3826 (when org-export-with-footnotes
3827 (when (and (boundp 'footnote-section-tag-regexp
)
3828 (string-match (concat "^" footnote-section-tag-regexp
)
3831 (throw 'nextline nil
))
3832 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3833 (org-close-par-maybe)
3834 (let ((n (match-string 1 line
)))
3835 (setq org-par-open t
3837 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
3839 ;; Check if the line break needs to be conserved
3841 ((string-match "\\\\\\\\[ \t]*$" line
)
3842 (setq line
(replace-match "<br/>" t t line
)))
3843 (org-export-preserve-breaks
3844 (setq line
(concat line
"<br/>"))))
3846 (insert line
"\n")))))
3848 ;; Properly close all local lists and other lists
3853 ;; Close any local lists before inserting a new header line
3854 (while local-list-type
3855 (org-close-li (car local-list-type
))
3856 (insert (format "</%sl>\n" (car local-list-type
)))
3857 (pop local-list-type
))
3858 (setq local-list-indent nil
3860 (org-html-level-start 1 nil umax
3861 (and org-export-with-toc
(<= level umax
))
3863 ;; the </div> to close the last text-... div.
3864 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
3867 (goto-char (point-min))
3868 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
3869 (push (match-string 0) footnotes
)
3870 (replace-match "" t t
)))
3872 (insert (format org-export-html-footnotes-section
3873 (or (nth 4 lang-words
) "Footnotes")
3874 (mapconcat 'identity
(nreverse footnotes
) "\n"))
3877 (when (plist-get opt-plist
:auto-postamble
)
3878 (insert "<div id=\"postamble\">")
3879 (when (and org-export-author-info author
)
3880 (insert "<p class=\"author\"> "
3881 (nth 1 lang-words
) ": " author
"\n")
3883 (if (listp (split-string email
",+ *"))
3885 (insert "<a href=\"mailto:" e
"\"><"
3887 (split-string email
",+ *"))
3888 (insert "<a href=\"mailto:" email
"\"><"
3889 email
"></a>\n")))
3891 (when (and date org-export-time-stamp-file
)
3892 (insert "<p class=\"date\"> "
3893 (nth 2 lang-words
) ": "
3895 (when org-export-creator-info
3896 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3897 org-version emacs-major-version
)))
3900 (if org-export-html-with-timestamp
3901 (insert org-export-html-html-helper-timestamp
))
3902 (insert (or (plist-get opt-plist
:postamble
) ""))
3903 (insert "</body>\n</html>\n"))
3905 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3907 (if (eq major-mode default-major-mode
) (html-mode)))
3909 ;; insert the table of contents
3910 (goto-char (point-min))
3912 (if (or (re-search-forward
3913 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3915 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3917 (goto-char (match-beginning 0))
3919 (goto-char first-heading-pos
)
3920 (when (looking-at "\\s-*</p>")
3921 (goto-char (match-end 0))
3923 (insert "<div id=\"table-of-contents\">\n")
3924 (mapc 'insert thetoc
)
3925 (insert "</div>\n"))
3926 ;; remove empty paragraphs and lists
3927 (goto-char (point-min))
3928 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3930 (goto-char (point-min))
3931 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3933 (goto-char (point-min))
3934 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3936 ;; Convert whitespace place holders
3937 (goto-char (point-min))
3939 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3940 (setq n
(get-text-property beg
'org-whitespace
)
3941 end
(next-single-property-change beg
'org-whitespace
))
3943 (delete-region beg end
)
3944 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3945 (make-string n ?x
)))))
3946 (or to-buffer
(save-buffer))
3947 (goto-char (point-min))
3948 (message "Exporting... done")
3949 (if (eq to-buffer
'string
)
3950 (prog1 (buffer-substring (point-min) (point-max))
3951 (kill-buffer (current-buffer)))
3952 (current-buffer)))))
3954 (defun org-export-get-coderef-format (path desc
)
3956 (if (and desc
(string-match
3957 (regexp-quote (concat "(" path
")"))
3959 (replace-match "%s" t t desc
)
3963 (defun org-export-html-format-href (s)
3964 "Make sure the S is valid as a href reference in an XHTML document."
3967 (while (string-match "&" s start
)
3968 (setq start
(+ (match-beginning 0) 3)
3969 s
(replace-match "&" t t s
)))))
3972 (defun org-export-html-format-desc (s)
3973 "Make sure the S is valid as a description in a link."
3974 (if (and s
(not (get-text-property 1 'org-protected s
)))
3976 (org-html-do-expand s
))
3979 (defun org-export-html-format-image (src)
3980 "Create image tag with source and attributes."
3982 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
3983 (attr (org-find-text-property-in-string 'org-attributes src
))
3984 (label (org-find-text-property-in-string 'org-label src
)))
3985 (format "<div %sclass=\"figure\">
3986 <p><img src=\"%s\"%s /></p>%s
3988 (if label
(format "id=\"%s\" " label
) "")
3990 (if (string-match "\\<alt=" (or attr
""))
3992 (concat " " attr
" alt=\"" src
"\""))
3993 (if caption
(concat "\n<p>" caption
"</p>") "")))))
3995 (defvar org-table-colgroup-info nil
)
3996 (defun org-format-table-ascii (lines)
3997 "Format a table for ascii export."
3999 (setq lines
(org-split-string lines
"\n")))
4000 (if (not (string-match "^[ \t]*|" (car lines
)))
4001 ;; Table made by table.el - test for spanning
4004 ;; A normal org table
4005 ;; Get rid of hlines at beginning and end
4006 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4007 (setq lines
(nreverse lines
))
4008 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4009 (setq lines
(nreverse lines
))
4010 (when org-export-table-remove-special-lines
4011 ;; Check if the table has a marking column. If yes remove the
4012 ;; column and the special lines
4013 (setq lines
(org-table-clean-before-export lines
)))
4014 ;; Get rid of the vertical lines except for grouping
4015 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
4017 (while (setq line
(pop lines
))
4018 (if (string-match org-table-hline-regexp line
)
4019 (and (string-match "|\\(.*\\)|" line
)
4020 (setq line
(replace-match " \\1" t nil line
)))
4021 (setq start
0 vl1 vl
)
4022 (while (string-match "|" line start
)
4023 (setq start
(match-end 0))
4024 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
4028 (defun org-colgroup-info-to-vline-list (info)
4031 (setq last new new
(pop info
))
4032 (if (or (memq last
'(:end
:startend
))
4033 (memq new
'(:start
:startend
)))
4036 (setq vl
(nreverse vl
))
4037 (and vl
(setcar vl nil
))
4040 (defvar org-table-number-regexp
) ; defined in org-table.el
4041 (defun org-format-table-html (lines olines
)
4042 "Find out which HTML converter to use and return the HTML code."
4044 (setq lines
(org-split-string lines
"\n")))
4045 (if (string-match "^[ \t]*|" (car lines
))
4046 ;; A normal org table
4047 (org-format-org-table-html lines
)
4048 ;; Table made by table.el - test for spanning
4049 (let* ((hlines (delq nil
(mapcar
4051 (if (string-match "^[ \t]*\\+-" x
) x
4054 (first (car hlines
))
4055 (ll (and (string-match "\\S-+" first
)
4056 (match-string 0 first
)))
4057 (re (concat "^[ \t]*" (regexp-quote ll
)))
4058 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
4060 (if (and (not spanning
)
4061 (not org-export-prefer-native-exporter-for-tables
))
4062 ;; We can use my own converter with HTML conversions
4063 (org-format-table-table-html lines
)
4064 ;; Need to use the code generator in table.el, with the original text.
4065 (org-format-table-table-html-using-table-generate-source olines
)))))
4067 (defvar org-table-number-fraction
) ; defined in org-table.el
4068 (defun org-format-org-table-html (lines &optional splice
)
4069 "Format a table into HTML."
4070 (require 'org-table
)
4071 ;; Get rid of hlines at beginning and end
4072 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4073 (setq lines
(nreverse lines
))
4074 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4075 (setq lines
(nreverse lines
))
4076 (when org-export-table-remove-special-lines
4077 ;; Check if the table has a marking column. If yes remove the
4078 ;; column and the special lines
4079 (setq lines
(org-table-clean-before-export lines
)))
4081 (let ((caption (or (get-text-property 0 'org-caption
(car lines
))
4082 (get-text-property (or (next-single-property-change
4083 0 'org-caption
(car lines
))
4085 'org-caption
(car lines
))))
4086 (head (and org-export-highlight-first-table-line
4088 (lambda (x) (string-match "^[ \t]*|-" x
))
4092 tbopen line fields html gr colgropen
)
4093 (if splice
(setq head nil
))
4094 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
4096 (while (setq line
(pop lines
))
4098 (if (string-match "^[ \t]*|-" line
)
4101 (push (if head
"</thead>" "</tbody>") html
)
4102 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
4103 (setq head nil
) ;; head ends here, first time around
4105 (throw 'next-line t
)))
4106 ;; Break the line into fields
4107 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4108 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
4109 (setq nlines
(1+ nlines
) i -
1)
4110 (push (concat "<tr>"
4114 (if (and (< i nlines
)
4115 (string-match org-table-number-regexp x
))
4116 (incf (aref fnum i
)))
4118 (concat (car org-export-table-header-tags
) x
4119 (cdr org-export-table-header-tags
))
4120 (concat (car org-export-table-data-tags
) x
4121 (cdr org-export-table-data-tags
))))
4125 (unless splice
(if tbopen
(push "</tbody>" html
)))
4126 (unless splice
(push "</table>\n" html
))
4127 (setq html
(nreverse html
))
4129 ;; Put in col tags with the alignment (unfortunately often ignored...)
4132 (setq gr
(pop org-table-colgroup-info
))
4133 (format "%s<col align=\"%s\"></col>%s"
4134 (if (memq gr
'(:start
:startend
))
4136 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
4139 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
4141 (if (memq gr
'(:end
:startend
))
4142 (progn (setq colgropen nil
) "</colgroup>")
4146 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
4147 (if caption
(push (format "<caption>%s</caption>" caption
) html
))
4148 (push html-table-tag html
))
4149 (concat (mapconcat 'identity html
"\n") "\n")))
4151 (defun org-table-clean-before-export (lines)
4152 "Check if the table has a marking column.
4153 If yes remove the column and the special lines."
4154 (setq org-table-colgroup-info nil
)
4157 (lambda (x) (or (string-match "^[ \t]*|-" x
)
4158 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
4161 (setq org-table-clean-did-remove-column nil
)
4166 ((string-match "^[ \t]*| */ *|" x
)
4167 (setq org-table-colgroup-info
4169 (cond ((member x
'("<" "<")) :start
)
4170 ((member x
'(">" ">")) :end
)
4171 ((member x
'("<>" "<>")) :startend
)
4173 (org-split-string x
"[ \t]*|[ \t]*")))
4177 (setq org-table-clean-did-remove-column t
)
4182 ((string-match "^[ \t]*| */ *|" x
)
4183 (setq org-table-colgroup-info
4185 (cond ((member x
'("<" "<")) :start
)
4186 ((member x
'(">" ">")) :end
)
4187 ((member x
'("<>" "<>")) :startend
)
4189 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
4191 ((string-match "^[ \t]*| *[!_^/] *|" x
)
4192 nil
) ; ignore this line
4193 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
4194 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
4195 ;; remove the first column
4196 (replace-match "\\1|" t nil x
))))
4199 (defun org-format-table-table-html (lines)
4200 "Format a table generated by table.el into HTML.
4201 This conversion does *not* use `table-generate-source' from table.el.
4202 This has the advantage that Org-mode's HTML conversions can be used.
4203 But it has the disadvantage, that no cell- or row-spanning is allowed."
4204 (let (line field-buffer
4205 (head org-export-highlight-first-table-line
)
4207 (setq html
(concat html-table-tag
"\n"))
4208 (while (setq line
(pop lines
))
4209 (setq empty
" ")
4211 (if (string-match "^[ \t]*\\+-" line
)
4222 (if (equal x
"") (setq x empty
))
4224 (concat (car org-export-table-header-tags
) x
4225 (cdr org-export-table-header-tags
))
4226 (concat (car org-export-table-data-tags
) x
4227 (cdr org-export-table-data-tags
))))
4231 (setq field-buffer nil
)))
4233 (throw 'next-line t
)))
4234 ;; Break the line into fields and store the fields
4235 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4237 (setq field-buffer
(mapcar
4239 (concat x
"<br/>" (pop fields
)))
4241 (setq field-buffer fields
))))
4242 (setq html
(concat html
"</table>\n"))
4245 (defun org-format-table-table-html-using-table-generate-source (lines)
4246 "Format a table into html, using `table-generate-source' from table.el.
4247 This has the advantage that cell- or row-spanning is allowed.
4248 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4250 (with-current-buffer (get-buffer-create " org-tmp1 ")
4252 (insert (mapconcat 'identity lines
"\n"))
4253 (goto-char (point-min))
4254 (if (not (re-search-forward "|[^+]" nil t
))
4255 (error "Error processing table"))
4256 (table-recognize-table)
4257 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4258 (table-generate-source 'html
" org-tmp2 ")
4259 (set-buffer " org-tmp2 ")
4260 (buffer-substring (point-min) (point-max))))
4262 (defun org-export-splice-style (style extra
)
4263 "Splice EXTRA into STYLE, just before \"</style>\"."
4264 (if (and (stringp extra
)
4265 (string-match "\\S-" extra
)
4266 (string-match "</style>" style
))
4267 (concat (substring style
0 (match-beginning 0))
4269 (substring style
(match-beginning 0)))
4272 (defun org-html-handle-time-stamps (s)
4273 "Format time stamps in string S, or remove them."
4276 (while (string-match org-maybe-keyword-time-regexp s
)
4277 (or b
(setq b
(substring s
0 (match-beginning 0))))
4279 r
(substring s
0 (match-beginning 0))
4281 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4282 (match-string 1 s
)))
4283 (format " @<span class=\"timestamp\">%s@</span>"
4285 (org-translate-time (match-string 3 s
)) 1 -
1)))
4286 s
(substring s
(match-end 0))))
4287 ;; Line break if line started and ended with time stamp stuff
4290 (setq r
(concat r s
))
4291 (unless (string-match "\\S-" (concat b s
))
4292 (setq r
(concat r
"@<br/>")))
4295 (defun org-export-htmlize-region-for-paste (beg end
)
4296 "Convert the region to HTML, using htmlize.el.
4297 This is much like `htmlize-region-for-paste', only that it uses
4298 the settings define in the org-... variables."
4299 (let* ((htmlize-output-type org-export-htmlize-output-type
)
4300 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
4301 (htmlbuf (htmlize-region beg end
)))
4303 (with-current-buffer htmlbuf
4304 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
4305 (plist-get htmlize-buffer-places
'content-end
)))
4306 (kill-buffer htmlbuf
))))
4309 (defun org-export-htmlize-generate-css ()
4310 "Create the CSS for all font definitions in the current Emacs session.
4311 Use this to create face definitions in your CSS style file that can then
4312 be used by code snippets transformed by htmlize.
4313 This command just produces a buffer that contains class definitions for all
4314 faces used in the current Emacs session. You can copy and paste the ones you
4315 need into your CSS file.
4317 If you then set `org-export-htmlize-output-type' to `css', calls to
4318 the function `org-export-htmlize-region-for-paste' will produce code
4319 that uses these same face definitions."
4322 (and (get-buffer "*html*") (kill-buffer "*html*"))
4324 (let ((fl (face-list))
4325 (htmlize-css-name-prefix "org-")
4326 (htmlize-output-type 'css
)
4328 (while (setq f
(pop fl
)
4329 i
(and f
(face-attribute f
:inherit
)))
4330 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
4331 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
4332 (htmlize-region (point-min) (point-max))))
4333 (switch-to-buffer "*html*")
4334 (goto-char (point-min))
4335 (if (re-search-forward "<style" nil t
)
4336 (delete-region (point-min) (match-beginning 0)))
4337 (if (re-search-forward "</style>" nil t
)
4338 (delete-region (1+ (match-end 0)) (point-max)))
4339 (beginning-of-line 1)
4340 (if (looking-at " +") (replace-match ""))
4341 (goto-char (point-min)))
4343 (defun org-html-protect (s)
4344 ;; convert & to &, < to < and > to >
4346 (while (string-match "&" s start
)
4347 (setq s
(replace-match "&" t t s
)
4348 start
(1+ (match-beginning 0))))
4349 (while (string-match "<" s
)
4350 (setq s
(replace-match "<" t t s
)))
4351 (while (string-match ">" s
)
4352 (setq s
(replace-match ">" t t s
)))
4353 ; (while (string-match "\"" s)
4354 ; (setq s (replace-match """ t t s)))
4358 (defun org-export-cleanup-toc-line (s)
4359 "Remove tags and timestamps from lines going into the toc."
4360 (when (memq org-export-with-tags
'(not-in-toc nil
))
4361 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
4362 (setq s
(replace-match "" t t s
))))
4363 (when org-export-remove-timestamps-from-toc
4364 (while (string-match org-maybe-keyword-time-regexp s
)
4365 (setq s
(replace-match "" t t s
))))
4366 (while (string-match org-bracket-link-regexp s
)
4367 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
4371 (defun org-html-expand (string)
4372 "Prepare STRING for HTML export. Applies all active conversions.
4373 If there are links in the string, don't modify these."
4374 (let* ((re (concat org-bracket-link-regexp
"\\|"
4375 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4377 (while (setq m
(string-match re string
))
4378 (setq s
(substring string
0 m
)
4379 l
(match-string 0 string
)
4380 string
(substring string
(match-end 0)))
4381 (push (org-html-do-expand s
) res
)
4383 (push (org-html-do-expand string
) res
)
4384 (apply 'concat
(nreverse res
))))
4386 (defun org-html-do-expand (s)
4387 "Apply all active conversions to translate special ASCII to HTML."
4388 (setq s
(org-html-protect s
))
4389 (if org-export-html-expand
4391 (while (string-match "@<\\([^&]*\\)>" s
)
4392 (setq s
(replace-match "<\\1>" t nil s
)))))
4393 (if org-export-with-emphasize
4394 (setq s
(org-export-html-convert-emphasize s
)))
4395 (if org-export-with-special-strings
4396 (setq s
(org-export-html-convert-special-strings s
)))
4397 (if org-export-with-sub-superscripts
4398 (setq s
(org-export-html-convert-sub-super s
)))
4399 (if org-export-with-TeX-macros
4400 (let ((start 0) wd ass
)
4401 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4403 (if (get-text-property (match-beginning 0) 'org-protected s
)
4404 (setq start
(match-end 0))
4405 (setq wd
(match-string 1 s
))
4406 (if (setq ass
(assoc wd org-html-entities
))
4407 (setq s
(replace-match (or (cdr ass
)
4408 (concat "&" (car ass
) ";"))
4410 (setq start
(+ start
(length wd
))))))))
4413 (defun org-create-multibrace-regexp (left right n
)
4414 "Create a regular expression which will match a balanced sexp.
4415 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4416 as single character strings.
4417 The regexp returned will match the entire expression including the
4418 delimiters. It will also define a single group which contains the
4419 match except for the outermost delimiters. The maximum depth of
4420 stacked delimiters is N. Escaping delimiters is not possible."
4421 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4424 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4427 re
(concat re or next
)
4428 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4429 (concat left
"\\(" re
"\\)" right
)))
4431 (defvar org-match-substring-regexp
4433 "\\([^\\]\\)\\([_^]\\)\\("
4434 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4436 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4438 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4439 "The regular expression matching a sub- or superscript.")
4441 (defvar org-match-substring-with-braces-regexp
4443 "\\([^\\]\\)\\([_^]\\)\\("
4444 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4446 "The regular expression matching a sub- or superscript, forcing braces.")
4448 (defconst org-export-html-special-string-regexps
4449 '(("\\\\-" .
"­")
4450 ("---\\([^-]\\)" .
"—\\1")
4451 ("--\\([^-]\\)" .
"–\\1")
4452 ("\\.\\.\\." .
"…"))
4453 "Regular expressions for special string conversion.")
4455 (defun org-export-html-convert-special-strings (string)
4456 "Convert special characters in STRING to HTML."
4457 (let ((all org-export-html-special-string-regexps
)
4459 (while (setq a
(pop all
))
4460 (setq re
(car a
) rpl
(cdr a
) start
0)
4461 (while (string-match re string start
)
4462 (if (get-text-property (match-beginning 0) 'org-protected string
)
4463 (setq start
(match-end 0))
4464 (setq string
(replace-match rpl t nil string
)))))
4467 (defun org-export-html-convert-sub-super (string)
4468 "Convert sub- and superscripts in STRING to HTML."
4469 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4470 (while (string-match org-match-substring-regexp string s
)
4472 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4473 ((get-text-property (match-beginning 2) 'org-protected string
)
4474 (setq s
(match-end 2)))
4476 (setq s
(match-end 1)
4477 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4478 c
(or (match-string 8 string
)
4479 (match-string 6 string
)
4480 (match-string 5 string
))
4481 string
(replace-match
4482 (concat (match-string 1 string
)
4483 "<" key
">" c
"</" key
">")
4485 (while (string-match "\\\\\\([_^]\\)" string
)
4486 (setq string
(replace-match (match-string 1 string
) t t string
)))
4489 (defun org-export-html-convert-emphasize (string)
4492 (while (string-match org-emph-re string s
)
4494 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4495 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4496 (setq s
(match-beginning 0)
4499 (match-string 1 string
)
4500 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4501 (match-string 4 string
)
4502 (nth 3 (assoc (match-string 3 string
)
4503 org-emphasis-alist
))
4504 (match-string 5 string
))
4505 string
(replace-match rpl t t string
)
4506 s
(+ s
(- (length rpl
) 2)))
4510 (defun org-open-par ()
4511 "Insert <p>, but first close previous paragraph if any."
4512 (org-close-par-maybe)
4514 (setq org-par-open t
))
4515 (defun org-close-par-maybe ()
4516 "Close paragraph if there is one open."
4519 (setq org-par-open nil
)))
4520 (defun org-close-li (&optional type
)
4521 "Close <li> if necessary."
4522 (org-close-par-maybe)
4523 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4525 (defvar body-only
) ; dynamically scoped into this.
4526 (defun org-html-level-start (level title umax with-toc head-count
)
4527 "Insert a new level in HTML export.
4528 When TITLE is nil, just close all open levels."
4529 (org-close-par-maybe)
4530 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
4532 (mapconcat (lambda (x)
4533 (format "<a name=\"%s\" id=\"%s\"></a>"
4535 (cdr (assoc target org-export-target-aliases
))
4540 (if (aref org-levels-open
(1- l
))
4542 (org-html-level-close l umax
)
4543 (aset org-levels-open
(1- l
) nil
)))
4546 ;; If title is nil, this means this function is called to close
4547 ;; all levels, so the rest is done only if title is given
4548 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4549 (setq title
(replace-match
4550 (if org-export-with-tags
4553 " <span class=\"tag\">"
4554 (mapconcat 'identity
(org-split-string
4555 (match-string 1 title
) ":")
4562 (if (aref org-levels-open
(1- level
))
4566 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
4567 (insert "<li>" title
"<br/>\n")))
4568 (aset org-levels-open
(1- level
) t
)
4569 (org-close-par-maybe)
4571 (insert (format "<ul>\n<li id=\"%s\">" target
)
4572 extra-targets title
"<br/>\n")
4573 (insert "<ul>\n<li>" title
"<br/>\n"))))
4574 (aset org-levels-open
(1- level
) t
)
4575 (setq snumber
(org-section-number level
))
4576 (if (and org-export-with-section-numbers
(not body-only
))
4577 (setq title
(concat snumber
" " title
)))
4578 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4579 (unless (= head-count
1) (insert "\n</div>\n"))
4580 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div id=\"text-%s\">\n"
4581 snumber level level snumber extra-targets title level snumber
))
4584 (defun org-get-text-property-any (pos prop
&optional object
)
4585 (or (get-text-property pos prop object
)
4586 (and (setq pos
(next-single-property-change pos prop object
))
4587 (get-text-property pos prop object
))))
4589 (defun org-html-level-close (level max-outline-level
)
4590 "Terminate one level in HTML export."
4591 (if (<= level max-outline-level
)
4594 (insert "</ul>\n")))
4596 ;;; iCalendar export
4599 (defun org-export-icalendar-this-file ()
4600 "Export current file as an iCalendar file.
4601 The iCalendar file will be located in the same directory as the Org-mode
4602 file, but with extension `.ics'."
4604 (org-export-icalendar nil buffer-file-name
))
4607 (defun org-export-icalendar-all-agenda-files ()
4608 "Export all files in `org-agenda-files' to iCalendar .ics files.
4609 Each iCalendar file will be located in the same directory as the Org-mode
4610 file, but with extension `.ics'."
4612 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4615 (defun org-export-icalendar-combine-agenda-files ()
4616 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4617 The file is stored under the name `org-combined-agenda-icalendar-file'."
4619 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4621 (defun org-export-icalendar (combine &rest files
)
4622 "Create iCalendar files for all elements of FILES.
4623 If COMBINE is non-nil, combine all calendar entries into a single large
4624 file and store it under the name `org-combined-agenda-icalendar-file'."
4626 (org-prepare-agenda-buffers files
)
4627 (let* ((dir (org-export-directory
4628 :ical
(list :publishing-directory
4629 org-export-publishing-directory
)))
4630 file ical-file ical-buffer category started org-agenda-new-buffers
)
4631 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4634 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4635 org-combined-agenda-icalendar-file
4636 (expand-file-name org-combined-agenda-icalendar-file dir
))
4637 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4638 (set-buffer ical-buffer
) (erase-buffer))
4639 (while (setq file
(pop files
))
4641 (org-check-agenda-file file
)
4642 (set-buffer (org-get-agenda-file-buffer file
))
4644 (setq ical-file
(concat (file-name-as-directory dir
)
4645 (file-name-sans-extension
4646 (file-name-nondirectory buffer-file-name
))
4648 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4649 (with-current-buffer ical-buffer
(erase-buffer)))
4650 (setq category
(or org-category
4651 (file-name-sans-extension
4652 (file-name-nondirectory buffer-file-name
))))
4653 (if (symbolp category
) (setq category
(symbol-name category
)))
4654 (let ((standard-output ical-buffer
))
4656 (and (not started
) (setq started t
)
4657 (org-start-icalendar-file org-icalendar-combined-name
))
4658 (org-start-icalendar-file category
))
4659 (org-print-icalendar-entries combine
)
4660 (when (or (and combine
(not files
)) (not combine
))
4661 (org-finish-icalendar-file)
4662 (set-buffer ical-buffer
)
4663 (run-hooks 'org-before-save-iCalendar-file-hook
)
4665 (run-hooks 'org-after-save-iCalendar-file-hook
)
4666 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4668 (org-release-buffers org-agenda-new-buffers
))))
4670 (defvar org-before-save-iCalendar-file-hook nil
4671 "Hook run before an iCalendar file has been saved.
4672 This can be used to modify the result of the export.")
4674 (defvar org-after-save-iCalendar-file-hook nil
4675 "Hook run after an iCalendar file has been saved.
4676 The iCalendar buffer is still current when this hook is run.
4677 A good way to use this is to tell a desktop calendar application to re-read
4678 the iCalendar file.")
4680 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4681 (defun org-print-icalendar-entries (&optional combine
)
4682 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4683 When COMBINE is non nil, add the category to each line."
4684 (require 'org-agenda
)
4685 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4686 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4687 (dts (org-ical-ts-to-string
4688 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4690 hd ts ts2 state status
(inc t
) pos b sexp rrule
4691 scheduledp deadlinep todo prefix due start
4692 tmp pri categories entry location summary desc uid
4693 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4694 (org-refresh-category-properties)
4696 (goto-char (point-min))
4697 (while (re-search-forward re1 nil t
)
4700 (when (boundp 'org-icalendar-verify-function
)
4701 (unless (funcall org-icalendar-verify-function
)
4702 (outline-next-heading)
4705 (setq pos
(match-beginning 0)
4708 hd
(condition-case nil
4709 (org-icalendar-cleanup-string
4711 (error (throw :skip nil
)))
4712 summary
(org-icalendar-cleanup-string
4713 (org-entry-get nil
"SUMMARY"))
4714 desc
(org-icalendar-cleanup-string
4715 (or (org-entry-get nil
"DESCRIPTION")
4716 (and org-icalendar-include-body
(org-get-entry)))
4717 t org-icalendar-include-body
)
4718 location
(org-icalendar-cleanup-string
4719 (org-entry-get nil
"LOCATION" 'selective
))
4720 uid
(if org-icalendar-store-UID
4722 (or (org-id-get) (org-id-new)))
4723 categories
(org-export-get-categories)
4724 deadlinep nil scheduledp nil
)
4725 (if (looking-at re2
)
4727 (goto-char (match-end 0))
4728 (setq ts2
(match-string 1)
4729 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4730 (setq tmp
(buffer-substring (max (point-min)
4731 (- pos org-ds-keyword-length
))
4733 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4736 (replace-match "\\1" t nil ts
))
4738 deadlinep
(string-match org-deadline-regexp tmp
)
4739 scheduledp
(string-match org-scheduled-regexp tmp
)
4740 todo
(org-get-todo-state)
4741 ;; donep (org-entry-is-done-p)
4746 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4747 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4752 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4753 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4755 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4756 (if (or (string-match org-tr-regexp hd
)
4757 (string-match org-ts-regexp hd
))
4758 (setq hd
(replace-match "" t t hd
)))
4759 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4761 (concat "\nRRULE:FREQ="
4764 '(("d" .
"DAILY")("w" .
"WEEKLY")
4765 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4766 ";INTERVAL=" (match-string 1 ts
)))
4768 (setq summary
(or summary hd
))
4769 (if (string-match org-bracket-link-regexp summary
)
4771 (replace-match (if (match-end 3)
4772 (match-string 3 summary
)
4773 (match-string 1 summary
))
4775 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4776 (if scheduledp
(setq summary
(concat "S: " summary
)))
4777 (if (string-match "\\`<%%" ts
)
4778 (with-current-buffer sexp-buffer
4779 (insert (substring ts
1 -
1) " " summary
"\n"))
4780 (princ (format "BEGIN:VEVENT
4788 (org-ical-ts-to-string ts
"DTSTART")
4789 (org-ical-ts-to-string ts2
"DTEND" inc
)
4791 (if (and desc
(string-match "\\S-" desc
))
4792 (concat "\nDESCRIPTION: " desc
) "")
4793 (if (and location
(string-match "\\S-" location
))
4794 (concat "\nLOCATION: " location
) "")
4796 (when (and org-icalendar-include-sexps
4797 (condition-case nil
(require 'icalendar
) (error nil
))
4798 (fboundp 'icalendar-export-region
))
4799 ;; Get all the literal sexps
4800 (goto-char (point-min))
4801 (while (re-search-forward "^&?%%(" nil t
)
4804 (setq b
(match-beginning 0))
4805 (goto-char (1- (match-end 0)))
4808 (setq sexp
(buffer-substring b
(point)))
4809 (with-current-buffer sexp-buffer
4810 (insert sexp
"\n"))))
4811 (princ (org-diary-to-ical-string sexp-buffer
))
4812 (kill-buffer sexp-buffer
))
4814 (when org-icalendar-include-todo
4815 (setq prefix
"TODO-")
4816 (goto-char (point-min))
4817 (while (re-search-forward org-todo-line-regexp nil t
)
4820 (when (boundp 'org-icalendar-verify-function
)
4821 (unless (funcall org-icalendar-verify-function
)
4822 (outline-next-heading)
4825 (setq state
(match-string 2))
4826 (setq status
(if (member state org-done-keywords
)
4827 "COMPLETED" "NEEDS-ACTION"))
4829 (or (not (member state org-done-keywords
))
4830 (eq org-icalendar-include-todo
'all
))
4831 (not (member org-archive-tag
(org-get-tags-at)))
4833 (setq hd
(match-string 3)
4834 summary
(org-icalendar-cleanup-string
4835 (org-entry-get nil
"SUMMARY"))
4836 desc
(org-icalendar-cleanup-string
4837 (or (org-entry-get nil
"DESCRIPTION")
4838 (and org-icalendar-include-body
(org-get-entry)))
4839 t org-icalendar-include-body
)
4840 location
(org-icalendar-cleanup-string
4841 (org-entry-get nil
"LOCATION" 'selective
))
4842 due
(and (member 'todo-due org-icalendar-use-deadline
)
4843 (org-entry-get nil
"DEADLINE"))
4844 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4845 (org-entry-get nil
"SCHEDULED"))
4846 categories
(org-export-get-categories)
4847 uid
(if org-icalendar-store-UID
4849 (or (org-id-get) (org-id-new))))
4850 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4851 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4853 (if (string-match org-bracket-link-regexp hd
)
4854 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4855 (match-string 1 hd
))
4857 (if (string-match org-priority-regexp hd
)
4858 (setq pri
(string-to-char (match-string 2 hd
))
4859 hd
(concat (substring hd
0 (match-beginning 1))
4860 (substring hd
(match-end 1))))
4861 (setq pri org-default-priority
))
4862 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4863 (- org-lowest-priority org-highest-priority
))))))
4865 (princ (format "BEGIN:VTODO
4877 (if (and location
(string-match "\\S-" location
))
4878 (concat "\nLOCATION: " location
) "")
4879 (if (and desc
(string-match "\\S-" desc
))
4880 (concat "\nDESCRIPTION: " desc
) "")
4881 (if due
(concat "\n" due
) "")
4885 (defun org-export-get-categories ()
4886 "Get categories according to `org-icalendar-categories'."
4887 (let ((cs org-icalendar-categories
) c rtn tmp
)
4888 (while (setq c
(pop cs
))
4890 ((eq c
'category
) (push (org-get-category) rtn
))
4892 (setq tmp
(org-get-todo-state))
4893 (and tmp
(push tmp rtn
)))
4895 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4897 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4898 (mapconcat 'identity
(nreverse rtn
) ",")))
4900 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4901 "Take out stuff and quote what needs to be quoted.
4902 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4903 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4908 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4909 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4910 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4911 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4913 (while (string-match "\\([,;]\\)" s start
)
4914 (setq start
(+ (match-beginning 0) 2)
4915 s
(replace-match "\\\\\\1" nil nil s
))))
4916 (setq s
(org-trim s
))
4918 (while (string-match "[ \t]*\n[ \t]*" s
)
4919 (setq s
(replace-match "\\n" t t s
))))
4922 (if (and (numberp maxlength
)
4923 (> (length s
) maxlength
))
4924 (setq s
(substring s
0 maxlength
)))))
4927 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength
)
4928 "Take out stuff and quote what needs to be quoted.
4929 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4930 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4932 This seems to be more like RFC 2455, but it causes problems, so it is
4933 not used right now."
4937 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4938 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4939 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4940 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))
4941 (setq s
(org-trim s
))
4942 (while (string-match "[ \t]*\n[ \t]*" s
)
4943 (setq s
(replace-match "\\n" t t s
)))
4945 (if (and (numberp maxlength
)
4946 (> (length s
) maxlength
))
4947 (setq s
(substring s
0 maxlength
)))))
4948 (setq s
(org-trim s
)))
4949 (while (string-match "\"" s
) (setq s
(replace-match "''" t t s
)))
4950 (when (string-match "[;,:]" s
) (setq s
(concat "\"" s
"\"")))
4953 (defun org-get-entry ()
4954 "Clean-up description string."
4956 (org-back-to-heading t
)
4957 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4959 (defun org-start-icalendar-file (name)
4960 "Start an iCalendar file by inserting the header."
4961 (let ((user user-full-name
)
4962 (name (or name
"unknown"))
4963 (timezone (cadr (current-time-zone))))
4965 (format "BEGIN:VCALENDAR
4968 PRODID:-//%s//Emacs with Org-mode//EN
4970 CALSCALE:GREGORIAN\n" name user timezone
))))
4972 (defun org-finish-icalendar-file ()
4973 "Finish an iCalendar file by inserting the END statement."
4974 (princ "END:VCALENDAR\n"))
4976 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4977 "Take a time string S and convert it to iCalendar format.
4978 KEYWORD is added in front, to make a complete line like DTSTART....
4979 When INC is non-nil, increase the hour by two (if time string contains
4980 a time), or the day by one (if it does not contain a time)."
4981 (let ((t1 (org-parse-time-string s
'nodefault
))
4982 t2 fmt have-time time
)
4983 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4984 (setq t2 t1 have-time t
)
4985 (setq t2
(org-parse-time-string s
)))
4986 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4987 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4990 (if org-agenda-default-appointment-duration
4991 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4994 (setq time
(encode-time s mi h d m y
)))
4995 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4996 (concat keyword
(format-time-string fmt time
))))
5000 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
5001 (with-current-buffer buffer
5002 (apply 'insert output
)))
5003 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
5006 (defun org-export-as-xoxo (&optional buffer
)
5007 "Export the org buffer as XOXO.
5008 The XOXO buffer is named *xoxo-<source buffer name>*"
5009 (interactive (list (current-buffer)))
5010 ;; A quickie abstraction
5012 ;; Output everything as XOXO
5013 (with-current-buffer (get-buffer buffer
)
5014 (let* ((pos (point))
5015 (opt-plist (org-combine-plists (org-default-export-plist)
5016 (org-infile-export-plist)))
5017 (filename (concat (file-name-as-directory
5018 (org-export-directory :xoxo opt-plist
))
5019 (file-name-sans-extension
5020 (file-name-nondirectory buffer-file-name
))
5022 (out (find-file-noselect filename
))
5025 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
5026 ;; Check the output buffer is empty.
5027 (with-current-buffer out
(erase-buffer))
5028 ;; Kick off the output
5029 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
5030 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
5031 (let* ((hd (match-string-no-properties 1))
5034 (match-string-no-properties 2)
5036 (goto-char (match-end 0))
5041 (if (looking-at "^[ \t]\\(.*\\)")
5042 (setq str
(concat str
(match-string-no-properties 1)))
5043 (throw 'loop str
)))))))))
5045 ;; Handle level rendering
5047 ((> level last-level
)
5048 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
5050 ((< level last-level
)
5051 (dotimes (- (- last-level level
) 1)
5053 (org-export-as-xoxo-insert-into out
"</li>\n"))
5054 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5056 (org-export-as-xoxo-insert-into out
"</li>\n")
5057 (setq hanging-li nil
)))
5059 ((equal level last-level
)
5061 (org-export-as-xoxo-insert-into out
"</li>\n")))
5064 (setq last-level level
)
5066 ;; And output the new li
5067 (setq hanging-li
't
)
5068 (if (equal ?
+ (elt text
0))
5069 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
5070 (org-export-as-xoxo-insert-into out
"<li>" text
))))
5072 ;; Finally finish off the ol
5073 (dotimes (- last-level
1)
5075 (org-export-as-xoxo-insert-into out
"</li>\n"))
5076 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5079 ;; Finish the buffer off and clean it up.
5080 (switch-to-buffer-other-window out
)
5081 (indent-region (point-min) (point-max) nil
)
5083 (goto-char (point-min))
5088 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
5090 ;;; org-exp.el ends here