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
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 (require 'org-exp-blocks
)
36 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
37 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
38 (declare-function org-export-html-preprocess
"org-html" (parameters))
39 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
40 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
41 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
42 (declare-function htmlize-buffer
"ext:htmlize" (&optional buffer
))
43 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
44 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
45 (defgroup org-export nil
46 "Options for exporting org-listings."
50 (defgroup org-export-general nil
51 "General options for exporting Org-mode files."
52 :tag
"Org Export General"
55 (defcustom org-export-allow-BIND
'confirm
56 "Non-nil means, allow #+BIND to define local variable values for export.
57 This is a potential security risk, which is why the user must confirm the
59 :group
'org-export-general
61 (const :tag
"Never" nil
)
62 (const :tag
"Always" t
)
63 (const :tag
"Make the user confirm for each file" confirm
)))
66 (defvar org-export-publishing-directory nil
)
68 (defcustom org-export-show-temporary-export-buffer t
69 "Non-nil means, show buffer after exporting to temp buffer.
70 When Org exports to a file, the buffer visiting that file is ever
71 shown, but remains buried. However, when exporting to a temporary
72 buffer, that buffer is popped up in a second window. When this variable
73 is nil, the buffer remains buried also in these cases."
74 :group
'org-export-general
77 (defcustom org-export-copy-to-kill-ring t
78 "Non-nil means, exported stuff will also be pushed onto the kill ring."
79 :group
'org-export-general
82 (defcustom org-export-run-in-background nil
83 "Non-nil means export and publishing commands will run in background.
84 This works by starting up a separate Emacs process visiting the same file
85 and doing the export from there.
86 Not all export commands are affected by this - only the ones which
87 actually write to a file, and that do not depend on the buffer state.
89 If this option is nil, you can still get background export by calling
90 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
92 If this option is t, the double prefix can be used to exceptionally
93 force an export command into the current process."
94 :group
'org-export-general
97 (defcustom org-export-select-tags
'("export")
98 "Tags that select a tree for export.
99 If any such tag is found in a buffer, all trees that do not carry one
100 of these tags will be deleted before export.
101 Inside trees that are selected like this, you can still deselect a
102 subtree by tagging it with one of the `org-export-exclude-tags'."
103 :group
'org-export-general
104 :type
'(repeat (string :tag
"Tag")))
106 (defcustom org-export-exclude-tags
'("noexport")
107 "Tags that exclude a tree from export.
108 All trees carrying any of these tags will be excluded from export.
109 This is without condition, so even subtrees inside that carry one of the
110 `org-export-select-tags' will be removed."
111 :group
'org-export-general
112 :type
'(repeat (string :tag
"Tag")))
114 ;; FIXME: rename, this is a general variable
115 (defcustom org-export-html-expand t
116 "Non-nil means, for HTML export, treat @<...> as HTML tag.
117 When nil, these tags will be exported as plain text and therefore
118 not be interpreted by a browser.
120 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
121 :group
'org-export-html
122 :group
'org-export-general
125 (defcustom org-export-with-special-strings t
126 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
127 When this option is turned on, these strings will be exported as:
130 -----+----------+--------
136 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
137 :group
'org-export-translation
140 (defcustom org-export-html-link-up
""
141 "Where should the \"UP\" link of exported HTML pages lead?"
142 :group
'org-export-html
143 :group
'org-export-general
144 :type
'(string :tag
"File or URL"))
146 (defcustom org-export-html-link-home
""
147 "Where should the \"HOME\" link of exported HTML pages lead?"
148 :group
'org-export-html
149 :group
'org-export-general
150 :type
'(string :tag
"File or URL"))
152 (defcustom org-export-language-setup
153 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
154 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
155 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
156 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
157 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
158 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
159 ("es" "Autor" "Fecha" "Índice" "Pies de página")
160 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
161 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
162 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
163 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
164 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
165 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
166 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
167 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
168 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
169 ("pl" "Autor" "Data" "Spis treści" "Przypis")
170 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
171 "Terms used in export text, translated to different languages.
172 Use the variable `org-export-default-language' to set the language,
173 or use the +OPTION lines for a per-file setting."
174 :group
'org-export-general
177 (string :tag
"HTML language tag")
178 (string :tag
"Author")
180 (string :tag
"Table of Contents")
181 (string :tag
"Footnotes"))))
183 (defcustom org-export-default-language
"en"
184 "The default language of HTML export, as a string.
185 This should have an association in `org-export-language-setup'."
186 :group
'org-export-general
189 (defvar org-export-page-description
""
190 "The page description, for the XHTML meta tag.
191 This is best set with the #+DESCRIPTION line in a file, it does not make
192 sense to set this globally.")
194 (defvar org-export-page-keywords
""
195 "The page description, for the XHTML meta tag.
196 This is best set with the #+KEYWORDS line in a file, it does not make
197 sense to set this globally.")
199 (defcustom org-export-skip-text-before-1st-heading nil
200 "Non-nil means, skip all text before the first headline when exporting.
201 When nil, that text is exported as well."
202 :group
'org-export-general
205 (defcustom org-export-headline-levels
3
206 "The last level which is still exported as a headline.
207 Inferior levels will produce itemize lists when exported.
208 Note that a numeric prefix argument to an exporter function overrides
211 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
212 :group
'org-export-general
215 (defcustom org-export-with-section-numbers t
216 "Non-nil means, add section numbers to headlines when exporting.
218 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
219 :group
'org-export-general
222 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
223 "Format of section numbers for export.
224 The variable has two components.
225 1. A list of lists, each indicating a counter type and a separator.
226 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
227 It causes causes numeric, alphabetic, or roman counters, respectively.
228 The separator is only used if another counter for a subsection is being
230 If there are more numbered section levels than entries in this lists,
231 then the last entry will be reused.
232 2. A terminator string that will be added after the entire
234 :group
'org-export-general
238 (string :tag
"Counter Type")
239 (string :tag
"Separator ")))
240 (string :tag
"Terminator")))
242 (defcustom org-export-with-toc t
243 "Non-nil means, create a table of contents in exported files.
244 The TOC contains headlines with levels up to`org-export-headline-levels'.
245 When an integer, include levels up to N in the toc, this may then be
246 different from `org-export-headline-levels', but it will not be allowed
247 to be larger than the number of headline levels.
248 When nil, no table of contents is made.
250 Headlines which contain any TODO items will be marked with \"(*)\" in
251 ASCII export, and with red color in HTML output, if the option
252 `org-export-mark-todo-in-toc' is set.
254 In HTML output, the TOC will be clickable.
256 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
258 :group
'org-export-general
260 (const :tag
"No Table of Contents" nil
)
261 (const :tag
"Full Table of Contents" t
)
262 (integer :tag
"TOC to level")))
264 (defcustom org-export-mark-todo-in-toc nil
265 "Non-nil means, mark TOC lines that contain any open TODO items."
266 :group
'org-export-general
269 (defcustom org-export-with-todo-keywords t
270 "Non-nil means, include TODO keywords in export.
271 When nil, remove all these keywords from the export."
272 :group
'org-export-general
275 (defcustom org-export-with-priority nil
276 "Non-nil means, include priority cookies in export.
277 When nil, remove priority cookies for export."
278 :group
'org-export-general
281 (defcustom org-export-preserve-breaks nil
282 "Non-nil means, preserve all line breaks when exporting.
283 Normally, in HTML output paragraphs will be reformatted. In ASCII
284 export, line breaks will always be preserved, regardless of this variable.
286 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
287 :group
'org-export-general
290 (defcustom org-export-with-archived-trees
'headline
291 "Whether subtrees with the ARCHIVE tag should be exported.
292 This can have three different values
293 nil Do not export, pretend this tree is not present
294 t Do export the entire tree
295 headline Only export the headline, but skip the tree below it."
296 :group
'org-export-general
299 (const :tag
"not at all" nil
)
300 (const :tag
"headline only" 'headline
)
301 (const :tag
"entirely" t
)))
303 (defcustom org-export-author-info t
304 "Non-nil means, insert author name and email into the exported file.
306 This option can also be set with the +OPTIONS line,
307 e.g. \"author-info:nil\"."
308 :group
'org-export-general
311 (defcustom org-export-creator-info t
312 "Non-nil means, the postamble should contain a creator sentence.
313 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
314 :group
'org-export-general
317 (defcustom org-export-time-stamp-file t
318 "Non-nil means, insert a time stamp into the exported file.
319 The time stamp shows when the file was created.
321 This option can also be set with the +OPTIONS line,
322 e.g. \"timestamp:nil\"."
323 :group
'org-export-general
326 (defcustom org-export-with-timestamps t
327 "If nil, do not export time stamps and associated keywords."
328 :group
'org-export-general
331 (defcustom org-export-remove-timestamps-from-toc t
332 "If t, remove timestamps from the table of contents entries."
333 :group
'org-export-general
336 (defcustom org-export-with-tags
'not-in-toc
337 "If nil, do not export tags, just remove them from headlines.
338 If this is the symbol `not-in-toc', tags will be removed from table of
339 contents entries, but still be shown in the headlines of the document.
341 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
342 :group
'org-export-general
344 (const :tag
"Off" nil
)
345 (const :tag
"Not in TOC" not-in-toc
)
346 (const :tag
"On" t
)))
348 (defcustom org-export-with-drawers nil
349 "Non-nil means, export with drawers like the property drawer.
350 When t, all drawers are exported. This may also be a list of
351 drawer names to export."
352 :group
'org-export-general
354 (const :tag
"All drawers" t
)
355 (const :tag
"None" nil
)
356 (repeat :tag
"Selected drawers"
357 (string :tag
"Drawer name"))))
359 (defvar org-export-preprocess-hook nil
360 "Hook for preprocessing an export buffer.
361 Pretty much the first thing when exporting is running this hook.")
363 (defvar org-export-preprocess-after-include-files-hook nil
364 "Hook for preprocessing an export buffer.
365 This is run after the contents of included files have been inserted.")
367 (defvar org-export-preprocess-after-tree-selection-hook nil
368 "Hook for preprocessing an export buffer.
369 This is run after selection of trees to be exported has happened.
370 This selection includes tags-based selection, as well as removal
371 of commented and archived trees.")
373 (defvar org-export-preprocess-after-blockquote-hook nil
374 "Hook for preprocessing an export buffer.
375 This is run after blockquote/quote/verse/center have been marked
378 (defvar org-export-preprocess-before-backend-specifics-hook nil
379 "Hook run before backend-specific functions are called during preprocessing.")
381 (defvar org-export-preprocess-final-hook nil
382 "Hook for preprocessing an export buffer.
383 This is run as the last thing in the preprocessing buffer, just before
384 returning the buffer string to the backend.")
386 (defgroup org-export-translation nil
387 "Options for translating special ascii sequences for the export backends."
388 :tag
"Org Export Translation"
391 (defcustom org-export-with-emphasize t
392 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
393 If the export target supports emphasizing text, the word will be
394 typeset in bold, italic, or underlined, respectively. Works only for
395 single words, but you can say: I *really* *mean* *this*.
396 Not all export backends support this.
398 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
399 :group
'org-export-translation
402 (defcustom org-export-with-footnotes t
403 "If nil, export [1] as a footnote marker.
404 Lines starting with [1] will be formatted as footnotes.
406 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
407 :group
'org-export-translation
410 (defcustom org-export-with-sub-superscripts t
411 "Non-nil means, interpret \"_\" and \"^\" for export.
412 When this option is turned on, you can use TeX-like syntax for sub- and
413 superscripts. Several characters after \"_\" or \"^\" will be
414 considered as a single item - so grouping with {} is normally not
415 needed. For example, the following things will be parsed as single
416 sub- or superscripts.
418 10^24 or 10^tau several digits will be considered 1 item.
419 10^-12 or 10^-tau a leading sign with digits or a word
420 x^2-y^3 will be read as x^2 - y^3, because items are
421 terminated by almost any nonword/nondigit char.
422 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
424 Still, ambiguity is possible - so when in doubt use {} to enclose the
425 sub/superscript. If you set this variable to the symbol `{}',
426 the braces are *required* in order to trigger interpretations as
427 sub/superscript. This can be helpful in documents that need \"_\"
428 frequently in plain text.
430 Not all export backends support this, but HTML does.
432 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
433 :group
'org-export-translation
435 (const :tag
"Always interpret" t
)
436 (const :tag
"Only with braces" {})
437 (const :tag
"Never interpret" nil
)))
439 (defcustom org-export-with-TeX-macros t
440 "Non-nil means, interpret simple TeX-like macros when exporting.
441 For example, HTML export converts \\alpha to α and \\AA to Å.
442 Not only real TeX macros will work here, but the standard HTML entities
443 for math can be used as macro names as well. For a list of supported
444 names in HTML export, see the constant `org-html-entities'.
445 Not all export backends support this.
447 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
448 :group
'org-export-translation
449 :group
'org-export-latex
452 (defcustom org-export-with-LaTeX-fragments nil
453 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
454 When set, the exporter will find LaTeX environments if the \\begin line is
455 the first non-white thing on a line. It will also find the math delimiters
456 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
459 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
461 The default is nil, because this option needs the `dvipng' program which
462 is not available on all systems."
463 :group
'org-export-translation
464 :group
'org-export-latex
467 (defcustom org-export-with-fixed-width t
468 "Non-nil means, lines starting with \":\" will be in fixed width font.
469 This can be used to have pre-formatted text, fragments of code etc. For
471 : ;; Some Lisp examples
474 will be looking just like this in also HTML. See also the QUOTE keyword.
475 Not all export backends support this.
477 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
478 :group
'org-export-translation
481 (defcustom org-match-sexp-depth
3
482 "Number of stacked braces for sub/superscript matching.
483 This has to be set before loading org.el to be effective."
484 :group
'org-export-translation
487 (defgroup org-export-tables nil
488 "Options for exporting tables in Org-mode."
489 :tag
"Org Export Tables"
492 (defcustom org-export-with-tables t
493 "If non-nil, lines starting with \"|\" define a table.
496 | Name | Address | Birthday |
497 |-------------+----------+-----------|
498 | Arthur Dent | England | 29.2.2100 |
500 Not all export backends support this.
502 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
503 :group
'org-export-tables
506 (defcustom org-export-highlight-first-table-line t
507 "Non-nil means, highlight the first table line.
508 In HTML export, this means use <th> instead of <td>.
509 In tables created with table.el, this applies to the first table line.
510 In Org-mode tables, all lines before the first horizontal separator
511 line will be formatted with <th> tags."
512 :group
'org-export-tables
515 (defcustom org-export-table-remove-special-lines t
516 "Remove special lines and marking characters in calculating tables.
517 This removes the special marking character column from tables that are set
518 up for spreadsheet calculations. It also removes the entire lines
519 marked with `!', `_', or `^'. The lines with `$' are kept, because
520 the values of constants may be useful to have."
521 :group
'org-export-tables
524 (defcustom org-export-prefer-native-exporter-for-tables nil
525 "Non-nil means, always export tables created with table.el natively.
526 Natively means, use the HTML code generator in table.el.
527 When nil, Org-mode's own HTML generator is used when possible (i.e. if
528 the table does not use row- or column-spanning). This has the
529 advantage, that the automatic HTML conversions for math symbols and
530 sub/superscripts can be applied. Org-mode's HTML generator is also
532 :group
'org-export-tables
536 (defgroup org-export-xml nil
537 "Options specific for XML export of Org-mode files."
538 :tag
"Org Export XML"
543 ;;; Variables, constants, and parameter plists
545 (defconst org-level-max
20)
547 (defvar org-current-export-file nil
) ; dynamically scoped parameter
548 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
549 (defvar org-export-opt-plist nil
550 "Contains the current option plist.")
551 (defvar org-last-level nil
) ; dynamically scoped variable
552 (defvar org-min-level nil
) ; dynamically scoped variable
553 (defvar org-levels-open nil
) ; dynamically scoped parameter
555 (defconst org-export-plist-vars
556 '((:link-up nil org-export-html-link-up
)
557 (:link-home nil org-export-html-link-home
)
558 (:language nil org-export-default-language
)
559 (:keywords nil org-export-page-keywords
)
560 (:description nil org-export-page-description
)
561 (:customtime nil org-display-custom-times
)
562 (:headline-levels
"H" org-export-headline-levels
)
563 (:section-numbers
"num" org-export-with-section-numbers
)
564 (:section-number-format nil org-export-section-number-format
)
565 (:table-of-contents
"toc" org-export-with-toc
)
566 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
567 (:archived-trees nil org-export-with-archived-trees
)
568 (:emphasize
"*" org-export-with-emphasize
)
569 (:sub-superscript
"^" org-export-with-sub-superscripts
)
570 (:special-strings
"-" org-export-with-special-strings
)
571 (:footnotes
"f" org-export-with-footnotes
)
572 (:drawers
"d" org-export-with-drawers
)
573 (:tags
"tags" org-export-with-tags
)
574 (:todo-keywords
"todo" org-export-with-todo-keywords
)
575 (:priority
"pri" org-export-with-priority
)
576 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
577 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
578 (:latex-listings nil org-export-latex-listings
)
579 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
580 (:fixed-width
":" org-export-with-fixed-width
)
581 (:timestamps
"<" org-export-with-timestamps
)
582 (:author-info
"author" org-export-author-info
)
583 (:creator-info
"creator" org-export-creator-info
)
584 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
585 (:tables
"|" org-export-with-tables
)
586 (:table-auto-headline nil org-export-highlight-first-table-line
)
587 (:style-include-default nil org-export-html-style-include-default
)
588 (:style-include-scripts nil org-export-html-style-include-scripts
)
589 (:style nil org-export-html-style
)
590 (:style-extra nil org-export-html-style-extra
)
591 (:agenda-style nil org-agenda-export-html-style
)
592 (:convert-org-links nil org-export-html-link-org-files-as-html
)
593 (:inline-images nil org-export-html-inline-images
)
594 (:html-extension nil org-export-html-extension
)
595 (:xml-declaration nil org-export-html-xml-declaration
)
596 (:html-table-tag nil org-export-html-table-tag
)
597 (:expand-quoted-html
"@" org-export-html-expand
)
598 (:timestamp nil org-export-html-with-timestamp
)
599 (:publishing-directory nil org-export-publishing-directory
)
600 (:preamble nil org-export-html-preamble
)
601 (:postamble nil org-export-html-postamble
)
602 (:auto-preamble nil org-export-html-auto-preamble
)
603 (:auto-postamble nil org-export-html-auto-postamble
)
604 (:author nil user-full-name
)
605 (:email nil user-mail-address
)
606 (:select-tags nil org-export-select-tags
)
607 (:exclude-tags nil org-export-exclude-tags
)
609 (:latex-image-options nil org-export-latex-image-default-option
))
610 "List of properties that represent export/publishing variables.
611 Each element is a list of 3 items:
612 1. The property that is used internally, and also for org-publish-project-alist
613 2. The string that can be used in the OPTION lines to set this option,
614 or nil if this option cannot be changed in this way
615 3. The customization variable that sets the default for this option."
618 (defun org-default-export-plist ()
619 "Return the property list with default settings for the export variables."
620 (let* ((infile (org-infile-export-plist))
621 (letbind (plist-get infile
:let-bind
))
622 (l org-export-plist-vars
) rtn e s v
)
623 (while (setq e
(pop l
))
626 ((assq s letbind
) (nth 1 (assq s letbind
)))
627 ((boundp s
) (symbol-value s
))
629 rtn
(cons (car e
) (cons v rtn
))))
632 (defvar org-export-inbuffer-options-extra nil
633 "List of additional in-buffer options that should be detected.
634 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
635 etc. Extensions can add to this list to get their options detected, and they
636 can then add a function to `org-export-options-filters' to process these
638 Each element in this list must be a list, with the in-buffer keyword as car,
639 and a property (a symbol) as the next element. All occurrences of the
640 keyword will be found, the values concatenated with a space character
641 in between, and the result stored in the export options property list.")
643 (defvar org-export-options-filters nil
644 "Functions to be called to finalize the export/publishing options.
645 All these options are stored in a property list, and each of the functions
646 in this hook gets a chance to modify this property list. Each function
647 must accept the property list as an argument, and must return the (possibly
650 ;; FIXME: should we fold case here?
651 (defun org-infile-export-plist ()
652 "Return the property list with file-local settings for export."
656 (goto-char (point-min))
657 (let ((re (org-make-options-regexp
659 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
660 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
661 "LATEX_HEADER" "LATEX_CLASS"
662 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
663 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND")
664 (mapcar 'car org-export-inbuffer-options-extra
))))
665 p key val text options a pr style
666 latex-header latex-class macros letbind
667 ext-setup-or-nil setup-contents
(start 0))
668 (while (or (and ext-setup-or-nil
669 (string-match re ext-setup-or-nil start
)
670 (setq start
(match-end 0)))
671 (and (setq ext-setup-or-nil nil start
0)
672 (re-search-forward re nil t
)))
673 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
674 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
676 ((setq a
(assoc key org-export-inbuffer-options-extra
))
678 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
679 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
680 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
681 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
682 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
683 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
684 ((string-equal key
"DESCRIPTION")
685 (setq p
(plist-put p
:description val
)))
686 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
687 ((string-equal key
"STYLE")
688 (setq style
(concat style
"\n" val
)))
689 ((string-equal key
"LATEX_HEADER")
690 (setq latex-header
(concat latex-header
"\n" val
)))
691 ((string-equal key
"LATEX_CLASS")
692 (setq latex-class val
))
693 ((string-equal key
"TEXT")
694 (setq text
(if text
(concat text
"\n" val
) val
)))
695 ((string-equal key
"OPTIONS")
696 (setq options
(concat val
" " options
)))
697 ((string-equal key
"BIND")
698 (push (read (concat "(" val
")")) letbind
))
699 ((string-equal key
"LINK_UP")
700 (setq p
(plist-put p
:link-up val
)))
701 ((string-equal key
"LINK_HOME")
702 (setq p
(plist-put p
:link-home val
)))
703 ((string-equal key
"EXPORT_SELECT_TAGS")
704 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
705 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
706 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
707 ((string-equal key
"MACRO")
709 ((equal key
"SETUPFILE")
710 (setq setup-contents
(org-file-contents
712 (org-remove-double-quotes
715 (if (not ext-setup-or-nil
)
716 (setq ext-setup-or-nil setup-contents start
0)
717 (setq ext-setup-or-nil
718 (concat (substring ext-setup-or-nil
0 start
)
719 "\n" setup-contents
"\n"
720 (substring ext-setup-or-nil start
)))))))
721 (setq p
(plist-put p
:text text
))
722 (when (and letbind
(org-export-confirm-letbind))
723 (setq p
(plist-put p
:let-bind letbind
)))
724 (when style
(setq p
(plist-put p
:style-extra style
)))
726 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
728 (setq p
(plist-put p
:latex-class latex-class
)))
730 (setq p
(org-export-add-options-to-plist p options
)))
731 ;; Add macro definitions
732 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
733 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
735 p
:macro-modification-time
736 (and (buffer-file-name)
737 (file-exists-p (buffer-file-name))
739 "(eval (format-time-string \"$1\" '"
740 (prin1-to-string (nth 5 (file-attributes
741 (buffer-file-name))))
743 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
744 (file-name-nondirectory
745 (buffer-file-name)))))
746 (while (setq val
(pop macros
))
747 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
750 (concat ":macro-" (downcase (match-string 1 val
))))
751 (org-export-interpolate-newlines (match-string 2 val
))))))
754 (defun org-export-interpolate-newlines (s)
755 (while (string-match "\\\\n" s
)
756 (setq s
(replace-match "\n" t t s
)))
759 (defvar org-export-allow-BIND-local nil
)
760 (defun org-export-confirm-letbind ()
761 "Can we use #+BIND values during export?
762 By default this will ask fro confirmation by the user, to divert possible
765 ((not org-export-allow-BIND
) nil
)
766 ((eq org-export-allow-BIND t
) t
)
767 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
768 org-export-allow-BIND-local
)
769 (t (org-set-local 'org-export-allow-BIND-local
770 (yes-or-no-p "Allow BIND values in this buffer? ")))))
772 (defun org-install-letbind ()
773 "Install the values from #+BIND lines as local variables."
774 (let ((letbind (plist-get org-export-opt-plist
:let-bind
)))
776 (org-set-local (caar letbind
) (nth 1 (pop letbind
))))))
778 (defun org-export-add-options-to-plist (p options
)
779 "Parse an OPTIONS line and set values in the property list P."
782 (let ((op org-export-plist-vars
))
783 (while (setq o
(pop op
))
785 (string-match (concat (regexp-quote (nth 1 o
))
786 ":\\([^ \t\n\r;,.]*\\)")
788 (setq p
(plist-put p
(car o
)
789 (car (read-from-string
790 (match-string 1 options
))))))))))
793 (defun org-export-add-subtree-options (p pos
)
794 "Add options in subtree at position POS to property list P."
797 (when (org-at-heading-p)
799 ;; This is actually read in `org-export-get-title-from-subtree'
800 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
801 ;; (setq p (plist-put p :title a)))
802 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
803 (setq p
(plist-put p
:text a
)))
804 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
805 (setq p
(plist-put p
:author a
)))
806 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
807 (setq p
(plist-put p
:date a
)))
808 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
809 (setq p
(org-export-add-options-to-plist p a
)))))
812 (defun org-export-directory (type plist
)
813 (let* ((val (plist-get plist
:publishing-directory
))
815 (or (cdr (assoc type val
)) ".")
819 (defun org-export-process-option-filters (plist)
820 (let ((functions org-export-options-filters
) f
)
821 (while (setq f
(pop functions
))
822 (setq plist
(funcall f plist
))))
826 (defun org-export (&optional arg
)
827 "Export dispatcher for Org-mode.
828 When `org-export-run-in-background' is non-nil, try to run the command
829 in the background. This will be done only for commands that write
830 to a file. For details see the docstring of `org-export-run-in-background'.
832 The prefix argument ARG will be passed to the exporter. However, if
833 ARG is a double universal prefix `C-u C-u', that means to inverse the
834 value of `org-export-run-in-background'."
836 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
837 (help "[t] insert the export option template
838 \[v] limit export to visible part of outline tree
840 \[a] export as ASCII [A] to temporary buffer
842 \[h] export as HTML [H] to temporary buffer [R] export region
843 \[b] export as HTML and open in browser
845 \[l] export as LaTeX [L] to temporary buffer
846 \[p] export as LaTeX and process to PDF
847 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
849 \[D] export as DocBook
850 \[V] export as DocBook, process to PDF, and open the resulting PDF document
853 \[g] export using Wes Hardaker's generic exporter
855 \[i] export current file as iCalendar file
856 \[I] export all agenda files as iCalendar files
857 \[c] export agenda files into combined iCalendar file
859 \[F] publish current file [P] publish current project
860 \[X] publish a project... [E] publish every projects")
862 '((?t org-insert-export-options-template nil
)
863 (?v org-export-visible nil
)
864 (?a org-export-as-ascii t
)
865 (?A org-export-as-ascii-to-buffer t
)
866 (?h org-export-as-html t
)
867 (?b org-export-as-html-and-open t
)
868 (?H org-export-as-html-to-buffer nil
)
869 (?R org-export-region-as-html nil
)
870 (?x org-export-as-xoxo t
)
871 (?g org-export-generic t
)
872 (?D org-export-as-docbook t
)
873 (?V org-export-as-docbook-pdf-and-open t
)
874 (?l org-export-as-latex t
)
875 (?p org-export-as-pdf t
)
876 (?d org-export-as-pdf-and-open t
)
877 (?L org-export-as-latex-to-buffer nil
)
878 (?i org-export-icalendar-this-file t
)
879 (?I org-export-icalendar-all-agenda-files t
)
880 (?c org-export-icalendar-combine-agenda-files t
)
881 (?F org-publish-current-file t
)
882 (?P org-publish-current-project t
)
884 (?E org-publish-all t
)))
887 (save-window-excursion
888 (delete-other-windows)
889 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
891 (org-fit-window-to-buffer (get-buffer-window
892 "*Org Export/Publishing Help*"))
893 (message "Select command: ")
894 (setq r1
(read-char-exclusive))))
895 (setq r2
(if (< r1
27) (+ r1
96) r1
))
896 (unless (setq ass
(assq r2 cmds
))
897 (error "No command associated with key %c" r1
))
898 (if (and bg
(nth 2 ass
)
899 (not (buffer-base-buffer))
900 (not (org-region-active-p)))
901 ;; execute in background
902 (let ((p (start-process
903 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
905 (expand-file-name invocation-name invocation-directory
)
908 "--eval" "(require 'org-exp)"
909 "--eval" "(setq org-wait .2)"
911 "-f" (symbol-name (nth 1 ass
)))))
912 (set-process-sentinel p
'org-export-process-sentinel
)
913 (message "Background process \"%s\": started" p
))
914 ;; background processing not requested, or not possible
915 (call-interactively (nth 1 ass
)))))
917 (defun org-export-process-sentinel (process status
)
918 (if (string-match "\n+\\'" status
)
919 (setq status
(substring status
0 -
1)))
920 (message "Background process \"%s\": %s" process status
))
922 (defconst org-html-entities
964 ("Aring") ("AA".
"Å")
1053 ("varepsilon".
"ε")
1066 ("sigmaf") ("varsigma".
"ς")
1074 ("thetasym") ("vartheta".
"ϑ")
1077 ("bull") ("bullet".
"•")
1078 ("hellip") ("dots".
"…")
1088 ("larr") ("leftarrow".
"←") ("gets".
"←")
1089 ("uarr") ("uparrow".
"↑")
1090 ("rarr") ("to".
"→") ("rightarrow".
"→")
1091 ("darr")("downarrow".
"↓")
1092 ("harr") ("leftrightarrow".
"↔")
1093 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1094 ("lArr") ("Leftarrow".
"⇐")
1095 ("uArr") ("Uparrow".
"⇑")
1096 ("rArr") ("Rightarrow".
"⇒")
1097 ("dArr") ("Downarrow".
"⇓")
1098 ("hArr") ("Leftrightarrow".
"⇔")
1100 ("part") ("partial".
"∂")
1101 ("exist") ("exists".
"∃")
1102 ("empty") ("emptyset".
"∅")
1104 ("isin") ("in".
"∈")
1110 ("lowast") ("ast".
"∗")
1112 ("prop") ("proptp".
"∝")
1113 ("infin") ("infty".
"∞")
1114 ("ang") ("angle".
"∠")
1115 ("and") ("wedge".
"∧")
1116 ("or") ("vee".
"∨")
1122 ("cong") ("simeq".
"≅")
1123 ("asymp")("approx".
"≈")
1124 ("ne") ("neq".
"≠")
1128 ("sub") ("subset".
"⊂")
1129 ("sup") ("supset".
"⊃")
1136 ("sdot") ("cdot".
"⋅")
1143 ("loz") ("Diamond".
"◊")
1144 ("spades") ("spadesuit".
"♠")
1145 ("clubs") ("clubsuit".
"♣")
1146 ("hearts") ("diamondsuit".
"♥")
1147 ("diams") ("diamondsuit".
"♦")
1148 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1215 "Entities for TeX->HTML translation.
1216 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1217 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1218 In that case, \"\\ent\" will be translated to \"&other;\".
1219 The list contains HTML entities for Latin-1, Greek and other symbols.
1220 It is supplemented by a number of commonly used TeX macros with appropriate
1221 translations. There is currently no way for users to extend this.")
1223 ;;; General functions for all backends
1225 (defvar org-export-target-aliases nil
1226 "Alist of targets with invisible aliases.")
1227 (defvar org-export-preferred-target-alist nil
1228 "Alist of section id's with preferred aliases.")
1229 (defvar org-export-code-refs nil
1230 "Alist of code references and line numbers")
1232 (defun org-export-preprocess-string (string &rest parameters
)
1233 "Cleanup STRING so that that the true exported has a more consistent source.
1234 This function takes STRING, which should be a buffer-string of an org-file
1235 to export. It then creates a temporary buffer where it does its job.
1236 The result is then again returned as a string, and the exporter works
1237 on this string to produce the exported version."
1239 (let* ((htmlp (plist-get parameters
:for-html
))
1240 (asciip (plist-get parameters
:for-ascii
))
1241 (latexp (plist-get parameters
:for-LaTeX
))
1242 (docbookp (plist-get parameters
:for-docbook
))
1243 (backend (cond (htmlp 'html
)
1246 (docbookp 'docbook
)))
1247 (archived-trees (plist-get parameters
:archived-trees
))
1248 (inhibit-read-only t
)
1249 (drawers org-drawers
)
1250 (outline-regexp "\\*+ ")
1253 (setq org-export-target-aliases nil
)
1254 (setq org-export-preferred-target-alist nil
)
1255 (setq org-export-code-refs nil
)
1257 (with-current-buffer (get-buffer-create " org-mode-tmp")
1260 (setq case-fold-search t
)
1262 ;; Remove license-to-kill stuff
1263 ;; The caller marks some stuff for killing, stuff that has been
1264 ;; used to create the page title, for example.
1265 (org-export-kill-licensed-text)
1267 (let ((org-inhibit-startup t
)) (org-mode))
1268 (setq case-fold-search t
)
1269 (org-install-letbind)
1272 (run-hooks 'org-export-preprocess-hook
)
1274 ;; Process the macros
1275 (org-export-preprocess-apply-macros)
1276 (run-hooks 'org-export-preprocess-after-macros-hook
)
1278 (untabify (point-min) (point-max))
1280 ;; Handle include files, and call a hook
1281 (org-export-handle-include-files)
1282 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1284 ;; Get rid of archived trees
1285 (org-export-remove-archived-trees archived-trees
)
1287 ;; Remove comment environment and comment subtrees
1288 (org-export-remove-comment-blocks-and-subtrees)
1290 ;; Get rid of excluded trees, and call a hook
1291 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1292 (plist-get parameters
:exclude-tags
))
1293 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1295 ;; Handle source code snippets
1296 (org-export-replace-src-segments-and-examples backend
)
1298 ;; Protect short examples marked by a leading colon
1299 (org-export-protect-colon-examples)
1301 ;; Normalize footnotes
1302 (when (plist-get parameters
:footnotes
)
1303 (org-footnote-normalize nil t
))
1305 ;; Find all headings and compute the targets for them
1306 (setq target-alist
(org-export-define-heading-targets target-alist
))
1308 ;; Get rid of drawers
1309 (org-export-remove-or-extract-drawers drawers
1310 (plist-get parameters
:drawers
))
1312 ;; Get the correct stuff before the first headline
1313 (when (plist-get parameters
:skip-before-1st-heading
)
1314 (goto-char (point-min))
1315 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1316 (delete-region (point-min) (match-beginning 0))
1317 (goto-char (point-min))
1319 (when (plist-get parameters
:add-text
)
1320 (goto-char (point-min))
1321 (insert (plist-get parameters
:add-text
) "\n"))
1323 ;; Remove todo-keywords before exporting, if the user has requested so
1324 (org-export-remove-headline-metadata parameters
)
1326 ;; Find targets in comments and move them out of comments,
1327 ;; but mark them as targets that should be invisible
1328 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1330 ;; Select and protect backend specific stuff, throw away stuff
1331 ;; that is specific for other backends
1332 (org-export-select-backend-specific-text backend
)
1334 ;; Protect quoted subtrees
1335 (org-export-protect-quoted-subtrees)
1337 ;; Remove clock lines
1338 (org-export-remove-clock-lines)
1340 ;; Protect verbatim elements
1341 (org-export-protect-verbatim)
1343 ;; Blockquotes, verse, and center
1344 (org-export-mark-blockquote-verse-center)
1345 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1347 ;; Remove timestamps, if the user has requested so
1348 (unless (plist-get parameters
:timestamps
)
1349 (org-export-remove-timestamps))
1351 ;; Attach captions to the correct object
1352 (setq target-alist
(org-export-attach-captions-and-attributes
1353 backend target-alist
))
1355 ;; Find matches for radio targets and turn them into internal links
1356 (org-export-mark-radio-links)
1358 ;; Find all links that contain a newline and put them into a single line
1359 (org-export-concatenate-multiline-links)
1361 ;; Normalize links: Convert angle and plain links into bracket links
1362 ;; and expand link abbreviations
1363 (org-export-normalize-links)
1365 ;; Find all internal links. If they have a fuzzy match (i.e. not
1366 ;; a *dedicated* target match, let the link point to the
1367 ;; corresponding section.
1368 (org-export-target-internal-links target-alist
)
1370 ;; Find multiline emphasis and put them into single line
1371 (when (plist-get parameters
:emph-multiline
)
1372 (org-export-concatenate-multiline-emphasis))
1374 ;; Remove special table lines
1375 (when org-export-table-remove-special-lines
1376 (org-export-remove-special-table-lines))
1379 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1381 ;; LaTeX-specific preprocessing
1383 (require 'org-latex nil
)
1384 (org-export-latex-preprocess parameters
))
1386 ;; ASCII-specific preprocessing
1388 (org-export-ascii-preprocess parameters
))
1390 ;; HTML-specific preprocessing
1392 (org-export-html-preprocess parameters
))
1394 ;; DocBook-specific preprocessing
1396 (require 'org-docbook nil
)
1397 (org-export-docbook-preprocess parameters
))
1399 ;; Remove or replace comments
1400 (org-export-handle-comments (plist-get parameters
:comments
))
1402 ;; Run the final hook
1403 (run-hooks 'org-export-preprocess-final-hook
)
1405 (setq rtn
(buffer-string)))
1406 (kill-buffer " org-mode-tmp")
1409 (defun org-export-kill-licensed-text ()
1410 "Remove all text that is marked with a :org-license-to-kill property."
1412 (while (setq p
(text-property-any (point-min) (point-max)
1413 :org-license-to-kill t
))
1415 p
(or (next-single-property-change p
:org-license-to-kill
)
1418 (defun org-export-define-heading-targets (target-alist)
1419 "Find all headings and define the targets for them.
1420 The new targets are added to TARGET-ALIST, which is also returned."
1421 (goto-char (point-min))
1422 (org-init-section-numbers)
1423 (let ((re (concat "^" org-outline-regexp
1424 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1425 level target last-section-target a id
)
1426 (while (re-search-forward re nil t
)
1429 (setq id
(org-match-string-no-properties 2))
1430 (push (cons id target
) target-alist
)
1431 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1433 (push (list last-section-target
)
1434 org-export-target-aliases
)
1435 (car org-export-target-aliases
))))
1436 (push (caar target-alist
) (cdr a
))
1437 (when (equal (match-string 1) "CUSTOM_ID")
1438 (if (not (assoc last-section-target
1439 org-export-preferred-target-alist
))
1440 (push (cons last-section-target id
)
1441 org-export-preferred-target-alist
))))
1442 (setq level
(org-reduced-level
1443 (save-excursion (goto-char (point-at-bol))
1444 (org-outline-level))))
1445 (setq target
(org-solidify-link-text
1446 (format "sec-%s" (org-section-number level
))))
1447 (setq last-section-target target
)
1448 (push (cons target target
) target-alist
)
1449 (add-text-properties
1450 (point-at-bol) (point-at-eol)
1451 (list 'target target
)))))
1454 (defun org-export-handle-invisible-targets (target-alist)
1455 "Find targets in comments and move them out of comments.
1456 Mark them as invisible targets."
1458 (goto-char (point-min))
1459 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1460 ;; Check if the line before or after is a headline with a target
1461 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1462 (get-text-property (point-at-bol 2) 'target
)))
1464 ;; use the existing target in a neighboring line
1465 (setq tmp
(match-string 2))
1467 (and (looking-at "\n") (delete-char 1))
1468 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1470 (setq a
(or (assoc target org-export-target-aliases
)
1472 (push (list target
) org-export-target-aliases
)
1473 (car org-export-target-aliases
))))
1475 ;; Make an invisible target
1476 (replace-match "\\1(INVISIBLE)"))))
1479 (defun org-export-target-internal-links (target-alist)
1480 "Find all internal links and assign targets to them.
1481 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1482 let the link point to the corresponding section.
1483 This function also handles the id links, if they have a match in
1485 (goto-char (point-min))
1486 (while (re-search-forward org-bracket-link-regexp nil t
)
1488 (let* ((md (match-data))
1489 (desc (match-end 2))
1490 (link (org-link-unescape (match-string 1)))
1491 (slink (org-solidify-link-text link
))
1492 found props pos cref
1495 ((= (string-to-char link
) ?
#)
1496 ;; user wants exactly this link
1498 ((cdr (assoc slink target-alist
))
1499 (or (cdr (assoc (assoc slink target-alist
)
1500 org-export-preferred-target-alist
))
1501 (cdr (assoc slink target-alist
))))
1502 ((and (string-match "^id:" link
)
1503 (cdr (assoc (substring link
3) target-alist
))))
1504 ((string-match "^(\\(.*\\))$" link
)
1505 (setq cref
(match-string 1 link
))
1506 (concat "coderef:" cref
))
1507 ((string-match org-link-types-re link
) nil
)
1508 ((or (file-name-absolute-p link
)
1509 (string-match "^\\." link
))
1513 (setq found
(condition-case nil
(org-link-search link
)
1516 (or (org-on-heading-p)
1517 (not (eq found
'dedicated
))))
1518 (or (get-text-property (point) 'target
)
1521 (1- (or (previous-single-property-change
1522 (point) 'target
) 0)))
1526 (goto-char (match-beginning 1))
1527 (setq props
(text-properties-at (point)))
1528 (delete-region (match-beginning 1) (match-end 1))
1531 (unless desc
(insert "][" link
))
1532 (add-text-properties pos
(point) props
))))))
1534 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1535 "Remove drawers, or extract the content.
1536 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1537 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1538 whose content to keep."
1539 (unless (eq t exp-drawers
)
1540 (goto-char (point-min))
1541 (let ((re (concat "^[ \t]*:\\("
1544 (org-delete-all exp-drawers
1545 (copy-sequence all-drawers
))
1549 (while (re-search-forward re nil t
)
1551 (setq beg
(match-beginning 0)
1553 (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
1556 ;; terminated in this entry
1558 (delete-region beg
(match-end 1))
1560 (goto-char eol
))))))))
1562 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1563 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1564 Both arguments are lists of tags.
1565 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1567 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1569 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1570 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1573 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1577 (goto-char (point-min))
1578 (when (and select-tags
1580 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1581 ;; At least one tree is marked for export, this means
1582 ;; all the unmarked stuff needs to go.
1583 ;; Dig out the trees that should be exported
1584 (goto-char (point-min))
1585 (outline-next-heading)
1587 (put-text-property beg
(point-max) :org-delete t
)
1588 (while (re-search-forward re-sel nil t
)
1589 (when (org-on-heading-p)
1590 (org-back-to-heading)
1591 (remove-text-properties
1592 (max (1- (point)) (point-min))
1593 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1595 (while (and (org-up-heading-safe)
1596 (get-text-property (point) :org-delete
))
1597 (remove-text-properties (max (1- (point)) (point-min))
1598 (point-at-eol) '(:org-delete t
)))
1600 ;; Remove the trees explicitly marked for noexport
1602 (goto-char (point-min))
1603 (while (re-search-forward re-excl nil t
)
1604 (when (org-at-heading-p)
1605 (org-back-to-heading t
)
1607 (org-end-of-subtree t t
)
1608 (delete-region beg
(point))
1609 (when (featurep 'org-inlinetask
)
1610 (org-inlinetask-remove-END-maybe)))))
1611 ;; Remove everything that is now still marked for deletion
1612 (goto-char (point-min))
1613 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1614 (setq end
(or (next-single-property-change beg
:org-delete
)
1616 (delete-region beg end
))))
1618 (defun org-export-remove-archived-trees (export-archived-trees)
1619 "Remove archived trees.
1620 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1621 When it is t, the entire archived tree will be exported.
1622 When it is nil the entire tree including the headline will be removed
1624 (let ((re-archive (concat ":" org-archive-tag
":"))
1626 (when (not (eq export-archived-trees t
))
1627 (goto-char (point-min))
1628 (while (re-search-forward re-archive nil t
)
1629 (if (not (org-on-heading-p t
))
1630 (org-end-of-subtree t
)
1631 (beginning-of-line 1)
1632 (setq a
(if export-archived-trees
1633 (1+ (point-at-eol)) (point))
1634 b
(org-end-of-subtree t
))
1635 (if (> b a
) (delete-region a b
)))))))
1637 (defun org-export-remove-headline-metadata (opts)
1638 "Remove meta data from the headline, according to user options."
1639 (let ((re org-complex-heading-regexp
)
1640 (todo (plist-get opts
:todo-keywords
))
1641 (tags (plist-get opts
:tags
))
1642 (pri (plist-get opts
:priority
))
1645 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1646 (when (or (not todo
) (not tags
) (not pri
))
1647 (goto-char (point-min))
1648 (while (re-search-forward re nil t
)
1650 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1652 (replace-match rpl t t
))))))
1654 (defun org-export-remove-timestamps ()
1655 "Remove timestamps and keywords for export."
1656 (goto-char (point-min))
1657 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1660 (unless (save-match-data (org-at-table-p))
1662 (beginning-of-line 1)
1663 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1664 (replace-match ""))))))
1666 (defun org-export-remove-clock-lines ()
1667 "Remove clock lines for export."
1668 (goto-char (point-min))
1669 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1670 (while (re-search-forward re nil t
)
1672 (replace-match "")))))
1674 (defun org-export-protect-quoted-subtrees ()
1675 "Mark quoted subtrees with the protection property."
1676 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1677 (goto-char (point-min))
1678 (while (re-search-forward re-quote nil t
)
1679 (goto-char (match-beginning 0))
1681 (add-text-properties (point) (org-end-of-subtree t
)
1682 '(org-protected t
)))))
1684 (defun org-export-protect-verbatim ()
1685 "Mark verbatim snippets with the protection property."
1686 (goto-char (point-min))
1687 (while (re-search-forward org-verbatim-re nil t
)
1688 (add-text-properties (match-beginning 4) (match-end 4)
1689 '(org-protected t org-verbatim-emph t
))
1690 (goto-char (1+ (match-end 4)))))
1692 (defun org-export-protect-colon-examples ()
1693 "Protect lines starting with a colon."
1694 (goto-char (point-min))
1695 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1696 (while (re-search-forward re nil t
)
1697 (beginning-of-line 1)
1699 (while (looking-at re
)
1701 (or (eobp) (forward-char 1)))
1702 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1703 '(org-protected t
)))))
1705 (defun org-export-select-backend-specific-text (backend)
1707 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1708 (html "HTML" "BEGIN_HTML" "END_HTML")
1709 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1710 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1711 (case-fold-search t
)
1712 fmt beg beg-content end end-content
)
1715 (setq fmt
(pop formatters
))
1716 (when (eq (car fmt
) backend
)
1717 ;; This is selected code, put it into the file for real
1718 (goto-char (point-min))
1719 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1720 ":[ \t]*\\(.*\\)") nil t
)
1721 (replace-match "\\1\\2" t
)
1722 (add-text-properties
1723 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1724 '(org-protected t
))))
1725 (goto-char (point-min))
1726 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt
) "\\>.*\n?")
1728 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1729 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt
) "\\>.*\n?")
1731 (setq end
(match-end 0) end-content
(match-beginning 0))
1732 (if (eq (car fmt
) backend
)
1735 (add-text-properties beg-content end-content
'(org-protected t
))
1736 (delete-region (match-beginning 0) (match-end 0))
1739 (delete-region (point) (1+ (point-at-eol)))))
1740 ;; No, this is for a different backend, kill it
1741 (delete-region beg end
)))))))
1743 (defun org-export-mark-blockquote-verse-center ()
1744 "Mark block quote and verse environments with special cookies.
1745 These special cookies will later be interpreted by the backend."
1747 (let (type t1 ind beg end beg1 end1 content
)
1748 (goto-char (point-min))
1749 (while (re-search-forward
1750 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1752 (setq ind
(length (match-string 1))
1753 type
(downcase (match-string 3))
1754 t1
(if (equal type
"quote") "blockquote" type
))
1755 (setq beg
(match-beginning 0)
1756 beg1
(1+ (match-end 0)))
1757 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1758 (setq end
(1+ (point-at-eol))
1759 end1
(1- (match-beginning 0)))
1760 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1761 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1763 "ORG-" (upcase t1
) "-END\n"))
1764 (delete-region beg end
)
1765 (insert (org-add-props content nil
'original-indentation ind
))))))
1767 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1768 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1769 If the next thing following is a table, add the text properties to the first
1770 table line. If it is a link, add it to the line containing the link."
1771 (goto-char (point-min))
1772 (remove-text-properties (point-min) (point-max)
1773 '(org-caption nil org-attributes nil
))
1774 (let ((case-fold-search t
)
1775 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1777 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1779 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1783 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1785 (while (re-search-forward re nil t
)
1788 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1790 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1792 (setq label
(org-trim (match-string 3))))
1794 (add-text-properties (point-at-bol) (point-at-eol)
1795 (list 'org-caption cap
1796 'org-attributes attr
1798 (if label
(push (cons label label
) target-alist
))
1799 (setq cap nil attr nil label nil
)))))
1802 (defun org-export-remove-comment-blocks-and-subtrees ()
1803 "Remove the comment environment, and also commented subtrees."
1804 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1805 (case-fold-search nil
))
1806 ;; Remove comment environment
1807 (goto-char (point-min))
1808 (while (re-search-forward
1809 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1810 (replace-match "" t t
))
1811 ;; Remove subtrees that are commented
1812 (goto-char (point-min))
1813 (while (re-search-forward re-commented nil t
)
1814 (goto-char (match-beginning 0))
1815 (delete-region (point) (org-end-of-subtree t
)))))
1817 (defun org-export-handle-comments (commentsp)
1818 "Remove comments, or convert to backend-specific format.
1819 COMMENTSP can be a format string for publishing comments.
1820 When it is nil, all comments will be removed."
1821 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1823 (goto-char (point-min))
1824 (while (or (looking-at re
)
1825 (re-search-forward re nil t
))
1826 (setq pos
(match-beginning 0))
1828 (not (equal (char-before (match-end 1)) ?
+)))
1829 (progn (add-text-properties
1830 (match-beginning 0) (match-end 0) '(org-protected t
))
1831 (replace-match (format commentsp
(match-string 2)) t t
))
1832 (goto-char (1+ pos
))
1835 (goto-char (max (point-min) (1- pos
))))))))
1837 (defun org-export-mark-radio-links ()
1838 "Find all matches for radio targets and turn them into internal links."
1839 (let ((re-radio (and org-target-link-regexp
1840 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1841 (goto-char (point-min))
1843 (while (re-search-forward re-radio nil t
)
1846 (or (org-in-regexp org-bracket-link-regexp
)
1847 (org-in-regexp org-plain-link-re
)))
1849 (replace-match "\\1[[\\2]]")))))))
1851 (defun org-export-remove-special-table-lines ()
1852 "Remove tables lines that are used for internal purposes."
1853 (goto-char (point-min))
1854 (while (re-search-forward "^[ \t]*|" nil t
)
1855 (beginning-of-line 1)
1856 (if (or (looking-at "[ \t]*| *[!_^] *|")
1862 (or (= (length f
) 0)
1864 "\\`<\\([0-9]\\|[rl]\\|[rl][0-9]+\\)>\\'" f
)))
1865 (org-split-string ;; FIXME, can't we do this without splitting???
1866 (buffer-substring (point-at-bol) (point-at-eol))
1867 "[ \t]*|[ \t]*")))))
1868 (delete-region (max (point-min) (1- (point-at-bol)))
1872 (defun org-export-protect-sub-super (s)
1874 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
1875 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
1878 (defun org-export-normalize-links ()
1879 "Convert all links to bracket links, and expand link abbreviations."
1880 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1881 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1883 (goto-char (point-min))
1884 (while (re-search-forward re-plain-link nil t
)
1885 (goto-char (1- (match-end 0)))
1886 (org-if-unprotected-at (1+ (match-beginning 0))
1887 (let* ((s (concat (match-string 1)
1888 "[[" (match-string 2) ":" (match-string 3)
1889 "][" (match-string 2) ":" (org-export-protect-sub-super
1892 ;; added 'org-link face to links
1893 (put-text-property 0 (length s
) 'face
'org-link s
)
1894 (replace-match s t t
))))
1895 (goto-char (point-min))
1896 (while (re-search-forward re-angle-link nil t
)
1897 (goto-char (1- (match-end 0)))
1899 (let* ((s (concat (match-string 1)
1900 "[[" (match-string 2) ":" (match-string 3)
1901 "][" (match-string 2) ":" (org-export-protect-sub-super
1904 (put-text-property 0 (length s
) 'face
'org-link s
)
1905 (replace-match s t t
))))
1906 (goto-char (point-min))
1907 (while (re-search-forward org-bracket-link-regexp nil t
)
1908 (goto-char (1- (match-end 0)))
1909 (setq nodesc
(not (match-end 3)))
1911 (let* ((xx (save-match-data
1913 (org-link-expand-abbrev (match-string 1)))))
1915 "[[" (org-add-props (copy-sequence xx
)
1916 nil
'org-protected t
'org-no-description nodesc
)
1920 (concat "[" (copy-sequence xx
)
1923 (put-text-property 0 (length s
) 'face
'org-link s
)
1924 (replace-match s t t
))))))
1926 (defun org-export-concatenate-multiline-links ()
1927 "Find multi-line links and put it all into a single line.
1928 This is to make sure that the line-processing export backends
1929 can work correctly."
1930 (goto-char (point-min))
1931 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1933 (replace-match "\\1 \\3")
1934 (goto-char (match-beginning 0)))))
1936 (defun org-export-concatenate-multiline-emphasis ()
1937 "Find multi-line emphasis and put it all into a single line.
1938 This is to make sure that the line-processing export backends
1939 can work correctly."
1940 (goto-char (point-min))
1941 (while (re-search-forward org-emph-re nil t
)
1942 (if (and (not (= (char-after (match-beginning 3))
1943 (char-after (match-beginning 4))))
1944 (save-excursion (goto-char (match-beginning 0))
1945 (save-match-data (not (org-at-table-p)))))
1947 (subst-char-in-region (match-beginning 0) (match-end 0)
1949 (goto-char (1- (match-end 0))))
1950 (goto-char (1+ (match-beginning 0))))))
1952 (defun org-export-grab-title-from-buffer ()
1953 "Get a title for the current document, from looking at the buffer."
1954 (let ((inhibit-read-only t
))
1956 (goto-char (point-min))
1957 (let ((end (if (looking-at org-outline-regexp
)
1959 (save-excursion (outline-next-heading) (point)))))
1960 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1961 ;; Mark the line so that it will not be exported as normal text.
1963 (add-text-properties (match-beginning 0) (match-end 0)
1964 (list :org-license-to-kill t
)))
1965 ;; Return the title string
1966 (org-trim (match-string 0)))))))
1968 (defun org-export-get-title-from-subtree ()
1969 "Return subtree title and exclude it from export."
1970 (let (title (rbeg (region-beginning)) (rend (region-end)))
1973 (when (and (org-at-heading-p)
1974 (>= (org-end-of-subtree t t
) rend
))
1975 ;; This is a subtree, we take the title from the first heading
1977 (looking-at org-todo-line-regexp
)
1978 (setq title
(match-string 3))
1980 (add-text-properties (point) (1+ (point-at-eol))
1981 (list :org-license-to-kill t
)))
1982 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1985 (defun org-solidify-link-text (s &optional alist
)
1986 "Take link text and make a safe target out of it."
1991 (org-split-string s
"[ \t\r\n]+") "=="))
1992 (a (assoc rtn alist
)))
1995 (defun org-get-min-level (lines &optional offset
)
1996 "Get the minimum level in LINES."
1997 (let ((re "^\\(\\*+\\) ") l
)
1999 (while (setq l
(pop lines
))
2000 (if (string-match re l
)
2001 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2005 ;; Variable holding the vector with section numbers
2006 (defvar org-section-numbers
(make-vector org-level-max
0))
2008 (defun org-init-section-numbers ()
2009 "Initialize the vector for the section numbers."
2011 (numbers (nreverse (org-split-string "" "\\.")))
2012 (depth (1- (length org-section-numbers
)))
2013 (i depth
) number-string
)
2016 (aset org-section-numbers i
0)
2017 (setq number-string
(or (car numbers
) "0"))
2018 (if (string-match "\\`[A-Z]\\'" number-string
)
2019 (aset org-section-numbers i
2020 (- (string-to-char number-string
) ?A -
1))
2021 (aset org-section-numbers i
(string-to-number number-string
)))
2025 (defun org-section-number (&optional level
)
2026 "Return a string with the current section number.
2027 When LEVEL is non-nil, increase section numbers on that level."
2028 (let* ((depth (1- (length org-section-numbers
)))
2030 (fmts (car org-export-section-number-format
))
2031 (term (cdr org-export-section-number-format
))
2036 (aset org-section-numbers
2037 level
(1+ (aref org-section-numbers level
))))
2038 (setq idx
(1+ level
))
2039 (while (<= idx depth
)
2041 (aset org-section-numbers idx
0))
2042 (setq idx
(1+ idx
))))
2044 (while (<= idx depth
)
2045 (when (> (aref org-section-numbers idx
) 0)
2046 (setq fmt
(or (pop fmts
) fmt
)
2048 n
(aref org-section-numbers idx
)
2050 (concat string sep
(org-number-to-counter n ctype
))
2051 (concat string
".0"))
2053 (setq idx
(1+ idx
)))
2055 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2056 (setq string
(replace-match "" t nil string
)))
2057 (if (string-match "\\(\\.0\\)+\\'" string
)
2058 (setq string
(replace-match "" t nil string
))))
2059 (concat string term
)))
2061 (defun org-number-to-counter (n type
)
2062 "Concert number N to a string counter, according to TYPE.
2063 TYPE must be a string, any of:
2067 I upper case roman numeral
2068 i lower case roman numeral"
2070 ((equal type
"1") (number-to-string n
))
2071 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2072 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2073 ((equal type
"I") (org-number-to-roman n
))
2074 ((equal type
"i") (downcase (org-number-to-roman n
)))
2075 (t (error "Invalid counter type `%s'" type
))))
2077 (defun org-number-to-roman (n)
2078 "Convert integer N into a roman numeral."
2079 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2080 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2081 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2085 (number-to-string n
)
2087 (if (>= n
(caar roman
))
2088 (setq n
(- n
(caar roman
))
2089 res
(concat res
(cdar roman
)))
2095 (defun org-export-preprocess-apply-macros ()
2096 "Replace macro references."
2097 (goto-char (point-min))
2098 (let (sy val key args args2 s n
)
2099 (while (re-search-forward
2100 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2102 (unless (save-match-data
2104 (goto-char (point-at-bol))
2105 (looking-at "[ \t]*#\\+macro")))
2106 (setq key
(downcase (match-string 1))
2107 args
(match-string 3))
2108 (when (setq val
(or (plist-get org-export-opt-plist
2109 (intern (concat ":macro-" key
)))
2110 (plist-get org-export-opt-plist
2111 (intern (concat ":" key
)))))
2114 (setq args
(org-split-string args
",[ \t\n]*") args2 nil
)
2115 (setq args
(mapcar 'org-trim args
))
2117 (while (string-match "\\\\\\'" (car args
))
2118 ;; repair bad splits
2119 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2122 (push (pop args
) args2
))
2123 (setq args
(nreverse args2
))
2125 (while (string-match "\\$\\([0-9]+\\)" val s
)
2126 (setq s
(1+ (match-beginning 0))
2127 n
(string-to-number (match-string 1 val
)))
2128 (and (>= (length args
) n
)
2129 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2130 (when (string-match "\\`(eval\\>" val
)
2131 (setq val
(eval (read val
))))
2132 (if (and val
(not (stringp val
)))
2133 (setq val
(format "%s" val
))))
2135 (prog1 (replace-match val t t
)
2136 (goto-char (match-beginning 0)))))))))
2138 (defun org-export-apply-macros-in-string (s)
2139 "Apply the macros in string S."
2143 (org-export-preprocess-apply-macros)
2148 (defun org-export-handle-include-files ()
2149 "Include the contents of include files, with proper formatting."
2150 (let ((case-fold-search t
)
2151 params file markup lang start end prefix prefix1 switches
)
2152 (goto-char (point-min))
2153 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2154 (setq params
(read (concat "(" (match-string 1) ")"))
2155 prefix
(org-get-and-remove-property 'params
:prefix
)
2156 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2157 file
(org-symname-or-string (pop params
))
2158 markup
(org-symname-or-string (pop params
))
2159 lang
(and (member markup
'("src" "SRC"))
2160 (org-symname-or-string (pop params
)))
2161 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" ")
2163 (delete-region (match-beginning 0) (match-end 0))
2165 (not (file-exists-p file
))
2166 (not (file-readable-p file
)))
2167 (insert (format "CANNOT INCLUDE FILE %s" file
))
2169 (if (equal (downcase markup
) "src")
2170 (setq start
(format "#+begin_src %s %s\n"
2171 (or lang
"fundamental")
2174 (setq start
(format "#+begin_%s %s\n" markup switches
)
2175 end
(format "#+end_%s" markup
))))
2176 (insert (or start
""))
2177 (insert (org-get-file-contents (expand-file-name file
)
2178 prefix prefix1 markup
))
2179 (or (bolp) (newline))
2180 (insert (or end
""))))))
2182 (defun org-get-file-contents (file &optional prefix prefix1 markup
)
2183 "Get the contents of FILE and return them as a string.
2184 If PREFIX is a string, prepend it to each line. If PREFIX1
2185 is a string, prepend it to the first line instead of PREFIX.
2186 If MARKUP, don't protect org-like lines, the exporter will
2187 take care of the block they are in."
2188 (if (stringp markup
) (setq markup
(downcase markup
)))
2190 (insert-file-contents file
)
2191 (when (or prefix prefix1
)
2192 (goto-char (point-min))
2194 (insert (or prefix1 prefix
))
2196 (beginning-of-line 2)))
2198 (when (member markup
'("src" "example"))
2199 (goto-char (point-min))
2200 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2201 (goto-char (match-beginning 0))
2206 (defun org-get-and-remove-property (listvar prop
)
2207 "Check if the value of LISTVAR contains PROP as a property.
2208 If yes, return the value of that property (i.e. the element following
2209 in the list) and remove property and value from the list in LISTVAR."
2210 (let ((list (symbol-value listvar
)) m v
)
2211 (when (setq m
(member prop list
))
2213 (if (equal (car list
) prop
)
2214 (set listvar
(cddr list
))
2215 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2217 (set listvar list
)))
2220 (defun org-symname-or-string (s)
2222 (if s
(symbol-name s
) s
)
2225 ;;; Fontification and line numbers for code examples
2227 (defvar org-export-last-code-line-counter-value
0)
2229 (defun org-export-replace-src-segments-and-examples (backend)
2230 "Replace source code segments with special code for export."
2231 (setq org-export-last-code-line-counter-value
0)
2232 (let ((case-fold-search t
)
2233 lang code trans opts indent
)
2234 (goto-char (point-min))
2235 (while (re-search-forward
2236 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
2240 (setq lang
(match-string 3)
2241 opts
(match-string 4)
2242 code
(match-string 5)
2243 indent
(length (match-string 2)))
2245 opts
(match-string 8)
2246 code
(match-string 9)
2247 indent
(length (match-string 7))))
2249 (setq trans
(org-export-format-source-code-or-example
2250 backend lang code opts indent
))
2251 (replace-match trans t t
))))
2253 (defvar htmlp
) ;; dynamically scoped
2254 (defvar latexp
) ;; dynamically scoped
2255 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2256 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2257 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2259 (defun org-export-format-source-code-or-example
2260 (backend lang code
&optional opts indent
)
2261 "Format CODE from language LANG and return it formatted for export.
2262 If LANG is nil, do not add any fontification.
2263 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2264 and `+n' for continuing previous numering.
2265 Code formatting according to language currently only works for HTML.
2266 Numbering lines works for all three major backends (html, latex, and ascii).
2267 INDENT was the original indentation of the block."
2269 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2270 (setq opts
(or opts
"")
2271 num
(string-match "[-+]n\\>" opts
)
2272 cont
(string-match "\\+n\\>" opts
)
2273 rpllbl
(string-match "-r\\>" opts
)
2274 keepp
(string-match "-k\\>" opts
)
2275 textareap
(string-match "-t\\>" opts
)
2276 preserve-indentp
(or org-src-preserve-indentation
2277 (string-match "-i\\>" opts
))
2278 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2279 (string-to-number (match-string 1 opts
))
2281 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2282 (string-to-number (match-string 1 opts
))
2283 (org-count-lines code
))
2284 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2285 (match-string 1 opts
)))
2286 (when (and textareap
(eq backend
'html
))
2287 ;; we cannot use numbering or highlighting.
2288 (setq num nil cont nil lang nil
))
2289 (if keepp
(setq rpllbl
'keep
))
2290 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2291 (when (string-match "^," rtn
)
2292 (setq rtn
(with-temp-buffer
2294 ;; Free up the protected lines
2295 (goto-char (point-min))
2296 (while (re-search-forward "^," nil t
)
2297 (if (or (equal lang
"org")
2299 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2303 ;; Now backend-specific coding
2306 ((eq backend
'docbook
)
2307 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2308 (concat "\n#+BEGIN_DOCBOOK\n"
2309 (org-add-props (concat "<programlisting><![CDATA["
2311 "]]>\n</programlisting>\n")
2315 ;; We are exporting to HTML
2317 (require 'htmlize nil t
)
2318 (when (not (fboundp 'htmlize-region-for-paste
))
2319 ;; we do not have htmlize.el, or an old version of it
2322 "htmlize.el 1.34 or later is needed for source code formatting")))
2325 (let* ((lang-m (when lang
2326 (or (cdr (assoc lang org-src-lang-modes
))
2328 (mode (and lang-m
(intern
2330 (if (symbolp lang-m
)
2331 (symbol-name lang-m
)
2334 (org-inhibit-startup t
)
2335 (org-startup-folded nil
))
2339 (if (functionp mode
)
2342 (font-lock-fontify-buffer)
2344 (set-buffer-modified-p nil
)
2345 (org-export-htmlize-region-for-paste
2346 (point-min) (point-max))))
2347 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2348 (setq rtn
(replace-match
2349 (format "<pre class=\"src src-%s\">\n" lang
)
2353 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2355 rtn
"</textarea>\n</p>\n"))
2358 (goto-char (point-min))
2359 (while (re-search-forward "[<>&]" nil t
)
2360 (replace-match (cdr (assq (char-before)
2361 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2363 (setq rtn
(buffer-string)))
2364 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2366 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2368 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2369 (setq rtn
(replace-match "\\1" t nil rtn
)))
2370 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2371 ((eq backend
'latex
)
2372 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2373 (concat "\n#+BEGIN_LaTeX\n"
2375 (if org-export-latex-listings
2379 ((lang-sym (intern lang
))
2384 org-export-latex-listings-langs
))
2386 (format "\\lstset{language=%s}\n" lstlang
))
2388 "\\begin{lstlisting}\n"
2389 rtn
"\\end{lstlisting}\n")
2390 (concat (car org-export-latex-verbatim-wrap
)
2391 rtn
(cdr org-export-latex-verbatim-wrap
)))
2394 ((eq backend
'ascii
)
2395 ;; This is not HTML or LaTeX, so just make it an example.
2396 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2397 (concat "#+BEGIN_ASCII\n"
2401 (lambda (l) (concat " " l
))
2402 (org-split-string rtn
"\n")
2407 (org-add-props rtn nil
'original-indentation indent
))))
2409 (defun org-export-number-lines (text backend
2410 &optional skip1 skip2 number cont
2411 replace-labels label-format
)
2412 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2413 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2416 (goto-char (point-max))
2417 (skip-chars-backward " \t\n\r")
2418 (delete-region (point) (point-max))
2419 (beginning-of-line (- 1 skip2
))
2420 (let* ((last (org-current-line))
2421 (n org-export-last-code-line-counter-value
)
2422 (nmax (+ n
(- last skip1
)))
2423 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2426 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2428 ((eq backend
'ascii
) fmt
)
2429 ((eq backend
'latex
) fmt
)
2430 ((eq backend
'docbook
) fmt
)
2432 (label-format (or label-format org-coderef-label-format
))
2433 (label-pre (if (string-match "%s" label-format
)
2434 (substring label-format
0 (match-beginning 0))
2436 (label-post (if (string-match "%s" label-format
)
2437 (substring label-format
(match-end 0))
2441 ".*?\\S-.*?\\([ \t]*\\("
2442 (regexp-quote label-pre
)
2443 "\\([-a-zA-Z0-9_ ]+\\)"
2444 (regexp-quote label-post
)
2448 (org-goto-line (1+ skip1
))
2449 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2451 (insert (format fm
(incf n
)))
2453 (when (looking-at lbl-re
)
2454 (setq ref
(match-string 3))
2455 (cond ((numberp replace-labels
)
2456 ;; remove labels; use numbers for references when lines
2457 ;; are numbered, use labels otherwise
2458 (delete-region (match-beginning 1) (match-end 1))
2459 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2460 ((eq replace-labels
'keep
)
2461 ;; don't remove labels; use numbers for references when
2462 ;; lines are numbered, use labels otherwise
2463 (goto-char (match-beginning 2))
2464 (delete-region (match-beginning 2) (match-end 2))
2465 (insert "(" ref
")")
2466 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2467 org-export-code-refs
))
2469 ;; don't remove labels and don't use numbers for
2471 (goto-char (match-beginning 2))
2472 (delete-region (match-beginning 2) (match-end 2))
2473 (insert "(" ref
")")
2474 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2475 (when (eq backend
'html
)
2477 (beginning-of-line 1)
2478 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2481 (insert "</span>")))))
2482 (setq org-export-last-code-line-counter-value n
)
2483 (goto-char (point-max))
2487 (defun org-search-todo-below (line lines level
)
2488 "Search the subtree below LINE for any TODO entries."
2489 (let ((rest (cdr (memq line lines
)))
2490 (re org-todo-line-regexp
)
2493 (while (setq line
(pop rest
))
2494 (if (string-match re line
)
2496 (setq lv
(- (match-end 1) (match-beginning 1))
2497 todo
(and (match-beginning 2)
2498 (not (member (match-string 2 line
)
2499 org-done-keywords
))))
2501 (if (<= lv level
) (throw 'exit nil
))
2502 (if todo
(throw 'exit t
))))))))
2505 (defun org-export-visible (type arg
)
2506 "Create a copy of the visible part of the current buffer, and export it.
2507 The copy is created in a temporary buffer and removed after use.
2508 TYPE is the final key (as a string) that also select the export command in
2509 the `C-c C-e' export dispatcher.
2510 As a special case, if the you type SPC at the prompt, the temporary
2511 org-mode file will not be removed but presented to you so that you can
2512 continue to use it. The prefix arg ARG is passed through to the exporting
2516 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2517 (read-char-exclusive))
2518 current-prefix-arg
))
2519 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\
)))
2520 (error "Invalid export key"))
2521 (let* ((binding (cdr (assoc type
2522 '((?a . org-export-as-ascii
)
2523 (?A . org-export-as-ascii-to-buffer
)
2524 (?\C-a . org-export-as-ascii
)
2525 (?b . org-export-as-html-and-open
)
2526 (?\C-b . org-export-as-html-and-open
)
2527 (?h . org-export-as-html
)
2528 (?H . org-export-as-html-to-buffer
)
2529 (?R . org-export-region-as-html
)
2530 (?D . org-export-as-docbook
)
2531 (?x . org-export-as-xoxo
)))))
2532 (keepp (equal type ?\
))
2533 (file buffer-file-name
)
2534 (buffer (get-buffer-create "*Org Export Visible*"))
2536 ;; Need to hack the drawers here.
2538 (goto-char (point-min))
2539 (while (re-search-forward org-drawer-regexp nil t
)
2540 (goto-char (match-beginning 1))
2541 (or (org-invisible-p) (org-flag-drawer nil
))))
2542 (with-current-buffer buffer
(erase-buffer))
2544 (setq s
(goto-char (point-min)))
2545 (while (not (= (point) (point-max)))
2546 (goto-char (org-find-invisible))
2547 (append-to-buffer buffer s
(point))
2548 (setq s
(goto-char (org-find-visible))))
2549 (org-cycle-hide-drawers 'all
)
2550 (goto-char (point-min))
2552 ;; Copy all comment lines to the end, to make sure #+ settings are
2553 ;; still available for the second export step. Kind of a hack, but
2554 ;; does do the trick.
2555 (if (looking-at "#[^\r\n]*")
2556 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2557 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2558 (append-to-buffer buffer
(1+ (match-beginning 0))
2559 (min (point-max) (1+ (match-end 0))))))
2561 (let ((buffer-file-name file
)
2562 (org-inhibit-startup t
))
2565 (unless keepp
(funcall binding arg
))))
2567 (kill-buffer buffer
)
2568 (switch-to-buffer-other-window buffer
)
2569 (goto-char (point-min)))))
2571 (defun org-find-visible ()
2573 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2574 (get-char-property s
'invisible
)))
2576 (defun org-find-invisible ()
2578 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2579 (not (get-char-property s
'invisible
))))
2582 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2585 (defun org-export-as-org (arg &optional hidden ext-plist
2586 to-buffer body-only pub-dir
)
2587 "Make a copy with not-exporting stuff removed.
2588 The purpose of this function is to provide a way to export the source
2589 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2590 stuff removed. This command will remove the following:
2592 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2593 - comment blocks and trees starting with the COMMENT keyword
2594 - only trees that are consistent with `org-export-select-tags'
2595 and `org-export-exclude-tags'.
2597 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2598 all the others will be ignored (but are present so that the general
2599 mechanism to call publishing functions will work).
2601 EXT-PLIST is a property list with external parameters overriding
2602 org-mode's default settings, but still inferior to file-local
2603 settings. When PUB-DIR is set, use this as the publishing
2606 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2608 (org-infile-export-plist)))
2609 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2610 (filename (concat (file-name-as-directory
2612 (org-export-directory :org opt-plist
)))
2613 (file-name-sans-extension
2614 (file-name-nondirectory bfname
))
2616 (filename (and filename
2617 (if (equal (file-truename filename
)
2618 (file-truename bfname
))
2619 (concat (file-name-sans-extension filename
)
2621 (file-name-extension filename
))
2623 (backup-inhibited t
)
2624 (buffer (find-file-noselect filename
))
2625 (region (buffer-string)))
2627 (switch-to-buffer buffer
)
2630 (let ((org-inhibit-startup t
)) (org-mode))
2631 (org-install-letbind)
2633 ;; Get rid of archived trees
2634 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2636 ;; Remove comment environment and comment subtrees
2637 (org-export-remove-comment-blocks-and-subtrees)
2639 ;; Get rid of excluded trees
2640 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2641 (plist-get opt-plist
:exclude-tags
))
2643 (when (or (plist-get opt-plist
:plain-source
)
2644 (not (or (plist-get opt-plist
:plain-source
)
2645 (plist-get opt-plist
:htmlized-source
))))
2646 ;; Either nothing special is requested (default call)
2647 ;; or the plain source is explicitly requested
2650 (when (plist-get opt-plist
:htmlized-source
)
2651 ;; Make the htmlized version
2654 (font-lock-fontify-buffer)
2655 (let* ((htmlize-output-type 'css
)
2656 (newbuf (htmlize-buffer)))
2657 (with-current-buffer newbuf
2658 (when org-export-htmlized-org-css-url
2659 (goto-char (point-min))
2660 (and (re-search-forward
2661 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2665 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2666 org-export-htmlized-org-css-url
)
2668 (write-file (concat filename
".html")))
2669 (kill-buffer newbuf
)))
2670 (set-buffer-modified-p nil
)
2671 (kill-buffer (current-buffer)))))
2673 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2674 (defun org-get-current-options ()
2675 "Return a string with current options as keyword options.
2676 Does include HTML export options as well as TODO and CATEGORY stuff."
2677 (require 'org-archive
)
2686 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2687 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2689 #+EXPORT_SELECT_TAGS: %s
2690 #+EXPORT_EXCLUDE_TAGS: %s
2696 #+PRIORITIES: %c %c %c
2698 #+STARTUP: %s %s %s %s %s
2704 (buffer-name) (user-full-name) user-mail-address
2705 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2706 org-export-default-language
2707 org-export-headline-levels
2708 org-export-with-section-numbers
2710 org-export-preserve-breaks
2711 org-export-html-expand
2712 org-export-with-fixed-width
2713 org-export-with-tables
2714 org-export-with-sub-superscripts
2715 org-export-with-special-strings
2716 org-export-with-footnotes
2717 org-export-with-emphasize
2718 org-export-with-timestamps
2719 org-export-with-TeX-macros
2720 org-export-with-LaTeX-fragments
2721 org-export-skip-text-before-1st-heading
2722 org-export-with-drawers
2723 org-export-with-todo-keywords
2724 org-export-with-priority
2725 org-export-with-tags
2726 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2727 (mapconcat 'identity org-export-select-tags
" ")
2728 (mapconcat 'identity org-export-exclude-tags
" ")
2729 org-export-html-link-up
2730 org-export-html-link-home
2732 (file-name-sans-extension
2733 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2735 "TODO FEEDBACK VERIFY DONE"
2736 "Me Jason Marie DONE"
2737 org-highest-priority org-lowest-priority org-default-priority
2738 (mapconcat 'identity org-drawers
" ")
2739 (cdr (assoc org-startup-folded
2740 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2741 (if org-odd-levels-only
"odd" "oddeven")
2742 (if org-hide-leading-stars
"hidestars" "showstars")
2743 (if org-startup-align-all-tables
"align" "noalign")
2744 (cond ((eq org-log-done t
) "logdone")
2745 ((equal org-log-done
'note
) "lognotedone")
2746 ((not org-log-done
) "nologdone"))
2747 (or (mapconcat (lambda (x)
2749 ((equal '(:startgroup
) x
) "{")
2750 ((equal '(:endgroup
) x
) "}")
2751 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2753 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2754 (mapconcat 'identity org-file-tags
" ")
2755 org-archive-location
2756 "org file:~/org/%s.org"
2760 (defun org-insert-export-options-template ()
2761 "Insert into the buffer a template with information for exporting."
2763 (if (not (bolp)) (newline))
2764 (let ((s (org-get-current-options)))
2765 (and (string-match "#\\+CATEGORY" s
)
2766 (setq s
(substring s
0 (match-beginning 0))))
2769 (defvar org-table-colgroup-info nil
)
2771 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2772 "Check if the table has a marking column.
2773 If yes remove the column and the special lines."
2774 (setq org-table-colgroup-info nil
)
2777 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2780 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2781 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2785 (setq org-table-clean-did-remove-column nil
)
2790 ((string-match "^[ \t]*| */ *|" x
)
2791 (setq org-table-colgroup-info
2793 (cond ((member x
'("<" "<")) :start
)
2794 ((member x
'(">" ">")) :end
)
2795 ((member x
'("<>" "<>")) :startend
)
2797 (org-split-string x
"[ \t]*|[ \t]*")))
2801 (setq org-table-clean-did-remove-column t
)
2806 ((string-match "^[ \t]*| */ *|" x
)
2807 (setq org-table-colgroup-info
2809 (cond ((member x
'("<" "<")) :start
)
2810 ((member x
'(">" ">")) :end
)
2811 ((member x
'("<>" "<>")) :startend
)
2813 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2815 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2816 nil
) ; ignore this line
2817 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2818 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2819 ;; remove the first column
2820 (replace-match "\\1|" t nil x
))))
2823 (defun org-export-cleanup-toc-line (s)
2824 "Remove tags and timestamps from lines going into the toc."
2825 (when (memq org-export-with-tags
'(not-in-toc nil
))
2826 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2827 (setq s
(replace-match "" t t s
))))
2828 (when org-export-remove-timestamps-from-toc
2829 (while (string-match org-maybe-keyword-time-regexp s
)
2830 (setq s
(replace-match "" t t s
))))
2831 (while (string-match org-bracket-link-regexp s
)
2832 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2834 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
2835 (setq s
(replace-match "" t t s
)))
2838 (defun org-create-multibrace-regexp (left right n
)
2839 "Create a regular expression which will match a balanced sexp.
2840 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2841 as single character strings.
2842 The regexp returned will match the entire expression including the
2843 delimiters. It will also define a single group which contains the
2844 match except for the outermost delimiters. The maximum depth of
2845 stacked delimiters is N. Escaping delimiters is not possible."
2846 (let* ((nothing (concat "[^" left right
"]*?"))
2849 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
2852 re
(concat re or next
)
2853 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
2854 (concat left
"\\(" re
"\\)" right
)))
2856 (defvar org-match-substring-regexp
2858 "\\([^\\]\\)\\([_^]\\)\\("
2859 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2861 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
2863 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2864 "The regular expression matching a sub- or superscript.")
2866 (defvar org-match-substring-with-braces-regexp
2868 "\\([^\\]\\)\\([_^]\\)\\("
2869 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2871 "The regular expression matching a sub- or superscript, forcing braces.")
2874 (defun org-get-text-property-any (pos prop
&optional object
)
2875 (or (get-text-property pos prop object
)
2876 (and (setq pos
(next-single-property-change pos prop object
))
2877 (get-text-property pos prop object
))))
2879 (defun org-export-get-coderef-format (path desc
)
2881 (if (and desc
(string-match
2882 (regexp-quote (concat "(" path
")"))
2884 (replace-match "%s" t t desc
)
2887 (defun org-export-push-to-kill-ring (format)
2888 "Push buffer content to kill ring.
2889 The depends on the variable `org-export-copy-to-kill'."
2890 (when org-export-copy-to-kill-ring
2891 (org-kill-new (buffer-string))
2892 (when (fboundp 'x-set-selection
)
2893 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
2894 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
2895 (message "%s export done, pushed to kill ring and clipboard" format
)))
2899 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2901 ;;; org-exp.el ends here