HTML Export: Make IDs valid
[org-mode.git] / lisp / org-exp.el
blobce6670cd514b3a2965f42fc82c417e38a1e70b5a
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 'boolean)
754 (defcustom org-export-html-with-timestamp nil
755 "If non-nil, write `org-export-html-html-helper-timestamp'
756 into the exported HTML text. Otherwise, the buffer will just be saved
757 to a file."
758 :group 'org-export-html
759 :type 'boolean)
761 (defcustom org-export-html-html-helper-timestamp
762 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
763 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
764 :group 'org-export-html
765 :type 'string)
767 (defgroup org-export-htmlize nil
768 "Options for processing examples with htmlize.el."
769 :tag "Org Export Htmlize"
770 :group 'org-export-html)
772 (defcustom org-export-htmlize-output-type 'inline-css
773 "Output type to be used by htmlize when formatting code snippets.
774 Normally this is `inline-css', but if you have defined to appropriate
775 classes in your css style file, setting this to `css' means that the
776 fontification will use the class names.
777 See also the function `org-export-htmlize-generate-css'."
778 :group 'org-export-htmlize
779 :type '(choice (const css) (const inline-css)))
781 (defcustom org-export-htmlize-css-font-prefix "org-"
782 "The prefix for CSS class names for htmlize font specifications."
783 :group 'org-export-htmlize
784 :type 'string)
786 (defgroup org-export-icalendar nil
787 "Options specific for iCalendar export of Org-mode files."
788 :tag "Org Export iCalendar"
789 :group 'org-export)
791 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
792 "The file name for the iCalendar file covering all agenda files.
793 This file is created with the command \\[org-export-icalendar-all-agenda-files].
794 The file name should be absolute, the file will be overwritten without warning."
795 :group 'org-export-icalendar
796 :type 'file)
798 (defcustom org-icalendar-combined-name "OrgMode"
799 "Calendar name for the combined iCalendar representing all agenda files."
800 :group 'org-export-icalendar
801 :type 'string)
803 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
804 "Contexts where iCalendar export should use a deadline time stamp.
805 This is a list with several symbols in it. Valid symbol are:
807 event-if-todo Deadlines in TODO entries become calendar events.
808 event-if-not-todo Deadlines in non-TODO entries become calendar events.
809 todo-due Use deadlines in TODO entries as due-dates"
810 :group 'org-export-icalendar
811 :type '(set :greedy t
812 (const :tag "Deadlines in non-TODO entries become events"
813 event-if-not-todo)
814 (const :tag "Deadline in TODO entries become events"
815 event-if-todo)
816 (const :tag "Deadlines in TODO entries become due-dates"
817 todo-due)))
819 (defcustom org-icalendar-use-scheduled '(todo-start)
820 "Contexts where iCalendar export should use a scheduling time stamp.
821 This is a list with several symbols in it. Valid symbol are:
823 event-if-todo Scheduling time stamps in TODO entries become an event.
824 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
825 todo-start Scheduling time stamps in TODO entries become start date.
826 Some calendar applications show TODO entries only after
827 that date."
828 :group 'org-export-icalendar
829 :type '(set :greedy t
830 (const :tag
831 "SCHEDULED timestamps in non-TODO entries become events"
832 event-if-not-todo)
833 (const :tag "SCHEDULED timestamps in TODO entries become events"
834 event-if-todo)
835 (const :tag "SCHEDULED in TODO entries become start date"
836 todo-start)))
838 (defcustom org-icalendar-categories '(local-tags category)
839 "Items that should be entered into the categories field.
840 This is a list of symbols, the following are valid:
842 category The Org-mode category of the current file or tree
843 todo-state The todo state, if any
844 local-tags The tags, defined in the current line
845 all-tags All tags, including inherited ones."
846 :group 'org-export-icalendar
847 :type '(repeat
848 (choice
849 (const :tag "The file or tree category" category)
850 (const :tag "The TODO state" todo-state)
851 (const :tag "Tags defined in current line" local-tags)
852 (const :tag "All tags, including inherited ones" all-tags))))
854 (defcustom org-icalendar-include-todo nil
855 "Non-nil means, export to iCalendar files should also cover TODO items."
856 :group 'org-export-icalendar
857 :type '(choice
858 (const :tag "None" nil)
859 (const :tag "Unfinished" t)
860 (const :tag "All" all)))
862 (defcustom org-icalendar-include-sexps t
863 "Non-nil means, export to iCalendar files should also cover sexp entries.
864 These are entries like in the diary, but directly in an Org-mode file."
865 :group 'org-export-icalendar
866 :type 'boolean)
868 (defcustom org-icalendar-include-body 100
869 "Amount of text below headline to be included in iCalendar export.
870 This is a number of characters that should maximally be included.
871 Properties, scheduling and clocking lines will always be removed.
872 The text will be inserted into the DESCRIPTION field."
873 :group 'org-export-icalendar
874 :type '(choice
875 (const :tag "Nothing" nil)
876 (const :tag "Everything" t)
877 (integer :tag "Max characters")))
879 (defcustom org-icalendar-store-UID nil
880 "Non-nil means, store any created UIDs in properties.
881 The iCalendar standard requires that all entries have a unique identifier.
882 Org will create these identifiers as needed. When this variable is non-nil,
883 the created UIDs will be stored in the ID property of the entry. Then the
884 next time this entry is exported, it will be exported with the same UID,
885 superceding the previous form of it. This is essential for
886 synchronization services.
887 This variable is not turned on by default because we want to avoid creating
888 a property drawer in every entry if people are only playing with this feature,
889 or if they are only using it locally."
890 :group 'org-export-icalendar
891 :type 'boolean)
893 ;;;; Exporting
895 ;;; Variables, constants, and parameter plists
897 (defconst org-level-max 20)
899 (defvar org-export-html-preamble nil
900 "Preamble, to be inserted just before <body>. Set by publishing functions.")
901 (defvar org-export-html-postamble nil
902 "Preamble, to be inserted just after </body>. Set by publishing functions.")
903 (defvar org-export-html-auto-preamble t
904 "Should default preamble be inserted? Set by publishing functions.")
905 (defvar org-export-html-auto-postamble t
906 "Should default postamble be inserted? Set by publishing functions.")
907 (defvar org-current-export-file nil) ; dynamically scoped parameter
908 (defvar org-current-export-dir nil) ; dynamically scoped parameter
909 (defvar org-export-opt-plist nil
910 "Contains the current option plist.")
912 (defconst org-export-plist-vars
913 '((:link-up nil org-export-html-link-up)
914 (:link-home nil org-export-html-link-home)
915 (:language nil org-export-default-language)
916 (:customtime nil org-display-custom-times)
917 (:headline-levels "H" org-export-headline-levels)
918 (:section-numbers "num" org-export-with-section-numbers)
919 (:section-number-format nil org-export-section-number-format)
920 (:table-of-contents "toc" org-export-with-toc)
921 (:preserve-breaks "\\n" org-export-preserve-breaks)
922 (:archived-trees nil org-export-with-archived-trees)
923 (:emphasize "*" org-export-with-emphasize)
924 (:sub-superscript "^" org-export-with-sub-superscripts)
925 (:special-strings "-" org-export-with-special-strings)
926 (:footnotes "f" org-export-with-footnotes)
927 (:drawers "d" org-export-with-drawers)
928 (:tags "tags" org-export-with-tags)
929 (:todo-keywords "todo" org-export-with-todo-keywords)
930 (:priority "pri" org-export-with-priority)
931 (:TeX-macros "TeX" org-export-with-TeX-macros)
932 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
933 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
934 (:fixed-width ":" org-export-with-fixed-width)
935 (:timestamps "<" org-export-with-timestamps)
936 (:author-info "author" org-export-author-info)
937 (:creator-info "creator" org-export-creator-info)
938 (:time-stamp-file "timestamp" org-export-time-stamp-file)
939 (:tables "|" org-export-with-tables)
940 (:table-auto-headline nil org-export-highlight-first-table-line)
941 (:style-include-default nil org-export-html-style-include-default)
942 (:style nil org-export-html-style)
943 (:style-extra nil org-export-html-style-extra)
944 (:agenda-style nil org-agenda-export-html-style)
945 (:convert-org-links nil org-export-html-link-org-files-as-html)
946 (:inline-images nil org-export-html-inline-images)
947 (:html-extension nil org-export-html-extension)
948 (:html-table-tag nil org-export-html-table-tag)
949 (:expand-quoted-html "@" org-export-html-expand)
950 (:timestamp nil org-export-html-with-timestamp)
951 (:publishing-directory nil org-export-publishing-directory)
952 (:preamble nil org-export-html-preamble)
953 (:postamble nil org-export-html-postamble)
954 (:auto-preamble nil org-export-html-auto-preamble)
955 (:auto-postamble nil org-export-html-auto-postamble)
956 (:author nil user-full-name)
957 (:email nil user-mail-address)
958 (:select-tags nil org-export-select-tags)
959 (:exclude-tags nil org-export-exclude-tags))
960 "List of properties that represent export/publishing variables.
961 Each element is a list of 3 items:
962 1. The property that is used internally, and also for org-publish-project-alist
963 2. The string that can be used in the OPTION lines to set this option,
964 or nil if this option cannot be changed in this way
965 3. The customization variable that sets the default for this option."
969 (defun org-default-export-plist ()
970 "Return the property list with default settings for the export variables."
971 (let ((l org-export-plist-vars) rtn e)
972 (while (setq e (pop l))
973 (setq rtn (cons (car e) (cons (symbol-value (nth 2 e)) rtn))))
974 rtn))
976 (defvar org-export-inbuffer-options-extra nil
977 "List of additional in-buffer options that should be detected.
978 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
979 etc. Extensions can add to this list to get their options detected, and they
980 can then add a function to `org-export-options-filters' to process these
981 options.
982 Each element in this list must be a list, with the in-buffer keyword as car,
983 and a property (a symbol) as the next element. All occurrences of the
984 keyword will be found, the values concatenated with a space character
985 in between, and the result stored in the export options property list.")
987 (defvar org-export-options-filters nil
988 "Functions to be called to finalize the export/publishing options.
989 All these options are stored in a property list, and each of the functions
990 in this hook gets a chance to modify this property list. Each function
991 must accept the property list as an argument, and must return the (possibly
992 modified) list.")
994 ;; FIXME: should we fold case here?
995 (defun org-infile-export-plist ()
996 "Return the property list with file-local settings for export."
997 (save-excursion
998 (save-restriction
999 (widen)
1000 (goto-char (point-min))
1001 (let ((re (org-make-options-regexp
1002 (append
1003 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
1004 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
1005 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
1006 (mapcar 'car org-export-inbuffer-options-extra))))
1007 p key val text options a pr style
1008 latex-header
1009 ext-setup-or-nil setup-contents (start 0))
1010 (while (or (and ext-setup-or-nil
1011 (string-match re ext-setup-or-nil start)
1012 (setq start (match-end 0)))
1013 (and (setq ext-setup-or-nil nil start 0)
1014 (re-search-forward re nil t)))
1015 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
1016 val (org-match-string-no-properties 2 ext-setup-or-nil))
1017 (cond
1018 ((setq a (assoc key org-export-inbuffer-options-extra))
1019 (setq pr (nth 1 a))
1020 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
1021 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
1022 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
1023 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
1024 ((string-equal key "DATE") (setq p (plist-put p :date val)))
1025 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
1026 ((string-equal key "STYLE")
1027 (setq style (concat style "\n" val)))
1028 ((string-equal key "LATEX_HEADER")
1029 (setq latex-header (concat latex-header "\n" val)))
1030 ((string-equal key "TEXT")
1031 (setq text (if text (concat text "\n" val) val)))
1032 ((string-equal key "OPTIONS")
1033 (setq options (concat val " " options)))
1034 ((string-equal key "LINK_UP")
1035 (setq p (plist-put p :link-up val)))
1036 ((string-equal key "LINK_HOME")
1037 (setq p (plist-put p :link-home val)))
1038 ((string-equal key "EXPORT_SELECT_TAGS")
1039 (setq p (plist-put p :select-tags (org-split-string val))))
1040 ((string-equal key "EXPORT_EXCLUDE_TAGS")
1041 (setq p (plist-put p :exclude-tags (org-split-string val))))
1042 ((equal key "SETUPFILE")
1043 (setq setup-contents (org-file-contents
1044 (expand-file-name
1045 (org-remove-double-quotes
1046 (org-trim val)))
1047 'noerror))
1048 (if (not ext-setup-or-nil)
1049 (setq ext-setup-or-nil setup-contents start 0)
1050 (setq ext-setup-or-nil
1051 (concat (substring ext-setup-or-nil 0 start)
1052 "\n" setup-contents "\n"
1053 (substring ext-setup-or-nil start)))))))
1054 (setq p (plist-put p :text text))
1055 (when style (setq p (plist-put p :style-extra style)))
1056 (when latex-header
1057 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
1058 (when options
1059 (setq p (org-export-add-options-to-plist p options)))
1060 ;; Add macro definitions
1061 (goto-char (point-min))
1062 (while (re-search-forward
1063 "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
1064 nil t)
1065 (setq p (plist-put p (intern (concat ":macro-"
1066 (downcase (match-string 1))))
1067 (match-string 2))))
1068 p))))
1070 (defun org-export-add-options-to-plist (p options)
1071 "Parse an OPTIONS line and set values in the property list P."
1072 (let (o)
1073 (when options
1074 (let ((op org-export-plist-vars))
1075 (while (setq o (pop op))
1076 (if (and (nth 1 o)
1077 (string-match (concat (regexp-quote (nth 1 o))
1078 ":\\([^ \t\n\r;,.]*\\)")
1079 options))
1080 (setq p (plist-put p (car o)
1081 (car (read-from-string
1082 (match-string 1 options))))))))))
1085 (defun org-export-add-subtree-options (p pos)
1086 "Add options in subtree at position POS to property list P."
1087 (save-excursion
1088 (goto-char pos)
1089 (when (org-at-heading-p)
1090 (let (a)
1091 ;; This is actually read in `org-export-get-title-from-subtree'
1092 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1093 ;; (setq p (plist-put p :title a)))
1094 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
1095 (setq p (plist-put p :text a)))
1096 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
1097 (setq p (org-export-add-options-to-plist p a)))))
1100 (defun org-export-directory (type plist)
1101 (let* ((val (plist-get plist :publishing-directory))
1102 (dir (if (listp val)
1103 (or (cdr (assoc type val)) ".")
1104 val)))
1105 dir))
1107 (defun org-export-process-option-filters (plist)
1108 (let ((functions org-export-options-filters) f)
1109 (while (setq f (pop functions))
1110 (setq plist (funcall f plist))))
1111 plist)
1113 ;;;###autoload
1114 (defun org-export (&optional arg)
1115 "Export dispatcher for Org-mode.
1116 When `org-export-run-in-background' is non-nil, try to run the command
1117 in the background. This will be done only for commands that write
1118 to a file. For details see the docstring of `org-export-run-in-background'.
1120 The prefix argument ARG will be passed to the exporter. However, if
1121 ARG is a double universal prefix `C-u C-u', that means to inverse the
1122 value of `org-export-run-in-background'."
1123 (interactive "P")
1124 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
1125 (help "[t] insert the export option template
1126 \[v] limit export to visible part of outline tree
1128 \[a] export as ASCII
1130 \[h] export as HTML
1131 \[H] export as HTML to temporary buffer
1132 \[R] export region as HTML
1133 \[b] export as HTML and browse immediately
1134 \[x] export as XOXO
1136 \[l] export as LaTeX
1137 \[p] export as LaTeX and process to PDF
1138 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1139 \[L] export as LaTeX to temporary buffer
1141 \[i] export current file as iCalendar file
1142 \[I] export all agenda files as iCalendar files
1143 \[c] export agenda files into combined iCalendar file
1145 \[F] publish current file
1146 \[P] publish current project
1147 \[X] publish... (project will be prompted for)
1148 \[A] publish all projects")
1149 (cmds
1150 '((?t org-insert-export-options-template nil)
1151 (?v org-export-visible nil)
1152 (?a org-export-as-ascii t)
1153 (?h org-export-as-html t)
1154 (?b org-export-as-html-and-open t)
1155 (?H org-export-as-html-to-buffer nil)
1156 (?R org-export-region-as-html nil)
1157 (?x org-export-as-xoxo t)
1158 (?l org-export-as-latex t)
1159 (?p org-export-as-pdf t)
1160 (?d org-export-as-pdf-and-open t)
1161 (?L org-export-as-latex-to-buffer nil)
1162 (?i org-export-icalendar-this-file t)
1163 (?I org-export-icalendar-all-agenda-files t)
1164 (?c org-export-icalendar-combine-agenda-files t)
1165 (?F org-publish-current-file t)
1166 (?P org-publish-current-project t)
1167 (?X org-publish t)
1168 (?A org-publish-all t)))
1169 r1 r2 ass)
1170 (save-excursion
1171 (save-window-excursion
1172 (delete-other-windows)
1173 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1174 (princ help))
1175 (org-fit-window-to-buffer (get-buffer-window
1176 "*Org Export/Publishing Help*"))
1177 (message "Select command: ")
1178 (setq r1 (read-char-exclusive))))
1179 (setq r2 (if (< r1 27) (+ r1 96) r1))
1180 (unless (setq ass (assq r2 cmds))
1181 (error "No command associated with key %c" r1))
1182 (if (and bg (nth 2 ass)
1183 (not (buffer-base-buffer))
1184 (not (org-region-active-p)))
1185 ;; execute in background
1186 (let ((p (start-process
1187 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1188 "*Org Processes*"
1189 (expand-file-name invocation-name invocation-directory)
1190 "-batch"
1191 "-l" user-init-file
1192 "--eval" "(require 'org-exp)"
1193 "--eval" "(setq org-wait .2)"
1194 (buffer-file-name)
1195 "-f" (symbol-name (nth 1 ass)))))
1196 (set-process-sentinel p 'org-export-process-sentinel)
1197 (message "Background process \"%s\": started" p))
1198 ;; background processing not requested, or not possible
1199 (call-interactively (nth 1 ass)))))
1201 (defun org-export-process-sentinel (process status)
1202 (if (string-match "\n+\\'" status)
1203 (setq status (substring status 0 -1)))
1204 (message "Background process \"%s\": %s" process status))
1206 (defconst org-html-entities
1207 '(("nbsp")
1208 ("iexcl")
1209 ("cent")
1210 ("pound")
1211 ("curren")
1212 ("yen")
1213 ("brvbar")
1214 ("vert" . "&#124;")
1215 ("sect")
1216 ("uml")
1217 ("copy")
1218 ("ordf")
1219 ("laquo")
1220 ("not")
1221 ("shy")
1222 ("reg")
1223 ("macr")
1224 ("deg")
1225 ("plusmn")
1226 ("sup2")
1227 ("sup3")
1228 ("acute")
1229 ("micro")
1230 ("para")
1231 ("middot")
1232 ("odot"."o")
1233 ("star"."*")
1234 ("cedil")
1235 ("sup1")
1236 ("ordm")
1237 ("raquo")
1238 ("frac14")
1239 ("frac12")
1240 ("frac34")
1241 ("iquest")
1242 ("Agrave")
1243 ("Aacute")
1244 ("Acirc")
1245 ("Atilde")
1246 ("Auml")
1247 ("Aring") ("AA"."&Aring;")
1248 ("AElig")
1249 ("Ccedil")
1250 ("Egrave")
1251 ("Eacute")
1252 ("Ecirc")
1253 ("Euml")
1254 ("Igrave")
1255 ("Iacute")
1256 ("Icirc")
1257 ("Iuml")
1258 ("ETH")
1259 ("Ntilde")
1260 ("Ograve")
1261 ("Oacute")
1262 ("Ocirc")
1263 ("Otilde")
1264 ("Ouml")
1265 ("times")
1266 ("Oslash")
1267 ("Ugrave")
1268 ("Uacute")
1269 ("Ucirc")
1270 ("Uuml")
1271 ("Yacute")
1272 ("THORN")
1273 ("szlig")
1274 ("agrave")
1275 ("aacute")
1276 ("acirc")
1277 ("atilde")
1278 ("auml")
1279 ("aring")
1280 ("aelig")
1281 ("ccedil")
1282 ("egrave")
1283 ("eacute")
1284 ("ecirc")
1285 ("euml")
1286 ("igrave")
1287 ("iacute")
1288 ("icirc")
1289 ("iuml")
1290 ("eth")
1291 ("ntilde")
1292 ("ograve")
1293 ("oacute")
1294 ("ocirc")
1295 ("otilde")
1296 ("ouml")
1297 ("divide")
1298 ("oslash")
1299 ("ugrave")
1300 ("uacute")
1301 ("ucirc")
1302 ("uuml")
1303 ("yacute")
1304 ("thorn")
1305 ("yuml")
1306 ("fnof")
1307 ("Alpha")
1308 ("Beta")
1309 ("Gamma")
1310 ("Delta")
1311 ("Epsilon")
1312 ("Zeta")
1313 ("Eta")
1314 ("Theta")
1315 ("Iota")
1316 ("Kappa")
1317 ("Lambda")
1318 ("Mu")
1319 ("Nu")
1320 ("Xi")
1321 ("Omicron")
1322 ("Pi")
1323 ("Rho")
1324 ("Sigma")
1325 ("Tau")
1326 ("Upsilon")
1327 ("Phi")
1328 ("Chi")
1329 ("Psi")
1330 ("Omega")
1331 ("alpha")
1332 ("beta")
1333 ("gamma")
1334 ("delta")
1335 ("epsilon")
1336 ("varepsilon"."&epsilon;")
1337 ("zeta")
1338 ("eta")
1339 ("theta")
1340 ("iota")
1341 ("kappa")
1342 ("lambda")
1343 ("mu")
1344 ("nu")
1345 ("xi")
1346 ("omicron")
1347 ("pi")
1348 ("rho")
1349 ("sigmaf") ("varsigma"."&sigmaf;")
1350 ("sigma")
1351 ("tau")
1352 ("upsilon")
1353 ("phi")
1354 ("chi")
1355 ("psi")
1356 ("omega")
1357 ("thetasym") ("vartheta"."&thetasym;")
1358 ("upsih")
1359 ("piv")
1360 ("bull") ("bullet"."&bull;")
1361 ("hellip") ("dots"."&hellip;")
1362 ("prime")
1363 ("Prime")
1364 ("oline")
1365 ("frasl")
1366 ("weierp")
1367 ("image")
1368 ("real")
1369 ("trade")
1370 ("alefsym")
1371 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1372 ("uarr") ("uparrow"."&uarr;")
1373 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1374 ("darr")("downarrow"."&darr;")
1375 ("harr") ("leftrightarrow"."&harr;")
1376 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1377 ("lArr") ("Leftarrow"."&lArr;")
1378 ("uArr") ("Uparrow"."&uArr;")
1379 ("rArr") ("Rightarrow"."&rArr;")
1380 ("dArr") ("Downarrow"."&dArr;")
1381 ("hArr") ("Leftrightarrow"."&hArr;")
1382 ("forall")
1383 ("part") ("partial"."&part;")
1384 ("exist") ("exists"."&exist;")
1385 ("empty") ("emptyset"."&empty;")
1386 ("nabla")
1387 ("isin") ("in"."&isin;")
1388 ("notin")
1389 ("ni")
1390 ("prod")
1391 ("sum")
1392 ("minus")
1393 ("lowast") ("ast"."&lowast;")
1394 ("radic")
1395 ("prop") ("proptp"."&prop;")
1396 ("infin") ("infty"."&infin;")
1397 ("ang") ("angle"."&ang;")
1398 ("and") ("wedge"."&and;")
1399 ("or") ("vee"."&or;")
1400 ("cap")
1401 ("cup")
1402 ("int")
1403 ("there4")
1404 ("sim")
1405 ("cong") ("simeq"."&cong;")
1406 ("asymp")("approx"."&asymp;")
1407 ("ne") ("neq"."&ne;")
1408 ("equiv")
1409 ("le")
1410 ("ge")
1411 ("sub") ("subset"."&sub;")
1412 ("sup") ("supset"."&sup;")
1413 ("nsub")
1414 ("sube")
1415 ("supe")
1416 ("oplus")
1417 ("otimes")
1418 ("perp")
1419 ("sdot") ("cdot"."&sdot;")
1420 ("lceil")
1421 ("rceil")
1422 ("lfloor")
1423 ("rfloor")
1424 ("lang")
1425 ("rang")
1426 ("loz") ("Diamond"."&loz;")
1427 ("spades") ("spadesuit"."&spades;")
1428 ("clubs") ("clubsuit"."&clubs;")
1429 ("hearts") ("diamondsuit"."&hearts;")
1430 ("diams") ("diamondsuit"."&diams;")
1431 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1432 ("quot")
1433 ("amp")
1434 ("lt")
1435 ("gt")
1436 ("OElig")
1437 ("oelig")
1438 ("Scaron")
1439 ("scaron")
1440 ("Yuml")
1441 ("circ")
1442 ("tilde")
1443 ("ensp")
1444 ("emsp")
1445 ("thinsp")
1446 ("zwnj")
1447 ("zwj")
1448 ("lrm")
1449 ("rlm")
1450 ("ndash")
1451 ("mdash")
1452 ("lsquo")
1453 ("rsquo")
1454 ("sbquo")
1455 ("ldquo")
1456 ("rdquo")
1457 ("bdquo")
1458 ("dagger")
1459 ("Dagger")
1460 ("permil")
1461 ("lsaquo")
1462 ("rsaquo")
1463 ("euro")
1465 ("arccos"."arccos")
1466 ("arcsin"."arcsin")
1467 ("arctan"."arctan")
1468 ("arg"."arg")
1469 ("cos"."cos")
1470 ("cosh"."cosh")
1471 ("cot"."cot")
1472 ("coth"."coth")
1473 ("csc"."csc")
1474 ("deg"."deg")
1475 ("det"."det")
1476 ("dim"."dim")
1477 ("exp"."exp")
1478 ("gcd"."gcd")
1479 ("hom"."hom")
1480 ("inf"."inf")
1481 ("ker"."ker")
1482 ("lg"."lg")
1483 ("lim"."lim")
1484 ("liminf"."liminf")
1485 ("limsup"."limsup")
1486 ("ln"."ln")
1487 ("log"."log")
1488 ("max"."max")
1489 ("min"."min")
1490 ("Pr"."Pr")
1491 ("sec"."sec")
1492 ("sin"."sin")
1493 ("sinh"."sinh")
1494 ("sup"."sup")
1495 ("tan"."tan")
1496 ("tanh"."tanh")
1498 "Entities for TeX->HTML translation.
1499 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1500 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1501 In that case, \"\\ent\" will be translated to \"&other;\".
1502 The list contains HTML entities for Latin-1, Greek and other symbols.
1503 It is supplemented by a number of commonly used TeX macros with appropriate
1504 translations. There is currently no way for users to extend this.")
1506 ;;; General functions for all backends
1508 (defvar org-export-target-aliases nil
1509 "Alist of targets with invisible aliases.")
1510 (defvar org-export-code-refs nil
1511 "Alist of code references and line numbers")
1513 (defun org-export-preprocess-string (string &rest parameters)
1514 "Cleanup STRING so that that the true exported has a more consistent source.
1515 This function takes STRING, which should be a buffer-string of an org-file
1516 to export. It then creates a temporary buffer where it does its job.
1517 The result is then again returned as a string, and the exporter works
1518 on this string to produce the exported version."
1519 (interactive)
1520 (let* ((htmlp (plist-get parameters :for-html))
1521 (asciip (plist-get parameters :for-ascii))
1522 (latexp (plist-get parameters :for-LaTeX))
1523 (backend (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))
1525 (archived-trees (plist-get parameters :archived-trees))
1526 (inhibit-read-only t)
1527 (drawers org-drawers)
1528 (outline-regexp "\\*+ ")
1529 target-alist rtn)
1531 (setq org-export-target-aliases nil)
1532 (setq org-export-code-refs nil)
1534 (with-current-buffer (get-buffer-create " org-mode-tmp")
1535 (erase-buffer)
1536 (insert string)
1537 (setq case-fold-search t)
1539 ;; Remove license-to-kill stuff
1540 ;; The caller marks some stuff for killing, stuff that has been
1541 ;; used to create the page title, for example.
1542 (org-export-kill-licensed-text)
1544 (let ((org-inhibit-startup t)) (org-mode))
1545 (setq case-fold-search t)
1547 ;; Call the hook
1548 (run-hooks 'org-export-preprocess-hook)
1550 ;; Process the macros
1551 (org-export-preprocess-apply-macros)
1552 (run-hooks 'org-export-preprocess-after-macros-hook)
1554 (untabify (point-min) (point-max))
1556 ;; Handle include files, and call a hook
1557 (org-export-handle-include-files)
1558 (run-hooks 'org-export-preprocess-after-include-files-hook)
1560 ;; Get rid of archived trees
1561 (org-export-remove-archived-trees archived-trees)
1563 ;; Remove comment environment and comment subtrees
1564 (org-export-remove-comment-blocks-and-subtrees)
1566 ;; Get rid of excluded trees, and call a hook
1567 (org-export-handle-export-tags (plist-get parameters :select-tags)
1568 (plist-get parameters :exclude-tags))
1569 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1571 ;; Handle source code snippets
1572 (org-export-replace-src-segments-and-examples backend)
1574 ;; Protect short examples marked by a leading colon
1575 (org-export-protect-colon-examples)
1577 ;; Normalize footnotes
1578 (when (plist-get parameters :footnotes)
1579 (org-footnote-normalize nil t))
1581 ;; Find all headings and compute the targets for them
1582 (setq target-alist (org-export-define-heading-targets target-alist))
1584 ;; Get rid of drawers
1585 (org-export-remove-or-extract-drawers drawers
1586 (plist-get parameters :drawers))
1588 ;; Get the correct stuff before the first headline
1589 (when (plist-get parameters :skip-before-1st-heading)
1590 (goto-char (point-min))
1591 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1592 (delete-region (point-min) (match-beginning 0))
1593 (goto-char (point-min))
1594 (insert "\n")))
1595 (when (plist-get parameters :add-text)
1596 (goto-char (point-min))
1597 (insert (plist-get parameters :add-text) "\n"))
1599 ;; Remove todo-keywords before exporting, if the user has requested so
1600 (org-export-remove-headline-metadata parameters)
1602 ;; Find targets in comments and move them out of comments,
1603 ;; but mark them as targets that should be invisible
1604 (setq target-alist (org-export-handle-invisible-targets target-alist))
1606 ;; Select and protect backend specific stuff, throw away stuff
1607 ;; that is specific for other backends
1608 (org-export-select-backend-specific-text backend)
1610 ;; Protect quoted subtrees
1611 (org-export-protect-quoted-subtrees)
1613 ;; Remove clock lines
1614 (org-export-remove-clock-lines)
1616 ;; Protect verbatim elements
1617 (org-export-protect-verbatim)
1619 ;; Blockquotes and verse
1620 (org-export-mark-blockquote-and-verse)
1622 ;; Remove timestamps, if the user has requested so
1623 (unless (plist-get parameters :timestamps)
1624 (org-export-remove-timestamps))
1626 ;; Attach captions to the correct object
1627 (setq target-alist (org-export-attach-captions-and-attributes
1628 backend target-alist))
1630 ;; Find matches for radio targets and turn them into internal links
1631 (org-export-mark-radio-links)
1633 ;; Find all links that contain a newline and put them into a single line
1634 (org-export-concatenate-multiline-links)
1636 ;; Normalize links: Convert angle and plain links into bracket links
1637 ;; and expand link abbreviations
1638 (org-export-normalize-links)
1640 ;; Find all internal links. If they have a fuzzy match (i.e. not
1641 ;; a *dedicated* target match, let the link point to the
1642 ;; corresponding section.
1643 (org-export-target-internal-links target-alist)
1645 ;; Find multiline emphasis and put them into single line
1646 (when (plist-get parameters :emph-multiline)
1647 (org-export-concatenate-multiline-emphasis))
1649 ;; Remove special table lines
1650 (when org-export-table-remove-special-lines
1651 (org-export-remove-special-table-lines))
1653 ;; Another hook
1654 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1656 ;; LaTeX-specific preprocessing
1657 (when latexp
1658 (require 'org-export-latex nil)
1659 (org-export-latex-preprocess))
1661 ;; ASCII-specific preprocessing
1662 (when asciip
1663 (org-export-ascii-preprocess))
1665 ;; HTML-specific preprocessing
1666 (when htmlp
1667 (org-export-html-preprocess parameters))
1669 ;; Remove or replace comments
1670 (org-export-handle-comments (plist-get parameters :comments))
1672 ;; Run the final hook
1673 (run-hooks 'org-export-preprocess-final-hook)
1675 (setq rtn (buffer-string)))
1676 (kill-buffer " org-mode-tmp")
1677 rtn))
1679 (defun org-export-kill-licensed-text ()
1680 "Remove all text that is marked with a :org-license-to-kill property."
1681 (let (p)
1682 (while (setq p (text-property-any (point-min) (point-max)
1683 :org-license-to-kill t))
1684 (delete-region
1685 p (or (next-single-property-change p :org-license-to-kill)
1686 (point-max))))))
1688 (defun org-export-define-heading-targets (target-alist)
1689 "Find all headings and define the targets for them.
1690 The new targets are added to TARGET-ALIST, which is also returned."
1691 (goto-char (point-min))
1692 (org-init-section-numbers)
1693 (let ((re (concat "^" org-outline-regexp
1694 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1695 level target last-section-target a)
1696 (while (re-search-forward re nil t)
1697 (if (match-end 1)
1698 (progn
1699 (push (cons (org-match-string-no-properties 1)
1700 target) target-alist)
1701 (setq a (or (assoc last-section-target org-export-target-aliases)
1702 (progn
1703 (push (list last-section-target)
1704 org-export-target-aliases)
1705 (car org-export-target-aliases))))
1706 (push (caar target-alist) (cdr a)))
1707 (setq level (org-reduced-level
1708 (save-excursion (goto-char (point-at-bol))
1709 (org-outline-level))))
1710 (setq target (org-solidify-link-text
1711 (format "sec-%s" (org-section-number level))))
1712 (setq last-section-target target)
1713 (push (cons target target) target-alist)
1714 (add-text-properties
1715 (point-at-bol) (point-at-eol)
1716 (list 'target target)))))
1717 target-alist)
1719 (defun org-export-handle-invisible-targets (target-alist)
1720 "Find targets in comments and move them out of comments.
1721 Mark them as invisible targets."
1722 (let (target tmp a)
1723 (goto-char (point-min))
1724 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1725 ;; Check if the line before or after is a headline with a target
1726 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1727 (get-text-property (point-at-bol 2) 'target)))
1728 (progn
1729 ;; use the existing target in a neighboring line
1730 (setq tmp (match-string 2))
1731 (replace-match "")
1732 (and (looking-at "\n") (delete-char 1))
1733 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1734 target-alist)
1735 (setq a (or (assoc target org-export-target-aliases)
1736 (progn
1737 (push (list target) org-export-target-aliases)
1738 (car org-export-target-aliases))))
1739 (push tmp (cdr a)))
1740 ;; Make an invisible target
1741 (replace-match "\\1(INVISIBLE)"))))
1742 target-alist)
1744 (defun org-export-target-internal-links (target-alist)
1745 "Find all internal links and assign targets to them.
1746 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1747 let the link point to the corresponding section.
1748 This function also handles the id links, if they have a match in
1749 the current file."
1750 (goto-char (point-min))
1751 (while (re-search-forward org-bracket-link-regexp nil t)
1752 (org-if-unprotected
1753 (let* ((md (match-data))
1754 (desc (match-end 2))
1755 (link (org-link-unescape (match-string 1)))
1756 (slink (org-solidify-link-text link))
1757 found props pos cref
1758 (target
1759 (cond
1760 ((cdr (assoc slink target-alist)))
1761 ((and (string-match "^id:" link)
1762 (cdr (assoc (substring link 3) target-alist))))
1763 ((string-match "^(\\(.*\\))$" link)
1764 (setq cref (match-string 1 link))
1765 (concat "coderef:" cref))
1766 ((string-match org-link-types-re link) nil)
1767 ((or (file-name-absolute-p link)
1768 (string-match "^\\." link))
1769 nil)
1771 (save-excursion
1772 (setq found (condition-case nil (org-link-search link)
1773 (error nil)))
1774 (when (and found
1775 (or (org-on-heading-p)
1776 (not (eq found 'dedicated))))
1777 (or (get-text-property (point) 'target)
1778 (get-text-property
1779 (max (point-min)
1780 (1- (or (previous-single-property-change
1781 (point) 'target) 0)))
1782 'target))))))))
1783 (when target
1784 (set-match-data md)
1785 (goto-char (match-beginning 1))
1786 (setq props (text-properties-at (point)))
1787 (delete-region (match-beginning 1) (match-end 1))
1788 (setq pos (point))
1789 (insert target)
1790 (unless desc (insert "][" link))
1791 (add-text-properties pos (point) props))))))
1793 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1794 "Remove drawers, or extract the content.
1795 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1796 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1797 whose content to keep."
1798 (unless (eq t exp-drawers)
1799 (goto-char (point-min))
1800 (let ((re (concat "^[ \t]*:\\("
1801 (mapconcat
1802 'identity
1803 (org-delete-all exp-drawers
1804 (copy-sequence all-drawers))
1805 "\\|")
1806 "\\):[ \t]*\n\\([^\000]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1807 (while (re-search-forward re nil t)
1808 (org-if-unprotected
1809 (replace-match ""))))))
1811 (defun org-export-handle-export-tags (select-tags exclude-tags)
1812 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1813 Both arguments are lists of tags.
1814 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1815 will be removed.
1816 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1817 removed as well."
1818 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1819 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1820 select-tags "\\|")
1821 "\\):"))
1822 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1823 exclude-tags "\\|")
1824 "\\):"))
1825 beg end cont)
1826 (goto-char (point-min))
1827 (when (and select-tags
1828 (re-search-forward
1829 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1830 ;; At least one tree is marked for export, this means
1831 ;; all the unmarked stuff needs to go.
1832 ;; Dig out the trees that should be exported
1833 (goto-char (point-min))
1834 (outline-next-heading)
1835 (setq beg (point))
1836 (put-text-property beg (point-max) :org-delete t)
1837 (while (re-search-forward re-sel nil t)
1838 (when (org-on-heading-p)
1839 (org-back-to-heading)
1840 (remove-text-properties
1841 (max (1- (point)) (point-min))
1842 (setq cont (save-excursion (org-end-of-subtree t t)))
1843 '(:org-delete t))
1844 (while (and (org-up-heading-safe)
1845 (get-text-property (point) :org-delete))
1846 (remove-text-properties (max (1- (point)) (point-min))
1847 (point-at-eol) '(:org-delete t)))
1848 (goto-char cont))))
1849 ;; Remove the trees explicitly marked for noexport
1850 (when exclude-tags
1851 (goto-char (point-min))
1852 (while (re-search-forward re-excl nil t)
1853 (when (org-at-heading-p)
1854 (org-back-to-heading t)
1855 (setq beg (point))
1856 (org-end-of-subtree t)
1857 (delete-region beg (point)))))
1858 ;; Remove everything that is now still marked for deletion
1859 (goto-char (point-min))
1860 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1861 (setq end (or (next-single-property-change beg :org-delete)
1862 (point-max)))
1863 (delete-region beg end))))
1865 (defun org-export-remove-archived-trees (export-archived-trees)
1866 "Remove archived trees.
1867 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1868 When it is t, the entire archived tree will be exported.
1869 When it is nil the entire tree including the headline will be removed
1870 from the buffer."
1871 (let ((re-archive (concat ":" org-archive-tag ":"))
1872 a b)
1873 (when (not (eq export-archived-trees t))
1874 (goto-char (point-min))
1875 (while (re-search-forward re-archive nil t)
1876 (if (not (org-on-heading-p t))
1877 (org-end-of-subtree t)
1878 (beginning-of-line 1)
1879 (setq a (if export-archived-trees
1880 (1+ (point-at-eol)) (point))
1881 b (org-end-of-subtree t))
1882 (if (> b a) (delete-region a b)))))))
1884 (defun org-export-remove-headline-metadata (opts)
1885 "Remove meta data from the headline, according to user options."
1886 (let ((re org-complex-heading-regexp)
1887 (todo (plist-get opts :todo-keywords))
1888 (tags (plist-get opts :tags))
1889 (pri (plist-get opts :priority))
1890 (elts '(1 2 3 4 5))
1891 rpl)
1892 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1893 (when (or (not todo) (not tags) (not pri))
1894 (goto-char (point-min))
1895 (while (re-search-forward re nil t)
1896 (org-if-unprotected
1897 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1898 elts " "))
1899 (replace-match rpl t t))))))
1901 (defun org-export-remove-timestamps ()
1902 "Remove timestamps and keywords for export."
1903 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1904 (backward-char 1)
1905 (org-if-unprotected
1906 (unless (save-match-data (org-at-table-p))
1907 (replace-match "")
1908 (beginning-of-line 1)
1909 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1910 (replace-match ""))))))
1912 (defun org-export-remove-clock-lines ()
1913 "Remove clock lines for export."
1914 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1915 (while (re-search-forward re nil t)
1916 (org-if-unprotected
1917 (replace-match "")))))
1919 (defun org-export-protect-quoted-subtrees ()
1920 "Mark quoted subtrees with the protection property."
1921 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1922 (goto-char (point-min))
1923 (while (re-search-forward re-quote nil t)
1924 (goto-char (match-beginning 0))
1925 (end-of-line 1)
1926 (add-text-properties (point) (org-end-of-subtree t)
1927 '(org-protected t)))))
1929 (defun org-export-protect-verbatim ()
1930 "Mark verbatim snippets with the protection property."
1931 (goto-char (point-min))
1932 (while (re-search-forward org-verbatim-re nil t)
1933 (add-text-properties (match-beginning 4) (match-end 4)
1934 '(org-protected t))
1935 (goto-char (1+ (match-end 4)))))
1937 (defun org-export-protect-colon-examples ()
1938 "Protect lines starting with a colon."
1939 (goto-char (point-min))
1940 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1941 (while (re-search-forward re nil t)
1942 (beginning-of-line 1)
1943 (setq beg (point))
1944 (while (looking-at re)
1945 (end-of-line 1)
1946 (or (eobp) (forward-char 1)))
1947 (add-text-properties beg (if (bolp) (1- (point)) (point))
1948 '(org-protected t)))))
1950 (defun org-export-select-backend-specific-text (backend)
1951 (let ((formatters
1952 '((html "HTML" "BEGIN_HTML" "END_HTML")
1953 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1954 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1955 (case-fold-search t)
1956 fmt)
1958 (while formatters
1959 (setq fmt (pop formatters))
1960 (when (eq (car fmt) backend)
1961 ;; This is selected code, put it into the file for real
1962 (goto-char (point-min))
1963 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1964 ":[ \t]*\\(.*\\)") nil t)
1965 (replace-match "\\1" t)
1966 (add-text-properties
1967 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1968 '(org-protected t))))
1969 (goto-char (point-min))
1970 (while (re-search-forward
1971 (concat "^#\\+"
1972 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1973 (cadddr fmt) "\\>.*\n?") nil t)
1974 (if (eq (car fmt) backend)
1975 ;; yes, keep this
1976 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1977 '(org-protected t))
1978 ;; No, this is for a different backend, kill it
1979 (delete-region (match-beginning 0) (match-end 0)))))))
1981 (defun org-export-mark-blockquote-and-verse ()
1982 "Mark block quote and verse environments with special cookies.
1983 These special cookies will later be interpreted by the backend."
1984 ;; Blockquotes
1985 (goto-char (point-min))
1986 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1987 nil t)
1988 (replace-match (if (equal (downcase (match-string 1)) "end")
1989 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1990 t t))
1991 ;; Verse
1992 (goto-char (point-min))
1993 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1994 (replace-match (if (equal (downcase (match-string 1)) "end")
1995 "ORG-VERSE-END" "ORG-VERSE-START")
1996 t t)))
1998 (defun org-export-attach-captions-and-attributes (backend target-alist)
1999 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
2000 If the next thing following is a table, add the text properties to the first
2001 table line. If it is a link, add it to the line containing the link."
2002 (goto-char (point-min))
2003 (remove-text-properties (point-min) (point-max)
2004 '(org-caption nil org-attributes nil))
2005 (let ((case-fold-search t)
2006 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
2007 "\\|"
2008 "^#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
2009 "\\|"
2010 "^#\\+label:[ \t]+\\(.*\\)"
2011 "\\|"
2012 "^[ \t]*|[^-]"
2013 "\\|"
2014 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
2015 cap attr label)
2016 (while (re-search-forward re nil t)
2017 (cond
2018 ((match-end 1)
2019 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
2020 ((match-end 2)
2021 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
2022 ((match-end 3)
2023 (setq label (org-trim (match-string 3))))
2025 (add-text-properties (point-at-bol) (point-at-eol)
2026 (list 'org-caption cap
2027 'org-attributes attr
2028 'org-label label))
2029 (if label (push (cons label label) target-alist))
2030 (setq cap nil attr nil label nil)))))
2031 target-alist)
2033 (defun org-export-remove-comment-blocks-and-subtrees ()
2034 "Remove the comment environment, and also commented subtrees."
2035 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
2036 (case-fold-search nil))
2037 ;; Remove comment environment
2038 (goto-char (point-min))
2039 (while (re-search-forward
2040 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
2041 (replace-match "" t t))
2042 ;; Remove subtrees that are commented
2043 (goto-char (point-min))
2044 (while (re-search-forward re-commented nil t)
2045 (goto-char (match-beginning 0))
2046 (delete-region (point) (org-end-of-subtree t)))))
2048 (defun org-export-handle-comments (commentsp)
2049 "Remove comments, or convert to backend-specific format.
2050 COMMENTSP can be a format string for publishing comments.
2051 When it is nil, all comments will be removed."
2052 (let ((re "^#\\(.*\n?\\)")
2053 pos)
2054 (goto-char (point-min))
2055 (while (or (looking-at re)
2056 (re-search-forward re nil t))
2057 (setq pos (match-beginning 0))
2058 (if commentsp
2059 (progn (add-text-properties
2060 (match-beginning 0) (match-end 0) '(org-protected t))
2061 (replace-match (format commentsp (match-string 1)) t t))
2062 (goto-char (1+ pos))
2063 (org-if-unprotected
2064 (replace-match "")
2065 (goto-char (max (point-min) (1- pos))))))))
2067 (defun org-export-mark-radio-links ()
2068 "Find all matches for radio targets and turn them into internal links."
2069 (let ((re-radio (and org-target-link-regexp
2070 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
2071 (goto-char (point-min))
2072 (when re-radio
2073 (while (re-search-forward re-radio nil t)
2074 (org-if-unprotected
2075 (replace-match "\\1[[\\2]]"))))))
2077 (defun org-export-remove-special-table-lines ()
2078 "Remove tables lines that are used for internal purposes."
2079 (goto-char (point-min))
2080 (while (re-search-forward "^[ \t]*|" nil t)
2081 (beginning-of-line 1)
2082 (if (or (looking-at "[ \t]*| *[!_^] *|")
2083 (and (looking-at ".*?| *<[0-9]+> *|")
2084 (not (looking-at ".*?| *[^ <|]"))))
2085 (delete-region (max (point-min) (1- (point-at-bol)))
2086 (point-at-eol))
2087 (end-of-line 1))))
2089 (defun org-export-normalize-links ()
2090 "Convert all links to bracket links, and expand link abbreviations."
2091 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
2092 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
2093 (goto-char (point-min))
2094 (while (re-search-forward re-plain-link nil t)
2095 (goto-char (1- (match-end 0)))
2096 (org-if-unprotected-at (1+ (match-beginning 0))
2097 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2098 ":" (match-string 3) "]]")))
2099 ;; added 'org-link face to links
2100 (put-text-property 0 (length s) 'face 'org-link s)
2101 (replace-match s t t))))
2102 (goto-char (point-min))
2103 (while (re-search-forward re-angle-link nil t)
2104 (goto-char (1- (match-end 0)))
2105 (org-if-unprotected
2106 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2107 ":" (match-string 3) "]]")))
2108 (put-text-property 0 (length s) 'face 'org-link s)
2109 (replace-match s t t))))
2110 (goto-char (point-min))
2111 (while (re-search-forward org-bracket-link-regexp nil t)
2112 (goto-char (1- (match-end 0)))
2113 (org-if-unprotected
2114 (let* ((xx (save-match-data
2115 (org-translate-link
2116 (org-link-expand-abbrev (match-string 1)))))
2117 (s (concat
2118 "[[" (org-add-props (copy-sequence xx)
2119 nil 'org-protected t)
2121 (if (match-end 3)
2122 (match-string 2)
2123 (concat "[" (org-add-props
2124 (copy-sequence xx)
2125 '(org-protected t))
2126 "]"))
2127 "]")))
2128 (put-text-property 0 (length s) 'face 'org-link s)
2129 (replace-match s t t))))))
2131 (defun org-export-concatenate-multiline-links ()
2132 "Find multi-line links and put it all into a single line.
2133 This is to make sure that the line-processing export backends
2134 can work correctly."
2135 (goto-char (point-min))
2136 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
2137 (org-if-unprotected
2138 (replace-match "\\1 \\3")
2139 (goto-char (match-beginning 0)))))
2141 (defun org-export-concatenate-multiline-emphasis ()
2142 "Find multi-line emphasis and put it all into a single line.
2143 This is to make sure that the line-processing export backends
2144 can work correctly."
2145 (goto-char (point-min))
2146 (while (re-search-forward org-emph-re nil t)
2147 (if (and (not (= (char-after (match-beginning 3))
2148 (char-after (match-beginning 4))))
2149 (save-excursion (goto-char (match-beginning 0))
2150 (save-match-data (not (org-at-table-p)))))
2151 (org-if-unprotected
2152 (subst-char-in-region (match-beginning 0) (match-end 0)
2153 ?\n ?\ t)
2154 (goto-char (1- (match-end 0))))
2155 (goto-char (1+ (match-beginning 0))))))
2157 (defun org-export-grab-title-from-buffer ()
2158 "Get a title for the current document, from looking at the buffer."
2159 (let ((inhibit-read-only t))
2160 (save-excursion
2161 (goto-char (point-min))
2162 (let ((end (if (looking-at org-outline-regexp)
2163 (point)
2164 (save-excursion (outline-next-heading) (point)))))
2165 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
2166 ;; Mark the line so that it will not be exported as normal text.
2167 (org-unmodified
2168 (add-text-properties (match-beginning 0) (match-end 0)
2169 (list :org-license-to-kill t)))
2170 ;; Return the title string
2171 (org-trim (match-string 0)))))))
2173 (defun org-export-get-title-from-subtree ()
2174 "Return subtree title and exclude it from export."
2175 (let (title (rbeg (region-beginning)) (rend (region-end)))
2176 (save-excursion
2177 (goto-char rbeg)
2178 (when (and (org-at-heading-p)
2179 (>= (org-end-of-subtree t t) rend))
2180 ;; This is a subtree, we take the title from the first heading
2181 (goto-char rbeg)
2182 (looking-at org-todo-line-regexp)
2183 (setq title (match-string 3))
2184 (org-unmodified
2185 (add-text-properties (point) (1+ (point-at-eol))
2186 (list :org-license-to-kill t)))
2187 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
2188 title))
2190 (defun org-solidify-link-text (s &optional alist)
2191 "Take link text and make a safe target out of it."
2192 (save-match-data
2193 (let* ((rtn
2194 (mapconcat
2195 'identity
2196 (org-split-string s "[ \t\r\n]+") "=="))
2197 (a (assoc rtn alist)))
2198 (or (cdr a) rtn))))
2200 (defun org-get-min-level (lines &optional offset)
2201 "Get the minimum level in LINES."
2202 (let ((re "^\\(\\*+\\) ") l)
2203 (catch 'exit
2204 (while (setq l (pop lines))
2205 (if (string-match re l)
2206 (throw 'exit (org-tr-level (- (length (match-string 1 l))
2207 (or offset 0))))))
2208 1)))
2210 ;; Variable holding the vector with section numbers
2211 (defvar org-section-numbers (make-vector org-level-max 0))
2213 (defun org-init-section-numbers ()
2214 "Initialize the vector for the section numbers."
2215 (let* ((level -1)
2216 (numbers (nreverse (org-split-string "" "\\.")))
2217 (depth (1- (length org-section-numbers)))
2218 (i depth) number-string)
2219 (while (>= i 0)
2220 (if (> i level)
2221 (aset org-section-numbers i 0)
2222 (setq number-string (or (car numbers) "0"))
2223 (if (string-match "\\`[A-Z]\\'" number-string)
2224 (aset org-section-numbers i
2225 (- (string-to-char number-string) ?A -1))
2226 (aset org-section-numbers i (string-to-number number-string)))
2227 (pop numbers))
2228 (setq i (1- i)))))
2230 (defun org-section-number (&optional level)
2231 "Return a string with the current section number.
2232 When LEVEL is non-nil, increase section numbers on that level."
2233 (let* ((depth (1- (length org-section-numbers)))
2234 (string "")
2235 (fmts (car org-export-section-number-format))
2236 (term (cdr org-export-section-number-format))
2237 (sep "")
2238 ctype fmt idx n)
2239 (when level
2240 (when (> level -1)
2241 (aset org-section-numbers
2242 level (1+ (aref org-section-numbers level))))
2243 (setq idx (1+ level))
2244 (while (<= idx depth)
2245 (if (not (= idx 1))
2246 (aset org-section-numbers idx 0))
2247 (setq idx (1+ idx))))
2248 (setq idx 0)
2249 (while (<= idx depth)
2250 (when (> (aref org-section-numbers idx) 0)
2251 (setq fmt (or (pop fmts) fmt)
2252 ctype (car fmt)
2253 n (aref org-section-numbers idx)
2254 string (if (> n 0)
2255 (concat string sep (org-number-to-counter n ctype))
2256 (concat string ".0"))
2257 sep (nth 1 fmt)))
2258 (setq idx (1+ idx)))
2259 (save-match-data
2260 (if (string-match "\\`\\([@0]\\.\\)+" string)
2261 (setq string (replace-match "" t nil string)))
2262 (if (string-match "\\(\\.0\\)+\\'" string)
2263 (setq string (replace-match "" t nil string))))
2264 (concat string term)))
2266 (defun org-number-to-counter (n type)
2267 "Concert number N to a string counter, according to TYPE.
2268 TYPE must be a string, any of:
2269 1 number
2270 A A,B,....
2271 a a,b,....
2272 I upper case roman numeral
2273 i lower case roman numeral"
2274 (cond
2275 ((equal type "1") (number-to-string n))
2276 ((equal type "A") (char-to-string (+ ?A n -1)))
2277 ((equal type "a") (char-to-string (+ ?a n -1)))
2278 ((equal type "I") (org-number-to-roman n))
2279 ((equal type "i") (downcase (org-number-to-roman n)))
2280 (t (error "Invalid counter type `%s'" type))))
2282 (defun org-number-to-roman (n)
2283 "Convert integer N into a roman numeral."
2284 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2285 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2286 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2287 ( 1 . "I")))
2288 (res ""))
2289 (if (<= n 0)
2290 (number-to-string n)
2291 (while roman
2292 (if (>= n (caar roman))
2293 (setq n (- n (caar roman))
2294 res (concat res (cdar roman)))
2295 (pop roman)))
2296 res)))
2298 ;;; Macros
2300 (defun org-export-preprocess-apply-macros ()
2301 "Replace macro references."
2302 (goto-char (point-min))
2303 (let (sy val key)
2304 (while (re-search-forward "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)}}}" nil t)
2305 (setq key (downcase (match-string 1)))
2306 (when (setq val (or (plist-get org-export-opt-plist
2307 (intern (concat ":macro-" key)))
2308 (plist-get org-export-opt-plist
2309 (intern (concat ":" key)))))
2310 (and (stringp val)
2311 (replace-match val t t))))))
2313 ;;; Include files
2315 (defun org-export-handle-include-files ()
2316 "Include the contents of include files, with proper formatting."
2317 (let ((case-fold-search t)
2318 params file markup lang start end prefix prefix1 switches)
2319 (goto-char (point-min))
2320 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2321 (setq params (read (concat "(" (match-string 1) ")"))
2322 prefix (org-get-and-remove-property 'params :prefix)
2323 prefix1 (org-get-and-remove-property 'params :prefix1)
2324 file (org-symname-or-string (pop params))
2325 markup (org-symname-or-string (pop params))
2326 lang (and (member markup '("src" "SRC"))
2327 (org-symname-or-string (pop params)))
2328 switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
2329 (delete-region (match-beginning 0) (match-end 0))
2330 (if (or (not file)
2331 (not (file-exists-p file))
2332 (not (file-readable-p file)))
2333 (insert (format "CANNOT INCLUDE FILE %s" file))
2334 (when markup
2335 (if (equal (downcase markup) "src")
2336 (setq start (format "#+begin_src %s %s\n"
2337 (or lang "fundamental")
2338 (or switches ""))
2339 end "#+end_src")
2340 (setq start (format "#+begin_%s %s\n" markup switches)
2341 end (format "#+end_%s" markup))))
2342 (insert (or start ""))
2343 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2344 (or (bolp) (newline))
2345 (insert (or end ""))))))
2347 (defun org-get-file-contents (file &optional prefix prefix1)
2348 "Get the contents of FILE and return them as a string.
2349 If PREFIX is a string, prepend it to each line. If PREFIX1
2350 is a string, prepend it to the first line instead of PREFIX."
2351 (with-temp-buffer
2352 (insert-file-contents file)
2353 (when (or prefix prefix1)
2354 (goto-char (point-min))
2355 (while (not (eobp))
2356 (insert (or prefix1 prefix))
2357 (setq prefix1 nil)
2358 (beginning-of-line 2)))
2359 (buffer-string)))
2361 (defun org-get-and-remove-property (listvar prop)
2362 "Check if the value of LISTVAR contains PROP as a property.
2363 If yes, return the value of that property (i.e. the element following
2364 in the list) and remove property and value from the list in LISTVAR."
2365 (let ((list (symbol-value listvar)) m v)
2366 (when (setq m (member prop list))
2367 (setq v (nth 1 m))
2368 (if (equal (car list) prop)
2369 (set listvar (cddr list))
2370 (setcdr (nthcdr (- (length list) (length m) 1) list)
2371 (cddr m))
2372 (set listvar list)))
2375 (defun org-symname-or-string (s)
2376 (if (symbolp s)
2377 (if s (symbol-name s) s)
2380 ;;; Fontification and line numbers for code examples
2382 (defvar org-export-last-code-line-counter-value 0)
2384 (defun org-export-replace-src-segments-and-examples (backend)
2385 "Replace source code segments with special code for export."
2386 (setq org-export-last-code-line-counter-value 0)
2387 (let ((case-fold-search t)
2388 lang code trans opts)
2389 (goto-char (point-min))
2390 (while (re-search-forward
2391 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2392 nil t)
2393 (if (match-end 1)
2394 ;; src segments
2395 (setq lang (match-string 2)
2396 opts (match-string 3)
2397 code (match-string 4))
2398 (setq lang nil
2399 opts (match-string 6)
2400 code (match-string 7)))
2402 (setq trans (org-export-format-source-code-or-example
2403 backend lang code opts))
2404 (replace-match trans t t))))
2406 (defvar htmlp) ;; dynamically scoped
2407 (defvar latexp) ;; dynamically scoped
2409 (defun org-export-format-source-code-or-example (backend
2410 lang code &optional opts)
2411 "Format CODE from language LANG and return it formatted for export.
2412 If LANG is nil, do not add any fontification.
2413 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2414 and `+n' for continuing previous numering.
2415 Code formatting according to language currently only works for HTML.
2416 Numbering lines works for all three major backends (html, latex, and ascii)."
2417 (save-match-data
2418 (let (num cont rtn rpllbl keepp textareap cols rows fmt)
2419 (setq opts (or opts "")
2420 num (string-match "[-+]n\\>" opts)
2421 cont (string-match "\\+n\\>" opts)
2422 rpllbl (string-match "-r\\>" opts)
2423 keepp (string-match "-k\\>" opts)
2424 textareap (string-match "-t\\>" opts)
2425 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2426 (string-to-number (match-string 1 opts))
2428 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2429 (string-to-number (match-string 1 opts))
2430 (org-count-lines code))
2431 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2432 (match-string 1 opts)))
2433 (when (and textareap (eq backend 'html))
2434 ;; we cannot use numbering or highlighting.
2435 (setq num nil cont nil lang nil))
2436 (if keepp (setq rpllbl 'keep))
2437 (setq rtn code)
2438 (when (equal lang "org")
2439 (setq rtn (with-temp-buffer
2440 (insert rtn)
2441 ;; Free up the protected lines
2442 (goto-char (point-min))
2443 (while (re-search-forward "^," nil t)
2444 (replace-match "")
2445 (end-of-line 1))
2446 (buffer-string))))
2447 ;; Now backend-specific coding
2448 (cond
2449 ((eq backend 'html)
2450 ;; We are exporting to HTML
2451 (when lang
2452 (require 'htmlize nil t)
2453 (when (not (fboundp 'htmlize-region-for-paste))
2454 ;; we do not have htmlize.el, or an old version of it
2455 (setq lang nil)
2456 (message
2457 "htmlize.el 1.34 or later is needed for source code formatting")))
2459 (if lang
2460 (let* ((mode (and lang (intern (concat lang "-mode"))))
2461 (org-inhibit-startup t)
2462 (org-startup-folded nil))
2463 (setq rtn
2464 (with-temp-buffer
2465 (insert rtn)
2466 (if (functionp mode)
2467 (funcall mode)
2468 (fundamental-mode))
2469 (font-lock-fontify-buffer)
2470 (org-export-htmlize-region-for-paste
2471 (point-min) (point-max))))
2472 (if (string-match "<pre\\([^>]*\\)>\n?" rtn)
2473 (setq rtn (replace-match
2474 (format "<pre class=\"src src-%s\">\n" lang)
2475 t t rtn))))
2476 (if textareap
2477 (setq rtn (concat
2478 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2479 cols rows)
2480 rtn "</textarea>\n</p>\n"))
2481 (with-temp-buffer
2482 (insert rtn)
2483 (goto-char (point-min))
2484 (while (re-search-forward "[<>&]" nil t)
2485 (replace-match (cdr (assq (char-before)
2486 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2487 t t))
2488 (setq rtn (buffer-string)))
2489 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2490 (unless textareap
2491 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2492 cont rpllbl fmt)))
2493 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2494 ((eq backend 'latex)
2495 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2496 (concat "\n#+BEGIN_LaTeX\n"
2497 (org-add-props (concat "\\begin{verbatim}\n" rtn "\n\\end{verbatim}\n")
2498 '(org-protected t))
2499 "#+END_LaTeX\n\n"))
2500 ((eq backend 'ascii)
2501 ;; This is not HTML or LaTeX, so just make it an example.
2502 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2503 (concat "#+BEGIN_ASCII\n"
2504 (org-add-props
2505 (concat
2506 (mapconcat
2507 (lambda (l) (concat " " l))
2508 (org-split-string rtn "\n")
2509 "\n")
2510 "\n")
2511 '(org-protected t))
2512 "#+END_ASCII\n"))))))
2514 (defun org-export-number-lines (text backend
2515 &optional skip1 skip2 number cont
2516 replace-labels label-format)
2517 (if (and (not number) (not (eq replace-labels 'keep)))
2518 (setq replace-labels nil)) ;; must use names if no numbers
2519 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2520 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2521 (with-temp-buffer
2522 (insert text)
2523 (goto-char (point-max))
2524 (skip-chars-backward " \t\n\r")
2525 (delete-region (point) (point-max))
2526 (beginning-of-line (- 1 skip2))
2527 (let* ((last (org-current-line))
2528 (n org-export-last-code-line-counter-value)
2529 (nmax (+ n (- last skip1)))
2530 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2532 (cond
2533 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2534 fmt))
2535 ((eq backend 'ascii) fmt)
2536 ((eq backend 'latex) fmt)
2537 (t "")))
2538 (label-format (or label-format org-coderef-label-format))
2539 (label-pre (if (string-match "%s" label-format)
2540 (substring label-format 0 (match-beginning 0))
2541 label-format))
2542 (label-post (if (string-match "%s" label-format)
2543 (substring label-format (match-end 0))
2544 ""))
2545 (lbl-re
2546 (concat
2547 ".*?\\S-.*?\\([ \t]*\\("
2548 (regexp-quote label-pre)
2549 "\\([-a-zA-Z0-9_]+\\)"
2550 (regexp-quote label-post)
2551 "\\)\\)"))
2552 ref)
2554 (goto-line (1+ skip1))
2555 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2556 (if number
2557 (insert (format fm (incf n)))
2558 (forward-char 1))
2559 (when (and (not (eq replace-labels 'keep))
2560 (looking-at lbl-re))
2561 (setq ref (match-string 3))
2562 (if replace-labels
2563 (progn
2564 (delete-region (match-beginning 1) (match-end 1))
2565 (push (cons ref n) org-export-code-refs))
2566 (goto-char (match-beginning 2))
2567 (delete-region (match-beginning 2) (match-end 2))
2568 (insert "(" ref ")")
2569 (push (cons ref (concat "(" ref ")")) org-export-code-refs))
2570 (when (eq backend 'html)
2571 (save-excursion
2572 (beginning-of-line 1)
2573 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2574 ref))
2575 (end-of-line 1)
2576 (insert "</span>")))))
2577 (setq org-export-last-code-line-counter-value n)
2578 (goto-char (point-max))
2579 (newline)
2580 (buffer-string))))
2582 ;;; ASCII export
2584 (defvar org-last-level nil) ; dynamically scoped variable
2585 (defvar org-min-level nil) ; dynamically scoped variable
2586 (defvar org-levels-open nil) ; dynamically scoped parameter
2587 (defvar org-ascii-current-indentation nil) ; For communication
2589 ;;;###autoload
2590 (defun org-export-as-ascii (arg)
2591 "Export the outline as a pretty ASCII file.
2592 If there is an active region, export only the region.
2593 The prefix ARG specifies how many levels of the outline should become
2594 underlined headlines. The default is 3."
2595 (interactive "P")
2596 (setq-default org-todo-line-regexp org-todo-line-regexp)
2597 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2598 (org-infile-export-plist)))
2599 (region-p (org-region-active-p))
2600 (rbeg (and region-p (region-beginning)))
2601 (rend (and region-p (region-end)))
2602 (subtree-p
2603 (when region-p
2604 (save-excursion
2605 (goto-char rbeg)
2606 (and (org-at-heading-p)
2607 (>= (org-end-of-subtree t t) rend)))))
2608 (level-offset (if subtree-p
2609 (save-excursion
2610 (goto-char rbeg)
2611 (+ (funcall outline-level)
2612 (if org-odd-levels-only 1 0)))
2614 (opt-plist (setq org-export-opt-plist
2615 (if subtree-p
2616 (org-export-add-subtree-options opt-plist rbeg)
2617 opt-plist)))
2618 (custom-times org-display-custom-times)
2619 (org-ascii-current-indentation '(0 . 0))
2620 (level 0) line txt
2621 (umax nil)
2622 (umax-toc nil)
2623 (case-fold-search nil)
2624 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2625 (filename (concat (file-name-as-directory
2626 (org-export-directory :ascii opt-plist))
2627 (file-name-sans-extension
2628 (or (and subtree-p
2629 (org-entry-get (region-beginning)
2630 "EXPORT_FILE_NAME" t))
2631 (file-name-nondirectory bfname)))
2632 ".txt"))
2633 (filename (if (equal (file-truename filename)
2634 (file-truename bfname))
2635 (concat filename ".txt")
2636 filename))
2637 (buffer (find-file-noselect filename))
2638 (org-levels-open (make-vector org-level-max nil))
2639 (odd org-odd-levels-only)
2640 (date (plist-get opt-plist :date))
2641 (author (plist-get opt-plist :author))
2642 (title (or (and subtree-p (org-export-get-title-from-subtree))
2643 (plist-get opt-plist :title)
2644 (and (not
2645 (plist-get opt-plist :skip-before-1st-heading))
2646 (org-export-grab-title-from-buffer))
2647 (file-name-sans-extension
2648 (file-name-nondirectory bfname))))
2649 (email (plist-get opt-plist :email))
2650 (language (plist-get opt-plist :language))
2651 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2652 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2653 (todo nil)
2654 (lang-words nil)
2655 (region
2656 (buffer-substring
2657 (if (org-region-active-p) (region-beginning) (point-min))
2658 (if (org-region-active-p) (region-end) (point-max))))
2659 (lines (org-split-string
2660 (org-export-preprocess-string
2661 region
2662 :for-ascii t
2663 :skip-before-1st-heading
2664 (plist-get opt-plist :skip-before-1st-heading)
2665 :drawers (plist-get opt-plist :drawers)
2666 :tags (plist-get opt-plist :tags)
2667 :priority (plist-get opt-plist :priority)
2668 :footnotes (plist-get opt-plist :footnotes)
2669 :timestamps (plist-get opt-plist :timestamps)
2670 :todo-keywords (plist-get opt-plist :todo-keywords)
2671 :verbatim-multiline t
2672 :select-tags (plist-get opt-plist :select-tags)
2673 :exclude-tags (plist-get opt-plist :exclude-tags)
2674 :archived-trees
2675 (plist-get opt-plist :archived-trees)
2676 :add-text (plist-get opt-plist :text))
2677 "\n"))
2678 thetoc have-headings first-heading-pos
2679 table-open table-buffer link-buffer link desc desc0 rpl wrap)
2680 (let ((inhibit-read-only t))
2681 (org-unmodified
2682 (remove-text-properties (point-min) (point-max)
2683 '(:org-license-to-kill t))))
2685 (setq org-min-level (org-get-min-level lines level-offset))
2686 (setq org-last-level org-min-level)
2687 (org-init-section-numbers)
2689 (find-file-noselect filename)
2691 (setq lang-words (or (assoc language org-export-language-setup)
2692 (assoc "en" org-export-language-setup)))
2693 (switch-to-buffer-other-window buffer)
2694 (erase-buffer)
2695 (fundamental-mode)
2696 ;; create local variables for all options, to make sure all called
2697 ;; functions get the correct information
2698 (mapc (lambda (x)
2699 (set (make-local-variable (nth 2 x))
2700 (plist-get opt-plist (car x))))
2701 org-export-plist-vars)
2702 (org-set-local 'org-odd-levels-only odd)
2703 (setq umax (if arg (prefix-numeric-value arg)
2704 org-export-headline-levels))
2705 (setq umax-toc (if (integerp org-export-with-toc)
2706 (min org-export-with-toc umax)
2707 umax))
2709 ;; File header
2710 (if title (org-insert-centered title ?=))
2711 (insert "\n")
2712 (if (and (or author email)
2713 org-export-author-info)
2714 (insert (concat (nth 1 lang-words) ": " (or author "")
2715 (if email (concat " <" email ">") "")
2716 "\n")))
2718 (cond
2719 ((and date (string-match "%" date))
2720 (setq date (format-time-string date)))
2721 (date)
2722 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
2724 (if (and date org-export-time-stamp-file)
2725 (insert (concat (nth 2 lang-words) ": " date"\n")))
2727 (insert "\n\n")
2729 (if org-export-with-toc
2730 (progn
2731 (push (concat (nth 3 lang-words) "\n") thetoc)
2732 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
2733 "\n") thetoc)
2734 (mapc '(lambda (line)
2735 (if (string-match org-todo-line-regexp
2736 line)
2737 ;; This is a headline
2738 (progn
2739 (setq have-headings t)
2740 (setq level (- (match-end 1) (match-beginning 1)
2741 level-offset)
2742 level (org-tr-level level)
2743 txt (match-string 3 line)
2744 todo
2745 (or (and org-export-mark-todo-in-toc
2746 (match-beginning 2)
2747 (not (member (match-string 2 line)
2748 org-done-keywords)))
2749 ; TODO, not DONE
2750 (and org-export-mark-todo-in-toc
2751 (= level umax-toc)
2752 (org-search-todo-below
2753 line lines level))))
2754 (setq txt (org-html-expand-for-ascii txt))
2756 (while (string-match org-bracket-link-regexp txt)
2757 (setq txt
2758 (replace-match
2759 (match-string (if (match-end 2) 3 1) txt)
2760 t t txt)))
2762 (if (and (memq org-export-with-tags '(not-in-toc nil))
2763 (string-match
2764 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2765 txt))
2766 (setq txt (replace-match "" t t txt)))
2767 (if (string-match quote-re0 txt)
2768 (setq txt (replace-match "" t t txt)))
2770 (if org-export-with-section-numbers
2771 (setq txt (concat (org-section-number level)
2772 " " txt)))
2773 (if (<= level umax-toc)
2774 (progn
2775 (push
2776 (concat
2777 (make-string
2778 (* (max 0 (- level org-min-level)) 4) ?\ )
2779 (format (if todo "%s (*)\n" "%s\n") txt))
2780 thetoc)
2781 (setq org-last-level level))
2782 ))))
2783 lines)
2784 (setq thetoc (if have-headings (nreverse thetoc) nil))))
2786 (org-init-section-numbers)
2787 (while (setq line (pop lines))
2788 (when (and link-buffer (string-match "^\\*+ " line))
2789 (org-export-ascii-push-links (nreverse link-buffer))
2790 (setq link-buffer nil))
2791 (setq wrap nil)
2792 ;; Remove the quoted HTML tags.
2793 (setq line (org-html-expand-for-ascii line))
2794 ;; Replace links with the description when possible
2795 (while (string-match org-bracket-link-regexp line)
2796 (setq link (match-string 1 line)
2797 desc0 (match-string 3 line)
2798 desc (or desc0 (match-string 1 line)))
2799 (if (and (> (length link) 8)
2800 (equal (substring link 0 8) "coderef:"))
2801 (setq line (replace-match
2802 (format (org-export-get-coderef-format (substring link 8) desc)
2803 (cdr (assoc
2804 (substring link 8)
2805 org-export-code-refs)))
2806 t t line))
2807 (setq rpl (concat "["
2808 (or (match-string 3 line) (match-string 1 line))
2809 "]"))
2810 (when (and desc0 (not (equal desc0 link)))
2811 (if org-export-ascii-links-to-notes
2812 (push (cons desc0 link) link-buffer)
2813 (setq rpl (concat rpl " (" link ")")
2814 wrap (+ (length line) (- (length (match-string 0)))
2815 (length desc)))))
2816 (setq line (replace-match rpl t t line))))
2817 (when custom-times
2818 (setq line (org-translate-time line)))
2819 (cond
2820 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
2821 ;; a Headline
2822 (setq first-heading-pos (or first-heading-pos (point)))
2823 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
2824 level-offset))
2825 txt (match-string 2 line))
2826 (org-ascii-level-start level txt umax lines))
2828 ((and org-export-with-tables
2829 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
2830 (if (not table-open)
2831 ;; New table starts
2832 (setq table-open t table-buffer nil))
2833 ;; Accumulate lines
2834 (setq table-buffer (cons line table-buffer))
2835 (when (or (not lines)
2836 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2837 (car lines))))
2838 (setq table-open nil
2839 table-buffer (nreverse table-buffer))
2840 (insert (mapconcat
2841 (lambda (x)
2842 (org-fix-indentation x org-ascii-current-indentation))
2843 (org-format-table-ascii table-buffer)
2844 "\n") "\n")))
2846 (setq line (org-fix-indentation line org-ascii-current-indentation))
2847 ;; Remove forced line breaks
2848 (if (string-match "\\\\\\\\[ \t]*$" line)
2849 (setq line (replace-match "" t t line)))
2850 (if (and org-export-with-fixed-width
2851 (string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line))
2852 (setq line (replace-match "\\1" nil nil line))
2853 (if wrap (setq line (org-export-ascii-wrap line wrap))))
2854 (insert line "\n"))))
2856 (org-export-ascii-push-links (nreverse link-buffer))
2858 (normal-mode)
2860 ;; insert the table of contents
2861 (when thetoc
2862 (goto-char (point-min))
2863 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
2864 (progn
2865 (goto-char (match-beginning 0))
2866 (replace-match ""))
2867 (goto-char first-heading-pos))
2868 (mapc 'insert thetoc)
2869 (or (looking-at "[ \t]*\n[ \t]*\n")
2870 (insert "\n\n")))
2872 ;; Convert whitespace place holders
2873 (goto-char (point-min))
2874 (let (beg end)
2875 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2876 (setq end (next-single-property-change beg 'org-whitespace))
2877 (goto-char beg)
2878 (delete-region beg end)
2879 (insert (make-string (- end beg) ?\ ))))
2881 (save-buffer)
2882 ;; remove display and invisible chars
2883 (let (beg end)
2884 (goto-char (point-min))
2885 (while (setq beg (next-single-property-change (point) 'display))
2886 (setq end (next-single-property-change beg 'display))
2887 (delete-region beg end)
2888 (goto-char beg)
2889 (insert "=>"))
2890 (goto-char (point-min))
2891 (while (setq beg (next-single-property-change (point) 'org-cwidth))
2892 (setq end (next-single-property-change beg 'org-cwidth))
2893 (delete-region beg end)
2894 (goto-char beg)))
2895 (goto-char (point-min))))
2897 (defun org-export-ascii-preprocess ()
2898 "Do extra work for ASCII export"
2899 ;; Put quotes around verbatim text
2900 (goto-char (point-min))
2901 (while (re-search-forward org-verbatim-re nil t)
2902 (goto-char (match-end 2))
2903 (backward-delete-char 1) (insert "'")
2904 (goto-char (match-beginning 2))
2905 (delete-char 1) (insert "`")
2906 (goto-char (match-end 2)))
2907 ;; Remove target markers
2908 (goto-char (point-min))
2909 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
2910 (replace-match "\\1\\2")))
2912 (defun org-search-todo-below (line lines level)
2913 "Search the subtree below LINE for any TODO entries."
2914 (let ((rest (cdr (memq line lines)))
2915 (re org-todo-line-regexp)
2916 line lv todo)
2917 (catch 'exit
2918 (while (setq line (pop rest))
2919 (if (string-match re line)
2920 (progn
2921 (setq lv (- (match-end 1) (match-beginning 1))
2922 todo (and (match-beginning 2)
2923 (not (member (match-string 2 line)
2924 org-done-keywords))))
2925 ; TODO, not DONE
2926 (if (<= lv level) (throw 'exit nil))
2927 (if todo (throw 'exit t))))))))
2929 (defun org-html-expand-for-ascii (line)
2930 "Handle quoted HTML for ASCII export."
2931 (if org-export-html-expand
2932 (while (string-match "@<[^<>\n]*>" line)
2933 ;; We just remove the tags for now.
2934 (setq line (replace-match "" nil nil line))))
2935 line)
2938 (defun org-export-ascii-wrap (line where)
2939 "Wrap LINE at or before WHERE."
2940 (let ((ind (org-get-indentation line))
2941 pos)
2942 (catch 'found
2943 (loop for i from where downto (/ where 2) do
2944 (and (equal (aref line i) ?\ )
2945 (setq pos i)
2946 (throw 'found t))))
2947 (if pos
2948 (concat (substring line 0 pos) "\n"
2949 (make-string ind ?\ )
2950 (substring line (1+ pos)))
2951 line)))
2953 (defun org-export-ascii-push-links (link-buffer)
2954 "Push out links in the buffer."
2955 (when link-buffer
2956 ;; We still have links to push out.
2957 (insert "\n")
2958 (let ((ind ""))
2959 (save-match-data
2960 (if (save-excursion
2961 (re-search-backward
2962 "^\\(\\([ \t]*\\)\\|\\(\\*+ \\)\\)[^ \t\n]" nil t))
2963 (setq ind (or (match-string 2)
2964 (make-string (length (match-string 3)) ?\ )))))
2965 (mapc (lambda (x) (insert ind "[" (car x) "]: " (cdr x) "\n"))
2966 link-buffer))
2967 (insert "\n")))
2969 (defun org-insert-centered (s &optional underline)
2970 "Insert the string S centered and underline it with character UNDERLINE."
2971 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
2972 (insert (make-string ind ?\ ) s "\n")
2973 (if underline
2974 (insert (make-string ind ?\ )
2975 (make-string (string-width s) underline)
2976 "\n"))))
2978 (defun org-ascii-level-start (level title umax &optional lines)
2979 "Insert a new level in ASCII export."
2980 (let (char (n (- level umax 1)) (ind 0))
2981 (if (> level umax)
2982 (progn
2983 (insert (make-string (* 2 n) ?\ )
2984 (char-to-string (nth (% n (length org-export-ascii-bullets))
2985 org-export-ascii-bullets))
2986 " " title "\n")
2987 ;; find the indentation of the next non-empty line
2988 (catch 'stop
2989 (while lines
2990 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
2991 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
2992 (throw 'stop (setq ind (org-get-indentation (car lines)))))
2993 (pop lines)))
2994 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
2995 (if (or (not (equal (char-before) ?\n))
2996 (not (equal (char-before (1- (point))) ?\n)))
2997 (insert "\n"))
2998 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
2999 (unless org-export-with-tags
3000 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
3001 (setq title (replace-match "" t t title))))
3002 (if org-export-with-section-numbers
3003 (setq title (concat (org-section-number level) " " title)))
3004 (insert title "\n" (make-string (string-width title) char) "\n")
3005 (setq org-ascii-current-indentation '(0 . 0)))))
3007 ;;;###autoload
3008 (defun org-export-visible (type arg)
3009 "Create a copy of the visible part of the current buffer, and export it.
3010 The copy is created in a temporary buffer and removed after use.
3011 TYPE is the final key (as a string) that also select the export command in
3012 the `C-c C-e' export dispatcher.
3013 As a special case, if the you type SPC at the prompt, the temporary
3014 org-mode file will not be removed but presented to you so that you can
3015 continue to use it. The prefix arg ARG is passed through to the exporting
3016 command."
3017 (interactive
3018 (list (progn
3019 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
3020 (read-char-exclusive))
3021 current-prefix-arg))
3022 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
3023 (error "Invalid export key"))
3024 (let* ((binding (cdr (assoc type
3025 '((?a . org-export-as-ascii)
3026 (?\C-a . org-export-as-ascii)
3027 (?b . org-export-as-html-and-open)
3028 (?\C-b . org-export-as-html-and-open)
3029 (?h . org-export-as-html)
3030 (?H . org-export-as-html-to-buffer)
3031 (?R . org-export-region-as-html)
3032 (?x . org-export-as-xoxo)))))
3033 (keepp (equal type ?\ ))
3034 (file buffer-file-name)
3035 (buffer (get-buffer-create "*Org Export Visible*"))
3036 s e)
3037 ;; Need to hack the drawers here.
3038 (save-excursion
3039 (goto-char (point-min))
3040 (while (re-search-forward org-drawer-regexp nil t)
3041 (goto-char (match-beginning 1))
3042 (or (org-invisible-p) (org-flag-drawer nil))))
3043 (with-current-buffer buffer (erase-buffer))
3044 (save-excursion
3045 (setq s (goto-char (point-min)))
3046 (while (not (= (point) (point-max)))
3047 (goto-char (org-find-invisible))
3048 (append-to-buffer buffer s (point))
3049 (setq s (goto-char (org-find-visible))))
3050 (org-cycle-hide-drawers 'all)
3051 (goto-char (point-min))
3052 (unless keepp
3053 ;; Copy all comment lines to the end, to make sure #+ settings are
3054 ;; still available for the second export step. Kind of a hack, but
3055 ;; does do the trick.
3056 (if (looking-at "#[^\r\n]*")
3057 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
3058 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
3059 (append-to-buffer buffer (1+ (match-beginning 0))
3060 (min (point-max) (1+ (match-end 0))))))
3061 (set-buffer buffer)
3062 (let ((buffer-file-name file)
3063 (org-inhibit-startup t))
3064 (org-mode)
3065 (show-all)
3066 (unless keepp (funcall binding arg))))
3067 (if (not keepp)
3068 (kill-buffer buffer)
3069 (switch-to-buffer-other-window buffer)
3070 (goto-char (point-min)))))
3072 (defun org-find-visible ()
3073 (let ((s (point)))
3074 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
3075 (get-char-property s 'invisible)))
3077 (defun org-find-invisible ()
3078 (let ((s (point)))
3079 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
3080 (not (get-char-property s 'invisible))))
3083 ;;; HTML export
3085 (defvar org-archive-location) ;; gets loaded with the org-archive require.
3086 (defun org-get-current-options ()
3087 "Return a string with current options as keyword options.
3088 Does include HTML export options as well as TODO and CATEGORY stuff."
3089 (require 'org-archive)
3090 (format
3091 "#+TITLE: %s
3092 #+AUTHOR: %s
3093 #+EMAIL: %s
3094 #+DATE: %s
3095 #+LANGUAGE: %s
3096 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
3097 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
3099 #+EXPORT_SELECT_TAGS: %s
3100 #+EXPORT_EXCLUDE_TAGS: %s
3101 #+LINK_UP: %s
3102 #+LINK_HOME: %s
3103 #+CATEGORY: %s
3104 #+SEQ_TODO: %s
3105 #+TYP_TODO: %s
3106 #+PRIORITIES: %c %c %c
3107 #+DRAWERS: %s
3108 #+STARTUP: %s %s %s %s %s
3109 #+TAGS: %s
3110 #+FILETAGS: %s
3111 #+ARCHIVE: %s
3112 #+LINK: %s
3114 (buffer-name) (user-full-name) user-mail-address
3115 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
3116 org-export-default-language
3117 org-export-headline-levels
3118 org-export-with-section-numbers
3119 org-export-with-toc
3120 org-export-preserve-breaks
3121 org-export-html-expand
3122 org-export-with-fixed-width
3123 org-export-with-tables
3124 org-export-with-sub-superscripts
3125 org-export-with-special-strings
3126 org-export-with-footnotes
3127 org-export-with-emphasize
3128 org-export-with-timestamps
3129 org-export-with-TeX-macros
3130 org-export-with-LaTeX-fragments
3131 org-export-skip-text-before-1st-heading
3132 org-export-with-drawers
3133 org-export-with-todo-keywords
3134 org-export-with-priority
3135 org-export-with-tags
3136 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
3137 (mapconcat 'identity org-export-select-tags " ")
3138 (mapconcat 'identity org-export-exclude-tags " ")
3139 org-export-html-link-up
3140 org-export-html-link-home
3141 (or (ignore-errors
3142 (file-name-sans-extension
3143 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3144 "NOFILENAME")
3145 "TODO FEEDBACK VERIFY DONE"
3146 "Me Jason Marie DONE"
3147 org-highest-priority org-lowest-priority org-default-priority
3148 (mapconcat 'identity org-drawers " ")
3149 (cdr (assoc org-startup-folded
3150 '((nil . "showall") (t . "overview") (content . "content"))))
3151 (if org-odd-levels-only "odd" "oddeven")
3152 (if org-hide-leading-stars "hidestars" "showstars")
3153 (if org-startup-align-all-tables "align" "noalign")
3154 (cond ((eq org-log-done t) "logdone")
3155 ((equal org-log-done 'note) "lognotedone")
3156 ((not org-log-done) "nologdone"))
3157 (or (mapconcat (lambda (x)
3158 (cond
3159 ((equal '(:startgroup) x) "{")
3160 ((equal '(:endgroup) x) "}")
3161 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
3162 (t (car x))))
3163 (or org-tag-alist (org-get-buffer-tags)) " ") "")
3164 (mapconcat 'identity org-file-tags " ")
3165 org-archive-location
3166 "org file:~/org/%s.org"
3169 (defun org-export-html-preprocess (parameters)
3170 ;; Convert LaTeX fragments to images
3171 (when (plist-get parameters :LaTeX-fragments)
3172 (org-format-latex
3173 (concat "ltxpng/" (file-name-sans-extension
3174 (file-name-nondirectory
3175 org-current-export-file)))
3176 org-current-export-dir nil "Creating LaTeX image %s"))
3177 (message "Exporting..."))
3179 ;;;###autoload
3180 (defun org-insert-export-options-template ()
3181 "Insert into the buffer a template with information for exporting."
3182 (interactive)
3183 (if (not (bolp)) (newline))
3184 (let ((s (org-get-current-options)))
3185 (and (string-match "#\\+CATEGORY" s)
3186 (setq s (substring s 0 (match-beginning 0))))
3187 (insert s)))
3189 ;;;###autoload
3190 (defun org-export-as-html-and-open (arg)
3191 "Export the outline as HTML and immediately open it with a browser.
3192 If there is an active region, export only the region.
3193 The prefix ARG specifies how many levels of the outline should become
3194 headlines. The default is 3. Lower levels will become bulleted lists."
3195 (interactive "P")
3196 (org-export-as-html arg 'hidden)
3197 (org-open-file buffer-file-name))
3199 ;;;###autoload
3200 (defun org-export-as-html-batch ()
3201 "Call `org-export-as-html', may be used in batch processing as
3202 emacs --batch
3203 --load=$HOME/lib/emacs/org.el
3204 --eval \"(setq org-export-headline-levels 2)\"
3205 --visit=MyFile --funcall org-export-as-html-batch"
3206 (org-export-as-html org-export-headline-levels 'hidden))
3208 ;;;###autoload
3209 (defun org-export-as-html-to-buffer (arg)
3210 "Call `org-export-as-html` with output to a temporary buffer.
3211 No file is created. The prefix ARG is passed through to `org-export-as-html'."
3212 (interactive "P")
3213 (org-export-as-html arg nil nil "*Org HTML Export*")
3214 (switch-to-buffer-other-window "*Org HTML Export*"))
3216 ;;;###autoload
3217 (defun org-replace-region-by-html (beg end)
3218 "Assume the current region has org-mode syntax, and convert it to HTML.
3219 This can be used in any buffer. For example, you could write an
3220 itemized list in org-mode syntax in an HTML buffer and then use this
3221 command to convert it."
3222 (interactive "r")
3223 (let (reg html buf pop-up-frames)
3224 (save-window-excursion
3225 (if (org-mode-p)
3226 (setq html (org-export-region-as-html
3227 beg end t 'string))
3228 (setq reg (buffer-substring beg end)
3229 buf (get-buffer-create "*Org tmp*"))
3230 (with-current-buffer buf
3231 (erase-buffer)
3232 (insert reg)
3233 (org-mode)
3234 (setq html (org-export-region-as-html
3235 (point-min) (point-max) t 'string)))
3236 (kill-buffer buf)))
3237 (delete-region beg end)
3238 (insert html)))
3240 ;;;###autoload
3241 (defun org-export-region-as-html (beg end &optional body-only buffer)
3242 "Convert region from BEG to END in org-mode buffer to HTML.
3243 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
3244 contents, and only produce the region of converted text, useful for
3245 cut-and-paste operations.
3246 If BUFFER is a buffer or a string, use/create that buffer as a target
3247 of the converted HTML. If BUFFER is the symbol `string', return the
3248 produced HTML as a string and leave not buffer behind. For example,
3249 a Lisp program could call this function in the following way:
3251 (setq html (org-export-region-as-html beg end t 'string))
3253 When called interactively, the output buffer is selected, and shown
3254 in a window. A non-interactive call will only return the buffer."
3255 (interactive "r\nP")
3256 (when (interactive-p)
3257 (setq buffer "*Org HTML Export*"))
3258 (let ((transient-mark-mode t) (zmacs-regions t)
3259 ext-plist rtn)
3260 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
3261 (goto-char end)
3262 (set-mark (point)) ;; to activate the region
3263 (goto-char beg)
3264 (setq rtn (org-export-as-html
3265 nil nil ext-plist
3266 buffer body-only))
3267 (if (fboundp 'deactivate-mark) (deactivate-mark))
3268 (if (and (interactive-p) (bufferp rtn))
3269 (switch-to-buffer-other-window rtn)
3270 rtn)))
3272 (defvar html-table-tag nil) ; dynamically scoped into this.
3273 (defvar org-par-open nil)
3274 ;;;###autoload
3275 (defun org-export-as-html (arg &optional hidden ext-plist
3276 to-buffer body-only pub-dir)
3277 "Export the outline as a pretty HTML file.
3278 If there is an active region, export only the region. The prefix
3279 ARG specifies how many levels of the outline should become
3280 headlines. The default is 3. Lower levels will become bulleted
3281 lists. When HIDDEN is non-nil, don't display the HTML buffer.
3282 EXT-PLIST is a property list with external parameters overriding
3283 org-mode's default settings, but still inferior to file-local
3284 settings. When TO-BUFFER is non-nil, create a buffer with that
3285 name and export to that buffer. If TO-BUFFER is the symbol
3286 `string', don't leave any buffer behind but just return the
3287 resulting HTML as a string. When BODY-ONLY is set, don't produce
3288 the file header and footer, simply return the content of
3289 <body>...</body>, without even the body tags themselves. When
3290 PUB-DIR is set, use this as the publishing directory."
3291 (interactive "P")
3293 ;; Make sure we have a file name when we need it.
3294 (when (and (not (or to-buffer body-only))
3295 (not buffer-file-name))
3296 (if (buffer-base-buffer)
3297 (org-set-local 'buffer-file-name
3298 (with-current-buffer (buffer-base-buffer)
3299 buffer-file-name))
3300 (error "Need a file name to be able to export.")))
3302 (message "Exporting...")
3303 (setq-default org-todo-line-regexp org-todo-line-regexp)
3304 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
3305 (setq-default org-done-keywords org-done-keywords)
3306 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
3307 (let* ((opt-plist
3308 (org-export-process-option-filters
3309 (org-combine-plists (org-default-export-plist)
3310 ext-plist
3311 (org-infile-export-plist))))
3312 (style (concat (if (plist-get opt-plist :style-include-default)
3313 org-export-html-style-default)
3314 (plist-get opt-plist :style)
3315 (plist-get opt-plist :style-extra)
3316 "\n" org-export-html-scripts))
3317 (html-extension (plist-get opt-plist :html-extension))
3318 (link-validate (plist-get opt-plist :link-validation-function))
3319 valid thetoc have-headings first-heading-pos
3320 (odd org-odd-levels-only)
3321 (region-p (org-region-active-p))
3322 (rbeg (and region-p (region-beginning)))
3323 (rend (and region-p (region-end)))
3324 (subtree-p
3325 (if (plist-get opt-plist :ignore-subree-p)
3327 (when region-p
3328 (save-excursion
3329 (goto-char rbeg)
3330 (and (org-at-heading-p)
3331 (>= (org-end-of-subtree t t) rend))))))
3332 (level-offset (if subtree-p
3333 (save-excursion
3334 (goto-char rbeg)
3335 (+ (funcall outline-level)
3336 (if org-odd-levels-only 1 0)))
3338 (opt-plist (setq org-export-opt-plist
3339 (if subtree-p
3340 (org-export-add-subtree-options opt-plist rbeg)
3341 opt-plist)))
3342 ;; The following two are dynamically scoped into other
3343 ;; routines below.
3344 (org-current-export-dir
3345 (or pub-dir (org-export-directory :html opt-plist)))
3346 (org-current-export-file buffer-file-name)
3347 (level 0) (line "") (origline "") txt todo
3348 (umax nil)
3349 (umax-toc nil)
3350 (filename (if to-buffer nil
3351 (expand-file-name
3352 (concat
3353 (file-name-sans-extension
3354 (or (and subtree-p
3355 (org-entry-get (region-beginning)
3356 "EXPORT_FILE_NAME" t))
3357 (file-name-nondirectory buffer-file-name)))
3358 "." html-extension)
3359 (file-name-as-directory
3360 (or pub-dir (org-export-directory :html opt-plist))))))
3361 (current-dir (if buffer-file-name
3362 (file-name-directory buffer-file-name)
3363 default-directory))
3364 (buffer (if to-buffer
3365 (cond
3366 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
3367 (t (get-buffer-create to-buffer)))
3368 (find-file-noselect filename)))
3369 (org-levels-open (make-vector org-level-max nil))
3370 (date (plist-get opt-plist :date))
3371 (author (plist-get opt-plist :author))
3372 (title (or (and subtree-p (org-export-get-title-from-subtree))
3373 (plist-get opt-plist :title)
3374 (and (not
3375 (plist-get opt-plist :skip-before-1st-heading))
3376 (org-export-grab-title-from-buffer))
3377 (and buffer-file-name
3378 (file-name-sans-extension
3379 (file-name-nondirectory buffer-file-name)))
3380 "UNTITLED"))
3381 (html-table-tag (plist-get opt-plist :html-table-tag))
3382 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
3383 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
3384 (inquote nil)
3385 (infixed nil)
3386 (inverse nil)
3387 (in-local-list nil)
3388 (local-list-type nil)
3389 (local-list-indent nil)
3390 (llt org-plain-list-ordered-item-terminator)
3391 (email (plist-get opt-plist :email))
3392 (language (plist-get opt-plist :language))
3393 (lang-words nil)
3394 (head-count 0) cnt
3395 (start 0)
3396 (coding-system (and (boundp 'buffer-file-coding-system)
3397 buffer-file-coding-system))
3398 (coding-system-for-write (or org-export-html-coding-system
3399 coding-system))
3400 (save-buffer-coding-system (or org-export-html-coding-system
3401 coding-system))
3402 (charset (and coding-system-for-write
3403 (fboundp 'coding-system-get)
3404 (coding-system-get coding-system-for-write
3405 'mime-charset)))
3406 (region
3407 (buffer-substring
3408 (if region-p (region-beginning) (point-min))
3409 (if region-p (region-end) (point-max))))
3410 (lines
3411 (org-split-string
3412 (org-export-preprocess-string
3413 region
3414 :emph-multiline t
3415 :for-html t
3416 :skip-before-1st-heading
3417 (plist-get opt-plist :skip-before-1st-heading)
3418 :drawers (plist-get opt-plist :drawers)
3419 :todo-keywords (plist-get opt-plist :todo-keywords)
3420 :tags (plist-get opt-plist :tags)
3421 :priority (plist-get opt-plist :priority)
3422 :footnotes (plist-get opt-plist :footnotes)
3423 :timestamps (plist-get opt-plist :timestamps)
3424 :archived-trees
3425 (plist-get opt-plist :archived-trees)
3426 :select-tags (plist-get opt-plist :select-tags)
3427 :exclude-tags (plist-get opt-plist :exclude-tags)
3428 :add-text
3429 (plist-get opt-plist :text)
3430 :LaTeX-fragments
3431 (plist-get opt-plist :LaTeX-fragments))
3432 "[\r\n]"))
3433 table-open type
3434 table-buffer table-orig-buffer
3435 ind item-type starter didclose
3436 rpl path attr desc descp desc1 desc2 link
3437 snumber fnc item-tag
3438 footnotes footref-seen
3439 id-file
3442 (let ((inhibit-read-only t))
3443 (org-unmodified
3444 (remove-text-properties (point-min) (point-max)
3445 '(:org-license-to-kill t))))
3447 (message "Exporting...")
3449 (setq org-min-level (org-get-min-level lines level-offset))
3450 (setq org-last-level org-min-level)
3451 (org-init-section-numbers)
3453 (cond
3454 ((and date (string-match "%" date))
3455 (setq date (format-time-string date)))
3456 (date)
3457 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
3459 ;; Get the language-dependent settings
3460 (setq lang-words (or (assoc language org-export-language-setup)
3461 (assoc "en" org-export-language-setup)))
3463 ;; Switch to the output buffer
3464 (set-buffer buffer)
3465 (let ((inhibit-read-only t)) (erase-buffer))
3466 (fundamental-mode)
3468 (and (fboundp 'set-buffer-file-coding-system)
3469 (set-buffer-file-coding-system coding-system-for-write))
3471 (let ((case-fold-search nil)
3472 (org-odd-levels-only odd))
3473 ;; create local variables for all options, to make sure all called
3474 ;; functions get the correct information
3475 (mapc (lambda (x)
3476 (set (make-local-variable (nth 2 x))
3477 (plist-get opt-plist (car x))))
3478 org-export-plist-vars)
3479 (setq umax (if arg (prefix-numeric-value arg)
3480 org-export-headline-levels))
3481 (setq umax-toc (if (integerp org-export-with-toc)
3482 (min org-export-with-toc umax)
3483 umax))
3484 (unless body-only
3485 ;; File header
3486 (insert (format
3487 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3488 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3489 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3490 lang=\"%s\" xml:lang=\"%s\">
3491 <head>
3492 <title>%s</title>
3493 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3494 <meta name=\"generator\" content=\"Org-mode\"/>
3495 <meta name=\"generated\" content=\"%s\"/>
3496 <meta name=\"author\" content=\"%s\"/>
3498 </head>
3499 <body>
3500 <div id=\"content\">
3502 language language (org-html-expand title)
3503 (or charset "iso-8859-1") date author style))
3505 (insert (or (plist-get opt-plist :preamble) ""))
3507 (when (plist-get opt-plist :auto-preamble)
3508 (if title (insert (format org-export-html-title-format
3509 (org-html-expand title))))))
3511 (if (and org-export-with-toc (not body-only))
3512 (progn
3513 (push (format "<h%d>%s</h%d>\n"
3514 org-export-html-toplevel-hlevel
3515 (nth 3 lang-words)
3516 org-export-html-toplevel-hlevel)
3517 thetoc)
3518 (push "<div id=\"text-table-of-contents\">\n" thetoc)
3519 (push "<ul>\n<li>" thetoc)
3520 (setq lines
3521 (mapcar '(lambda (line)
3522 (if (string-match org-todo-line-regexp line)
3523 ;; This is a headline
3524 (progn
3525 (setq have-headings t)
3526 (setq level (- (match-end 1) (match-beginning 1)
3527 level-offset)
3528 level (org-tr-level level)
3529 txt (save-match-data
3530 (org-html-expand
3531 (org-export-cleanup-toc-line
3532 (match-string 3 line))))
3533 todo
3534 (or (and org-export-mark-todo-in-toc
3535 (match-beginning 2)
3536 (not (member (match-string 2 line)
3537 org-done-keywords)))
3538 ; TODO, not DONE
3539 (and org-export-mark-todo-in-toc
3540 (= level umax-toc)
3541 (org-search-todo-below
3542 line lines level))))
3543 (if (string-match
3544 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
3545 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
3546 (if (string-match quote-re0 txt)
3547 (setq txt (replace-match "" t t txt)))
3548 (setq snumber (org-section-number level))
3549 (if org-export-with-section-numbers
3550 (setq txt (concat snumber " " txt)))
3551 (if (<= level (max umax umax-toc))
3552 (setq head-count (+ head-count 1)))
3553 (if (<= level umax-toc)
3554 (progn
3555 (if (> level org-last-level)
3556 (progn
3557 (setq cnt (- level org-last-level))
3558 (while (>= (setq cnt (1- cnt)) 0)
3559 (push "\n<ul>\n<li>" thetoc))
3560 (push "\n" thetoc)))
3561 (if (< level org-last-level)
3562 (progn
3563 (setq cnt (- org-last-level level))
3564 (while (>= (setq cnt (1- cnt)) 0)
3565 (push "</li>\n</ul>" thetoc))
3566 (push "\n" thetoc)))
3567 ;; Check for targets
3568 (while (string-match org-any-target-regexp line)
3569 (setq line (replace-match
3570 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3571 t t line)))
3572 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
3573 (setq txt (replace-match "" t t txt)))
3574 (push
3575 (format
3576 (if todo
3577 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3578 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3579 snumber txt) thetoc)
3581 (setq org-last-level level))
3583 line)
3584 lines))
3585 (while (> org-last-level (1- org-min-level))
3586 (setq org-last-level (1- org-last-level))
3587 (push "</li>\n</ul>\n" thetoc))
3588 (push "</div>\n" thetoc)
3589 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3591 (setq head-count 0)
3592 (org-init-section-numbers)
3594 (org-open-par)
3596 (while (setq line (pop lines) origline line)
3597 (catch 'nextline
3599 ;; end of quote section?
3600 (when (and inquote (string-match "^\\*+ " line))
3601 (insert "</pre>\n")
3602 (setq inquote nil))
3603 ;; inside a quote section?
3604 (when inquote
3605 (insert (org-html-protect line) "\n")
3606 (throw 'nextline nil))
3608 ;; Fixed-width, verbatim lines (examples)
3609 (when (and org-export-with-fixed-width
3610 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
3611 (when (not infixed)
3612 (setq infixed t)
3613 (org-close-par-maybe)
3614 (insert "<pre class=\"example\">\n"))
3615 (insert (org-html-protect (match-string 3 line)) "\n")
3616 (when (or (not lines)
3617 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
3618 (car lines))))
3619 (setq infixed nil)
3620 (insert "</pre>\n"))
3621 (throw 'nextline nil))
3623 ;; Protected HTML
3624 (when (get-text-property 0 'org-protected line)
3625 (let (par)
3626 (when (re-search-backward
3627 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3628 (setq par (match-string 1))
3629 (replace-match "\\2\n"))
3630 (insert line "\n")
3631 (while (and lines
3632 (or (= (length (car lines)) 0)
3633 (get-text-property 0 'org-protected (car lines))))
3634 (insert (pop lines) "\n"))
3635 (and par (insert "<p>\n")))
3636 (throw 'nextline nil))
3638 ;; Horizontal line
3639 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3640 (if org-par-open
3641 (insert "\n</p>\n<hr/>\n<p>\n")
3642 (insert "\n<hr/>\n"))
3643 (throw 'nextline nil))
3645 ;; Blockquotes and verse
3646 (when (equal "ORG-BLOCKQUOTE-START" line)
3647 (org-close-par-maybe)
3648 (insert "<blockquote>\n<p>\n")
3649 (throw 'nextline nil))
3650 (when (equal "ORG-BLOCKQUOTE-END" line)
3651 (insert "</p>\n</blockquote>\n")
3652 (throw 'nextline nil))
3653 (when (equal "ORG-VERSE-START" line)
3654 (org-close-par-maybe)
3655 (insert "\n<p class=\"verse\">\n")
3656 (setq inverse t)
3657 (throw 'nextline nil))
3658 (when (equal "ORG-VERSE-END" line)
3659 (insert "</p>\n")
3660 (setq inverse nil)
3661 (throw 'nextline nil))
3662 (when inverse
3663 (let ((i (org-get-string-indentation line)))
3664 (if (> i 0)
3665 (setq line (concat (mapconcat 'identity
3666 (make-list (* 2 i) "\\nbsp") "")
3667 " " (org-trim line))))
3668 (setq line (concat line "\\\\"))))
3670 ;; make targets to anchors
3671 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3672 (cond
3673 ((match-end 2)
3674 (setq line (replace-match
3675 (format
3676 "@<a name=\"%s\" id=\"%s\">@</a>"
3677 (org-solidify-link-text (match-string 1 line))
3678 (org-solidify-link-text (match-string 1 line)))
3679 t t line)))
3680 ((and org-export-with-toc (equal (string-to-char line) ?*))
3681 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3682 (setq line (replace-match
3683 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3684 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3685 t t line)))
3687 (setq line (replace-match
3688 (concat "@<a name=\""
3689 (org-solidify-link-text (match-string 1 line))
3690 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3691 t t line)))))
3693 (setq line (org-html-handle-time-stamps line))
3695 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3696 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3697 ;; Also handle sub_superscripts and checkboxes
3698 (or (string-match org-table-hline-regexp line)
3699 (setq line (org-html-expand line)))
3701 ;; Format the links
3702 (setq start 0)
3703 (while (string-match org-bracket-link-analytic-regexp++ line start)
3704 (setq start (match-beginning 0))
3705 (setq path (save-match-data (org-link-unescape
3706 (match-string 3 line))))
3707 (setq type (cond
3708 ((match-end 2) (match-string 2 line))
3709 ((save-match-data
3710 (or (file-name-absolute-p path)
3711 (string-match "^\\.\\.?/" path)))
3712 "file")
3713 (t "internal")))
3714 (setq path (org-extract-attributes (org-link-unescape path)))
3715 (setq attr (get-text-property 0 'org-attributes path))
3716 (setq desc1 (if (match-end 5) (match-string 5 line))
3717 desc2 (if (match-end 2) (concat type ":" path) path)
3718 descp (and desc1 (not (equal desc1 desc2)))
3719 desc (or desc1 desc2))
3720 ;; Make an image out of the description if that is so wanted
3721 (when (and descp (org-file-image-p
3722 desc org-export-html-inline-image-extensions))
3723 (save-match-data
3724 (if (string-match "^file:" desc)
3725 (setq desc (substring desc (match-end 0)))))
3726 (setq desc (org-add-props
3727 (concat "<img src=\"" desc "\"/>")
3728 '(org-protected t))))
3729 ;; FIXME: do we need to unescape here somewhere?
3730 (cond
3731 ((equal type "internal")
3732 (setq rpl
3733 (concat
3734 "<a href=\"#"
3735 (org-solidify-link-text
3736 (save-match-data (org-link-unescape path)) nil)
3737 "\"" attr ">"
3738 (org-export-html-format-desc desc)
3739 "</a>")))
3740 ((and (equal type "id")
3741 (setq id-file (org-id-find-id-file path)))
3742 ;; This is an id: link to another file (if it was the same file,
3743 ;; it would have become an internal link...)
3744 (setq id-file (file-relative-name
3745 id-file (file-name-directory org-current-export-file)))
3746 (setq id-file (concat (file-name-sans-extension id-file)
3747 "." html-extension))
3748 (setq rpl (concat "<a href=\"" id-file "#"
3749 (if (org-uuidgen-p path) "ID-")
3750 path "\""
3751 attr ">"
3752 (org-export-html-format-desc desc)
3753 "</a>")))
3754 ((member type '("http" "https"))
3755 ;; standard URL, just check if we need to inline an image
3756 (if (and (or (eq t org-export-html-inline-images)
3757 (and org-export-html-inline-images (not descp)))
3758 (org-file-image-p
3759 path org-export-html-inline-image-extensions))
3760 (setq rpl (org-export-html-format-image
3761 (concat type ":" path) org-par-open))
3762 (setq link (concat type ":" path))
3763 (setq rpl (concat "<a href=\""
3764 (org-export-html-format-href link)
3765 "\"" attr ">"
3766 (org-export-html-format-desc desc)
3767 "</a>"))))
3768 ((member type '("ftp" "mailto" "news"))
3769 ;; standard URL
3770 (setq link (concat type ":" path))
3771 (setq rpl (concat "<a href=\""
3772 (org-export-html-format-href link)
3773 "\"" attr ">"
3774 (org-export-html-format-desc desc)
3775 "</a>")))
3777 ((string= type "coderef")
3779 (setq rpl (format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3780 path path path
3781 (format (org-export-get-coderef-format path (and descp desc))
3782 (cdr (assoc path org-export-code-refs))))))
3784 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3785 ;; The link protocol has a function for format the link
3786 (setq rpl
3787 (save-match-data
3788 (funcall fnc (org-link-unescape path) desc1 'html))))
3790 ((string= type "file")
3791 ;; FILE link
3792 (let* ((filename path)
3793 (abs-p (file-name-absolute-p filename))
3794 thefile file-is-image-p search)
3795 (save-match-data
3796 (if (string-match "::\\(.*\\)" filename)
3797 (setq search (match-string 1 filename)
3798 filename (replace-match "" t nil filename)))
3799 (setq valid
3800 (if (functionp link-validate)
3801 (funcall link-validate filename current-dir)
3803 (setq file-is-image-p
3804 (org-file-image-p
3805 filename org-export-html-inline-image-extensions))
3806 (setq thefile (if abs-p (expand-file-name filename) filename))
3807 (when (and org-export-html-link-org-files-as-html
3808 (string-match "\\.org$" thefile))
3809 (setq thefile (concat (substring thefile 0
3810 (match-beginning 0))
3811 "." html-extension))
3812 (if (and search
3813 ;; make sure this is can be used as target search
3814 (not (string-match "^[0-9]*$" search))
3815 (not (string-match "^\\*" search))
3816 (not (string-match "^/.*/$" search)))
3817 (setq thefile (concat thefile "#"
3818 (org-solidify-link-text
3819 (org-link-unescape search)))))
3820 (when (string-match "^file:" desc)
3821 (setq desc (replace-match "" t t desc))
3822 (if (string-match "\\.org$" desc)
3823 (setq desc (replace-match "" t t desc))))))
3824 (setq rpl (if (and file-is-image-p
3825 (or (eq t org-export-html-inline-images)
3826 (and org-export-html-inline-images
3827 (not descp))))
3828 (progn
3829 (message "image %s %s" thefile org-par-open)
3830 (org-export-html-format-image thefile org-par-open))
3831 (concat "<a href=\"" thefile "\"" attr ">"
3832 (org-export-html-format-desc desc)
3833 "</a>")))
3834 (if (not valid) (setq rpl desc))))
3837 ;; just publish the path, as default
3838 (setq rpl (concat "<i>&lt;" type ":"
3839 (save-match-data (org-link-unescape path))
3840 "&gt;</i>"))))
3841 (setq line (replace-match rpl t t line)
3842 start (+ start (length rpl))))
3844 ;; TODO items
3845 (if (and (string-match org-todo-line-regexp line)
3846 (match-beginning 2))
3848 (setq line
3849 (concat (substring line 0 (match-beginning 2))
3850 "<span class=\""
3851 (if (member (match-string 2 line)
3852 org-done-keywords)
3853 "done" "todo")
3854 " " (match-string 2 line)
3855 "\"> " (org-export-html-get-todo-kwd-class-name
3856 (match-string 2 line))
3857 "</span>" (substring line (match-end 2)))))
3859 ;; Does this contain a reference to a footnote?
3860 (when org-export-with-footnotes
3861 (setq start 0)
3862 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3863 (if (get-text-property (match-beginning 2) 'org-protected line)
3864 (setq start (match-end 2))
3865 (let ((n (match-string 2 line)) extra a)
3866 (if (setq a (assoc n footref-seen))
3867 (progn
3868 (setcdr a (1+ (cdr a)))
3869 (setq extra (format ".%d" (cdr a))))
3870 (setq extra "")
3871 (push (cons n 1) footref-seen))
3872 (setq line
3873 (replace-match
3874 (format
3875 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
3876 (match-string 1 line) n extra n n)
3877 t t line))))))
3879 (cond
3880 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3881 ;; This is a headline
3882 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
3883 level-offset))
3884 txt (match-string 2 line))
3885 (if (string-match quote-re0 txt)
3886 (setq txt (replace-match "" t t txt)))
3887 (if (<= level (max umax umax-toc))
3888 (setq head-count (+ head-count 1)))
3889 (when in-local-list
3890 ;; Close any local lists before inserting a new header line
3891 (while local-list-type
3892 (org-close-li (car local-list-type))
3893 (insert (format "</%sl>\n" (car local-list-type)))
3894 (pop local-list-type))
3895 (setq local-list-indent nil
3896 in-local-list nil))
3897 (setq first-heading-pos (or first-heading-pos (point)))
3898 (org-html-level-start level txt umax
3899 (and org-export-with-toc (<= level umax))
3900 head-count)
3901 ;; QUOTES
3902 (when (string-match quote-re line)
3903 (org-close-par-maybe)
3904 (insert "<pre>")
3905 (setq inquote t)))
3907 ((and org-export-with-tables
3908 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3909 (if (not table-open)
3910 ;; New table starts
3911 (setq table-open t table-buffer nil table-orig-buffer nil))
3912 ;; Accumulate lines
3913 (setq table-buffer (cons line table-buffer)
3914 table-orig-buffer (cons origline table-orig-buffer))
3915 (when (or (not lines)
3916 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3917 (car lines))))
3918 (setq table-open nil
3919 table-buffer (nreverse table-buffer)
3920 table-orig-buffer (nreverse table-orig-buffer))
3921 (org-close-par-maybe)
3922 (insert (org-format-table-html table-buffer table-orig-buffer))))
3924 ;; Normal lines
3925 (when (string-match
3926 (cond
3927 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3928 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3929 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3930 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3931 line)
3932 (setq ind (org-get-string-indentation line)
3933 item-type (if (match-beginning 4) "o" "u")
3934 starter (if (match-beginning 2)
3935 (substring (match-string 2 line) 0 -1))
3936 line (substring line (match-beginning 5))
3937 item-tag nil)
3938 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3939 (setq item-type "d"
3940 item-tag (match-string 1 line)
3941 line (substring line (match-end 0))))
3942 (when (and (not (equal item-type "d"))
3943 (not (string-match "[^ \t]" line)))
3944 ;; empty line. Pretend indentation is large.
3945 (setq ind (if org-empty-line-terminates-plain-lists
3947 (1+ (or (car local-list-indent) 1)))))
3948 (setq didclose nil)
3949 (while (and in-local-list
3950 (or (and (= ind (car local-list-indent))
3951 (not starter))
3952 (< ind (car local-list-indent))))
3953 (setq didclose t)
3954 (org-close-li (car local-list-type))
3955 (insert (format "</%sl>\n" (car local-list-type)))
3956 (pop local-list-type) (pop local-list-indent)
3957 (setq in-local-list local-list-indent))
3958 (cond
3959 ((and starter
3960 (or (not in-local-list)
3961 (> ind (car local-list-indent))))
3962 ;; Start new (level of) list
3963 (org-close-par-maybe)
3964 (insert (cond
3965 ((equal item-type "u") "<ul>\n<li>\n")
3966 ((equal item-type "o") "<ol>\n<li>\n")
3967 ((equal item-type "d")
3968 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3969 (push item-type local-list-type)
3970 (push ind local-list-indent)
3971 (setq in-local-list t))
3972 (starter
3973 ;; continue current list
3974 (org-close-li (car local-list-type))
3975 (insert (cond
3976 ((equal (car local-list-type) "d")
3977 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3978 (t "<li>\n"))))
3979 (didclose
3980 ;; we did close a list, normal text follows: need <p>
3981 (org-open-par)))
3982 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3983 (setq line
3984 (replace-match
3985 (if (equal (match-string 1 line) "X")
3986 "<b>[X]</b>"
3987 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3988 t t line))))
3990 ;; Empty lines start a new paragraph. If hand-formatted lists
3991 ;; are not fully interpreted, lines starting with "-", "+", "*"
3992 ;; also start a new paragraph.
3993 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3995 ;; Is this the start of a footnote?
3996 (when org-export-with-footnotes
3997 (when (and (boundp 'footnote-section-tag-regexp)
3998 (string-match (concat "^" footnote-section-tag-regexp)
3999 line))
4000 ;; ignore this line
4001 (throw 'nextline nil))
4002 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
4003 (org-close-par-maybe)
4004 (let ((n (match-string 1 line)))
4005 (setq org-par-open t
4006 line (replace-match
4007 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
4009 ;; Check if the line break needs to be conserved
4010 (cond
4011 ((string-match "\\\\\\\\[ \t]*$" line)
4012 (setq line (replace-match "<br/>" t t line)))
4013 (org-export-preserve-breaks
4014 (setq line (concat line "<br/>"))))
4016 ;; Check if a paragraph should be started
4017 (let ((start 0))
4018 (while (and org-par-open
4019 (string-match "\\\\par\\>" line start))
4020 ;; Leave a space in the </p> so that the footnote matcher
4021 ;; does not see this.
4022 (if (not (get-text-property (match-beginning 0)
4023 'org-protected line))
4024 (setq line (replace-match "</p ><p >" t t line)))
4025 (setq start (match-end 0))))
4027 (insert line "\n")))))
4029 ;; Properly close all local lists and other lists
4030 (when inquote
4031 (insert "</pre>\n")
4032 (org-open-par))
4033 (when in-local-list
4034 ;; Close any local lists before inserting a new header line
4035 (while local-list-type
4036 (org-close-li (car local-list-type))
4037 (insert (format "</%sl>\n" (car local-list-type)))
4038 (pop local-list-type))
4039 (setq local-list-indent nil
4040 in-local-list nil))
4041 (org-html-level-start 1 nil umax
4042 (and org-export-with-toc (<= level umax))
4043 head-count)
4044 ;; the </div> to close the last text-... div.
4045 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
4047 (save-excursion
4048 (goto-char (point-min))
4049 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
4050 (push (match-string 0) footnotes)
4051 (replace-match "" t t)))
4052 (when footnotes
4053 (insert (format org-export-html-footnotes-section
4054 (or (nth 4 lang-words) "Footnotes")
4055 (mapconcat 'identity (nreverse footnotes) "\n"))
4056 "\n"))
4057 (let ((bib (org-export-html-get-bibliography)))
4058 (when bib
4059 (insert "\n" bib "\n")))
4060 (unless body-only
4061 (when (plist-get opt-plist :auto-postamble)
4062 (insert "<div id=\"postamble\">\n")
4063 (when (and org-export-author-info author)
4064 (insert "<p class=\"author\"> "
4065 (nth 1 lang-words) ": " author "\n")
4066 (when email
4067 (if (listp (split-string email ",+ *"))
4068 (mapc (lambda(e)
4069 (insert "<a href=\"mailto:" e "\">&lt;"
4070 e "&gt;</a>\n"))
4071 (split-string email ",+ *"))
4072 (insert "<a href=\"mailto:" email "\">&lt;"
4073 email "&gt;</a>\n")))
4074 (insert "</p>\n"))
4075 (when (and date org-export-time-stamp-file)
4076 (insert "<p class=\"date\"> "
4077 (nth 2 lang-words) ": "
4078 date "</p>\n"))
4079 (when org-export-creator-info
4080 (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
4081 org-version emacs-major-version)))
4082 (when org-export-html-validation-link
4083 (insert "<p class=\"xhtml-validation\"><a href=\"http://validator.w3.org/check?uri=referer\" target=\"_blank\">Validate XHTML 1.0</a></p>"))
4084 (insert "</div>"))
4086 (if org-export-html-with-timestamp
4087 (insert org-export-html-html-helper-timestamp))
4088 (insert (or (plist-get opt-plist :postamble) ""))
4089 (insert "\n</div>\n</body>\n</html>\n"))
4091 (unless (plist-get opt-plist :buffer-will-be-killed)
4092 (normal-mode)
4093 (if (eq major-mode default-major-mode) (html-mode)))
4095 ;; insert the table of contents
4096 (goto-char (point-min))
4097 (when thetoc
4098 (if (or (re-search-forward
4099 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
4100 (re-search-forward
4101 "\\[TABLE-OF-CONTENTS\\]" nil t))
4102 (progn
4103 (goto-char (match-beginning 0))
4104 (replace-match ""))
4105 (goto-char first-heading-pos)
4106 (when (looking-at "\\s-*</p>")
4107 (goto-char (match-end 0))
4108 (insert "\n")))
4109 (insert "<div id=\"table-of-contents\">\n")
4110 (mapc 'insert thetoc)
4111 (insert "</div>\n"))
4112 ;; remove empty paragraphs and lists
4113 (goto-char (point-min))
4114 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
4115 (replace-match ""))
4116 (goto-char (point-min))
4117 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
4118 (replace-match ""))
4119 (goto-char (point-min))
4120 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
4121 (replace-match ""))
4122 ;; Convert whitespace place holders
4123 (goto-char (point-min))
4124 (let (beg end n)
4125 (while (setq beg (next-single-property-change (point) 'org-whitespace))
4126 (setq n (get-text-property beg 'org-whitespace)
4127 end (next-single-property-change beg 'org-whitespace))
4128 (goto-char beg)
4129 (delete-region beg end)
4130 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
4131 (make-string n ?x)))))
4132 (or to-buffer (save-buffer))
4133 (goto-char (point-min))
4134 (message "Exporting... done")
4135 (if (eq to-buffer 'string)
4136 (prog1 (buffer-substring (point-min) (point-max))
4137 (kill-buffer (current-buffer)))
4138 (current-buffer)))))
4140 (defun org-export-get-coderef-format (path desc)
4141 (save-match-data
4142 (if (and desc (string-match
4143 (regexp-quote (concat "(" path ")"))
4144 desc))
4145 (replace-match "%s" t t desc)
4146 "%s")))
4149 (defun org-export-html-format-href (s)
4150 "Make sure the S is valid as a href reference in an XHTML document."
4151 (save-match-data
4152 (let ((start 0))
4153 (while (string-match "&" s start)
4154 (setq start (+ (match-beginning 0) 3)
4155 s (replace-match "&amp;" t t s)))))
4158 (defun org-export-html-format-desc (s)
4159 "Make sure the S is valid as a description in a link."
4160 (if (and s (not (get-text-property 1 'org-protected s)))
4161 (save-match-data
4162 (org-html-do-expand s))
4165 (defun org-export-html-format-image (src par-open)
4166 "Create image tag with source and attributes."
4167 (save-match-data
4168 (if (string-match "^ltxpng/" src)
4169 (format "<img src=\"%s\"/>" src)
4170 (let* ((caption (org-find-text-property-in-string 'org-caption src))
4171 (attr (org-find-text-property-in-string 'org-attributes src))
4172 (label (org-find-text-property-in-string 'org-label src)))
4173 (format "%s<div %sclass=\"figure\">
4174 <p><img src=\"%s\"%s /></p>%s
4175 </div>%s"
4176 (if org-par-open "</p>\n" "")
4177 (if label (format "id=\"%s\" " label) "")
4179 (if (string-match "\\<alt=" (or attr ""))
4180 (concat " " attr )
4181 (concat " " attr " alt=\"" src "\""))
4182 (if caption (concat "\n<p>" caption "</p>") "")
4183 (if org-par-open "\n<p>" ""))))))
4185 (defun org-export-html-get-bibliography ()
4186 "Find bibliography, cut it out and return it."
4187 (catch 'exit
4188 (let (beg end (cnt 1))
4189 (save-excursion
4190 (goto-char (point-min))
4191 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
4192 (setq beg (match-beginning 0))
4193 (while (re-search-forward "</?div\\>" nil t)
4194 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
4195 (when (= cnt 0)
4196 (and (looking-at ">") (forward-char 1))
4197 (setq bib (buffer-substring beg (point)))
4198 (delete-region beg (point))
4199 (throw 'exit bib))))
4200 nil))))
4202 (defvar org-table-colgroup-info nil)
4203 (defun org-format-table-ascii (lines)
4204 "Format a table for ascii export."
4205 (if (stringp lines)
4206 (setq lines (org-split-string lines "\n")))
4207 (if (not (string-match "^[ \t]*|" (car lines)))
4208 ;; Table made by table.el - test for spanning
4209 lines
4211 ;; A normal org table
4212 ;; Get rid of hlines at beginning and end
4213 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
4214 (setq lines (nreverse lines))
4215 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
4216 (setq lines (nreverse lines))
4217 (when org-export-table-remove-special-lines
4218 ;; Check if the table has a marking column. If yes remove the
4219 ;; column and the special lines
4220 (setq lines (org-table-clean-before-export lines)))
4221 ;; Get rid of the vertical lines except for grouping
4222 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
4223 rtn line vl1 start)
4224 (while (setq line (pop lines))
4225 (if (string-match org-table-hline-regexp line)
4226 (and (string-match "|\\(.*\\)|" line)
4227 (setq line (replace-match " \\1" t nil line)))
4228 (setq start 0 vl1 vl)
4229 (while (string-match "|" line start)
4230 (setq start (match-end 0))
4231 (or (pop vl1) (setq line (replace-match " " t t line)))))
4232 (push line rtn))
4233 (nreverse rtn))))
4235 (defun org-colgroup-info-to-vline-list (info)
4236 (let (vl new last)
4237 (while info
4238 (setq last new new (pop info))
4239 (if (or (memq last '(:end :startend))
4240 (memq new '(:start :startend)))
4241 (push t vl)
4242 (push nil vl)))
4243 (setq vl (nreverse vl))
4244 (and vl (setcar vl nil))
4245 vl))
4247 (defvar org-table-number-regexp) ; defined in org-table.el
4248 (defun org-format-table-html (lines olines)
4249 "Find out which HTML converter to use and return the HTML code."
4250 (if (stringp lines)
4251 (setq lines (org-split-string lines "\n")))
4252 (if (string-match "^[ \t]*|" (car lines))
4253 ;; A normal org table
4254 (org-format-org-table-html lines)
4255 ;; Table made by table.el - test for spanning
4256 (let* ((hlines (delq nil (mapcar
4257 (lambda (x)
4258 (if (string-match "^[ \t]*\\+-" x) x
4259 nil))
4260 lines)))
4261 (first (car hlines))
4262 (ll (and (string-match "\\S-+" first)
4263 (match-string 0 first)))
4264 (re (concat "^[ \t]*" (regexp-quote ll)))
4265 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
4266 hlines))))
4267 (if (and (not spanning)
4268 (not org-export-prefer-native-exporter-for-tables))
4269 ;; We can use my own converter with HTML conversions
4270 (org-format-table-table-html lines)
4271 ;; Need to use the code generator in table.el, with the original text.
4272 (org-format-table-table-html-using-table-generate-source olines)))))
4274 (defvar org-table-number-fraction) ; defined in org-table.el
4275 (defun org-format-org-table-html (lines &optional splice)
4276 "Format a table into HTML."
4277 (require 'org-table)
4278 ;; Get rid of hlines at beginning and end
4279 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
4280 (setq lines (nreverse lines))
4281 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
4282 (setq lines (nreverse lines))
4283 (when org-export-table-remove-special-lines
4284 ;; Check if the table has a marking column. If yes remove the
4285 ;; column and the special lines
4286 (setq lines (org-table-clean-before-export lines)))
4288 (let ((caption (or (get-text-property 0 'org-caption (car lines))
4289 (get-text-property (or (next-single-property-change
4290 0 'org-caption (car lines))
4292 'org-caption (car lines))))
4293 (head (and org-export-highlight-first-table-line
4294 (delq nil (mapcar
4295 (lambda (x) (string-match "^[ \t]*|-" x))
4296 (cdr lines)))))
4298 (nlines 0) fnum i
4299 tbopen line fields html gr colgropen)
4300 (if splice (setq head nil))
4301 (unless splice (push (if head "<thead>" "<tbody>") html))
4302 (setq tbopen t)
4303 (while (setq line (pop lines))
4304 (catch 'next-line
4305 (if (string-match "^[ \t]*|-" line)
4306 (progn
4307 (unless splice
4308 (push (if head "</thead>" "</tbody>") html)
4309 (if lines (push "<tbody>" html) (setq tbopen nil)))
4310 (setq head nil) ;; head ends here, first time around
4311 ;; ignore this line
4312 (throw 'next-line t)))
4313 ;; Break the line into fields
4314 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
4315 (unless fnum (setq fnum (make-vector (length fields) 0)))
4316 (setq nlines (1+ nlines) i -1)
4317 (push (concat "<tr>"
4318 (mapconcat
4319 (lambda (x)
4320 (setq i (1+ i))
4321 (if (and (< i nlines)
4322 (string-match org-table-number-regexp x))
4323 (incf (aref fnum i)))
4324 (if head
4325 (concat (car org-export-table-header-tags) x
4326 (cdr org-export-table-header-tags))
4327 (concat (car org-export-table-data-tags) x
4328 (cdr org-export-table-data-tags))))
4329 fields "")
4330 "</tr>")
4331 html)))
4332 (unless splice (if tbopen (push "</tbody>" html)))
4333 (unless splice (push "</table>\n" html))
4334 (setq html (nreverse html))
4335 (unless splice
4336 ;; Put in col tags with the alignment (unfortunately often ignored...)
4337 (push (mapconcat
4338 (lambda (x)
4339 (setq gr (pop org-table-colgroup-info))
4340 (format "%s<col align=\"%s\"></col>%s"
4341 (if (memq gr '(:start :startend))
4342 (prog1
4343 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
4344 (setq colgropen t))
4346 (if (> (/ (float x) nlines) org-table-number-fraction)
4347 "right" "left")
4348 (if (memq gr '(:end :startend))
4349 (progn (setq colgropen nil) "</colgroup>")
4350 "")))
4351 fnum "")
4352 html)
4353 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
4354 (if caption (push (format "<caption>%s</caption>" caption) html))
4355 (push html-table-tag html))
4356 (concat (mapconcat 'identity html "\n") "\n")))
4358 (defun org-table-clean-before-export (lines &optional maybe-quoted)
4359 "Check if the table has a marking column.
4360 If yes remove the column and the special lines."
4361 (setq org-table-colgroup-info nil)
4362 (if (memq nil
4363 (mapcar
4364 (lambda (x) (or (string-match "^[ \t]*|-" x)
4365 (string-match
4366 (if maybe-quoted
4367 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
4368 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
4369 x)))
4370 lines))
4371 (progn
4372 (setq org-table-clean-did-remove-column nil)
4373 (delq nil
4374 (mapcar
4375 (lambda (x)
4376 (cond
4377 ((string-match "^[ \t]*| */ *|" x)
4378 (setq org-table-colgroup-info
4379 (mapcar (lambda (x)
4380 (cond ((member x '("<" "&lt;")) :start)
4381 ((member x '(">" "&gt;")) :end)
4382 ((member x '("<>" "&lt;&gt;")) :startend)
4383 (t nil)))
4384 (org-split-string x "[ \t]*|[ \t]*")))
4385 nil)
4386 (t x)))
4387 lines)))
4388 (setq org-table-clean-did-remove-column t)
4389 (delq nil
4390 (mapcar
4391 (lambda (x)
4392 (cond
4393 ((string-match "^[ \t]*| */ *|" x)
4394 (setq org-table-colgroup-info
4395 (mapcar (lambda (x)
4396 (cond ((member x '("<" "&lt;")) :start)
4397 ((member x '(">" "&gt;")) :end)
4398 ((member x '("<>" "&lt;&gt;")) :startend)
4399 (t nil)))
4400 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
4401 nil)
4402 ((string-match "^[ \t]*| *[!_^/] *|" x)
4403 nil) ; ignore this line
4404 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
4405 (string-match "^\\([ \t]*\\)|[^|]*|" x))
4406 ;; remove the first column
4407 (replace-match "\\1|" t nil x))))
4408 lines))))
4410 (defun org-format-table-table-html (lines)
4411 "Format a table generated by table.el into HTML.
4412 This conversion does *not* use `table-generate-source' from table.el.
4413 This has the advantage that Org-mode's HTML conversions can be used.
4414 But it has the disadvantage, that no cell- or row-spanning is allowed."
4415 (let (line field-buffer
4416 (head org-export-highlight-first-table-line)
4417 fields html empty)
4418 (setq html (concat html-table-tag "\n"))
4419 (while (setq line (pop lines))
4420 (setq empty "&nbsp;")
4421 (catch 'next-line
4422 (if (string-match "^[ \t]*\\+-" line)
4423 (progn
4424 (if field-buffer
4425 (progn
4426 (setq
4427 html
4428 (concat
4429 html
4430 "<tr>"
4431 (mapconcat
4432 (lambda (x)
4433 (if (equal x "") (setq x empty))
4434 (if head
4435 (concat (car org-export-table-header-tags) x
4436 (cdr org-export-table-header-tags))
4437 (concat (car org-export-table-data-tags) x
4438 (cdr org-export-table-data-tags))))
4439 field-buffer "\n")
4440 "</tr>\n"))
4441 (setq head nil)
4442 (setq field-buffer nil)))
4443 ;; Ignore this line
4444 (throw 'next-line t)))
4445 ;; Break the line into fields and store the fields
4446 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
4447 (if field-buffer
4448 (setq field-buffer (mapcar
4449 (lambda (x)
4450 (concat x "<br/>" (pop fields)))
4451 field-buffer))
4452 (setq field-buffer fields))))
4453 (setq html (concat html "</table>\n"))
4454 html))
4456 (defun org-format-table-table-html-using-table-generate-source (lines)
4457 "Format a table into html, using `table-generate-source' from table.el.
4458 This has the advantage that cell- or row-spanning is allowed.
4459 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4460 (require 'table)
4461 (with-current-buffer (get-buffer-create " org-tmp1 ")
4462 (erase-buffer)
4463 (insert (mapconcat 'identity lines "\n"))
4464 (goto-char (point-min))
4465 (if (not (re-search-forward "|[^+]" nil t))
4466 (error "Error processing table"))
4467 (table-recognize-table)
4468 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4469 (table-generate-source 'html " org-tmp2 ")
4470 (set-buffer " org-tmp2 ")
4471 (buffer-substring (point-min) (point-max))))
4473 (defun org-export-splice-style (style extra)
4474 "Splice EXTRA into STYLE, just before \"</style>\"."
4475 (if (and (stringp extra)
4476 (string-match "\\S-" extra)
4477 (string-match "</style>" style))
4478 (concat (substring style 0 (match-beginning 0))
4479 "\n" extra "\n"
4480 (substring style (match-beginning 0)))
4481 style))
4483 (defun org-html-handle-time-stamps (s)
4484 "Format time stamps in string S, or remove them."
4485 (catch 'exit
4486 (let (r b)
4487 (while (string-match org-maybe-keyword-time-regexp s)
4488 (or b (setq b (substring s 0 (match-beginning 0))))
4489 (setq r (concat
4490 r (substring s 0 (match-beginning 0))
4491 (if (match-end 1)
4492 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4493 (match-string 1 s)))
4494 (format " @<span class=\"timestamp\">%s@</span>"
4495 (substring
4496 (org-translate-time (match-string 3 s)) 1 -1)))
4497 s (substring s (match-end 0))))
4498 ;; Line break if line started and ended with time stamp stuff
4499 (if (not r)
4501 (setq r (concat r s))
4502 (unless (string-match "\\S-" (concat b s))
4503 (setq r (concat r "@<br/>")))
4504 r))))
4506 (defun org-export-htmlize-region-for-paste (beg end)
4507 "Convert the region to HTML, using htmlize.el.
4508 This is much like `htmlize-region-for-paste', only that it uses
4509 the settings define in the org-... variables."
4510 (let* ((htmlize-output-type org-export-htmlize-output-type)
4511 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
4512 (htmlbuf (htmlize-region beg end)))
4513 (unwind-protect
4514 (with-current-buffer htmlbuf
4515 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
4516 (plist-get htmlize-buffer-places 'content-end)))
4517 (kill-buffer htmlbuf))))
4519 ;;;###autoload
4520 (defun org-export-htmlize-generate-css ()
4521 "Create the CSS for all font definitions in the current Emacs session.
4522 Use this to create face definitions in your CSS style file that can then
4523 be used by code snippets transformed by htmlize.
4524 This command just produces a buffer that contains class definitions for all
4525 faces used in the current Emacs session. You can copy and paste the ones you
4526 need into your CSS file.
4528 If you then set `org-export-htmlize-output-type' to `css', calls to
4529 the function `org-export-htmlize-region-for-paste' will produce code
4530 that uses these same face definitions."
4531 (interactive)
4532 (require 'htmlize)
4533 (and (get-buffer "*html*") (kill-buffer "*html*"))
4534 (with-temp-buffer
4535 (let ((fl (face-list))
4536 (htmlize-css-name-prefix "org-")
4537 (htmlize-output-type 'css)
4538 f i)
4539 (while (setq f (pop fl)
4540 i (and f (face-attribute f :inherit)))
4541 (when (and (symbolp f) (or (not i) (not (listp i))))
4542 (insert (org-add-props (copy-sequence "1") nil 'face f))))
4543 (htmlize-region (point-min) (point-max))))
4544 (switch-to-buffer "*html*")
4545 (goto-char (point-min))
4546 (if (re-search-forward "<style" nil t)
4547 (delete-region (point-min) (match-beginning 0)))
4548 (if (re-search-forward "</style>" nil t)
4549 (delete-region (1+ (match-end 0)) (point-max)))
4550 (beginning-of-line 1)
4551 (if (looking-at " +") (replace-match ""))
4552 (goto-char (point-min)))
4554 (defun org-html-protect (s)
4555 ;; convert & to &amp;, < to &lt; and > to &gt;
4556 (let ((start 0))
4557 (while (string-match "&" s start)
4558 (setq s (replace-match "&amp;" t t s)
4559 start (1+ (match-beginning 0))))
4560 (while (string-match "<" s)
4561 (setq s (replace-match "&lt;" t t s)))
4562 (while (string-match ">" s)
4563 (setq s (replace-match "&gt;" t t s)))
4564 ; (while (string-match "\"" s)
4565 ; (setq s (replace-match "&quot;" t t s)))
4569 (defun org-export-cleanup-toc-line (s)
4570 "Remove tags and timestamps from lines going into the toc."
4571 (when (memq org-export-with-tags '(not-in-toc nil))
4572 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
4573 (setq s (replace-match "" t t s))))
4574 (when org-export-remove-timestamps-from-toc
4575 (while (string-match org-maybe-keyword-time-regexp s)
4576 (setq s (replace-match "" t t s))))
4577 (while (string-match org-bracket-link-regexp s)
4578 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
4579 t t s)))
4582 (defun org-html-expand (string)
4583 "Prepare STRING for HTML export. Applies all active conversions.
4584 If there are links in the string, don't modify these."
4585 (let* ((re (concat org-bracket-link-regexp "\\|"
4586 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4587 m s l res)
4588 (while (setq m (string-match re string))
4589 (setq s (substring string 0 m)
4590 l (match-string 0 string)
4591 string (substring string (match-end 0)))
4592 (push (org-html-do-expand s) res)
4593 (push l res))
4594 (push (org-html-do-expand string) res)
4595 (apply 'concat (nreverse res))))
4597 (defun org-html-do-expand (s)
4598 "Apply all active conversions to translate special ASCII to HTML."
4599 (setq s (org-html-protect s))
4600 (if org-export-html-expand
4601 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
4602 (setq s (replace-match "<\\1>" t nil s))))
4603 (if org-export-with-emphasize
4604 (setq s (org-export-html-convert-emphasize s)))
4605 (if org-export-with-special-strings
4606 (setq s (org-export-html-convert-special-strings s)))
4607 (if org-export-with-sub-superscripts
4608 (setq s (org-export-html-convert-sub-super s)))
4609 (if org-export-with-TeX-macros
4610 (let ((start 0) wd ass)
4611 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4612 s start))
4613 (if (get-text-property (match-beginning 0) 'org-protected s)
4614 (setq start (match-end 0))
4615 (setq wd (match-string 1 s))
4616 (if (setq ass (assoc wd org-html-entities))
4617 (setq s (replace-match (or (cdr ass)
4618 (concat "&" (car ass) ";"))
4619 t t s))
4620 (setq start (+ start (length wd))))))))
4623 (defun org-create-multibrace-regexp (left right n)
4624 "Create a regular expression which will match a balanced sexp.
4625 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4626 as single character strings.
4627 The regexp returned will match the entire expression including the
4628 delimiters. It will also define a single group which contains the
4629 match except for the outermost delimiters. The maximum depth of
4630 stacked delimiters is N. Escaping delimiters is not possible."
4631 (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
4632 (or "\\|")
4633 (re nothing)
4634 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
4635 (while (> n 1)
4636 (setq n (1- n)
4637 re (concat re or next)
4638 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
4639 (concat left "\\(" re "\\)" right)))
4641 (defvar org-match-substring-regexp
4642 (concat
4643 "\\([^\\]\\)\\([_^]\\)\\("
4644 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4645 "\\|"
4646 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
4647 "\\|"
4648 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4649 "The regular expression matching a sub- or superscript.")
4651 (defvar org-match-substring-with-braces-regexp
4652 (concat
4653 "\\([^\\]\\)\\([_^]\\)\\("
4654 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4655 "\\)")
4656 "The regular expression matching a sub- or superscript, forcing braces.")
4658 (defconst org-export-html-special-string-regexps
4659 '(("\\\\-" . "&shy;")
4660 ("---\\([^-]\\)" . "&mdash;\\1")
4661 ("--\\([^-]\\)" . "&ndash;\\1")
4662 ("\\.\\.\\." . "&hellip;"))
4663 "Regular expressions for special string conversion.")
4665 (defun org-export-html-convert-special-strings (string)
4666 "Convert special characters in STRING to HTML."
4667 (let ((all org-export-html-special-string-regexps)
4668 e a re rpl start)
4669 (while (setq a (pop all))
4670 (setq re (car a) rpl (cdr a) start 0)
4671 (while (string-match re string start)
4672 (if (get-text-property (match-beginning 0) 'org-protected string)
4673 (setq start (match-end 0))
4674 (setq string (replace-match rpl t nil string)))))
4675 string))
4677 (defun org-export-html-convert-sub-super (string)
4678 "Convert sub- and superscripts in STRING to HTML."
4679 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
4680 (while (string-match org-match-substring-regexp string s)
4681 (cond
4682 ((and requireb (match-end 8)) (setq s (match-end 2)))
4683 ((get-text-property (match-beginning 2) 'org-protected string)
4684 (setq s (match-end 2)))
4686 (setq s (match-end 1)
4687 key (if (string= (match-string 2 string) "_") "sub" "sup")
4688 c (or (match-string 8 string)
4689 (match-string 6 string)
4690 (match-string 5 string))
4691 string (replace-match
4692 (concat (match-string 1 string)
4693 "<" key ">" c "</" key ">")
4694 t t string)))))
4695 (while (string-match "\\\\\\([_^]\\)" string)
4696 (setq string (replace-match (match-string 1 string) t t string)))
4697 string))
4699 (defun org-export-html-convert-emphasize (string)
4700 "Apply emphasis."
4701 (let ((s 0) rpl)
4702 (while (string-match org-emph-re string s)
4703 (if (not (equal
4704 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4705 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4706 (setq s (match-beginning 0)
4708 (concat
4709 (match-string 1 string)
4710 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4711 (match-string 4 string)
4712 (nth 3 (assoc (match-string 3 string)
4713 org-emphasis-alist))
4714 (match-string 5 string))
4715 string (replace-match rpl t t string)
4716 s (+ s (- (length rpl) 2)))
4717 (setq s (1+ s))))
4718 string))
4720 (defun org-open-par ()
4721 "Insert <p>, but first close previous paragraph if any."
4722 (org-close-par-maybe)
4723 (insert "\n<p>")
4724 (setq org-par-open t))
4725 (defun org-close-par-maybe ()
4726 "Close paragraph if there is one open."
4727 (when org-par-open
4728 (insert "</p>")
4729 (setq org-par-open nil)))
4730 (defun org-close-li (&optional type)
4731 "Close <li> if necessary."
4732 (org-close-par-maybe)
4733 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4735 (defvar body-only) ; dynamically scoped into this.
4736 (defun org-html-level-start (level title umax with-toc head-count)
4737 "Insert a new level in HTML export.
4738 When TITLE is nil, just close all open levels."
4739 (org-close-par-maybe)
4740 (let* ((target (and title (org-get-text-property-any 0 'target title)))
4741 (extra-targets
4742 (mapconcat (lambda (x)
4743 (if (org-uuidgen-p x) (setq x (concat "ID-" x)))
4744 (format "<a name=\"%s\" id=\"%s\"></a>"
4745 x x))
4746 (cdr (assoc target org-export-target-aliases))
4747 ""))
4748 (l org-level-max)
4749 snumber)
4750 (while (>= l level)
4751 (if (aref org-levels-open (1- l))
4752 (progn
4753 (org-html-level-close l umax)
4754 (aset org-levels-open (1- l) nil)))
4755 (setq l (1- l)))
4756 (when title
4757 ;; If title is nil, this means this function is called to close
4758 ;; all levels, so the rest is done only if title is given
4759 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4760 (setq title (replace-match
4761 (if org-export-with-tags
4762 (save-match-data
4763 (concat
4764 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
4765 (mapconcat
4766 (lambda (x)
4767 (format "<span class=\"%s\">%s</span>"
4768 (org-export-html-get-tag-class-name x)
4770 (org-split-string (match-string 1 title) ":")
4771 "&nbsp;")
4772 "</span>"))
4774 t t title)))
4775 (if (> level umax)
4776 (progn
4777 (if (aref org-levels-open (1- level))
4778 (progn
4779 (org-close-li)
4780 (if target
4781 (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
4782 (insert "<li>" title "<br/>\n")))
4783 (aset org-levels-open (1- level) t)
4784 (org-close-par-maybe)
4785 (if target
4786 (insert (format "<ul>\n<li id=\"%s\">" target)
4787 extra-targets title "<br/>\n")
4788 (insert "<ul>\n<li>" title "<br/>\n"))))
4789 (aset org-levels-open (1- level) t)
4790 (setq snumber (org-section-number level))
4791 (setq level (+ level org-export-html-toplevel-hlevel -1))
4792 (if (and org-export-with-section-numbers (not body-only))
4793 (setq title (concat
4794 (format "<span class=\"section-number-%d\">%s</span>"
4795 level snumber)
4796 " " title)))
4797 (unless (= head-count 1) (insert "\n</div>\n"))
4798 (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"
4799 snumber level level snumber extra-targets
4800 title level level snumber))
4801 (org-open-par)))))
4803 (defun org-get-text-property-any (pos prop &optional object)
4804 (or (get-text-property pos prop object)
4805 (and (setq pos (next-single-property-change pos prop object))
4806 (get-text-property pos prop object))))
4808 (defun org-export-html-get-tag-class-name (tag)
4809 "Turn tag into a valid class name.
4810 Replaces invalid characters with \"_\" and then prepends a prefix."
4811 (save-match-data
4812 (while (string-match "[^a-zA-Z0-9_]" tag)
4813 (setq tag (replace-match "_" t t tag))))
4814 (concat org-export-html-tag-class-prefix tag))
4816 (defun org-export-html-get-todo-kwd-class-name (kwd)
4817 "Turn todo keyword into a valid class name.
4818 Replaces invalid characters with \"_\" and then prepends a prefix."
4819 (save-match-data
4820 (while (string-match "[^a-zA-Z0-9_]" kwd)
4821 (setq kwd (replace-match "_" t t kwd))))
4822 (concat org-export-html-todo-kwd-class-prefix kwd))
4824 (defun org-html-level-close (level max-outline-level)
4825 "Terminate one level in HTML export."
4826 (if (<= level max-outline-level)
4827 (insert "</div>\n")
4828 (org-close-li)
4829 (insert "</ul>\n")))
4831 ;;; iCalendar export
4833 ;;;###autoload
4834 (defun org-export-icalendar-this-file ()
4835 "Export current file as an iCalendar file.
4836 The iCalendar file will be located in the same directory as the Org-mode
4837 file, but with extension `.ics'."
4838 (interactive)
4839 (org-export-icalendar nil buffer-file-name))
4841 ;;;###autoload
4842 (defun org-export-icalendar-all-agenda-files ()
4843 "Export all files in `org-agenda-files' to iCalendar .ics files.
4844 Each iCalendar file will be located in the same directory as the Org-mode
4845 file, but with extension `.ics'."
4846 (interactive)
4847 (apply 'org-export-icalendar nil (org-agenda-files t)))
4849 ;;;###autoload
4850 (defun org-export-icalendar-combine-agenda-files ()
4851 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4852 The file is stored under the name `org-combined-agenda-icalendar-file'."
4853 (interactive)
4854 (apply 'org-export-icalendar t (org-agenda-files t)))
4856 (defun org-export-icalendar (combine &rest files)
4857 "Create iCalendar files for all elements of FILES.
4858 If COMBINE is non-nil, combine all calendar entries into a single large
4859 file and store it under the name `org-combined-agenda-icalendar-file'."
4860 (save-excursion
4861 (org-prepare-agenda-buffers files)
4862 (let* ((dir (org-export-directory
4863 :ical (list :publishing-directory
4864 org-export-publishing-directory)))
4865 file ical-file ical-buffer category started org-agenda-new-buffers)
4866 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4867 (when combine
4868 (setq ical-file
4869 (if (file-name-absolute-p org-combined-agenda-icalendar-file)
4870 org-combined-agenda-icalendar-file
4871 (expand-file-name org-combined-agenda-icalendar-file dir))
4872 ical-buffer (org-get-agenda-file-buffer ical-file))
4873 (set-buffer ical-buffer) (erase-buffer))
4874 (while (setq file (pop files))
4875 (catch 'nextfile
4876 (org-check-agenda-file file)
4877 (set-buffer (org-get-agenda-file-buffer file))
4878 (unless combine
4879 (setq ical-file (concat (file-name-as-directory dir)
4880 (file-name-sans-extension
4881 (file-name-nondirectory buffer-file-name))
4882 ".ics"))
4883 (setq ical-buffer (org-get-agenda-file-buffer ical-file))
4884 (with-current-buffer ical-buffer (erase-buffer)))
4885 (setq category (or org-category
4886 (file-name-sans-extension
4887 (file-name-nondirectory buffer-file-name))))
4888 (if (symbolp category) (setq category (symbol-name category)))
4889 (let ((standard-output ical-buffer))
4890 (if combine
4891 (and (not started) (setq started t)
4892 (org-start-icalendar-file org-icalendar-combined-name))
4893 (org-start-icalendar-file category))
4894 (org-print-icalendar-entries combine)
4895 (when (or (and combine (not files)) (not combine))
4896 (org-finish-icalendar-file)
4897 (set-buffer ical-buffer)
4898 (run-hooks 'org-before-save-iCalendar-file-hook)
4899 (save-buffer)
4900 (run-hooks 'org-after-save-iCalendar-file-hook)
4901 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
4902 ))))
4903 (org-release-buffers org-agenda-new-buffers))))
4905 (defvar org-before-save-iCalendar-file-hook nil
4906 "Hook run before an iCalendar file has been saved.
4907 This can be used to modify the result of the export.")
4909 (defvar org-after-save-iCalendar-file-hook nil
4910 "Hook run after an iCalendar file has been saved.
4911 The iCalendar buffer is still current when this hook is run.
4912 A good way to use this is to tell a desktop calendar application to re-read
4913 the iCalendar file.")
4915 (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
4916 (defun org-print-icalendar-entries (&optional combine)
4917 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4918 When COMBINE is non nil, add the category to each line."
4919 (require 'org-agenda)
4920 (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
4921 (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
4922 (dts (org-ical-ts-to-string
4923 (format-time-string (cdr org-time-stamp-formats) (current-time))
4924 "DTSTART"))
4925 hd ts ts2 state status (inc t) pos b sexp rrule
4926 scheduledp deadlinep todo prefix due start
4927 tmp pri categories location summary desc uid
4928 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4929 (org-refresh-category-properties)
4930 (save-excursion
4931 (goto-char (point-min))
4932 (while (re-search-forward re1 nil t)
4933 (catch :skip
4934 (org-agenda-skip)
4935 (when (boundp 'org-icalendar-verify-function)
4936 (unless (funcall org-icalendar-verify-function)
4937 (outline-next-heading)
4938 (backward-char 1)
4939 (throw :skip nil)))
4940 (setq pos (match-beginning 0)
4941 ts (match-string 0)
4942 inc t
4943 hd (condition-case nil
4944 (org-icalendar-cleanup-string
4945 (org-get-heading))
4946 (error (throw :skip nil)))
4947 summary (org-icalendar-cleanup-string
4948 (org-entry-get nil "SUMMARY"))
4949 desc (org-icalendar-cleanup-string
4950 (or (org-entry-get nil "DESCRIPTION")
4951 (and org-icalendar-include-body (org-get-entry)))
4952 t org-icalendar-include-body)
4953 location (org-icalendar-cleanup-string
4954 (org-entry-get nil "LOCATION" 'selective))
4955 uid (if org-icalendar-store-UID
4956 (org-id-get-create)
4957 (or (org-id-get) (org-id-new)))
4958 categories (org-export-get-categories)
4959 deadlinep nil scheduledp nil)
4960 (if (looking-at re2)
4961 (progn
4962 (goto-char (match-end 0))
4963 (setq ts2 (match-string 1)
4964 inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
4965 (setq tmp (buffer-substring (max (point-min)
4966 (- pos org-ds-keyword-length))
4967 pos)
4968 ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
4969 (progn
4970 (setq inc nil)
4971 (replace-match "\\1" t nil ts))
4973 deadlinep (string-match org-deadline-regexp tmp)
4974 scheduledp (string-match org-scheduled-regexp tmp)
4975 todo (org-get-todo-state)
4976 ;; donep (org-entry-is-done-p)
4978 (when (and
4979 deadlinep
4980 (if todo
4981 (not (memq 'event-if-todo org-icalendar-use-deadline))
4982 (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
4983 (throw :skip t))
4984 (when (and
4985 scheduledp
4986 (if todo
4987 (not (memq 'event-if-todo org-icalendar-use-scheduled))
4988 (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
4989 (throw :skip t))
4990 (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
4991 (if (or (string-match org-tr-regexp hd)
4992 (string-match org-ts-regexp hd))
4993 (setq hd (replace-match "" t t hd)))
4994 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
4995 (setq rrule
4996 (concat "\nRRULE:FREQ="
4997 (cdr (assoc
4998 (match-string 2 ts)
4999 '(("d" . "DAILY")("w" . "WEEKLY")
5000 ("m" . "MONTHLY")("y" . "YEARLY"))))
5001 ";INTERVAL=" (match-string 1 ts)))
5002 (setq rrule ""))
5003 (setq summary (or summary hd))
5004 (if (string-match org-bracket-link-regexp summary)
5005 (setq summary
5006 (replace-match (if (match-end 3)
5007 (match-string 3 summary)
5008 (match-string 1 summary))
5009 t t summary)))
5010 (if deadlinep (setq summary (concat "DL: " summary)))
5011 (if scheduledp (setq summary (concat "S: " summary)))
5012 (if (string-match "\\`<%%" ts)
5013 (with-current-buffer sexp-buffer
5014 (insert (substring ts 1 -1) " " summary "\n"))
5015 (princ (format "BEGIN:VEVENT
5016 UID: %s
5018 %s%s
5019 SUMMARY:%s%s%s
5020 CATEGORIES:%s
5021 END:VEVENT\n"
5022 (concat prefix uid)
5023 (org-ical-ts-to-string ts "DTSTART")
5024 (org-ical-ts-to-string ts2 "DTEND" inc)
5025 rrule summary
5026 (if (and desc (string-match "\\S-" desc))
5027 (concat "\nDESCRIPTION: " desc) "")
5028 (if (and location (string-match "\\S-" location))
5029 (concat "\nLOCATION: " location) "")
5030 categories)))))
5031 (when (and org-icalendar-include-sexps
5032 (condition-case nil (require 'icalendar) (error nil))
5033 (fboundp 'icalendar-export-region))
5034 ;; Get all the literal sexps
5035 (goto-char (point-min))
5036 (while (re-search-forward "^&?%%(" nil t)
5037 (catch :skip
5038 (org-agenda-skip)
5039 (setq b (match-beginning 0))
5040 (goto-char (1- (match-end 0)))
5041 (forward-sexp 1)
5042 (end-of-line 1)
5043 (setq sexp (buffer-substring b (point)))
5044 (with-current-buffer sexp-buffer
5045 (insert sexp "\n"))))
5046 (princ (org-diary-to-ical-string sexp-buffer))
5047 (kill-buffer sexp-buffer))
5049 (when org-icalendar-include-todo
5050 (setq prefix "TODO-")
5051 (goto-char (point-min))
5052 (while (re-search-forward org-todo-line-regexp nil t)
5053 (catch :skip
5054 (org-agenda-skip)
5055 (when (boundp 'org-icalendar-verify-function)
5056 (unless (funcall org-icalendar-verify-function)
5057 (outline-next-heading)
5058 (backward-char 1)
5059 (throw :skip nil)))
5060 (setq state (match-string 2))
5061 (setq status (if (member state org-done-keywords)
5062 "COMPLETED" "NEEDS-ACTION"))
5063 (when (and state
5064 (or (not (member state org-done-keywords))
5065 (eq org-icalendar-include-todo 'all))
5066 (not (member org-archive-tag (org-get-tags-at)))
5068 (setq hd (match-string 3)
5069 summary (org-icalendar-cleanup-string
5070 (org-entry-get nil "SUMMARY"))
5071 desc (org-icalendar-cleanup-string
5072 (or (org-entry-get nil "DESCRIPTION")
5073 (and org-icalendar-include-body (org-get-entry)))
5074 t org-icalendar-include-body)
5075 location (org-icalendar-cleanup-string
5076 (org-entry-get nil "LOCATION" 'selective))
5077 due (and (member 'todo-due org-icalendar-use-deadline)
5078 (org-entry-get nil "DEADLINE"))
5079 start (and (member 'todo-start org-icalendar-use-scheduled)
5080 (org-entry-get nil "SCHEDULED"))
5081 categories (org-export-get-categories)
5082 uid (if org-icalendar-store-UID
5083 (org-id-get-create)
5084 (or (org-id-get) (org-id-new))))
5085 (and due (setq due (org-ical-ts-to-string due "DUE")))
5086 (and start (setq start (org-ical-ts-to-string start "DTSTART")))
5088 (if (string-match org-bracket-link-regexp hd)
5089 (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
5090 (match-string 1 hd))
5091 t t hd)))
5092 (if (string-match org-priority-regexp hd)
5093 (setq pri (string-to-char (match-string 2 hd))
5094 hd (concat (substring hd 0 (match-beginning 1))
5095 (substring hd (match-end 1))))
5096 (setq pri org-default-priority))
5097 (setq pri (floor (- 9 (* 8. (/ (float (- org-lowest-priority pri))
5098 (- org-lowest-priority org-highest-priority))))))
5100 (princ (format "BEGIN:VTODO
5101 UID: %s
5103 SUMMARY:%s%s%s%s
5104 CATEGORIES:%s
5105 SEQUENCE:1
5106 PRIORITY:%d
5107 STATUS:%s
5108 END:VTODO\n"
5109 (concat prefix uid)
5110 (or start dts)
5111 (or summary hd)
5112 (if (and location (string-match "\\S-" location))
5113 (concat "\nLOCATION: " location) "")
5114 (if (and desc (string-match "\\S-" desc))
5115 (concat "\nDESCRIPTION: " desc) "")
5116 (if due (concat "\n" due) "")
5117 categories
5118 pri status)))))))))
5120 (defun org-export-get-categories ()
5121 "Get categories according to `org-icalendar-categories'."
5122 (let ((cs org-icalendar-categories) c rtn tmp)
5123 (while (setq c (pop cs))
5124 (cond
5125 ((eq c 'category) (push (org-get-category) rtn))
5126 ((eq c 'todo-state)
5127 (setq tmp (org-get-todo-state))
5128 (and tmp (push tmp rtn)))
5129 ((eq c 'local-tags)
5130 (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
5131 ((eq c 'all-tags)
5132 (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
5133 (mapconcat 'identity (nreverse rtn) ",")))
5135 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
5136 "Take out stuff and quote what needs to be quoted.
5137 When IS-BODY is non-nil, assume that this is the body of an item, clean up
5138 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
5139 characters."
5140 (if (not s)
5142 (when is-body
5143 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
5144 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
5145 (while (string-match re s) (setq s (replace-match "" t t s)))
5146 (while (string-match re2 s) (setq s (replace-match "" t t s)))))
5147 (let ((start 0))
5148 (while (string-match "\\([,;]\\)" s start)
5149 (setq start (+ (match-beginning 0) 2)
5150 s (replace-match "\\\\\\1" nil nil s))))
5151 (setq s (org-trim s))
5152 (when is-body
5153 (while (string-match "[ \t]*\n[ \t]*" s)
5154 (setq s (replace-match "\\n" t t s))))
5155 (if is-body
5156 (if maxlength
5157 (if (and (numberp maxlength)
5158 (> (length s) maxlength))
5159 (setq s (substring s 0 maxlength)))))
5162 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength)
5163 "Take out stuff and quote what needs to be quoted.
5164 When IS-BODY is non-nil, assume that this is the body of an item, clean up
5165 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
5166 characters.
5167 This seems to be more like RFC 2455, but it causes problems, so it is
5168 not used right now."
5169 (if (not s)
5171 (if is-body
5172 (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
5173 (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
5174 (while (string-match re s) (setq s (replace-match "" t t s)))
5175 (while (string-match re2 s) (setq s (replace-match "" t t s)))
5176 (setq s (org-trim s))
5177 (while (string-match "[ \t]*\n[ \t]*" s)
5178 (setq s (replace-match "\\n" t t s)))
5179 (if maxlength
5180 (if (and (numberp maxlength)
5181 (> (length s) maxlength))
5182 (setq s (substring s 0 maxlength)))))
5183 (setq s (org-trim s)))
5184 (while (string-match "\"" s) (setq s (replace-match "''" t t s)))
5185 (when (string-match "[;,:]" s) (setq s (concat "\"" s "\"")))
5188 (defun org-get-entry ()
5189 "Clean-up description string."
5190 (save-excursion
5191 (org-back-to-heading t)
5192 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
5194 (defun org-start-icalendar-file (name)
5195 "Start an iCalendar file by inserting the header."
5196 (let ((user user-full-name)
5197 (name (or name "unknown"))
5198 (timezone (cadr (current-time-zone))))
5199 (princ
5200 (format "BEGIN:VCALENDAR
5201 VERSION:2.0
5202 X-WR-CALNAME:%s
5203 PRODID:-//%s//Emacs with Org-mode//EN
5204 X-WR-TIMEZONE:%s
5205 CALSCALE:GREGORIAN\n" name user timezone))))
5207 (defun org-finish-icalendar-file ()
5208 "Finish an iCalendar file by inserting the END statement."
5209 (princ "END:VCALENDAR\n"))
5211 (defun org-ical-ts-to-string (s keyword &optional inc)
5212 "Take a time string S and convert it to iCalendar format.
5213 KEYWORD is added in front, to make a complete line like DTSTART....
5214 When INC is non-nil, increase the hour by two (if time string contains
5215 a time), or the day by one (if it does not contain a time)."
5216 (let ((t1 (org-parse-time-string s 'nodefault))
5217 t2 fmt have-time time)
5218 (if (and (car t1) (nth 1 t1) (nth 2 t1))
5219 (setq t2 t1 have-time t)
5220 (setq t2 (org-parse-time-string s)))
5221 (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
5222 (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
5223 (when inc
5224 (if have-time
5225 (if org-agenda-default-appointment-duration
5226 (setq mi (+ org-agenda-default-appointment-duration mi))
5227 (setq h (+ 2 h)))
5228 (setq d (1+ d))))
5229 (setq time (encode-time s mi h d m y)))
5230 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
5231 (concat keyword (format-time-string fmt time))))
5233 ;;; XOXO export
5235 (defun org-export-as-xoxo-insert-into (buffer &rest output)
5236 (with-current-buffer buffer
5237 (apply 'insert output)))
5238 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
5240 ;;;###autoload
5241 (defun org-export-as-xoxo (&optional buffer)
5242 "Export the org buffer as XOXO.
5243 The XOXO buffer is named *xoxo-<source buffer name>*"
5244 (interactive (list (current-buffer)))
5245 ;; A quickie abstraction
5247 ;; Output everything as XOXO
5248 (with-current-buffer (get-buffer buffer)
5249 (let* ((pos (point))
5250 (opt-plist (org-combine-plists (org-default-export-plist)
5251 (org-infile-export-plist)))
5252 (filename (concat (file-name-as-directory
5253 (org-export-directory :xoxo opt-plist))
5254 (file-name-sans-extension
5255 (file-name-nondirectory buffer-file-name))
5256 ".html"))
5257 (out (find-file-noselect filename))
5258 (last-level 1)
5259 (hanging-li nil))
5260 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
5261 ;; Check the output buffer is empty.
5262 (with-current-buffer out (erase-buffer))
5263 ;; Kick off the output
5264 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
5265 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
5266 (let* ((hd (match-string-no-properties 1))
5267 (level (length hd))
5268 (text (concat
5269 (match-string-no-properties 2)
5270 (save-excursion
5271 (goto-char (match-end 0))
5272 (let ((str ""))
5273 (catch 'loop
5274 (while 't
5275 (forward-line)
5276 (if (looking-at "^[ \t]\\(.*\\)")
5277 (setq str (concat str (match-string-no-properties 1)))
5278 (throw 'loop str)))))))))
5280 ;; Handle level rendering
5281 (cond
5282 ((> level last-level)
5283 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
5285 ((< level last-level)
5286 (dotimes (- (- last-level level) 1)
5287 (if hanging-li
5288 (org-export-as-xoxo-insert-into out "</li>\n"))
5289 (org-export-as-xoxo-insert-into out "</ol>\n"))
5290 (when hanging-li
5291 (org-export-as-xoxo-insert-into out "</li>\n")
5292 (setq hanging-li nil)))
5294 ((equal level last-level)
5295 (if hanging-li
5296 (org-export-as-xoxo-insert-into out "</li>\n")))
5299 (setq last-level level)
5301 ;; And output the new li
5302 (setq hanging-li 't)
5303 (if (equal ?+ (elt text 0))
5304 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
5305 (org-export-as-xoxo-insert-into out "<li>" text))))
5307 ;; Finally finish off the ol
5308 (dotimes (- last-level 1)
5309 (if hanging-li
5310 (org-export-as-xoxo-insert-into out "</li>\n"))
5311 (org-export-as-xoxo-insert-into out "</ol>\n"))
5313 (goto-char pos)
5314 ;; Finish the buffer off and clean it up.
5315 (switch-to-buffer-other-window out)
5316 (indent-region (point-min) (point-max) nil)
5317 (save-buffer)
5318 (goto-char (point-min))
5321 (provide 'org-exp)
5323 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
5325 ;;; org-exp.el ends here