1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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
)
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."
51 (defgroup org-export-general nil
52 "General options for exporting Org-mode files."
53 :tag
"Org Export General"
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
60 :group
'org-export-general
62 (const :tag
"Never" nil
)
63 (const :tag
"Always" t
)
64 (const :tag
"Make the user confirm for each file" confirm
)))
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
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
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
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
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
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:
138 -----+----------+--------
144 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
145 :group
'org-export-translation
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" "Índex" "Peus de pàgina")
163 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
164 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
165 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
166 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
167 ("es" "Autor" "Fecha" "Índice" "Pies de página")
168 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
169 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
170 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
171 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
172 ("it" "Autore" "Data" "Indice" "Note a piè 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ści" "Przypis")
178 ("sv" "Författare" "Datum" "Innehå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
185 (string :tag
"HTML language tag")
186 (string :tag
"Author")
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
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
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
219 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
220 :group
'org-export-general
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
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
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
242 :group
'org-export-general
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\"
266 :group
'org-export-general
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
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
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
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
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
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
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,
324 :group
'org-export-general
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
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
342 (defcustom org-export-with-timestamps t
343 "If nil, do not export time stamps and associated keywords."
344 :group
'org-export-general
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
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
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
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
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"
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
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
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
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 α and \\AA to Å.
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-entities' and the user option
485 Not all export backends support this.
487 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
488 :group
'org-export-translation
489 :group
'org-export-latex
492 (defcustom org-export-with-LaTeX-fragments nil
493 "Non-nil means convert LaTeX fragments to images when exporting to HTML.
494 When set, the exporter will find LaTeX environments if the \\begin line is
495 the first non-white thing on a line. It will also find the math delimiters
496 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
499 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
501 The default is nil, because this option needs the `dvipng' program which
502 is not available on all systems."
503 :group
'org-export-translation
504 :group
'org-export-latex
507 (defcustom org-export-with-fixed-width t
508 "Non-nil means lines starting with \":\" will be in fixed width font.
509 This can be used to have pre-formatted text, fragments of code etc. For
511 : ;; Some Lisp examples
514 will be looking just like this in also HTML. See also the QUOTE keyword.
515 Not all export backends support this.
517 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
518 :group
'org-export-translation
521 (defcustom org-match-sexp-depth
3
522 "Number of stacked braces for sub/superscript matching.
523 This has to be set before loading org.el to be effective."
524 :group
'org-export-translation
527 (defgroup org-export-tables nil
528 "Options for exporting tables in Org-mode."
529 :tag
"Org Export Tables"
532 (defcustom org-export-with-tables t
533 "If non-nil, lines starting with \"|\" define a table.
536 | Name | Address | Birthday |
537 |-------------+----------+-----------|
538 | Arthur Dent | England | 29.2.2100 |
540 Not all export backends support this.
542 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
543 :group
'org-export-tables
546 (defcustom org-export-highlight-first-table-line t
547 "Non-nil means highlight the first table line.
548 In HTML export, this means use <th> instead of <td>.
549 In tables created with table.el, this applies to the first table line.
550 In Org-mode tables, all lines before the first horizontal separator
551 line will be formatted with <th> tags."
552 :group
'org-export-tables
555 (defcustom org-export-table-remove-special-lines t
556 "Remove special lines and marking characters in calculating tables.
557 This removes the special marking character column from tables that are set
558 up for spreadsheet calculations. It also removes the entire lines
559 marked with `!', `_', or `^'. The lines with `$' are kept, because
560 the values of constants may be useful to have."
561 :group
'org-export-tables
564 (defcustom org-export-prefer-native-exporter-for-tables nil
565 "Non-nil means always export tables created with table.el natively.
566 Natively means use the HTML code generator in table.el.
567 When nil, Org-mode's own HTML generator is used when possible (i.e. if
568 the table does not use row- or column-spanning). This has the
569 advantage, that the automatic HTML conversions for math symbols and
570 sub/superscripts can be applied. Org-mode's HTML generator is also
571 much faster. The LaTeX exporter always use the native exporter for
573 :group
'org-export-tables
577 (defgroup org-export-xml nil
578 "Options specific for XML export of Org-mode files."
579 :tag
"Org Export XML"
584 ;;; Variables, constants, and parameter plists
586 (defconst org-level-max
20)
588 (defvar org-current-export-file nil
) ; dynamically scoped parameter
589 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
590 (defvar org-export-opt-plist nil
591 "Contains the current option plist.")
592 (defvar org-last-level nil
) ; dynamically scoped variable
593 (defvar org-min-level nil
) ; dynamically scoped variable
594 (defvar org-levels-open nil
) ; dynamically scoped parameter
596 (defconst org-export-plist-vars
597 '((:link-up nil org-export-html-link-up
)
598 (:link-home nil org-export-html-link-home
)
599 (:language nil org-export-default-language
)
600 (:keywords nil org-export-page-keywords
)
601 (:description nil org-export-page-description
)
602 (:customtime nil org-display-custom-times
)
603 (:headline-levels
"H" org-export-headline-levels
)
604 (:section-numbers
"num" org-export-with-section-numbers
)
605 (:section-number-format nil org-export-section-number-format
)
606 (:table-of-contents
"toc" org-export-with-toc
)
607 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
608 (:archived-trees nil org-export-with-archived-trees
)
609 (:emphasize
"*" org-export-with-emphasize
)
610 (:sub-superscript
"^" org-export-with-sub-superscripts
)
611 (:special-strings
"-" org-export-with-special-strings
)
612 (:footnotes
"f" org-export-with-footnotes
)
613 (:drawers
"d" org-export-with-drawers
)
614 (:tags
"tags" org-export-with-tags
)
615 (:todo-keywords
"todo" org-export-with-todo-keywords
)
616 (:priority
"pri" org-export-with-priority
)
617 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
618 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
619 (:latex-listings nil org-export-latex-listings
)
620 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
621 (:fixed-width
":" org-export-with-fixed-width
)
622 (:timestamps
"<" org-export-with-timestamps
)
623 (:author-info
"author" org-export-author-info
)
624 (:email-info
"email" org-export-email-info
)
625 (:creator-info
"creator" org-export-creator-info
)
626 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
627 (:tables
"|" org-export-with-tables
)
628 (:table-auto-headline nil org-export-highlight-first-table-line
)
629 (:style-include-default nil org-export-html-style-include-default
)
630 (:style-include-scripts nil org-export-html-style-include-scripts
)
631 (:style nil org-export-html-style
)
632 (:style-extra nil org-export-html-style-extra
)
633 (:agenda-style nil org-agenda-export-html-style
)
634 (:convert-org-links nil org-export-html-link-org-files-as-html
)
635 (:inline-images nil org-export-html-inline-images
)
636 (:html-extension nil org-export-html-extension
)
637 (:xml-declaration nil org-export-html-xml-declaration
)
638 (:html-table-tag nil org-export-html-table-tag
)
639 (:expand-quoted-html
"@" org-export-html-expand
)
640 (:timestamp nil org-export-html-with-timestamp
)
641 (:publishing-directory nil org-export-publishing-directory
)
642 (:preamble nil org-export-html-preamble
)
643 (:postamble nil org-export-html-postamble
)
644 (:auto-preamble nil org-export-html-auto-preamble
)
645 (:auto-postamble nil org-export-html-auto-postamble
)
646 (:author nil user-full-name
)
647 (:email nil user-mail-address
)
648 (:select-tags nil org-export-select-tags
)
649 (:exclude-tags nil org-export-exclude-tags
)
651 (:latex-image-options nil org-export-latex-image-default-option
))
652 "List of properties that represent export/publishing variables.
653 Each element is a list of 3 items:
654 1. The property that is used internally, and also for org-publish-project-alist
655 2. The string that can be used in the OPTION lines to set this option,
656 or nil if this option cannot be changed in this way
657 3. The customization variable that sets the default for this option."
660 (defun org-default-export-plist ()
661 "Return the property list with default settings for the export variables."
662 (let* ((infile (org-infile-export-plist))
663 (letbind (plist-get infile
:let-bind
))
664 (l org-export-plist-vars
) rtn e s v
)
665 (while (setq e
(pop l
))
668 ((assq s letbind
) (nth 1 (assq s letbind
)))
669 ((boundp s
) (symbol-value s
))
671 rtn
(cons (car e
) (cons v rtn
))))
674 (defvar org-export-inbuffer-options-extra nil
675 "List of additional in-buffer options that should be detected.
676 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
677 etc. Extensions can add to this list to get their options detected, and they
678 can then add a function to `org-export-options-filters' to process these
680 Each element in this list must be a list, with the in-buffer keyword as car,
681 and a property (a symbol) as the next element. All occurrences of the
682 keyword will be found, the values concatenated with a space character
683 in between, and the result stored in the export options property list.")
685 (defvar org-export-options-filters nil
686 "Functions to be called to finalize the export/publishing options.
687 All these options are stored in a property list, and each of the functions
688 in this hook gets a chance to modify this property list. Each function
689 must accept the property list as an argument, and must return the (possibly
692 ;; FIXME: should we fold case here?
693 (defun org-infile-export-plist ()
694 "Return the property list with file-local settings for export."
698 (goto-char (point-min))
699 (let ((re (org-make-options-regexp
701 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
702 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
703 "LATEX_HEADER" "LATEX_CLASS"
704 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
705 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND")
706 (mapcar 'car org-export-inbuffer-options-extra
))))
707 p key val text options a pr style
708 latex-header latex-class macros letbind
709 ext-setup-or-nil setup-contents
(start 0))
710 (while (or (and ext-setup-or-nil
711 (string-match re ext-setup-or-nil start
)
712 (setq start
(match-end 0)))
713 (and (setq ext-setup-or-nil nil start
0)
714 (re-search-forward re nil t
)))
715 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
716 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
718 ((setq a
(assoc key org-export-inbuffer-options-extra
))
720 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
721 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
722 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
723 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
724 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
725 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
726 ((string-equal key
"DESCRIPTION")
727 (setq p
(plist-put p
:description val
)))
728 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
729 ((string-equal key
"STYLE")
730 (setq style
(concat style
"\n" val
)))
731 ((string-equal key
"LATEX_HEADER")
732 (setq latex-header
(concat latex-header
"\n" val
)))
733 ((string-equal key
"LATEX_CLASS")
734 (setq latex-class val
))
735 ((string-equal key
"TEXT")
736 (setq text
(if text
(concat text
"\n" val
) val
)))
737 ((string-equal key
"OPTIONS")
738 (setq options
(concat val
" " options
)))
739 ((string-equal key
"BIND")
740 (push (read (concat "(" val
")")) letbind
))
741 ((string-equal key
"LINK_UP")
742 (setq p
(plist-put p
:link-up val
)))
743 ((string-equal key
"LINK_HOME")
744 (setq p
(plist-put p
:link-home val
)))
745 ((string-equal key
"EXPORT_SELECT_TAGS")
746 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
747 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
748 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
749 ((string-equal key
"MACRO")
751 ((equal key
"SETUPFILE")
752 (setq setup-contents
(org-file-contents
754 (org-remove-double-quotes
757 (if (not ext-setup-or-nil
)
758 (setq ext-setup-or-nil setup-contents start
0)
759 (setq ext-setup-or-nil
760 (concat (substring ext-setup-or-nil
0 start
)
761 "\n" setup-contents
"\n"
762 (substring ext-setup-or-nil start
)))))))
763 (setq p
(plist-put p
:text text
))
764 (when (and letbind
(org-export-confirm-letbind))
765 (setq p
(plist-put p
:let-bind letbind
)))
766 (when style
(setq p
(plist-put p
:style-extra style
)))
768 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
770 (setq p
(plist-put p
:latex-class latex-class
)))
772 (setq p
(org-export-add-options-to-plist p options
)))
773 ;; Add macro definitions
774 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
775 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
777 p
:macro-modification-time
778 (and (buffer-file-name)
779 (file-exists-p (buffer-file-name))
781 "(eval (format-time-string \"$1\" '"
782 (prin1-to-string (nth 5 (file-attributes
783 (buffer-file-name))))
785 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
786 (file-name-nondirectory
787 (buffer-file-name)))))
788 (while (setq val
(pop macros
))
789 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
792 (concat ":macro-" (downcase (match-string 1 val
))))
793 (org-export-interpolate-newlines (match-string 2 val
))))))
796 (defun org-export-interpolate-newlines (s)
797 (while (string-match "\\\\n" s
)
798 (setq s
(replace-match "\n" t t s
)))
801 (defvar org-export-allow-BIND-local nil
)
802 (defun org-export-confirm-letbind ()
803 "Can we use #+BIND values during export?
804 By default this will ask fro confirmation by the user, to divert possible
807 ((not org-export-allow-BIND
) nil
)
808 ((eq org-export-allow-BIND t
) t
)
809 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
810 org-export-allow-BIND-local
)
811 (t (org-set-local 'org-export-allow-BIND-local
812 (yes-or-no-p "Allow BIND values in this buffer? ")))))
814 (defun org-install-letbind ()
815 "Install the values from #+BIND lines as local variables."
816 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
818 (while (setq pair
(pop letbind
))
819 (org-set-local (car pair
) (nth 1 pair
)))))
821 (defun org-export-add-options-to-plist (p options
)
822 "Parse an OPTIONS line and set values in the property list P."
825 (let ((op org-export-plist-vars
))
826 (while (setq o
(pop op
))
828 (string-match (concat (regexp-quote (nth 1 o
))
829 ":\\([^ \t\n\r;,.]*\\)")
831 (setq p
(plist-put p
(car o
)
832 (car (read-from-string
833 (match-string 1 options
))))))))))
836 (defun org-export-add-subtree-options (p pos
)
837 "Add options in subtree at position POS to property list P."
840 (when (org-at-heading-p)
842 ;; This is actually read in `org-export-get-title-from-subtree'
843 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
844 ;; (setq p (plist-put p :title a)))
845 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
846 (setq p
(plist-put p
:text a
)))
847 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
848 (setq p
(plist-put p
:author a
)))
849 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
850 (setq p
(plist-put p
:date a
)))
851 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
852 (setq p
(org-export-add-options-to-plist p a
)))))
855 (defun org-export-directory (type plist
)
856 (let* ((val (plist-get plist
:publishing-directory
))
858 (or (cdr (assoc type val
)) ".")
862 (defun org-export-process-option-filters (plist)
863 (let ((functions org-export-options-filters
) f
)
864 (while (setq f
(pop functions
))
865 (setq plist
(funcall f plist
))))
869 (defun org-export (&optional arg
)
870 "Export dispatcher for Org-mode.
871 When `org-export-run-in-background' is non-nil, try to run the command
872 in the background. This will be done only for commands that write
873 to a file. For details see the docstring of `org-export-run-in-background'.
875 The prefix argument ARG will be passed to the exporter. However, if
876 ARG is a double universal prefix `C-u C-u', that means to inverse the
877 value of `org-export-run-in-background'."
879 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
881 (help "[t] insert the export option template
882 \[v] limit export to visible part of outline tree
883 \[1] only export the current subtree
884 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
886 \[a/n/u] export as ASCII/Latin-1/UFT-8 [A/N/U] to temporary buffer
888 \[h] export as HTML [H] to temporary buffer [R] export region
889 \[b] export as HTML and open in browser
891 \[l] export as LaTeX [L] to temporary buffer
892 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
894 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
896 \[m] export as Freemind mind map
898 \[g] export using Wes Hardaker's generic exporter
900 \[i] export current file as iCalendar file
901 \[I] export all agenda files as iCalendar files [c] ...as one combined file
903 \[F] publish current file [P] publish current project
904 \[X] publish a project... [E] publish every projects")
906 '((?t org-insert-export-options-template nil
)
907 (?v org-export-visible nil
)
908 (?a org-export-as-ascii t
)
909 (?A org-export-as-ascii-to-buffer t
)
910 (?n org-export-as-latin1 t
)
911 (?N org-export-as-latin1-to-buffer t
)
912 (?u org-export-as-utf8 t
)
913 (?U org-export-as-utf8-to-buffer t
)
914 (?h org-export-as-html t
)
915 (?b org-export-as-html-and-open t
)
916 (?H org-export-as-html-to-buffer nil
)
917 (?R org-export-region-as-html nil
)
918 (?x org-export-as-xoxo t
)
919 (?g org-export-generic t
)
920 (?D org-export-as-docbook t
)
921 (?V org-export-as-docbook-pdf-and-open t
)
922 (?m org-export-as-freemind t
)
923 (?l org-export-as-latex t
)
924 (?p org-export-as-pdf t
)
925 (?d org-export-as-pdf-and-open t
)
926 (?L org-export-as-latex-to-buffer nil
)
927 (?i org-export-icalendar-this-file t
)
928 (?I org-export-icalendar-all-agenda-files t
)
929 (?c org-export-icalendar-combine-agenda-files t
)
930 (?F org-publish-current-file t
)
931 (?P org-publish-current-project t
)
933 (?E org-publish-all t
)))
935 (cpos (point)) (cbuf (current-buffer)) bpos
)
937 (save-window-excursion
938 (delete-other-windows)
939 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
941 (org-fit-window-to-buffer (get-buffer-window
942 "*Org Export/Publishing Help*"))
943 (message "Select command: ")
944 (setq r1
(read-char-exclusive))
947 (message "Select command (for subtree): ")
948 (setq r1
(read-char-exclusive)))
950 (let ((case-fold-search t
))
951 (if (re-search-backward
952 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
955 (org-back-to-heading t
)
958 (message "Select command (for subtree): ")
959 (setq r1
(read-char-exclusive)))
960 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
962 (and bpos
(goto-char bpos
))
963 (setq r2
(if (< r1
27) (+ r1
96) r1
))
964 (unless (setq ass
(assq r2 cmds
))
965 (error "No command associated with key %c" r1
))
966 (if (and bg
(nth 2 ass
)
967 (not (buffer-base-buffer))
968 (not (org-region-active-p)))
969 ;; execute in background
970 (let ((p (start-process
971 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
973 (expand-file-name invocation-name invocation-directory
)
976 "--eval" "(require 'org-exp)"
977 "--eval" "(setq org-wait .2)"
979 "-f" (symbol-name (nth 1 ass
)))))
980 (set-process-sentinel p
'org-export-process-sentinel
)
981 (message "Background process \"%s\": started" p
))
982 ;; background processing not requested, or not possible
983 (if subtree-p
(progn (outline-mark-subtree) (activate-mark)))
984 (call-interactively (nth 1 ass
))
985 (when (and bpos
(get-buffer-window cbuf
))
986 (let ((cw (selected-window)))
987 (select-window (get-buffer-window cbuf
))
990 (select-window cw
))))))
992 (defun org-export-process-sentinel (process status
)
993 (if (string-match "\n+\\'" status
)
994 (setq status
(substring status
0 -
1)))
995 (message "Background process \"%s\": %s" process status
))
997 ;;; General functions for all backends
999 (defvar org-export-target-aliases nil
1000 "Alist of targets with invisible aliases.")
1001 (defvar org-export-preferred-target-alist nil
1002 "Alist of section id's with preferred aliases.")
1003 (defvar org-export-id-target-alist nil
1004 "Alist of section id's with preferred aliases.")
1005 (defvar org-export-code-refs nil
1006 "Alist of code references and line numbers")
1008 (defun org-export-preprocess-string (string &rest parameters
)
1009 "Cleanup STRING so that that the true exported has a more consistent source.
1010 This function takes STRING, which should be a buffer-string of an org-file
1011 to export. It then creates a temporary buffer where it does its job.
1012 The result is then again returned as a string, and the exporter works
1013 on this string to produce the exported version."
1015 (let* ((htmlp (plist-get parameters
:for-html
))
1016 (asciip (plist-get parameters
:for-ascii
))
1017 (latexp (plist-get parameters
:for-LaTeX
))
1018 (docbookp (plist-get parameters
:for-docbook
))
1019 (backend (cond (htmlp 'html
)
1022 (docbookp 'docbook
)))
1023 (archived-trees (plist-get parameters
:archived-trees
))
1024 (inhibit-read-only t
)
1025 (drawers org-drawers
)
1026 (outline-regexp "\\*+ ")
1029 (setq org-export-target-aliases nil
1030 org-export-preferred-target-alist nil
1031 org-export-id-target-alist nil
1032 org-export-code-refs nil
)
1034 (with-current-buffer (get-buffer-create " org-mode-tmp")
1037 (setq case-fold-search t
)
1039 (let ((inhibit-read-only t
))
1040 (remove-text-properties (point-min) (point-max)
1043 ;; Remove license-to-kill stuff
1044 ;; The caller marks some stuff for killing, stuff that has been
1045 ;; used to create the page title, for example.
1046 (org-export-kill-licensed-text)
1048 (let ((org-inhibit-startup t
)) (org-mode))
1049 (setq case-fold-search t
)
1050 (org-install-letbind)
1053 (run-hooks 'org-export-preprocess-hook
)
1055 ;; Process the macros
1056 (org-export-preprocess-apply-macros)
1057 (run-hooks 'org-export-preprocess-after-macros-hook
)
1059 (untabify (point-min) (point-max))
1061 ;; Handle include files, and call a hook
1062 (org-export-handle-include-files)
1063 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1065 ;; Get rid of archived trees
1066 (org-export-remove-archived-trees archived-trees
)
1068 ;; Remove comment environment and comment subtrees
1069 (org-export-remove-comment-blocks-and-subtrees)
1071 ;; Get rid of excluded trees, and call a hook
1072 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1073 (plist-get parameters
:exclude-tags
))
1074 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1076 ;; Handle source code snippets
1077 (org-export-replace-src-segments-and-examples backend
)
1079 ;; Protect short examples marked by a leading colon
1080 (org-export-protect-colon-examples)
1082 ;; Normalize footnotes
1083 (when (plist-get parameters
:footnotes
)
1084 (org-footnote-normalize nil t
))
1086 ;; Find all headings and compute the targets for them
1087 (setq target-alist
(org-export-define-heading-targets target-alist
))
1089 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1091 ;; Find HTML special classes for headlines
1092 (org-export-remember-html-container-classes)
1094 ;; Get rid of drawers
1095 (org-export-remove-or-extract-drawers
1096 drawers
(plist-get parameters
:drawers
) backend
)
1098 ;; Get the correct stuff before the first headline
1099 (when (plist-get parameters
:skip-before-1st-heading
)
1100 (goto-char (point-min))
1101 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1102 (delete-region (point-min) (match-beginning 0))
1103 (goto-char (point-min))
1105 (when (plist-get parameters
:add-text
)
1106 (goto-char (point-min))
1107 (insert (plist-get parameters
:add-text
) "\n"))
1109 ;; Remove todo-keywords before exporting, if the user has requested so
1110 (org-export-remove-headline-metadata parameters
)
1112 ;; Find targets in comments and move them out of comments,
1113 ;; but mark them as targets that should be invisible
1114 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1116 ;; Select and protect backend specific stuff, throw away stuff
1117 ;; that is specific for other backends
1118 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1119 (org-export-select-backend-specific-text backend
)
1121 ;; Protect quoted subtrees
1122 (org-export-protect-quoted-subtrees)
1124 ;; Remove clock lines
1125 (org-export-remove-clock-lines)
1127 ;; Protect verbatim elements
1128 (org-export-protect-verbatim)
1130 ;; Blockquotes, verse, and center
1131 (org-export-mark-blockquote-verse-center)
1132 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1134 ;; Remove timestamps, if the user has requested so
1135 (unless (plist-get parameters
:timestamps
)
1136 (org-export-remove-timestamps))
1138 ;; Attach captions to the correct object
1139 (setq target-alist
(org-export-attach-captions-and-attributes
1140 backend target-alist
))
1142 ;; Find matches for radio targets and turn them into internal links
1143 (org-export-mark-radio-links)
1145 ;; Find all links that contain a newline and put them into a single line
1146 (org-export-concatenate-multiline-links)
1148 ;; Normalize links: Convert angle and plain links into bracket links
1149 ;; and expand link abbreviations
1150 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1151 (org-export-normalize-links)
1153 ;; Find all internal links. If they have a fuzzy match (i.e. not
1154 ;; a *dedicated* target match, let the link point to the
1155 ;; corresponding section.
1156 (org-export-target-internal-links target-alist
)
1158 ;; Find multiline emphasis and put them into single line
1159 (when (plist-get parameters
:emph-multiline
)
1160 (org-export-concatenate-multiline-emphasis))
1162 ;; Remove special table lines
1163 (when org-export-table-remove-special-lines
1164 (org-export-remove-special-table-lines))
1167 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1169 ;; LaTeX-specific preprocessing
1171 (require 'org-latex nil
)
1172 (org-export-latex-preprocess parameters
))
1174 ;; ASCII-specific preprocessing
1176 (org-export-ascii-preprocess parameters
))
1178 ;; HTML-specific preprocessing
1180 (org-export-html-preprocess parameters
))
1182 ;; DocBook-specific preprocessing
1184 (require 'org-docbook nil
)
1185 (org-export-docbook-preprocess parameters
))
1187 ;; Remove or replace comments
1188 (org-export-handle-comments (plist-get parameters
:comments
))
1190 ;; Run the final hook
1191 (run-hooks 'org-export-preprocess-final-hook
)
1193 (setq rtn
(buffer-string)))
1194 (kill-buffer " org-mode-tmp")
1197 (defun org-export-kill-licensed-text ()
1198 "Remove all text that is marked with a :org-license-to-kill property."
1200 (while (setq p
(text-property-any (point-min) (point-max)
1201 :org-license-to-kill t
))
1203 p
(or (next-single-property-change p
:org-license-to-kill
)
1206 (defun org-export-define-heading-targets (target-alist)
1207 "Find all headings and define the targets for them.
1208 The new targets are added to TARGET-ALIST, which is also returned."
1209 (goto-char (point-min))
1210 (org-init-section-numbers)
1211 (let ((re (concat "^" org-outline-regexp
1212 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1213 level target last-section-target a id
)
1214 (while (re-search-forward re nil t
)
1217 (setq id
(org-match-string-no-properties 2))
1218 (push (cons id target
) target-alist
)
1219 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1221 (push (list last-section-target
)
1222 org-export-target-aliases
)
1223 (car org-export-target-aliases
))))
1224 (push (caar target-alist
) (cdr a
))
1225 (when (equal (match-string 1) "CUSTOM_ID")
1226 (if (not (assoc last-section-target
1227 org-export-preferred-target-alist
))
1228 (push (cons last-section-target id
)
1229 org-export-preferred-target-alist
)))
1230 (when (equal (match-string 1) "ID")
1231 (if (not (assoc last-section-target
1232 org-export-id-target-alist
))
1233 (push (cons last-section-target
(concat "ID-" id
))
1234 org-export-id-target-alist
))))
1235 (setq level
(org-reduced-level
1236 (save-excursion (goto-char (point-at-bol))
1237 (org-outline-level))))
1238 (setq target
(org-solidify-link-text
1239 (format "sec-%s" (org-section-number level
))))
1240 (setq last-section-target target
)
1241 (push (cons target target
) target-alist
)
1242 (add-text-properties
1243 (point-at-bol) (point-at-eol)
1244 (list 'target target
)))))
1247 (defun org-export-handle-invisible-targets (target-alist)
1248 "Find targets in comments and move them out of comments.
1249 Mark them as invisible targets."
1251 (goto-char (point-min))
1252 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1253 ;; Check if the line before or after is a headline with a target
1254 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1255 (get-text-property (point-at-bol 2) 'target
)))
1257 ;; use the existing target in a neighboring line
1258 (setq tmp
(match-string 2))
1260 (and (looking-at "\n") (delete-char 1))
1261 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1263 (setq a
(or (assoc target org-export-target-aliases
)
1265 (push (list target
) org-export-target-aliases
)
1266 (car org-export-target-aliases
))))
1268 ;; Make an invisible target
1269 (replace-match "\\1(INVISIBLE)"))))
1272 (defun org-export-target-internal-links (target-alist)
1273 "Find all internal links and assign targets to them.
1274 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1275 let the link point to the corresponding section.
1276 This function also handles the id links, if they have a match in
1278 (goto-char (point-min))
1279 (while (re-search-forward org-bracket-link-regexp nil t
)
1280 (org-if-unprotected-at (1+ (match-beginning 0))
1281 (let* ((md (match-data))
1282 (desc (match-end 2))
1283 (link (org-link-unescape (match-string 1)))
1284 (slink (org-solidify-link-text link
))
1285 found props pos cref
1288 ((= (string-to-char link
) ?
#)
1289 ;; user wants exactly this link
1291 ((cdr (assoc slink target-alist
))
1292 (or (cdr (assoc (assoc slink target-alist
)
1293 org-export-preferred-target-alist
))
1294 (cdr (assoc slink target-alist
))))
1295 ((and (string-match "^id:" link
)
1296 (cdr (assoc (substring link
3) target-alist
))))
1297 ((string-match "^(\\(.*\\))$" link
)
1298 (setq cref
(match-string 1 link
))
1299 (concat "coderef:" cref
))
1300 ((string-match org-link-types-re link
) nil
)
1301 ((or (file-name-absolute-p link
)
1302 (string-match "^\\." link
))
1306 (setq found
(condition-case nil
(org-link-search link
)
1309 (or (org-on-heading-p)
1310 (not (eq found
'dedicated
))))
1311 (or (get-text-property (point) 'target
)
1314 (1- (or (previous-single-property-change
1315 (point) 'target
) 0)))
1319 (goto-char (match-beginning 1))
1320 (setq props
(text-properties-at (point)))
1321 (delete-region (match-beginning 1) (match-end 1))
1324 (unless desc
(insert "][" link
))
1325 (add-text-properties pos
(point) props
))))))
1327 (defun org-export-remember-html-container-classes ()
1328 "Store the HTML_CONTAINER_CLASS properties in a text property."
1329 (goto-char (point-min))
1331 (while (re-search-forward
1332 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(\\S-+\\)" nil t
)
1333 (setq class
(match-string 1))
1335 (org-back-to-heading t
)
1336 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1338 (defvar org-export-format-drawer-function nil
1339 "Function to be called to format the contents of a drawer.
1340 The function must accept three parameters:
1341 BACKEND one of the symbols html, docbook, latex, ascii, xoxo
1342 NAME the drawer name, like \"PROPERTIES\"
1343 CONTENT the content of the drawer.
1344 The function should return the text to be inserted into the buffer.
1345 If this is nil, `org-export-format-drawer' is used as a default.")
1347 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend
)
1348 "Remove drawers, or extract and format the content.
1349 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1350 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1351 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1352 EXP-DRAWERS will be removed.
1353 BACKEND is the current export backend."
1354 (goto-char (point-min))
1355 (let ((re (concat "^[ \t]*:\\("
1356 (mapconcat 'identity all-drawers
"\\|")
1358 name beg beg-content eol content
)
1359 (while (re-search-forward re nil t
)
1361 (setq name
(match-string 1))
1362 (setq beg
(match-beginning 0)
1363 beg-content
(1+ (point-at-eol))
1365 (if (not (and (re-search-forward
1366 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1369 (goto-char (match-beginning 0))
1370 (and (looking-at ".*\n?") (replace-match ""))
1371 (setq content
(buffer-substring beg-content
(point)))
1372 (delete-region beg
(point))
1373 (when (or (eq exp-drawers t
)
1374 (member name exp-drawers
))
1375 (setq content
(funcall (or org-export-format-drawer-function
1376 'org-export-format-drawer
)
1377 name content backend
))
1378 (insert content
)))))))
1380 (defun org-export-format-drawer (name content backend
)
1381 "Format the content of a drawer as a colon example."
1382 (if (string-match "[ \t]+\\'" content
)
1383 (setq content
(substring content
(match-beginning 0))))
1384 (while (string-match "\\`[ \t]*\n" content
)
1385 (setq content
(substring content
(match-end 0))))
1386 (setq content
(org-remove-indentation content
))
1387 (setq content
(concat ": " (mapconcat 'identity
1388 (org-split-string content
"\n")
1391 (setq content
(concat " : " (upcase name
) "\n" content
))
1392 (org-add-props content nil
'org-protected t
))
1394 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1395 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1396 Both arguments are lists of tags.
1397 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1399 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1401 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1402 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1405 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1409 (goto-char (point-min))
1410 (when (and select-tags
1412 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1413 ;; At least one tree is marked for export, this means
1414 ;; all the unmarked stuff needs to go.
1415 ;; Dig out the trees that should be exported
1416 (goto-char (point-min))
1417 (outline-next-heading)
1419 (put-text-property beg
(point-max) :org-delete t
)
1420 (while (re-search-forward re-sel nil t
)
1421 (when (org-on-heading-p)
1422 (org-back-to-heading)
1423 (remove-text-properties
1424 (max (1- (point)) (point-min))
1425 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1427 (while (and (org-up-heading-safe)
1428 (get-text-property (point) :org-delete
))
1429 (remove-text-properties (max (1- (point)) (point-min))
1430 (point-at-eol) '(:org-delete t
)))
1432 ;; Remove the trees explicitly marked for noexport
1434 (goto-char (point-min))
1435 (while (re-search-forward re-excl nil t
)
1436 (when (org-at-heading-p)
1437 (org-back-to-heading t
)
1439 (org-end-of-subtree t t
)
1440 (delete-region beg
(point))
1441 (when (featurep 'org-inlinetask
)
1442 (org-inlinetask-remove-END-maybe)))))
1443 ;; Remove everything that is now still marked for deletion
1444 (goto-char (point-min))
1445 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1446 (setq end
(or (next-single-property-change beg
:org-delete
)
1448 (delete-region beg end
))))
1450 (defun org-export-remove-archived-trees (export-archived-trees)
1451 "Remove archived trees.
1452 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1453 When it is t, the entire archived tree will be exported.
1454 When it is nil the entire tree including the headline will be removed
1456 (let ((re-archive (concat ":" org-archive-tag
":"))
1458 (when (not (eq export-archived-trees t
))
1459 (goto-char (point-min))
1460 (while (re-search-forward re-archive nil t
)
1461 (if (not (org-on-heading-p t
))
1462 (org-end-of-subtree t
)
1463 (beginning-of-line 1)
1464 (setq a
(if export-archived-trees
1465 (1+ (point-at-eol)) (point))
1466 b
(org-end-of-subtree t
))
1467 (if (> b a
) (delete-region a b
)))))))
1469 (defun org-export-remove-headline-metadata (opts)
1470 "Remove meta data from the headline, according to user options."
1471 (let ((re org-complex-heading-regexp
)
1472 (todo (plist-get opts
:todo-keywords
))
1473 (tags (plist-get opts
:tags
))
1474 (pri (plist-get opts
:priority
))
1477 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1478 (when (or (not todo
) (not tags
) (not pri
))
1479 (goto-char (point-min))
1480 (while (re-search-forward re nil t
)
1482 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1484 (replace-match rpl t t
))))))
1486 (defun org-export-remove-timestamps ()
1487 "Remove timestamps and keywords for export."
1488 (goto-char (point-min))
1489 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1492 (unless (save-match-data (org-at-table-p))
1494 (beginning-of-line 1)
1495 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1496 (replace-match ""))))))
1498 (defun org-export-remove-clock-lines ()
1499 "Remove clock lines for export."
1500 (goto-char (point-min))
1501 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1502 (while (re-search-forward re nil t
)
1504 (replace-match "")))))
1506 (defun org-export-protect-quoted-subtrees ()
1507 "Mark quoted subtrees with the protection property."
1508 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1509 (goto-char (point-min))
1510 (while (re-search-forward re-quote nil t
)
1511 (goto-char (match-beginning 0))
1513 (add-text-properties (point) (org-end-of-subtree t
)
1514 '(org-protected t
)))))
1516 (defun org-export-protect-verbatim ()
1517 "Mark verbatim snippets with the protection property."
1518 (goto-char (point-min))
1519 (while (re-search-forward org-verbatim-re nil t
)
1521 (add-text-properties (match-beginning 4) (match-end 4)
1522 '(org-protected t org-verbatim-emph t
))
1523 (goto-char (1+ (match-end 4))))))
1525 (defun org-export-protect-colon-examples ()
1526 "Protect lines starting with a colon."
1527 (goto-char (point-min))
1528 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1529 (while (re-search-forward re nil t
)
1530 (beginning-of-line 1)
1532 (while (looking-at re
)
1534 (or (eobp) (forward-char 1)))
1535 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1536 '(org-protected t
)))))
1538 (defun org-export-select-backend-specific-text (backend)
1540 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1541 (html "HTML" "BEGIN_HTML" "END_HTML")
1542 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1543 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1544 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1545 (case-fold-search t
)
1546 fmt beg beg-content end end-content
)
1549 (setq fmt
(pop formatters
))
1550 (when (eq (car fmt
) backend
)
1551 ;; This is selected code, put it into the file for real
1552 (goto-char (point-min))
1553 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1554 ":[ \t]*\\(.*\\)") nil t
)
1555 (replace-match "\\1\\2" t
)
1556 (add-text-properties
1557 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1558 '(org-protected t
))))
1559 (goto-char (point-min))
1560 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt
) "\\>.*\n?")
1562 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1563 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt
) "\\>.*\n?")
1565 (setq end
(match-end 0) end-content
(match-beginning 0))
1566 (if (eq (car fmt
) backend
)
1569 (add-text-properties beg-content end-content
'(org-protected t
))
1570 (delete-region (match-beginning 0) (match-end 0))
1573 (delete-region (point) (1+ (point-at-eol)))))
1574 ;; No, this is for a different backend, kill it
1575 (delete-region beg end
)))))))
1577 (defun org-export-mark-blockquote-verse-center ()
1578 "Mark block quote and verse environments with special cookies.
1579 These special cookies will later be interpreted by the backend."
1581 (let (type t1 ind beg end beg1 end1 content
)
1582 (goto-char (point-min))
1583 (while (re-search-forward
1584 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1586 (setq ind
(length (match-string 1))
1587 type
(downcase (match-string 3))
1588 t1
(if (equal type
"quote") "blockquote" type
))
1589 (setq beg
(match-beginning 0)
1590 beg1
(1+ (match-end 0)))
1591 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1592 (setq end
(1+ (point-at-eol))
1593 end1
(1- (match-beginning 0)))
1594 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1595 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1597 "ORG-" (upcase t1
) "-END\n"))
1598 (delete-region beg end
)
1599 (insert (org-add-props content nil
'original-indentation ind
))))))
1601 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1602 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1603 If the next thing following is a table, add the text properties to the first
1604 table line. If it is a link, add it to the line containing the link."
1605 (goto-char (point-min))
1606 (remove-text-properties (point-min) (point-max)
1607 '(org-caption nil org-attributes nil
))
1608 (let ((case-fold-search t
)
1609 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1611 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1613 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1615 "^[ \t]*\\(|[^-]\\)"
1617 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1619 (while (re-search-forward re nil t
)
1622 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1624 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1626 (setq label
(org-trim (match-string 3))))
1628 (setq end
(if (match-end 4)
1629 (let ((ee (org-table-end)))
1630 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1632 (add-text-properties (point-at-bol) end
1633 (list 'org-caption cap
1634 'org-attributes attr
1636 (if label
(push (cons label label
) target-alist
))
1638 (setq cap nil attr nil label nil
)))))
1641 (defun org-export-remove-comment-blocks-and-subtrees ()
1642 "Remove the comment environment, and also commented subtrees."
1643 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1645 ;; Remove comment environment
1646 (goto-char (point-min))
1647 (setq case-fold-search t
)
1648 (while (re-search-forward
1649 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t
)
1650 (replace-match "" t t
))
1651 ;; Remove subtrees that are commented
1652 (goto-char (point-min))
1653 (setq case-fold-search nil
)
1654 (while (re-search-forward re-commented nil t
)
1655 (goto-char (match-beginning 0))
1656 (delete-region (point) (org-end-of-subtree t
)))))
1658 (defun org-export-handle-comments (commentsp)
1659 "Remove comments, or convert to backend-specific format.
1660 COMMENTSP can be a format string for publishing comments.
1661 When it is nil, all comments will be removed."
1662 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1664 (goto-char (point-min))
1665 (while (or (looking-at re
)
1666 (re-search-forward re nil t
))
1667 (setq pos
(match-beginning 0))
1669 (not (equal (char-before (match-end 1)) ?
+)))
1670 (progn (add-text-properties
1671 (match-beginning 0) (match-end 0) '(org-protected t
))
1672 (replace-match (format commentsp
(match-string 2)) t t
))
1673 (goto-char (1+ pos
))
1676 (goto-char (max (point-min) (1- pos
))))))))
1678 (defun org-export-mark-radio-links ()
1679 "Find all matches for radio targets and turn them into internal links."
1680 (let ((re-radio (and org-target-link-regexp
1681 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1682 (goto-char (point-min))
1684 (while (re-search-forward re-radio nil t
)
1687 (or (org-in-regexp org-bracket-link-regexp
)
1688 (org-in-regexp org-plain-link-re
)
1689 (org-in-regexp "<<[^<>]+>>")))
1691 (replace-match "\\1[[\\2]]")))))))
1693 (defun org-export-remove-special-table-lines ()
1694 "Remove tables lines that are used for internal purposes."
1695 (goto-char (point-min))
1696 (while (re-search-forward "^[ \t]*|" nil t
)
1697 (beginning-of-line 1)
1698 (if (or (looking-at "[ \t]*| *[!_^] *|")
1704 (or (= (length f
) 0)
1706 "\\`<\\([0-9]\\|[rl]\\|[rl][0-9]+\\)>\\'" f
)))
1707 (org-split-string ;; FIXME, can't we do this without splitting???
1708 (buffer-substring (point-at-bol) (point-at-eol))
1709 "[ \t]*|[ \t]*")))))
1710 (delete-region (max (point-min) (1- (point-at-bol)))
1714 (defun org-export-protect-sub-super (s)
1716 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
1717 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
1720 (defun org-export-normalize-links ()
1721 "Convert all links to bracket links, and expand link abbreviations."
1722 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1723 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1725 (goto-char (point-min))
1726 (while (re-search-forward re-plain-link nil t
)
1727 (goto-char (1- (match-end 0)))
1728 (org-if-unprotected-at (1+ (match-beginning 0))
1729 (let* ((s (concat (match-string 1)
1730 "[[" (match-string 2) ":" (match-string 3)
1731 "][" (match-string 2) ":" (org-export-protect-sub-super
1734 ;; added 'org-link face to links
1735 (put-text-property 0 (length s
) 'face
'org-link s
)
1736 (replace-match s t t
))))
1737 (goto-char (point-min))
1738 (while (re-search-forward re-angle-link nil t
)
1739 (goto-char (1- (match-end 0)))
1741 (let* ((s (concat (match-string 1)
1742 "[[" (match-string 2) ":" (match-string 3)
1743 "][" (match-string 2) ":" (org-export-protect-sub-super
1746 (put-text-property 0 (length s
) 'face
'org-link s
)
1747 (replace-match s t t
))))
1748 (goto-char (point-min))
1749 (while (re-search-forward org-bracket-link-regexp nil t
)
1750 (goto-char (1- (match-end 0)))
1751 (setq nodesc
(not (match-end 3)))
1753 (let* ((xx (save-match-data
1755 (org-link-expand-abbrev (match-string 1)))))
1757 "[[" (org-add-props (copy-sequence xx
)
1758 nil
'org-protected t
'org-no-description nodesc
)
1762 (concat "[" (copy-sequence xx
)
1765 (put-text-property 0 (length s
) 'face
'org-link s
)
1766 (replace-match s t t
))))))
1768 (defun org-export-concatenate-multiline-links ()
1769 "Find multi-line links and put it all into a single line.
1770 This is to make sure that the line-processing export backends
1771 can work correctly."
1772 (goto-char (point-min))
1773 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1774 (org-if-unprotected-at (match-beginning 1)
1775 (replace-match "\\1 \\3")
1776 (goto-char (match-beginning 0)))))
1778 (defun org-export-concatenate-multiline-emphasis ()
1779 "Find multi-line emphasis and put it all into a single line.
1780 This is to make sure that the line-processing export backends
1781 can work correctly."
1782 (goto-char (point-min))
1783 (while (re-search-forward org-emph-re nil t
)
1784 (if (and (not (= (char-after (match-beginning 3))
1785 (char-after (match-beginning 4))))
1786 (save-excursion (goto-char (match-beginning 0))
1787 (save-match-data (not (org-at-table-p)))))
1789 (subst-char-in-region (match-beginning 0) (match-end 0)
1791 (goto-char (1- (match-end 0))))
1792 (goto-char (1+ (match-beginning 0))))))
1794 (defun org-export-grab-title-from-buffer ()
1795 "Get a title for the current document, from looking at the buffer."
1796 (let ((inhibit-read-only t
))
1798 (goto-char (point-min))
1799 (let ((end (if (looking-at org-outline-regexp
)
1801 (save-excursion (outline-next-heading) (point)))))
1802 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1803 ;; Mark the line so that it will not be exported as normal text.
1805 (add-text-properties (match-beginning 0) (match-end 0)
1806 (list :org-license-to-kill t
)))
1807 ;; Return the title string
1808 (org-trim (match-string 0)))))))
1810 (defun org-export-get-title-from-subtree ()
1811 "Return subtree title and exclude it from export."
1812 (let (title (rbeg (region-beginning)) (rend (region-end)))
1815 (when (and (org-at-heading-p)
1816 (>= (org-end-of-subtree t t
) rend
))
1817 ;; This is a subtree, we take the title from the first heading
1819 (looking-at org-todo-line-regexp
)
1820 (setq title
(match-string 3))
1822 (add-text-properties (point) (1+ (point-at-eol))
1823 (list :org-license-to-kill t
)))
1824 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1827 (defun org-solidify-link-text (s &optional alist
)
1828 "Take link text and make a safe target out of it."
1833 (org-split-string s
"[ \t\r\n]+") "=="))
1834 (a (assoc rtn alist
)))
1837 (defun org-get-min-level (lines &optional offset
)
1838 "Get the minimum level in LINES."
1839 (let ((re "^\\(\\*+\\) ") l
)
1841 (while (setq l
(pop lines
))
1842 (if (string-match re l
)
1843 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1847 ;; Variable holding the vector with section numbers
1848 (defvar org-section-numbers
(make-vector org-level-max
0))
1850 (defun org-init-section-numbers ()
1851 "Initialize the vector for the section numbers."
1853 (numbers (nreverse (org-split-string "" "\\.")))
1854 (depth (1- (length org-section-numbers
)))
1855 (i depth
) number-string
)
1858 (aset org-section-numbers i
0)
1859 (setq number-string
(or (car numbers
) "0"))
1860 (if (string-match "\\`[A-Z]\\'" number-string
)
1861 (aset org-section-numbers i
1862 (- (string-to-char number-string
) ?A -
1))
1863 (aset org-section-numbers i
(string-to-number number-string
)))
1867 (defun org-section-number (&optional level
)
1868 "Return a string with the current section number.
1869 When LEVEL is non-nil, increase section numbers on that level."
1870 (let* ((depth (1- (length org-section-numbers
)))
1872 (fmts (car org-export-section-number-format
))
1873 (term (cdr org-export-section-number-format
))
1878 (aset org-section-numbers
1879 level
(1+ (aref org-section-numbers level
))))
1880 (setq idx
(1+ level
))
1881 (while (<= idx depth
)
1883 (aset org-section-numbers idx
0))
1884 (setq idx
(1+ idx
))))
1886 (while (<= idx depth
)
1887 (when (> (aref org-section-numbers idx
) 0)
1888 (setq fmt
(or (pop fmts
) fmt
)
1890 n
(aref org-section-numbers idx
)
1892 (concat string sep
(org-number-to-counter n ctype
))
1893 (concat string
".0"))
1895 (setq idx
(1+ idx
)))
1897 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1898 (setq string
(replace-match "" t nil string
)))
1899 (if (string-match "\\(\\.0\\)+\\'" string
)
1900 (setq string
(replace-match "" t nil string
))))
1901 (concat string term
)))
1903 (defun org-number-to-counter (n type
)
1904 "Concert number N to a string counter, according to TYPE.
1905 TYPE must be a string, any of:
1909 I upper case roman numeral
1910 i lower case roman numeral"
1912 ((equal type
"1") (number-to-string n
))
1913 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1914 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1915 ((equal type
"I") (org-number-to-roman n
))
1916 ((equal type
"i") (downcase (org-number-to-roman n
)))
1917 (t (error "Invalid counter type `%s'" type
))))
1919 (defun org-number-to-roman (n)
1920 "Convert integer N into a roman numeral."
1921 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1922 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1923 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1927 (number-to-string n
)
1929 (if (>= n
(caar roman
))
1930 (setq n
(- n
(caar roman
))
1931 res
(concat res
(cdar roman
)))
1937 (defun org-export-preprocess-apply-macros ()
1938 "Replace macro references."
1939 (goto-char (point-min))
1940 (let (sy val key args args2 s n
)
1941 (while (re-search-forward
1942 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
1944 (unless (save-match-data
1946 (goto-char (point-at-bol))
1947 (looking-at "[ \t]*#\\+macro")))
1948 (setq key
(downcase (match-string 1))
1949 args
(match-string 3))
1950 (when (setq val
(or (plist-get org-export-opt-plist
1951 (intern (concat ":macro-" key
)))
1952 (plist-get org-export-opt-plist
1953 (intern (concat ":" key
)))))
1956 (setq args
(org-split-string args
",[ \t\n]*") args2 nil
)
1957 (setq args
(mapcar 'org-trim args
))
1959 (while (string-match "\\\\\\'" (car args
))
1960 ;; repair bad splits
1961 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
1964 (push (pop args
) args2
))
1965 (setq args
(nreverse args2
))
1967 (while (string-match "\\$\\([0-9]+\\)" val s
)
1968 (setq s
(1+ (match-beginning 0))
1969 n
(string-to-number (match-string 1 val
)))
1970 (and (>= (length args
) n
)
1971 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
1972 (when (string-match "\\`(eval\\>" val
)
1973 (setq val
(eval (read val
))))
1974 (if (and val
(not (stringp val
)))
1975 (setq val
(format "%s" val
))))
1977 (prog1 (replace-match val t t
)
1978 (goto-char (match-beginning 0)))))))))
1980 (defun org-export-apply-macros-in-string (s)
1981 "Apply the macros in string S."
1985 (org-export-preprocess-apply-macros)
1990 (defun org-export-handle-include-files ()
1991 "Include the contents of include files, with proper formatting."
1992 (let ((case-fold-search t
)
1993 params file markup lang start end prefix prefix1 switches
)
1994 (goto-char (point-min))
1995 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1996 (setq params
(read (concat "(" (match-string 1) ")"))
1997 prefix
(org-get-and-remove-property 'params
:prefix
)
1998 prefix1
(org-get-and-remove-property 'params
:prefix1
)
1999 file
(org-symname-or-string (pop params
))
2000 markup
(org-symname-or-string (pop params
))
2001 lang
(and (member markup
'("src" "SRC"))
2002 (org-symname-or-string (pop params
)))
2003 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" ")
2005 (delete-region (match-beginning 0) (match-end 0))
2007 (not (file-exists-p file
))
2008 (not (file-readable-p file
)))
2009 (insert (format "CANNOT INCLUDE FILE %s" file
))
2011 (if (equal (downcase markup
) "src")
2012 (setq start
(format "#+begin_src %s %s\n"
2013 (or lang
"fundamental")
2016 (setq start
(format "#+begin_%s %s\n" markup switches
)
2017 end
(format "#+end_%s" markup
))))
2018 (insert (or start
""))
2019 (insert (org-get-file-contents (expand-file-name file
)
2020 prefix prefix1 markup
))
2021 (or (bolp) (newline))
2022 (insert (or end
""))))))
2024 (defun org-get-file-contents (file &optional prefix prefix1 markup
)
2025 "Get the contents of FILE and return them as a string.
2026 If PREFIX is a string, prepend it to each line. If PREFIX1
2027 is a string, prepend it to the first line instead of PREFIX.
2028 If MARKUP, don't protect org-like lines, the exporter will
2029 take care of the block they are in."
2030 (if (stringp markup
) (setq markup
(downcase markup
)))
2032 (insert-file-contents file
)
2033 (when (or prefix prefix1
)
2034 (goto-char (point-min))
2036 (insert (or prefix1 prefix
))
2038 (beginning-of-line 2)))
2040 (when (member markup
'("src" "example"))
2041 (goto-char (point-min))
2042 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2043 (goto-char (match-beginning 0))
2048 (defun org-get-and-remove-property (listvar prop
)
2049 "Check if the value of LISTVAR contains PROP as a property.
2050 If yes, return the value of that property (i.e. the element following
2051 in the list) and remove property and value from the list in LISTVAR."
2052 (let ((list (symbol-value listvar
)) m v
)
2053 (when (setq m
(member prop list
))
2055 (if (equal (car list
) prop
)
2056 (set listvar
(cddr list
))
2057 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2059 (set listvar list
)))
2062 (defun org-symname-or-string (s)
2064 (if s
(symbol-name s
) s
)
2067 ;;; Fontification and line numbers for code examples
2069 (defvar org-export-last-code-line-counter-value
0)
2071 (defun org-export-replace-src-segments-and-examples (backend)
2072 "Replace source code segments with special code for export."
2073 (setq org-export-last-code-line-counter-value
0)
2074 (let ((case-fold-search t
)
2075 lang code trans opts indent caption
)
2076 (goto-char (point-min))
2077 (while (re-search-forward
2078 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2082 (setq lang
(match-string 3)
2083 opts
(match-string 4)
2084 code
(match-string 5)
2085 indent
(length (match-string 2))
2086 caption
(get-text-property 0 'org-caption
(match-string 0)))
2088 opts
(match-string 8)
2089 code
(match-string 9)
2090 indent
(length (match-string 7))
2091 caption
(get-text-property 0 'org-caption
(match-string 0))))
2093 (setq trans
(org-export-format-source-code-or-example
2094 backend lang code opts indent caption
))
2095 (replace-match trans t t
))))
2097 (defvar htmlp
) ;; dynamically scoped
2098 (defvar latexp
) ;; dynamically scoped
2099 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2100 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2101 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2103 (defun org-export-format-source-code-or-example
2104 (backend lang code
&optional opts indent caption
)
2105 "Format CODE from language LANG and return it formatted for export.
2106 If LANG is nil, do not add any fontification.
2107 OPTS contains formatting options, like `-n' for triggering numbering lines,
2108 and `+n' for continuing previous numbering.
2109 Code formatting according to language currently only works for HTML.
2110 Numbering lines works for all three major backends (html, latex, and ascii).
2111 INDENT was the original indentation of the block."
2113 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2114 (setq opts
(or opts
"")
2115 num
(string-match "[-+]n\\>" opts
)
2116 cont
(string-match "\\+n\\>" opts
)
2117 rpllbl
(string-match "-r\\>" opts
)
2118 keepp
(string-match "-k\\>" opts
)
2119 textareap
(string-match "-t\\>" opts
)
2120 preserve-indentp
(or org-src-preserve-indentation
2121 (string-match "-i\\>" opts
))
2122 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2123 (string-to-number (match-string 1 opts
))
2125 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2126 (string-to-number (match-string 1 opts
))
2127 (org-count-lines code
))
2128 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2129 (match-string 1 opts
)))
2130 (when (and textareap
(eq backend
'html
))
2131 ;; we cannot use numbering or highlighting.
2132 (setq num nil cont nil lang nil
))
2133 (if keepp
(setq rpllbl
'keep
))
2134 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2135 (when (string-match "^," rtn
)
2136 (setq rtn
(with-temp-buffer
2138 ;; Free up the protected lines
2139 (goto-char (point-min))
2140 (while (re-search-forward "^," nil t
)
2141 (if (or (equal lang
"org")
2143 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2147 ;; Now backend-specific coding
2150 ((eq backend
'docbook
)
2151 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2152 (concat "\n#+BEGIN_DOCBOOK\n"
2153 (org-add-props (concat "<programlisting><![CDATA["
2155 "]]></programlisting>\n")
2159 ;; We are exporting to HTML
2161 (require 'htmlize nil t
)
2162 (when (not (fboundp 'htmlize-region-for-paste
))
2163 ;; we do not have htmlize.el, or an old version of it
2166 "htmlize.el 1.34 or later is needed for source code formatting")))
2169 (let* ((lang-m (when lang
2170 (or (cdr (assoc lang org-src-lang-modes
))
2172 (mode (and lang-m
(intern
2174 (if (symbolp lang-m
)
2175 (symbol-name lang-m
)
2178 (org-inhibit-startup t
)
2179 (org-startup-folded nil
))
2183 (if (functionp mode
)
2186 (font-lock-fontify-buffer)
2188 (set-buffer-modified-p nil
)
2189 (org-export-htmlize-region-for-paste
2190 (point-min) (point-max))))
2191 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2196 "<div class=\"org-src-container\">"
2198 "<label class=\"org-src-name\">%s</label>"
2202 (format "<pre class=\"src src-%s\">\n" lang
)
2204 (if caption
"</div>" "")))))
2207 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2209 rtn
"</textarea>\n</p>\n"))
2212 (goto-char (point-min))
2213 (while (re-search-forward "[<>&]" nil t
)
2214 (replace-match (cdr (assq (char-before)
2215 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2217 (setq rtn
(buffer-string)))
2218 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2220 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2222 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2223 (setq rtn
(replace-match "\\1" t nil rtn
)))
2224 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2225 ((eq backend
'latex
)
2226 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2227 (concat "#+BEGIN_LaTeX\n"
2229 (if org-export-latex-listings
2233 ((lang-sym (intern lang
))
2238 org-export-latex-listings-langs
))
2240 (format "\\lstset{language=%s}\n" lstlang
))
2243 (format "\n%s $\\equiv$ \n" caption
))
2244 "\\begin{lstlisting}\n"
2245 rtn
"\\end{lstlisting}\n")
2246 (concat (car org-export-latex-verbatim-wrap
)
2247 rtn
(cdr org-export-latex-verbatim-wrap
)))
2250 ((eq backend
'ascii
)
2251 ;; This is not HTML or LaTeX, so just make it an example.
2252 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2253 (concat caption
"\n"
2258 (lambda (l) (concat " " l
))
2259 (org-split-string rtn
"\n")
2264 (org-add-props rtn nil
'original-indentation indent
))))
2266 (defun org-export-number-lines (text backend
2267 &optional skip1 skip2 number cont
2268 replace-labels label-format
)
2269 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2270 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2273 (goto-char (point-max))
2274 (skip-chars-backward " \t\n\r")
2275 (delete-region (point) (point-max))
2276 (beginning-of-line (- 1 skip2
))
2277 (let* ((last (org-current-line))
2278 (n org-export-last-code-line-counter-value
)
2279 (nmax (+ n
(- last skip1
)))
2280 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2283 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2285 ((eq backend
'ascii
) fmt
)
2286 ((eq backend
'latex
) fmt
)
2287 ((eq backend
'docbook
) fmt
)
2289 (label-format (or label-format org-coderef-label-format
))
2290 (label-pre (if (string-match "%s" label-format
)
2291 (substring label-format
0 (match-beginning 0))
2293 (label-post (if (string-match "%s" label-format
)
2294 (substring label-format
(match-end 0))
2298 ".*?\\S-.*?\\([ \t]*\\("
2299 (regexp-quote label-pre
)
2300 "\\([-a-zA-Z0-9_ ]+\\)"
2301 (regexp-quote label-post
)
2305 (org-goto-line (1+ skip1
))
2306 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2308 (insert (format fm
(incf n
)))
2310 (when (looking-at lbl-re
)
2311 (setq ref
(match-string 3))
2312 (cond ((numberp replace-labels
)
2313 ;; remove labels; use numbers for references when lines
2314 ;; are numbered, use labels otherwise
2315 (delete-region (match-beginning 1) (match-end 1))
2316 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2317 ((eq replace-labels
'keep
)
2318 ;; don't remove labels; use numbers for references when
2319 ;; lines are numbered, use labels otherwise
2320 (goto-char (match-beginning 2))
2321 (delete-region (match-beginning 2) (match-end 2))
2322 (insert "(" ref
")")
2323 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2324 org-export-code-refs
))
2326 ;; don't remove labels and don't use numbers for
2328 (goto-char (match-beginning 2))
2329 (delete-region (match-beginning 2) (match-end 2))
2330 (insert "(" ref
")")
2331 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2332 (when (eq backend
'html
)
2334 (beginning-of-line 1)
2335 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2338 (insert "</span>")))))
2339 (setq org-export-last-code-line-counter-value n
)
2340 (goto-char (point-max))
2344 (defun org-search-todo-below (line lines level
)
2345 "Search the subtree below LINE for any TODO entries."
2346 (let ((rest (cdr (memq line lines
)))
2347 (re org-todo-line-regexp
)
2350 (while (setq line
(pop rest
))
2351 (if (string-match re line
)
2353 (setq lv
(- (match-end 1) (match-beginning 1))
2354 todo
(and (match-beginning 2)
2355 (not (member (match-string 2 line
)
2356 org-done-keywords
))))
2358 (if (<= lv level
) (throw 'exit nil
))
2359 (if todo
(throw 'exit t
))))))))
2362 (defun org-export-visible (type arg
)
2363 "Create a copy of the visible part of the current buffer, and export it.
2364 The copy is created in a temporary buffer and removed after use.
2365 TYPE is the final key (as a string) that also select the export command in
2366 the `C-c C-e' export dispatcher.
2367 As a special case, if the you type SPC at the prompt, the temporary
2368 org-mode file will not be removed but presented to you so that you can
2369 continue to use it. The prefix arg ARG is passed through to the exporting
2373 (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")
2374 (read-char-exclusive))
2375 current-prefix-arg
))
2376 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L
)))
2377 (error "Invalid export key"))
2378 (let* ((binding (cdr (assoc type
2380 (?a . org-export-as-ascii
)
2381 (?A . org-export-as-ascii-to-buffer
)
2382 (?n . org-export-as-latin1
)
2383 (?N . org-export-as-latin1-to-buffer
)
2384 (?u . org-export-as-utf8
)
2385 (?U . org-export-as-utf8-to-buffer
)
2386 (?\C-a . org-export-as-ascii
)
2387 (?b . org-export-as-html-and-open
)
2388 (?\C-b . org-export-as-html-and-open
)
2389 (?h . org-export-as-html
)
2390 (?H . org-export-as-html-to-buffer
)
2391 (?R . org-export-region-as-html
)
2392 (?D . org-export-as-docbook
)
2394 (?l . org-export-as-latex
)
2395 (?p . org-export-as-pdf
)
2396 (?d . org-export-as-pdf-and-open
)
2397 (?L . org-export-as-latex-to-buffer
)
2399 (?x . org-export-as-xoxo
)))))
2400 (keepp (equal type ?\
))
2401 (file buffer-file-name
)
2402 (buffer (get-buffer-create "*Org Export Visible*"))
2404 ;; Need to hack the drawers here.
2406 (goto-char (point-min))
2407 (while (re-search-forward org-drawer-regexp nil t
)
2408 (goto-char (match-beginning 1))
2409 (or (org-invisible-p) (org-flag-drawer nil
))))
2410 (with-current-buffer buffer
(erase-buffer))
2412 (setq s
(goto-char (point-min)))
2413 (while (not (= (point) (point-max)))
2414 (goto-char (org-find-invisible))
2415 (append-to-buffer buffer s
(point))
2416 (setq s
(goto-char (org-find-visible))))
2417 (org-cycle-hide-drawers 'all
)
2418 (goto-char (point-min))
2420 ;; Copy all comment lines to the end, to make sure #+ settings are
2421 ;; still available for the second export step. Kind of a hack, but
2422 ;; does do the trick.
2423 (if (looking-at "#[^\r\n]*")
2424 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2425 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2426 (append-to-buffer buffer
(1+ (match-beginning 0))
2427 (min (point-max) (1+ (match-end 0))))))
2429 (let ((buffer-file-name file
)
2430 (org-inhibit-startup t
))
2433 (unless keepp
(funcall binding arg
))))
2435 (kill-buffer buffer
)
2436 (switch-to-buffer-other-window buffer
)
2437 (goto-char (point-min)))))
2439 (defun org-find-visible ()
2441 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2442 (get-char-property s
'invisible
)))
2444 (defun org-find-invisible ()
2446 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2447 (not (get-char-property s
'invisible
))))
2450 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2453 (defun org-export-as-org (arg &optional hidden ext-plist
2454 to-buffer body-only pub-dir
)
2455 "Make a copy with not-exporting stuff removed.
2456 The purpose of this function is to provide a way to export the source
2457 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2458 stuff removed. This command will remove the following:
2460 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2461 - comment blocks and trees starting with the COMMENT keyword
2462 - only trees that are consistent with `org-export-select-tags'
2463 and `org-export-exclude-tags'.
2465 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2466 all the others will be ignored (but are present so that the general
2467 mechanism to call publishing functions will work).
2469 EXT-PLIST is a property list with external parameters overriding
2470 org-mode's default settings, but still inferior to file-local
2471 settings. When PUB-DIR is set, use this as the publishing
2474 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2476 (org-infile-export-plist)))
2477 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2478 (filename (concat (file-name-as-directory
2480 (org-export-directory :org opt-plist
)))
2481 (file-name-sans-extension
2482 (file-name-nondirectory bfname
))
2484 (filename (and filename
2485 (if (equal (file-truename filename
)
2486 (file-truename bfname
))
2487 (concat (file-name-sans-extension filename
)
2489 (file-name-extension filename
))
2491 (backup-inhibited t
)
2492 (buffer (find-file-noselect filename
))
2493 (region (buffer-string))
2496 (switch-to-buffer buffer
)
2499 (let ((org-inhibit-startup t
)) (org-mode))
2500 (org-install-letbind)
2502 ;; Get rid of archived trees
2503 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2505 ;; Remove comment environment and comment subtrees
2506 (org-export-remove-comment-blocks-and-subtrees)
2508 ;; Get rid of excluded trees
2509 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2510 (plist-get opt-plist
:exclude-tags
))
2512 (when (or (plist-get opt-plist
:plain-source
)
2513 (not (or (plist-get opt-plist
:plain-source
)
2514 (plist-get opt-plist
:htmlized-source
))))
2515 ;; Either nothing special is requested (default call)
2516 ;; or the plain source is explicitly requested
2519 (when (plist-get opt-plist
:htmlized-source
)
2520 ;; Make the htmlized version
2523 (font-lock-fontify-buffer)
2524 (let* ((htmlize-output-type 'css
)
2525 (newbuf (htmlize-buffer)))
2526 (with-current-buffer newbuf
2527 (when org-export-htmlized-org-css-url
2528 (goto-char (point-min))
2529 (and (re-search-forward
2530 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2534 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2535 org-export-htmlized-org-css-url
)
2537 (write-file (concat filename
".html")))
2538 (kill-buffer newbuf
)))
2539 (set-buffer-modified-p nil
)
2540 (if (equal to-buffer
'string
)
2541 (progn (setq str-ret
(buffer-string))
2542 (kill-buffer (current-buffer))
2544 (kill-buffer (current-buffer))))))
2546 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2547 (defun org-get-current-options ()
2548 "Return a string with current options as keyword options.
2549 Does include HTML export options as well as TODO and CATEGORY stuff."
2550 (require 'org-archive
)
2559 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2560 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2562 #+EXPORT_SELECT_TAGS: %s
2563 #+EXPORT_EXCLUDE_TAGS: %s
2569 #+PRIORITIES: %c %c %c
2571 #+STARTUP: %s %s %s %s %s
2577 (buffer-name) (user-full-name) user-mail-address
2578 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2579 org-export-default-language
2580 org-export-headline-levels
2581 org-export-with-section-numbers
2583 org-export-preserve-breaks
2584 org-export-html-expand
2585 org-export-with-fixed-width
2586 org-export-with-tables
2587 org-export-with-sub-superscripts
2588 org-export-with-special-strings
2589 org-export-with-footnotes
2590 org-export-with-emphasize
2591 org-export-with-timestamps
2592 org-export-with-TeX-macros
2593 org-export-with-LaTeX-fragments
2594 org-export-skip-text-before-1st-heading
2595 org-export-with-drawers
2596 org-export-with-todo-keywords
2597 org-export-with-priority
2598 org-export-with-tags
2599 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2600 (mapconcat 'identity org-export-select-tags
" ")
2601 (mapconcat 'identity org-export-exclude-tags
" ")
2602 org-export-html-link-up
2603 org-export-html-link-home
2605 (file-name-sans-extension
2606 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2608 "TODO FEEDBACK VERIFY DONE"
2609 "Me Jason Marie DONE"
2610 org-highest-priority org-lowest-priority org-default-priority
2611 (mapconcat 'identity org-drawers
" ")
2612 (cdr (assoc org-startup-folded
2613 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2614 (if org-odd-levels-only
"odd" "oddeven")
2615 (if org-hide-leading-stars
"hidestars" "showstars")
2616 (if org-startup-align-all-tables
"align" "noalign")
2617 (cond ((eq org-log-done t
) "logdone")
2618 ((equal org-log-done
'note
) "lognotedone")
2619 ((not org-log-done
) "nologdone"))
2620 (or (mapconcat (lambda (x)
2622 ((equal :startgroup
(car x
)) "{")
2623 ((equal :endgroup
(car x
)) "}")
2624 ((equal :newline
(car x
)) "")
2625 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2627 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2628 (mapconcat 'identity org-file-tags
" ")
2629 org-archive-location
2630 "org file:~/org/%s.org"
2634 (defun org-insert-export-options-template ()
2635 "Insert into the buffer a template with information for exporting."
2637 (if (not (bolp)) (newline))
2638 (let ((s (org-get-current-options)))
2639 (and (string-match "#\\+CATEGORY" s
)
2640 (setq s
(substring s
0 (match-beginning 0))))
2643 (defvar org-table-colgroup-info nil
)
2645 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2646 "Check if the table has a marking column.
2647 If yes remove the column and the special lines."
2648 (setq org-table-colgroup-info nil
)
2651 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2654 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2655 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2659 (setq org-table-clean-did-remove-column nil
)
2664 ((string-match "^[ \t]*| */ *|" x
)
2665 (setq org-table-colgroup-info
2667 (cond ((member x
'("<" "<")) :start
)
2668 ((member x
'(">" ">")) :end
)
2669 ((member x
'("<>" "<>")) :startend
)
2671 (org-split-string x
"[ \t]*|[ \t]*")))
2675 (setq org-table-clean-did-remove-column t
)
2680 ((string-match "^[ \t]*| */ *|" x
)
2681 (setq org-table-colgroup-info
2683 (cond ((member x
'("<" "<")) :start
)
2684 ((member x
'(">" ">")) :end
)
2685 ((member x
'("<>" "<>")) :startend
)
2687 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2689 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2690 nil
) ; ignore this line
2691 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2692 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2693 ;; remove the first column
2694 (replace-match "\\1|" t nil x
))))
2697 (defun org-export-cleanup-toc-line (s)
2698 "Remove tags and timestamps from lines going into the toc."
2699 (when (memq org-export-with-tags
'(not-in-toc nil
))
2700 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2701 (setq s
(replace-match "" t t s
))))
2702 (when org-export-remove-timestamps-from-toc
2703 (while (string-match org-maybe-keyword-time-regexp s
)
2704 (setq s
(replace-match "" t t s
))))
2705 (while (string-match org-bracket-link-regexp s
)
2706 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2708 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
2709 (setq s
(replace-match "" t t s
)))
2712 (defun org-create-multibrace-regexp (left right n
)
2713 "Create a regular expression which will match a balanced sexp.
2714 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2715 as single character strings.
2716 The regexp returned will match the entire expression including the
2717 delimiters. It will also define a single group which contains the
2718 match except for the outermost delimiters. The maximum depth of
2719 stacked delimiters is N. Escaping delimiters is not possible."
2720 (let* ((nothing (concat "[^" left right
"]*?"))
2723 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
2726 re
(concat re or next
)
2727 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
2728 (concat left
"\\(" re
"\\)" right
)))
2730 (defvar org-match-substring-regexp
2732 "\\([^\\]\\)\\([_^]\\)\\("
2733 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2735 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
2737 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2738 "The regular expression matching a sub- or superscript.")
2740 (defvar org-match-substring-with-braces-regexp
2742 "\\([^\\]\\)\\([_^]\\)\\("
2743 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2745 "The regular expression matching a sub- or superscript, forcing braces.")
2748 (defun org-get-text-property-any (pos prop
&optional object
)
2749 (or (get-text-property pos prop object
)
2750 (and (setq pos
(next-single-property-change pos prop object
))
2751 (get-text-property pos prop object
))))
2753 (defun org-export-get-coderef-format (path desc
)
2755 (if (and desc
(string-match
2756 (regexp-quote (concat "(" path
")"))
2758 (replace-match "%s" t t desc
)
2761 (defun org-export-push-to-kill-ring (format)
2762 "Push buffer content to kill ring.
2763 The depends on the variable `org-export-copy-to-kill'."
2764 (when org-export-copy-to-kill-ring
2765 (org-kill-new (buffer-string))
2766 (when (fboundp 'x-set-selection
)
2767 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
2768 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
2769 (message "%s export done, pushed to kill ring and clipboard" format
)))
2773 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2775 ;;; org-exp.el ends here