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