Export: Make validation link fully configurable
[org-mode.git] / lisp / org-exp.el
blobf802ce79e6b4d7d464480232328771ac51f6052e
1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 6.23trans
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 (require 'org)
30 (require 'org-agenda)
31 (eval-and-compile
32 (require 'cl))
34 (declare-function org-export-latex-preprocess "org-export-latex" ())
35 (declare-function org-agenda-skip "org-agenda" ())
36 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
37 (declare-function htmlize-region "ext:htmlize" (beg end))
38 (declare-function org-id-find-id-file "org-id" (id))
39 (defvar htmlize-buffer-places) ; from htmlize.el
41 (defgroup org-export nil
42 "Options for exporting org-listings."
43 :tag "Org Export"
44 :group 'org)
46 (defgroup org-export-general nil
47 "General options for exporting Org-mode files."
48 :tag "Org Export General"
49 :group 'org-export)
51 ;; FIXME
52 (defvar org-export-publishing-directory nil)
54 (defcustom org-export-run-in-background nil
55 "Non-nil means export and publishing commands will run in background.
56 This works by starting up a separate Emacs process visiting the same file
57 and doing the export from there.
58 Not all export commands are affected by this - only the ones which
59 actually write to a file, and that do not depend on the buffer state.
61 If this option is nil, you can still get background export by calling
62 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
64 If this option is t, the double prefix can be used to exceptionally
65 force an export command into the current process."
66 :group 'org-export-general
67 :type 'boolean)
70 (defcustom org-export-select-tags '("export")
71 "Tags that select a tree for export.
72 If any such tag is found in a buffer, all trees that do not carry one
73 of these tags will be deleted before export.
74 Inside trees that are selected like this, you can still deselect a
75 subtree by tagging it with one of the `org-export-exclude-tags'."
76 :group 'org-export-general
77 :type '(repeat (string :tag "Tag")))
79 (defcustom org-export-exclude-tags '("noexport")
80 "Tags that exclude a tree from export.
81 All trees carrying any of these tags will be excluded from export.
82 This is without condition, so even subtrees inside that carry one of the
83 `org-export-select-tags' will be removed."
84 :group 'org-export-general
85 :type '(repeat (string :tag "Tag")))
87 (defcustom org-export-with-special-strings t
88 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
89 When this option is turned on, these strings will be exported as:
91 Org HTML LaTeX
92 -----+----------+--------
93 \\- &shy; \\-
94 -- &ndash; --
95 --- &mdash; ---
96 ... &hellip; \ldots
98 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
99 :group 'org-export-translation
100 :type 'boolean)
102 (defcustom org-export-language-setup
103 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
104 ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
105 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
106 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
107 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
108 ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
109 ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
110 ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
111 ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
112 ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
113 ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
114 ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
115 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
116 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
117 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
118 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
119 ("pl" "Autor" "Data" "Spis tre&sacute;ci" "Przypis")
120 ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
121 "Terms used in export text, translated to different languages.
122 Use the variable `org-export-default-language' to set the language,
123 or use the +OPTION lines for a per-file setting."
124 :group 'org-export-general
125 :type '(repeat
126 (list
127 (string :tag "HTML language tag")
128 (string :tag "Author")
129 (string :tag "Date")
130 (string :tag "Table of Contents")
131 (string :tag "Footnotes"))))
133 (defcustom org-export-default-language "en"
134 "The default language of HTML export, as a string.
135 This should have an association in `org-export-language-setup'."
136 :group 'org-export-general
137 :type 'string)
139 (defcustom org-export-skip-text-before-1st-heading nil
140 "Non-nil means, skip all text before the first headline when exporting.
141 When nil, that text is exported as well."
142 :group 'org-export-general
143 :type 'boolean)
145 (defcustom org-export-headline-levels 3
146 "The last level which is still exported as a headline.
147 Inferior levels will produce itemize lists when exported.
148 Note that a numeric prefix argument to an exporter function overrides
149 this setting.
151 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
152 :group 'org-export-general
153 :type 'number)
155 (defcustom org-export-with-section-numbers t
156 "Non-nil means, add section numbers to headlines when exporting.
158 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
159 :group 'org-export-general
160 :type 'boolean)
162 (defcustom org-export-section-number-format '((("1" ".")) . "")
163 "Format of section numbers for export.
164 The variable has two components.
165 1. A list of lists, each indicating a counter type and a separator.
166 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
167 It causes causes numeric, alphabetic, or roman counters, respectively.
168 The separator is only used if another counter for a subsection is being
169 added.
170 If there are more numbered section levels than entries in this lists,
171 then the last entry will be reused.
172 2. A terminator string that will be added after the entire
173 section number."
174 :group 'org-export-general
175 :type '(cons
176 (repeat
177 (list
178 (string :tag "Counter Type")
179 (string :tag "Separator ")))
180 (string :tag "Terminator")))
182 (defcustom org-export-with-toc t
183 "Non-nil means, create a table of contents in exported files.
184 The TOC contains headlines with levels up to`org-export-headline-levels'.
185 When an integer, include levels up to N in the toc, this may then be
186 different from `org-export-headline-levels', but it will not be allowed
187 to be larger than the number of headline levels.
188 When nil, no table of contents is made.
190 Headlines which contain any TODO items will be marked with \"(*)\" in
191 ASCII export, and with red color in HTML output, if the option
192 `org-export-mark-todo-in-toc' is set.
194 In HTML output, the TOC will be clickable.
196 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
197 or \"toc:3\"."
198 :group 'org-export-general
199 :type '(choice
200 (const :tag "No Table of Contents" nil)
201 (const :tag "Full Table of Contents" t)
202 (integer :tag "TOC to level")))
204 (defcustom org-export-mark-todo-in-toc nil
205 "Non-nil means, mark TOC lines that contain any open TODO items."
206 :group 'org-export-general
207 :type 'boolean)
209 (defcustom org-export-with-todo-keywords t
210 "Non-nil means, include TODO keywords in export.
211 When nil, remove all these keywords from the export."
212 :group 'org-export-general
213 :type 'boolean)
215 (defcustom org-export-with-priority nil
216 "Non-nil means, include priority cookies in export.
217 When nil, remove priority cookies for export."
218 :group 'org-export-general
219 :type 'boolean)
221 (defcustom org-export-preserve-breaks nil
222 "Non-nil means, preserve all line breaks when exporting.
223 Normally, in HTML output paragraphs will be reformatted. In ASCII
224 export, line breaks will always be preserved, regardless of this variable.
226 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
227 :group 'org-export-general
228 :type 'boolean)
230 (defcustom org-export-with-archived-trees 'headline
231 "Whether subtrees with the ARCHIVE tag should be exported.
232 This can have three different values
233 nil Do not export, pretend this tree is not present
234 t Do export the entire tree
235 headline Only export the headline, but skip the tree below it."
236 :group 'org-export-general
237 :group 'org-archive
238 :type '(choice
239 (const :tag "not at all" nil)
240 (const :tag "headline only" 'headline)
241 (const :tag "entirely" t)))
243 (defcustom org-export-author-info t
244 "Non-nil means, insert author name and email into the exported file.
246 This option can also be set with the +OPTIONS line,
247 e.g. \"author-info:nil\"."
248 :group 'org-export-general
249 :type 'boolean)
251 (defcustom org-export-creator-info t
252 "Non-nil means, the postamble should contain a creator sentence.
253 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
254 :group 'org-export-general
255 :type 'boolean)
257 (defcustom org-export-time-stamp-file t
258 "Non-nil means, insert a time stamp into the exported file.
259 The time stamp shows when the file was created.
261 This option can also be set with the +OPTIONS line,
262 e.g. \"timestamp:nil\"."
263 :group 'org-export-general
264 :type 'boolean)
266 (defcustom org-export-with-timestamps t
267 "If nil, do not export time stamps and associated keywords."
268 :group 'org-export-general
269 :type 'boolean)
271 (defcustom org-export-remove-timestamps-from-toc t
272 "If nil, remove timestamps from the table of contents entries."
273 :group 'org-export-general
274 :type 'boolean)
276 (defcustom org-export-with-tags 'not-in-toc
277 "If nil, do not export tags, just remove them from headlines.
278 If this is the symbol `not-in-toc', tags will be removed from table of
279 contents entries, but still be shown in the headlines of the document.
281 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
282 :group 'org-export-general
283 :type '(choice
284 (const :tag "Off" nil)
285 (const :tag "Not in TOC" not-in-toc)
286 (const :tag "On" t)))
288 (defcustom org-export-with-drawers nil
289 "Non-nil means, export with drawers like the property drawer.
290 When t, all drawers are exported. This may also be a list of
291 drawer names to export."
292 :group 'org-export-general
293 :type '(choice
294 (const :tag "All drawers" t)
295 (const :tag "None" nil)
296 (repeat :tag "Selected drawers"
297 (string :tag "Drawer name"))))
299 (defvar org-export-preprocess-hook nil
300 "Hook for preprocessing an export buffer.
301 Pretty much the first thing when exporting is running this hook.")
303 (defvar org-export-preprocess-after-include-files-hook nil
304 "Hook for preprocessing an export buffer.
305 This is run after the contents of included files have been inserted.")
307 (defvar org-export-preprocess-after-tree-selection-hook nil
308 "Hook for preprocessing an export buffer.
309 This is run after selection of trees to be exported has happened.
310 This selection includes tags-based selection, as well as removal
311 of commented and archived trees.")
313 (defvar org-export-preprocess-before-backend-specifics-hook nil
314 "Hook run before backend-specific functions are called during preprocessing.")
316 (defvar org-export-preprocess-final-hook nil
317 "Hook for preprocessing an export buffer.
318 This is run as the last thing in the preprocessing buffer, just before
319 returning the buffer string to the backend.")
321 (defgroup org-export-translation nil
322 "Options for translating special ascii sequences for the export backends."
323 :tag "Org Export Translation"
324 :group 'org-export)
326 (defcustom org-export-with-emphasize t
327 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
328 If the export target supports emphasizing text, the word will be
329 typeset in bold, italic, or underlined, respectively. Works only for
330 single words, but you can say: I *really* *mean* *this*.
331 Not all export backends support this.
333 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
334 :group 'org-export-translation
335 :type 'boolean)
337 (defcustom org-export-with-footnotes t
338 "If nil, export [1] as a footnote marker.
339 Lines starting with [1] will be formatted as footnotes.
341 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
342 :group 'org-export-translation
343 :type 'boolean)
345 (defcustom org-export-html-footnotes-section "<div id=\"footnotes\">
346 <h2 class=\"footnotes\">%s: </h2>
347 <div id=\"text-footnotes\">
349 </div>
350 </div>"
351 "Format for the footnotes section.
352 Should contain a two instances of %s. The first will be replaced with the
353 language-specific word for \"Footnotes\", the second one will be replaced
354 by the footnotes themselves."
355 :group 'org-export-html
356 :type 'string)
358 (defcustom org-export-with-sub-superscripts t
359 "Non-nil means, interpret \"_\" and \"^\" for export.
360 When this option is turned on, you can use TeX-like syntax for sub- and
361 superscripts. Several characters after \"_\" or \"^\" will be
362 considered as a single item - so grouping with {} is normally not
363 needed. For example, the following things will be parsed as single
364 sub- or superscripts.
366 10^24 or 10^tau several digits will be considered 1 item.
367 10^-12 or 10^-tau a leading sign with digits or a word
368 x^2-y^3 will be read as x^2 - y^3, because items are
369 terminated by almost any nonword/nondigit char.
370 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
372 Still, ambiguity is possible - so when in doubt use {} to enclose the
373 sub/superscript. If you set this variable to the symbol `{}',
374 the braces are *required* in order to trigger interpretations as
375 sub/superscript. This can be helpful in documents that need \"_\"
376 frequently in plain text.
378 Not all export backends support this, but HTML does.
380 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
381 :group 'org-export-translation
382 :type '(choice
383 (const :tag "Always interpret" t)
384 (const :tag "Only with braces" {})
385 (const :tag "Never interpret" nil)))
387 (defcustom org-export-with-TeX-macros t
388 "Non-nil means, interpret simple TeX-like macros when exporting.
389 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
390 Not only real TeX macros will work here, but the standard HTML entities
391 for math can be used as macro names as well. For a list of supported
392 names in HTML export, see the constant `org-html-entities'.
393 Not all export backends support this.
395 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
396 :group 'org-export-translation
397 :group 'org-export-latex
398 :type 'boolean)
400 (defcustom org-export-with-LaTeX-fragments nil
401 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
402 When set, the exporter will find LaTeX environments if the \\begin line is
403 the first non-white thing on a line. It will also find the math delimiters
404 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
405 display math.
407 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
408 :group 'org-export-translation
409 :group 'org-export-latex
410 :type 'boolean)
412 (defcustom org-export-with-fixed-width t
413 "Non-nil means, lines starting with \":\" will be in fixed width font.
414 This can be used to have pre-formatted text, fragments of code etc. For
415 example:
416 : ;; Some Lisp examples
417 : (while (defc cnt)
418 : (ding))
419 will be looking just like this in also HTML. See also the QUOTE keyword.
420 Not all export backends support this.
422 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
423 :group 'org-export-translation
424 :type 'boolean)
426 (defcustom org-match-sexp-depth 3
427 "Number of stacked braces for sub/superscript matching.
428 This has to be set before loading org.el to be effective."
429 :group 'org-export-translation
430 :type 'integer)
432 (defgroup org-export-tables nil
433 "Options for exporting tables in Org-mode."
434 :tag "Org Export Tables"
435 :group 'org-export)
437 (defcustom org-export-with-tables t
438 "If non-nil, lines starting with \"|\" define a table.
439 For example:
441 | Name | Address | Birthday |
442 |-------------+----------+-----------|
443 | Arthur Dent | England | 29.2.2100 |
445 Not all export backends support this.
447 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
448 :group 'org-export-tables
449 :type 'boolean)
451 (defcustom org-export-highlight-first-table-line t
452 "Non-nil means, highlight the first table line.
453 In HTML export, this means use <th> instead of <td>.
454 In tables created with table.el, this applies to the first table line.
455 In Org-mode tables, all lines before the first horizontal separator
456 line will be formatted with <th> tags."
457 :group 'org-export-tables
458 :type 'boolean)
460 (defcustom org-export-table-remove-special-lines t
461 "Remove special lines and marking characters in calculating tables.
462 This removes the special marking character column from tables that are set
463 up for spreadsheet calculations. It also removes the entire lines
464 marked with `!', `_', or `^'. The lines with `$' are kept, because
465 the values of constants may be useful to have."
466 :group 'org-export-tables
467 :type 'boolean)
469 (defcustom org-export-prefer-native-exporter-for-tables nil
470 "Non-nil means, always export tables created with table.el natively.
471 Natively means, use the HTML code generator in table.el.
472 When nil, Org-mode's own HTML generator is used when possible (i.e. if
473 the table does not use row- or column-spanning). This has the
474 advantage, that the automatic HTML conversions for math symbols and
475 sub/superscripts can be applied. Org-mode's HTML generator is also
476 much faster."
477 :group 'org-export-tables
478 :type 'boolean)
480 (defgroup org-export-ascii nil
481 "Options specific for ASCII export of Org-mode files."
482 :tag "Org Export ASCII"
483 :group 'org-export)
485 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
486 "Characters for underlining headings in ASCII export.
487 In the given sequence, these characters will be used for level 1, 2, ..."
488 :group 'org-export-ascii
489 :type '(repeat character))
491 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
492 "Bullet characters for headlines converted to lists in ASCII export.
493 The first character is used for the first lest level generated in this
494 way, and so on. If there are more levels than characters given here,
495 the list will be repeated.
496 Note that plain lists will keep the same bullets as the have in the
497 Org-mode file."
498 :group 'org-export-ascii
499 :type '(repeat character))
501 (defcustom org-export-ascii-links-to-notes t
502 "Non-nil means, convert links to notes before the next headline.
503 When nil, the link will be exported in place. If the line becomes long
504 in this way, it will be wrapped."
505 :group 'org-export-ascii
506 :type 'boolean)
508 (defgroup org-export-xml nil
509 "Options specific for XML export of Org-mode files."
510 :tag "Org Export XML"
511 :group 'org-export)
513 (defgroup org-export-html nil
514 "Options specific for HTML export of Org-mode files."
515 :tag "Org Export HTML"
516 :group 'org-export)
518 (defcustom org-export-html-coding-system nil
519 "Coding system for HTML export, defaults to buffer-file-coding-system."
520 :group 'org-export-html
521 :type 'coding-system)
523 (defcustom org-export-html-extension "html"
524 "The extension for exported HTML files."
525 :group 'org-export-html
526 :type 'string)
528 (defcustom org-export-html-link-up ""
529 "Where should the \"UP\" link of exported HTML pages lead?"
530 :group 'org-export-html
531 :type '(string :tag "File or URL"))
533 (defcustom org-export-html-link-home ""
534 "Where should the \"HOME\" link of exported HTML pages lead?"
535 :group 'org-export-html
536 :type '(string :tag "File or URL"))
538 (defconst org-export-html-scripts
539 "<script type=\"text/javascript\">
540 <!--/*--><![CDATA[/*><!--*/
541 function CodeHighlightOn(elem, id)
543 var target = document.getElementById(id);
544 if(null != target) {
545 elem.cacheClassElem = elem.className;
546 elem.cacheClassTarget = target.className;
547 target.className = \"code-highlighted\";
548 elem.className = \"code-highlighted\";
551 function CodeHighlightOff(elem, id)
553 var target = document.getElementById(id);
554 if(elem.cacheClassElem)
555 elem.className = elem.cacheClassElem;
556 if(elem.cacheClassTarget)
557 target.className = elem.cacheClassTarget;
559 /*]]>*/-->
560 </script>"
561 "Basic javascript that is needed by HTML files produced by Org-mode.")
563 (defconst org-export-html-style-default
564 "<style type=\"text/css\">
565 <!--/*--><![CDATA[/*><!--*/
566 html { font-family: Times, serif; font-size: 12pt; }
567 .title { text-align: center; }
568 .todo { color: red; }
569 .done { color: green; }
570 .tag { background-color: #add8e6; font-weight:normal }
571 .target { }
572 .timestamp { color: #bebebe; }
573 .timestamp-kwd { color: #5f9ea0; }
574 p.verse { margin-left: 3% }
575 pre {
576 border: 1pt solid #AEBDCC;
577 background-color: #F3F5F7;
578 padding: 5pt;
579 font-family: courier, monospace;
580 font-size: 90%;
581 overflow:auto;
583 table { border-collapse: collapse; }
584 td, th { vertical-align: top; }
585 dt { font-weight: bold; }
586 div.figure { padding: 0.5em; }
587 div.figure p { text-align: center; }
588 .linenr { font-size:smaller }
589 .code-highlighted {background-color:#ffff00;}
590 .org-info-js_info-navigation { border-style:none; }
591 #org-info-js_console-label { font-size:10px; font-weight:bold;
592 white-space:nowrap; }
593 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
594 font-weight:bold; }
595 /*]]>*/-->
596 </style>"
597 "The default style specification for exported HTML files.
598 Please use the variables `org-export-html-style' and
599 `org-export-html-style-extra' to add to this style. If you wish to not
600 have the default style included, customize the variable
601 `org-export-html-style-include-default'.")
603 (defcustom org-export-html-style-include-default t
604 "Non-nil means, include the default style in exported HTML files.
605 The actual style is defined in `org-export-html-style-default' and should
606 not be modified. Use the variables `org-export-html-style' to add
607 your own style information."
608 :group 'org-export-html
609 :type 'boolean)
610 ;;;###autoload
611 (put 'org-export-html-style 'safe-local-variable 'booleanp)
613 (defcustom org-export-html-style ""
614 "Org-wide style definitions for exported HTML files.
616 This variable needs to contain the full HTML structure to provide a style,
617 including the surrounding HTML tags. If you set the value of this variable,
618 you should consider to include definitions for the following classes:
619 title, todo, done, timestamp, timestamp-kwd, tag, target.
621 For example, a valid value would be:
623 <style type=\"text/css\">
624 <![CDATA[
625 p { font-weight: normal; color: gray; }
626 h1 { color: black; }
627 .title { text-align: center; }
628 .todo, .timestamp-kwd { color: red; }
629 .done { color: green; }
631 </style>
633 If you'd like to refer to en external style file, use something like
635 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
637 As the value of this option simply gets inserted into the HTML <head> header,
638 you can \"misuse\" it to add arbitrary text to the header.
639 See also the variable `org-export-html-style-extra'."
640 :group 'org-export-html
641 :type 'string)
642 ;;;###autoload
643 (put 'org-export-html-style 'safe-local-variable 'stringp)
645 (defcustom org-export-html-style-extra ""
646 "Additional style information for HTML export.
647 The value of this variable is inserted into the HTML buffer right after
648 the value of `org-export-html-style'. Use this variable for per-file
649 settings of style information, and do not forget to surround the style
650 settings with <style>...</style> tags."
651 :group 'org-export-html
652 :type 'string)
653 ;;;###autoload
654 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
656 (defcustom org-export-html-tag-class-prefix ""
657 "Prefix to clas names for TODO keywords.
658 Each tag gets a class given by the tag itself, with this prefix.
659 The default prefix is empty because it is nice to just use the keyword
660 as a class name. But if you get into conflicts with other, existing
661 CSS classes, then this prefic can be very useful."
662 :group 'org-export-html
663 :type 'string)
665 (defcustom org-export-html-todo-kwd-class-prefix ""
666 "Prefix to clas names for TODO keywords.
667 Each TODO keyword gets a class given by the keyword itself, with this prefix.
668 The default prefix is empty because it is nice to just use the keyword
669 as a class name. But if you get into conflicts with other, existing
670 CSS classes, then this prefic can be very useful."
671 :group 'org-export-html
672 :type 'string)
674 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
675 "Format for typesetting the document title in HTML export."
676 :group 'org-export-html
677 :type 'string)
679 (defcustom org-export-html-toplevel-hlevel 2
680 "The <H> level for level 1 headings in HTML export.
681 This is also important for the classes that will be wrapped around headlines
682 and outline structure. If this variable is 1, the top-level headlines will
683 be <h1>, and the corresponding classes will be outline-1, section-number-1,
684 and outline-text-1. If this is 2, all of these will get a 2 instead.
685 The default for this variable is 2, because we use <h1> for formatting the
686 document title."
687 :group 'org-export-html
688 :type 'string)
690 (defcustom org-export-html-link-org-files-as-html t
691 "Non-nil means, make file links to `file.org' point to `file.html'.
692 When org-mode is exporting an org-mode file to HTML, links to
693 non-html files are directly put into a href tag in HTML.
694 However, links to other Org-mode files (recognized by the
695 extension `.org.) should become links to the corresponding html
696 file, assuming that the linked org-mode file will also be
697 converted to HTML.
698 When nil, the links still point to the plain `.org' file."
699 :group 'org-export-html
700 :type 'boolean)
702 (defcustom org-export-html-inline-images 'maybe
703 "Non-nil means, inline images into exported HTML pages.
704 This is done using an <img> tag. When nil, an anchor with href is used to
705 link to the image. If this option is `maybe', then images in links with
706 an empty description will be inlined, while images with a description will
707 be linked only."
708 :group 'org-export-html
709 :type '(choice (const :tag "Never" nil)
710 (const :tag "Always" t)
711 (const :tag "When there is no description" maybe)))
713 (defcustom org-export-html-inline-image-extensions
714 '("png" "jpeg" "jpg" "gif")
715 "Extensions of image files that can be inlined into HTML."
716 :group 'org-export-html
717 :type '(repeat (string :tag "Extension")))
719 ;; FIXME: rename
720 (defcustom org-export-html-expand t
721 "Non-nil means, for HTML export, treat @<...> as HTML tag.
722 When nil, these tags will be exported as plain text and therefore
723 not be interpreted by a browser.
725 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
726 :group 'org-export-html
727 :type 'boolean)
729 (defcustom org-export-html-table-tag
730 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
731 "The HTML tag that is used to start a table.
732 This must be a <table> tag, but you may change the options like
733 borders and spacing."
734 :group 'org-export-html
735 :type 'string)
737 (defcustom org-export-table-header-tags '("<th>" . "</th>")
738 "The opening tag for table header fields.
739 This is customizable so that alignment options can be specified."
740 :group 'org-export-tables
741 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
743 (defcustom org-export-table-data-tags '("<td>" . "</td>")
744 "The opening tag for table data fields.
745 This is customizable so that alignment options can be specified."
746 :group 'org-export-tables
747 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
749 (defcustom org-export-html-validation-link nil
750 "Non-nil means, add validationlink to postamble of HTML exported files."
751 :group 'org-export-html
752 :type '(choice
753 (const :tag "Nothing" nil)
754 (const :tag "XHTML 1.0" "<p class=\"xhtml-validation\"><a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a></p>")
755 (string :tag "Specify full HTML")))
758 (defcustom org-export-html-with-timestamp nil
759 "If non-nil, write `org-export-html-html-helper-timestamp'
760 into the exported HTML text. Otherwise, the buffer will just be saved
761 to a file."
762 :group 'org-export-html
763 :type 'boolean)
765 (defcustom org-export-html-html-helper-timestamp
766 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
767 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
768 :group 'org-export-html
769 :type 'string)
771 (defgroup org-export-htmlize nil
772 "Options for processing examples with htmlize.el."
773 :tag "Org Export Htmlize"
774 :group 'org-export-html)
776 (defcustom org-export-htmlize-output-type 'inline-css
777 "Output type to be used by htmlize when formatting code snippets.
778 Normally this is `inline-css', but if you have defined to appropriate
779 classes in your css style file, setting this to `css' means that the
780 fontification will use the class names.
781 See also the function `org-export-htmlize-generate-css'."
782 :group 'org-export-htmlize
783 :type '(choice (const css) (const inline-css)))
785 (defcustom org-export-htmlize-css-font-prefix "org-"
786 "The prefix for CSS class names for htmlize font specifications."
787 :group 'org-export-htmlize
788 :type 'string)
790 (defgroup org-export-icalendar nil
791 "Options specific for iCalendar export of Org-mode files."
792 :tag "Org Export iCalendar"
793 :group 'org-export)
795 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
796 "The file name for the iCalendar file covering all agenda files.
797 This file is created with the command \\[org-export-icalendar-all-agenda-files].
798 The file name should be absolute, the file will be overwritten without warning."
799 :group 'org-export-icalendar
800 :type 'file)
802 (defcustom org-icalendar-combined-name "OrgMode"
803 "Calendar name for the combined iCalendar representing all agenda files."
804 :group 'org-export-icalendar
805 :type 'string)
807 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
808 "Contexts where iCalendar export should use a deadline time stamp.
809 This is a list with several symbols in it. Valid symbol are:
811 event-if-todo Deadlines in TODO entries become calendar events.
812 event-if-not-todo Deadlines in non-TODO entries become calendar events.
813 todo-due Use deadlines in TODO entries as due-dates"
814 :group 'org-export-icalendar
815 :type '(set :greedy t
816 (const :tag "Deadlines in non-TODO entries become events"
817 event-if-not-todo)
818 (const :tag "Deadline in TODO entries become events"
819 event-if-todo)
820 (const :tag "Deadlines in TODO entries become due-dates"
821 todo-due)))
823 (defcustom org-icalendar-use-scheduled '(todo-start)
824 "Contexts where iCalendar export should use a scheduling time stamp.
825 This is a list with several symbols in it. Valid symbol are:
827 event-if-todo Scheduling time stamps in TODO entries become an event.
828 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
829 todo-start Scheduling time stamps in TODO entries become start date.
830 Some calendar applications show TODO entries only after
831 that date."
832 :group 'org-export-icalendar
833 :type '(set :greedy t
834 (const :tag
835 "SCHEDULED timestamps in non-TODO entries become events"
836 event-if-not-todo)
837 (const :tag "SCHEDULED timestamps in TODO entries become events"
838 event-if-todo)
839 (const :tag "SCHEDULED in TODO entries become start date"
840 todo-start)))
842 (defcustom org-icalendar-categories '(local-tags category)
843 "Items that should be entered into the categories field.
844 This is a list of symbols, the following are valid:
846 category The Org-mode category of the current file or tree
847 todo-state The todo state, if any
848 local-tags The tags, defined in the current line
849 all-tags All tags, including inherited ones."
850 :group 'org-export-icalendar
851 :type '(repeat
852 (choice
853 (const :tag "The file or tree category" category)
854 (const :tag "The TODO state" todo-state)
855 (const :tag "Tags defined in current line" local-tags)
856 (const :tag "All tags, including inherited ones" all-tags))))
858 (defcustom org-icalendar-include-todo nil
859 "Non-nil means, export to iCalendar files should also cover TODO items."
860 :group 'org-export-icalendar
861 :type '(choice
862 (const :tag "None" nil)
863 (const :tag "Unfinished" t)
864 (const :tag "All" all)))
866 (defcustom org-icalendar-include-sexps t
867 "Non-nil means, export to iCalendar files should also cover sexp entries.
868 These are entries like in the diary, but directly in an Org-mode file."
869 :group 'org-export-icalendar
870 :type 'boolean)
872 (defcustom org-icalendar-include-body 100
873 "Amount of text below headline to be included in iCalendar export.
874 This is a number of characters that should maximally be included.
875 Properties, scheduling and clocking lines will always be removed.
876 The text will be inserted into the DESCRIPTION field."
877 :group 'org-export-icalendar
878 :type '(choice
879 (const :tag "Nothing" nil)
880 (const :tag "Everything" t)
881 (integer :tag "Max characters")))
883 (defcustom org-icalendar-store-UID nil
884 "Non-nil means, store any created UIDs in properties.
885 The iCalendar standard requires that all entries have a unique identifier.
886 Org will create these identifiers as needed. When this variable is non-nil,
887 the created UIDs will be stored in the ID property of the entry. Then the
888 next time this entry is exported, it will be exported with the same UID,
889 superceding the previous form of it. This is essential for
890 synchronization services.
891 This variable is not turned on by default because we want to avoid creating
892 a property drawer in every entry if people are only playing with this feature,
893 or if they are only using it locally."
894 :group 'org-export-icalendar
895 :type 'boolean)
897 ;;;; Exporting
899 ;;; Variables, constants, and parameter plists
901 (defconst org-level-max 20)
903 (defvar org-export-html-preamble nil
904 "Preamble, to be inserted just before <body>. Set by publishing functions.")
905 (defvar org-export-html-postamble nil
906 "Preamble, to be inserted just after </body>. Set by publishing functions.")
907 (defvar org-export-html-auto-preamble t
908 "Should default preamble be inserted? Set by publishing functions.")
909 (defvar org-export-html-auto-postamble t
910 "Should default postamble be inserted? Set by publishing functions.")
911 (defvar org-current-export-file nil) ; dynamically scoped parameter
912 (defvar org-current-export-dir nil) ; dynamically scoped parameter
913 (defvar org-export-opt-plist nil
914 "Contains the current option plist.")
916 (defconst org-export-plist-vars
917 '((:link-up nil org-export-html-link-up)
918 (:link-home nil org-export-html-link-home)
919 (:language nil org-export-default-language)
920 (:customtime nil org-display-custom-times)
921 (:headline-levels "H" org-export-headline-levels)
922 (:section-numbers "num" org-export-with-section-numbers)
923 (:section-number-format nil org-export-section-number-format)
924 (:table-of-contents "toc" org-export-with-toc)
925 (:preserve-breaks "\\n" org-export-preserve-breaks)
926 (:archived-trees nil org-export-with-archived-trees)
927 (:emphasize "*" org-export-with-emphasize)
928 (:sub-superscript "^" org-export-with-sub-superscripts)
929 (:special-strings "-" org-export-with-special-strings)
930 (:footnotes "f" org-export-with-footnotes)
931 (:drawers "d" org-export-with-drawers)
932 (:tags "tags" org-export-with-tags)
933 (:todo-keywords "todo" org-export-with-todo-keywords)
934 (:priority "pri" org-export-with-priority)
935 (:TeX-macros "TeX" org-export-with-TeX-macros)
936 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
937 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
938 (:fixed-width ":" org-export-with-fixed-width)
939 (:timestamps "<" org-export-with-timestamps)
940 (:author-info "author" org-export-author-info)
941 (:creator-info "creator" org-export-creator-info)
942 (:time-stamp-file "timestamp" org-export-time-stamp-file)
943 (:tables "|" org-export-with-tables)
944 (:table-auto-headline nil org-export-highlight-first-table-line)
945 (:style-include-default nil org-export-html-style-include-default)
946 (:style nil org-export-html-style)
947 (:style-extra nil org-export-html-style-extra)
948 (:agenda-style nil org-agenda-export-html-style)
949 (:convert-org-links nil org-export-html-link-org-files-as-html)
950 (:inline-images nil org-export-html-inline-images)
951 (:html-extension nil org-export-html-extension)
952 (:html-table-tag nil org-export-html-table-tag)
953 (:expand-quoted-html "@" org-export-html-expand)
954 (:timestamp nil org-export-html-with-timestamp)
955 (:publishing-directory nil org-export-publishing-directory)
956 (:preamble nil org-export-html-preamble)
957 (:postamble nil org-export-html-postamble)
958 (:auto-preamble nil org-export-html-auto-preamble)
959 (:auto-postamble nil org-export-html-auto-postamble)
960 (:author nil user-full-name)
961 (:email nil user-mail-address)
962 (:select-tags nil org-export-select-tags)
963 (:exclude-tags nil org-export-exclude-tags))
964 "List of properties that represent export/publishing variables.
965 Each element is a list of 3 items:
966 1. The property that is used internally, and also for org-publish-project-alist
967 2. The string that can be used in the OPTION lines to set this option,
968 or nil if this option cannot be changed in this way
969 3. The customization variable that sets the default for this option."
973 (defun org-default-export-plist ()
974 "Return the property list with default settings for the export variables."
975 (let ((l org-export-plist-vars) rtn e)
976 (while (setq e (pop l))
977 (setq rtn (cons (car e) (cons (symbol-value (nth 2 e)) rtn))))
978 rtn))
980 (defvar org-export-inbuffer-options-extra nil
981 "List of additional in-buffer options that should be detected.
982 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
983 etc. Extensions can add to this list to get their options detected, and they
984 can then add a function to `org-export-options-filters' to process these
985 options.
986 Each element in this list must be a list, with the in-buffer keyword as car,
987 and a property (a symbol) as the next element. All occurrences of the
988 keyword will be found, the values concatenated with a space character
989 in between, and the result stored in the export options property list.")
991 (defvar org-export-options-filters nil
992 "Functions to be called to finalize the export/publishing options.
993 All these options are stored in a property list, and each of the functions
994 in this hook gets a chance to modify this property list. Each function
995 must accept the property list as an argument, and must return the (possibly
996 modified) list.")
998 ;; FIXME: should we fold case here?
999 (defun org-infile-export-plist ()
1000 "Return the property list with file-local settings for export."
1001 (save-excursion
1002 (save-restriction
1003 (widen)
1004 (goto-char (point-min))
1005 (let ((re (org-make-options-regexp
1006 (append
1007 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
1008 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
1009 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
1010 (mapcar 'car org-export-inbuffer-options-extra))))
1011 p key val text options a pr style
1012 latex-header
1013 ext-setup-or-nil setup-contents (start 0))
1014 (while (or (and ext-setup-or-nil
1015 (string-match re ext-setup-or-nil start)
1016 (setq start (match-end 0)))
1017 (and (setq ext-setup-or-nil nil start 0)
1018 (re-search-forward re nil t)))
1019 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
1020 val (org-match-string-no-properties 2 ext-setup-or-nil))
1021 (cond
1022 ((setq a (assoc key org-export-inbuffer-options-extra))
1023 (setq pr (nth 1 a))
1024 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
1025 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
1026 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
1027 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
1028 ((string-equal key "DATE") (setq p (plist-put p :date val)))
1029 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
1030 ((string-equal key "STYLE")
1031 (setq style (concat style "\n" val)))
1032 ((string-equal key "LATEX_HEADER")
1033 (setq latex-header (concat latex-header "\n" val)))
1034 ((string-equal key "TEXT")
1035 (setq text (if text (concat text "\n" val) val)))
1036 ((string-equal key "OPTIONS")
1037 (setq options (concat val " " options)))
1038 ((string-equal key "LINK_UP")
1039 (setq p (plist-put p :link-up val)))
1040 ((string-equal key "LINK_HOME")
1041 (setq p (plist-put p :link-home val)))
1042 ((string-equal key "EXPORT_SELECT_TAGS")
1043 (setq p (plist-put p :select-tags (org-split-string val))))
1044 ((string-equal key "EXPORT_EXCLUDE_TAGS")
1045 (setq p (plist-put p :exclude-tags (org-split-string val))))
1046 ((equal key "SETUPFILE")
1047 (setq setup-contents (org-file-contents
1048 (expand-file-name
1049 (org-remove-double-quotes
1050 (org-trim val)))
1051 'noerror))
1052 (if (not ext-setup-or-nil)
1053 (setq ext-setup-or-nil setup-contents start 0)
1054 (setq ext-setup-or-nil
1055 (concat (substring ext-setup-or-nil 0 start)
1056 "\n" setup-contents "\n"
1057 (substring ext-setup-or-nil start)))))))
1058 (setq p (plist-put p :text text))
1059 (when style (setq p (plist-put p :style-extra style)))
1060 (when latex-header
1061 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
1062 (when options
1063 (setq p (org-export-add-options-to-plist p options)))
1064 ;; Add macro definitions
1065 (goto-char (point-min))
1066 (while (re-search-forward
1067 "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
1068 nil t)
1069 (setq p (plist-put p (intern (concat ":macro-"
1070 (downcase (match-string 1))))
1071 (match-string 2))))
1072 p))))
1074 (defun org-export-add-options-to-plist (p options)
1075 "Parse an OPTIONS line and set values in the property list P."
1076 (let (o)
1077 (when options
1078 (let ((op org-export-plist-vars))
1079 (while (setq o (pop op))
1080 (if (and (nth 1 o)
1081 (string-match (concat (regexp-quote (nth 1 o))
1082 ":\\([^ \t\n\r;,.]*\\)")
1083 options))
1084 (setq p (plist-put p (car o)
1085 (car (read-from-string
1086 (match-string 1 options))))))))))
1089 (defun org-export-add-subtree-options (p pos)
1090 "Add options in subtree at position POS to property list P."
1091 (save-excursion
1092 (goto-char pos)
1093 (when (org-at-heading-p)
1094 (let (a)
1095 ;; This is actually read in `org-export-get-title-from-subtree'
1096 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1097 ;; (setq p (plist-put p :title a)))
1098 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
1099 (setq p (plist-put p :text a)))
1100 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
1101 (setq p (org-export-add-options-to-plist p a)))))
1104 (defun org-export-directory (type plist)
1105 (let* ((val (plist-get plist :publishing-directory))
1106 (dir (if (listp val)
1107 (or (cdr (assoc type val)) ".")
1108 val)))
1109 dir))
1111 (defun org-export-process-option-filters (plist)
1112 (let ((functions org-export-options-filters) f)
1113 (while (setq f (pop functions))
1114 (setq plist (funcall f plist))))
1115 plist)
1117 ;;;###autoload
1118 (defun org-export (&optional arg)
1119 "Export dispatcher for Org-mode.
1120 When `org-export-run-in-background' is non-nil, try to run the command
1121 in the background. This will be done only for commands that write
1122 to a file. For details see the docstring of `org-export-run-in-background'.
1124 The prefix argument ARG will be passed to the exporter. However, if
1125 ARG is a double universal prefix `C-u C-u', that means to inverse the
1126 value of `org-export-run-in-background'."
1127 (interactive "P")
1128 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
1129 (help "[t] insert the export option template
1130 \[v] limit export to visible part of outline tree
1132 \[a] export as ASCII
1134 \[h] export as HTML
1135 \[H] export as HTML to temporary buffer
1136 \[R] export region as HTML
1137 \[b] export as HTML and browse immediately
1138 \[x] export as XOXO
1140 \[l] export as LaTeX
1141 \[p] export as LaTeX and process to PDF
1142 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1143 \[L] export as LaTeX to temporary buffer
1145 \[i] export current file as iCalendar file
1146 \[I] export all agenda files as iCalendar files
1147 \[c] export agenda files into combined iCalendar file
1149 \[F] publish current file
1150 \[P] publish current project
1151 \[X] publish... (project will be prompted for)
1152 \[A] publish all projects")
1153 (cmds
1154 '((?t org-insert-export-options-template nil)
1155 (?v org-export-visible nil)
1156 (?a org-export-as-ascii t)
1157 (?h org-export-as-html t)
1158 (?b org-export-as-html-and-open t)
1159 (?H org-export-as-html-to-buffer nil)
1160 (?R org-export-region-as-html nil)
1161 (?x org-export-as-xoxo t)
1162 (?l org-export-as-latex t)
1163 (?p org-export-as-pdf t)
1164 (?d org-export-as-pdf-and-open t)
1165 (?L org-export-as-latex-to-buffer nil)
1166 (?i org-export-icalendar-this-file t)
1167 (?I org-export-icalendar-all-agenda-files t)
1168 (?c org-export-icalendar-combine-agenda-files t)
1169 (?F org-publish-current-file t)
1170 (?P org-publish-current-project t)
1171 (?X org-publish t)
1172 (?A org-publish-all t)))
1173 r1 r2 ass)
1174 (save-excursion
1175 (save-window-excursion
1176 (delete-other-windows)
1177 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1178 (princ help))
1179 (org-fit-window-to-buffer (get-buffer-window
1180 "*Org Export/Publishing Help*"))
1181 (message "Select command: ")
1182 (setq r1 (read-char-exclusive))))
1183 (setq r2 (if (< r1 27) (+ r1 96) r1))
1184 (unless (setq ass (assq r2 cmds))
1185 (error "No command associated with key %c" r1))
1186 (if (and bg (nth 2 ass)
1187 (not (buffer-base-buffer))
1188 (not (org-region-active-p)))
1189 ;; execute in background
1190 (let ((p (start-process
1191 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1192 "*Org Processes*"
1193 (expand-file-name invocation-name invocation-directory)
1194 "-batch"
1195 "-l" user-init-file
1196 "--eval" "(require 'org-exp)"
1197 "--eval" "(setq org-wait .2)"
1198 (buffer-file-name)
1199 "-f" (symbol-name (nth 1 ass)))))
1200 (set-process-sentinel p 'org-export-process-sentinel)
1201 (message "Background process \"%s\": started" p))
1202 ;; background processing not requested, or not possible
1203 (call-interactively (nth 1 ass)))))
1205 (defun org-export-process-sentinel (process status)
1206 (if (string-match "\n+\\'" status)
1207 (setq status (substring status 0 -1)))
1208 (message "Background process \"%s\": %s" process status))
1210 (defconst org-html-entities
1211 '(("nbsp")
1212 ("iexcl")
1213 ("cent")
1214 ("pound")
1215 ("curren")
1216 ("yen")
1217 ("brvbar")
1218 ("vert" . "&#124;")
1219 ("sect")
1220 ("uml")
1221 ("copy")
1222 ("ordf")
1223 ("laquo")
1224 ("not")
1225 ("shy")
1226 ("reg")
1227 ("macr")
1228 ("deg")
1229 ("plusmn")
1230 ("sup2")
1231 ("sup3")
1232 ("acute")
1233 ("micro")
1234 ("para")
1235 ("middot")
1236 ("odot"."o")
1237 ("star"."*")
1238 ("cedil")
1239 ("sup1")
1240 ("ordm")
1241 ("raquo")
1242 ("frac14")
1243 ("frac12")
1244 ("frac34")
1245 ("iquest")
1246 ("Agrave")
1247 ("Aacute")
1248 ("Acirc")
1249 ("Atilde")
1250 ("Auml")
1251 ("Aring") ("AA"."&Aring;")
1252 ("AElig")
1253 ("Ccedil")
1254 ("Egrave")
1255 ("Eacute")
1256 ("Ecirc")
1257 ("Euml")
1258 ("Igrave")
1259 ("Iacute")
1260 ("Icirc")
1261 ("Iuml")
1262 ("ETH")
1263 ("Ntilde")
1264 ("Ograve")
1265 ("Oacute")
1266 ("Ocirc")
1267 ("Otilde")
1268 ("Ouml")
1269 ("times")
1270 ("Oslash")
1271 ("Ugrave")
1272 ("Uacute")
1273 ("Ucirc")
1274 ("Uuml")
1275 ("Yacute")
1276 ("THORN")
1277 ("szlig")
1278 ("agrave")
1279 ("aacute")
1280 ("acirc")
1281 ("atilde")
1282 ("auml")
1283 ("aring")
1284 ("aelig")
1285 ("ccedil")
1286 ("egrave")
1287 ("eacute")
1288 ("ecirc")
1289 ("euml")
1290 ("igrave")
1291 ("iacute")
1292 ("icirc")
1293 ("iuml")
1294 ("eth")
1295 ("ntilde")
1296 ("ograve")
1297 ("oacute")
1298 ("ocirc")
1299 ("otilde")
1300 ("ouml")
1301 ("divide")
1302 ("oslash")
1303 ("ugrave")
1304 ("uacute")
1305 ("ucirc")
1306 ("uuml")
1307 ("yacute")
1308 ("thorn")
1309 ("yuml")
1310 ("fnof")
1311 ("Alpha")
1312 ("Beta")
1313 ("Gamma")
1314 ("Delta")
1315 ("Epsilon")
1316 ("Zeta")
1317 ("Eta")
1318 ("Theta")
1319 ("Iota")
1320 ("Kappa")
1321 ("Lambda")
1322 ("Mu")
1323 ("Nu")
1324 ("Xi")
1325 ("Omicron")
1326 ("Pi")
1327 ("Rho")
1328 ("Sigma")
1329 ("Tau")
1330 ("Upsilon")
1331 ("Phi")
1332 ("Chi")
1333 ("Psi")
1334 ("Omega")
1335 ("alpha")
1336 ("beta")
1337 ("gamma")
1338 ("delta")
1339 ("epsilon")
1340 ("varepsilon"."&epsilon;")
1341 ("zeta")
1342 ("eta")
1343 ("theta")
1344 ("iota")
1345 ("kappa")
1346 ("lambda")
1347 ("mu")
1348 ("nu")
1349 ("xi")
1350 ("omicron")
1351 ("pi")
1352 ("rho")
1353 ("sigmaf") ("varsigma"."&sigmaf;")
1354 ("sigma")
1355 ("tau")
1356 ("upsilon")
1357 ("phi")
1358 ("chi")
1359 ("psi")
1360 ("omega")
1361 ("thetasym") ("vartheta"."&thetasym;")
1362 ("upsih")
1363 ("piv")
1364 ("bull") ("bullet"."&bull;")
1365 ("hellip") ("dots"."&hellip;")
1366 ("prime")
1367 ("Prime")
1368 ("oline")
1369 ("frasl")
1370 ("weierp")
1371 ("image")
1372 ("real")
1373 ("trade")
1374 ("alefsym")
1375 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1376 ("uarr") ("uparrow"."&uarr;")
1377 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1378 ("darr")("downarrow"."&darr;")
1379 ("harr") ("leftrightarrow"."&harr;")
1380 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1381 ("lArr") ("Leftarrow"."&lArr;")
1382 ("uArr") ("Uparrow"."&uArr;")
1383 ("rArr") ("Rightarrow"."&rArr;")
1384 ("dArr") ("Downarrow"."&dArr;")
1385 ("hArr") ("Leftrightarrow"."&hArr;")
1386 ("forall")
1387 ("part") ("partial"."&part;")
1388 ("exist") ("exists"."&exist;")
1389 ("empty") ("emptyset"."&empty;")
1390 ("nabla")
1391 ("isin") ("in"."&isin;")
1392 ("notin")
1393 ("ni")
1394 ("prod")
1395 ("sum")
1396 ("minus")
1397 ("lowast") ("ast"."&lowast;")
1398 ("radic")
1399 ("prop") ("proptp"."&prop;")
1400 ("infin") ("infty"."&infin;")
1401 ("ang") ("angle"."&ang;")
1402 ("and") ("wedge"."&and;")
1403 ("or") ("vee"."&or;")
1404 ("cap")
1405 ("cup")
1406 ("int")
1407 ("there4")
1408 ("sim")
1409 ("cong") ("simeq"."&cong;")
1410 ("asymp")("approx"."&asymp;")
1411 ("ne") ("neq"."&ne;")
1412 ("equiv")
1413 ("le")
1414 ("ge")
1415 ("sub") ("subset"."&sub;")
1416 ("sup") ("supset"."&sup;")
1417 ("nsub")
1418 ("sube")
1419 ("supe")
1420 ("oplus")
1421 ("otimes")
1422 ("perp")
1423 ("sdot") ("cdot"."&sdot;")
1424 ("lceil")
1425 ("rceil")
1426 ("lfloor")
1427 ("rfloor")
1428 ("lang")
1429 ("rang")
1430 ("loz") ("Diamond"."&loz;")
1431 ("spades") ("spadesuit"."&spades;")
1432 ("clubs") ("clubsuit"."&clubs;")
1433 ("hearts") ("diamondsuit"."&hearts;")
1434 ("diams") ("diamondsuit"."&diams;")
1435 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1436 ("quot")
1437 ("amp")
1438 ("lt")
1439 ("gt")
1440 ("OElig")
1441 ("oelig")
1442 ("Scaron")
1443 ("scaron")
1444 ("Yuml")
1445 ("circ")
1446 ("tilde")
1447 ("ensp")
1448 ("emsp")
1449 ("thinsp")
1450 ("zwnj")
1451 ("zwj")
1452 ("lrm")
1453 ("rlm")
1454 ("ndash")
1455 ("mdash")
1456 ("lsquo")
1457 ("rsquo")
1458 ("sbquo")
1459 ("ldquo")
1460 ("rdquo")
1461 ("bdquo")
1462 ("dagger")
1463 ("Dagger")
1464 ("permil")
1465 ("lsaquo")
1466 ("rsaquo")
1467 ("euro")
1469 ("arccos"."arccos")
1470 ("arcsin"."arcsin")
1471 ("arctan"."arctan")
1472 ("arg"."arg")
1473 ("cos"."cos")
1474 ("cosh"."cosh")
1475 ("cot"."cot")
1476 ("coth"."coth")
1477 ("csc"."csc")
1478 ("deg"."deg")
1479 ("det"."det")
1480 ("dim"."dim")
1481 ("exp"."exp")
1482 ("gcd"."gcd")
1483 ("hom"."hom")
1484 ("inf"."inf")
1485 ("ker"."ker")
1486 ("lg"."lg")
1487 ("lim"."lim")
1488 ("liminf"."liminf")
1489 ("limsup"."limsup")
1490 ("ln"."ln")
1491 ("log"."log")
1492 ("max"."max")
1493 ("min"."min")
1494 ("Pr"."Pr")
1495 ("sec"."sec")
1496 ("sin"."sin")
1497 ("sinh"."sinh")
1498 ("sup"."sup")
1499 ("tan"."tan")
1500 ("tanh"."tanh")
1502 "Entities for TeX->HTML translation.
1503 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1504 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1505 In that case, \"\\ent\" will be translated to \"&other;\".
1506 The list contains HTML entities for Latin-1, Greek and other symbols.
1507 It is supplemented by a number of commonly used TeX macros with appropriate
1508 translations. There is currently no way for users to extend this.")
1510 ;;; General functions for all backends
1512 (defvar org-export-target-aliases nil
1513 "Alist of targets with invisible aliases.")
1514 (defvar org-export-code-refs nil
1515 "Alist of code references and line numbers")
1517 (defun org-export-preprocess-string (string &rest parameters)
1518 "Cleanup STRING so that that the true exported has a more consistent source.
1519 This function takes STRING, which should be a buffer-string of an org-file
1520 to export. It then creates a temporary buffer where it does its job.
1521 The result is then again returned as a string, and the exporter works
1522 on this string to produce the exported version."
1523 (interactive)
1524 (let* ((htmlp (plist-get parameters :for-html))
1525 (asciip (plist-get parameters :for-ascii))
1526 (latexp (plist-get parameters :for-LaTeX))
1527 (backend (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))
1529 (archived-trees (plist-get parameters :archived-trees))
1530 (inhibit-read-only t)
1531 (drawers org-drawers)
1532 (outline-regexp "\\*+ ")
1533 target-alist rtn)
1535 (setq org-export-target-aliases nil)
1536 (setq org-export-code-refs nil)
1538 (with-current-buffer (get-buffer-create " org-mode-tmp")
1539 (erase-buffer)
1540 (insert string)
1541 (setq case-fold-search t)
1543 ;; Remove license-to-kill stuff
1544 ;; The caller marks some stuff for killing, stuff that has been
1545 ;; used to create the page title, for example.
1546 (org-export-kill-licensed-text)
1548 (let ((org-inhibit-startup t)) (org-mode))
1549 (setq case-fold-search t)
1551 ;; Call the hook
1552 (run-hooks 'org-export-preprocess-hook)
1554 ;; Process the macros
1555 (org-export-preprocess-apply-macros)
1556 (run-hooks 'org-export-preprocess-after-macros-hook)
1558 (untabify (point-min) (point-max))
1560 ;; Handle include files, and call a hook
1561 (org-export-handle-include-files)
1562 (run-hooks 'org-export-preprocess-after-include-files-hook)
1564 ;; Get rid of archived trees
1565 (org-export-remove-archived-trees archived-trees)
1567 ;; Remove comment environment and comment subtrees
1568 (org-export-remove-comment-blocks-and-subtrees)
1570 ;; Get rid of excluded trees, and call a hook
1571 (org-export-handle-export-tags (plist-get parameters :select-tags)
1572 (plist-get parameters :exclude-tags))
1573 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1575 ;; Handle source code snippets
1576 (org-export-replace-src-segments-and-examples backend)
1578 ;; Protect short examples marked by a leading colon
1579 (org-export-protect-colon-examples)
1581 ;; Normalize footnotes
1582 (when (plist-get parameters :footnotes)
1583 (org-footnote-normalize nil t))
1585 ;; Find all headings and compute the targets for them
1586 (setq target-alist (org-export-define-heading-targets target-alist))
1588 ;; Get rid of drawers
1589 (org-export-remove-or-extract-drawers drawers
1590 (plist-get parameters :drawers))
1592 ;; Get the correct stuff before the first headline
1593 (when (plist-get parameters :skip-before-1st-heading)
1594 (goto-char (point-min))
1595 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1596 (delete-region (point-min) (match-beginning 0))
1597 (goto-char (point-min))
1598 (insert "\n")))
1599 (when (plist-get parameters :add-text)
1600 (goto-char (point-min))
1601 (insert (plist-get parameters :add-text) "\n"))
1603 ;; Remove todo-keywords before exporting, if the user has requested so
1604 (org-export-remove-headline-metadata parameters)
1606 ;; Find targets in comments and move them out of comments,
1607 ;; but mark them as targets that should be invisible
1608 (setq target-alist (org-export-handle-invisible-targets target-alist))
1610 ;; Select and protect backend specific stuff, throw away stuff
1611 ;; that is specific for other backends
1612 (org-export-select-backend-specific-text backend)
1614 ;; Protect quoted subtrees
1615 (org-export-protect-quoted-subtrees)
1617 ;; Remove clock lines
1618 (org-export-remove-clock-lines)
1620 ;; Protect verbatim elements
1621 (org-export-protect-verbatim)
1623 ;; Blockquotes and verse
1624 (org-export-mark-blockquote-and-verse)
1626 ;; Remove timestamps, if the user has requested so
1627 (unless (plist-get parameters :timestamps)
1628 (org-export-remove-timestamps))
1630 ;; Attach captions to the correct object
1631 (setq target-alist (org-export-attach-captions-and-attributes
1632 backend target-alist))
1634 ;; Find matches for radio targets and turn them into internal links
1635 (org-export-mark-radio-links)
1637 ;; Find all links that contain a newline and put them into a single line
1638 (org-export-concatenate-multiline-links)
1640 ;; Normalize links: Convert angle and plain links into bracket links
1641 ;; and expand link abbreviations
1642 (org-export-normalize-links)
1644 ;; Find all internal links. If they have a fuzzy match (i.e. not
1645 ;; a *dedicated* target match, let the link point to the
1646 ;; corresponding section.
1647 (org-export-target-internal-links target-alist)
1649 ;; Find multiline emphasis and put them into single line
1650 (when (plist-get parameters :emph-multiline)
1651 (org-export-concatenate-multiline-emphasis))
1653 ;; Remove special table lines
1654 (when org-export-table-remove-special-lines
1655 (org-export-remove-special-table-lines))
1657 ;; Another hook
1658 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1660 ;; LaTeX-specific preprocessing
1661 (when latexp
1662 (require 'org-export-latex nil)
1663 (org-export-latex-preprocess))
1665 ;; ASCII-specific preprocessing
1666 (when asciip
1667 (org-export-ascii-preprocess))
1669 ;; HTML-specific preprocessing
1670 (when htmlp
1671 (org-export-html-preprocess parameters))
1673 ;; Remove or replace comments
1674 (org-export-handle-comments (plist-get parameters :comments))
1676 ;; Run the final hook
1677 (run-hooks 'org-export-preprocess-final-hook)
1679 (setq rtn (buffer-string)))
1680 (kill-buffer " org-mode-tmp")
1681 rtn))
1683 (defun org-export-kill-licensed-text ()
1684 "Remove all text that is marked with a :org-license-to-kill property."
1685 (let (p)
1686 (while (setq p (text-property-any (point-min) (point-max)
1687 :org-license-to-kill t))
1688 (delete-region
1689 p (or (next-single-property-change p :org-license-to-kill)
1690 (point-max))))))
1692 (defun org-export-define-heading-targets (target-alist)
1693 "Find all headings and define the targets for them.
1694 The new targets are added to TARGET-ALIST, which is also returned."
1695 (goto-char (point-min))
1696 (org-init-section-numbers)
1697 (let ((re (concat "^" org-outline-regexp
1698 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1699 level target last-section-target a)
1700 (while (re-search-forward re nil t)
1701 (if (match-end 1)
1702 (progn
1703 (push (cons (org-match-string-no-properties 1)
1704 target) target-alist)
1705 (setq a (or (assoc last-section-target org-export-target-aliases)
1706 (progn
1707 (push (list last-section-target)
1708 org-export-target-aliases)
1709 (car org-export-target-aliases))))
1710 (push (caar target-alist) (cdr a)))
1711 (setq level (org-reduced-level
1712 (save-excursion (goto-char (point-at-bol))
1713 (org-outline-level))))
1714 (setq target (org-solidify-link-text
1715 (format "sec-%s" (org-section-number level))))
1716 (setq last-section-target target)
1717 (push (cons target target) target-alist)
1718 (add-text-properties
1719 (point-at-bol) (point-at-eol)
1720 (list 'target target)))))
1721 target-alist)
1723 (defun org-export-handle-invisible-targets (target-alist)
1724 "Find targets in comments and move them out of comments.
1725 Mark them as invisible targets."
1726 (let (target tmp a)
1727 (goto-char (point-min))
1728 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1729 ;; Check if the line before or after is a headline with a target
1730 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1731 (get-text-property (point-at-bol 2) 'target)))
1732 (progn
1733 ;; use the existing target in a neighboring line
1734 (setq tmp (match-string 2))
1735 (replace-match "")
1736 (and (looking-at "\n") (delete-char 1))
1737 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1738 target-alist)
1739 (setq a (or (assoc target org-export-target-aliases)
1740 (progn
1741 (push (list target) org-export-target-aliases)
1742 (car org-export-target-aliases))))
1743 (push tmp (cdr a)))
1744 ;; Make an invisible target
1745 (replace-match "\\1(INVISIBLE)"))))
1746 target-alist)
1748 (defun org-export-target-internal-links (target-alist)
1749 "Find all internal links and assign targets to them.
1750 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1751 let the link point to the corresponding section.
1752 This function also handles the id links, if they have a match in
1753 the current file."
1754 (goto-char (point-min))
1755 (while (re-search-forward org-bracket-link-regexp nil t)
1756 (org-if-unprotected
1757 (let* ((md (match-data))
1758 (desc (match-end 2))
1759 (link (org-link-unescape (match-string 1)))
1760 (slink (org-solidify-link-text link))
1761 found props pos cref
1762 (target
1763 (cond
1764 ((cdr (assoc slink target-alist)))
1765 ((and (string-match "^id:" link)
1766 (cdr (assoc (substring link 3) target-alist))))
1767 ((string-match "^(\\(.*\\))$" link)
1768 (setq cref (match-string 1 link))
1769 (concat "coderef:" cref))
1770 ((string-match org-link-types-re link) nil)
1771 ((or (file-name-absolute-p link)
1772 (string-match "^\\." link))
1773 nil)
1775 (save-excursion
1776 (setq found (condition-case nil (org-link-search link)
1777 (error nil)))
1778 (when (and found
1779 (or (org-on-heading-p)
1780 (not (eq found 'dedicated))))
1781 (or (get-text-property (point) 'target)
1782 (get-text-property
1783 (max (point-min)
1784 (1- (or (previous-single-property-change
1785 (point) 'target) 0)))
1786 'target))))))))
1787 (when target
1788 (set-match-data md)
1789 (goto-char (match-beginning 1))
1790 (setq props (text-properties-at (point)))
1791 (delete-region (match-beginning 1) (match-end 1))
1792 (setq pos (point))
1793 (insert target)
1794 (unless desc (insert "][" link))
1795 (add-text-properties pos (point) props))))))
1797 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1798 "Remove drawers, or extract the content.
1799 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1800 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1801 whose content to keep."
1802 (unless (eq t exp-drawers)
1803 (goto-char (point-min))
1804 (let ((re (concat "^[ \t]*:\\("
1805 (mapconcat
1806 'identity
1807 (org-delete-all exp-drawers
1808 (copy-sequence all-drawers))
1809 "\\|")
1810 "\\):[ \t]*\n\\([^\000]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1811 (while (re-search-forward re nil t)
1812 (org-if-unprotected
1813 (replace-match ""))))))
1815 (defun org-export-handle-export-tags (select-tags exclude-tags)
1816 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1817 Both arguments are lists of tags.
1818 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1819 will be removed.
1820 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1821 removed as well."
1822 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1823 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1824 select-tags "\\|")
1825 "\\):"))
1826 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1827 exclude-tags "\\|")
1828 "\\):"))
1829 beg end cont)
1830 (goto-char (point-min))
1831 (when (and select-tags
1832 (re-search-forward
1833 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1834 ;; At least one tree is marked for export, this means
1835 ;; all the unmarked stuff needs to go.
1836 ;; Dig out the trees that should be exported
1837 (goto-char (point-min))
1838 (outline-next-heading)
1839 (setq beg (point))
1840 (put-text-property beg (point-max) :org-delete t)
1841 (while (re-search-forward re-sel nil t)
1842 (when (org-on-heading-p)
1843 (org-back-to-heading)
1844 (remove-text-properties
1845 (max (1- (point)) (point-min))
1846 (setq cont (save-excursion (org-end-of-subtree t t)))
1847 '(:org-delete t))
1848 (while (and (org-up-heading-safe)
1849 (get-text-property (point) :org-delete))
1850 (remove-text-properties (max (1- (point)) (point-min))
1851 (point-at-eol) '(:org-delete t)))
1852 (goto-char cont))))
1853 ;; Remove the trees explicitly marked for noexport
1854 (when exclude-tags
1855 (goto-char (point-min))
1856 (while (re-search-forward re-excl nil t)
1857 (when (org-at-heading-p)
1858 (org-back-to-heading t)
1859 (setq beg (point))
1860 (org-end-of-subtree t)
1861 (delete-region beg (point)))))
1862 ;; Remove everything that is now still marked for deletion
1863 (goto-char (point-min))
1864 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1865 (setq end (or (next-single-property-change beg :org-delete)
1866 (point-max)))
1867 (delete-region beg end))))
1869 (defun org-export-remove-archived-trees (export-archived-trees)
1870 "Remove archived trees.
1871 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1872 When it is t, the entire archived tree will be exported.
1873 When it is nil the entire tree including the headline will be removed
1874 from the buffer."
1875 (let ((re-archive (concat ":" org-archive-tag ":"))
1876 a b)
1877 (when (not (eq export-archived-trees t))
1878 (goto-char (point-min))
1879 (while (re-search-forward re-archive nil t)
1880 (if (not (org-on-heading-p t))
1881 (org-end-of-subtree t)
1882 (beginning-of-line 1)
1883 (setq a (if export-archived-trees
1884 (1+ (point-at-eol)) (point))
1885 b (org-end-of-subtree t))
1886 (if (> b a) (delete-region a b)))))))
1888 (defun org-export-remove-headline-metadata (opts)
1889 "Remove meta data from the headline, according to user options."
1890 (let ((re org-complex-heading-regexp)
1891 (todo (plist-get opts :todo-keywords))
1892 (tags (plist-get opts :tags))
1893 (pri (plist-get opts :priority))
1894 (elts '(1 2 3 4 5))
1895 rpl)
1896 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1897 (when (or (not todo) (not tags) (not pri))
1898 (goto-char (point-min))
1899 (while (re-search-forward re nil t)
1900 (org-if-unprotected
1901 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1902 elts " "))
1903 (replace-match rpl t t))))))
1905 (defun org-export-remove-timestamps ()
1906 "Remove timestamps and keywords for export."
1907 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1908 (backward-char 1)
1909 (org-if-unprotected
1910 (unless (save-match-data (org-at-table-p))
1911 (replace-match "")
1912 (beginning-of-line 1)
1913 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1914 (replace-match ""))))))
1916 (defun org-export-remove-clock-lines ()
1917 "Remove clock lines for export."
1918 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1919 (while (re-search-forward re nil t)
1920 (org-if-unprotected
1921 (replace-match "")))))
1923 (defun org-export-protect-quoted-subtrees ()
1924 "Mark quoted subtrees with the protection property."
1925 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1926 (goto-char (point-min))
1927 (while (re-search-forward re-quote nil t)
1928 (goto-char (match-beginning 0))
1929 (end-of-line 1)
1930 (add-text-properties (point) (org-end-of-subtree t)
1931 '(org-protected t)))))
1933 (defun org-export-protect-verbatim ()
1934 "Mark verbatim snippets with the protection property."
1935 (goto-char (point-min))
1936 (while (re-search-forward org-verbatim-re nil t)
1937 (add-text-properties (match-beginning 4) (match-end 4)
1938 '(org-protected t))
1939 (goto-char (1+ (match-end 4)))))
1941 (defun org-export-protect-colon-examples ()
1942 "Protect lines starting with a colon."
1943 (goto-char (point-min))
1944 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1945 (while (re-search-forward re nil t)
1946 (beginning-of-line 1)
1947 (setq beg (point))
1948 (while (looking-at re)
1949 (end-of-line 1)
1950 (or (eobp) (forward-char 1)))
1951 (add-text-properties beg (if (bolp) (1- (point)) (point))
1952 '(org-protected t)))))
1954 (defun org-export-select-backend-specific-text (backend)
1955 (let ((formatters
1956 '((html "HTML" "BEGIN_HTML" "END_HTML")
1957 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1958 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1959 (case-fold-search t)
1960 fmt)
1962 (while formatters
1963 (setq fmt (pop formatters))
1964 (when (eq (car fmt) backend)
1965 ;; This is selected code, put it into the file for real
1966 (goto-char (point-min))
1967 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1968 ":[ \t]*\\(.*\\)") nil t)
1969 (replace-match "\\1" t)
1970 (add-text-properties
1971 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1972 '(org-protected t))))
1973 (goto-char (point-min))
1974 (while (re-search-forward
1975 (concat "^#\\+"
1976 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1977 (cadddr fmt) "\\>.*\n?") nil t)
1978 (if (eq (car fmt) backend)
1979 ;; yes, keep this
1980 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1981 '(org-protected t))
1982 ;; No, this is for a different backend, kill it
1983 (delete-region (match-beginning 0) (match-end 0)))))))
1985 (defun org-export-mark-blockquote-and-verse ()
1986 "Mark block quote and verse environments with special cookies.
1987 These special cookies will later be interpreted by the backend."
1988 ;; Blockquotes
1989 (goto-char (point-min))
1990 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1991 nil t)
1992 (replace-match (if (equal (downcase (match-string 1)) "end")
1993 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1994 t t))
1995 ;; Verse
1996 (goto-char (point-min))
1997 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1998 (replace-match (if (equal (downcase (match-string 1)) "end")
1999 "ORG-VERSE-END" "ORG-VERSE-START")
2000 t t)))
2002 (defun org-export-attach-captions-and-attributes (backend target-alist)
2003 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
2004 If the next thing following is a table, add the text properties to the first
2005 table line. If it is a link, add it to the line containing the link."
2006 (goto-char (point-min))
2007 (remove-text-properties (point-min) (point-max)
2008 '(org-caption nil org-attributes nil))
2009 (let ((case-fold-search t)
2010 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
2011 "\\|"
2012 "^#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
2013 "\\|"
2014 "^#\\+label:[ \t]+\\(.*\\)"
2015 "\\|"
2016 "^[ \t]*|[^-]"
2017 "\\|"
2018 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
2019 cap attr label)
2020 (while (re-search-forward re nil t)
2021 (cond
2022 ((match-end 1)
2023 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
2024 ((match-end 2)
2025 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
2026 ((match-end 3)
2027 (setq label (org-trim (match-string 3))))
2029 (add-text-properties (point-at-bol) (point-at-eol)
2030 (list 'org-caption cap
2031 'org-attributes attr
2032 'org-label label))
2033 (if label (push (cons label label) target-alist))
2034 (setq cap nil attr nil label nil)))))
2035 target-alist)
2037 (defun org-export-remove-comment-blocks-and-subtrees ()
2038 "Remove the comment environment, and also commented subtrees."
2039 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
2040 (case-fold-search nil))
2041 ;; Remove comment environment
2042 (goto-char (point-min))
2043 (while (re-search-forward
2044 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
2045 (replace-match "" t t))
2046 ;; Remove subtrees that are commented
2047 (goto-char (point-min))
2048 (while (re-search-forward re-commented nil t)
2049 (goto-char (match-beginning 0))
2050 (delete-region (point) (org-end-of-subtree t)))))
2052 (defun org-export-handle-comments (commentsp)
2053 "Remove comments, or convert to backend-specific format.
2054 COMMENTSP can be a format string for publishing comments.
2055 When it is nil, all comments will be removed."
2056 (let ((re "^#\\(.*\n?\\)")
2057 pos)
2058 (goto-char (point-min))
2059 (while (or (looking-at re)
2060 (re-search-forward re nil t))
2061 (setq pos (match-beginning 0))
2062 (if commentsp
2063 (progn (add-text-properties
2064 (match-beginning 0) (match-end 0) '(org-protected t))
2065 (replace-match (format commentsp (match-string 1)) t t))
2066 (goto-char (1+ pos))
2067 (org-if-unprotected
2068 (replace-match "")
2069 (goto-char (max (point-min) (1- pos))))))))
2071 (defun org-export-mark-radio-links ()
2072 "Find all matches for radio targets and turn them into internal links."
2073 (let ((re-radio (and org-target-link-regexp
2074 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
2075 (goto-char (point-min))
2076 (when re-radio
2077 (while (re-search-forward re-radio nil t)
2078 (org-if-unprotected
2079 (replace-match "\\1[[\\2]]"))))))
2081 (defun org-export-remove-special-table-lines ()
2082 "Remove tables lines that are used for internal purposes."
2083 (goto-char (point-min))
2084 (while (re-search-forward "^[ \t]*|" nil t)
2085 (beginning-of-line 1)
2086 (if (or (looking-at "[ \t]*| *[!_^] *|")
2087 (and (looking-at ".*?| *<[0-9]+> *|")
2088 (not (looking-at ".*?| *[^ <|]"))))
2089 (delete-region (max (point-min) (1- (point-at-bol)))
2090 (point-at-eol))
2091 (end-of-line 1))))
2093 (defun org-export-normalize-links ()
2094 "Convert all links to bracket links, and expand link abbreviations."
2095 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
2096 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
2097 (goto-char (point-min))
2098 (while (re-search-forward re-plain-link nil t)
2099 (goto-char (1- (match-end 0)))
2100 (org-if-unprotected-at (1+ (match-beginning 0))
2101 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2102 ":" (match-string 3) "]]")))
2103 ;; added 'org-link face to links
2104 (put-text-property 0 (length s) 'face 'org-link s)
2105 (replace-match s t t))))
2106 (goto-char (point-min))
2107 (while (re-search-forward re-angle-link nil t)
2108 (goto-char (1- (match-end 0)))
2109 (org-if-unprotected
2110 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2111 ":" (match-string 3) "]]")))
2112 (put-text-property 0 (length s) 'face 'org-link s)
2113 (replace-match s t t))))
2114 (goto-char (point-min))
2115 (while (re-search-forward org-bracket-link-regexp nil t)
2116 (goto-char (1- (match-end 0)))
2117 (org-if-unprotected
2118 (let* ((xx (save-match-data
2119 (org-translate-link
2120 (org-link-expand-abbrev (match-string 1)))))
2121 (s (concat
2122 "[[" (org-add-props (copy-sequence xx)
2123 nil 'org-protected t)
2125 (if (match-end 3)
2126 (match-string 2)
2127 (concat "[" (org-add-props
2128 (copy-sequence xx)
2129 '(org-protected t))
2130 "]"))
2131 "]")))
2132 (put-text-property 0 (length s) 'face 'org-link s)
2133 (replace-match s t t))))))
2135 (defun org-export-concatenate-multiline-links ()
2136 "Find multi-line links and put it all into a single line.
2137 This is to make sure that the line-processing export backends
2138 can work correctly."
2139 (goto-char (point-min))
2140 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
2141 (org-if-unprotected
2142 (replace-match "\\1 \\3")
2143 (goto-char (match-beginning 0)))))
2145 (defun org-export-concatenate-multiline-emphasis ()
2146 "Find multi-line emphasis and put it all into a single line.
2147 This is to make sure that the line-processing export backends
2148 can work correctly."
2149 (goto-char (point-min))
2150 (while (re-search-forward org-emph-re nil t)
2151 (if (and (not (= (char-after (match-beginning 3))
2152 (char-after (match-beginning 4))))
2153 (save-excursion (goto-char (match-beginning 0))
2154 (save-match-data (not (org-at-table-p)))))
2155 (org-if-unprotected
2156 (subst-char-in-region (match-beginning 0) (match-end 0)
2157 ?\n ?\ t)
2158 (goto-char (1- (match-end 0))))
2159 (goto-char (1+ (match-beginning 0))))))
2161 (defun org-export-grab-title-from-buffer ()
2162 "Get a title for the current document, from looking at the buffer."
2163 (let ((inhibit-read-only t))
2164 (save-excursion
2165 (goto-char (point-min))
2166 (let ((end (if (looking-at org-outline-regexp)
2167 (point)
2168 (save-excursion (outline-next-heading) (point)))))
2169 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
2170 ;; Mark the line so that it will not be exported as normal text.
2171 (org-unmodified
2172 (add-text-properties (match-beginning 0) (match-end 0)
2173 (list :org-license-to-kill t)))
2174 ;; Return the title string
2175 (org-trim (match-string 0)))))))
2177 (defun org-export-get-title-from-subtree ()
2178 "Return subtree title and exclude it from export."
2179 (let (title (rbeg (region-beginning)) (rend (region-end)))
2180 (save-excursion
2181 (goto-char rbeg)
2182 (when (and (org-at-heading-p)
2183 (>= (org-end-of-subtree t t) rend))
2184 ;; This is a subtree, we take the title from the first heading
2185 (goto-char rbeg)
2186 (looking-at org-todo-line-regexp)
2187 (setq title (match-string 3))
2188 (org-unmodified
2189 (add-text-properties (point) (1+ (point-at-eol))
2190 (list :org-license-to-kill t)))
2191 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
2192 title))
2194 (defun org-solidify-link-text (s &optional alist)
2195 "Take link text and make a safe target out of it."
2196 (save-match-data
2197 (let* ((rtn
2198 (mapconcat
2199 'identity
2200 (org-split-string s "[ \t\r\n]+") "=="))
2201 (a (assoc rtn alist)))
2202 (or (cdr a) rtn))))
2204 (defun org-get-min-level (lines &optional offset)
2205 "Get the minimum level in LINES."
2206 (let ((re "^\\(\\*+\\) ") l)
2207 (catch 'exit
2208 (while (setq l (pop lines))
2209 (if (string-match re l)
2210 (throw 'exit (org-tr-level (- (length (match-string 1 l))
2211 (or offset 0))))))
2212 1)))
2214 ;; Variable holding the vector with section numbers
2215 (defvar org-section-numbers (make-vector org-level-max 0))
2217 (defun org-init-section-numbers ()
2218 "Initialize the vector for the section numbers."
2219 (let* ((level -1)
2220 (numbers (nreverse (org-split-string "" "\\.")))
2221 (depth (1- (length org-section-numbers)))
2222 (i depth) number-string)
2223 (while (>= i 0)
2224 (if (> i level)
2225 (aset org-section-numbers i 0)
2226 (setq number-string (or (car numbers) "0"))
2227 (if (string-match "\\`[A-Z]\\'" number-string)
2228 (aset org-section-numbers i
2229 (- (string-to-char number-string) ?A -1))
2230 (aset org-section-numbers i (string-to-number number-string)))
2231 (pop numbers))
2232 (setq i (1- i)))))
2234 (defun org-section-number (&optional level)
2235 "Return a string with the current section number.
2236 When LEVEL is non-nil, increase section numbers on that level."
2237 (let* ((depth (1- (length org-section-numbers)))
2238 (string "")
2239 (fmts (car org-export-section-number-format))
2240 (term (cdr org-export-section-number-format))
2241 (sep "")
2242 ctype fmt idx n)
2243 (when level
2244 (when (> level -1)
2245 (aset org-section-numbers
2246 level (1+ (aref org-section-numbers level))))
2247 (setq idx (1+ level))
2248 (while (<= idx depth)
2249 (if (not (= idx 1))
2250 (aset org-section-numbers idx 0))
2251 (setq idx (1+ idx))))
2252 (setq idx 0)
2253 (while (<= idx depth)
2254 (when (> (aref org-section-numbers idx) 0)
2255 (setq fmt (or (pop fmts) fmt)
2256 ctype (car fmt)
2257 n (aref org-section-numbers idx)
2258 string (if (> n 0)
2259 (concat string sep (org-number-to-counter n ctype))
2260 (concat string ".0"))
2261 sep (nth 1 fmt)))
2262 (setq idx (1+ idx)))
2263 (save-match-data
2264 (if (string-match "\\`\\([@0]\\.\\)+" string)
2265 (setq string (replace-match "" t nil string)))
2266 (if (string-match "\\(\\.0\\)+\\'" string)
2267 (setq string (replace-match "" t nil string))))
2268 (concat string term)))
2270 (defun org-number-to-counter (n type)
2271 "Concert number N to a string counter, according to TYPE.
2272 TYPE must be a string, any of:
2273 1 number
2274 A A,B,....
2275 a a,b,....
2276 I upper case roman numeral
2277 i lower case roman numeral"
2278 (cond
2279 ((equal type "1") (number-to-string n))
2280 ((equal type "A") (char-to-string (+ ?A n -1)))
2281 ((equal type "a") (char-to-string (+ ?a n -1)))
2282 ((equal type "I") (org-number-to-roman n))
2283 ((equal type "i") (downcase (org-number-to-roman n)))
2284 (t (error "Invalid counter type `%s'" type))))
2286 (defun org-number-to-roman (n)
2287 "Convert integer N into a roman numeral."
2288 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2289 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2290 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2291 ( 1 . "I")))
2292 (res ""))
2293 (if (<= n 0)
2294 (number-to-string n)
2295 (while roman
2296 (if (>= n (caar roman))
2297 (setq n (- n (caar roman))
2298 res (concat res (cdar roman)))
2299 (pop roman)))
2300 res)))
2302 ;;; Macros
2304 (defun org-export-preprocess-apply-macros ()
2305 "Replace macro references."
2306 (goto-char (point-min))
2307 (let (sy val key)
2308 (while (re-search-forward "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)}}}" nil t)
2309 (setq key (downcase (match-string 1)))
2310 (when (setq val (or (plist-get org-export-opt-plist
2311 (intern (concat ":macro-" key)))
2312 (plist-get org-export-opt-plist
2313 (intern (concat ":" key)))))
2314 (and (stringp val)
2315 (replace-match val t t))))))
2317 ;;; Include files
2319 (defun org-export-handle-include-files ()
2320 "Include the contents of include files, with proper formatting."
2321 (let ((case-fold-search t)
2322 params file markup lang start end prefix prefix1 switches)
2323 (goto-char (point-min))
2324 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2325 (setq params (read (concat "(" (match-string 1) ")"))
2326 prefix (org-get-and-remove-property 'params :prefix)
2327 prefix1 (org-get-and-remove-property 'params :prefix1)
2328 file (org-symname-or-string (pop params))
2329 markup (org-symname-or-string (pop params))
2330 lang (and (member markup '("src" "SRC"))
2331 (org-symname-or-string (pop params)))
2332 switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
2333 (delete-region (match-beginning 0) (match-end 0))
2334 (if (or (not file)
2335 (not (file-exists-p file))
2336 (not (file-readable-p file)))
2337 (insert (format "CANNOT INCLUDE FILE %s" file))
2338 (when markup
2339 (if (equal (downcase markup) "src")
2340 (setq start (format "#+begin_src %s %s\n"
2341 (or lang "fundamental")
2342 (or switches ""))
2343 end "#+end_src")
2344 (setq start (format "#+begin_%s %s\n" markup switches)
2345 end (format "#+end_%s" markup))))
2346 (insert (or start ""))
2347 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2348 (or (bolp) (newline))
2349 (insert (or end ""))))))
2351 (defun org-get-file-contents (file &optional prefix prefix1)
2352 "Get the contents of FILE and return them as a string.
2353 If PREFIX is a string, prepend it to each line. If PREFIX1
2354 is a string, prepend it to the first line instead of PREFIX."
2355 (with-temp-buffer
2356 (insert-file-contents file)
2357 (when (or prefix prefix1)
2358 (goto-char (point-min))
2359 (while (not (eobp))
2360 (insert (or prefix1 prefix))
2361 (setq prefix1 nil)
2362 (beginning-of-line 2)))
2363 (buffer-string)))
2365 (defun org-get-and-remove-property (listvar prop)
2366 "Check if the value of LISTVAR contains PROP as a property.
2367 If yes, return the value of that property (i.e. the element following
2368 in the list) and remove property and value from the list in LISTVAR."
2369 (let ((list (symbol-value listvar)) m v)
2370 (when (setq m (member prop list))
2371 (setq v (nth 1 m))
2372 (if (equal (car list) prop)
2373 (set listvar (cddr list))
2374 (setcdr (nthcdr (- (length list) (length m) 1) list)
2375 (cddr m))
2376 (set listvar list)))
2379 (defun org-symname-or-string (s)
2380 (if (symbolp s)
2381 (if s (symbol-name s) s)
2384 ;;; Fontification and line numbers for code examples
2386 (defvar org-export-last-code-line-counter-value 0)
2388 (defun org-export-replace-src-segments-and-examples (backend)
2389 "Replace source code segments with special code for export."
2390 (setq org-export-last-code-line-counter-value 0)
2391 (let ((case-fold-search t)
2392 lang code trans opts)
2393 (goto-char (point-min))
2394 (while (re-search-forward
2395 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2396 nil t)
2397 (if (match-end 1)
2398 ;; src segments
2399 (setq lang (match-string 2)
2400 opts (match-string 3)
2401 code (match-string 4))
2402 (setq lang nil
2403 opts (match-string 6)
2404 code (match-string 7)))
2406 (setq trans (org-export-format-source-code-or-example
2407 backend lang code opts))
2408 (replace-match trans t t))))
2410 (defvar htmlp) ;; dynamically scoped
2411 (defvar latexp) ;; dynamically scoped
2413 (defun org-export-format-source-code-or-example (backend
2414 lang code &optional opts)
2415 "Format CODE from language LANG and return it formatted for export.
2416 If LANG is nil, do not add any fontification.
2417 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2418 and `+n' for continuing previous numering.
2419 Code formatting according to language currently only works for HTML.
2420 Numbering lines works for all three major backends (html, latex, and ascii)."
2421 (save-match-data
2422 (let (num cont rtn rpllbl keepp textareap cols rows fmt)
2423 (setq opts (or opts "")
2424 num (string-match "[-+]n\\>" opts)
2425 cont (string-match "\\+n\\>" opts)
2426 rpllbl (string-match "-r\\>" opts)
2427 keepp (string-match "-k\\>" opts)
2428 textareap (string-match "-t\\>" opts)
2429 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2430 (string-to-number (match-string 1 opts))
2432 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2433 (string-to-number (match-string 1 opts))
2434 (org-count-lines code))
2435 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2436 (match-string 1 opts)))
2437 (when (and textareap (eq backend 'html))
2438 ;; we cannot use numbering or highlighting.
2439 (setq num nil cont nil lang nil))
2440 (if keepp (setq rpllbl 'keep))
2441 (setq rtn code)
2442 (when (equal lang "org")
2443 (setq rtn (with-temp-buffer
2444 (insert rtn)
2445 ;; Free up the protected lines
2446 (goto-char (point-min))
2447 (while (re-search-forward "^," nil t)
2448 (replace-match "")
2449 (end-of-line 1))
2450 (buffer-string))))
2451 ;; Now backend-specific coding
2452 (cond
2453 ((eq backend 'html)
2454 ;; We are exporting to HTML
2455 (when lang
2456 (require 'htmlize nil t)
2457 (when (not (fboundp 'htmlize-region-for-paste))
2458 ;; we do not have htmlize.el, or an old version of it
2459 (setq lang nil)
2460 (message
2461 "htmlize.el 1.34 or later is needed for source code formatting")))
2463 (if lang
2464 (let* ((mode (and lang (intern (concat lang "-mode"))))
2465 (org-inhibit-startup t)
2466 (org-startup-folded nil))
2467 (setq rtn
2468 (with-temp-buffer
2469 (insert rtn)
2470 (if (functionp mode)
2471 (funcall mode)
2472 (fundamental-mode))
2473 (font-lock-fontify-buffer)
2474 (org-export-htmlize-region-for-paste
2475 (point-min) (point-max))))
2476 (if (string-match "<pre\\([^>]*\\)>\n?" rtn)
2477 (setq rtn (replace-match
2478 (format "<pre class=\"src src-%s\">\n" lang)
2479 t t rtn))))
2480 (if textareap
2481 (setq rtn (concat
2482 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2483 cols rows)
2484 rtn "</textarea>\n</p>\n"))
2485 (with-temp-buffer
2486 (insert rtn)
2487 (goto-char (point-min))
2488 (while (re-search-forward "[<>&]" nil t)
2489 (replace-match (cdr (assq (char-before)
2490 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2491 t t))
2492 (setq rtn (buffer-string)))
2493 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2494 (unless textareap
2495 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2496 cont rpllbl fmt)))
2497 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2498 ((eq backend 'latex)
2499 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2500 (concat "\n#+BEGIN_LaTeX\n"
2501 (org-add-props (concat "\\begin{verbatim}\n" rtn "\n\\end{verbatim}\n")
2502 '(org-protected t))
2503 "#+END_LaTeX\n\n"))
2504 ((eq backend 'ascii)
2505 ;; This is not HTML or LaTeX, so just make it an example.
2506 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2507 (concat "#+BEGIN_ASCII\n"
2508 (org-add-props
2509 (concat
2510 (mapconcat
2511 (lambda (l) (concat " " l))
2512 (org-split-string rtn "\n")
2513 "\n")
2514 "\n")
2515 '(org-protected t))
2516 "#+END_ASCII\n"))))))
2518 (defun org-export-number-lines (text backend
2519 &optional skip1 skip2 number cont
2520 replace-labels label-format)
2521 (if (and (not number) (not (eq replace-labels 'keep)))
2522 (setq replace-labels nil)) ;; must use names if no numbers
2523 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2524 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2525 (with-temp-buffer
2526 (insert text)
2527 (goto-char (point-max))
2528 (skip-chars-backward " \t\n\r")
2529 (delete-region (point) (point-max))
2530 (beginning-of-line (- 1 skip2))
2531 (let* ((last (org-current-line))
2532 (n org-export-last-code-line-counter-value)
2533 (nmax (+ n (- last skip1)))
2534 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2536 (cond
2537 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2538 fmt))
2539 ((eq backend 'ascii) fmt)
2540 ((eq backend 'latex) fmt)
2541 (t "")))
2542 (label-format (or label-format org-coderef-label-format))
2543 (label-pre (if (string-match "%s" label-format)
2544 (substring label-format 0 (match-beginning 0))
2545 label-format))
2546 (label-post (if (string-match "%s" label-format)
2547 (substring label-format (match-end 0))
2548 ""))
2549 (lbl-re
2550 (concat
2551 ".*?\\S-.*?\\([ \t]*\\("
2552 (regexp-quote label-pre)
2553 "\\([-a-zA-Z0-9_]+\\)"
2554 (regexp-quote label-post)
2555 "\\)\\)"))
2556 ref)
2558 (goto-line (1+ skip1))
2559 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2560 (if number
2561 (insert (format fm (incf n)))
2562 (forward-char 1))
2563 (when (and (not (eq replace-labels 'keep))
2564 (looking-at lbl-re))
2565 (setq ref (match-string 3))
2566 (if replace-labels
2567 (progn
2568 (delete-region (match-beginning 1) (match-end 1))
2569 (push (cons ref n) org-export-code-refs))
2570 (goto-char (match-beginning 2))
2571 (delete-region (match-beginning 2) (match-end 2))
2572 (insert "(" ref ")")
2573 (push (cons ref (concat "(" ref ")")) org-export-code-refs))
2574 (when (eq backend 'html)
2575 (save-excursion
2576 (beginning-of-line 1)
2577 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2578 ref))
2579 (end-of-line 1)
2580 (insert "</span>")))))
2581 (setq org-export-last-code-line-counter-value n)
2582 (goto-char (point-max))
2583 (newline)
2584 (buffer-string))))
2586 ;;; ASCII export
2588 (defvar org-last-level nil) ; dynamically scoped variable
2589 (defvar org-min-level nil) ; dynamically scoped variable
2590 (defvar org-levels-open nil) ; dynamically scoped parameter
2591 (defvar org-ascii-current-indentation nil) ; For communication
2593 ;;;###autoload
2594 (defun org-export-as-ascii (arg)
2595 "Export the outline as a pretty ASCII file.
2596 If there is an active region, export only the region.
2597 The prefix ARG specifies how many levels of the outline should become
2598 underlined headlines. The default is 3."
2599 (interactive "P")
2600 (setq-default org-todo-line-regexp org-todo-line-regexp)
2601 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2602 (org-infile-export-plist)))
2603 (region-p (org-region-active-p))
2604 (rbeg (and region-p (region-beginning)))
2605 (rend (and region-p (region-end)))
2606 (subtree-p
2607 (when region-p
2608 (save-excursion
2609 (goto-char rbeg)
2610 (and (org-at-heading-p)
2611 (>= (org-end-of-subtree t t) rend)))))
2612 (level-offset (if subtree-p
2613 (save-excursion
2614 (goto-char rbeg)
2615 (+ (funcall outline-level)
2616 (if org-odd-levels-only 1 0)))
2618 (opt-plist (setq org-export-opt-plist
2619 (if subtree-p
2620 (org-export-add-subtree-options opt-plist rbeg)
2621 opt-plist)))
2622 (custom-times org-display-custom-times)
2623 (org-ascii-current-indentation '(0 . 0))
2624 (level 0) line txt
2625 (umax nil)
2626 (umax-toc nil)
2627 (case-fold-search nil)
2628 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2629 (filename (concat (file-name-as-directory
2630 (org-export-directory :ascii opt-plist))
2631 (file-name-sans-extension
2632 (or (and subtree-p
2633 (org-entry-get (region-beginning)
2634 "EXPORT_FILE_NAME" t))
2635 (file-name-nondirectory bfname)))
2636 ".txt"))
2637 (filename (if (equal (file-truename filename)
2638 (file-truename bfname))
2639 (concat filename ".txt")
2640 filename))
2641 (buffer (find-file-noselect filename))
2642 (org-levels-open (make-vector org-level-max nil))
2643 (odd org-odd-levels-only)
2644 (date (plist-get opt-plist :date))
2645 (author (plist-get opt-plist :author))
2646 (title (or (and subtree-p (org-export-get-title-from-subtree))
2647 (plist-get opt-plist :title)
2648 (and (not
2649 (plist-get opt-plist :skip-before-1st-heading))
2650 (org-export-grab-title-from-buffer))
2651 (file-name-sans-extension
2652 (file-name-nondirectory bfname))))
2653 (email (plist-get opt-plist :email))
2654 (language (plist-get opt-plist :language))
2655 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2656 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2657 (todo nil)
2658 (lang-words nil)
2659 (region
2660 (buffer-substring
2661 (if (org-region-active-p) (region-beginning) (point-min))
2662 (if (org-region-active-p) (region-end) (point-max))))
2663 (lines (org-split-string
2664 (org-export-preprocess-string
2665 region
2666 :for-ascii t
2667 :skip-before-1st-heading
2668 (plist-get opt-plist :skip-before-1st-heading)
2669 :drawers (plist-get opt-plist :drawers)
2670 :tags (plist-get opt-plist :tags)
2671 :priority (plist-get opt-plist :priority)
2672 :footnotes (plist-get opt-plist :footnotes)
2673 :timestamps (plist-get opt-plist :timestamps)
2674 :todo-keywords (plist-get opt-plist :todo-keywords)
2675 :verbatim-multiline t
2676 :select-tags (plist-get opt-plist :select-tags)
2677 :exclude-tags (plist-get opt-plist :exclude-tags)
2678 :archived-trees
2679 (plist-get opt-plist :archived-trees)
2680 :add-text (plist-get opt-plist :text))
2681 "\n"))
2682 thetoc have-headings first-heading-pos
2683 table-open table-buffer link-buffer link desc desc0 rpl wrap)
2684 (let ((inhibit-read-only t))
2685 (org-unmodified
2686 (remove-text-properties (point-min) (point-max)
2687 '(:org-license-to-kill t))))
2689 (setq org-min-level (org-get-min-level lines level-offset))
2690 (setq org-last-level org-min-level)
2691 (org-init-section-numbers)
2693 (find-file-noselect filename)
2695 (setq lang-words (or (assoc language org-export-language-setup)
2696 (assoc "en" org-export-language-setup)))
2697 (switch-to-buffer-other-window buffer)
2698 (erase-buffer)
2699 (fundamental-mode)
2700 ;; create local variables for all options, to make sure all called
2701 ;; functions get the correct information
2702 (mapc (lambda (x)
2703 (set (make-local-variable (nth 2 x))
2704 (plist-get opt-plist (car x))))
2705 org-export-plist-vars)
2706 (org-set-local 'org-odd-levels-only odd)
2707 (setq umax (if arg (prefix-numeric-value arg)
2708 org-export-headline-levels))
2709 (setq umax-toc (if (integerp org-export-with-toc)
2710 (min org-export-with-toc umax)
2711 umax))
2713 ;; File header
2714 (if title (org-insert-centered title ?=))
2715 (insert "\n")
2716 (if (and (or author email)
2717 org-export-author-info)
2718 (insert (concat (nth 1 lang-words) ": " (or author "")
2719 (if email (concat " <" email ">") "")
2720 "\n")))
2722 (cond
2723 ((and date (string-match "%" date))
2724 (setq date (format-time-string date)))
2725 (date)
2726 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2728 (if (and date org-export-time-stamp-file)
2729 (insert (concat (nth 2 lang-words) ": " date"\n")))
2731 (insert "\n\n")
2733 (if org-export-with-toc
2734 (progn
2735 (push (concat (nth 3 lang-words) "\n") thetoc)
2736 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2737 "\n") thetoc)
2738 (mapc '(lambda (line)
2739 (if (string-match org-todo-line-regexp
2740 line)
2741 ;; This is a headline
2742 (progn
2743 (setq have-headings t)
2744 (setq level (- (match-end 1) (match-beginning 1)
2745 level-offset)
2746 level (org-tr-level level)
2747 txt (match-string 3 line)
2748 todo
2749 (or (and org-export-mark-todo-in-toc
2750 (match-beginning 2)
2751 (not (member (match-string 2 line)
2752 org-done-keywords)))
2753 ; TODO, not DONE
2754 (and org-export-mark-todo-in-toc
2755 (= level umax-toc)
2756 (org-search-todo-below
2757 line lines level))))
2758 (setq txt (org-html-expand-for-ascii txt))
2760 (while (string-match org-bracket-link-regexp txt)
2761 (setq txt
2762 (replace-match
2763 (match-string (if (match-end 2) 3 1) txt)
2764 t t txt)))
2766 (if (and (memq org-export-with-tags '(not-in-toc nil))
2767 (string-match
2768 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2769 txt))
2770 (setq txt (replace-match "" t t txt)))
2771 (if (string-match quote-re0 txt)
2772 (setq txt (replace-match "" t t txt)))
2774 (if org-export-with-section-numbers
2775 (setq txt (concat (org-section-number level)
2776 " " txt)))
2777 (if (<= level umax-toc)
2778 (progn
2779 (push
2780 (concat
2781 (make-string
2782 (* (max 0 (- level org-min-level)) 4) ?\ )
2783 (format (if todo "%s (*)\n" "%s\n") txt))
2784 thetoc)
2785 (setq org-last-level level))
2786 ))))
2787 lines)
2788 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2790 (org-init-section-numbers)
2791 (while (setq line (pop lines))
2792 (when (and link-buffer (string-match "^\\*+ " line))
2793 (org-export-ascii-push-links (nreverse link-buffer))
2794 (setq link-buffer nil))
2795 (setq wrap nil)
2796 ;; Remove the quoted HTML tags.
2797 (setq line (org-html-expand-for-ascii line))
2798 ;; Replace links with the description when possible
2799 (while (string-match org-bracket-link-regexp line)
2800 (setq link (match-string 1 line)
2801 desc0 (match-string 3 line)
2802 desc (or desc0 (match-string 1 line)))
2803 (if (and (> (length link) 8)
2804 (equal (substring link 0 8) "coderef:"))
2805 (setq line (replace-match
2806 (format (org-export-get-coderef-format (substring link 8) desc)
2807 (cdr (assoc
2808 (substring link 8)
2809 org-export-code-refs)))
2810 t t line))
2811 (setq rpl (concat "["
2812 (or (match-string 3 line) (match-string 1 line))
2813 "]"))
2814 (when (and desc0 (not (equal desc0 link)))
2815 (if org-export-ascii-links-to-notes
2816 (push (cons desc0 link) link-buffer)
2817 (setq rpl (concat rpl " (" link ")")
2818 wrap (+ (length line) (- (length (match-string 0)))
2819 (length desc)))))
2820 (setq line (replace-match rpl t t line))))
2821 (when custom-times
2822 (setq line (org-translate-time line)))
2823 (cond
2824 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2825 ;; a Headline
2826 (setq first-heading-pos (or first-heading-pos (point)))
2827 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
2828 level-offset))
2829 txt (match-string 2 line))
2830 (org-ascii-level-start level txt umax lines))
2832 ((and org-export-with-tables
2833 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2834 (if (not table-open)
2835 ;; New table starts
2836 (setq table-open t table-buffer nil))
2837 ;; Accumulate lines
2838 (setq table-buffer (cons line table-buffer))
2839 (when (or (not lines)
2840 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2841 (car lines))))
2842 (setq table-open nil
2843 table-buffer (nreverse table-buffer))
2844 (insert (mapconcat
2845 (lambda (x)
2846 (org-fix-indentation x org-ascii-current-indentation))
2847 (org-format-table-ascii table-buffer)
2848 "\n") "\n")))
2850 (setq line (org-fix-indentation line org-ascii-current-indentation))
2851 ;; Remove forced line breaks
2852 (if (string-match "\\\\\\\\[ \t]*$" line)
2853 (setq line (replace-match "" t t line)))
2854 (if (and org-export-with-fixed-width
2855 (string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line))
2856 (setq line (replace-match "\\1" nil nil line))
2857 (if wrap (setq line (org-export-ascii-wrap line wrap))))
2858 (insert line "\n"))))
2860 (org-export-ascii-push-links (nreverse link-buffer))
2862 (normal-mode)
2864 ;; insert the table of contents
2865 (when thetoc
2866 (goto-char (point-min))
2867 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2868 (progn
2869 (goto-char (match-beginning 0))
2870 (replace-match ""))
2871 (goto-char first-heading-pos))
2872 (mapc 'insert thetoc)
2873 (or (looking-at "[ \t]*\n[ \t]*\n")
2874 (insert "\n\n")))
2876 ;; Convert whitespace place holders
2877 (goto-char (point-min))
2878 (let (beg end)
2879 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2880 (setq end (next-single-property-change beg 'org-whitespace))
2881 (goto-char beg)
2882 (delete-region beg end)
2883 (insert (make-string (- end beg) ?\ ))))
2885 (save-buffer)
2886 ;; remove display and invisible chars
2887 (let (beg end)
2888 (goto-char (point-min))
2889 (while (setq beg (next-single-property-change (point) 'display))
2890 (setq end (next-single-property-change beg 'display))
2891 (delete-region beg end)
2892 (goto-char beg)
2893 (insert "=>"))
2894 (goto-char (point-min))
2895 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2896 (setq end (next-single-property-change beg 'org-cwidth))
2897 (delete-region beg end)
2898 (goto-char beg)))
2899 (goto-char (point-min))))
2901 (defun org-export-ascii-preprocess ()
2902 "Do extra work for ASCII export"
2903 ;; Put quotes around verbatim text
2904 (goto-char (point-min))
2905 (while (re-search-forward org-verbatim-re nil t)
2906 (goto-char (match-end 2))
2907 (backward-delete-char 1) (insert "'")
2908 (goto-char (match-beginning 2))
2909 (delete-char 1) (insert "`")
2910 (goto-char (match-end 2)))
2911 ;; Remove target markers
2912 (goto-char (point-min))
2913 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
2914 (replace-match "\\1\\2")))
2916 (defun org-search-todo-below (line lines level)
2917 "Search the subtree below LINE for any TODO entries."
2918 (let ((rest (cdr (memq line lines)))
2919 (re org-todo-line-regexp)
2920 line lv todo)
2921 (catch 'exit
2922 (while (setq line (pop rest))
2923 (if (string-match re line)
2924 (progn
2925 (setq lv (- (match-end 1) (match-beginning 1))
2926 todo (and (match-beginning 2)
2927 (not (member (match-string 2 line)
2928 org-done-keywords))))
2929 ; TODO, not DONE
2930 (if (<= lv level) (throw 'exit nil))
2931 (if todo (throw 'exit t))))))))
2933 (defun org-html-expand-for-ascii (line)
2934 "Handle quoted HTML for ASCII export."
2935 (if org-export-html-expand
2936 (while (string-match "@<[^<>\n]*>" line)
2937 ;; We just remove the tags for now.
2938 (setq line (replace-match "" nil nil line))))
2939 line)
2942 (defun org-export-ascii-wrap (line where)
2943 "Wrap LINE at or before WHERE."
2944 (let ((ind (org-get-indentation line))
2945 pos)
2946 (catch 'found
2947 (loop for i from where downto (/ where 2) do
2948 (and (equal (aref line i) ?\ )
2949 (setq pos i)
2950 (throw 'found t))))
2951 (if pos
2952 (concat (substring line 0 pos) "\n"
2953 (make-string ind ?\ )
2954 (substring line (1+ pos)))
2955 line)))
2957 (defun org-export-ascii-push-links (link-buffer)
2958 "Push out links in the buffer."
2959 (when link-buffer
2960 ;; We still have links to push out.
2961 (insert "\n")
2962 (let ((ind ""))
2963 (save-match-data
2964 (if (save-excursion
2965 (re-search-backward
2966 "^\\(\\([ \t]*\\)\\|\\(\\*+ \\)\\)[^ \t\n]" nil t))
2967 (setq ind (or (match-string 2)
2968 (make-string (length (match-string 3)) ?\ )))))
2969 (mapc (lambda (x) (insert ind "[" (car x) "]: " (cdr x) "\n"))
2970 link-buffer))
2971 (insert "\n")))
2973 (defun org-insert-centered (s &optional underline)
2974 "Insert the string S centered and underline it with character UNDERLINE."
2975 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2976 (insert (make-string ind ?\ ) s "\n")
2977 (if underline
2978 (insert (make-string ind ?\ )
2979 (make-string (string-width s) underline)
2980 "\n"))))
2982 (defun org-ascii-level-start (level title umax &optional lines)
2983 "Insert a new level in ASCII export."
2984 (let (char (n (- level umax 1)) (ind 0))
2985 (if (> level umax)
2986 (progn
2987 (insert (make-string (* 2 n) ?\ )
2988 (char-to-string (nth (% n (length org-export-ascii-bullets))
2989 org-export-ascii-bullets))
2990 " " title "\n")
2991 ;; find the indentation of the next non-empty line
2992 (catch 'stop
2993 (while lines
2994 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2995 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2996 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2997 (pop lines)))
2998 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2999 (if (or (not (equal (char-before) ?\n))
3000 (not (equal (char-before (1- (point))) ?\n)))
3001 (insert "\n"))
3002 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
3003 (unless org-export-with-tags
3004 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3005 (setq title (replace-match "" t t title))))
3006 (if org-export-with-section-numbers
3007 (setq title (concat (org-section-number level) " " title)))
3008 (insert title "\n" (make-string (string-width title) char) "\n")
3009 (setq org-ascii-current-indentation '(0 . 0)))))
3011 ;;;###autoload
3012 (defun org-export-visible (type arg)
3013 "Create a copy of the visible part of the current buffer, and export it.
3014 The copy is created in a temporary buffer and removed after use.
3015 TYPE is the final key (as a string) that also select the export command in
3016 the `C-c C-e' export dispatcher.
3017 As a special case, if the you type SPC at the prompt, the temporary
3018 org-mode file will not be removed but presented to you so that you can
3019 continue to use it. The prefix arg ARG is passed through to the exporting
3020 command."
3021 (interactive
3022 (list (progn
3023 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
3024 (read-char-exclusive))
3025 current-prefix-arg))
3026 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
3027 (error "Invalid export key"))
3028 (let* ((binding (cdr (assoc type
3029 '((?a . org-export-as-ascii)
3030 (?\C-a . org-export-as-ascii)
3031 (?b . org-export-as-html-and-open)
3032 (?\C-b . org-export-as-html-and-open)
3033 (?h . org-export-as-html)
3034 (?H . org-export-as-html-to-buffer)
3035 (?R . org-export-region-as-html)
3036 (?x . org-export-as-xoxo)))))
3037 (keepp (equal type ?\ ))
3038 (file buffer-file-name)
3039 (buffer (get-buffer-create "*Org Export Visible*"))
3040 s e)
3041 ;; Need to hack the drawers here.
3042 (save-excursion
3043 (goto-char (point-min))
3044 (while (re-search-forward org-drawer-regexp nil t)
3045 (goto-char (match-beginning 1))
3046 (or (org-invisible-p) (org-flag-drawer nil))))
3047 (with-current-buffer buffer (erase-buffer))
3048 (save-excursion
3049 (setq s (goto-char (point-min)))
3050 (while (not (= (point) (point-max)))
3051 (goto-char (org-find-invisible))
3052 (append-to-buffer buffer s (point))
3053 (setq s (goto-char (org-find-visible))))
3054 (org-cycle-hide-drawers 'all)
3055 (goto-char (point-min))
3056 (unless keepp
3057 ;; Copy all comment lines to the end, to make sure #+ settings are
3058 ;; still available for the second export step. Kind of a hack, but
3059 ;; does do the trick.
3060 (if (looking-at "#[^\r\n]*")
3061 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
3062 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
3063 (append-to-buffer buffer (1+ (match-beginning 0))
3064 (min (point-max) (1+ (match-end 0))))))
3065 (set-buffer buffer)
3066 (let ((buffer-file-name file)
3067 (org-inhibit-startup t))
3068 (org-mode)
3069 (show-all)
3070 (unless keepp (funcall binding arg))))
3071 (if (not keepp)
3072 (kill-buffer buffer)
3073 (switch-to-buffer-other-window buffer)
3074 (goto-char (point-min)))))
3076 (defun org-find-visible ()
3077 (let ((s (point)))
3078 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
3079 (get-char-property s 'invisible)))
3081 (defun org-find-invisible ()
3082 (let ((s (point)))
3083 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
3084 (not (get-char-property s 'invisible))))
3087 ;;; HTML export
3089 (defvar org-archive-location) ;; gets loaded with the org-archive require.
3090 (defun org-get-current-options ()
3091 "Return a string with current options as keyword options.
3092 Does include HTML export options as well as TODO and CATEGORY stuff."
3093 (require 'org-archive)
3094 (format
3095 "#+TITLE: %s
3096 #+AUTHOR: %s
3097 #+EMAIL: %s
3098 #+DATE: %s
3099 #+LANGUAGE: %s
3100 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
3101 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
3103 #+EXPORT_SELECT_TAGS: %s
3104 #+EXPORT_EXCLUDE_TAGS: %s
3105 #+LINK_UP: %s
3106 #+LINK_HOME: %s
3107 #+CATEGORY: %s
3108 #+SEQ_TODO: %s
3109 #+TYP_TODO: %s
3110 #+PRIORITIES: %c %c %c
3111 #+DRAWERS: %s
3112 #+STARTUP: %s %s %s %s %s
3113 #+TAGS: %s
3114 #+FILETAGS: %s
3115 #+ARCHIVE: %s
3116 #+LINK: %s
3118 (buffer-name) (user-full-name) user-mail-address
3119 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
3120 org-export-default-language
3121 org-export-headline-levels
3122 org-export-with-section-numbers
3123 org-export-with-toc
3124 org-export-preserve-breaks
3125 org-export-html-expand
3126 org-export-with-fixed-width
3127 org-export-with-tables
3128 org-export-with-sub-superscripts
3129 org-export-with-special-strings
3130 org-export-with-footnotes
3131 org-export-with-emphasize
3132 org-export-with-timestamps
3133 org-export-with-TeX-macros
3134 org-export-with-LaTeX-fragments
3135 org-export-skip-text-before-1st-heading
3136 org-export-with-drawers
3137 org-export-with-todo-keywords
3138 org-export-with-priority
3139 org-export-with-tags
3140 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
3141 (mapconcat 'identity org-export-select-tags " ")
3142 (mapconcat 'identity org-export-exclude-tags " ")
3143 org-export-html-link-up
3144 org-export-html-link-home
3145 (or (ignore-errors
3146 (file-name-sans-extension
3147 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3148 "NOFILENAME")
3149 "TODO FEEDBACK VERIFY DONE"
3150 "Me Jason Marie DONE"
3151 org-highest-priority org-lowest-priority org-default-priority
3152 (mapconcat 'identity org-drawers " ")
3153 (cdr (assoc org-startup-folded
3154 '((nil . "showall") (t . "overview") (content . "content"))))
3155 (if org-odd-levels-only "odd" "oddeven")
3156 (if org-hide-leading-stars "hidestars" "showstars")
3157 (if org-startup-align-all-tables "align" "noalign")
3158 (cond ((eq org-log-done t) "logdone")
3159 ((equal org-log-done 'note) "lognotedone")
3160 ((not org-log-done) "nologdone"))
3161 (or (mapconcat (lambda (x)
3162 (cond
3163 ((equal '(:startgroup) x) "{")
3164 ((equal '(:endgroup) x) "}")
3165 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
3166 (t (car x))))
3167 (or org-tag-alist (org-get-buffer-tags)) " ") "")
3168 (mapconcat 'identity org-file-tags " ")
3169 org-archive-location
3170 "org file:~/org/%s.org"
3173 (defun org-export-html-preprocess (parameters)
3174 ;; Convert LaTeX fragments to images
3175 (when (plist-get parameters :LaTeX-fragments)
3176 (org-format-latex
3177 (concat "ltxpng/" (file-name-sans-extension
3178 (file-name-nondirectory
3179 org-current-export-file)))
3180 org-current-export-dir nil "Creating LaTeX image %s"))
3181 (message "Exporting..."))
3183 ;;;###autoload
3184 (defun org-insert-export-options-template ()
3185 "Insert into the buffer a template with information for exporting."
3186 (interactive)
3187 (if (not (bolp)) (newline))
3188 (let ((s (org-get-current-options)))
3189 (and (string-match "#\\+CATEGORY" s)
3190 (setq s (substring s 0 (match-beginning 0))))
3191 (insert s)))
3193 ;;;###autoload
3194 (defun org-export-as-html-and-open (arg)
3195 "Export the outline as HTML and immediately open it with a browser.
3196 If there is an active region, export only the region.
3197 The prefix ARG specifies how many levels of the outline should become
3198 headlines. The default is 3. Lower levels will become bulleted lists."
3199 (interactive "P")
3200 (org-export-as-html arg 'hidden)
3201 (org-open-file buffer-file-name))
3203 ;;;###autoload
3204 (defun org-export-as-html-batch ()
3205 "Call `org-export-as-html', may be used in batch processing as
3206 emacs --batch
3207 --load=$HOME/lib/emacs/org.el
3208 --eval \"(setq org-export-headline-levels 2)\"
3209 --visit=MyFile --funcall org-export-as-html-batch"
3210 (org-export-as-html org-export-headline-levels 'hidden))
3212 ;;;###autoload
3213 (defun org-export-as-html-to-buffer (arg)
3214 "Call `org-export-as-html` with output to a temporary buffer.
3215 No file is created. The prefix ARG is passed through to `org-export-as-html'."
3216 (interactive "P")
3217 (org-export-as-html arg nil nil "*Org HTML Export*")
3218 (switch-to-buffer-other-window "*Org HTML Export*"))
3220 ;;;###autoload
3221 (defun org-replace-region-by-html (beg end)
3222 "Assume the current region has org-mode syntax, and convert it to HTML.
3223 This can be used in any buffer. For example, you could write an
3224 itemized list in org-mode syntax in an HTML buffer and then use this
3225 command to convert it."
3226 (interactive "r")
3227 (let (reg html buf pop-up-frames)
3228 (save-window-excursion
3229 (if (org-mode-p)
3230 (setq html (org-export-region-as-html
3231 beg end t 'string))
3232 (setq reg (buffer-substring beg end)
3233 buf (get-buffer-create "*Org tmp*"))
3234 (with-current-buffer buf
3235 (erase-buffer)
3236 (insert reg)
3237 (org-mode)
3238 (setq html (org-export-region-as-html
3239 (point-min) (point-max) t 'string)))
3240 (kill-buffer buf)))
3241 (delete-region beg end)
3242 (insert html)))
3244 ;;;###autoload
3245 (defun org-export-region-as-html (beg end &optional body-only buffer)
3246 "Convert region from BEG to END in org-mode buffer to HTML.
3247 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
3248 contents, and only produce the region of converted text, useful for
3249 cut-and-paste operations.
3250 If BUFFER is a buffer or a string, use/create that buffer as a target
3251 of the converted HTML. If BUFFER is the symbol `string', return the
3252 produced HTML as a string and leave not buffer behind. For example,
3253 a Lisp program could call this function in the following way:
3255 (setq html (org-export-region-as-html beg end t 'string))
3257 When called interactively, the output buffer is selected, and shown
3258 in a window. A non-interactive call will only return the buffer."
3259 (interactive "r\nP")
3260 (when (interactive-p)
3261 (setq buffer "*Org HTML Export*"))
3262 (let ((transient-mark-mode t) (zmacs-regions t)
3263 ext-plist rtn)
3264 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
3265 (goto-char end)
3266 (set-mark (point)) ;; to activate the region
3267 (goto-char beg)
3268 (setq rtn (org-export-as-html
3269 nil nil ext-plist
3270 buffer body-only))
3271 (if (fboundp 'deactivate-mark) (deactivate-mark))
3272 (if (and (interactive-p) (bufferp rtn))
3273 (switch-to-buffer-other-window rtn)
3274 rtn)))
3276 (defvar html-table-tag nil) ; dynamically scoped into this.
3277 (defvar org-par-open nil)
3278 ;;;###autoload
3279 (defun org-export-as-html (arg &optional hidden ext-plist
3280 to-buffer body-only pub-dir)
3281 "Export the outline as a pretty HTML file.
3282 If there is an active region, export only the region. The prefix
3283 ARG specifies how many levels of the outline should become
3284 headlines. The default is 3. Lower levels will become bulleted
3285 lists. When HIDDEN is non-nil, don't display the HTML buffer.
3286 EXT-PLIST is a property list with external parameters overriding
3287 org-mode's default settings, but still inferior to file-local
3288 settings. When TO-BUFFER is non-nil, create a buffer with that
3289 name and export to that buffer. If TO-BUFFER is the symbol
3290 `string', don't leave any buffer behind but just return the
3291 resulting HTML as a string. When BODY-ONLY is set, don't produce
3292 the file header and footer, simply return the content of
3293 <body>...</body>, without even the body tags themselves. When
3294 PUB-DIR is set, use this as the publishing directory."
3295 (interactive "P")
3297 ;; Make sure we have a file name when we need it.
3298 (when (and (not (or to-buffer body-only))
3299 (not buffer-file-name))
3300 (if (buffer-base-buffer)
3301 (org-set-local 'buffer-file-name
3302 (with-current-buffer (buffer-base-buffer)
3303 buffer-file-name))
3304 (error "Need a file name to be able to export.")))
3306 (message "Exporting...")
3307 (setq-default org-todo-line-regexp org-todo-line-regexp)
3308 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
3309 (setq-default org-done-keywords org-done-keywords)
3310 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
3311 (let* ((opt-plist
3312 (org-export-process-option-filters
3313 (org-combine-plists (org-default-export-plist)
3314 ext-plist
3315 (org-infile-export-plist))))
3316 (style (concat (if (plist-get opt-plist :style-include-default)
3317 org-export-html-style-default)
3318 (plist-get opt-plist :style)
3319 (plist-get opt-plist :style-extra)
3320 "\n" org-export-html-scripts))
3321 (html-extension (plist-get opt-plist :html-extension))
3322 (link-validate (plist-get opt-plist :link-validation-function))
3323 valid thetoc have-headings first-heading-pos
3324 (odd org-odd-levels-only)
3325 (region-p (org-region-active-p))
3326 (rbeg (and region-p (region-beginning)))
3327 (rend (and region-p (region-end)))
3328 (subtree-p
3329 (if (plist-get opt-plist :ignore-subree-p)
3331 (when region-p
3332 (save-excursion
3333 (goto-char rbeg)
3334 (and (org-at-heading-p)
3335 (>= (org-end-of-subtree t t) rend))))))
3336 (level-offset (if subtree-p
3337 (save-excursion
3338 (goto-char rbeg)
3339 (+ (funcall outline-level)
3340 (if org-odd-levels-only 1 0)))
3342 (opt-plist (setq org-export-opt-plist
3343 (if subtree-p
3344 (org-export-add-subtree-options opt-plist rbeg)
3345 opt-plist)))
3346 ;; The following two are dynamically scoped into other
3347 ;; routines below.
3348 (org-current-export-dir
3349 (or pub-dir (org-export-directory :html opt-plist)))
3350 (org-current-export-file buffer-file-name)
3351 (level 0) (line "") (origline "") txt todo
3352 (umax nil)
3353 (umax-toc nil)
3354 (filename (if to-buffer nil
3355 (expand-file-name
3356 (concat
3357 (file-name-sans-extension
3358 (or (and subtree-p
3359 (org-entry-get (region-beginning)
3360 "EXPORT_FILE_NAME" t))
3361 (file-name-nondirectory buffer-file-name)))
3362 "." html-extension)
3363 (file-name-as-directory
3364 (or pub-dir (org-export-directory :html opt-plist))))))
3365 (current-dir (if buffer-file-name
3366 (file-name-directory buffer-file-name)
3367 default-directory))
3368 (buffer (if to-buffer
3369 (cond
3370 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
3371 (t (get-buffer-create to-buffer)))
3372 (find-file-noselect filename)))
3373 (org-levels-open (make-vector org-level-max nil))
3374 (date (plist-get opt-plist :date))
3375 (author (plist-get opt-plist :author))
3376 (title (or (and subtree-p (org-export-get-title-from-subtree))
3377 (plist-get opt-plist :title)
3378 (and (not
3379 (plist-get opt-plist :skip-before-1st-heading))
3380 (org-export-grab-title-from-buffer))
3381 (and buffer-file-name
3382 (file-name-sans-extension
3383 (file-name-nondirectory buffer-file-name)))
3384 "UNTITLED"))
3385 (html-table-tag (plist-get opt-plist :html-table-tag))
3386 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
3387 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
3388 (inquote nil)
3389 (infixed nil)
3390 (inverse nil)
3391 (in-local-list nil)
3392 (local-list-type nil)
3393 (local-list-indent nil)
3394 (llt org-plain-list-ordered-item-terminator)
3395 (email (plist-get opt-plist :email))
3396 (language (plist-get opt-plist :language))
3397 (lang-words nil)
3398 (head-count 0) cnt
3399 (start 0)
3400 (coding-system (and (boundp 'buffer-file-coding-system)
3401 buffer-file-coding-system))
3402 (coding-system-for-write (or org-export-html-coding-system
3403 coding-system))
3404 (save-buffer-coding-system (or org-export-html-coding-system
3405 coding-system))
3406 (charset (and coding-system-for-write
3407 (fboundp 'coding-system-get)
3408 (coding-system-get coding-system-for-write
3409 'mime-charset)))
3410 (region
3411 (buffer-substring
3412 (if region-p (region-beginning) (point-min))
3413 (if region-p (region-end) (point-max))))
3414 (lines
3415 (org-split-string
3416 (org-export-preprocess-string
3417 region
3418 :emph-multiline t
3419 :for-html t
3420 :skip-before-1st-heading
3421 (plist-get opt-plist :skip-before-1st-heading)
3422 :drawers (plist-get opt-plist :drawers)
3423 :todo-keywords (plist-get opt-plist :todo-keywords)
3424 :tags (plist-get opt-plist :tags)
3425 :priority (plist-get opt-plist :priority)
3426 :footnotes (plist-get opt-plist :footnotes)
3427 :timestamps (plist-get opt-plist :timestamps)
3428 :archived-trees
3429 (plist-get opt-plist :archived-trees)
3430 :select-tags (plist-get opt-plist :select-tags)
3431 :exclude-tags (plist-get opt-plist :exclude-tags)
3432 :add-text
3433 (plist-get opt-plist :text)
3434 :LaTeX-fragments
3435 (plist-get opt-plist :LaTeX-fragments))
3436 "[\r\n]"))
3437 table-open type
3438 table-buffer table-orig-buffer
3439 ind item-type starter didclose
3440 rpl path attr desc descp desc1 desc2 link
3441 snumber fnc item-tag
3442 footnotes footref-seen
3443 id-file
3446 (let ((inhibit-read-only t))
3447 (org-unmodified
3448 (remove-text-properties (point-min) (point-max)
3449 '(:org-license-to-kill t))))
3451 (message "Exporting...")
3453 (setq org-min-level (org-get-min-level lines level-offset))
3454 (setq org-last-level org-min-level)
3455 (org-init-section-numbers)
3457 (cond
3458 ((and date (string-match "%" date))
3459 (setq date (format-time-string date)))
3460 (date)
3461 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
3463 ;; Get the language-dependent settings
3464 (setq lang-words (or (assoc language org-export-language-setup)
3465 (assoc "en" org-export-language-setup)))
3467 ;; Switch to the output buffer
3468 (set-buffer buffer)
3469 (let ((inhibit-read-only t)) (erase-buffer))
3470 (fundamental-mode)
3472 (and (fboundp 'set-buffer-file-coding-system)
3473 (set-buffer-file-coding-system coding-system-for-write))
3475 (let ((case-fold-search nil)
3476 (org-odd-levels-only odd))
3477 ;; create local variables for all options, to make sure all called
3478 ;; functions get the correct information
3479 (mapc (lambda (x)
3480 (set (make-local-variable (nth 2 x))
3481 (plist-get opt-plist (car x))))
3482 org-export-plist-vars)
3483 (setq umax (if arg (prefix-numeric-value arg)
3484 org-export-headline-levels))
3485 (setq umax-toc (if (integerp org-export-with-toc)
3486 (min org-export-with-toc umax)
3487 umax))
3488 (unless body-only
3489 ;; File header
3490 (insert (format
3491 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3492 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3493 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3494 lang=\"%s\" xml:lang=\"%s\">
3495 <head>
3496 <title>%s</title>
3497 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3498 <meta name=\"generator\" content=\"Org-mode\"/>
3499 <meta name=\"generated\" content=\"%s\"/>
3500 <meta name=\"author\" content=\"%s\"/>
3502 </head>
3503 <body>
3504 <div id=\"content\">
3506 language language (org-html-expand title)
3507 (or charset "iso-8859-1") date author style))
3509 (insert (or (plist-get opt-plist :preamble) ""))
3511 (when (plist-get opt-plist :auto-preamble)
3512 (if title (insert (format org-export-html-title-format
3513 (org-html-expand title))))))
3515 (if (and org-export-with-toc (not body-only))
3516 (progn
3517 (push (format "<h%d>%s</h%d>\n"
3518 org-export-html-toplevel-hlevel
3519 (nth 3 lang-words)
3520 org-export-html-toplevel-hlevel)
3521 thetoc)
3522 (push "<div id=\"text-table-of-contents\">\n" thetoc)
3523 (push "<ul>\n<li>" thetoc)
3524 (setq lines
3525 (mapcar '(lambda (line)
3526 (if (string-match org-todo-line-regexp line)
3527 ;; This is a headline
3528 (progn
3529 (setq have-headings t)
3530 (setq level (- (match-end 1) (match-beginning 1)
3531 level-offset)
3532 level (org-tr-level level)
3533 txt (save-match-data
3534 (org-html-expand
3535 (org-export-cleanup-toc-line
3536 (match-string 3 line))))
3537 todo
3538 (or (and org-export-mark-todo-in-toc
3539 (match-beginning 2)
3540 (not (member (match-string 2 line)
3541 org-done-keywords)))
3542 ; TODO, not DONE
3543 (and org-export-mark-todo-in-toc
3544 (= level umax-toc)
3545 (org-search-todo-below
3546 line lines level))))
3547 (if (string-match
3548 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
3549 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
3550 (if (string-match quote-re0 txt)
3551 (setq txt (replace-match "" t t txt)))
3552 (setq snumber (org-section-number level))
3553 (if org-export-with-section-numbers
3554 (setq txt (concat snumber " " txt)))
3555 (if (<= level (max umax umax-toc))
3556 (setq head-count (+ head-count 1)))
3557 (if (<= level umax-toc)
3558 (progn
3559 (if (> level org-last-level)
3560 (progn
3561 (setq cnt (- level org-last-level))
3562 (while (>= (setq cnt (1- cnt)) 0)
3563 (push "\n<ul>\n<li>" thetoc))
3564 (push "\n" thetoc)))
3565 (if (< level org-last-level)
3566 (progn
3567 (setq cnt (- org-last-level level))
3568 (while (>= (setq cnt (1- cnt)) 0)
3569 (push "</li>\n</ul>" thetoc))
3570 (push "\n" thetoc)))
3571 ;; Check for targets
3572 (while (string-match org-any-target-regexp line)
3573 (setq line (replace-match
3574 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3575 t t line)))
3576 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
3577 (setq txt (replace-match "" t t txt)))
3578 (push
3579 (format
3580 (if todo
3581 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3582 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3583 snumber txt) thetoc)
3585 (setq org-last-level level))
3587 line)
3588 lines))
3589 (while (> org-last-level (1- org-min-level))
3590 (setq org-last-level (1- org-last-level))
3591 (push "</li>\n</ul>\n" thetoc))
3592 (push "</div>\n" thetoc)
3593 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3595 (setq head-count 0)
3596 (org-init-section-numbers)
3598 (org-open-par)
3600 (while (setq line (pop lines) origline line)
3601 (catch 'nextline
3603 ;; end of quote section?
3604 (when (and inquote (string-match "^\\*+ " line))
3605 (insert "</pre>\n")
3606 (setq inquote nil))
3607 ;; inside a quote section?
3608 (when inquote
3609 (insert (org-html-protect line) "\n")
3610 (throw 'nextline nil))
3612 ;; Fixed-width, verbatim lines (examples)
3613 (when (and org-export-with-fixed-width
3614 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
3615 (when (not infixed)
3616 (setq infixed t)
3617 (org-close-par-maybe)
3618 (insert "<pre class=\"example\">\n"))
3619 (insert (org-html-protect (match-string 3 line)) "\n")
3620 (when (or (not lines)
3621 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
3622 (car lines))))
3623 (setq infixed nil)
3624 (insert "</pre>\n"))
3625 (throw 'nextline nil))
3627 ;; Protected HTML
3628 (when (get-text-property 0 'org-protected line)
3629 (let (par)
3630 (when (re-search-backward
3631 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3632 (setq par (match-string 1))
3633 (replace-match "\\2\n"))
3634 (insert line "\n")
3635 (while (and lines
3636 (or (= (length (car lines)) 0)
3637 (get-text-property 0 'org-protected (car lines))))
3638 (insert (pop lines) "\n"))
3639 (and par (insert "<p>\n")))
3640 (throw 'nextline nil))
3642 ;; Horizontal line
3643 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3644 (if org-par-open
3645 (insert "\n</p>\n<hr/>\n<p>\n")
3646 (insert "\n<hr/>\n"))
3647 (throw 'nextline nil))
3649 ;; Blockquotes and verse
3650 (when (equal "ORG-BLOCKQUOTE-START" line)
3651 (org-close-par-maybe)
3652 (insert "<blockquote>\n<p>\n")
3653 (throw 'nextline nil))
3654 (when (equal "ORG-BLOCKQUOTE-END" line)
3655 (insert "</p>\n</blockquote>\n")
3656 (throw 'nextline nil))
3657 (when (equal "ORG-VERSE-START" line)
3658 (org-close-par-maybe)
3659 (insert "\n<p class=\"verse\">\n")
3660 (setq inverse t)
3661 (throw 'nextline nil))
3662 (when (equal "ORG-VERSE-END" line)
3663 (insert "</p>\n")
3664 (setq inverse nil)
3665 (throw 'nextline nil))
3666 (when inverse
3667 (let ((i (org-get-string-indentation line)))
3668 (if (> i 0)
3669 (setq line (concat (mapconcat 'identity
3670 (make-list (* 2 i) "\\nbsp") "")
3671 " " (org-trim line))))
3672 (setq line (concat line "\\\\"))))
3674 ;; make targets to anchors
3675 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3676 (cond
3677 ((match-end 2)
3678 (setq line (replace-match
3679 (format
3680 "@<a name=\"%s\" id=\"%s\">@</a>"
3681 (org-solidify-link-text (match-string 1 line))
3682 (org-solidify-link-text (match-string 1 line)))
3683 t t line)))
3684 ((and org-export-with-toc (equal (string-to-char line) ?*))
3685 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3686 (setq line (replace-match
3687 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3688 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3689 t t line)))
3691 (setq line (replace-match
3692 (concat "@<a name=\""
3693 (org-solidify-link-text (match-string 1 line))
3694 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3695 t t line)))))
3697 (setq line (org-html-handle-time-stamps line))
3699 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3700 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3701 ;; Also handle sub_superscripts and checkboxes
3702 (or (string-match org-table-hline-regexp line)
3703 (setq line (org-html-expand line)))
3705 ;; Format the links
3706 (setq start 0)
3707 (while (string-match org-bracket-link-analytic-regexp++ line start)
3708 (setq start (match-beginning 0))
3709 (setq path (save-match-data (org-link-unescape
3710 (match-string 3 line))))
3711 (setq type (cond
3712 ((match-end 2) (match-string 2 line))
3713 ((save-match-data
3714 (or (file-name-absolute-p path)
3715 (string-match "^\\.\\.?/" path)))
3716 "file")
3717 (t "internal")))
3718 (setq path (org-extract-attributes (org-link-unescape path)))
3719 (setq attr (get-text-property 0 'org-attributes path))
3720 (setq desc1 (if (match-end 5) (match-string 5 line))
3721 desc2 (if (match-end 2) (concat type ":" path) path)
3722 descp (and desc1 (not (equal desc1 desc2)))
3723 desc (or desc1 desc2))
3724 ;; Make an image out of the description if that is so wanted
3725 (when (and descp (org-file-image-p
3726 desc org-export-html-inline-image-extensions))
3727 (save-match-data
3728 (if (string-match "^file:" desc)
3729 (setq desc (substring desc (match-end 0)))))
3730 (setq desc (org-add-props
3731 (concat "<img src=\"" desc "\"/>")
3732 '(org-protected t))))
3733 ;; FIXME: do we need to unescape here somewhere?
3734 (cond
3735 ((equal type "internal")
3736 (setq rpl
3737 (concat
3738 "<a href=\"#"
3739 (org-solidify-link-text
3740 (save-match-data (org-link-unescape path)) nil)
3741 "\"" attr ">"
3742 (org-export-html-format-desc desc)
3743 "</a>")))
3744 ((and (equal type "id")
3745 (setq id-file (org-id-find-id-file path)))
3746 ;; This is an id: link to another file (if it was the same file,
3747 ;; it would have become an internal link...)
3748 (setq id-file (file-relative-name
3749 id-file (file-name-directory org-current-export-file)))
3750 (setq id-file (concat (file-name-sans-extension id-file)
3751 "." html-extension))
3752 (setq rpl (concat "<a href=\"" id-file "#"
3753 (if (org-uuidgen-p path) "ID-")
3754 path "\""
3755 attr ">"
3756 (org-export-html-format-desc desc)
3757 "</a>")))
3758 ((member type '("http" "https"))
3759 ;; standard URL, just check if we need to inline an image
3760 (if (and (or (eq t org-export-html-inline-images)
3761 (and org-export-html-inline-images (not descp)))
3762 (org-file-image-p
3763 path org-export-html-inline-image-extensions))
3764 (setq rpl (org-export-html-format-image
3765 (concat type ":" path) org-par-open))
3766 (setq link (concat type ":" path))
3767 (setq rpl (concat "<a href=\""
3768 (org-export-html-format-href link)
3769 "\"" attr ">"
3770 (org-export-html-format-desc desc)
3771 "</a>"))))
3772 ((member type '("ftp" "mailto" "news"))
3773 ;; standard URL
3774 (setq link (concat type ":" path))
3775 (setq rpl (concat "<a href=\""
3776 (org-export-html-format-href link)
3777 "\"" attr ">"
3778 (org-export-html-format-desc desc)
3779 "</a>")))
3781 ((string= type "coderef")
3783 (setq rpl (format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3784 path path path
3785 (format (org-export-get-coderef-format path (and descp desc))
3786 (cdr (assoc path org-export-code-refs))))))
3788 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3789 ;; The link protocol has a function for format the link
3790 (setq rpl
3791 (save-match-data
3792 (funcall fnc (org-link-unescape path) desc1 'html))))
3794 ((string= type "file")
3795 ;; FILE link
3796 (let* ((filename path)
3797 (abs-p (file-name-absolute-p filename))
3798 thefile file-is-image-p search)
3799 (save-match-data
3800 (if (string-match "::\\(.*\\)" filename)
3801 (setq search (match-string 1 filename)
3802 filename (replace-match "" t nil filename)))
3803 (setq valid
3804 (if (functionp link-validate)
3805 (funcall link-validate filename current-dir)
3807 (setq file-is-image-p
3808 (org-file-image-p
3809 filename org-export-html-inline-image-extensions))
3810 (setq thefile (if abs-p (expand-file-name filename) filename))
3811 (when (and org-export-html-link-org-files-as-html
3812 (string-match "\\.org$" thefile))
3813 (setq thefile (concat (substring thefile 0
3814 (match-beginning 0))
3815 "." html-extension))
3816 (if (and search
3817 ;; make sure this is can be used as target search
3818 (not (string-match "^[0-9]*$" search))
3819 (not (string-match "^\\*" search))
3820 (not (string-match "^/.*/$" search)))
3821 (setq thefile (concat thefile "#"
3822 (org-solidify-link-text
3823 (org-link-unescape search)))))
3824 (when (string-match "^file:" desc)
3825 (setq desc (replace-match "" t t desc))
3826 (if (string-match "\\.org$" desc)
3827 (setq desc (replace-match "" t t desc))))))
3828 (setq rpl (if (and file-is-image-p
3829 (or (eq t org-export-html-inline-images)
3830 (and org-export-html-inline-images
3831 (not descp))))
3832 (progn
3833 (message "image %s %s" thefile org-par-open)
3834 (org-export-html-format-image thefile org-par-open))
3835 (concat "<a href=\"" thefile "\"" attr ">"
3836 (org-export-html-format-desc desc)
3837 "</a>")))
3838 (if (not valid) (setq rpl desc))))
3841 ;; just publish the path, as default
3842 (setq rpl (concat "<i>&lt;" type ":"
3843 (save-match-data (org-link-unescape path))
3844 "&gt;</i>"))))
3845 (setq line (replace-match rpl t t line)
3846 start (+ start (length rpl))))
3848 ;; TODO items
3849 (if (and (string-match org-todo-line-regexp line)
3850 (match-beginning 2))
3852 (setq line
3853 (concat (substring line 0 (match-beginning 2))
3854 "<span class=\""
3855 (if (member (match-string 2 line)
3856 org-done-keywords)
3857 "done" "todo")
3858 " " (match-string 2 line)
3859 "\"> " (org-export-html-get-todo-kwd-class-name
3860 (match-string 2 line))
3861 "</span>" (substring line (match-end 2)))))
3863 ;; Does this contain a reference to a footnote?
3864 (when org-export-with-footnotes
3865 (setq start 0)
3866 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3867 (if (get-text-property (match-beginning 2) 'org-protected line)
3868 (setq start (match-end 2))
3869 (let ((n (match-string 2 line)) extra a)
3870 (if (setq a (assoc n footref-seen))
3871 (progn
3872 (setcdr a (1+ (cdr a)))
3873 (setq extra (format ".%d" (cdr a))))
3874 (setq extra "")
3875 (push (cons n 1) footref-seen))
3876 (setq line
3877 (replace-match
3878 (format
3879 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
3880 (match-string 1 line) n extra n n)
3881 t t line))))))
3883 (cond
3884 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3885 ;; This is a headline
3886 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
3887 level-offset))
3888 txt (match-string 2 line))
3889 (if (string-match quote-re0 txt)
3890 (setq txt (replace-match "" t t txt)))
3891 (if (<= level (max umax umax-toc))
3892 (setq head-count (+ head-count 1)))
3893 (when in-local-list
3894 ;; Close any local lists before inserting a new header line
3895 (while local-list-type
3896 (org-close-li (car local-list-type))
3897 (insert (format "</%sl>\n" (car local-list-type)))
3898 (pop local-list-type))
3899 (setq local-list-indent nil
3900 in-local-list nil))
3901 (setq first-heading-pos (or first-heading-pos (point)))
3902 (org-html-level-start level txt umax
3903 (and org-export-with-toc (<= level umax))
3904 head-count)
3905 ;; QUOTES
3906 (when (string-match quote-re line)
3907 (org-close-par-maybe)
3908 (insert "<pre>")
3909 (setq inquote t)))
3911 ((and org-export-with-tables
3912 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3913 (if (not table-open)
3914 ;; New table starts
3915 (setq table-open t table-buffer nil table-orig-buffer nil))
3916 ;; Accumulate lines
3917 (setq table-buffer (cons line table-buffer)
3918 table-orig-buffer (cons origline table-orig-buffer))
3919 (when (or (not lines)
3920 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3921 (car lines))))
3922 (setq table-open nil
3923 table-buffer (nreverse table-buffer)
3924 table-orig-buffer (nreverse table-orig-buffer))
3925 (org-close-par-maybe)
3926 (insert (org-format-table-html table-buffer table-orig-buffer))))
3928 ;; Normal lines
3929 (when (string-match
3930 (cond
3931 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3932 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3933 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3934 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3935 line)
3936 (setq ind (org-get-string-indentation line)
3937 item-type (if (match-beginning 4) "o" "u")
3938 starter (if (match-beginning 2)
3939 (substring (match-string 2 line) 0 -1))
3940 line (substring line (match-beginning 5))
3941 item-tag nil)
3942 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3943 (setq item-type "d"
3944 item-tag (match-string 1 line)
3945 line (substring line (match-end 0))))
3946 (when (and (not (equal item-type "d"))
3947 (not (string-match "[^ \t]" line)))
3948 ;; empty line. Pretend indentation is large.
3949 (setq ind (if org-empty-line-terminates-plain-lists
3951 (1+ (or (car local-list-indent) 1)))))
3952 (setq didclose nil)
3953 (while (and in-local-list
3954 (or (and (= ind (car local-list-indent))
3955 (not starter))
3956 (< ind (car local-list-indent))))
3957 (setq didclose t)
3958 (org-close-li (car local-list-type))
3959 (insert (format "</%sl>\n" (car local-list-type)))
3960 (pop local-list-type) (pop local-list-indent)
3961 (setq in-local-list local-list-indent))
3962 (cond
3963 ((and starter
3964 (or (not in-local-list)
3965 (> ind (car local-list-indent))))
3966 ;; Start new (level of) list
3967 (org-close-par-maybe)
3968 (insert (cond
3969 ((equal item-type "u") "<ul>\n<li>\n")
3970 ((equal item-type "o") "<ol>\n<li>\n")
3971 ((equal item-type "d")
3972 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3973 (push item-type local-list-type)
3974 (push ind local-list-indent)
3975 (setq in-local-list t))
3976 (starter
3977 ;; continue current list
3978 (org-close-li (car local-list-type))
3979 (insert (cond
3980 ((equal (car local-list-type) "d")
3981 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3982 (t "<li>\n"))))
3983 (didclose
3984 ;; we did close a list, normal text follows: need <p>
3985 (org-open-par)))
3986 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3987 (setq line
3988 (replace-match
3989 (if (equal (match-string 1 line) "X")
3990 "<b>[X]</b>"
3991 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3992 t t line))))
3994 ;; Empty lines start a new paragraph. If hand-formatted lists
3995 ;; are not fully interpreted, lines starting with "-", "+", "*"
3996 ;; also start a new paragraph.
3997 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3999 ;; Is this the start of a footnote?
4000 (when org-export-with-footnotes
4001 (when (and (boundp 'footnote-section-tag-regexp)
4002 (string-match (concat "^" footnote-section-tag-regexp)
4003 line))
4004 ;; ignore this line
4005 (throw 'nextline nil))
4006 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
4007 (org-close-par-maybe)
4008 (let ((n (match-string 1 line)))
4009 (setq org-par-open t
4010 line (replace-match
4011 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
4013 ;; Check if the line break needs to be conserved
4014 (cond
4015 ((string-match "\\\\\\\\[ \t]*$" line)
4016 (setq line (replace-match "<br/>" t t line)))
4017 (org-export-preserve-breaks
4018 (setq line (concat line "<br/>"))))
4020 ;; Check if a paragraph should be started
4021 (let ((start 0))
4022 (while (and org-par-open
4023 (string-match "\\\\par\\>" line start))
4024 ;; Leave a space in the </p> so that the footnote matcher
4025 ;; does not see this.
4026 (if (not (get-text-property (match-beginning 0)
4027 'org-protected line))
4028 (setq line (replace-match "</p ><p >" t t line)))
4029 (setq start (match-end 0))))
4031 (insert line "\n")))))
4033 ;; Properly close all local lists and other lists
4034 (when inquote
4035 (insert "</pre>\n")
4036 (org-open-par))
4037 (when in-local-list
4038 ;; Close any local lists before inserting a new header line
4039 (while local-list-type
4040 (org-close-li (car local-list-type))
4041 (insert (format "</%sl>\n" (car local-list-type)))
4042 (pop local-list-type))
4043 (setq local-list-indent nil
4044 in-local-list nil))
4045 (org-html-level-start 1 nil umax
4046 (and org-export-with-toc (<= level umax))
4047 head-count)
4048 ;; the </div> to close the last text-... div.
4049 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
4051 (save-excursion
4052 (goto-char (point-min))
4053 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
4054 (push (match-string 0) footnotes)
4055 (replace-match "" t t)))
4056 (when footnotes
4057 (insert (format org-export-html-footnotes-section
4058 (or (nth 4 lang-words) "Footnotes")
4059 (mapconcat 'identity (nreverse footnotes) "\n"))
4060 "\n"))
4061 (let ((bib (org-export-html-get-bibliography)))
4062 (when bib
4063 (insert "\n" bib "\n")))
4064 (unless body-only
4065 (when (plist-get opt-plist :auto-postamble)
4066 (insert "<div id=\"postamble\">\n")
4067 (when (and org-export-author-info author)
4068 (insert "<p class=\"author\"> "
4069 (nth 1 lang-words) ": " author "\n")
4070 (when email
4071 (if (listp (split-string email ",+ *"))
4072 (mapc (lambda(e)
4073 (insert "<a href=\"mailto:" e "\">&lt;"
4074 e "&gt;</a>\n"))
4075 (split-string email ",+ *"))
4076 (insert "<a href=\"mailto:" email "\">&lt;"
4077 email "&gt;</a>\n")))
4078 (insert "</p>\n"))
4079 (when (and date org-export-time-stamp-file)
4080 (insert "<p class=\"date\"> "
4081 (nth 2 lang-words) ": "
4082 date "</p>\n"))
4083 (when org-export-creator-info
4084 (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
4085 org-version emacs-major-version)))
4086 (when org-export-html-validation-link
4087 (insert org-export-html-validation-link "\n"))
4088 (insert "</div>"))
4090 (if org-export-html-with-timestamp
4091 (insert org-export-html-html-helper-timestamp))
4092 (insert (or (plist-get opt-plist :postamble) ""))
4093 (insert "\n</div>\n</body>\n</html>\n"))
4095 (unless (plist-get opt-plist :buffer-will-be-killed)
4096 (normal-mode)
4097 (if (eq major-mode default-major-mode) (html-mode)))
4099 ;; insert the table of contents
4100 (goto-char (point-min))
4101 (when thetoc
4102 (if (or (re-search-forward
4103 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
4104 (re-search-forward
4105 "\\[TABLE-OF-CONTENTS\\]" nil t))
4106 (progn
4107 (goto-char (match-beginning 0))
4108 (replace-match ""))
4109 (goto-char first-heading-pos)
4110 (when (looking-at "\\s-*</p>")
4111 (goto-char (match-end 0))
4112 (insert "\n")))
4113 (insert "<div id=\"table-of-contents\">\n")
4114 (mapc 'insert thetoc)
4115 (insert "</div>\n"))
4116 ;; remove empty paragraphs and lists
4117 (goto-char (point-min))
4118 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
4119 (replace-match ""))
4120 (goto-char (point-min))
4121 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
4122 (replace-match ""))
4123 (goto-char (point-min))
4124 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
4125 (replace-match ""))
4126 ;; Convert whitespace place holders
4127 (goto-char (point-min))
4128 (let (beg end n)
4129 (while (setq beg (next-single-property-change (point) 'org-whitespace))
4130 (setq n (get-text-property beg 'org-whitespace)
4131 end (next-single-property-change beg 'org-whitespace))
4132 (goto-char beg)
4133 (delete-region beg end)
4134 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
4135 (make-string n ?x)))))
4136 (or to-buffer (save-buffer))
4137 (goto-char (point-min))
4138 (message "Exporting... done")
4139 (if (eq to-buffer 'string)
4140 (prog1 (buffer-substring (point-min) (point-max))
4141 (kill-buffer (current-buffer)))
4142 (current-buffer)))))
4144 (defun org-export-get-coderef-format (path desc)
4145 (save-match-data
4146 (if (and desc (string-match
4147 (regexp-quote (concat "(" path ")"))
4148 desc))
4149 (replace-match "%s" t t desc)
4150 "%s")))
4153 (defun org-export-html-format-href (s)
4154 "Make sure the S is valid as a href reference in an XHTML document."
4155 (save-match-data
4156 (let ((start 0))
4157 (while (string-match "&" s start)
4158 (setq start (+ (match-beginning 0) 3)
4159 s (replace-match "&amp;" t t s)))))
4162 (defun org-export-html-format-desc (s)
4163 "Make sure the S is valid as a description in a link."
4164 (if (and s (not (get-text-property 1 'org-protected s)))
4165 (save-match-data
4166 (org-html-do-expand s))
4169 (defun org-export-html-format-image (src par-open)
4170 "Create image tag with source and attributes."
4171 (save-match-data
4172 (if (string-match "^ltxpng/" src)
4173 (format "<img src=\"%s\"/>" src)
4174 (let* ((caption (org-find-text-property-in-string 'org-caption src))
4175 (attr (org-find-text-property-in-string 'org-attributes src))
4176 (label (org-find-text-property-in-string 'org-label src)))
4177 (format "%s<div %sclass=\"figure\">
4178 <p><img src=\"%s\"%s /></p>%s
4179 </div>%s"
4180 (if org-par-open "</p>\n" "")
4181 (if label (format "id=\"%s\" " label) "")
4183 (if (string-match "\\<alt=" (or attr ""))
4184 (concat " " attr )
4185 (concat " " attr " alt=\"" src "\""))
4186 (if caption (concat "\n<p>" caption "</p>") "")
4187 (if org-par-open "\n<p>" ""))))))
4189 (defun org-export-html-get-bibliography ()
4190 "Find bibliography, cut it out and return it."
4191 (catch 'exit
4192 (let (beg end (cnt 1))
4193 (save-excursion
4194 (goto-char (point-min))
4195 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
4196 (setq beg (match-beginning 0))
4197 (while (re-search-forward "</?div\\>" nil t)
4198 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
4199 (when (= cnt 0)
4200 (and (looking-at ">") (forward-char 1))
4201 (setq bib (buffer-substring beg (point)))
4202 (delete-region beg (point))
4203 (throw 'exit bib))))
4204 nil))))
4206 (defvar org-table-colgroup-info nil)
4207 (defun org-format-table-ascii (lines)
4208 "Format a table for ascii export."
4209 (if (stringp lines)
4210 (setq lines (org-split-string lines "\n")))
4211 (if (not (string-match "^[ \t]*|" (car lines)))
4212 ;; Table made by table.el - test for spanning
4213 lines
4215 ;; A normal org table
4216 ;; Get rid of hlines at beginning and end
4217 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
4218 (setq lines (nreverse lines))
4219 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
4220 (setq lines (nreverse lines))
4221 (when org-export-table-remove-special-lines
4222 ;; Check if the table has a marking column. If yes remove the
4223 ;; column and the special lines
4224 (setq lines (org-table-clean-before-export lines)))
4225 ;; Get rid of the vertical lines except for grouping
4226 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
4227 rtn line vl1 start)
4228 (while (setq line (pop lines))
4229 (if (string-match org-table-hline-regexp line)
4230 (and (string-match "|\\(.*\\)|" line)
4231 (setq line (replace-match " \\1" t nil line)))
4232 (setq start 0 vl1 vl)
4233 (while (string-match "|" line start)
4234 (setq start (match-end 0))
4235 (or (pop vl1) (setq line (replace-match " " t t line)))))
4236 (push line rtn))
4237 (nreverse rtn))))
4239 (defun org-colgroup-info-to-vline-list (info)
4240 (let (vl new last)
4241 (while info
4242 (setq last new new (pop info))
4243 (if (or (memq last '(:end :startend))
4244 (memq new '(:start :startend)))
4245 (push t vl)
4246 (push nil vl)))
4247 (setq vl (nreverse vl))
4248 (and vl (setcar vl nil))
4249 vl))
4251 (defvar org-table-number-regexp) ; defined in org-table.el
4252 (defun org-format-table-html (lines olines)
4253 "Find out which HTML converter to use and return the HTML code."
4254 (if (stringp lines)
4255 (setq lines (org-split-string lines "\n")))
4256 (if (string-match "^[ \t]*|" (car lines))
4257 ;; A normal org table
4258 (org-format-org-table-html lines)
4259 ;; Table made by table.el - test for spanning
4260 (let* ((hlines (delq nil (mapcar
4261 (lambda (x)
4262 (if (string-match "^[ \t]*\\+-" x) x
4263 nil))
4264 lines)))
4265 (first (car hlines))
4266 (ll (and (string-match "\\S-+" first)
4267 (match-string 0 first)))
4268 (re (concat "^[ \t]*" (regexp-quote ll)))
4269 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
4270 hlines))))
4271 (if (and (not spanning)
4272 (not org-export-prefer-native-exporter-for-tables))
4273 ;; We can use my own converter with HTML conversions
4274 (org-format-table-table-html lines)
4275 ;; Need to use the code generator in table.el, with the original text.
4276 (org-format-table-table-html-using-table-generate-source olines)))))
4278 (defvar org-table-number-fraction) ; defined in org-table.el
4279 (defun org-format-org-table-html (lines &optional splice)
4280 "Format a table into HTML."
4281 (require 'org-table)
4282 ;; Get rid of hlines at beginning and end
4283 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
4284 (setq lines (nreverse lines))
4285 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
4286 (setq lines (nreverse lines))
4287 (when org-export-table-remove-special-lines
4288 ;; Check if the table has a marking column. If yes remove the
4289 ;; column and the special lines
4290 (setq lines (org-table-clean-before-export lines)))
4292 (let ((caption (or (get-text-property 0 'org-caption (car lines))
4293 (get-text-property (or (next-single-property-change
4294 0 'org-caption (car lines))
4296 'org-caption (car lines))))
4297 (head (and org-export-highlight-first-table-line
4298 (delq nil (mapcar
4299 (lambda (x) (string-match "^[ \t]*|-" x))
4300 (cdr lines)))))
4302 (nlines 0) fnum i
4303 tbopen line fields html gr colgropen)
4304 (if splice (setq head nil))
4305 (unless splice (push (if head "<thead>" "<tbody>") html))
4306 (setq tbopen t)
4307 (while (setq line (pop lines))
4308 (catch 'next-line
4309 (if (string-match "^[ \t]*|-" line)
4310 (progn
4311 (unless splice
4312 (push (if head "</thead>" "</tbody>") html)
4313 (if lines (push "<tbody>" html) (setq tbopen nil)))
4314 (setq head nil) ;; head ends here, first time around
4315 ;; ignore this line
4316 (throw 'next-line t)))
4317 ;; Break the line into fields
4318 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
4319 (unless fnum (setq fnum (make-vector (length fields) 0)))
4320 (setq nlines (1+ nlines) i -1)
4321 (push (concat "<tr>"
4322 (mapconcat
4323 (lambda (x)
4324 (setq i (1+ i))
4325 (if (and (< i nlines)
4326 (string-match org-table-number-regexp x))
4327 (incf (aref fnum i)))
4328 (if head
4329 (concat (car org-export-table-header-tags) x
4330 (cdr org-export-table-header-tags))
4331 (concat (car org-export-table-data-tags) x
4332 (cdr org-export-table-data-tags))))
4333 fields "")
4334 "</tr>")
4335 html)))
4336 (unless splice (if tbopen (push "</tbody>" html)))
4337 (unless splice (push "</table>\n" html))
4338 (setq html (nreverse html))
4339 (unless splice
4340 ;; Put in col tags with the alignment (unfortunately often ignored...)
4341 (push (mapconcat
4342 (lambda (x)
4343 (setq gr (pop org-table-colgroup-info))
4344 (format "%s<col align=\"%s\"></col>%s"
4345 (if (memq gr '(:start :startend))
4346 (prog1
4347 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
4348 (setq colgropen t))
4350 (if (> (/ (float x) nlines) org-table-number-fraction)
4351 "right" "left")
4352 (if (memq gr '(:end :startend))
4353 (progn (setq colgropen nil) "</colgroup>")
4354 "")))
4355 fnum "")
4356 html)
4357 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
4358 (if caption (push (format "<caption>%s</caption>" caption) html))
4359 (push html-table-tag html))
4360 (concat (mapconcat 'identity html "\n") "\n")))
4362 (defun org-table-clean-before-export (lines &optional maybe-quoted)
4363 "Check if the table has a marking column.
4364 If yes remove the column and the special lines."
4365 (setq org-table-colgroup-info nil)
4366 (if (memq nil
4367 (mapcar
4368 (lambda (x) (or (string-match "^[ \t]*|-" x)
4369 (string-match
4370 (if maybe-quoted
4371 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
4372 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
4373 x)))
4374 lines))
4375 (progn
4376 (setq org-table-clean-did-remove-column nil)
4377 (delq nil
4378 (mapcar
4379 (lambda (x)
4380 (cond
4381 ((string-match "^[ \t]*| */ *|" x)
4382 (setq org-table-colgroup-info
4383 (mapcar (lambda (x)
4384 (cond ((member x '("<" "&lt;")) :start)
4385 ((member x '(">" "&gt;")) :end)
4386 ((member x '("<>" "&lt;&gt;")) :startend)
4387 (t nil)))
4388 (org-split-string x "[ \t]*|[ \t]*")))
4389 nil)
4390 (t x)))
4391 lines)))
4392 (setq org-table-clean-did-remove-column t)
4393 (delq nil
4394 (mapcar
4395 (lambda (x)
4396 (cond
4397 ((string-match "^[ \t]*| */ *|" x)
4398 (setq org-table-colgroup-info
4399 (mapcar (lambda (x)
4400 (cond ((member x '("<" "&lt;")) :start)
4401 ((member x '(">" "&gt;")) :end)
4402 ((member x '("<>" "&lt;&gt;")) :startend)
4403 (t nil)))
4404 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
4405 nil)
4406 ((string-match "^[ \t]*| *[!_^/] *|" x)
4407 nil) ; ignore this line
4408 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
4409 (string-match "^\\([ \t]*\\)|[^|]*|" x))
4410 ;; remove the first column
4411 (replace-match "\\1|" t nil x))))
4412 lines))))
4414 (defun org-format-table-table-html (lines)
4415 "Format a table generated by table.el into HTML.
4416 This conversion does *not* use `table-generate-source' from table.el.
4417 This has the advantage that Org-mode's HTML conversions can be used.
4418 But it has the disadvantage, that no cell- or row-spanning is allowed."
4419 (let (line field-buffer
4420 (head org-export-highlight-first-table-line)
4421 fields html empty)
4422 (setq html (concat html-table-tag "\n"))
4423 (while (setq line (pop lines))
4424 (setq empty "&nbsp;")
4425 (catch 'next-line
4426 (if (string-match "^[ \t]*\\+-" line)
4427 (progn
4428 (if field-buffer
4429 (progn
4430 (setq
4431 html
4432 (concat
4433 html
4434 "<tr>"
4435 (mapconcat
4436 (lambda (x)
4437 (if (equal x "") (setq x empty))
4438 (if head
4439 (concat (car org-export-table-header-tags) x
4440 (cdr org-export-table-header-tags))
4441 (concat (car org-export-table-data-tags) x
4442 (cdr org-export-table-data-tags))))
4443 field-buffer "\n")
4444 "</tr>\n"))
4445 (setq head nil)
4446 (setq field-buffer nil)))
4447 ;; Ignore this line
4448 (throw 'next-line t)))
4449 ;; Break the line into fields and store the fields
4450 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
4451 (if field-buffer
4452 (setq field-buffer (mapcar
4453 (lambda (x)
4454 (concat x "<br/>" (pop fields)))
4455 field-buffer))
4456 (setq field-buffer fields))))
4457 (setq html (concat html "</table>\n"))
4458 html))
4460 (defun org-format-table-table-html-using-table-generate-source (lines)
4461 "Format a table into html, using `table-generate-source' from table.el.
4462 This has the advantage that cell- or row-spanning is allowed.
4463 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4464 (require 'table)
4465 (with-current-buffer (get-buffer-create " org-tmp1 ")
4466 (erase-buffer)
4467 (insert (mapconcat 'identity lines "\n"))
4468 (goto-char (point-min))
4469 (if (not (re-search-forward "|[^+]" nil t))
4470 (error "Error processing table"))
4471 (table-recognize-table)
4472 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4473 (table-generate-source 'html " org-tmp2 ")
4474 (set-buffer " org-tmp2 ")
4475 (buffer-substring (point-min) (point-max))))
4477 (defun org-export-splice-style (style extra)
4478 "Splice EXTRA into STYLE, just before \"</style>\"."
4479 (if (and (stringp extra)
4480 (string-match "\\S-" extra)
4481 (string-match "</style>" style))
4482 (concat (substring style 0 (match-beginning 0))
4483 "\n" extra "\n"
4484 (substring style (match-beginning 0)))
4485 style))
4487 (defun org-html-handle-time-stamps (s)
4488 "Format time stamps in string S, or remove them."
4489 (catch 'exit
4490 (let (r b)
4491 (while (string-match org-maybe-keyword-time-regexp s)
4492 (or b (setq b (substring s 0 (match-beginning 0))))
4493 (setq r (concat
4494 r (substring s 0 (match-beginning 0))
4495 (if (match-end 1)
4496 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4497 (match-string 1 s)))
4498 (format " @<span class=\"timestamp\">%s@</span>"
4499 (substring
4500 (org-translate-time (match-string 3 s)) 1 -1)))
4501 s (substring s (match-end 0))))
4502 ;; Line break if line started and ended with time stamp stuff
4503 (if (not r)
4505 (setq r (concat r s))
4506 (unless (string-match "\\S-" (concat b s))
4507 (setq r (concat r "@<br/>")))
4508 r))))
4510 (defun org-export-htmlize-region-for-paste (beg end)
4511 "Convert the region to HTML, using htmlize.el.
4512 This is much like `htmlize-region-for-paste', only that it uses
4513 the settings define in the org-... variables."
4514 (let* ((htmlize-output-type org-export-htmlize-output-type)
4515 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
4516 (htmlbuf (htmlize-region beg end)))
4517 (unwind-protect
4518 (with-current-buffer htmlbuf
4519 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
4520 (plist-get htmlize-buffer-places 'content-end)))
4521 (kill-buffer htmlbuf))))
4523 ;;;###autoload
4524 (defun org-export-htmlize-generate-css ()
4525 "Create the CSS for all font definitions in the current Emacs session.
4526 Use this to create face definitions in your CSS style file that can then
4527 be used by code snippets transformed by htmlize.
4528 This command just produces a buffer that contains class definitions for all
4529 faces used in the current Emacs session. You can copy and paste the ones you
4530 need into your CSS file.
4532 If you then set `org-export-htmlize-output-type' to `css', calls to
4533 the function `org-export-htmlize-region-for-paste' will produce code
4534 that uses these same face definitions."
4535 (interactive)
4536 (require 'htmlize)
4537 (and (get-buffer "*html*") (kill-buffer "*html*"))
4538 (with-temp-buffer
4539 (let ((fl (face-list))
4540 (htmlize-css-name-prefix "org-")
4541 (htmlize-output-type 'css)
4542 f i)
4543 (while (setq f (pop fl)
4544 i (and f (face-attribute f :inherit)))
4545 (when (and (symbolp f) (or (not i) (not (listp i))))
4546 (insert (org-add-props (copy-sequence "1") nil 'face f))))
4547 (htmlize-region (point-min) (point-max))))
4548 (switch-to-buffer "*html*")
4549 (goto-char (point-min))
4550 (if (re-search-forward "<style" nil t)
4551 (delete-region (point-min) (match-beginning 0)))
4552 (if (re-search-forward "</style>" nil t)
4553 (delete-region (1+ (match-end 0)) (point-max)))
4554 (beginning-of-line 1)
4555 (if (looking-at " +") (replace-match ""))
4556 (goto-char (point-min)))
4558 (defun org-html-protect (s)
4559 ;; convert & to &amp;, < to &lt; and > to &gt;
4560 (let ((start 0))
4561 (while (string-match "&" s start)
4562 (setq s (replace-match "&amp;" t t s)
4563 start (1+ (match-beginning 0))))
4564 (while (string-match "<" s)
4565 (setq s (replace-match "&lt;" t t s)))
4566 (while (string-match ">" s)
4567 (setq s (replace-match "&gt;" t t s)))
4568 ; (while (string-match "\"" s)
4569 ; (setq s (replace-match "&quot;" t t s)))
4573 (defun org-export-cleanup-toc-line (s)
4574 "Remove tags and timestamps from lines going into the toc."
4575 (when (memq org-export-with-tags '(not-in-toc nil))
4576 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
4577 (setq s (replace-match "" t t s))))
4578 (when org-export-remove-timestamps-from-toc
4579 (while (string-match org-maybe-keyword-time-regexp s)
4580 (setq s (replace-match "" t t s))))
4581 (while (string-match org-bracket-link-regexp s)
4582 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
4583 t t s)))
4586 (defun org-html-expand (string)
4587 "Prepare STRING for HTML export. Applies all active conversions.
4588 If there are links in the string, don't modify these."
4589 (let* ((re (concat org-bracket-link-regexp "\\|"
4590 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4591 m s l res)
4592 (while (setq m (string-match re string))
4593 (setq s (substring string 0 m)
4594 l (match-string 0 string)
4595 string (substring string (match-end 0)))
4596 (push (org-html-do-expand s) res)
4597 (push l res))
4598 (push (org-html-do-expand string) res)
4599 (apply 'concat (nreverse res))))
4601 (defun org-html-do-expand (s)
4602 "Apply all active conversions to translate special ASCII to HTML."
4603 (setq s (org-html-protect s))
4604 (if org-export-html-expand
4605 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
4606 (setq s (replace-match "<\\1>" t nil s))))
4607 (if org-export-with-emphasize
4608 (setq s (org-export-html-convert-emphasize s)))
4609 (if org-export-with-special-strings
4610 (setq s (org-export-html-convert-special-strings s)))
4611 (if org-export-with-sub-superscripts
4612 (setq s (org-export-html-convert-sub-super s)))
4613 (if org-export-with-TeX-macros
4614 (let ((start 0) wd ass)
4615 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4616 s start))
4617 (if (get-text-property (match-beginning 0) 'org-protected s)
4618 (setq start (match-end 0))
4619 (setq wd (match-string 1 s))
4620 (if (setq ass (assoc wd org-html-entities))
4621 (setq s (replace-match (or (cdr ass)
4622 (concat "&" (car ass) ";"))
4623 t t s))
4624 (setq start (+ start (length wd))))))))
4627 (defun org-create-multibrace-regexp (left right n)
4628 "Create a regular expression which will match a balanced sexp.
4629 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4630 as single character strings.
4631 The regexp returned will match the entire expression including the
4632 delimiters. It will also define a single group which contains the
4633 match except for the outermost delimiters. The maximum depth of
4634 stacked delimiters is N. Escaping delimiters is not possible."
4635 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
4636 (or "\\|")
4637 (re nothing)
4638 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
4639 (while (> n 1)
4640 (setq n (1- n)
4641 re (concat re or next)
4642 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
4643 (concat left "\\(" re "\\)" right)))
4645 (defvar org-match-substring-regexp
4646 (concat
4647 "\\([^\\]\\)\\([_^]\\)\\("
4648 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4649 "\\|"
4650 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
4651 "\\|"
4652 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4653 "The regular expression matching a sub- or superscript.")
4655 (defvar org-match-substring-with-braces-regexp
4656 (concat
4657 "\\([^\\]\\)\\([_^]\\)\\("
4658 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4659 "\\)")
4660 "The regular expression matching a sub- or superscript, forcing braces.")
4662 (defconst org-export-html-special-string-regexps
4663 '(("\\\\-" . "&shy;")
4664 ("---\\([^-]\\)" . "&mdash;\\1")
4665 ("--\\([^-]\\)" . "&ndash;\\1")
4666 ("\\.\\.\\." . "&hellip;"))
4667 "Regular expressions for special string conversion.")
4669 (defun org-export-html-convert-special-strings (string)
4670 "Convert special characters in STRING to HTML."
4671 (let ((all org-export-html-special-string-regexps)
4672 e a re rpl start)
4673 (while (setq a (pop all))
4674 (setq re (car a) rpl (cdr a) start 0)
4675 (while (string-match re string start)
4676 (if (get-text-property (match-beginning 0) 'org-protected string)
4677 (setq start (match-end 0))
4678 (setq string (replace-match rpl t nil string)))))
4679 string))
4681 (defun org-export-html-convert-sub-super (string)
4682 "Convert sub- and superscripts in STRING to HTML."
4683 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
4684 (while (string-match org-match-substring-regexp string s)
4685 (cond
4686 ((and requireb (match-end 8)) (setq s (match-end 2)))
4687 ((get-text-property (match-beginning 2) 'org-protected string)
4688 (setq s (match-end 2)))
4690 (setq s (match-end 1)
4691 key (if (string= (match-string 2 string) "_") "sub" "sup")
4692 c (or (match-string 8 string)
4693 (match-string 6 string)
4694 (match-string 5 string))
4695 string (replace-match
4696 (concat (match-string 1 string)
4697 "<" key ">" c "</" key ">")
4698 t t string)))))
4699 (while (string-match "\\\\\\([_^]\\)" string)
4700 (setq string (replace-match (match-string 1 string) t t string)))
4701 string))
4703 (defun org-export-html-convert-emphasize (string)
4704 "Apply emphasis."
4705 (let ((s 0) rpl)
4706 (while (string-match org-emph-re string s)
4707 (if (not (equal
4708 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4709 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4710 (setq s (match-beginning 0)
4712 (concat
4713 (match-string 1 string)
4714 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4715 (match-string 4 string)
4716 (nth 3 (assoc (match-string 3 string)
4717 org-emphasis-alist))
4718 (match-string 5 string))
4719 string (replace-match rpl t t string)
4720 s (+ s (- (length rpl) 2)))
4721 (setq s (1+ s))))
4722 string))
4724 (defun org-open-par ()
4725 "Insert <p>, but first close previous paragraph if any."
4726 (org-close-par-maybe)
4727 (insert "\n<p>")
4728 (setq org-par-open t))
4729 (defun org-close-par-maybe ()
4730 "Close paragraph if there is one open."
4731 (when org-par-open
4732 (insert "</p>")
4733 (setq org-par-open nil)))
4734 (defun org-close-li (&optional type)
4735 "Close <li> if necessary."
4736 (org-close-par-maybe)
4737 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4739 (defvar body-only) ; dynamically scoped into this.
4740 (defun org-html-level-start (level title umax with-toc head-count)
4741 "Insert a new level in HTML export.
4742 When TITLE is nil, just close all open levels."
4743 (org-close-par-maybe)
4744 (let* ((target (and title (org-get-text-property-any 0 'target title)))
4745 (extra-targets
4746 (mapconcat (lambda (x)
4747 (if (org-uuidgen-p x) (setq x (concat "ID-" x)))
4748 (format "<a name=\"%s\" id=\"%s\"></a>"
4749 x x))
4750 (cdr (assoc target org-export-target-aliases))
4751 ""))
4752 (l org-level-max)
4753 snumber)
4754 (while (>= l level)
4755 (if (aref org-levels-open (1- l))
4756 (progn
4757 (org-html-level-close l umax)
4758 (aset org-levels-open (1- l) nil)))
4759 (setq l (1- l)))
4760 (when title
4761 ;; If title is nil, this means this function is called to close
4762 ;; all levels, so the rest is done only if title is given
4763 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4764 (setq title (replace-match
4765 (if org-export-with-tags
4766 (save-match-data
4767 (concat
4768 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
4769 (mapconcat
4770 (lambda (x)
4771 (format "<span class=\"%s\">%s</span>"
4772 (org-export-html-get-tag-class-name x)
4774 (org-split-string (match-string 1 title) ":")
4775 "&nbsp;")
4776 "</span>"))
4778 t t title)))
4779 (if (> level umax)
4780 (progn
4781 (if (aref org-levels-open (1- level))
4782 (progn
4783 (org-close-li)
4784 (if target
4785 (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
4786 (insert "<li>" title "<br/>\n")))
4787 (aset org-levels-open (1- level) t)
4788 (org-close-par-maybe)
4789 (if target
4790 (insert (format "<ul>\n<li id=\"%s\">" target)
4791 extra-targets title "<br/>\n")
4792 (insert "<ul>\n<li>" title "<br/>\n"))))
4793 (aset org-levels-open (1- level) t)
4794 (setq snumber (org-section-number level))
4795 (setq level (+ level org-export-html-toplevel-hlevel -1))
4796 (if (and org-export-with-section-numbers (not body-only))
4797 (setq title (concat
4798 (format "<span class=\"section-number-%d\">%s</span>"
4799 level snumber)
4800 " " title)))
4801 (unless (= head-count 1) (insert "\n</div>\n"))
4802 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
4803 snumber level level snumber extra-targets
4804 title level level snumber))
4805 (org-open-par)))))
4807 (defun org-get-text-property-any (pos prop &optional object)
4808 (or (get-text-property pos prop object)
4809 (and (setq pos (next-single-property-change pos prop object))
4810 (get-text-property pos prop object))))
4812 (defun org-export-html-get-tag-class-name (tag)
4813 "Turn tag into a valid class name.
4814 Replaces invalid characters with \"_\" and then prepends a prefix."
4815 (save-match-data
4816 (while (string-match "[^a-zA-Z0-9_]" tag)
4817 (setq tag (replace-match "_" t t tag))))
4818 (concat org-export-html-tag-class-prefix tag))
4820 (defun org-export-html-get-todo-kwd-class-name (kwd)
4821 "Turn todo keyword into a valid class name.
4822 Replaces invalid characters with \"_\" and then prepends a prefix."
4823 (save-match-data
4824 (while (string-match "[^a-zA-Z0-9_]" kwd)
4825 (setq kwd (replace-match "_" t t kwd))))
4826 (concat org-export-html-todo-kwd-class-prefix kwd))
4828 (defun org-html-level-close (level max-outline-level)
4829 "Terminate one level in HTML export."
4830 (if (<= level max-outline-level)
4831 (insert "</div>\n")
4832 (org-close-li)
4833 (insert "</ul>\n")))
4835 ;;; iCalendar export
4837 ;;;###autoload
4838 (defun org-export-icalendar-this-file ()
4839 "Export current file as an iCalendar file.
4840 The iCalendar file will be located in the same directory as the Org-mode
4841 file, but with extension `.ics'."
4842 (interactive)
4843 (org-export-icalendar nil buffer-file-name))
4845 ;;;###autoload
4846 (defun org-export-icalendar-all-agenda-files ()
4847 "Export all files in `org-agenda-files' to iCalendar .ics files.
4848 Each iCalendar file will be located in the same directory as the Org-mode
4849 file, but with extension `.ics'."
4850 (interactive)
4851 (apply 'org-export-icalendar nil (org-agenda-files t)))
4853 ;;;###autoload
4854 (defun org-export-icalendar-combine-agenda-files ()
4855 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4856 The file is stored under the name `org-combined-agenda-icalendar-file'."
4857 (interactive)
4858 (apply 'org-export-icalendar t (org-agenda-files t)))
4860 (defun org-export-icalendar (combine &rest files)
4861 "Create iCalendar files for all elements of FILES.
4862 If COMBINE is non-nil, combine all calendar entries into a single large
4863 file and store it under the name `org-combined-agenda-icalendar-file'."
4864 (save-excursion
4865 (org-prepare-agenda-buffers files)
4866 (let* ((dir (org-export-directory
4867 :ical (list :publishing-directory
4868 org-export-publishing-directory)))
4869 file ical-file ical-buffer category started org-agenda-new-buffers)
4870 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4871 (when combine
4872 (setq ical-file
4873 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4874 org-combined-agenda-icalendar-file
4875 (expand-file-name org-combined-agenda-icalendar-file dir))
4876 ical-buffer (org-get-agenda-file-buffer ical-file))
4877 (set-buffer ical-buffer) (erase-buffer))
4878 (while (setq file (pop files))
4879 (catch 'nextfile
4880 (org-check-agenda-file file)
4881 (set-buffer (org-get-agenda-file-buffer file))
4882 (unless combine
4883 (setq ical-file (concat (file-name-as-directory dir)
4884 (file-name-sans-extension
4885 (file-name-nondirectory buffer-file-name))
4886 ".ics"))
4887 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4888 (with-current-buffer ical-buffer (erase-buffer)))
4889 (setq category (or org-category
4890 (file-name-sans-extension
4891 (file-name-nondirectory buffer-file-name))))
4892 (if (symbolp category) (setq category (symbol-name category)))
4893 (let ((standard-output ical-buffer))
4894 (if combine
4895 (and (not started) (setq started t)
4896 (org-start-icalendar-file org-icalendar-combined-name))
4897 (org-start-icalendar-file category))
4898 (org-print-icalendar-entries combine)
4899 (when (or (and combine (not files)) (not combine))
4900 (org-finish-icalendar-file)
4901 (set-buffer ical-buffer)
4902 (run-hooks 'org-before-save-iCalendar-file-hook)
4903 (save-buffer)
4904 (run-hooks 'org-after-save-iCalendar-file-hook)
4905 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4906 ))))
4907 (org-release-buffers org-agenda-new-buffers))))
4909 (defvar org-before-save-iCalendar-file-hook nil
4910 "Hook run before an iCalendar file has been saved.
4911 This can be used to modify the result of the export.")
4913 (defvar org-after-save-iCalendar-file-hook nil
4914 "Hook run after an iCalendar file has been saved.
4915 The iCalendar buffer is still current when this hook is run.
4916 A good way to use this is to tell a desktop calendar application to re-read
4917 the iCalendar file.")
4919 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4920 (defun org-print-icalendar-entries (&optional combine)
4921 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4922 When COMBINE is non nil, add the category to each line."
4923 (require 'org-agenda)
4924 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4925 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4926 (dts (org-ical-ts-to-string
4927 (format-time-string (cdr org-time-stamp-formats) (current-time))
4928 "DTSTART"))
4929 hd ts ts2 state status (inc t) pos b sexp rrule
4930 scheduledp deadlinep todo prefix due start
4931 tmp pri categories location summary desc uid
4932 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4933 (org-refresh-category-properties)
4934 (save-excursion
4935 (goto-char (point-min))
4936 (while (re-search-forward re1 nil t)
4937 (catch :skip
4938 (org-agenda-skip)
4939 (when (boundp 'org-icalendar-verify-function)
4940 (unless (funcall org-icalendar-verify-function)
4941 (outline-next-heading)
4942 (backward-char 1)
4943 (throw :skip nil)))
4944 (setq pos (match-beginning 0)
4945 ts (match-string 0)
4946 inc t
4947 hd (condition-case nil
4948 (org-icalendar-cleanup-string
4949 (org-get-heading))
4950 (error (throw :skip nil)))
4951 summary (org-icalendar-cleanup-string
4952 (org-entry-get nil "SUMMARY"))
4953 desc (org-icalendar-cleanup-string
4954 (or (org-entry-get nil "DESCRIPTION")
4955 (and org-icalendar-include-body (org-get-entry)))
4956 t org-icalendar-include-body)
4957 location (org-icalendar-cleanup-string
4958 (org-entry-get nil "LOCATION" 'selective))
4959 uid (if org-icalendar-store-UID
4960 (org-id-get-create)
4961 (or (org-id-get) (org-id-new)))
4962 categories (org-export-get-categories)
4963 deadlinep nil scheduledp nil)
4964 (if (looking-at re2)
4965 (progn
4966 (goto-char (match-end 0))
4967 (setq ts2 (match-string 1)
4968 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4969 (setq tmp (buffer-substring (max (point-min)
4970 (- pos org-ds-keyword-length))
4971 pos)
4972 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4973 (progn
4974 (setq inc nil)
4975 (replace-match "\\1" t nil ts))
4977 deadlinep (string-match org-deadline-regexp tmp)
4978 scheduledp (string-match org-scheduled-regexp tmp)
4979 todo (org-get-todo-state)
4980 ;; donep (org-entry-is-done-p)
4982 (when (and
4983 deadlinep
4984 (if todo
4985 (not (memq 'event-if-todo org-icalendar-use-deadline))
4986 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4987 (throw :skip t))
4988 (when (and
4989 scheduledp
4990 (if todo
4991 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4992 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4993 (throw :skip t))
4994 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4995 (if (or (string-match org-tr-regexp hd)
4996 (string-match org-ts-regexp hd))
4997 (setq hd (replace-match "" t t hd)))
4998 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4999 (setq rrule
5000 (concat "\nRRULE:FREQ="
5001 (cdr (assoc
5002 (match-string 2 ts)
5003 '(("d" . "DAILY")("w" . "WEEKLY")
5004 ("m" . "MONTHLY")("y" . "YEARLY"))))
5005 ";INTERVAL=" (match-string 1 ts)))
5006 (setq rrule ""))
5007 (setq summary (or summary hd))
5008 (if (string-match org-bracket-link-regexp summary)
5009 (setq summary
5010 (replace-match (if (match-end 3)
5011 (match-string 3 summary)
5012 (match-string 1 summary))
5013 t t summary)))
5014 (if deadlinep (setq summary (concat "DL: " summary)))
5015 (if scheduledp (setq summary (concat "S: " summary)))
5016 (if (string-match "\\`<%%" ts)
5017 (with-current-buffer sexp-buffer
5018 (insert (substring ts 1 -1) " " summary "\n"))
5019 (princ (format "BEGIN:VEVENT
5020 UID: %s
5022 %s%s
5023 SUMMARY:%s%s%s
5024 CATEGORIES:%s
5025 END:VEVENT\n"
5026 (concat prefix uid)
5027 (org-ical-ts-to-string ts "DTSTART")
5028 (org-ical-ts-to-string ts2 "DTEND" inc)
5029 rrule summary
5030 (if (and desc (string-match "\\S-" desc))
5031 (concat "\nDESCRIPTION: " desc) "")
5032 (if (and location (string-match "\\S-" location))
5033 (concat "\nLOCATION: " location) "")
5034 categories)))))
5035 (when (and org-icalendar-include-sexps
5036 (condition-case nil (require 'icalendar) (error nil))
5037 (fboundp 'icalendar-export-region))
5038 ;; Get all the literal sexps
5039 (goto-char (point-min))
5040 (while (re-search-forward "^&?%%(" nil t)
5041 (catch :skip
5042 (org-agenda-skip)
5043 (setq b (match-beginning 0))
5044 (goto-char (1- (match-end 0)))
5045 (forward-sexp 1)
5046 (end-of-line 1)
5047 (setq sexp (buffer-substring b (point)))
5048 (with-current-buffer sexp-buffer
5049 (insert sexp "\n"))))
5050 (princ (org-diary-to-ical-string sexp-buffer))
5051 (kill-buffer sexp-buffer))
5053 (when org-icalendar-include-todo
5054 (setq prefix "TODO-")
5055 (goto-char (point-min))
5056 (while (re-search-forward org-todo-line-regexp nil t)
5057 (catch :skip
5058 (org-agenda-skip)
5059 (when (boundp 'org-icalendar-verify-function)
5060 (unless (funcall org-icalendar-verify-function)
5061 (outline-next-heading)
5062 (backward-char 1)
5063 (throw :skip nil)))
5064 (setq state (match-string 2))
5065 (setq status (if (member state org-done-keywords)
5066 "COMPLETED" "NEEDS-ACTION"))
5067 (when (and state
5068 (or (not (member state org-done-keywords))
5069 (eq org-icalendar-include-todo 'all))
5070 (not (member org-archive-tag (org-get-tags-at)))
5072 (setq hd (match-string 3)
5073 summary (org-icalendar-cleanup-string
5074 (org-entry-get nil "SUMMARY"))
5075 desc (org-icalendar-cleanup-string
5076 (or (org-entry-get nil "DESCRIPTION")
5077 (and org-icalendar-include-body (org-get-entry)))
5078 t org-icalendar-include-body)
5079 location (org-icalendar-cleanup-string
5080 (org-entry-get nil "LOCATION" 'selective))
5081 due (and (member 'todo-due org-icalendar-use-deadline)
5082 (org-entry-get nil "DEADLINE"))
5083 start (and (member 'todo-start org-icalendar-use-scheduled)
5084 (org-entry-get nil "SCHEDULED"))
5085 categories (org-export-get-categories)
5086 uid (if org-icalendar-store-UID
5087 (org-id-get-create)
5088 (or (org-id-get) (org-id-new))))
5089 (and due (setq due (org-ical-ts-to-string due "DUE")))
5090 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
5092 (if (string-match org-bracket-link-regexp hd)
5093 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
5094 (match-string 1 hd))
5095 t t hd)))
5096 (if (string-match org-priority-regexp hd)
5097 (setq pri (string-to-char (match-string 2 hd))
5098 hd (concat (substring hd 0 (match-beginning 1))
5099 (substring hd (match-end 1))))
5100 (setq pri org-default-priority))
5101 (setq pri (floor (- 9 (* 8. (/ (float (- org-lowest-priority pri))
5102 (- org-lowest-priority org-highest-priority))))))
5104 (princ (format "BEGIN:VTODO
5105 UID: %s
5107 SUMMARY:%s%s%s%s
5108 CATEGORIES:%s
5109 SEQUENCE:1
5110 PRIORITY:%d
5111 STATUS:%s
5112 END:VTODO\n"
5113 (concat prefix uid)
5114 (or start dts)
5115 (or summary hd)
5116 (if (and location (string-match "\\S-" location))
5117 (concat "\nLOCATION: " location) "")
5118 (if (and desc (string-match "\\S-" desc))
5119 (concat "\nDESCRIPTION: " desc) "")
5120 (if due (concat "\n" due) "")
5121 categories
5122 pri status)))))))))
5124 (defun org-export-get-categories ()
5125 "Get categories according to `org-icalendar-categories'."
5126 (let ((cs org-icalendar-categories) c rtn tmp)
5127 (while (setq c (pop cs))
5128 (cond
5129 ((eq c 'category) (push (org-get-category) rtn))
5130 ((eq c 'todo-state)
5131 (setq tmp (org-get-todo-state))
5132 (and tmp (push tmp rtn)))
5133 ((eq c 'local-tags)
5134 (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
5135 ((eq c 'all-tags)
5136 (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
5137 (mapconcat 'identity (nreverse rtn) ",")))
5139 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
5140 "Take out stuff and quote what needs to be quoted.
5141 When IS-BODY is non-nil, assume that this is the body of an item, clean up
5142 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
5143 characters."
5144 (if (not s)
5146 (when is-body
5147 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
5148 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
5149 (while (string-match re s) (setq s (replace-match "" t t s)))
5150 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
5151 (let ((start 0))
5152 (while (string-match "\\([,;]\\)" s start)
5153 (setq start (+ (match-beginning 0) 2)
5154 s (replace-match "\\\\\\1" nil nil s))))
5155 (setq s (org-trim s))
5156 (when is-body
5157 (while (string-match "[ \t]*\n[ \t]*" s)
5158 (setq s (replace-match "\\n" t t s))))
5159 (if is-body
5160 (if maxlength
5161 (if (and (numberp maxlength)
5162 (> (length s) maxlength))
5163 (setq s (substring s 0 maxlength)))))
5166 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength)
5167 "Take out stuff and quote what needs to be quoted.
5168 When IS-BODY is non-nil, assume that this is the body of an item, clean up
5169 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
5170 characters.
5171 This seems to be more like RFC 2455, but it causes problems, so it is
5172 not used right now."
5173 (if (not s)
5175 (if is-body
5176 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
5177 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
5178 (while (string-match re s) (setq s (replace-match "" t t s)))
5179 (while (string-match re2 s) (setq s (replace-match "" t t s)))
5180 (setq s (org-trim s))
5181 (while (string-match "[ \t]*\n[ \t]*" s)
5182 (setq s (replace-match "\\n" t t s)))
5183 (if maxlength
5184 (if (and (numberp maxlength)
5185 (> (length s) maxlength))
5186 (setq s (substring s 0 maxlength)))))
5187 (setq s (org-trim s)))
5188 (while (string-match "\"" s) (setq s (replace-match "''" t t s)))
5189 (when (string-match "[;,:]" s) (setq s (concat "\"" s "\"")))
5192 (defun org-get-entry ()
5193 "Clean-up description string."
5194 (save-excursion
5195 (org-back-to-heading t)
5196 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
5198 (defun org-start-icalendar-file (name)
5199 "Start an iCalendar file by inserting the header."
5200 (let ((user user-full-name)
5201 (name (or name "unknown"))
5202 (timezone (cadr (current-time-zone))))
5203 (princ
5204 (format "BEGIN:VCALENDAR
5205 VERSION:2.0
5206 X-WR-CALNAME:%s
5207 PRODID:-//%s//Emacs with Org-mode//EN
5208 X-WR-TIMEZONE:%s
5209 CALSCALE:GREGORIAN\n" name user timezone))))
5211 (defun org-finish-icalendar-file ()
5212 "Finish an iCalendar file by inserting the END statement."
5213 (princ "END:VCALENDAR\n"))
5215 (defun org-ical-ts-to-string (s keyword &optional inc)
5216 "Take a time string S and convert it to iCalendar format.
5217 KEYWORD is added in front, to make a complete line like DTSTART....
5218 When INC is non-nil, increase the hour by two (if time string contains
5219 a time), or the day by one (if it does not contain a time)."
5220 (let ((t1 (org-parse-time-string s 'nodefault))
5221 t2 fmt have-time time)
5222 (if (and (car t1) (nth 1 t1) (nth 2 t1))
5223 (setq t2 t1 have-time t)
5224 (setq t2 (org-parse-time-string s)))
5225 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
5226 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
5227 (when inc
5228 (if have-time
5229 (if org-agenda-default-appointment-duration
5230 (setq mi (+ org-agenda-default-appointment-duration mi))
5231 (setq h (+ 2 h)))
5232 (setq d (1+ d))))
5233 (setq time (encode-time s mi h d m y)))
5234 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
5235 (concat keyword (format-time-string fmt time))))
5237 ;;; XOXO export
5239 (defun org-export-as-xoxo-insert-into (buffer &rest output)
5240 (with-current-buffer buffer
5241 (apply 'insert output)))
5242 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
5244 ;;;###autoload
5245 (defun org-export-as-xoxo (&optional buffer)
5246 "Export the org buffer as XOXO.
5247 The XOXO buffer is named *xoxo-<source buffer name>*"
5248 (interactive (list (current-buffer)))
5249 ;; A quickie abstraction
5251 ;; Output everything as XOXO
5252 (with-current-buffer (get-buffer buffer)
5253 (let* ((pos (point))
5254 (opt-plist (org-combine-plists (org-default-export-plist)
5255 (org-infile-export-plist)))
5256 (filename (concat (file-name-as-directory
5257 (org-export-directory :xoxo opt-plist))
5258 (file-name-sans-extension
5259 (file-name-nondirectory buffer-file-name))
5260 ".html"))
5261 (out (find-file-noselect filename))
5262 (last-level 1)
5263 (hanging-li nil))
5264 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
5265 ;; Check the output buffer is empty.
5266 (with-current-buffer out (erase-buffer))
5267 ;; Kick off the output
5268 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
5269 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
5270 (let* ((hd (match-string-no-properties 1))
5271 (level (length hd))
5272 (text (concat
5273 (match-string-no-properties 2)
5274 (save-excursion
5275 (goto-char (match-end 0))
5276 (let ((str ""))
5277 (catch 'loop
5278 (while 't
5279 (forward-line)
5280 (if (looking-at "^[ \t]\\(.*\\)")
5281 (setq str (concat str (match-string-no-properties 1)))
5282 (throw 'loop str)))))))))
5284 ;; Handle level rendering
5285 (cond
5286 ((> level last-level)
5287 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
5289 ((< level last-level)
5290 (dotimes (- (- last-level level) 1)
5291 (if hanging-li
5292 (org-export-as-xoxo-insert-into out "</li>\n"))
5293 (org-export-as-xoxo-insert-into out "</ol>\n"))
5294 (when hanging-li
5295 (org-export-as-xoxo-insert-into out "</li>\n")
5296 (setq hanging-li nil)))
5298 ((equal level last-level)
5299 (if hanging-li
5300 (org-export-as-xoxo-insert-into out "</li>\n")))
5303 (setq last-level level)
5305 ;; And output the new li
5306 (setq hanging-li 't)
5307 (if (equal ?+ (elt text 0))
5308 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
5309 (org-export-as-xoxo-insert-into out "<li>" text))))
5311 ;; Finally finish off the ol
5312 (dotimes (- last-level 1)
5313 (if hanging-li
5314 (org-export-as-xoxo-insert-into out "</li>\n"))
5315 (org-export-as-xoxo-insert-into out "</ol>\n"))
5317 (goto-char pos)
5318 ;; Finish the buffer off and clean it up.
5319 (switch-to-buffer-other-window out)
5320 (indent-region (point-min) (point-max) nil)
5321 (save-buffer)
5322 (goto-char (point-min))
5325 (provide 'org-exp)
5327 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
5329 ;;; org-exp.el ends here