Minor fixes
[org-mode.git] / lisp / org-exp.el
blobb8fb2018cc581703d92dcde847a5b0838d3a56b6
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 t1) "-START\n"
1699 content "\n"
1700 "ORG-" (upcase t1) "-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 (org-src-mode)
2223 (set-buffer-modified-p nil)
2224 (org-export-htmlize-region-for-paste
2225 (point-min) (point-max))))
2226 (if (string-match "<pre\\([^>]*\\)>\n?" rtn)
2227 (setq rtn (replace-match
2228 (format "<pre class=\"src src-%s\">\n" lang)
2229 t t rtn))))
2230 (if textareap
2231 (setq rtn (concat
2232 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2233 cols rows)
2234 rtn "</textarea>\n</p>\n"))
2235 (with-temp-buffer
2236 (insert rtn)
2237 (goto-char (point-min))
2238 (while (re-search-forward "[<>&]" nil t)
2239 (replace-match (cdr (assq (char-before)
2240 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2241 t t))
2242 (setq rtn (buffer-string)))
2243 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2244 (unless textareap
2245 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2246 cont rpllbl fmt)))
2247 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2248 ((eq backend 'latex)
2249 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2250 (concat "\n#+BEGIN_LaTeX\n"
2251 (org-add-props (concat "\\begin{verbatim}\n" rtn "\n\\end{verbatim}\n")
2252 '(org-protected t))
2253 "#+END_LaTeX\n\n"))
2254 ((eq backend 'ascii)
2255 ;; This is not HTML or LaTeX, so just make it an example.
2256 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2257 (concat "#+BEGIN_ASCII\n"
2258 (org-add-props
2259 (concat
2260 (mapconcat
2261 (lambda (l) (concat " " l))
2262 (org-split-string rtn "\n")
2263 "\n")
2264 "\n")
2265 '(org-protected t))
2266 "#+END_ASCII\n"))))
2267 (org-add-props rtn nil 'original-indentation indent))))
2269 (defun org-export-number-lines (text backend
2270 &optional skip1 skip2 number cont
2271 replace-labels label-format)
2272 (if (and (not number) (not (eq replace-labels 'keep)))
2273 (setq replace-labels nil)) ;; must use names if no numbers
2274 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2275 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2276 (with-temp-buffer
2277 (insert text)
2278 (goto-char (point-max))
2279 (skip-chars-backward " \t\n\r")
2280 (delete-region (point) (point-max))
2281 (beginning-of-line (- 1 skip2))
2282 (let* ((last (org-current-line))
2283 (n org-export-last-code-line-counter-value)
2284 (nmax (+ n (- last skip1)))
2285 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2287 (cond
2288 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2289 fmt))
2290 ((eq backend 'ascii) fmt)
2291 ((eq backend 'latex) fmt)
2292 ((eq backend 'docbook) fmt)
2293 (t "")))
2294 (label-format (or label-format org-coderef-label-format))
2295 (label-pre (if (string-match "%s" label-format)
2296 (substring label-format 0 (match-beginning 0))
2297 label-format))
2298 (label-post (if (string-match "%s" label-format)
2299 (substring label-format (match-end 0))
2300 ""))
2301 (lbl-re
2302 (concat
2303 ".*?\\S-.*?\\([ \t]*\\("
2304 (regexp-quote label-pre)
2305 "\\([-a-zA-Z0-9_]+\\)"
2306 (regexp-quote label-post)
2307 "\\)\\)"))
2308 ref)
2310 (goto-line (1+ skip1))
2311 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2312 (if number
2313 (insert (format fm (incf n)))
2314 (forward-char 1))
2315 (when (and (not (eq replace-labels 'keep))
2316 (looking-at lbl-re))
2317 (setq ref (match-string 3))
2318 (if replace-labels
2319 (progn
2320 (delete-region (match-beginning 1) (match-end 1))
2321 (push (cons ref n) org-export-code-refs))
2322 (goto-char (match-beginning 2))
2323 (delete-region (match-beginning 2) (match-end 2))
2324 (insert "(" ref ")")
2325 (push (cons ref (concat "(" ref ")")) org-export-code-refs))
2326 (when (eq backend 'html)
2327 (save-excursion
2328 (beginning-of-line 1)
2329 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2330 ref))
2331 (end-of-line 1)
2332 (insert "</span>")))))
2333 (setq org-export-last-code-line-counter-value n)
2334 (goto-char (point-max))
2335 (newline)
2336 (buffer-string))))
2338 (defun org-search-todo-below (line lines level)
2339 "Search the subtree below LINE for any TODO entries."
2340 (let ((rest (cdr (memq line lines)))
2341 (re org-todo-line-regexp)
2342 line lv todo)
2343 (catch 'exit
2344 (while (setq line (pop rest))
2345 (if (string-match re line)
2346 (progn
2347 (setq lv (- (match-end 1) (match-beginning 1))
2348 todo (and (match-beginning 2)
2349 (not (member (match-string 2 line)
2350 org-done-keywords))))
2351 ; TODO, not DONE
2352 (if (<= lv level) (throw 'exit nil))
2353 (if todo (throw 'exit t))))))))
2355 ;;;###autoload
2356 (defun org-export-visible (type arg)
2357 "Create a copy of the visible part of the current buffer, and export it.
2358 The copy is created in a temporary buffer and removed after use.
2359 TYPE is the final key (as a string) that also select the export command in
2360 the `C-c C-e' export dispatcher.
2361 As a special case, if the you type SPC at the prompt, the temporary
2362 org-mode file will not be removed but presented to you so that you can
2363 continue to use it. The prefix arg ARG is passed through to the exporting
2364 command."
2365 (interactive
2366 (list (progn
2367 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2368 (read-char-exclusive))
2369 current-prefix-arg))
2370 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ )))
2371 (error "Invalid export key"))
2372 (let* ((binding (cdr (assoc type
2373 '((?a . org-export-as-ascii)
2374 (?A . org-export-as-ascii-to-buffer)
2375 (?\C-a . org-export-as-ascii)
2376 (?b . org-export-as-html-and-open)
2377 (?\C-b . org-export-as-html-and-open)
2378 (?h . org-export-as-html)
2379 (?H . org-export-as-html-to-buffer)
2380 (?R . org-export-region-as-html)
2381 (?D . org-export-as-docbook)
2382 (?x . org-export-as-xoxo)))))
2383 (keepp (equal type ?\ ))
2384 (file buffer-file-name)
2385 (buffer (get-buffer-create "*Org Export Visible*"))
2386 s e)
2387 ;; Need to hack the drawers here.
2388 (save-excursion
2389 (goto-char (point-min))
2390 (while (re-search-forward org-drawer-regexp nil t)
2391 (goto-char (match-beginning 1))
2392 (or (org-invisible-p) (org-flag-drawer nil))))
2393 (with-current-buffer buffer (erase-buffer))
2394 (save-excursion
2395 (setq s (goto-char (point-min)))
2396 (while (not (= (point) (point-max)))
2397 (goto-char (org-find-invisible))
2398 (append-to-buffer buffer s (point))
2399 (setq s (goto-char (org-find-visible))))
2400 (org-cycle-hide-drawers 'all)
2401 (goto-char (point-min))
2402 (unless keepp
2403 ;; Copy all comment lines to the end, to make sure #+ settings are
2404 ;; still available for the second export step. Kind of a hack, but
2405 ;; does do the trick.
2406 (if (looking-at "#[^\r\n]*")
2407 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2408 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2409 (append-to-buffer buffer (1+ (match-beginning 0))
2410 (min (point-max) (1+ (match-end 0))))))
2411 (set-buffer buffer)
2412 (let ((buffer-file-name file)
2413 (org-inhibit-startup t))
2414 (org-mode)
2415 (show-all)
2416 (unless keepp (funcall binding arg))))
2417 (if (not keepp)
2418 (kill-buffer buffer)
2419 (switch-to-buffer-other-window buffer)
2420 (goto-char (point-min)))))
2422 (defun org-find-visible ()
2423 (let ((s (point)))
2424 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2425 (get-char-property s 'invisible)))
2427 (defun org-find-invisible ()
2428 (let ((s (point)))
2429 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2430 (not (get-char-property s 'invisible))))
2433 (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
2435 ;;;###autoload
2436 (defun org-export-as-org (arg &optional hidden ext-plist
2437 to-buffer body-only pub-dir)
2438 "Make a copy wiht not-exporting stuff removed.
2439 The purpose of this function is to provide a way to export the source
2440 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2441 stuff removed. This command will remove the following:
2443 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2444 - comment blocks and trees starting with the COMMENT keyword
2445 - only trees that are consistent with `org-export-select-tags'
2446 and `org-export-exclude-tags'.
2448 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2449 all the others will be ignored (but are present so that the general
2450 mechanism to call publishing functions will work).
2452 EXT-PLIST is a property list with external parameters overriding
2453 org-mode's default settings, but still inferior to file-local
2454 settings. When PUB-DIR is set, use this as the publishing
2455 directory."
2456 (interactive "P")
2457 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2458 ext-plist
2459 (org-infile-export-plist)))
2460 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2461 (filename (concat (file-name-as-directory
2462 (or pub-dir
2463 (org-export-directory :org opt-plist)))
2464 (file-name-sans-extension
2465 (file-name-nondirectory bfname))
2466 ".org"))
2467 (filename (and filename
2468 (if (equal (file-truename filename)
2469 (file-truename bfname))
2470 (concat filename "-source")
2471 filename)))
2472 (backup-inhibited t)
2473 (buffer (find-file-noselect filename))
2474 (region (buffer-string)))
2475 (save-excursion
2476 (switch-to-buffer buffer)
2477 (erase-buffer)
2478 (insert region)
2479 (let ((org-inhibit-startup t)) (org-mode))
2481 ;; Get rid of archived trees
2482 (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
2484 ;; Remove comment environment and comment subtrees
2485 (org-export-remove-comment-blocks-and-subtrees)
2487 ;; Get rid of excluded trees
2488 (org-export-handle-export-tags (plist-get opt-plist :select-tags)
2489 (plist-get opt-plist :exclude-tags))
2491 (when (or (plist-get opt-plist :plain-source)
2492 (not (or (plist-get opt-plist :plain-source)
2493 (plist-get opt-plist :htmlized-source))))
2494 ;; Either nothing special is requested (default call)
2495 ;; or the plain source is explicitly requested
2496 ;; so: save it
2497 (save-buffer))
2498 (when (plist-get opt-plist :htmlized-source)
2499 ;; Make the htmlized version
2500 (require 'htmlize)
2501 (require 'org-html)
2502 (font-lock-fontify-buffer)
2503 (let* ((htmlize-output-type 'css)
2504 (newbuf (htmlize-buffer)))
2505 (with-current-buffer newbuf
2506 (when org-export-htmlized-org-css-url
2507 (goto-char (point-min))
2508 (and (re-search-forward
2509 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2510 nil t)
2511 (replace-match
2512 (format
2513 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2514 org-export-htmlized-org-css-url)
2515 t t)))
2516 (write-file (concat filename ".html")))
2517 (kill-buffer newbuf)))
2518 (set-buffer-modified-p nil)
2519 (kill-buffer (current-buffer)))))
2521 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2522 (defun org-get-current-options ()
2523 "Return a string with current options as keyword options.
2524 Does include HTML export options as well as TODO and CATEGORY stuff."
2525 (require 'org-archive)
2526 (format
2527 "#+TITLE: %s
2528 #+AUTHOR: %s
2529 #+EMAIL: %s
2530 #+DATE: %s
2531 #+DESCRIPTION:
2532 #+KEYWORDS:
2533 #+LANGUAGE: %s
2534 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2535 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2537 #+EXPORT_SELECT_TAGS: %s
2538 #+EXPORT_EXCLUDE_TAGS: %s
2539 #+LINK_UP: %s
2540 #+LINK_HOME: %s
2541 #+CATEGORY: %s
2542 #+SEQ_TODO: %s
2543 #+TYP_TODO: %s
2544 #+PRIORITIES: %c %c %c
2545 #+DRAWERS: %s
2546 #+STARTUP: %s %s %s %s %s
2547 #+TAGS: %s
2548 #+FILETAGS: %s
2549 #+ARCHIVE: %s
2550 #+LINK: %s
2552 (buffer-name) (user-full-name) user-mail-address
2553 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2554 org-export-default-language
2555 org-export-headline-levels
2556 org-export-with-section-numbers
2557 org-export-with-toc
2558 org-export-preserve-breaks
2559 org-export-html-expand
2560 org-export-with-fixed-width
2561 org-export-with-tables
2562 org-export-with-sub-superscripts
2563 org-export-with-special-strings
2564 org-export-with-footnotes
2565 org-export-with-emphasize
2566 org-export-with-timestamps
2567 org-export-with-TeX-macros
2568 org-export-with-LaTeX-fragments
2569 org-export-skip-text-before-1st-heading
2570 org-export-with-drawers
2571 org-export-with-todo-keywords
2572 org-export-with-priority
2573 org-export-with-tags
2574 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2575 (mapconcat 'identity org-export-select-tags " ")
2576 (mapconcat 'identity org-export-exclude-tags " ")
2577 org-export-html-link-up
2578 org-export-html-link-home
2579 (or (ignore-errors
2580 (file-name-sans-extension
2581 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2582 "NOFILENAME")
2583 "TODO FEEDBACK VERIFY DONE"
2584 "Me Jason Marie DONE"
2585 org-highest-priority org-lowest-priority org-default-priority
2586 (mapconcat 'identity org-drawers " ")
2587 (cdr (assoc org-startup-folded
2588 '((nil . "showall") (t . "overview") (content . "content"))))
2589 (if org-odd-levels-only "odd" "oddeven")
2590 (if org-hide-leading-stars "hidestars" "showstars")
2591 (if org-startup-align-all-tables "align" "noalign")
2592 (cond ((eq org-log-done t) "logdone")
2593 ((equal org-log-done 'note) "lognotedone")
2594 ((not org-log-done) "nologdone"))
2595 (or (mapconcat (lambda (x)
2596 (cond
2597 ((equal '(:startgroup) x) "{")
2598 ((equal '(:endgroup) x) "}")
2599 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2600 (t (car x))))
2601 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2602 (mapconcat 'identity org-file-tags " ")
2603 org-archive-location
2604 "org file:~/org/%s.org"
2607 ;;;###autoload
2608 (defun org-insert-export-options-template ()
2609 "Insert into the buffer a template with information for exporting."
2610 (interactive)
2611 (if (not (bolp)) (newline))
2612 (let ((s (org-get-current-options)))
2613 (and (string-match "#\\+CATEGORY" s)
2614 (setq s (substring s 0 (match-beginning 0))))
2615 (insert s)))
2617 (defvar org-table-colgroup-info nil)
2619 (defun org-table-clean-before-export (lines &optional maybe-quoted)
2620 "Check if the table has a marking column.
2621 If yes remove the column and the special lines."
2622 (setq org-table-colgroup-info nil)
2623 (if (memq nil
2624 (mapcar
2625 (lambda (x) (or (string-match "^[ \t]*|-" x)
2626 (string-match
2627 (if maybe-quoted
2628 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2629 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2630 x)))
2631 lines))
2632 (progn
2633 (setq org-table-clean-did-remove-column nil)
2634 (delq nil
2635 (mapcar
2636 (lambda (x)
2637 (cond
2638 ((string-match "^[ \t]*| */ *|" x)
2639 (setq org-table-colgroup-info
2640 (mapcar (lambda (x)
2641 (cond ((member x '("<" "&lt;")) :start)
2642 ((member x '(">" "&gt;")) :end)
2643 ((member x '("<>" "&lt;&gt;")) :startend)
2644 (t nil)))
2645 (org-split-string x "[ \t]*|[ \t]*")))
2646 nil)
2647 (t x)))
2648 lines)))
2649 (setq org-table-clean-did-remove-column t)
2650 (delq nil
2651 (mapcar
2652 (lambda (x)
2653 (cond
2654 ((string-match "^[ \t]*| */ *|" x)
2655 (setq org-table-colgroup-info
2656 (mapcar (lambda (x)
2657 (cond ((member x '("<" "&lt;")) :start)
2658 ((member x '(">" "&gt;")) :end)
2659 ((member x '("<>" "&lt;&gt;")) :startend)
2660 (t nil)))
2661 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2662 nil)
2663 ((string-match "^[ \t]*| *[!_^/] *|" x)
2664 nil) ; ignore this line
2665 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2666 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2667 ;; remove the first column
2668 (replace-match "\\1|" t nil x))))
2669 lines))))
2671 (defun org-export-cleanup-toc-line (s)
2672 "Remove tags and timestamps from lines going into the toc."
2673 (when (memq org-export-with-tags '(not-in-toc nil))
2674 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
2675 (setq s (replace-match "" t t s))))
2676 (when org-export-remove-timestamps-from-toc
2677 (while (string-match org-maybe-keyword-time-regexp s)
2678 (setq s (replace-match "" t t s))))
2679 (while (string-match org-bracket-link-regexp s)
2680 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
2681 t t s)))
2684 (defun org-create-multibrace-regexp (left right n)
2685 "Create a regular expression which will match a balanced sexp.
2686 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2687 as single character strings.
2688 The regexp returned will match the entire expression including the
2689 delimiters. It will also define a single group which contains the
2690 match except for the outermost delimiters. The maximum depth of
2691 stacked delimiters is N. Escaping delimiters is not possible."
2692 (let* ((nothing (concat "[^" left right "]*?"))
2693 (or "\\|")
2694 (re nothing)
2695 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
2696 (while (> n 1)
2697 (setq n (1- n)
2698 re (concat re or next)
2699 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
2700 (concat left "\\(" re "\\)" right)))
2702 (defvar org-match-substring-regexp
2703 (concat
2704 "\\([^\\]\\)\\([_^]\\)\\("
2705 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2706 "\\|"
2707 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
2708 "\\|"
2709 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2710 "The regular expression matching a sub- or superscript.")
2712 (defvar org-match-substring-with-braces-regexp
2713 (concat
2714 "\\([^\\]\\)\\([_^]\\)\\("
2715 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2716 "\\)")
2717 "The regular expression matching a sub- or superscript, forcing braces.")
2720 (defun org-get-text-property-any (pos prop &optional object)
2721 (or (get-text-property pos prop object)
2722 (and (setq pos (next-single-property-change pos prop object))
2723 (get-text-property pos prop object))))
2725 (defun org-export-get-coderef-format (path desc)
2726 (save-match-data
2727 (if (and desc (string-match
2728 (regexp-quote (concat "(" path ")"))
2729 desc))
2730 (replace-match "%s" t t desc)
2731 (or desc "%s"))))
2733 (defun org-export-push-to-kill-ring (format)
2734 "Push buffer content to kill ring.
2735 The depends on the variable `org-export-copy-to-kill'."
2736 (when org-export-copy-to-kill-ring
2737 (kill-new (buffer-string))
2738 (when (fboundp 'x-set-selection)
2739 (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
2740 (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
2741 (message "%s export done, pushed to kill ring and clipboard" format)))
2743 (provide 'org-exp)
2745 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2747 ;;; org-exp.el ends here