Declare a function.
[org-mode.git] / lisp / org-exp.el
blob93d5b3c83198e57a4e02be2f7d7c08b27d57a6a4
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.27trans
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-latex" (parameters))
35 (declare-function org-export-ascii-preprocess "org-ascii" (parameters))
36 (declare-function org-export-html-preprocess "org-html" (parameters))
37 (declare-function org-export-docbook-preprocess "org-docbook" (parameters))
38 (declare-function org-agenda-skip "org-agenda" ())
39 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
40 (declare-function org-export-htmlize-region-for-paste "org-html" (beg end))
41 (declare-function htmlize-buffer "htmlize" (&optional buffer))
43 (defgroup org-export nil
44 "Options for exporting org-listings."
45 :tag "Org Export"
46 :group 'org)
48 (defgroup org-export-general nil
49 "General options for exporting Org-mode files."
50 :tag "Org Export General"
51 :group 'org-export)
53 ;; FIXME
54 (defvar org-export-publishing-directory nil)
56 (defcustom org-export-show-temporary-export-buffer t
57 "Non-nil means, show buffer after exporting to temp buffer.
58 When Org exports to a file, the buffer visiting that file is ever
59 shown, but remains buried. However, when exporting to a temporary
60 buffer, that buffer is popped up in a second window. When this variable
61 is nil, the buffer remains buried also in these cases."
62 :group 'org-export-general
63 :type 'boolean)
65 (defcustom org-export-copy-to-kill-ring t
66 "Non-nil means, exported stuff will also be pushed onto the kill ring."
67 :group 'org-export-general
68 :type 'boolean)
70 (defcustom org-export-run-in-background nil
71 "Non-nil means export and publishing commands will run in background.
72 This works by starting up a separate Emacs process visiting the same file
73 and doing the export from there.
74 Not all export commands are affected by this - only the ones which
75 actually write to a file, and that do not depend on the buffer state.
77 If this option is nil, you can still get background export by calling
78 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
80 If this option is t, the double prefix can be used to exceptionally
81 force an export command into the current process."
82 :group 'org-export-general
83 :type 'boolean)
85 (defcustom org-export-select-tags '("export")
86 "Tags that select a tree for export.
87 If any such tag is found in a buffer, all trees that do not carry one
88 of these tags will be deleted before export.
89 Inside trees that are selected like this, you can still deselect a
90 subtree by tagging it with one of the `org-export-exclude-tags'."
91 :group 'org-export-general
92 :type '(repeat (string :tag "Tag")))
94 (defcustom org-export-exclude-tags '("noexport")
95 "Tags that exclude a tree from export.
96 All trees carrying any of these tags will be excluded from export.
97 This is without condition, so even subtrees inside that carry one of the
98 `org-export-select-tags' will be removed."
99 :group 'org-export-general
100 :type '(repeat (string :tag "Tag")))
102 ;; FIXME: rename, this is a general variable
103 (defcustom org-export-html-expand t
104 "Non-nil means, for HTML export, treat @<...> as HTML tag.
105 When nil, these tags will be exported as plain text and therefore
106 not be interpreted by a browser.
108 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
109 :group 'org-export-html
110 :group 'org-export-general
111 :type 'boolean)
113 (defcustom org-export-with-special-strings t
114 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
115 When this option is turned on, these strings will be exported as:
117 Org HTML LaTeX
118 -----+----------+--------
119 \\- &shy; \\-
120 -- &ndash; --
121 --- &mdash; ---
122 ... &hellip; \ldots
124 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
125 :group 'org-export-translation
126 :type 'boolean)
128 (defcustom org-export-html-link-up ""
129 "Where should the \"UP\" link of exported HTML pages lead?"
130 :group 'org-export-html
131 :group 'org-export-general
132 :type '(string :tag "File or URL"))
134 (defcustom org-export-html-link-home ""
135 "Where should the \"HOME\" link of exported HTML pages lead?"
136 :group 'org-export-html
137 :group 'org-export-general
138 :type '(string :tag "File or URL"))
140 (defcustom org-export-language-setup
141 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
142 ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
143 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
144 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
145 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
146 ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
147 ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
148 ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
149 ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
150 ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
151 ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
152 ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
153 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
154 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
155 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
156 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
157 ("pl" "Autor" "Data" "Spis tre&sacute;ci" "Przypis")
158 ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
159 "Terms used in export text, translated to different languages.
160 Use the variable `org-export-default-language' to set the language,
161 or use the +OPTION lines for a per-file setting."
162 :group 'org-export-general
163 :type '(repeat
164 (list
165 (string :tag "HTML language tag")
166 (string :tag "Author")
167 (string :tag "Date")
168 (string :tag "Table of Contents")
169 (string :tag "Footnotes"))))
171 (defcustom org-export-default-language "en"
172 "The default language of HTML export, as a string.
173 This should have an association in `org-export-language-setup'."
174 :group 'org-export-general
175 :type 'string)
177 (defvar org-export-page-description ""
178 "The page description, for the XHTML meta tag.
179 This is best set with the #+DESCRIPTION line in a file, it does not make
180 sense to set this globally.")
182 (defvar org-export-page-keywords ""
183 "The page description, for the XHTML meta tag.
184 This is best set with the #+KEYWORDS line in a file, it does not make
185 sense to set this globally.")
187 (defcustom org-export-skip-text-before-1st-heading nil
188 "Non-nil means, skip all text before the first headline when exporting.
189 When nil, that text is exported as well."
190 :group 'org-export-general
191 :type 'boolean)
193 (defcustom org-export-headline-levels 3
194 "The last level which is still exported as a headline.
195 Inferior levels will produce itemize lists when exported.
196 Note that a numeric prefix argument to an exporter function overrides
197 this setting.
199 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
200 :group 'org-export-general
201 :type 'integer)
203 (defcustom org-export-with-section-numbers t
204 "Non-nil means, add section numbers to headlines when exporting.
206 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
207 :group 'org-export-general
208 :type 'boolean)
210 (defcustom org-export-section-number-format '((("1" ".")) . "")
211 "Format of section numbers for export.
212 The variable has two components.
213 1. A list of lists, each indicating a counter type and a separator.
214 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
215 It causes causes numeric, alphabetic, or roman counters, respectively.
216 The separator is only used if another counter for a subsection is being
217 added.
218 If there are more numbered section levels than entries in this lists,
219 then the last entry will be reused.
220 2. A terminator string that will be added after the entire
221 section number."
222 :group 'org-export-general
223 :type '(cons
224 (repeat
225 (list
226 (string :tag "Counter Type")
227 (string :tag "Separator ")))
228 (string :tag "Terminator")))
230 (defcustom org-export-with-toc t
231 "Non-nil means, create a table of contents in exported files.
232 The TOC contains headlines with levels up to`org-export-headline-levels'.
233 When an integer, include levels up to N in the toc, this may then be
234 different from `org-export-headline-levels', but it will not be allowed
235 to be larger than the number of headline levels.
236 When nil, no table of contents is made.
238 Headlines which contain any TODO items will be marked with \"(*)\" in
239 ASCII export, and with red color in HTML output, if the option
240 `org-export-mark-todo-in-toc' is set.
242 In HTML output, the TOC will be clickable.
244 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
245 or \"toc:3\"."
246 :group 'org-export-general
247 :type '(choice
248 (const :tag "No Table of Contents" nil)
249 (const :tag "Full Table of Contents" t)
250 (integer :tag "TOC to level")))
252 (defcustom org-export-mark-todo-in-toc nil
253 "Non-nil means, mark TOC lines that contain any open TODO items."
254 :group 'org-export-general
255 :type 'boolean)
257 (defcustom org-export-with-todo-keywords t
258 "Non-nil means, include TODO keywords in export.
259 When nil, remove all these keywords from the export."
260 :group 'org-export-general
261 :type 'boolean)
263 (defcustom org-export-with-priority nil
264 "Non-nil means, include priority cookies in export.
265 When nil, remove priority cookies for export."
266 :group 'org-export-general
267 :type 'boolean)
269 (defcustom org-export-preserve-breaks nil
270 "Non-nil means, preserve all line breaks when exporting.
271 Normally, in HTML output paragraphs will be reformatted. In ASCII
272 export, line breaks will always be preserved, regardless of this variable.
274 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
275 :group 'org-export-general
276 :type 'boolean)
278 (defcustom org-export-with-archived-trees 'headline
279 "Whether subtrees with the ARCHIVE tag should be exported.
280 This can have three different values
281 nil Do not export, pretend this tree is not present
282 t Do export the entire tree
283 headline Only export the headline, but skip the tree below it."
284 :group 'org-export-general
285 :group 'org-archive
286 :type '(choice
287 (const :tag "not at all" nil)
288 (const :tag "headline only" 'headline)
289 (const :tag "entirely" t)))
291 (defcustom org-export-author-info t
292 "Non-nil means, insert author name and email into the exported file.
294 This option can also be set with the +OPTIONS line,
295 e.g. \"author-info:nil\"."
296 :group 'org-export-general
297 :type 'boolean)
299 (defcustom org-export-creator-info t
300 "Non-nil means, the postamble should contain a creator sentence.
301 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
302 :group 'org-export-general
303 :type 'boolean)
305 (defcustom org-export-time-stamp-file t
306 "Non-nil means, insert a time stamp into the exported file.
307 The time stamp shows when the file was created.
309 This option can also be set with the +OPTIONS line,
310 e.g. \"timestamp:nil\"."
311 :group 'org-export-general
312 :type 'boolean)
314 (defcustom org-export-with-timestamps t
315 "If nil, do not export time stamps and associated keywords."
316 :group 'org-export-general
317 :type 'boolean)
319 (defcustom org-export-remove-timestamps-from-toc t
320 "If nil, remove timestamps from the table of contents entries."
321 :group 'org-export-general
322 :type 'boolean)
324 (defcustom org-export-with-tags 'not-in-toc
325 "If nil, do not export tags, just remove them from headlines.
326 If this is the symbol `not-in-toc', tags will be removed from table of
327 contents entries, but still be shown in the headlines of the document.
329 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
330 :group 'org-export-general
331 :type '(choice
332 (const :tag "Off" nil)
333 (const :tag "Not in TOC" not-in-toc)
334 (const :tag "On" t)))
336 (defcustom org-export-with-drawers nil
337 "Non-nil means, export with drawers like the property drawer.
338 When t, all drawers are exported. This may also be a list of
339 drawer names to export."
340 :group 'org-export-general
341 :type '(choice
342 (const :tag "All drawers" t)
343 (const :tag "None" nil)
344 (repeat :tag "Selected drawers"
345 (string :tag "Drawer name"))))
347 (defvar org-export-preprocess-hook nil
348 "Hook for preprocessing an export buffer.
349 Pretty much the first thing when exporting is running this hook.")
351 (defvar org-export-preprocess-after-include-files-hook nil
352 "Hook for preprocessing an export buffer.
353 This is run after the contents of included files have been inserted.")
355 (defvar org-export-preprocess-after-tree-selection-hook nil
356 "Hook for preprocessing an export buffer.
357 This is run after selection of trees to be exported has happened.
358 This selection includes tags-based selection, as well as removal
359 of commented and archived trees.")
361 (defvar org-export-preprocess-after-blockquote-hook nil
362 "Hook for preprocessing an export buffer.
363 This is run after blockquote/quote/verse/center have been marked
364 with cookies.")
366 (defvar org-export-preprocess-before-backend-specifics-hook nil
367 "Hook run before backend-specific functions are called during preprocessing.")
369 (defvar org-export-preprocess-final-hook nil
370 "Hook for preprocessing an export buffer.
371 This is run as the last thing in the preprocessing buffer, just before
372 returning the buffer string to the backend.")
374 (defgroup org-export-translation nil
375 "Options for translating special ascii sequences for the export backends."
376 :tag "Org Export Translation"
377 :group 'org-export)
379 (defcustom org-export-with-emphasize t
380 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
381 If the export target supports emphasizing text, the word will be
382 typeset in bold, italic, or underlined, respectively. Works only for
383 single words, but you can say: I *really* *mean* *this*.
384 Not all export backends support this.
386 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
387 :group 'org-export-translation
388 :type 'boolean)
390 (defcustom org-export-with-footnotes t
391 "If nil, export [1] as a footnote marker.
392 Lines starting with [1] will be formatted as footnotes.
394 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
395 :group 'org-export-translation
396 :type 'boolean)
398 (defcustom org-export-with-sub-superscripts t
399 "Non-nil means, interpret \"_\" and \"^\" for export.
400 When this option is turned on, you can use TeX-like syntax for sub- and
401 superscripts. Several characters after \"_\" or \"^\" will be
402 considered as a single item - so grouping with {} is normally not
403 needed. For example, the following things will be parsed as single
404 sub- or superscripts.
406 10^24 or 10^tau several digits will be considered 1 item.
407 10^-12 or 10^-tau a leading sign with digits or a word
408 x^2-y^3 will be read as x^2 - y^3, because items are
409 terminated by almost any nonword/nondigit char.
410 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
412 Still, ambiguity is possible - so when in doubt use {} to enclose the
413 sub/superscript. If you set this variable to the symbol `{}',
414 the braces are *required* in order to trigger interpretations as
415 sub/superscript. This can be helpful in documents that need \"_\"
416 frequently in plain text.
418 Not all export backends support this, but HTML does.
420 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
421 :group 'org-export-translation
422 :type '(choice
423 (const :tag "Always interpret" t)
424 (const :tag "Only with braces" {})
425 (const :tag "Never interpret" nil)))
427 (defcustom org-export-with-TeX-macros t
428 "Non-nil means, interpret simple TeX-like macros when exporting.
429 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
430 Not only real TeX macros will work here, but the standard HTML entities
431 for math can be used as macro names as well. For a list of supported
432 names in HTML export, see the constant `org-html-entities'.
433 Not all export backends support this.
435 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
436 :group 'org-export-translation
437 :group 'org-export-latex
438 :type 'boolean)
440 (defcustom org-export-with-LaTeX-fragments nil
441 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
442 When set, the exporter will find LaTeX environments if the \\begin line is
443 the first non-white thing on a line. It will also find the math delimiters
444 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
445 display math.
447 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
449 The default is nil, because this option needs the `dvipng' program which
450 is not available on all systems."
451 :group 'org-export-translation
452 :group 'org-export-latex
453 :type 'boolean)
455 (defcustom org-export-with-fixed-width t
456 "Non-nil means, lines starting with \":\" will be in fixed width font.
457 This can be used to have pre-formatted text, fragments of code etc. For
458 example:
459 : ;; Some Lisp examples
460 : (while (defc cnt)
461 : (ding))
462 will be looking just like this in also HTML. See also the QUOTE keyword.
463 Not all export backends support this.
465 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
466 :group 'org-export-translation
467 :type 'boolean)
469 (defcustom org-match-sexp-depth 3
470 "Number of stacked braces for sub/superscript matching.
471 This has to be set before loading org.el to be effective."
472 :group 'org-export-translation
473 :type 'integer)
475 (defgroup org-export-tables nil
476 "Options for exporting tables in Org-mode."
477 :tag "Org Export Tables"
478 :group 'org-export)
480 (defcustom org-export-with-tables t
481 "If non-nil, lines starting with \"|\" define a table.
482 For example:
484 | Name | Address | Birthday |
485 |-------------+----------+-----------|
486 | Arthur Dent | England | 29.2.2100 |
488 Not all export backends support this.
490 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
491 :group 'org-export-tables
492 :type 'boolean)
494 (defcustom org-export-highlight-first-table-line t
495 "Non-nil means, highlight the first table line.
496 In HTML export, this means use <th> instead of <td>.
497 In tables created with table.el, this applies to the first table line.
498 In Org-mode tables, all lines before the first horizontal separator
499 line will be formatted with <th> tags."
500 :group 'org-export-tables
501 :type 'boolean)
503 (defcustom org-export-table-remove-special-lines t
504 "Remove special lines and marking characters in calculating tables.
505 This removes the special marking character column from tables that are set
506 up for spreadsheet calculations. It also removes the entire lines
507 marked with `!', `_', or `^'. The lines with `$' are kept, because
508 the values of constants may be useful to have."
509 :group 'org-export-tables
510 :type 'boolean)
512 (defcustom org-export-prefer-native-exporter-for-tables nil
513 "Non-nil means, always export tables created with table.el natively.
514 Natively means, use the HTML code generator in table.el.
515 When nil, Org-mode's own HTML generator is used when possible (i.e. if
516 the table does not use row- or column-spanning). This has the
517 advantage, that the automatic HTML conversions for math symbols and
518 sub/superscripts can be applied. Org-mode's HTML generator is also
519 much faster."
520 :group 'org-export-tables
521 :type 'boolean)
524 (defgroup org-export-xml nil
525 "Options specific for XML export of Org-mode files."
526 :tag "Org Export XML"
527 :group 'org-export)
529 ;;;; Exporting
531 ;;; Variables, constants, and parameter plists
533 (defconst org-level-max 20)
535 (defvar org-current-export-file nil) ; dynamically scoped parameter
536 (defvar org-current-export-dir nil) ; dynamically scoped parameter
537 (defvar org-export-opt-plist nil
538 "Contains the current option plist.")
539 (defvar org-last-level nil) ; dynamically scoped variable
540 (defvar org-min-level nil) ; dynamically scoped variable
541 (defvar org-levels-open nil) ; dynamically scoped parameter
543 (defconst org-export-plist-vars
544 '((:link-up nil org-export-html-link-up)
545 (:link-home nil org-export-html-link-home)
546 (:language nil org-export-default-language)
547 (:keywords nil org-export-page-keywords)
548 (:description nil org-export-page-description)
549 (:customtime nil org-display-custom-times)
550 (:headline-levels "H" org-export-headline-levels)
551 (:section-numbers "num" org-export-with-section-numbers)
552 (:section-number-format nil org-export-section-number-format)
553 (:table-of-contents "toc" org-export-with-toc)
554 (:preserve-breaks "\\n" org-export-preserve-breaks)
555 (:archived-trees nil org-export-with-archived-trees)
556 (:emphasize "*" org-export-with-emphasize)
557 (:sub-superscript "^" org-export-with-sub-superscripts)
558 (:special-strings "-" org-export-with-special-strings)
559 (:footnotes "f" org-export-with-footnotes)
560 (:drawers "d" org-export-with-drawers)
561 (:tags "tags" org-export-with-tags)
562 (:todo-keywords "todo" org-export-with-todo-keywords)
563 (:priority "pri" org-export-with-priority)
564 (:TeX-macros "TeX" org-export-with-TeX-macros)
565 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
566 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
567 (:fixed-width ":" org-export-with-fixed-width)
568 (:timestamps "<" org-export-with-timestamps)
569 (:author-info "author" org-export-author-info)
570 (:creator-info "creator" org-export-creator-info)
571 (:time-stamp-file "timestamp" org-export-time-stamp-file)
572 (:tables "|" org-export-with-tables)
573 (:table-auto-headline nil org-export-highlight-first-table-line)
574 (:style-include-default nil org-export-html-style-include-default)
575 (:style-include-scripts nil org-export-html-style-include-scripts)
576 (:style nil org-export-html-style)
577 (:style-extra nil org-export-html-style-extra)
578 (:agenda-style nil org-agenda-export-html-style)
579 (:convert-org-links nil org-export-html-link-org-files-as-html)
580 (:inline-images nil org-export-html-inline-images)
581 (:html-extension nil org-export-html-extension)
582 (:xml-declaration nil org-export-html-xml-declaration)
583 (:html-table-tag nil org-export-html-table-tag)
584 (:expand-quoted-html "@" org-export-html-expand)
585 (:timestamp nil org-export-html-with-timestamp)
586 (:publishing-directory nil org-export-publishing-directory)
587 (:preamble nil org-export-html-preamble)
588 (:postamble nil org-export-html-postamble)
589 (:auto-preamble nil org-export-html-auto-preamble)
590 (:auto-postamble nil org-export-html-auto-postamble)
591 (:author nil user-full-name)
592 (:email nil user-mail-address)
593 (:select-tags nil org-export-select-tags)
594 (:exclude-tags nil org-export-exclude-tags)
596 (:latex-image-options nil org-export-latex-image-default-option))
597 "List of properties that represent export/publishing variables.
598 Each element is a list of 3 items:
599 1. The property that is used internally, and also for org-publish-project-alist
600 2. The string that can be used in the OPTION lines to set this option,
601 or nil if this option cannot be changed in this way
602 3. The customization variable that sets the default for this option."
605 (defun org-default-export-plist ()
606 "Return the property list with default settings for the export variables."
607 (let ((l org-export-plist-vars) rtn e s v)
608 (while (setq e (pop l))
609 (setq s (nth 2 e)
610 v (if (boundp s) (symbol-value s) nil)
611 rtn (cons (car e) (cons v rtn))))
612 rtn))
614 (defvar org-export-inbuffer-options-extra nil
615 "List of additional in-buffer options that should be detected.
616 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
617 etc. Extensions can add to this list to get their options detected, and they
618 can then add a function to `org-export-options-filters' to process these
619 options.
620 Each element in this list must be a list, with the in-buffer keyword as car,
621 and a property (a symbol) as the next element. All occurrences of the
622 keyword will be found, the values concatenated with a space character
623 in between, and the result stored in the export options property list.")
625 (defvar org-export-options-filters nil
626 "Functions to be called to finalize the export/publishing options.
627 All these options are stored in a property list, and each of the functions
628 in this hook gets a chance to modify this property list. Each function
629 must accept the property list as an argument, and must return the (possibly
630 modified) list.")
632 ;; FIXME: should we fold case here?
633 (defun org-infile-export-plist ()
634 "Return the property list with file-local settings for export."
635 (save-excursion
636 (save-restriction
637 (widen)
638 (goto-char (point-min))
639 (let ((re (org-make-options-regexp
640 (append
641 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
642 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
643 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
644 "KEYWORDS" "DESCRIPTION")
645 (mapcar 'car org-export-inbuffer-options-extra))))
646 p key val text options a pr style
647 latex-header
648 ext-setup-or-nil setup-contents (start 0))
649 (while (or (and ext-setup-or-nil
650 (string-match re ext-setup-or-nil start)
651 (setq start (match-end 0)))
652 (and (setq ext-setup-or-nil nil start 0)
653 (re-search-forward re nil t)))
654 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
655 val (org-match-string-no-properties 2 ext-setup-or-nil))
656 (cond
657 ((setq a (assoc key org-export-inbuffer-options-extra))
658 (setq pr (nth 1 a))
659 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
660 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
661 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
662 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
663 ((string-equal key "DATE") (setq p (plist-put p :date val)))
664 ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
665 ((string-equal key "DESCRIPTION")
666 (setq p (plist-put p :description val)))
667 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
668 ((string-equal key "STYLE")
669 (setq style (concat style "\n" val)))
670 ((string-equal key "LATEX_HEADER")
671 (setq latex-header (concat latex-header "\n" val)))
672 ((string-equal key "TEXT")
673 (setq text (if text (concat text "\n" val) val)))
674 ((string-equal key "OPTIONS")
675 (setq options (concat val " " options)))
676 ((string-equal key "LINK_UP")
677 (setq p (plist-put p :link-up val)))
678 ((string-equal key "LINK_HOME")
679 (setq p (plist-put p :link-home val)))
680 ((string-equal key "EXPORT_SELECT_TAGS")
681 (setq p (plist-put p :select-tags (org-split-string val))))
682 ((string-equal key "EXPORT_EXCLUDE_TAGS")
683 (setq p (plist-put p :exclude-tags (org-split-string val))))
684 ((equal key "SETUPFILE")
685 (setq setup-contents (org-file-contents
686 (expand-file-name
687 (org-remove-double-quotes
688 (org-trim val)))
689 'noerror))
690 (if (not ext-setup-or-nil)
691 (setq ext-setup-or-nil setup-contents start 0)
692 (setq ext-setup-or-nil
693 (concat (substring ext-setup-or-nil 0 start)
694 "\n" setup-contents "\n"
695 (substring ext-setup-or-nil start)))))))
696 (setq p (plist-put p :text text))
697 (when style (setq p (plist-put p :style-extra style)))
698 (when latex-header
699 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
700 (when options
701 (setq p (org-export-add-options-to-plist p options)))
702 ;; Add macro definitions
703 (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
704 (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
705 (setq p (plist-put
706 p :macro-modification-time
707 (and (buffer-file-name)
708 (file-exists-p (buffer-file-name))
709 (concat
710 "(eval (format-time-string \"$1\" '"
711 (prin1-to-string (nth 5 (file-attributes
712 (buffer-file-name))))
713 "))"))))
714 (setq p (plist-put p :macro-input-file (and (buffer-file-name)
715 (file-name-nondirectory
716 (buffer-file-name)))))
717 (goto-char (point-min))
718 (while (re-search-forward
719 "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
720 nil t)
721 (setq p (plist-put p (intern (concat ":macro-"
722 (downcase (match-string 1))))
723 (match-string 2))))
724 p))))
726 (defun org-export-add-options-to-plist (p options)
727 "Parse an OPTIONS line and set values in the property list P."
728 (let (o)
729 (when options
730 (let ((op org-export-plist-vars))
731 (while (setq o (pop op))
732 (if (and (nth 1 o)
733 (string-match (concat (regexp-quote (nth 1 o))
734 ":\\([^ \t\n\r;,.]*\\)")
735 options))
736 (setq p (plist-put p (car o)
737 (car (read-from-string
738 (match-string 1 options))))))))))
741 (defun org-export-add-subtree-options (p pos)
742 "Add options in subtree at position POS to property list P."
743 (save-excursion
744 (goto-char pos)
745 (when (org-at-heading-p)
746 (let (a)
747 ;; This is actually read in `org-export-get-title-from-subtree'
748 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
749 ;; (setq p (plist-put p :title a)))
750 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
751 (setq p (plist-put p :text a)))
752 (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
753 (setq p (plist-put p :author a)))
754 (when (setq a (org-entry-get pos "EXPORT_DATE"))
755 (setq p (plist-put p :date a)))
756 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
757 (setq p (org-export-add-options-to-plist p a)))))
760 (defun org-export-directory (type plist)
761 (let* ((val (plist-get plist :publishing-directory))
762 (dir (if (listp val)
763 (or (cdr (assoc type val)) ".")
764 val)))
765 dir))
767 (defun org-export-process-option-filters (plist)
768 (let ((functions org-export-options-filters) f)
769 (while (setq f (pop functions))
770 (setq plist (funcall f plist))))
771 plist)
773 ;;;###autoload
774 (defun org-export (&optional arg)
775 "Export dispatcher for Org-mode.
776 When `org-export-run-in-background' is non-nil, try to run the command
777 in the background. This will be done only for commands that write
778 to a file. For details see the docstring of `org-export-run-in-background'.
780 The prefix argument ARG will be passed to the exporter. However, if
781 ARG is a double universal prefix `C-u C-u', that means to inverse the
782 value of `org-export-run-in-background'."
783 (interactive "P")
784 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
785 (help "[t] insert the export option template
786 \[v] limit export to visible part of outline tree
788 \[a] export as ASCII [A] to temporary buffer
790 \[h] export as HTML [H] to temporary buffer [R] export region
791 \[b] export as HTML and open in browser
793 \[l] export as LaTeX [L] to temporary buffer
794 \[p] export as LaTeX and process to PDF
795 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
797 \[D] export as DocBook
798 \[V] export as DocBook, process to PDF, and open the resulting PDF document
800 \[x] export as XOXO
802 \[i] export current file as iCalendar file
803 \[I] export all agenda files as iCalendar files
804 \[c] export agenda files into combined iCalendar file
806 \[F] publish current file [P] publish current project
807 \[X] publish a project... [E] publish every projects")
808 (cmds
809 '((?t org-insert-export-options-template nil)
810 (?v org-export-visible nil)
811 (?a org-export-as-ascii t)
812 (?A org-export-as-ascii-to-buffer t)
813 (?h org-export-as-html t)
814 (?b org-export-as-html-and-open t)
815 (?H org-export-as-html-to-buffer nil)
816 (?R org-export-region-as-html nil)
817 (?x org-export-as-xoxo t)
818 (?D org-export-as-docbook t)
819 (?V org-export-as-docbook-pdf-and-open t)
820 (?l org-export-as-latex t)
821 (?p org-export-as-pdf t)
822 (?d org-export-as-pdf-and-open t)
823 (?L org-export-as-latex-to-buffer nil)
824 (?i org-export-icalendar-this-file t)
825 (?I org-export-icalendar-all-agenda-files t)
826 (?c org-export-icalendar-combine-agenda-files t)
827 (?F org-publish-current-file t)
828 (?P org-publish-current-project t)
829 (?X org-publish t)
830 (?E org-publish-all t)))
831 r1 r2 ass)
832 (save-excursion
833 (save-window-excursion
834 (delete-other-windows)
835 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
836 (princ help))
837 (org-fit-window-to-buffer (get-buffer-window
838 "*Org Export/Publishing Help*"))
839 (message "Select command: ")
840 (setq r1 (read-char-exclusive))))
841 (setq r2 (if (< r1 27) (+ r1 96) r1))
842 (unless (setq ass (assq r2 cmds))
843 (error "No command associated with key %c" r1))
844 (if (and bg (nth 2 ass)
845 (not (buffer-base-buffer))
846 (not (org-region-active-p)))
847 ;; execute in background
848 (let ((p (start-process
849 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
850 "*Org Processes*"
851 (expand-file-name invocation-name invocation-directory)
852 "-batch"
853 "-l" user-init-file
854 "--eval" "(require 'org-exp)"
855 "--eval" "(setq org-wait .2)"
856 (buffer-file-name)
857 "-f" (symbol-name (nth 1 ass)))))
858 (set-process-sentinel p 'org-export-process-sentinel)
859 (message "Background process \"%s\": started" p))
860 ;; background processing not requested, or not possible
861 (call-interactively (nth 1 ass)))))
863 (defun org-export-process-sentinel (process status)
864 (if (string-match "\n+\\'" status)
865 (setq status (substring status 0 -1)))
866 (message "Background process \"%s\": %s" process status))
868 (defconst org-html-entities
869 '(("nbsp")
870 ("iexcl")
871 ("cent")
872 ("pound")
873 ("curren")
874 ("yen")
875 ("brvbar")
876 ("vert" . "&#124;")
877 ("sect")
878 ("uml")
879 ("copy")
880 ("ordf")
881 ("laquo")
882 ("not")
883 ("shy")
884 ("reg")
885 ("macr")
886 ("deg")
887 ("pm" . "&plusmn;")
888 ("plusmn")
889 ("sup2")
890 ("sup3")
891 ("acute")
892 ("micro")
893 ("para")
894 ("middot")
895 ("odot"."o")
896 ("star"."*")
897 ("cedil")
898 ("sup1")
899 ("ordm")
900 ("raquo")
901 ("frac14")
902 ("frac12")
903 ("frac34")
904 ("iquest")
905 ("Agrave")
906 ("Aacute")
907 ("Acirc")
908 ("Atilde")
909 ("Auml")
910 ("Aring") ("AA"."&Aring;")
911 ("AElig")
912 ("Ccedil")
913 ("Egrave")
914 ("Eacute")
915 ("Ecirc")
916 ("Euml")
917 ("Igrave")
918 ("Iacute")
919 ("Icirc")
920 ("Iuml")
921 ("ETH")
922 ("Ntilde")
923 ("Ograve")
924 ("Oacute")
925 ("Ocirc")
926 ("Otilde")
927 ("Ouml")
928 ("times")
929 ("Oslash")
930 ("Ugrave")
931 ("Uacute")
932 ("Ucirc")
933 ("Uuml")
934 ("Yacute")
935 ("THORN")
936 ("szlig")
937 ("agrave")
938 ("aacute")
939 ("acirc")
940 ("atilde")
941 ("auml")
942 ("aring")
943 ("aelig")
944 ("ccedil")
945 ("egrave")
946 ("eacute")
947 ("ecirc")
948 ("euml")
949 ("igrave")
950 ("iacute")
951 ("icirc")
952 ("iuml")
953 ("eth")
954 ("ntilde")
955 ("ograve")
956 ("oacute")
957 ("ocirc")
958 ("otilde")
959 ("ouml")
960 ("divide")
961 ("oslash")
962 ("ugrave")
963 ("uacute")
964 ("ucirc")
965 ("uuml")
966 ("yacute")
967 ("thorn")
968 ("yuml")
969 ("fnof")
970 ("Alpha")
971 ("Beta")
972 ("Gamma")
973 ("Delta")
974 ("Epsilon")
975 ("Zeta")
976 ("Eta")
977 ("Theta")
978 ("Iota")
979 ("Kappa")
980 ("Lambda")
981 ("Mu")
982 ("Nu")
983 ("Xi")
984 ("Omicron")
985 ("Pi")
986 ("Rho")
987 ("Sigma")
988 ("Tau")
989 ("Upsilon")
990 ("Phi")
991 ("Chi")
992 ("Psi")
993 ("Omega")
994 ("alpha")
995 ("beta")
996 ("gamma")
997 ("delta")
998 ("epsilon")
999 ("varepsilon"."&epsilon;")
1000 ("zeta")
1001 ("eta")
1002 ("theta")
1003 ("iota")
1004 ("kappa")
1005 ("lambda")
1006 ("mu")
1007 ("nu")
1008 ("xi")
1009 ("omicron")
1010 ("pi")
1011 ("rho")
1012 ("sigmaf") ("varsigma"."&sigmaf;")
1013 ("sigma")
1014 ("tau")
1015 ("upsilon")
1016 ("phi")
1017 ("chi")
1018 ("psi")
1019 ("omega")
1020 ("thetasym") ("vartheta"."&thetasym;")
1021 ("upsih")
1022 ("piv")
1023 ("bull") ("bullet"."&bull;")
1024 ("hellip") ("dots"."&hellip;")
1025 ("prime")
1026 ("Prime")
1027 ("oline")
1028 ("frasl")
1029 ("weierp")
1030 ("image")
1031 ("real")
1032 ("trade")
1033 ("alefsym")
1034 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1035 ("uarr") ("uparrow"."&uarr;")
1036 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1037 ("darr")("downarrow"."&darr;")
1038 ("harr") ("leftrightarrow"."&harr;")
1039 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1040 ("lArr") ("Leftarrow"."&lArr;")
1041 ("uArr") ("Uparrow"."&uArr;")
1042 ("rArr") ("Rightarrow"."&rArr;")
1043 ("dArr") ("Downarrow"."&dArr;")
1044 ("hArr") ("Leftrightarrow"."&hArr;")
1045 ("forall")
1046 ("part") ("partial"."&part;")
1047 ("exist") ("exists"."&exist;")
1048 ("empty") ("emptyset"."&empty;")
1049 ("nabla")
1050 ("isin") ("in"."&isin;")
1051 ("notin")
1052 ("ni")
1053 ("prod")
1054 ("sum")
1055 ("minus")
1056 ("lowast") ("ast"."&lowast;")
1057 ("radic")
1058 ("prop") ("proptp"."&prop;")
1059 ("infin") ("infty"."&infin;")
1060 ("ang") ("angle"."&ang;")
1061 ("and") ("wedge"."&and;")
1062 ("or") ("vee"."&or;")
1063 ("cap")
1064 ("cup")
1065 ("int")
1066 ("there4")
1067 ("sim")
1068 ("cong") ("simeq"."&cong;")
1069 ("asymp")("approx"."&asymp;")
1070 ("ne") ("neq"."&ne;")
1071 ("equiv")
1072 ("le")
1073 ("ge")
1074 ("sub") ("subset"."&sub;")
1075 ("sup") ("supset"."&sup;")
1076 ("nsub")
1077 ("sube")
1078 ("supe")
1079 ("oplus")
1080 ("otimes")
1081 ("perp")
1082 ("sdot") ("cdot"."&sdot;")
1083 ("lceil")
1084 ("rceil")
1085 ("lfloor")
1086 ("rfloor")
1087 ("lang")
1088 ("rang")
1089 ("loz") ("Diamond"."&loz;")
1090 ("spades") ("spadesuit"."&spades;")
1091 ("clubs") ("clubsuit"."&clubs;")
1092 ("hearts") ("diamondsuit"."&hearts;")
1093 ("diams") ("diamondsuit"."&diams;")
1094 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1095 ("quot")
1096 ("amp")
1097 ("lt")
1098 ("gt")
1099 ("OElig")
1100 ("oelig")
1101 ("Scaron")
1102 ("scaron")
1103 ("Yuml")
1104 ("circ")
1105 ("tilde")
1106 ("ensp")
1107 ("emsp")
1108 ("thinsp")
1109 ("zwnj")
1110 ("zwj")
1111 ("lrm")
1112 ("rlm")
1113 ("ndash")
1114 ("mdash")
1115 ("lsquo")
1116 ("rsquo")
1117 ("sbquo")
1118 ("ldquo")
1119 ("rdquo")
1120 ("bdquo")
1121 ("dagger")
1122 ("Dagger")
1123 ("permil")
1124 ("lsaquo")
1125 ("rsaquo")
1126 ("euro")
1128 ("arccos"."arccos")
1129 ("arcsin"."arcsin")
1130 ("arctan"."arctan")
1131 ("arg"."arg")
1132 ("cos"."cos")
1133 ("cosh"."cosh")
1134 ("cot"."cot")
1135 ("coth"."coth")
1136 ("csc"."csc")
1137 ("deg"."deg")
1138 ("det"."det")
1139 ("dim"."dim")
1140 ("exp"."exp")
1141 ("gcd"."gcd")
1142 ("hom"."hom")
1143 ("inf"."inf")
1144 ("ker"."ker")
1145 ("lg"."lg")
1146 ("lim"."lim")
1147 ("liminf"."liminf")
1148 ("limsup"."limsup")
1149 ("ln"."ln")
1150 ("log"."log")
1151 ("max"."max")
1152 ("min"."min")
1153 ("Pr"."Pr")
1154 ("sec"."sec")
1155 ("sin"."sin")
1156 ("sinh"."sinh")
1157 ("sup"."sup")
1158 ("tan"."tan")
1159 ("tanh"."tanh")
1161 "Entities for TeX->HTML translation.
1162 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1163 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1164 In that case, \"\\ent\" will be translated to \"&other;\".
1165 The list contains HTML entities for Latin-1, Greek and other symbols.
1166 It is supplemented by a number of commonly used TeX macros with appropriate
1167 translations. There is currently no way for users to extend this.")
1169 ;;; General functions for all backends
1171 (defvar org-export-target-aliases nil
1172 "Alist of targets with invisible aliases.")
1173 (defvar org-export-preferred-target-alist nil
1174 "Alist of section id's with preferred aliases.")
1175 (defvar org-export-code-refs nil
1176 "Alist of code references and line numbers")
1178 (defun org-export-preprocess-string (string &rest parameters)
1179 "Cleanup STRING so that that the true exported has a more consistent source.
1180 This function takes STRING, which should be a buffer-string of an org-file
1181 to export. It then creates a temporary buffer where it does its job.
1182 The result is then again returned as a string, and the exporter works
1183 on this string to produce the exported version."
1184 (interactive)
1185 (let* ((htmlp (plist-get parameters :for-html))
1186 (asciip (plist-get parameters :for-ascii))
1187 (latexp (plist-get parameters :for-LaTeX))
1188 (docbookp (plist-get parameters :for-docbook))
1189 (backend (cond (htmlp 'html)
1190 (latexp 'latex)
1191 (asciip 'ascii)
1192 (docbookp 'docbook)))
1193 (archived-trees (plist-get parameters :archived-trees))
1194 (inhibit-read-only t)
1195 (drawers org-drawers)
1196 (outline-regexp "\\*+ ")
1197 target-alist rtn)
1199 (setq org-export-target-aliases nil)
1200 (setq org-export-preferred-target-alist nil)
1201 (setq org-export-code-refs nil)
1203 (with-current-buffer (get-buffer-create " org-mode-tmp")
1204 (erase-buffer)
1205 (insert string)
1206 (setq case-fold-search t)
1208 ;; Remove license-to-kill stuff
1209 ;; The caller marks some stuff for killing, stuff that has been
1210 ;; used to create the page title, for example.
1211 (org-export-kill-licensed-text)
1213 (let ((org-inhibit-startup t)) (org-mode))
1214 (setq case-fold-search t)
1216 ;; Call the hook
1217 (run-hooks 'org-export-preprocess-hook)
1219 ;; Process the macros
1220 (org-export-preprocess-apply-macros)
1221 (run-hooks 'org-export-preprocess-after-macros-hook)
1223 (untabify (point-min) (point-max))
1225 ;; Handle include files, and call a hook
1226 (org-export-handle-include-files)
1227 (run-hooks 'org-export-preprocess-after-include-files-hook)
1229 ;; Get rid of archived trees
1230 (org-export-remove-archived-trees archived-trees)
1232 ;; Remove comment environment and comment subtrees
1233 (org-export-remove-comment-blocks-and-subtrees)
1235 ;; Get rid of excluded trees, and call a hook
1236 (org-export-handle-export-tags (plist-get parameters :select-tags)
1237 (plist-get parameters :exclude-tags))
1238 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1240 ;; Handle source code snippets
1241 (org-export-replace-src-segments-and-examples backend)
1243 ;; Protect short examples marked by a leading colon
1244 (org-export-protect-colon-examples)
1246 ;; Normalize footnotes
1247 (when (plist-get parameters :footnotes)
1248 (org-footnote-normalize nil t))
1250 ;; Find all headings and compute the targets for them
1251 (setq target-alist (org-export-define-heading-targets target-alist))
1253 ;; Get rid of drawers
1254 (org-export-remove-or-extract-drawers drawers
1255 (plist-get parameters :drawers))
1257 ;; Get the correct stuff before the first headline
1258 (when (plist-get parameters :skip-before-1st-heading)
1259 (goto-char (point-min))
1260 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1261 (delete-region (point-min) (match-beginning 0))
1262 (goto-char (point-min))
1263 (insert "\n")))
1264 (when (plist-get parameters :add-text)
1265 (goto-char (point-min))
1266 (insert (plist-get parameters :add-text) "\n"))
1268 ;; Remove todo-keywords before exporting, if the user has requested so
1269 (org-export-remove-headline-metadata parameters)
1271 ;; Find targets in comments and move them out of comments,
1272 ;; but mark them as targets that should be invisible
1273 (setq target-alist (org-export-handle-invisible-targets target-alist))
1275 ;; Select and protect backend specific stuff, throw away stuff
1276 ;; that is specific for other backends
1277 (org-export-select-backend-specific-text backend)
1279 ;; Protect quoted subtrees
1280 (org-export-protect-quoted-subtrees)
1282 ;; Remove clock lines
1283 (org-export-remove-clock-lines)
1285 ;; Protect verbatim elements
1286 (org-export-protect-verbatim)
1288 ;; Blockquotes, verse, and center
1289 (org-export-mark-blockquote-verse-center)
1290 (run-hooks 'org-export-preprocess-after-blockquote-hook)
1292 ;; Remove timestamps, if the user has requested so
1293 (unless (plist-get parameters :timestamps)
1294 (org-export-remove-timestamps))
1296 ;; Attach captions to the correct object
1297 (setq target-alist (org-export-attach-captions-and-attributes
1298 backend target-alist))
1300 ;; Find matches for radio targets and turn them into internal links
1301 (org-export-mark-radio-links)
1303 ;; Find all links that contain a newline and put them into a single line
1304 (org-export-concatenate-multiline-links)
1306 ;; Normalize links: Convert angle and plain links into bracket links
1307 ;; and expand link abbreviations
1308 (org-export-normalize-links)
1310 ;; Find all internal links. If they have a fuzzy match (i.e. not
1311 ;; a *dedicated* target match, let the link point to the
1312 ;; corresponding section.
1313 (org-export-target-internal-links target-alist)
1315 ;; Find multiline emphasis and put them into single line
1316 (when (plist-get parameters :emph-multiline)
1317 (org-export-concatenate-multiline-emphasis))
1319 ;; Remove special table lines
1320 (when org-export-table-remove-special-lines
1321 (org-export-remove-special-table-lines))
1323 ;; Another hook
1324 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1326 ;; LaTeX-specific preprocessing
1327 (when latexp
1328 (require 'org-latex nil)
1329 (org-export-latex-preprocess parameters))
1331 ;; ASCII-specific preprocessing
1332 (when asciip
1333 (org-export-ascii-preprocess parameters))
1335 ;; HTML-specific preprocessing
1336 (when htmlp
1337 (org-export-html-preprocess parameters))
1339 ;; DocBook-specific preprocessing
1340 (when docbookp
1341 (require 'org-docbook nil)
1342 (org-export-docbook-preprocess parameters))
1344 ;; Remove or replace comments
1345 (org-export-handle-comments (plist-get parameters :comments))
1347 ;; Run the final hook
1348 (run-hooks 'org-export-preprocess-final-hook)
1350 (setq rtn (buffer-string)))
1351 (kill-buffer " org-mode-tmp")
1352 rtn))
1354 (defun org-export-kill-licensed-text ()
1355 "Remove all text that is marked with a :org-license-to-kill property."
1356 (let (p)
1357 (while (setq p (text-property-any (point-min) (point-max)
1358 :org-license-to-kill t))
1359 (delete-region
1360 p (or (next-single-property-change p :org-license-to-kill)
1361 (point-max))))))
1363 (defun org-export-define-heading-targets (target-alist)
1364 "Find all headings and define the targets for them.
1365 The new targets are added to TARGET-ALIST, which is also returned."
1366 (goto-char (point-min))
1367 (org-init-section-numbers)
1368 (let ((re (concat "^" org-outline-regexp
1369 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1370 level target last-section-target a id)
1371 (while (re-search-forward re nil t)
1372 (if (match-end 2)
1373 (progn
1374 (setq id (org-match-string-no-properties 2))
1375 (push (cons id target) target-alist)
1376 (setq a (or (assoc last-section-target org-export-target-aliases)
1377 (progn
1378 (push (list last-section-target)
1379 org-export-target-aliases)
1380 (car org-export-target-aliases))))
1381 (push (caar target-alist) (cdr a))
1382 (when (equal (match-string 1) "CUSTOM_ID")
1383 (if (not (assoc last-section-target
1384 org-export-preferred-target-alist))
1385 (push (cons last-section-target id)
1386 org-export-preferred-target-alist))))
1387 (setq level (org-reduced-level
1388 (save-excursion (goto-char (point-at-bol))
1389 (org-outline-level))))
1390 (setq target (org-solidify-link-text
1391 (format "sec-%s" (org-section-number level))))
1392 (setq last-section-target target)
1393 (push (cons target target) target-alist)
1394 (add-text-properties
1395 (point-at-bol) (point-at-eol)
1396 (list 'target target)))))
1397 target-alist)
1399 (defun org-export-handle-invisible-targets (target-alist)
1400 "Find targets in comments and move them out of comments.
1401 Mark them as invisible targets."
1402 (let (target tmp a)
1403 (goto-char (point-min))
1404 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1405 ;; Check if the line before or after is a headline with a target
1406 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1407 (get-text-property (point-at-bol 2) 'target)))
1408 (progn
1409 ;; use the existing target in a neighboring line
1410 (setq tmp (match-string 2))
1411 (replace-match "")
1412 (and (looking-at "\n") (delete-char 1))
1413 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1414 target-alist)
1415 (setq a (or (assoc target org-export-target-aliases)
1416 (progn
1417 (push (list target) org-export-target-aliases)
1418 (car org-export-target-aliases))))
1419 (push tmp (cdr a)))
1420 ;; Make an invisible target
1421 (replace-match "\\1(INVISIBLE)"))))
1422 target-alist)
1424 (defun org-export-target-internal-links (target-alist)
1425 "Find all internal links and assign targets to them.
1426 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1427 let the link point to the corresponding section.
1428 This function also handles the id links, if they have a match in
1429 the current file."
1430 (goto-char (point-min))
1431 (while (re-search-forward org-bracket-link-regexp nil t)
1432 (org-if-unprotected
1433 (let* ((md (match-data))
1434 (desc (match-end 2))
1435 (link (org-link-unescape (match-string 1)))
1436 (slink (org-solidify-link-text link))
1437 found props pos cref
1438 (target
1439 (cond
1440 ((= (string-to-char link) ?#)
1441 ;; user wants exactly this link
1442 link)
1443 ((cdr (assoc slink target-alist))
1444 (or (cdr (assoc (assoc slink target-alist)
1445 org-export-preferred-target-alist))
1446 (cdr (assoc slink target-alist))))
1447 ((and (string-match "^id:" link)
1448 (cdr (assoc (substring link 3) target-alist))))
1449 ((string-match "^(\\(.*\\))$" link)
1450 (setq cref (match-string 1 link))
1451 (concat "coderef:" cref))
1452 ((string-match org-link-types-re link) nil)
1453 ((or (file-name-absolute-p link)
1454 (string-match "^\\." link))
1455 nil)
1457 (save-excursion
1458 (setq found (condition-case nil (org-link-search link)
1459 (error nil)))
1460 (when (and found
1461 (or (org-on-heading-p)
1462 (not (eq found 'dedicated))))
1463 (or (get-text-property (point) 'target)
1464 (get-text-property
1465 (max (point-min)
1466 (1- (or (previous-single-property-change
1467 (point) 'target) 0)))
1468 'target))))))))
1469 (when target
1470 (set-match-data md)
1471 (goto-char (match-beginning 1))
1472 (setq props (text-properties-at (point)))
1473 (delete-region (match-beginning 1) (match-end 1))
1474 (setq pos (point))
1475 (insert target)
1476 (unless desc (insert "][" link))
1477 (add-text-properties pos (point) props))))))
1479 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1480 "Remove drawers, or extract the content.
1481 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1482 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1483 whose content to keep."
1484 (unless (eq t exp-drawers)
1485 (goto-char (point-min))
1486 (let ((re (concat "^[ \t]*:\\("
1487 (mapconcat
1488 'identity
1489 (org-delete-all exp-drawers
1490 (copy-sequence all-drawers))
1491 "\\|")
1492 "\\):[ \t]*$"))
1493 beg eol)
1494 (while (re-search-forward re nil t)
1495 (org-if-unprotected
1496 (setq beg (match-beginning 0)
1497 eol (match-end 0))
1498 (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
1499 nil t)
1500 (if (match-end 1)
1501 ;; terminated in this entry
1502 (progn
1503 (delete-region beg (match-end 1))
1504 (goto-char beg))
1505 (goto-char eol))))))))
1507 (defun org-export-handle-export-tags (select-tags exclude-tags)
1508 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1509 Both arguments are lists of tags.
1510 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1511 will be removed.
1512 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1513 removed as well."
1514 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1515 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1516 select-tags "\\|")
1517 "\\):"))
1518 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1519 exclude-tags "\\|")
1520 "\\):"))
1521 beg end cont)
1522 (goto-char (point-min))
1523 (when (and select-tags
1524 (re-search-forward
1525 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1526 ;; At least one tree is marked for export, this means
1527 ;; all the unmarked stuff needs to go.
1528 ;; Dig out the trees that should be exported
1529 (goto-char (point-min))
1530 (outline-next-heading)
1531 (setq beg (point))
1532 (put-text-property beg (point-max) :org-delete t)
1533 (while (re-search-forward re-sel nil t)
1534 (when (org-on-heading-p)
1535 (org-back-to-heading)
1536 (remove-text-properties
1537 (max (1- (point)) (point-min))
1538 (setq cont (save-excursion (org-end-of-subtree t t)))
1539 '(:org-delete t))
1540 (while (and (org-up-heading-safe)
1541 (get-text-property (point) :org-delete))
1542 (remove-text-properties (max (1- (point)) (point-min))
1543 (point-at-eol) '(:org-delete t)))
1544 (goto-char cont))))
1545 ;; Remove the trees explicitly marked for noexport
1546 (when exclude-tags
1547 (goto-char (point-min))
1548 (while (re-search-forward re-excl nil t)
1549 (when (org-at-heading-p)
1550 (org-back-to-heading t)
1551 (setq beg (point))
1552 (org-end-of-subtree t)
1553 (delete-region beg (point)))))
1554 ;; Remove everything that is now still marked for deletion
1555 (goto-char (point-min))
1556 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1557 (setq end (or (next-single-property-change beg :org-delete)
1558 (point-max)))
1559 (delete-region beg end))))
1561 (defun org-export-remove-archived-trees (export-archived-trees)
1562 "Remove archived trees.
1563 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1564 When it is t, the entire archived tree will be exported.
1565 When it is nil the entire tree including the headline will be removed
1566 from the buffer."
1567 (let ((re-archive (concat ":" org-archive-tag ":"))
1568 a b)
1569 (when (not (eq export-archived-trees t))
1570 (goto-char (point-min))
1571 (while (re-search-forward re-archive nil t)
1572 (if (not (org-on-heading-p t))
1573 (org-end-of-subtree t)
1574 (beginning-of-line 1)
1575 (setq a (if export-archived-trees
1576 (1+ (point-at-eol)) (point))
1577 b (org-end-of-subtree t))
1578 (if (> b a) (delete-region a b)))))))
1580 (defun org-export-remove-headline-metadata (opts)
1581 "Remove meta data from the headline, according to user options."
1582 (let ((re org-complex-heading-regexp)
1583 (todo (plist-get opts :todo-keywords))
1584 (tags (plist-get opts :tags))
1585 (pri (plist-get opts :priority))
1586 (elts '(1 2 3 4 5))
1587 rpl)
1588 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1589 (when (or (not todo) (not tags) (not pri))
1590 (goto-char (point-min))
1591 (while (re-search-forward re nil t)
1592 (org-if-unprotected
1593 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1594 elts " "))
1595 (replace-match rpl t t))))))
1597 (defun org-export-remove-timestamps ()
1598 "Remove timestamps and keywords for export."
1599 (goto-char (point-min))
1600 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1601 (backward-char 1)
1602 (org-if-unprotected
1603 (unless (save-match-data (org-at-table-p))
1604 (replace-match "")
1605 (beginning-of-line 1)
1606 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1607 (replace-match ""))))))
1609 (defun org-export-remove-clock-lines ()
1610 "Remove clock lines for export."
1611 (goto-char (point-min))
1612 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1613 (while (re-search-forward re nil t)
1614 (org-if-unprotected
1615 (replace-match "")))))
1617 (defun org-export-protect-quoted-subtrees ()
1618 "Mark quoted subtrees with the protection property."
1619 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1620 (goto-char (point-min))
1621 (while (re-search-forward re-quote nil t)
1622 (goto-char (match-beginning 0))
1623 (end-of-line 1)
1624 (add-text-properties (point) (org-end-of-subtree t)
1625 '(org-protected t)))))
1627 (defun org-export-protect-verbatim ()
1628 "Mark verbatim snippets with the protection property."
1629 (goto-char (point-min))
1630 (while (re-search-forward org-verbatim-re nil t)
1631 (add-text-properties (match-beginning 4) (match-end 4)
1632 '(org-protected t))
1633 (goto-char (1+ (match-end 4)))))
1635 (defun org-export-protect-colon-examples ()
1636 "Protect lines starting with a colon."
1637 (goto-char (point-min))
1638 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1639 (while (re-search-forward re nil t)
1640 (beginning-of-line 1)
1641 (setq beg (point))
1642 (while (looking-at re)
1643 (end-of-line 1)
1644 (or (eobp) (forward-char 1)))
1645 (add-text-properties beg (if (bolp) (1- (point)) (point))
1646 '(org-protected t)))))
1648 (defun org-export-select-backend-specific-text (backend)
1649 (let ((formatters
1650 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1651 (html "HTML" "BEGIN_HTML" "END_HTML")
1652 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1653 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1654 (case-fold-search t)
1655 fmt)
1657 (while formatters
1658 (setq fmt (pop formatters))
1659 (when (eq (car fmt) backend)
1660 ;; This is selected code, put it into the file for real
1661 (goto-char (point-min))
1662 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
1663 ":[ \t]*\\(.*\\)") nil t)
1664 (replace-match "\\1\\2" t)
1665 (add-text-properties
1666 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1667 '(org-protected t))))
1668 (goto-char (point-min))
1669 (while (re-search-forward
1670 (concat "^[ \t]*#\\+" (caddr fmt)
1671 "\\>.*\\(\\(\n.*\\)*?\n\\)[ \t]*#\\+" (cadddr fmt)
1672 "\\>.*\n?") nil t)
1673 (if (eq (car fmt) backend)
1674 ;; yes, keep this
1675 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1676 '(org-protected t))
1677 ;; No, this is for a different backend, kill it
1678 (delete-region (match-beginning 0) (match-end 0)))))))
1680 (defun org-export-mark-blockquote-verse-center ()
1681 "Mark block quote and verse environments with special cookies.
1682 These special cookies will later be interpreted by the backend."
1683 ;; Blockquotes
1684 (let (type t1 ind beg end beg1 end1 content)
1685 (goto-char (point-min))
1686 (while (re-search-forward
1687 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1688 nil t)
1689 (setq ind (length (match-string 1))
1690 type (downcase (match-string 3))
1691 t1 (if (equal type "quote") "blockquote" type))
1692 (setq beg (match-beginning 0)
1693 beg1 (1+ (match-end 0)))
1694 (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
1695 (setq end (1+ (point-at-eol))
1696 end1 (1- (match-beginning 0)))
1697 (setq content (org-remove-indentation (buffer-substring beg1 end1)))
1698 (setq content (concat "ORG-" (upcase type) "-START\n"
1699 content "\n"
1700 "ORG-" (upcase type) "-END\n"))
1701 (delete-region beg end)
1702 (insert (org-add-props content nil 'original-indentation ind))))))
1704 (defun org-export-attach-captions-and-attributes (backend target-alist)
1705 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1706 If the next thing following is a table, add the text properties to the first
1707 table line. If it is a link, add it to the line containing the link."
1708 (goto-char (point-min))
1709 (remove-text-properties (point-min) (point-max)
1710 '(org-caption nil org-attributes nil))
1711 (let ((case-fold-search t)
1712 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1713 "\\|"
1714 "^[ \t]*#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
1715 "\\|"
1716 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1717 "\\|"
1718 "^[ \t]*|[^-]"
1719 "\\|"
1720 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1721 cap attr label)
1722 (while (re-search-forward re nil t)
1723 (cond
1724 ((match-end 1)
1725 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
1726 ((match-end 2)
1727 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
1728 ((match-end 3)
1729 (setq label (org-trim (match-string 3))))
1731 (add-text-properties (point-at-bol) (point-at-eol)
1732 (list 'org-caption cap
1733 'org-attributes attr
1734 'org-label label))
1735 (if label (push (cons label label) target-alist))
1736 (setq cap nil attr nil label nil)))))
1737 target-alist)
1739 (defun org-export-remove-comment-blocks-and-subtrees ()
1740 "Remove the comment environment, and also commented subtrees."
1741 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1742 (case-fold-search nil))
1743 ;; Remove comment environment
1744 (goto-char (point-min))
1745 (while (re-search-forward
1746 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1747 (replace-match "" t t))
1748 ;; Remove subtrees that are commented
1749 (goto-char (point-min))
1750 (while (re-search-forward re-commented nil t)
1751 (goto-char (match-beginning 0))
1752 (delete-region (point) (org-end-of-subtree t)))))
1754 (defun org-export-handle-comments (commentsp)
1755 "Remove comments, or convert to backend-specific format.
1756 COMMENTSP can be a format string for publishing comments.
1757 When it is nil, all comments will be removed."
1758 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1759 pos)
1760 (goto-char (point-min))
1761 (while (or (looking-at re)
1762 (re-search-forward re nil t))
1763 (setq pos (match-beginning 0))
1764 (if (and commentsp
1765 (not (equal (char-before (match-end 1)) ?+)))
1766 (progn (add-text-properties
1767 (match-beginning 0) (match-end 0) '(org-protected t))
1768 (replace-match (format commentsp (match-string 2)) t t))
1769 (goto-char (1+ pos))
1770 (org-if-unprotected
1771 (replace-match "")
1772 (goto-char (max (point-min) (1- pos))))))))
1774 (defun org-export-mark-radio-links ()
1775 "Find all matches for radio targets and turn them into internal links."
1776 (let ((re-radio (and org-target-link-regexp
1777 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1778 (goto-char (point-min))
1779 (when re-radio
1780 (while (re-search-forward re-radio nil t)
1781 (org-if-unprotected
1782 (replace-match "\\1[[\\2]]"))))))
1784 (defun org-export-remove-special-table-lines ()
1785 "Remove tables lines that are used for internal purposes."
1786 (goto-char (point-min))
1787 (while (re-search-forward "^[ \t]*|" nil t)
1788 (beginning-of-line 1)
1789 (if (or (looking-at "[ \t]*| *[!_^] *|")
1790 (and (looking-at ".*?| *<[0-9]+> *|")
1791 (not (looking-at ".*?| *[^ <|]"))))
1792 (delete-region (max (point-min) (1- (point-at-bol)))
1793 (point-at-eol))
1794 (end-of-line 1))))
1796 (defun org-export-normalize-links ()
1797 "Convert all links to bracket links, and expand link abbreviations."
1798 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1799 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
1800 (goto-char (point-min))
1801 (while (re-search-forward re-plain-link nil t)
1802 (goto-char (1- (match-end 0)))
1803 (org-if-unprotected-at (1+ (match-beginning 0))
1804 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1805 ":" (match-string 3) "]]")))
1806 ;; added 'org-link face to links
1807 (put-text-property 0 (length s) 'face 'org-link s)
1808 (replace-match s t t))))
1809 (goto-char (point-min))
1810 (while (re-search-forward re-angle-link nil t)
1811 (goto-char (1- (match-end 0)))
1812 (org-if-unprotected
1813 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1814 ":" (match-string 3) "]]")))
1815 (put-text-property 0 (length s) 'face 'org-link s)
1816 (replace-match s t t))))
1817 (goto-char (point-min))
1818 (while (re-search-forward org-bracket-link-regexp nil t)
1819 (goto-char (1- (match-end 0)))
1820 (org-if-unprotected
1821 (let* ((xx (save-match-data
1822 (org-translate-link
1823 (org-link-expand-abbrev (match-string 1)))))
1824 (s (concat
1825 "[[" (org-add-props (copy-sequence xx)
1826 nil 'org-protected t)
1828 (if (match-end 3)
1829 (match-string 2)
1830 (concat "[" (copy-sequence xx)
1831 "]"))
1832 "]")))
1833 (put-text-property 0 (length s) 'face 'org-link s)
1834 (replace-match s t t))))))
1836 (defun org-export-concatenate-multiline-links ()
1837 "Find multi-line links and put it all into a single line.
1838 This is to make sure that the line-processing export backends
1839 can work correctly."
1840 (goto-char (point-min))
1841 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1842 (org-if-unprotected
1843 (replace-match "\\1 \\3")
1844 (goto-char (match-beginning 0)))))
1846 (defun org-export-concatenate-multiline-emphasis ()
1847 "Find multi-line emphasis and put it all into a single line.
1848 This is to make sure that the line-processing export backends
1849 can work correctly."
1850 (goto-char (point-min))
1851 (while (re-search-forward org-emph-re nil t)
1852 (if (and (not (= (char-after (match-beginning 3))
1853 (char-after (match-beginning 4))))
1854 (save-excursion (goto-char (match-beginning 0))
1855 (save-match-data (not (org-at-table-p)))))
1856 (org-if-unprotected
1857 (subst-char-in-region (match-beginning 0) (match-end 0)
1858 ?\n ?\ t)
1859 (goto-char (1- (match-end 0))))
1860 (goto-char (1+ (match-beginning 0))))))
1862 (defun org-export-grab-title-from-buffer ()
1863 "Get a title for the current document, from looking at the buffer."
1864 (let ((inhibit-read-only t))
1865 (save-excursion
1866 (goto-char (point-min))
1867 (let ((end (if (looking-at org-outline-regexp)
1868 (point)
1869 (save-excursion (outline-next-heading) (point)))))
1870 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1871 ;; Mark the line so that it will not be exported as normal text.
1872 (org-unmodified
1873 (add-text-properties (match-beginning 0) (match-end 0)
1874 (list :org-license-to-kill t)))
1875 ;; Return the title string
1876 (org-trim (match-string 0)))))))
1878 (defun org-export-get-title-from-subtree ()
1879 "Return subtree title and exclude it from export."
1880 (let (title (rbeg (region-beginning)) (rend (region-end)))
1881 (save-excursion
1882 (goto-char rbeg)
1883 (when (and (org-at-heading-p)
1884 (>= (org-end-of-subtree t t) rend))
1885 ;; This is a subtree, we take the title from the first heading
1886 (goto-char rbeg)
1887 (looking-at org-todo-line-regexp)
1888 (setq title (match-string 3))
1889 (org-unmodified
1890 (add-text-properties (point) (1+ (point-at-eol))
1891 (list :org-license-to-kill t)))
1892 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1893 title))
1895 (defun org-solidify-link-text (s &optional alist)
1896 "Take link text and make a safe target out of it."
1897 (save-match-data
1898 (let* ((rtn
1899 (mapconcat
1900 'identity
1901 (org-split-string s "[ \t\r\n]+") "=="))
1902 (a (assoc rtn alist)))
1903 (or (cdr a) rtn))))
1905 (defun org-get-min-level (lines &optional offset)
1906 "Get the minimum level in LINES."
1907 (let ((re "^\\(\\*+\\) ") l)
1908 (catch 'exit
1909 (while (setq l (pop lines))
1910 (if (string-match re l)
1911 (throw 'exit (org-tr-level (- (length (match-string 1 l))
1912 (or offset 0))))))
1913 1)))
1915 ;; Variable holding the vector with section numbers
1916 (defvar org-section-numbers (make-vector org-level-max 0))
1918 (defun org-init-section-numbers ()
1919 "Initialize the vector for the section numbers."
1920 (let* ((level -1)
1921 (numbers (nreverse (org-split-string "" "\\.")))
1922 (depth (1- (length org-section-numbers)))
1923 (i depth) number-string)
1924 (while (>= i 0)
1925 (if (> i level)
1926 (aset org-section-numbers i 0)
1927 (setq number-string (or (car numbers) "0"))
1928 (if (string-match "\\`[A-Z]\\'" number-string)
1929 (aset org-section-numbers i
1930 (- (string-to-char number-string) ?A -1))
1931 (aset org-section-numbers i (string-to-number number-string)))
1932 (pop numbers))
1933 (setq i (1- i)))))
1935 (defun org-section-number (&optional level)
1936 "Return a string with the current section number.
1937 When LEVEL is non-nil, increase section numbers on that level."
1938 (let* ((depth (1- (length org-section-numbers)))
1939 (string "")
1940 (fmts (car org-export-section-number-format))
1941 (term (cdr org-export-section-number-format))
1942 (sep "")
1943 ctype fmt idx n)
1944 (when level
1945 (when (> level -1)
1946 (aset org-section-numbers
1947 level (1+ (aref org-section-numbers level))))
1948 (setq idx (1+ level))
1949 (while (<= idx depth)
1950 (if (not (= idx 1))
1951 (aset org-section-numbers idx 0))
1952 (setq idx (1+ idx))))
1953 (setq idx 0)
1954 (while (<= idx depth)
1955 (when (> (aref org-section-numbers idx) 0)
1956 (setq fmt (or (pop fmts) fmt)
1957 ctype (car fmt)
1958 n (aref org-section-numbers idx)
1959 string (if (> n 0)
1960 (concat string sep (org-number-to-counter n ctype))
1961 (concat string ".0"))
1962 sep (nth 1 fmt)))
1963 (setq idx (1+ idx)))
1964 (save-match-data
1965 (if (string-match "\\`\\([@0]\\.\\)+" string)
1966 (setq string (replace-match "" t nil string)))
1967 (if (string-match "\\(\\.0\\)+\\'" string)
1968 (setq string (replace-match "" t nil string))))
1969 (concat string term)))
1971 (defun org-number-to-counter (n type)
1972 "Concert number N to a string counter, according to TYPE.
1973 TYPE must be a string, any of:
1974 1 number
1975 A A,B,....
1976 a a,b,....
1977 I upper case roman numeral
1978 i lower case roman numeral"
1979 (cond
1980 ((equal type "1") (number-to-string n))
1981 ((equal type "A") (char-to-string (+ ?A n -1)))
1982 ((equal type "a") (char-to-string (+ ?a n -1)))
1983 ((equal type "I") (org-number-to-roman n))
1984 ((equal type "i") (downcase (org-number-to-roman n)))
1985 (t (error "Invalid counter type `%s'" type))))
1987 (defun org-number-to-roman (n)
1988 "Convert integer N into a roman numeral."
1989 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
1990 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1991 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1992 ( 1 . "I")))
1993 (res ""))
1994 (if (<= n 0)
1995 (number-to-string n)
1996 (while roman
1997 (if (>= n (caar roman))
1998 (setq n (- n (caar roman))
1999 res (concat res (cdar roman)))
2000 (pop roman)))
2001 res)))
2003 ;;; Macros
2005 (defun org-export-preprocess-apply-macros ()
2006 "Replace macro references."
2007 (goto-char (point-min))
2008 (let (sy val key args args2 s n)
2009 (while (re-search-forward
2010 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\(.*?\\))\\)?}}}"
2011 nil t)
2012 (setq key (downcase (match-string 1))
2013 args (match-string 3))
2014 (when (setq val (or (plist-get org-export-opt-plist
2015 (intern (concat ":macro-" key)))
2016 (plist-get org-export-opt-plist
2017 (intern (concat ":" key)))))
2018 (save-match-data
2019 (when args
2020 (setq args (org-split-string args ";") args2 nil)
2021 (while args
2022 (while (string-match "\\\\\\'" (car args))
2023 ;; repair bad splits
2024 (setcar (cdr args) (concat (substring (car args) 0 -1)
2025 ";" (nth 1 args)))
2026 (pop args))
2027 (push (pop args) args2))
2028 (setq args (nreverse args2))
2029 (setq s 0)
2030 (while (string-match "\\$\\([0-9]+\\)" val s)
2031 (setq s (1+ (match-beginning 0))
2032 n (string-to-number (match-string 1 val)))
2033 (and (>= (length args) n)
2034 (setq val (replace-match (nth (1- n) args) t t val)))))
2035 (when (string-match "\\`(eval\\>" val)
2036 (setq val (eval (read val))))
2037 (if (and val (not (stringp val)))
2038 (setq val (format "%s" val))))
2039 (and (stringp val)
2040 (replace-match val t t))))))
2042 (defun org-export-apply-macros-in-string (s)
2043 "Apply the macros in string S."
2044 (when s
2045 (with-temp-buffer
2046 (insert s)
2047 (org-export-preprocess-apply-macros)
2048 (buffer-string))))
2050 ;;; Include files
2052 (defun org-export-handle-include-files ()
2053 "Include the contents of include files, with proper formatting."
2054 (let ((case-fold-search t)
2055 params file markup lang start end prefix prefix1 switches)
2056 (goto-char (point-min))
2057 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2058 (setq params (read (concat "(" (match-string 1) ")"))
2059 prefix (org-get-and-remove-property 'params :prefix)
2060 prefix1 (org-get-and-remove-property 'params :prefix1)
2061 file (org-symname-or-string (pop params))
2062 markup (org-symname-or-string (pop params))
2063 lang (and (member markup '("src" "SRC"))
2064 (org-symname-or-string (pop params)))
2065 switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
2066 (delete-region (match-beginning 0) (match-end 0))
2067 (if (or (not file)
2068 (not (file-exists-p file))
2069 (not (file-readable-p file)))
2070 (insert (format "CANNOT INCLUDE FILE %s" file))
2071 (when markup
2072 (if (equal (downcase markup) "src")
2073 (setq start (format "#+begin_src %s %s\n"
2074 (or lang "fundamental")
2075 (or switches ""))
2076 end "#+end_src")
2077 (setq start (format "#+begin_%s %s\n" markup switches)
2078 end (format "#+end_%s" markup))))
2079 (insert (or start ""))
2080 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2081 (or (bolp) (newline))
2082 (insert (or end ""))))))
2084 (defun org-get-file-contents (file &optional prefix prefix1)
2085 "Get the contents of FILE and return them as a string.
2086 If PREFIX is a string, prepend it to each line. If PREFIX1
2087 is a string, prepend it to the first line instead of PREFIX."
2088 (with-temp-buffer
2089 (insert-file-contents file)
2090 (when (or prefix prefix1)
2091 (goto-char (point-min))
2092 (while (not (eobp))
2093 (insert (or prefix1 prefix))
2094 (setq prefix1 nil)
2095 (beginning-of-line 2)))
2096 (buffer-string)))
2098 (defun org-get-and-remove-property (listvar prop)
2099 "Check if the value of LISTVAR contains PROP as a property.
2100 If yes, return the value of that property (i.e. the element following
2101 in the list) and remove property and value from the list in LISTVAR."
2102 (let ((list (symbol-value listvar)) m v)
2103 (when (setq m (member prop list))
2104 (setq v (nth 1 m))
2105 (if (equal (car list) prop)
2106 (set listvar (cddr list))
2107 (setcdr (nthcdr (- (length list) (length m) 1) list)
2108 (cddr m))
2109 (set listvar list)))
2112 (defun org-symname-or-string (s)
2113 (if (symbolp s)
2114 (if s (symbol-name s) s)
2117 ;;; Fontification and line numbers for code examples
2119 (defvar org-export-last-code-line-counter-value 0)
2121 (defun org-export-replace-src-segments-and-examples (backend)
2122 "Replace source code segments with special code for export."
2123 (setq org-export-last-code-line-counter-value 0)
2124 (let ((case-fold-search t)
2125 lang code trans opts indent)
2126 (goto-char (point-min))
2127 (while (re-search-forward
2128 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
2129 nil t)
2130 (if (match-end 1)
2131 ;; src segments
2132 (setq lang (match-string 3)
2133 opts (match-string 4)
2134 code (match-string 5)
2135 indent (length (match-string 2)))
2136 (setq lang nil
2137 opts (match-string 8)
2138 code (match-string 9)
2139 indent (length (match-string 7))))
2141 (setq trans (org-export-format-source-code-or-example
2142 backend lang code opts indent))
2143 (replace-match trans t t))))
2145 (defvar htmlp) ;; dynamically scoped
2146 (defvar latexp) ;; dynamically scoped
2148 (defun org-export-format-source-code-or-example
2149 (backend lang code &optional opts indent)
2150 "Format CODE from language LANG and return it formatted for export.
2151 If LANG is nil, do not add any fontification.
2152 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2153 and `+n' for continuing previous numering.
2154 Code formatting according to language currently only works for HTML.
2155 Numbering lines works for all three major backends (html, latex, and ascii).
2156 INDENT was the original indentation of the block."
2157 (save-match-data
2158 (let (num cont rtn rpllbl keepp textareap cols rows fmt)
2159 (setq opts (or opts "")
2160 num (string-match "[-+]n\\>" opts)
2161 cont (string-match "\\+n\\>" opts)
2162 rpllbl (string-match "-r\\>" opts)
2163 keepp (string-match "-k\\>" opts)
2164 textareap (string-match "-t\\>" opts)
2165 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2166 (string-to-number (match-string 1 opts))
2168 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2169 (string-to-number (match-string 1 opts))
2170 (org-count-lines code))
2171 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2172 (match-string 1 opts)))
2173 (when (and textareap (eq backend 'html))
2174 ;; we cannot use numbering or highlighting.
2175 (setq num nil cont nil lang nil))
2176 (if keepp (setq rpllbl 'keep))
2177 (setq rtn (org-remove-indentation code))
2178 (when (string-match "^," rtn)
2179 (setq rtn (with-temp-buffer
2180 (insert rtn)
2181 ;; Free up the protected lines
2182 (goto-char (point-min))
2183 (while (re-search-forward "^," nil t)
2184 (if (or (equal lang "org")
2185 (save-match-data
2186 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2187 (replace-match ""))
2188 (end-of-line 1))
2189 (buffer-string))))
2190 ;; Now backend-specific coding
2191 (setq rtn
2192 (cond
2193 ((eq backend 'docbook)
2194 (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
2195 (concat "\n#+BEGIN_DOCBOOK\n"
2196 (org-add-props (concat "<programlisting><![CDATA["
2198 "]]>\n</programlisting>\n")
2199 '(org-protected t))
2200 "#+END_DOCBOOK\n"))
2201 ((eq backend 'html)
2202 ;; We are exporting to HTML
2203 (when lang
2204 (require 'htmlize nil t)
2205 (when (not (fboundp 'htmlize-region-for-paste))
2206 ;; we do not have htmlize.el, or an old version of it
2207 (setq lang nil)
2208 (message
2209 "htmlize.el 1.34 or later is needed for source code formatting")))
2211 (if lang
2212 (let* ((mode (and lang (intern (concat lang "-mode"))))
2213 (org-inhibit-startup t)
2214 (org-startup-folded nil))
2215 (setq rtn
2216 (with-temp-buffer
2217 (insert rtn)
2218 (if (functionp mode)
2219 (funcall mode)
2220 (fundamental-mode))
2221 (font-lock-fontify-buffer)
2222 (set-buffer-modified-p nil)
2223 (org-export-htmlize-region-for-paste
2224 (point-min) (point-max))))
2225 (if (string-match "<pre\\([^>]*\\)>\n?" rtn)
2226 (setq rtn (replace-match
2227 (format "<pre class=\"src src-%s\">\n" lang)
2228 t t rtn))))
2229 (if textareap
2230 (setq rtn (concat
2231 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2232 cols rows)
2233 rtn "</textarea>\n</p>\n"))
2234 (with-temp-buffer
2235 (insert rtn)
2236 (goto-char (point-min))
2237 (while (re-search-forward "[<>&]" nil t)
2238 (replace-match (cdr (assq (char-before)
2239 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2240 t t))
2241 (setq rtn (buffer-string)))
2242 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2243 (unless textareap
2244 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2245 cont rpllbl fmt)))
2246 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2247 ((eq backend 'latex)
2248 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2249 (concat "\n#+BEGIN_LaTeX\n"
2250 (org-add-props (concat "\\begin{verbatim}\n" rtn "\n\\end{verbatim}\n")
2251 '(org-protected t))
2252 "#+END_LaTeX\n\n"))
2253 ((eq backend 'ascii)
2254 ;; This is not HTML or LaTeX, so just make it an example.
2255 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2256 (concat "#+BEGIN_ASCII\n"
2257 (org-add-props
2258 (concat
2259 (mapconcat
2260 (lambda (l) (concat " " l))
2261 (org-split-string rtn "\n")
2262 "\n")
2263 "\n")
2264 '(org-protected t))
2265 "#+END_ASCII\n"))))
2266 (org-add-props rtn nil 'original-indentation indent))))
2268 (defun org-export-number-lines (text backend
2269 &optional skip1 skip2 number cont
2270 replace-labels label-format)
2271 (if (and (not number) (not (eq replace-labels 'keep)))
2272 (setq replace-labels nil)) ;; must use names if no numbers
2273 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2274 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2275 (with-temp-buffer
2276 (insert text)
2277 (goto-char (point-max))
2278 (skip-chars-backward " \t\n\r")
2279 (delete-region (point) (point-max))
2280 (beginning-of-line (- 1 skip2))
2281 (let* ((last (org-current-line))
2282 (n org-export-last-code-line-counter-value)
2283 (nmax (+ n (- last skip1)))
2284 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2286 (cond
2287 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2288 fmt))
2289 ((eq backend 'ascii) fmt)
2290 ((eq backend 'latex) fmt)
2291 ((eq backend 'docbook) fmt)
2292 (t "")))
2293 (label-format (or label-format org-coderef-label-format))
2294 (label-pre (if (string-match "%s" label-format)
2295 (substring label-format 0 (match-beginning 0))
2296 label-format))
2297 (label-post (if (string-match "%s" label-format)
2298 (substring label-format (match-end 0))
2299 ""))
2300 (lbl-re
2301 (concat
2302 ".*?\\S-.*?\\([ \t]*\\("
2303 (regexp-quote label-pre)
2304 "\\([-a-zA-Z0-9_]+\\)"
2305 (regexp-quote label-post)
2306 "\\)\\)"))
2307 ref)
2309 (goto-line (1+ skip1))
2310 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2311 (if number
2312 (insert (format fm (incf n)))
2313 (forward-char 1))
2314 (when (and (not (eq replace-labels 'keep))
2315 (looking-at lbl-re))
2316 (setq ref (match-string 3))
2317 (if replace-labels
2318 (progn
2319 (delete-region (match-beginning 1) (match-end 1))
2320 (push (cons ref n) org-export-code-refs))
2321 (goto-char (match-beginning 2))
2322 (delete-region (match-beginning 2) (match-end 2))
2323 (insert "(" ref ")")
2324 (push (cons ref (concat "(" ref ")")) org-export-code-refs))
2325 (when (eq backend 'html)
2326 (save-excursion
2327 (beginning-of-line 1)
2328 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2329 ref))
2330 (end-of-line 1)
2331 (insert "</span>")))))
2332 (setq org-export-last-code-line-counter-value n)
2333 (goto-char (point-max))
2334 (newline)
2335 (buffer-string))))
2337 (defun org-search-todo-below (line lines level)
2338 "Search the subtree below LINE for any TODO entries."
2339 (let ((rest (cdr (memq line lines)))
2340 (re org-todo-line-regexp)
2341 line lv todo)
2342 (catch 'exit
2343 (while (setq line (pop rest))
2344 (if (string-match re line)
2345 (progn
2346 (setq lv (- (match-end 1) (match-beginning 1))
2347 todo (and (match-beginning 2)
2348 (not (member (match-string 2 line)
2349 org-done-keywords))))
2350 ; TODO, not DONE
2351 (if (<= lv level) (throw 'exit nil))
2352 (if todo (throw 'exit t))))))))
2354 ;;;###autoload
2355 (defun org-export-visible (type arg)
2356 "Create a copy of the visible part of the current buffer, and export it.
2357 The copy is created in a temporary buffer and removed after use.
2358 TYPE is the final key (as a string) that also select the export command in
2359 the `C-c C-e' export dispatcher.
2360 As a special case, if the you type SPC at the prompt, the temporary
2361 org-mode file will not be removed but presented to you so that you can
2362 continue to use it. The prefix arg ARG is passed through to the exporting
2363 command."
2364 (interactive
2365 (list (progn
2366 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2367 (read-char-exclusive))
2368 current-prefix-arg))
2369 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ )))
2370 (error "Invalid export key"))
2371 (let* ((binding (cdr (assoc type
2372 '((?a . org-export-as-ascii)
2373 (?A . org-export-as-ascii-to-buffer)
2374 (?\C-a . org-export-as-ascii)
2375 (?b . org-export-as-html-and-open)
2376 (?\C-b . org-export-as-html-and-open)
2377 (?h . org-export-as-html)
2378 (?H . org-export-as-html-to-buffer)
2379 (?R . org-export-region-as-html)
2380 (?D . org-export-as-docbook)
2381 (?x . org-export-as-xoxo)))))
2382 (keepp (equal type ?\ ))
2383 (file buffer-file-name)
2384 (buffer (get-buffer-create "*Org Export Visible*"))
2385 s e)
2386 ;; Need to hack the drawers here.
2387 (save-excursion
2388 (goto-char (point-min))
2389 (while (re-search-forward org-drawer-regexp nil t)
2390 (goto-char (match-beginning 1))
2391 (or (org-invisible-p) (org-flag-drawer nil))))
2392 (with-current-buffer buffer (erase-buffer))
2393 (save-excursion
2394 (setq s (goto-char (point-min)))
2395 (while (not (= (point) (point-max)))
2396 (goto-char (org-find-invisible))
2397 (append-to-buffer buffer s (point))
2398 (setq s (goto-char (org-find-visible))))
2399 (org-cycle-hide-drawers 'all)
2400 (goto-char (point-min))
2401 (unless keepp
2402 ;; Copy all comment lines to the end, to make sure #+ settings are
2403 ;; still available for the second export step. Kind of a hack, but
2404 ;; does do the trick.
2405 (if (looking-at "#[^\r\n]*")
2406 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2407 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2408 (append-to-buffer buffer (1+ (match-beginning 0))
2409 (min (point-max) (1+ (match-end 0))))))
2410 (set-buffer buffer)
2411 (let ((buffer-file-name file)
2412 (org-inhibit-startup t))
2413 (org-mode)
2414 (show-all)
2415 (unless keepp (funcall binding arg))))
2416 (if (not keepp)
2417 (kill-buffer buffer)
2418 (switch-to-buffer-other-window buffer)
2419 (goto-char (point-min)))))
2421 (defun org-find-visible ()
2422 (let ((s (point)))
2423 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2424 (get-char-property s 'invisible)))
2426 (defun org-find-invisible ()
2427 (let ((s (point)))
2428 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2429 (not (get-char-property s 'invisible))))
2432 (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
2434 ;;;###autoload
2435 (defun org-export-as-org (arg &optional hidden ext-plist
2436 to-buffer body-only pub-dir)
2437 "Make a copy wiht not-exporting stuff removed.
2438 The purpose of this function is to provide a way to export the source
2439 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2440 stuff removed. This command will remove the following:
2442 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2443 - comment blocks and trees starting with the COMMENT keyword
2444 - only trees that are consistent with `org-export-select-tags'
2445 and `org-export-exclude-tags'.
2447 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2448 all the others will be ignored (but are present so that the general
2449 mechanism to call publishing functions will work).
2451 EXT-PLIST is a property list with external parameters overriding
2452 org-mode's default settings, but still inferior to file-local
2453 settings. When PUB-DIR is set, use this as the publishing
2454 directory."
2455 (interactive "P")
2456 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2457 ext-plist
2458 (org-infile-export-plist)))
2459 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2460 (filename (concat (file-name-as-directory
2461 (or pub-dir
2462 (org-export-directory :org opt-plist)))
2463 (file-name-sans-extension
2464 (file-name-nondirectory bfname))
2465 ".org"))
2466 (filename (and filename
2467 (if (equal (file-truename filename)
2468 (file-truename bfname))
2469 (concat filename "-source")
2470 filename)))
2471 (backup-inhibited t)
2472 (buffer (find-file-noselect filename))
2473 (region (buffer-string)))
2474 (save-excursion
2475 (switch-to-buffer buffer)
2476 (erase-buffer)
2477 (insert region)
2478 (let ((org-inhibit-startup t)) (org-mode))
2480 ;; Get rid of archived trees
2481 (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
2483 ;; Remove comment environment and comment subtrees
2484 (org-export-remove-comment-blocks-and-subtrees)
2486 ;; Get rid of excluded trees
2487 (org-export-handle-export-tags (plist-get opt-plist :select-tags)
2488 (plist-get opt-plist :exclude-tags))
2490 (when (or (plist-get opt-plist :plain-source)
2491 (not (or (plist-get opt-plist :plain-source)
2492 (plist-get opt-plist :htmlized-source))))
2493 ;; Either nothing special is requested (default call)
2494 ;; or the plain source is explicitly requested
2495 ;; so: save it
2496 (save-buffer))
2497 (when (plist-get opt-plist :htmlized-source)
2498 ;; Make the htmlized version
2499 (require 'htmlize)
2500 (require 'org-html)
2501 (font-lock-fontify-buffer)
2502 (let* ((htmlize-output-type 'css)
2503 (newbuf (htmlize-buffer)))
2504 (with-current-buffer newbuf
2505 (when org-export-htmlized-org-css-url
2506 (goto-char (point-min))
2507 (and (re-search-forward
2508 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2509 nil t)
2510 (replace-match
2511 (format
2512 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2513 org-export-htmlized-org-css-url)
2514 t t)))
2515 (write-file (concat filename ".html")))
2516 (kill-buffer newbuf)))
2517 (set-buffer-modified-p nil)
2518 (kill-buffer (current-buffer)))))
2520 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2521 (defun org-get-current-options ()
2522 "Return a string with current options as keyword options.
2523 Does include HTML export options as well as TODO and CATEGORY stuff."
2524 (require 'org-archive)
2525 (format
2526 "#+TITLE: %s
2527 #+AUTHOR: %s
2528 #+EMAIL: %s
2529 #+DATE: %s
2530 #+DESCRIPTION:
2531 #+KEYWORDS:
2532 #+LANGUAGE: %s
2533 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2534 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2536 #+EXPORT_SELECT_TAGS: %s
2537 #+EXPORT_EXCLUDE_TAGS: %s
2538 #+LINK_UP: %s
2539 #+LINK_HOME: %s
2540 #+CATEGORY: %s
2541 #+SEQ_TODO: %s
2542 #+TYP_TODO: %s
2543 #+PRIORITIES: %c %c %c
2544 #+DRAWERS: %s
2545 #+STARTUP: %s %s %s %s %s
2546 #+TAGS: %s
2547 #+FILETAGS: %s
2548 #+ARCHIVE: %s
2549 #+LINK: %s
2551 (buffer-name) (user-full-name) user-mail-address
2552 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2553 org-export-default-language
2554 org-export-headline-levels
2555 org-export-with-section-numbers
2556 org-export-with-toc
2557 org-export-preserve-breaks
2558 org-export-html-expand
2559 org-export-with-fixed-width
2560 org-export-with-tables
2561 org-export-with-sub-superscripts
2562 org-export-with-special-strings
2563 org-export-with-footnotes
2564 org-export-with-emphasize
2565 org-export-with-timestamps
2566 org-export-with-TeX-macros
2567 org-export-with-LaTeX-fragments
2568 org-export-skip-text-before-1st-heading
2569 org-export-with-drawers
2570 org-export-with-todo-keywords
2571 org-export-with-priority
2572 org-export-with-tags
2573 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2574 (mapconcat 'identity org-export-select-tags " ")
2575 (mapconcat 'identity org-export-exclude-tags " ")
2576 org-export-html-link-up
2577 org-export-html-link-home
2578 (or (ignore-errors
2579 (file-name-sans-extension
2580 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2581 "NOFILENAME")
2582 "TODO FEEDBACK VERIFY DONE"
2583 "Me Jason Marie DONE"
2584 org-highest-priority org-lowest-priority org-default-priority
2585 (mapconcat 'identity org-drawers " ")
2586 (cdr (assoc org-startup-folded
2587 '((nil . "showall") (t . "overview") (content . "content"))))
2588 (if org-odd-levels-only "odd" "oddeven")
2589 (if org-hide-leading-stars "hidestars" "showstars")
2590 (if org-startup-align-all-tables "align" "noalign")
2591 (cond ((eq org-log-done t) "logdone")
2592 ((equal org-log-done 'note) "lognotedone")
2593 ((not org-log-done) "nologdone"))
2594 (or (mapconcat (lambda (x)
2595 (cond
2596 ((equal '(:startgroup) x) "{")
2597 ((equal '(:endgroup) x) "}")
2598 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2599 (t (car x))))
2600 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2601 (mapconcat 'identity org-file-tags " ")
2602 org-archive-location
2603 "org file:~/org/%s.org"
2606 ;;;###autoload
2607 (defun org-insert-export-options-template ()
2608 "Insert into the buffer a template with information for exporting."
2609 (interactive)
2610 (if (not (bolp)) (newline))
2611 (let ((s (org-get-current-options)))
2612 (and (string-match "#\\+CATEGORY" s)
2613 (setq s (substring s 0 (match-beginning 0))))
2614 (insert s)))
2616 (defvar org-table-colgroup-info nil)
2618 (defun org-table-clean-before-export (lines &optional maybe-quoted)
2619 "Check if the table has a marking column.
2620 If yes remove the column and the special lines."
2621 (setq org-table-colgroup-info nil)
2622 (if (memq nil
2623 (mapcar
2624 (lambda (x) (or (string-match "^[ \t]*|-" x)
2625 (string-match
2626 (if maybe-quoted
2627 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2628 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2629 x)))
2630 lines))
2631 (progn
2632 (setq org-table-clean-did-remove-column nil)
2633 (delq nil
2634 (mapcar
2635 (lambda (x)
2636 (cond
2637 ((string-match "^[ \t]*| */ *|" x)
2638 (setq org-table-colgroup-info
2639 (mapcar (lambda (x)
2640 (cond ((member x '("<" "&lt;")) :start)
2641 ((member x '(">" "&gt;")) :end)
2642 ((member x '("<>" "&lt;&gt;")) :startend)
2643 (t nil)))
2644 (org-split-string x "[ \t]*|[ \t]*")))
2645 nil)
2646 (t x)))
2647 lines)))
2648 (setq org-table-clean-did-remove-column t)
2649 (delq nil
2650 (mapcar
2651 (lambda (x)
2652 (cond
2653 ((string-match "^[ \t]*| */ *|" x)
2654 (setq org-table-colgroup-info
2655 (mapcar (lambda (x)
2656 (cond ((member x '("<" "&lt;")) :start)
2657 ((member x '(">" "&gt;")) :end)
2658 ((member x '("<>" "&lt;&gt;")) :startend)
2659 (t nil)))
2660 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2661 nil)
2662 ((string-match "^[ \t]*| *[!_^/] *|" x)
2663 nil) ; ignore this line
2664 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2665 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2666 ;; remove the first column
2667 (replace-match "\\1|" t nil x))))
2668 lines))))
2670 (defun org-export-cleanup-toc-line (s)
2671 "Remove tags and timestamps from lines going into the toc."
2672 (when (memq org-export-with-tags '(not-in-toc nil))
2673 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
2674 (setq s (replace-match "" t t s))))
2675 (when org-export-remove-timestamps-from-toc
2676 (while (string-match org-maybe-keyword-time-regexp s)
2677 (setq s (replace-match "" t t s))))
2678 (while (string-match org-bracket-link-regexp s)
2679 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
2680 t t s)))
2683 (defun org-create-multibrace-regexp (left right n)
2684 "Create a regular expression which will match a balanced sexp.
2685 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2686 as single character strings.
2687 The regexp returned will match the entire expression including the
2688 delimiters. It will also define a single group which contains the
2689 match except for the outermost delimiters. The maximum depth of
2690 stacked delimiters is N. Escaping delimiters is not possible."
2691 (let* ((nothing (concat "[^" left right "]*?"))
2692 (or "\\|")
2693 (re nothing)
2694 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
2695 (while (> n 1)
2696 (setq n (1- n)
2697 re (concat re or next)
2698 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
2699 (concat left "\\(" re "\\)" right)))
2701 (defvar org-match-substring-regexp
2702 (concat
2703 "\\([^\\]\\)\\([_^]\\)\\("
2704 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2705 "\\|"
2706 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
2707 "\\|"
2708 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2709 "The regular expression matching a sub- or superscript.")
2711 (defvar org-match-substring-with-braces-regexp
2712 (concat
2713 "\\([^\\]\\)\\([_^]\\)\\("
2714 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2715 "\\)")
2716 "The regular expression matching a sub- or superscript, forcing braces.")
2719 (defun org-get-text-property-any (pos prop &optional object)
2720 (or (get-text-property pos prop object)
2721 (and (setq pos (next-single-property-change pos prop object))
2722 (get-text-property pos prop object))))
2724 (defun org-export-get-coderef-format (path desc)
2725 (save-match-data
2726 (if (and desc (string-match
2727 (regexp-quote (concat "(" path ")"))
2728 desc))
2729 (replace-match "%s" t t desc)
2730 (or desc "%s"))))
2732 (defun org-export-push-to-kill-ring (format)
2733 "Push buffer content to kill ring.
2734 The depends on the variable `org-export-copy-to-kill'."
2735 (when org-export-copy-to-kill-ring
2736 (kill-new (buffer-string))
2737 (when (fboundp 'x-set-selection)
2738 (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
2739 (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
2740 (message "%s export done, pushed to kill ring and clipboard" format)))
2742 (provide 'org-exp)
2744 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2746 ;;; org-exp.el ends here