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 (declare-function org-table-cookie-line-p
"org-table" (line))
46 (declare-function org-table-colgroup-line-p
"org-table" (line))
47 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
48 (defgroup org-export nil
49 "Options for exporting org-listings."
53 (defgroup org-export-general nil
54 "General options for exporting Org-mode files."
55 :tag
"Org Export General"
58 (defcustom org-export-allow-BIND
'confirm
59 "Non-nil means allow #+BIND to define local variable values for export.
60 This is a potential security risk, which is why the user must confirm the
62 :group
'org-export-general
64 (const :tag
"Never" nil
)
65 (const :tag
"Always" t
)
66 (const :tag
"Make the user confirm for each file" confirm
)))
69 (defvar org-export-publishing-directory nil
)
71 (defcustom org-export-show-temporary-export-buffer t
72 "Non-nil means show buffer after exporting to temp buffer.
73 When Org exports to a file, the buffer visiting that file is ever
74 shown, but remains buried. However, when exporting to a temporary
75 buffer, that buffer is popped up in a second window. When this variable
76 is nil, the buffer remains buried also in these cases."
77 :group
'org-export-general
80 (defcustom org-export-copy-to-kill-ring t
81 "Non-nil means exported stuff will also be pushed onto the kill ring."
82 :group
'org-export-general
85 (defcustom org-export-kill-product-buffer-when-displayed nil
86 "Non-nil means kill the product buffer if it is displayed immediately.
87 This applied to the commands `org-export-html-and-open' and
88 `org-export-as-pdf-and-open'."
89 :group
'org-export-general
92 (defcustom org-export-run-in-background nil
93 "Non-nil means export and publishing commands will run in background.
94 This works by starting up a separate Emacs process visiting the same file
95 and doing the export from there.
96 Not all export commands are affected by this - only the ones which
97 actually write to a file, and that do not depend on the buffer state.
99 If this option is nil, you can still get background export by calling
100 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
102 If this option is t, the double prefix can be used to exceptionally
103 force an export command into the current process."
104 :group
'org-export-general
107 (defcustom org-export-select-tags
'("export")
108 "Tags that select a tree for export.
109 If any such tag is found in a buffer, all trees that do not carry one
110 of these tags will be deleted before export.
111 Inside trees that are selected like this, you can still deselect a
112 subtree by tagging it with one of the `org-export-exclude-tags'."
113 :group
'org-export-general
114 :type
'(repeat (string :tag
"Tag")))
116 (defcustom org-export-exclude-tags
'("noexport")
117 "Tags that exclude a tree from export.
118 All trees carrying any of these tags will be excluded from export.
119 This is without condition, so even subtrees inside that carry one of the
120 `org-export-select-tags' will be removed."
121 :group
'org-export-general
122 :type
'(repeat (string :tag
"Tag")))
124 ;; FIXME: rename, this is a general variable
125 (defcustom org-export-html-expand t
126 "Non-nil means for HTML export, treat @<...> as HTML tag.
127 When nil, these tags will be exported as plain text and therefore
128 not be interpreted by a browser.
130 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
131 :group
'org-export-html
132 :group
'org-export-general
135 (defcustom org-export-with-special-strings t
136 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
137 When this option is turned on, these strings will be exported as:
140 -----+----------+--------
146 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
147 :group
'org-export-translation
150 (defcustom org-export-html-link-up
""
151 "Where should the \"UP\" link of exported HTML pages lead?"
152 :group
'org-export-html
153 :group
'org-export-general
154 :type
'(string :tag
"File or URL"))
156 (defcustom org-export-html-link-home
""
157 "Where should the \"HOME\" link of exported HTML pages lead?"
158 :group
'org-export-html
159 :group
'org-export-general
160 :type
'(string :tag
"File or URL"))
162 (defcustom org-export-language-setup
163 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
164 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
165 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
166 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
167 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
168 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
169 ("es" "Autor" "Fecha" "Índice" "Pies de página")
170 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
171 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
172 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
173 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
174 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
175 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
176 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
177 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
178 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
179 ("pl" "Autor" "Data" "Spis treści" "Przypis")
180 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
181 "Terms used in export text, translated to different languages.
182 Use the variable `org-export-default-language' to set the language,
183 or use the +OPTION lines for a per-file setting."
184 :group
'org-export-general
187 (string :tag
"HTML language tag")
188 (string :tag
"Author")
190 (string :tag
"Table of Contents")
191 (string :tag
"Footnotes"))))
193 (defcustom org-export-default-language
"en"
194 "The default language of HTML export, as a string.
195 This should have an association in `org-export-language-setup'."
196 :group
'org-export-general
199 (defvar org-export-page-description
""
200 "The page description, for the XHTML meta tag.
201 This is best set with the #+DESCRIPTION line in a file, it does not make
202 sense to set this globally.")
204 (defvar org-export-page-keywords
""
205 "The page description, for the XHTML meta tag.
206 This is best set with the #+KEYWORDS line in a file, it does not make
207 sense to set this globally.")
209 (defcustom org-export-skip-text-before-1st-heading nil
210 "Non-nil means skip all text before the first headline when exporting.
211 When nil, that text is exported as well."
212 :group
'org-export-general
215 (defcustom org-export-headline-levels
3
216 "The last level which is still exported as a headline.
217 Inferior levels will produce itemize lists when exported.
218 Note that a numeric prefix argument to an exporter function overrides
221 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
222 :group
'org-export-general
225 (defcustom org-export-with-section-numbers t
226 "Non-nil means add section numbers to headlines when exporting.
228 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
229 :group
'org-export-general
232 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
233 "Format of section numbers for export.
234 The variable has two components.
235 1. A list of lists, each indicating a counter type and a separator.
236 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
237 It causes causes numeric, alphabetic, or roman counters, respectively.
238 The separator is only used if another counter for a subsection is being
240 If there are more numbered section levels than entries in this lists,
241 then the last entry will be reused.
242 2. A terminator string that will be added after the entire
244 :group
'org-export-general
248 (string :tag
"Counter Type")
249 (string :tag
"Separator ")))
250 (string :tag
"Terminator")))
252 (defcustom org-export-with-toc t
253 "Non-nil means create a table of contents in exported files.
254 The TOC contains headlines with levels up to`org-export-headline-levels'.
255 When an integer, include levels up to N in the toc, this may then be
256 different from `org-export-headline-levels', but it will not be allowed
257 to be larger than the number of headline levels.
258 When nil, no table of contents is made.
260 Headlines which contain any TODO items will be marked with \"(*)\" in
261 ASCII export, and with red color in HTML output, if the option
262 `org-export-mark-todo-in-toc' is set.
264 In HTML output, the TOC will be clickable.
266 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
268 :group
'org-export-general
270 (const :tag
"No Table of Contents" nil
)
271 (const :tag
"Full Table of Contents" t
)
272 (integer :tag
"TOC to level")))
274 (defcustom org-export-mark-todo-in-toc nil
275 "Non-nil means mark TOC lines that contain any open TODO items."
276 :group
'org-export-general
279 (defcustom org-export-with-todo-keywords t
280 "Non-nil means include TODO keywords in export.
281 When nil, remove all these keywords from the export."
282 :group
'org-export-general
285 (defcustom org-export-with-priority nil
286 "Non-nil means include priority cookies in export.
287 When nil, remove priority cookies for export."
288 :group
'org-export-general
291 (defcustom org-export-preserve-breaks nil
292 "Non-nil means preserve all line breaks when exporting.
293 Normally, in HTML output paragraphs will be reformatted. In ASCII
294 export, line breaks will always be preserved, regardless of this variable.
296 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
297 :group
'org-export-general
300 (defcustom org-export-with-archived-trees
'headline
301 "Whether subtrees with the ARCHIVE tag should be exported.
302 This can have three different values
303 nil Do not export, pretend this tree is not present
304 t Do export the entire tree
305 headline Only export the headline, but skip the tree below it."
306 :group
'org-export-general
309 (const :tag
"not at all" nil
)
310 (const :tag
"headline only" 'headline
)
311 (const :tag
"entirely" t
)))
313 (defcustom org-export-author-info t
314 "Non-nil means insert author name and email into the exported file.
316 This option can also be set with the +OPTIONS line,
317 e.g. \"author:nil\"."
318 :group
'org-export-general
321 (defcustom org-export-email-info nil
322 "Non-nil means insert author name and email into the exported file.
324 This option can also be set with the +OPTIONS line,
326 :group
'org-export-general
329 (defcustom org-export-creator-info t
330 "Non-nil means the postamble should contain a creator sentence.
331 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
332 :group
'org-export-general
335 (defcustom org-export-time-stamp-file t
336 "Non-nil means insert a time stamp into the exported file.
337 The time stamp shows when the file was created.
339 This option can also be set with the +OPTIONS line,
340 e.g. \"timestamp:nil\"."
341 :group
'org-export-general
344 (defcustom org-export-with-timestamps t
345 "If nil, do not export time stamps and associated keywords."
346 :group
'org-export-general
349 (defcustom org-export-remove-timestamps-from-toc t
350 "If t, remove timestamps from the table of contents entries."
351 :group
'org-export-general
354 (defcustom org-export-with-tags
'not-in-toc
355 "If nil, do not export tags, just remove them from headlines.
356 If this is the symbol `not-in-toc', tags will be removed from table of
357 contents entries, but still be shown in the headlines of the document.
359 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
360 :group
'org-export-general
362 (const :tag
"Off" nil
)
363 (const :tag
"Not in TOC" not-in-toc
)
364 (const :tag
"On" t
)))
366 (defcustom org-export-with-drawers nil
367 "Non-nil means export with drawers like the property drawer.
368 When t, all drawers are exported. This may also be a list of
369 drawer names to export."
370 :group
'org-export-general
372 (const :tag
"All drawers" t
)
373 (const :tag
"None" nil
)
374 (repeat :tag
"Selected drawers"
375 (string :tag
"Drawer name"))))
377 (defvar org-export-first-hook nil
378 "Hook called as the first thing in each exporter.
379 Point will be still in the original buffer.
380 Good for general initialization")
382 (defvar org-export-preprocess-hook nil
383 "Hook for preprocessing an export buffer.
384 Pretty much the first thing when exporting is running this hook.
385 Point will be in a temporary buffer that contains a copy of
386 the original buffer, or of the section that is being export.
387 All the other hooks in the org-export-preprocess... category
388 also work in that temporary buffer, already modified by various
389 stages of the processing.")
391 (defvar org-export-preprocess-after-include-files-hook nil
392 "Hook for preprocessing an export buffer.
393 This is run after the contents of included files have been inserted.")
395 (defvar org-export-preprocess-after-tree-selection-hook nil
396 "Hook for preprocessing an export buffer.
397 This is run after selection of trees to be exported has happened.
398 This selection includes tags-based selection, as well as removal
399 of commented and archived trees.")
401 (defvar org-export-preprocess-after-headline-targets-hook nil
402 "Hook for preprocessing export buffer.
403 This is run just after the headline targets have been defined and
404 the target-alist has been set up.")
406 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
407 "Hook for preprocessing an export buffer.
408 This is run just before backend-specific blocks get selected.")
410 (defvar org-export-preprocess-after-blockquote-hook nil
411 "Hook for preprocessing an export buffer.
412 This is run after blockquote/quote/verse/center have been marked
415 (defvar org-export-preprocess-before-normalizing-links-hook nil
416 "Hook for preprocessing an export buffer.
417 This hook is run before links are normalized.")
419 (defvar org-export-preprocess-before-backend-specifics-hook nil
420 "Hook run before backend-specific functions are called during preprocessing.")
422 (defvar org-export-preprocess-final-hook nil
423 "Hook for preprocessing an export buffer.
424 This is run as the last thing in the preprocessing buffer, just before
425 returning the buffer string to the backend.")
427 (defgroup org-export-translation nil
428 "Options for translating special ascii sequences for the export backends."
429 :tag
"Org Export Translation"
432 (defcustom org-export-with-emphasize t
433 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
434 If the export target supports emphasizing text, the word will be
435 typeset in bold, italic, or underlined, respectively. Works only for
436 single words, but you can say: I *really* *mean* *this*.
437 Not all export backends support this.
439 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
440 :group
'org-export-translation
443 (defcustom org-export-with-footnotes t
444 "If nil, export [1] as a footnote marker.
445 Lines starting with [1] will be formatted as footnotes.
447 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
448 :group
'org-export-translation
451 (defcustom org-export-with-sub-superscripts t
452 "Non-nil means interpret \"_\" and \"^\" for export.
453 When this option is turned on, you can use TeX-like syntax for sub- and
454 superscripts. Several characters after \"_\" or \"^\" will be
455 considered as a single item - so grouping with {} is normally not
456 needed. For example, the following things will be parsed as single
457 sub- or superscripts.
459 10^24 or 10^tau several digits will be considered 1 item.
460 10^-12 or 10^-tau a leading sign with digits or a word
461 x^2-y^3 will be read as x^2 - y^3, because items are
462 terminated by almost any nonword/nondigit char.
463 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
465 Still, ambiguity is possible - so when in doubt use {} to enclose the
466 sub/superscript. If you set this variable to the symbol `{}',
467 the braces are *required* in order to trigger interpretations as
468 sub/superscript. This can be helpful in documents that need \"_\"
469 frequently in plain text.
471 Not all export backends support this, but HTML does.
473 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
474 :group
'org-export-translation
476 (const :tag
"Always interpret" t
)
477 (const :tag
"Only with braces" {})
478 (const :tag
"Never interpret" nil
)))
480 (defcustom org-export-with-TeX-macros t
481 "Non-nil means interpret simple TeX-like macros when exporting.
482 For example, HTML export converts \\alpha to α and \\AA to Å.
483 Not only real TeX macros will work here, but the standard HTML entities
484 for math can be used as macro names as well. For a list of supported
485 names in HTML export, see the constant `org-entities' and the user option
487 Not all export backends support this.
489 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
490 :group
'org-export-translation
491 :group
'org-export-latex
494 (defcustom org-export-with-LaTeX-fragments nil
495 "Non-nil means convert LaTeX fragments to images when exporting to HTML.
496 When set, the exporter will find LaTeX environments if the \\begin line is
497 the first non-white thing on a line. It will also find the math delimiters
498 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
501 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
503 The default is nil, because this option needs the `dvipng' program which
504 is not available on all systems."
505 :group
'org-export-translation
506 :group
'org-export-latex
509 (defcustom org-export-with-fixed-width t
510 "Non-nil means lines starting with \":\" will be in fixed width font.
511 This can be used to have pre-formatted text, fragments of code etc. For
513 : ;; Some Lisp examples
516 will be looking just like this in also HTML. See also the QUOTE keyword.
517 Not all export backends support this.
519 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
520 :group
'org-export-translation
523 (defcustom org-match-sexp-depth
3
524 "Number of stacked braces for sub/superscript matching.
525 This has to be set before loading org.el to be effective."
526 :group
'org-export-translation
529 (defgroup org-export-tables nil
530 "Options for exporting tables in Org-mode."
531 :tag
"Org Export Tables"
534 (defcustom org-export-with-tables t
535 "If non-nil, lines starting with \"|\" define a table.
538 | Name | Address | Birthday |
539 |-------------+----------+-----------|
540 | Arthur Dent | England | 29.2.2100 |
542 Not all export backends support this.
544 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
545 :group
'org-export-tables
548 (defcustom org-export-highlight-first-table-line t
549 "Non-nil means highlight the first table line.
550 In HTML export, this means use <th> instead of <td>.
551 In tables created with table.el, this applies to the first table line.
552 In Org-mode tables, all lines before the first horizontal separator
553 line will be formatted with <th> tags."
554 :group
'org-export-tables
557 (defcustom org-export-table-remove-special-lines t
558 "Remove special lines and marking characters in calculating tables.
559 This removes the special marking character column from tables that are set
560 up for spreadsheet calculations. It also removes the entire lines
561 marked with `!', `_', or `^'. The lines with `$' are kept, because
562 the values of constants may be useful to have."
563 :group
'org-export-tables
566 (defcustom org-export-prefer-native-exporter-for-tables nil
567 "Non-nil means always export tables created with table.el natively.
568 Natively means use the HTML code generator in table.el.
569 When nil, Org-mode's own HTML generator is used when possible (i.e. if
570 the table does not use row- or column-spanning). This has the
571 advantage, that the automatic HTML conversions for math symbols and
572 sub/superscripts can be applied. Org-mode's HTML generator is also
573 much faster. The LaTeX exporter always use the native exporter for
575 :group
'org-export-tables
579 (defgroup org-export-xml nil
580 "Options specific for XML export of Org-mode files."
581 :tag
"Org Export XML"
586 ;;; Variables, constants, and parameter plists
588 (defconst org-level-max
20)
590 (defvar org-current-export-file nil
) ; dynamically scoped parameter
591 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
592 (defvar org-export-opt-plist nil
593 "Contains the current option plist.")
594 (defvar org-last-level nil
) ; dynamically scoped variable
595 (defvar org-min-level nil
) ; dynamically scoped variable
596 (defvar org-levels-open nil
) ; dynamically scoped parameter
598 (defconst org-export-plist-vars
599 '((:link-up nil org-export-html-link-up
)
600 (:link-home nil org-export-html-link-home
)
601 (:language nil org-export-default-language
)
602 (:keywords nil org-export-page-keywords
)
603 (:description nil org-export-page-description
)
604 (:customtime nil org-display-custom-times
)
605 (:headline-levels
"H" org-export-headline-levels
)
606 (:section-numbers
"num" org-export-with-section-numbers
)
607 (:section-number-format nil org-export-section-number-format
)
608 (:table-of-contents
"toc" org-export-with-toc
)
609 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
610 (:archived-trees nil org-export-with-archived-trees
)
611 (:emphasize
"*" org-export-with-emphasize
)
612 (:sub-superscript
"^" org-export-with-sub-superscripts
)
613 (:special-strings
"-" org-export-with-special-strings
)
614 (:footnotes
"f" org-export-with-footnotes
)
615 (:drawers
"d" org-export-with-drawers
)
616 (:tags
"tags" org-export-with-tags
)
617 (:todo-keywords
"todo" org-export-with-todo-keywords
)
618 (:priority
"pri" org-export-with-priority
)
619 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
620 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
621 (:latex-listings nil org-export-latex-listings
)
622 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
623 (:fixed-width
":" org-export-with-fixed-width
)
624 (:timestamps
"<" org-export-with-timestamps
)
625 (:author-info
"author" org-export-author-info
)
626 (:email-info
"email" org-export-email-info
)
627 (:creator-info
"creator" org-export-creator-info
)
628 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
629 (:tables
"|" org-export-with-tables
)
630 (:table-auto-headline nil org-export-highlight-first-table-line
)
631 (:style-include-default nil org-export-html-style-include-default
)
632 (:style-include-scripts nil org-export-html-style-include-scripts
)
633 (:style nil org-export-html-style
)
634 (:style-extra nil org-export-html-style-extra
)
635 (:agenda-style nil org-agenda-export-html-style
)
636 (:convert-org-links nil org-export-html-link-org-files-as-html
)
637 (:inline-images nil org-export-html-inline-images
)
638 (:html-extension nil org-export-html-extension
)
639 (:xml-declaration nil org-export-html-xml-declaration
)
640 (:html-table-tag nil org-export-html-table-tag
)
641 (:expand-quoted-html
"@" org-export-html-expand
)
642 (:timestamp nil org-export-html-with-timestamp
)
643 (:publishing-directory nil org-export-publishing-directory
)
644 (:preamble nil org-export-html-preamble
)
645 (:postamble nil org-export-html-postamble
)
646 (:auto-preamble nil org-export-html-auto-preamble
)
647 (:auto-postamble nil org-export-html-auto-postamble
)
648 (:author nil user-full-name
)
649 (:email nil user-mail-address
)
650 (:select-tags nil org-export-select-tags
)
651 (:exclude-tags nil org-export-exclude-tags
)
653 (:latex-image-options nil org-export-latex-image-default-option
))
654 "List of properties that represent export/publishing variables.
655 Each element is a list of 3 items:
656 1. The property that is used internally, and also for org-publish-project-alist
657 2. The string that can be used in the OPTION lines to set this option,
658 or nil if this option cannot be changed in this way
659 3. The customization variable that sets the default for this option."
662 (defun org-default-export-plist ()
663 "Return the property list with default settings for the export variables."
664 (let* ((infile (org-infile-export-plist))
665 (letbind (plist-get infile
:let-bind
))
666 (l org-export-plist-vars
) rtn e s v
)
667 (while (setq e
(pop l
))
670 ((assq s letbind
) (nth 1 (assq s letbind
)))
671 ((boundp s
) (symbol-value s
))
673 rtn
(cons (car e
) (cons v rtn
))))
676 (defvar org-export-inbuffer-options-extra nil
677 "List of additional in-buffer options that should be detected.
678 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
679 etc. Extensions can add to this list to get their options detected, and they
680 can then add a function to `org-export-options-filters' to process these
682 Each element in this list must be a list, with the in-buffer keyword as car,
683 and a property (a symbol) as the next element. All occurrences of the
684 keyword will be found, the values concatenated with a space character
685 in between, and the result stored in the export options property list.")
687 (defvar org-export-options-filters nil
688 "Functions to be called to finalize the export/publishing options.
689 All these options are stored in a property list, and each of the functions
690 in this hook gets a chance to modify this property list. Each function
691 must accept the property list as an argument, and must return the (possibly
694 ;; FIXME: should we fold case here?
695 (defun org-infile-export-plist ()
696 "Return the property list with file-local settings for export."
700 (goto-char (point-min))
701 (let ((re (org-make-options-regexp
703 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
704 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
705 "LATEX_HEADER" "LATEX_CLASS"
706 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
707 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND")
708 (mapcar 'car org-export-inbuffer-options-extra
))))
709 p key val text options a pr style
710 latex-header latex-class macros letbind
711 ext-setup-or-nil setup-contents
(start 0))
712 (while (or (and ext-setup-or-nil
713 (string-match re ext-setup-or-nil start
)
714 (setq start
(match-end 0)))
715 (and (setq ext-setup-or-nil nil start
0)
716 (re-search-forward re nil t
)))
717 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
718 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
720 ((setq a
(assoc key org-export-inbuffer-options-extra
))
722 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
723 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
724 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
725 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
726 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
727 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
728 ((string-equal key
"DESCRIPTION")
729 (setq p
(plist-put p
:description val
)))
730 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
731 ((string-equal key
"STYLE")
732 (setq style
(concat style
"\n" val
)))
733 ((string-equal key
"LATEX_HEADER")
734 (setq latex-header
(concat latex-header
"\n" val
)))
735 ((string-equal key
"LATEX_CLASS")
736 (setq latex-class val
))
737 ((string-equal key
"TEXT")
738 (setq text
(if text
(concat text
"\n" val
) val
)))
739 ((string-equal key
"OPTIONS")
740 (setq options
(concat val
" " options
)))
741 ((string-equal key
"BIND")
742 (push (read (concat "(" val
")")) letbind
))
743 ((string-equal key
"LINK_UP")
744 (setq p
(plist-put p
:link-up val
)))
745 ((string-equal key
"LINK_HOME")
746 (setq p
(plist-put p
:link-home val
)))
747 ((string-equal key
"EXPORT_SELECT_TAGS")
748 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
749 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
750 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
751 ((string-equal key
"MACRO")
753 ((equal key
"SETUPFILE")
754 (setq setup-contents
(org-file-contents
756 (org-remove-double-quotes
759 (if (not ext-setup-or-nil
)
760 (setq ext-setup-or-nil setup-contents start
0)
761 (setq ext-setup-or-nil
762 (concat (substring ext-setup-or-nil
0 start
)
763 "\n" setup-contents
"\n"
764 (substring ext-setup-or-nil start
)))))))
765 (setq p
(plist-put p
:text text
))
766 (when (and letbind
(org-export-confirm-letbind))
767 (setq p
(plist-put p
:let-bind letbind
)))
768 (when style
(setq p
(plist-put p
:style-extra style
)))
770 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
772 (setq p
(plist-put p
:latex-class latex-class
)))
774 (setq p
(org-export-add-options-to-plist p options
)))
775 ;; Add macro definitions
776 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
777 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
779 p
:macro-modification-time
780 (and (buffer-file-name)
781 (file-exists-p (buffer-file-name))
783 "(eval (format-time-string \"$1\" '"
784 (prin1-to-string (nth 5 (file-attributes
785 (buffer-file-name))))
787 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
788 (file-name-nondirectory
789 (buffer-file-name)))))
790 (while (setq val
(pop macros
))
791 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
794 (concat ":macro-" (downcase (match-string 1 val
))))
795 (org-export-interpolate-newlines (match-string 2 val
))))))
798 (defun org-export-interpolate-newlines (s)
799 (while (string-match "\\\\n" s
)
800 (setq s
(replace-match "\n" t t s
)))
803 (defvar org-export-allow-BIND-local nil
)
804 (defun org-export-confirm-letbind ()
805 "Can we use #+BIND values during export?
806 By default this will ask fro confirmation by the user, to divert possible
809 ((not org-export-allow-BIND
) nil
)
810 ((eq org-export-allow-BIND t
) t
)
811 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
812 org-export-allow-BIND-local
)
813 (t (org-set-local 'org-export-allow-BIND-local
814 (yes-or-no-p "Allow BIND values in this buffer? ")))))
816 (defun org-install-letbind ()
817 "Install the values from #+BIND lines as local variables."
818 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
820 (while (setq pair
(pop letbind
))
821 (org-set-local (car pair
) (nth 1 pair
)))))
823 (defun org-export-add-options-to-plist (p options
)
824 "Parse an OPTIONS line and set values in the property list P."
827 (let ((op org-export-plist-vars
))
828 (while (setq o
(pop op
))
830 (string-match (concat (regexp-quote (nth 1 o
))
831 ":\\([^ \t\n\r;,.]*\\)")
833 (setq p
(plist-put p
(car o
)
834 (car (read-from-string
835 (match-string 1 options
))))))))))
838 (defun org-export-add-subtree-options (p pos
)
839 "Add options in subtree at position POS to property list P."
842 (when (org-at-heading-p)
844 ;; This is actually read in `org-export-get-title-from-subtree'
845 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
846 ;; (setq p (plist-put p :title a)))
847 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
848 (setq p
(plist-put p
:text a
)))
849 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
850 (setq p
(plist-put p
:author a
)))
851 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
852 (setq p
(plist-put p
:date a
)))
853 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
854 (setq p
(org-export-add-options-to-plist p a
)))))
857 (defun org-export-directory (type plist
)
858 (let* ((val (plist-get plist
:publishing-directory
))
860 (or (cdr (assoc type val
)) ".")
864 (defun org-export-process-option-filters (plist)
865 (let ((functions org-export-options-filters
) f
)
866 (while (setq f
(pop functions
))
867 (setq plist
(funcall f plist
))))
871 (defun org-export (&optional arg
)
872 "Export dispatcher for Org-mode.
873 When `org-export-run-in-background' is non-nil, try to run the command
874 in the background. This will be done only for commands that write
875 to a file. For details see the docstring of `org-export-run-in-background'.
877 The prefix argument ARG will be passed to the exporter. However, if
878 ARG is a double universal prefix `C-u C-u', that means to inverse the
879 value of `org-export-run-in-background'."
881 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
883 (help "[t] insert the export option template
884 \[v] limit export to visible part of outline tree
885 \[1] only export the current subtree
886 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
888 \[a/n/u] export as ASCII/Latin-1/UFT-8 [A/N/U] to temporary buffer
890 \[h] export as HTML [H] to temporary buffer [R] export region
891 \[b] export as HTML and open in browser
893 \[l] export as LaTeX [L] to temporary buffer
894 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
896 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
898 \[m] export as Freemind mind map
900 \[g] export using Wes Hardaker's generic exporter
902 \[i] export current file as iCalendar file
903 \[I] export all agenda files as iCalendar files [c] ...as one combined file
905 \[F] publish current file [P] publish current project
906 \[X] publish a project... [E] publish every projects")
908 '((?t org-insert-export-options-template nil
)
909 (?v org-export-visible nil
)
910 (?a org-export-as-ascii t
)
911 (?A org-export-as-ascii-to-buffer t
)
912 (?n org-export-as-latin1 t
)
913 (?N org-export-as-latin1-to-buffer t
)
914 (?u org-export-as-utf8 t
)
915 (?U org-export-as-utf8-to-buffer t
)
916 (?h org-export-as-html t
)
917 (?b org-export-as-html-and-open t
)
918 (?H org-export-as-html-to-buffer nil
)
919 (?R org-export-region-as-html nil
)
920 (?x org-export-as-xoxo t
)
921 (?g org-export-generic t
)
922 (?D org-export-as-docbook t
)
923 (?V org-export-as-docbook-pdf-and-open t
)
924 (?m org-export-as-freemind t
)
925 (?l org-export-as-latex t
)
926 (?p org-export-as-pdf t
)
927 (?d org-export-as-pdf-and-open t
)
928 (?L org-export-as-latex-to-buffer nil
)
929 (?i org-export-icalendar-this-file t
)
930 (?I org-export-icalendar-all-agenda-files t
)
931 (?c org-export-icalendar-combine-agenda-files t
)
932 (?F org-publish-current-file t
)
933 (?P org-publish-current-project t
)
935 (?E org-publish-all t
)))
937 (cpos (point)) (cbuf (current-buffer)) bpos
)
939 (save-window-excursion
940 (delete-other-windows)
941 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
943 (org-fit-window-to-buffer (get-buffer-window
944 "*Org Export/Publishing Help*"))
945 (message "Select command: ")
946 (setq r1
(read-char-exclusive))
949 (message "Select command (for subtree): ")
950 (setq r1
(read-char-exclusive)))
952 (let ((case-fold-search t
))
953 (if (re-search-backward
954 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
957 (org-back-to-heading t
)
960 (message "Select command (for subtree): ")
961 (setq r1
(read-char-exclusive)))
962 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
964 (and bpos
(goto-char bpos
))
965 (setq r2
(if (< r1
27) (+ r1
96) r1
))
966 (unless (setq ass
(assq r2 cmds
))
967 (error "No command associated with key %c" r1
))
968 (if (and bg
(nth 2 ass
)
969 (not (buffer-base-buffer))
970 (not (org-region-active-p)))
971 ;; execute in background
972 (let ((p (start-process
973 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
975 (expand-file-name invocation-name invocation-directory
)
978 "--eval" "(require 'org-exp)"
979 "--eval" "(setq org-wait .2)"
981 "-f" (symbol-name (nth 1 ass
)))))
982 (set-process-sentinel p
'org-export-process-sentinel
)
983 (message "Background process \"%s\": started" p
))
984 ;; background processing not requested, or not possible
985 (if subtree-p
(progn (outline-mark-subtree) (activate-mark)))
986 (call-interactively (nth 1 ass
))
987 (when (and bpos
(get-buffer-window cbuf
))
988 (let ((cw (selected-window)))
989 (select-window (get-buffer-window cbuf
))
992 (select-window cw
))))))
994 (defun org-export-process-sentinel (process status
)
995 (if (string-match "\n+\\'" status
)
996 (setq status
(substring status
0 -
1)))
997 (message "Background process \"%s\": %s" process status
))
999 ;;; General functions for all backends
1001 (defvar org-export-target-aliases nil
1002 "Alist of targets with invisible aliases.")
1003 (defvar org-export-preferred-target-alist nil
1004 "Alist of section id's with preferred aliases.")
1005 (defvar org-export-id-target-alist nil
1006 "Alist of section id's with preferred aliases.")
1007 (defvar org-export-code-refs nil
1008 "Alist of code references and line numbers")
1010 (defun org-export-preprocess-string (string &rest parameters
)
1011 "Cleanup STRING so that that the true exported has a more consistent source.
1012 This function takes STRING, which should be a buffer-string of an org-file
1013 to export. It then creates a temporary buffer where it does its job.
1014 The result is then again returned as a string, and the exporter works
1015 on this string to produce the exported version."
1017 (let* ((htmlp (plist-get parameters
:for-html
))
1018 (asciip (plist-get parameters
:for-ascii
))
1019 (latexp (plist-get parameters
:for-LaTeX
))
1020 (docbookp (plist-get parameters
:for-docbook
))
1021 (backend (cond (htmlp 'html
)
1024 (docbookp 'docbook
)))
1025 (archived-trees (plist-get parameters
:archived-trees
))
1026 (inhibit-read-only t
)
1027 (drawers org-drawers
)
1028 (outline-regexp "\\*+ ")
1031 (setq org-export-target-aliases nil
1032 org-export-preferred-target-alist nil
1033 org-export-id-target-alist nil
1034 org-export-code-refs nil
)
1036 (with-current-buffer (get-buffer-create " org-mode-tmp")
1039 (setq case-fold-search t
)
1041 (let ((inhibit-read-only t
))
1042 (remove-text-properties (point-min) (point-max)
1045 ;; Remove license-to-kill stuff
1046 ;; The caller marks some stuff for killing, stuff that has been
1047 ;; used to create the page title, for example.
1048 (org-export-kill-licensed-text)
1050 (let ((org-inhibit-startup t
)) (org-mode))
1051 (setq case-fold-search t
)
1052 (org-install-letbind)
1055 (run-hooks 'org-export-preprocess-hook
)
1057 ;; Process the macros
1058 (org-export-preprocess-apply-macros)
1059 (run-hooks 'org-export-preprocess-after-macros-hook
)
1061 (untabify (point-min) (point-max))
1063 ;; Handle include files, and call a hook
1064 (org-export-handle-include-files)
1065 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1067 ;; Get rid of archived trees
1068 (org-export-remove-archived-trees archived-trees
)
1070 ;; Remove comment environment and comment subtrees
1071 (org-export-remove-comment-blocks-and-subtrees)
1073 ;; Get rid of excluded trees, and call a hook
1074 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1075 (plist-get parameters
:exclude-tags
))
1076 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1078 ;; Handle source code snippets
1079 (org-export-replace-src-segments-and-examples backend
)
1081 ;; Protect short examples marked by a leading colon
1082 (org-export-protect-colon-examples)
1084 ;; Normalize footnotes
1085 (when (plist-get parameters
:footnotes
)
1086 (org-footnote-normalize nil t
))
1088 ;; Find all headings and compute the targets for them
1089 (setq target-alist
(org-export-define-heading-targets target-alist
))
1091 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1093 ;; Find HTML special classes for headlines
1094 (org-export-remember-html-container-classes)
1096 ;; Get rid of drawers
1097 (org-export-remove-or-extract-drawers
1098 drawers
(plist-get parameters
:drawers
) backend
)
1100 ;; Get the correct stuff before the first headline
1101 (when (plist-get parameters
:skip-before-1st-heading
)
1102 (goto-char (point-min))
1103 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1104 (delete-region (point-min) (match-beginning 0))
1105 (goto-char (point-min))
1107 (when (plist-get parameters
:add-text
)
1108 (goto-char (point-min))
1109 (insert (plist-get parameters
:add-text
) "\n"))
1111 ;; Remove todo-keywords before exporting, if the user has requested so
1112 (org-export-remove-headline-metadata parameters
)
1114 ;; Find targets in comments and move them out of comments,
1115 ;; but mark them as targets that should be invisible
1116 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1118 ;; Select and protect backend specific stuff, throw away stuff
1119 ;; that is specific for other backends
1120 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1121 (org-export-select-backend-specific-text backend
)
1123 ;; Protect quoted subtrees
1124 (org-export-protect-quoted-subtrees)
1126 ;; Remove clock lines
1127 (org-export-remove-clock-lines)
1129 ;; Protect verbatim elements
1130 (org-export-protect-verbatim)
1132 ;; Blockquotes, verse, and center
1133 (org-export-mark-blockquote-verse-center)
1134 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1136 ;; Remove timestamps, if the user has requested so
1137 (unless (plist-get parameters
:timestamps
)
1138 (org-export-remove-timestamps))
1140 ;; Attach captions to the correct object
1141 (setq target-alist
(org-export-attach-captions-and-attributes
1142 backend target-alist
))
1144 ;; Find matches for radio targets and turn them into internal links
1145 (org-export-mark-radio-links)
1147 ;; Find all links that contain a newline and put them into a single line
1148 (org-export-concatenate-multiline-links)
1150 ;; Normalize links: Convert angle and plain links into bracket links
1151 ;; and expand link abbreviations
1152 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1153 (org-export-normalize-links)
1155 ;; Find all internal links. If they have a fuzzy match (i.e. not
1156 ;; a *dedicated* target match, let the link point to the
1157 ;; corresponding section.
1158 (org-export-target-internal-links target-alist
)
1160 ;; Find multiline emphasis and put them into single line
1161 (when (plist-get parameters
:emph-multiline
)
1162 (org-export-concatenate-multiline-emphasis))
1164 ;; Remove special table lines
1165 (when org-export-table-remove-special-lines
1166 (org-export-remove-special-table-lines))
1169 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1171 ;; LaTeX-specific preprocessing
1173 (require 'org-latex nil
)
1174 (org-export-latex-preprocess parameters
))
1176 ;; ASCII-specific preprocessing
1178 (org-export-ascii-preprocess parameters
))
1180 ;; HTML-specific preprocessing
1182 (org-export-html-preprocess parameters
))
1184 ;; DocBook-specific preprocessing
1186 (require 'org-docbook nil
)
1187 (org-export-docbook-preprocess parameters
))
1189 ;; Remove or replace comments
1190 (org-export-handle-comments (plist-get parameters
:comments
))
1192 ;; Run the final hook
1193 (run-hooks 'org-export-preprocess-final-hook
)
1195 (setq rtn
(buffer-string)))
1196 (kill-buffer " org-mode-tmp")
1199 (defun org-export-kill-licensed-text ()
1200 "Remove all text that is marked with a :org-license-to-kill property."
1202 (while (setq p
(text-property-any (point-min) (point-max)
1203 :org-license-to-kill t
))
1205 p
(or (next-single-property-change p
:org-license-to-kill
)
1208 (defun org-export-define-heading-targets (target-alist)
1209 "Find all headings and define the targets for them.
1210 The new targets are added to TARGET-ALIST, which is also returned.
1211 Also find all ID and CUSTOM_ID propertiess and store them."
1212 (goto-char (point-min))
1213 (org-init-section-numbers)
1214 (let ((re (concat "^" org-outline-regexp
1216 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1217 level target last-section-target a id
)
1218 (while (re-search-forward re nil t
)
1219 (org-if-unprotected-at (match-beginning 0)
1222 (setq id
(org-match-string-no-properties 2))
1223 (push (cons id target
) target-alist
)
1224 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1226 (push (list last-section-target
)
1227 org-export-target-aliases
)
1228 (car org-export-target-aliases
))))
1229 (push (caar target-alist
) (cdr a
))
1230 (when (equal (match-string 1) "CUSTOM_ID")
1231 (if (not (assoc last-section-target
1232 org-export-preferred-target-alist
))
1233 (push (cons last-section-target id
)
1234 org-export-preferred-target-alist
)))
1235 (when (equal (match-string 1) "ID")
1236 (if (not (assoc last-section-target
1237 org-export-id-target-alist
))
1238 (push (cons last-section-target
(concat "ID-" id
))
1239 org-export-id-target-alist
))))
1240 (setq level
(org-reduced-level
1241 (save-excursion (goto-char (point-at-bol))
1242 (org-outline-level))))
1243 (setq target
(org-solidify-link-text
1244 (format "sec-%s" (replace-regexp-in-string
1246 (org-section-number level
)))))
1247 (setq last-section-target target
)
1248 (push (cons target target
) target-alist
)
1249 (add-text-properties
1250 (point-at-bol) (point-at-eol)
1251 (list 'target target
))))))
1254 (defun org-export-handle-invisible-targets (target-alist)
1255 "Find targets in comments and move them out of comments.
1256 Mark them as invisible targets."
1258 (goto-char (point-min))
1259 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1260 ;; Check if the line before or after is a headline with a target
1261 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1262 (get-text-property (point-at-bol 2) 'target
)))
1264 ;; use the existing target in a neighboring line
1265 (setq tmp
(match-string 2))
1267 (and (looking-at "\n") (delete-char 1))
1268 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1270 (setq a
(or (assoc target org-export-target-aliases
)
1272 (push (list target
) org-export-target-aliases
)
1273 (car org-export-target-aliases
))))
1275 ;; Make an invisible target
1276 (replace-match "\\1(INVISIBLE)"))))
1279 (defun org-export-target-internal-links (target-alist)
1280 "Find all internal links and assign targets to them.
1281 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1282 let the link point to the corresponding section.
1283 This function also handles the id links, if they have a match in
1285 (goto-char (point-min))
1286 (while (re-search-forward org-bracket-link-regexp nil t
)
1287 (org-if-unprotected-at (1+ (match-beginning 0))
1288 (let* ((md (match-data))
1289 (desc (match-end 2))
1290 (link (org-link-unescape (match-string 1)))
1291 (slink (org-solidify-link-text link
))
1292 found props pos cref
1295 ((= (string-to-char link
) ?
#)
1296 ;; user wants exactly this link
1298 ((cdr (assoc slink target-alist
))
1299 (or (cdr (assoc (assoc slink target-alist
)
1300 org-export-preferred-target-alist
))
1301 (cdr (assoc slink target-alist
))))
1302 ((and (string-match "^id:" link
)
1303 (cdr (assoc (substring link
3) target-alist
))))
1304 ((string-match "^(\\(.*\\))$" link
)
1305 (setq cref
(match-string 1 link
))
1306 (concat "coderef:" cref
))
1307 ((string-match org-link-types-re link
) nil
)
1308 ((or (file-name-absolute-p link
)
1309 (string-match "^\\." link
))
1313 (setq found
(condition-case nil
(org-link-search link
)
1316 (or (org-on-heading-p)
1317 (not (eq found
'dedicated
))))
1318 (or (get-text-property (point) 'target
)
1321 (1- (or (previous-single-property-change
1322 (point) 'target
) 0)))
1326 (goto-char (match-beginning 1))
1327 (setq props
(text-properties-at (point)))
1328 (delete-region (match-beginning 1) (match-end 1))
1331 (unless desc
(insert "][" link
))
1332 (add-text-properties pos
(point) props
))))))
1334 (defun org-export-remember-html-container-classes ()
1335 "Store the HTML_CONTAINER_CLASS properties in a text property."
1336 (goto-char (point-min))
1338 (while (re-search-forward
1339 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(\\S-+\\)" nil t
)
1340 (setq class
(match-string 1))
1342 (org-back-to-heading t
)
1343 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1345 (defvar org-export-format-drawer-function nil
1346 "Function to be called to format the contents of a drawer.
1347 The function must accept three parameters:
1348 NAME the drawer name, like \"PROPERTIES\"
1349 CONTENT the content of the drawer.
1350 BACKEND one of the symbols html, docbook, latex, ascii, xoxo
1351 The function should return the text to be inserted into the buffer.
1352 If this is nil, `org-export-format-drawer' is used as a default.")
1354 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend
)
1355 "Remove drawers, or extract and format the content.
1356 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1357 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1358 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1359 EXP-DRAWERS will be removed.
1360 BACKEND is the current export backend."
1361 (goto-char (point-min))
1362 (let ((re (concat "^[ \t]*:\\("
1363 (mapconcat 'identity all-drawers
"\\|")
1365 name beg beg-content eol content
)
1366 (while (re-search-forward re nil t
)
1368 (setq name
(match-string 1))
1369 (setq beg
(match-beginning 0)
1370 beg-content
(1+ (point-at-eol))
1372 (if (not (and (re-search-forward
1373 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1376 (goto-char (match-beginning 0))
1377 (and (looking-at ".*\n?") (replace-match ""))
1378 (setq content
(buffer-substring beg-content
(point)))
1379 (delete-region beg
(point))
1380 (when (or (eq exp-drawers t
)
1381 (member name exp-drawers
))
1382 (setq content
(funcall (or org-export-format-drawer-function
1383 'org-export-format-drawer
)
1384 name content backend
))
1385 (insert content
)))))))
1387 (defun org-export-format-drawer (name content backend
)
1388 "Format the content of a drawer as a colon example."
1389 (if (string-match "[ \t]+\\'" content
)
1390 (setq content
(substring content
(match-beginning 0))))
1391 (while (string-match "\\`[ \t]*\n" content
)
1392 (setq content
(substring content
(match-end 0))))
1393 (setq content
(org-remove-indentation content
))
1394 (setq content
(concat ": " (mapconcat 'identity
1395 (org-split-string content
"\n")
1398 (setq content
(concat " : " (upcase name
) "\n" content
))
1399 (org-add-props content nil
'org-protected t
))
1401 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1402 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1403 Both arguments are lists of tags.
1404 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1406 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1408 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1409 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1412 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1416 (goto-char (point-min))
1417 (when (and select-tags
1419 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1420 ;; At least one tree is marked for export, this means
1421 ;; all the unmarked stuff needs to go.
1422 ;; Dig out the trees that should be exported
1423 (goto-char (point-min))
1424 (outline-next-heading)
1426 (put-text-property beg
(point-max) :org-delete t
)
1427 (while (re-search-forward re-sel nil t
)
1428 (when (org-on-heading-p)
1429 (org-back-to-heading)
1430 (remove-text-properties
1431 (max (1- (point)) (point-min))
1432 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1434 (while (and (org-up-heading-safe)
1435 (get-text-property (point) :org-delete
))
1436 (remove-text-properties (max (1- (point)) (point-min))
1437 (point-at-eol) '(:org-delete t
)))
1439 ;; Remove the trees explicitly marked for noexport
1441 (goto-char (point-min))
1442 (while (re-search-forward re-excl nil t
)
1443 (when (org-at-heading-p)
1444 (org-back-to-heading t
)
1446 (org-end-of-subtree t t
)
1447 (delete-region beg
(point))
1448 (when (featurep 'org-inlinetask
)
1449 (org-inlinetask-remove-END-maybe)))))
1450 ;; Remove everything that is now still marked for deletion
1451 (goto-char (point-min))
1452 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1453 (setq end
(or (next-single-property-change beg
:org-delete
)
1455 (delete-region beg end
))))
1457 (defun org-export-remove-archived-trees (export-archived-trees)
1458 "Remove archived trees.
1459 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1460 When it is t, the entire archived tree will be exported.
1461 When it is nil the entire tree including the headline will be removed
1463 (let ((re-archive (concat ":" org-archive-tag
":"))
1465 (when (not (eq export-archived-trees t
))
1466 (goto-char (point-min))
1467 (while (re-search-forward re-archive nil t
)
1468 (if (not (org-on-heading-p t
))
1469 (org-end-of-subtree t
)
1470 (beginning-of-line 1)
1471 (setq a
(if export-archived-trees
1472 (1+ (point-at-eol)) (point))
1473 b
(org-end-of-subtree t
))
1474 (if (> b a
) (delete-region a b
)))))))
1476 (defun org-export-remove-headline-metadata (opts)
1477 "Remove meta data from the headline, according to user options."
1478 (let ((re org-complex-heading-regexp
)
1479 (todo (plist-get opts
:todo-keywords
))
1480 (tags (plist-get opts
:tags
))
1481 (pri (plist-get opts
:priority
))
1484 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1485 (when (or (not todo
) (not tags
) (not pri
))
1486 (goto-char (point-min))
1487 (while (re-search-forward re nil t
)
1489 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1491 (replace-match rpl t t
))))))
1493 (defun org-export-remove-timestamps ()
1494 "Remove timestamps and keywords for export."
1495 (goto-char (point-min))
1496 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1499 (unless (save-match-data (org-at-table-p))
1501 (beginning-of-line 1)
1502 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1503 (replace-match ""))))))
1505 (defun org-export-remove-clock-lines ()
1506 "Remove clock lines for export."
1507 (goto-char (point-min))
1508 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1509 (while (re-search-forward re nil t
)
1511 (replace-match "")))))
1513 (defun org-export-protect-quoted-subtrees ()
1514 "Mark quoted subtrees with the protection property."
1515 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1516 (goto-char (point-min))
1517 (while (re-search-forward re-quote nil t
)
1518 (goto-char (match-beginning 0))
1520 (add-text-properties (point) (org-end-of-subtree t
)
1521 '(org-protected t
)))))
1523 (defun org-export-protect-verbatim ()
1524 "Mark verbatim snippets with the protection property."
1525 (goto-char (point-min))
1526 (while (re-search-forward org-verbatim-re nil t
)
1528 (add-text-properties (match-beginning 4) (match-end 4)
1529 '(org-protected t org-verbatim-emph t
))
1530 (goto-char (1+ (match-end 4))))))
1532 (defun org-export-protect-colon-examples ()
1533 "Protect lines starting with a colon."
1534 (goto-char (point-min))
1535 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1536 (while (re-search-forward re nil t
)
1537 (beginning-of-line 1)
1539 (while (looking-at re
)
1541 (or (eobp) (forward-char 1)))
1542 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1543 '(org-protected t
)))))
1545 (defun org-export-select-backend-specific-text (backend)
1547 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1548 (html "HTML" "BEGIN_HTML" "END_HTML")
1549 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1550 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1551 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1552 (case-fold-search t
)
1553 fmt beg beg-content end end-content
)
1556 (setq fmt
(pop formatters
))
1557 (when (eq (car fmt
) backend
)
1558 ;; This is selected code, put it into the file for real
1559 (goto-char (point-min))
1560 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1561 ":[ \t]*\\(.*\\)") nil t
)
1562 (replace-match "\\1\\2" t
)
1563 (add-text-properties
1564 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1565 '(org-protected t
))))
1566 (goto-char (point-min))
1567 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt
) "\\>.*\n?")
1569 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1570 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt
) "\\>.*\n?")
1572 (setq end
(match-end 0) end-content
(match-beginning 0))
1573 (if (eq (car fmt
) backend
)
1576 (add-text-properties beg-content end-content
'(org-protected t
))
1577 (delete-region (match-beginning 0) (match-end 0))
1580 (delete-region (point) (1+ (point-at-eol)))))
1581 ;; No, this is for a different backend, kill it
1582 (delete-region beg end
)))))))
1584 (defun org-export-mark-blockquote-verse-center ()
1585 "Mark block quote and verse environments with special cookies.
1586 These special cookies will later be interpreted by the backend."
1588 (let (type t1 ind beg end beg1 end1 content
)
1589 (goto-char (point-min))
1590 (while (re-search-forward
1591 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1593 (setq ind
(length (match-string 1))
1594 type
(downcase (match-string 3))
1595 t1
(if (equal type
"quote") "blockquote" type
))
1596 (setq beg
(match-beginning 0)
1597 beg1
(1+ (match-end 0)))
1598 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1599 (setq end
(1+ (point-at-eol))
1600 end1
(1- (match-beginning 0)))
1601 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1602 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1604 "ORG-" (upcase t1
) "-END\n"))
1605 (delete-region beg end
)
1606 (insert (org-add-props content nil
'original-indentation ind
))))))
1608 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1609 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1610 If the next thing following is a table, add the text properties to the first
1611 table line. If it is a link, add it to the line containing the link."
1612 (goto-char (point-min))
1613 (remove-text-properties (point-min) (point-max)
1614 '(org-caption nil org-attributes nil
))
1615 (let ((case-fold-search t
)
1616 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1618 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1620 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1622 "^[ \t]*\\(|[^-]\\)"
1624 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1626 (while (re-search-forward re nil t
)
1629 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1631 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1633 (setq label
(org-trim (match-string 3))))
1635 (setq end
(if (match-end 4)
1636 (let ((ee (org-table-end)))
1637 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1639 (add-text-properties (point-at-bol) end
1640 (list 'org-caption cap
1641 'org-attributes attr
1643 (if label
(push (cons label label
) target-alist
))
1645 (setq cap nil attr nil label nil
)))))
1648 (defun org-export-remove-comment-blocks-and-subtrees ()
1649 "Remove the comment environment, and also commented subtrees."
1650 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1652 ;; Remove comment environment
1653 (goto-char (point-min))
1654 (setq case-fold-search t
)
1655 (while (re-search-forward
1656 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t
)
1657 (replace-match "" t t
))
1658 ;; Remove subtrees that are commented
1659 (goto-char (point-min))
1660 (setq case-fold-search nil
)
1661 (while (re-search-forward re-commented nil t
)
1662 (goto-char (match-beginning 0))
1663 (delete-region (point) (org-end-of-subtree t
)))))
1665 (defun org-export-handle-comments (commentsp)
1666 "Remove comments, or convert to backend-specific format.
1667 COMMENTSP can be a format string for publishing comments.
1668 When it is nil, all comments will be removed."
1669 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1671 (goto-char (point-min))
1672 (while (or (looking-at re
)
1673 (re-search-forward re nil t
))
1674 (setq pos
(match-beginning 0))
1676 (not (equal (char-before (match-end 1)) ?
+)))
1677 (progn (add-text-properties
1678 (match-beginning 0) (match-end 0) '(org-protected t
))
1679 (replace-match (format commentsp
(match-string 2)) t t
))
1680 (goto-char (1+ pos
))
1683 (goto-char (max (point-min) (1- pos
))))))))
1685 (defun org-export-mark-radio-links ()
1686 "Find all matches for radio targets and turn them into internal links."
1687 (let ((re-radio (and org-target-link-regexp
1688 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1689 (goto-char (point-min))
1691 (while (re-search-forward re-radio nil t
)
1694 (or (org-in-regexp org-bracket-link-regexp
)
1695 (org-in-regexp org-plain-link-re
)
1696 (org-in-regexp "<<[^<>]+>>")))
1698 (replace-match "\\1[[\\2]]")))))))
1700 (defun org-export-remove-special-table-lines ()
1701 "Remove tables lines that are used for internal purposes."
1702 (goto-char (point-min))
1703 (while (re-search-forward "^[ \t]*|" nil t
)
1704 (beginning-of-line 1)
1705 (if (or (looking-at "[ \t]*| *[!_^] *|")
1711 (or (= (length f
) 0)
1713 "\\`<\\([0-9]\\|[rl]\\|[rl][0-9]+\\)>\\'" f
)))
1714 (org-split-string ;; FIXME, can't we do this without splitting???
1715 (buffer-substring (point-at-bol) (point-at-eol))
1716 "[ \t]*|[ \t]*")))))
1717 (delete-region (max (point-min) (1- (point-at-bol)))
1721 (defun org-export-protect-sub-super (s)
1723 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
1724 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
1727 (defun org-export-normalize-links ()
1728 "Convert all links to bracket links, and expand link abbreviations."
1729 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1730 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1732 (goto-char (point-min))
1733 (while (re-search-forward re-plain-link nil t
)
1734 (goto-char (1- (match-end 0)))
1735 (org-if-unprotected-at (1+ (match-beginning 0))
1736 (let* ((s (concat (match-string 1)
1737 "[[" (match-string 2) ":" (match-string 3)
1738 "][" (match-string 2) ":" (org-export-protect-sub-super
1741 ;; added 'org-link face to links
1742 (put-text-property 0 (length s
) 'face
'org-link s
)
1743 (replace-match s t t
))))
1744 (goto-char (point-min))
1745 (while (re-search-forward re-angle-link nil t
)
1746 (goto-char (1- (match-end 0)))
1748 (let* ((s (concat (match-string 1)
1749 "[[" (match-string 2) ":" (match-string 3)
1750 "][" (match-string 2) ":" (org-export-protect-sub-super
1753 (put-text-property 0 (length s
) 'face
'org-link s
)
1754 (replace-match s t t
))))
1755 (goto-char (point-min))
1756 (while (re-search-forward org-bracket-link-regexp nil t
)
1757 (goto-char (1- (match-end 0)))
1758 (setq nodesc
(not (match-end 3)))
1760 (let* ((xx (save-match-data
1762 (org-link-expand-abbrev (match-string 1)))))
1764 "[[" (org-add-props (copy-sequence xx
)
1765 nil
'org-protected t
'org-no-description nodesc
)
1769 (concat "[" (copy-sequence xx
)
1772 (put-text-property 0 (length s
) 'face
'org-link s
)
1773 (replace-match s t t
))))))
1775 (defun org-export-concatenate-multiline-links ()
1776 "Find multi-line links and put it all into a single line.
1777 This is to make sure that the line-processing export backends
1778 can work correctly."
1779 (goto-char (point-min))
1780 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1781 (org-if-unprotected-at (match-beginning 1)
1782 (replace-match "\\1 \\3")
1783 (goto-char (match-beginning 0)))))
1785 (defun org-export-concatenate-multiline-emphasis ()
1786 "Find multi-line emphasis and put it all into a single line.
1787 This is to make sure that the line-processing export backends
1788 can work correctly."
1789 (goto-char (point-min))
1790 (while (re-search-forward org-emph-re nil t
)
1791 (if (and (not (= (char-after (match-beginning 3))
1792 (char-after (match-beginning 4))))
1793 (save-excursion (goto-char (match-beginning 0))
1794 (save-match-data (not (org-at-table-p)))))
1796 (subst-char-in-region (match-beginning 0) (match-end 0)
1798 (goto-char (1- (match-end 0))))
1799 (goto-char (1+ (match-beginning 0))))))
1801 (defun org-export-grab-title-from-buffer ()
1802 "Get a title for the current document, from looking at the buffer."
1803 (let ((inhibit-read-only t
))
1805 (goto-char (point-min))
1806 (let ((end (if (looking-at org-outline-regexp
)
1808 (save-excursion (outline-next-heading) (point)))))
1809 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1810 ;; Mark the line so that it will not be exported as normal text.
1812 (add-text-properties (match-beginning 0) (match-end 0)
1813 (list :org-license-to-kill t
)))
1814 ;; Return the title string
1815 (org-trim (match-string 0)))))))
1817 (defun org-export-get-title-from-subtree ()
1818 "Return subtree title and exclude it from export."
1819 (let (title (rbeg (region-beginning)) (rend (region-end)))
1822 (when (and (org-at-heading-p)
1823 (>= (org-end-of-subtree t t
) rend
))
1824 ;; This is a subtree, we take the title from the first heading
1826 (looking-at org-todo-line-regexp
)
1827 (setq title
(match-string 3))
1829 (add-text-properties (point) (1+ (point-at-eol))
1830 (list :org-license-to-kill t
)))
1831 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1834 (defun org-solidify-link-text (s &optional alist
)
1835 "Take link text and make a safe target out of it."
1840 (org-split-string s
"[ \t\r\n]+") "=="))
1841 (a (assoc rtn alist
)))
1844 (defun org-get-min-level (lines &optional offset
)
1845 "Get the minimum level in LINES."
1846 (let ((re "^\\(\\*+\\) ") l
)
1848 (while (setq l
(pop lines
))
1849 (if (string-match re l
)
1850 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1854 ;; Variable holding the vector with section numbers
1855 (defvar org-section-numbers
(make-vector org-level-max
0))
1857 (defun org-init-section-numbers ()
1858 "Initialize the vector for the section numbers."
1860 (numbers (nreverse (org-split-string "" "\\.")))
1861 (depth (1- (length org-section-numbers
)))
1862 (i depth
) number-string
)
1865 (aset org-section-numbers i
0)
1866 (setq number-string
(or (car numbers
) "0"))
1867 (if (string-match "\\`[A-Z]\\'" number-string
)
1868 (aset org-section-numbers i
1869 (- (string-to-char number-string
) ?A -
1))
1870 (aset org-section-numbers i
(string-to-number number-string
)))
1874 (defun org-section-number (&optional level
)
1875 "Return a string with the current section number.
1876 When LEVEL is non-nil, increase section numbers on that level."
1877 (let* ((depth (1- (length org-section-numbers
)))
1879 (fmts (car org-export-section-number-format
))
1880 (term (cdr org-export-section-number-format
))
1885 (aset org-section-numbers
1886 level
(1+ (aref org-section-numbers level
))))
1887 (setq idx
(1+ level
))
1888 (while (<= idx depth
)
1890 (aset org-section-numbers idx
0))
1891 (setq idx
(1+ idx
))))
1893 (while (<= idx depth
)
1894 (when (> (aref org-section-numbers idx
) 0)
1895 (setq fmt
(or (pop fmts
) fmt
)
1897 n
(aref org-section-numbers idx
)
1899 (concat string sep
(org-number-to-counter n ctype
))
1900 (concat string
".0"))
1902 (setq idx
(1+ idx
)))
1904 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1905 (setq string
(replace-match "" t nil string
)))
1906 (if (string-match "\\(\\.0\\)+\\'" string
)
1907 (setq string
(replace-match "" t nil string
))))
1908 (concat string term
)))
1910 (defun org-number-to-counter (n type
)
1911 "Concert number N to a string counter, according to TYPE.
1912 TYPE must be a string, any of:
1916 I upper case roman numeral
1917 i lower case roman numeral"
1919 ((equal type
"1") (number-to-string n
))
1920 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1921 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1922 ((equal type
"I") (org-number-to-roman n
))
1923 ((equal type
"i") (downcase (org-number-to-roman n
)))
1924 (t (error "Invalid counter type `%s'" type
))))
1926 (defun org-number-to-roman (n)
1927 "Convert integer N into a roman numeral."
1928 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1929 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1930 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1934 (number-to-string n
)
1936 (if (>= n
(caar roman
))
1937 (setq n
(- n
(caar roman
))
1938 res
(concat res
(cdar roman
)))
1944 (defun org-export-preprocess-apply-macros ()
1945 "Replace macro references."
1946 (goto-char (point-min))
1947 (let (sy val key args args2 s n
)
1948 (while (re-search-forward
1949 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
1951 (unless (save-match-data
1953 (goto-char (point-at-bol))
1954 (looking-at "[ \t]*#\\+macro")))
1955 (setq key
(downcase (match-string 1))
1956 args
(match-string 3))
1957 (when (setq val
(or (plist-get org-export-opt-plist
1958 (intern (concat ":macro-" key
)))
1959 (plist-get org-export-opt-plist
1960 (intern (concat ":" key
)))))
1963 (setq args
(org-split-string args
",[ \t\n]*") args2 nil
)
1964 (setq args
(mapcar 'org-trim args
))
1966 (while (string-match "\\\\\\'" (car args
))
1967 ;; repair bad splits
1968 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
1971 (push (pop args
) args2
))
1972 (setq args
(nreverse args2
))
1974 (while (string-match "\\$\\([0-9]+\\)" val s
)
1975 (setq s
(1+ (match-beginning 0))
1976 n
(string-to-number (match-string 1 val
)))
1977 (and (>= (length args
) n
)
1978 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
1979 (when (string-match "\\`(eval\\>" val
)
1980 (setq val
(eval (read val
))))
1981 (if (and val
(not (stringp val
)))
1982 (setq val
(format "%s" val
))))
1984 (prog1 (replace-match val t t
)
1985 (goto-char (match-beginning 0)))))))))
1987 (defun org-export-apply-macros-in-string (s)
1988 "Apply the macros in string S."
1992 (org-export-preprocess-apply-macros)
1997 (defun org-export-handle-include-files ()
1998 "Include the contents of include files, with proper formatting."
1999 (let ((case-fold-search t
)
2000 params file markup lang start end prefix prefix1 switches
)
2001 (goto-char (point-min))
2002 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2003 (setq params
(read (concat "(" (match-string 1) ")"))
2004 prefix
(org-get-and-remove-property 'params
:prefix
)
2005 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2006 file
(org-symname-or-string (pop params
))
2007 markup
(org-symname-or-string (pop params
))
2008 lang
(and (member markup
'("src" "SRC"))
2009 (org-symname-or-string (pop params
)))
2010 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" ")
2012 (delete-region (match-beginning 0) (match-end 0))
2014 (not (file-exists-p file
))
2015 (not (file-readable-p file
)))
2016 (insert (format "CANNOT INCLUDE FILE %s" file
))
2018 (if (equal (downcase markup
) "src")
2019 (setq start
(format "#+begin_src %s %s\n"
2020 (or lang
"fundamental")
2023 (setq start
(format "#+begin_%s %s\n" markup switches
)
2024 end
(format "#+end_%s" markup
))))
2025 (insert (or start
""))
2026 (insert (org-get-file-contents (expand-file-name file
)
2027 prefix prefix1 markup
))
2028 (or (bolp) (newline))
2029 (insert (or end
""))))))
2031 (defun org-get-file-contents (file &optional prefix prefix1 markup
)
2032 "Get the contents of FILE and return them as a string.
2033 If PREFIX is a string, prepend it to each line. If PREFIX1
2034 is a string, prepend it to the first line instead of PREFIX.
2035 If MARKUP, don't protect org-like lines, the exporter will
2036 take care of the block they are in."
2037 (if (stringp markup
) (setq markup
(downcase markup
)))
2039 (insert-file-contents file
)
2040 (when (or prefix prefix1
)
2041 (goto-char (point-min))
2043 (insert (or prefix1 prefix
))
2045 (beginning-of-line 2)))
2047 (when (member markup
'("src" "example"))
2048 (goto-char (point-min))
2049 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2050 (goto-char (match-beginning 0))
2055 (defun org-get-and-remove-property (listvar prop
)
2056 "Check if the value of LISTVAR contains PROP as a property.
2057 If yes, return the value of that property (i.e. the element following
2058 in the list) and remove property and value from the list in LISTVAR."
2059 (let ((list (symbol-value listvar
)) m v
)
2060 (when (setq m
(member prop list
))
2062 (if (equal (car list
) prop
)
2063 (set listvar
(cddr list
))
2064 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2066 (set listvar list
)))
2069 (defun org-symname-or-string (s)
2071 (if s
(symbol-name s
) s
)
2074 ;;; Fontification and line numbers for code examples
2076 (defvar org-export-last-code-line-counter-value
0)
2078 (defun org-export-replace-src-segments-and-examples (backend)
2079 "Replace source code segments with special code for export."
2080 (setq org-export-last-code-line-counter-value
0)
2081 (let ((case-fold-search t
)
2082 lang code trans opts indent caption
)
2083 (goto-char (point-min))
2084 (while (re-search-forward
2085 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2089 (setq lang
(match-string 3)
2090 opts
(match-string 4)
2091 code
(match-string 5)
2092 indent
(length (match-string 2))
2093 caption
(get-text-property 0 'org-caption
(match-string 0)))
2095 opts
(match-string 8)
2096 code
(match-string 9)
2097 indent
(length (match-string 7))
2098 caption
(get-text-property 0 'org-caption
(match-string 0))))
2100 (setq trans
(org-export-format-source-code-or-example
2101 backend lang code opts indent caption
))
2102 (replace-match trans t t
))))
2104 (defvar htmlp
) ;; dynamically scoped
2105 (defvar latexp
) ;; dynamically scoped
2106 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2107 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2108 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2110 (defun org-export-format-source-code-or-example
2111 (backend lang code
&optional opts indent caption
)
2112 "Format CODE from language LANG and return it formatted for export.
2113 If LANG is nil, do not add any fontification.
2114 OPTS contains formatting options, like `-n' for triggering numbering lines,
2115 and `+n' for continuing previous numbering.
2116 Code formatting according to language currently only works for HTML.
2117 Numbering lines works for all three major backends (html, latex, and ascii).
2118 INDENT was the original indentation of the block."
2120 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2121 (setq opts
(or opts
"")
2122 num
(string-match "[-+]n\\>" opts
)
2123 cont
(string-match "\\+n\\>" opts
)
2124 rpllbl
(string-match "-r\\>" opts
)
2125 keepp
(string-match "-k\\>" opts
)
2126 textareap
(string-match "-t\\>" opts
)
2127 preserve-indentp
(or org-src-preserve-indentation
2128 (string-match "-i\\>" opts
))
2129 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2130 (string-to-number (match-string 1 opts
))
2132 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2133 (string-to-number (match-string 1 opts
))
2134 (org-count-lines code
))
2135 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2136 (match-string 1 opts
)))
2137 (when (and textareap
(eq backend
'html
))
2138 ;; we cannot use numbering or highlighting.
2139 (setq num nil cont nil lang nil
))
2140 (if keepp
(setq rpllbl
'keep
))
2141 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2142 (when (string-match "^," rtn
)
2143 (setq rtn
(with-temp-buffer
2145 ;; Free up the protected lines
2146 (goto-char (point-min))
2147 (while (re-search-forward "^," nil t
)
2148 (if (or (equal lang
"org")
2150 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2154 ;; Now backend-specific coding
2157 ((eq backend
'docbook
)
2158 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2159 (concat "\n#+BEGIN_DOCBOOK\n"
2160 (org-add-props (concat "<programlisting><![CDATA["
2162 "]]></programlisting>\n")
2166 ;; We are exporting to HTML
2168 (require 'htmlize nil t
)
2169 (when (not (fboundp 'htmlize-region-for-paste
))
2170 ;; we do not have htmlize.el, or an old version of it
2173 "htmlize.el 1.34 or later is needed for source code formatting")))
2176 (let* ((lang-m (when lang
2177 (or (cdr (assoc lang org-src-lang-modes
))
2179 (mode (and lang-m
(intern
2181 (if (symbolp lang-m
)
2182 (symbol-name lang-m
)
2185 (org-inhibit-startup t
)
2186 (org-startup-folded nil
))
2190 (if (functionp mode
)
2193 (font-lock-fontify-buffer)
2195 (set-buffer-modified-p nil
)
2196 (org-export-htmlize-region-for-paste
2197 (point-min) (point-max))))
2198 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2203 "<div class=\"org-src-container\">"
2205 "<label class=\"org-src-name\">%s</label>"
2209 (format "<pre class=\"src src-%s\">\n" lang
)
2211 (if caption
"</div>" "")))))
2214 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2216 rtn
"</textarea>\n</p>\n"))
2219 (goto-char (point-min))
2220 (while (re-search-forward "[<>&]" nil t
)
2221 (replace-match (cdr (assq (char-before)
2222 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2224 (setq rtn
(buffer-string)))
2225 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2227 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2229 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2230 (setq rtn
(replace-match "\\1" t nil rtn
)))
2231 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2232 ((eq backend
'latex
)
2233 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2234 (concat "#+BEGIN_LaTeX\n"
2236 (if org-export-latex-listings
2240 ((lang-sym (intern lang
))
2245 org-export-latex-listings-langs
))
2247 (format "\\lstset{language=%s}\n" lstlang
))
2250 (format "\n%s $\\equiv$ \n" caption
))
2251 "\\begin{lstlisting}\n"
2252 rtn
"\\end{lstlisting}\n")
2253 (concat (car org-export-latex-verbatim-wrap
)
2254 rtn
(cdr org-export-latex-verbatim-wrap
)))
2257 ((eq backend
'ascii
)
2258 ;; This is not HTML or LaTeX, so just make it an example.
2259 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2260 (concat caption
"\n"
2265 (lambda (l) (concat " " l
))
2266 (org-split-string rtn
"\n")
2271 (org-add-props rtn nil
'original-indentation indent
))))
2273 (defun org-export-number-lines (text backend
2274 &optional skip1 skip2 number cont
2275 replace-labels label-format
)
2276 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2277 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2280 (goto-char (point-max))
2281 (skip-chars-backward " \t\n\r")
2282 (delete-region (point) (point-max))
2283 (beginning-of-line (- 1 skip2
))
2284 (let* ((last (org-current-line))
2285 (n org-export-last-code-line-counter-value
)
2286 (nmax (+ n
(- last skip1
)))
2287 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2290 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2292 ((eq backend
'ascii
) fmt
)
2293 ((eq backend
'latex
) fmt
)
2294 ((eq backend
'docbook
) fmt
)
2296 (label-format (or label-format org-coderef-label-format
))
2297 (label-pre (if (string-match "%s" label-format
)
2298 (substring label-format
0 (match-beginning 0))
2300 (label-post (if (string-match "%s" label-format
)
2301 (substring label-format
(match-end 0))
2305 ".*?\\S-.*?\\([ \t]*\\("
2306 (regexp-quote label-pre
)
2307 "\\([-a-zA-Z0-9_ ]+\\)"
2308 (regexp-quote label-post
)
2312 (org-goto-line (1+ skip1
))
2313 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2315 (insert (format fm
(incf n
)))
2317 (when (looking-at lbl-re
)
2318 (setq ref
(match-string 3))
2319 (cond ((numberp replace-labels
)
2320 ;; remove labels; use numbers for references when lines
2321 ;; are numbered, use labels otherwise
2322 (delete-region (match-beginning 1) (match-end 1))
2323 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2324 ((eq replace-labels
'keep
)
2325 ;; don't remove labels; use numbers for references when
2326 ;; lines are numbered, use labels otherwise
2327 (goto-char (match-beginning 2))
2328 (delete-region (match-beginning 2) (match-end 2))
2329 (insert "(" ref
")")
2330 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2331 org-export-code-refs
))
2333 ;; don't remove labels and don't use numbers for
2335 (goto-char (match-beginning 2))
2336 (delete-region (match-beginning 2) (match-end 2))
2337 (insert "(" ref
")")
2338 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2339 (when (eq backend
'html
)
2341 (beginning-of-line 1)
2342 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2345 (insert "</span>")))))
2346 (setq org-export-last-code-line-counter-value n
)
2347 (goto-char (point-max))
2351 (defun org-search-todo-below (line lines level
)
2352 "Search the subtree below LINE for any TODO entries."
2353 (let ((rest (cdr (memq line lines
)))
2354 (re org-todo-line-regexp
)
2357 (while (setq line
(pop rest
))
2358 (if (string-match re line
)
2360 (setq lv
(- (match-end 1) (match-beginning 1))
2361 todo
(and (match-beginning 2)
2362 (not (member (match-string 2 line
)
2363 org-done-keywords
))))
2365 (if (<= lv level
) (throw 'exit nil
))
2366 (if todo
(throw 'exit t
))))))))
2369 (defun org-export-visible (type arg
)
2370 "Create a copy of the visible part of the current buffer, and export it.
2371 The copy is created in a temporary buffer and removed after use.
2372 TYPE is the final key (as a string) that also select the export command in
2373 the `C-c C-e' export dispatcher.
2374 As a special case, if the you type SPC at the prompt, the temporary
2375 org-mode file will not be removed but presented to you so that you can
2376 continue to use it. The prefix arg ARG is passed through to the exporting
2380 (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")
2381 (read-char-exclusive))
2382 current-prefix-arg
))
2383 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L
)))
2384 (error "Invalid export key"))
2385 (let* ((binding (cdr (assoc type
2387 (?a . org-export-as-ascii
)
2388 (?A . org-export-as-ascii-to-buffer
)
2389 (?n . org-export-as-latin1
)
2390 (?N . org-export-as-latin1-to-buffer
)
2391 (?u . org-export-as-utf8
)
2392 (?U . org-export-as-utf8-to-buffer
)
2393 (?\C-a . org-export-as-ascii
)
2394 (?b . org-export-as-html-and-open
)
2395 (?\C-b . org-export-as-html-and-open
)
2396 (?h . org-export-as-html
)
2397 (?H . org-export-as-html-to-buffer
)
2398 (?R . org-export-region-as-html
)
2399 (?D . org-export-as-docbook
)
2401 (?l . org-export-as-latex
)
2402 (?p . org-export-as-pdf
)
2403 (?d . org-export-as-pdf-and-open
)
2404 (?L . org-export-as-latex-to-buffer
)
2406 (?x . org-export-as-xoxo
)))))
2407 (keepp (equal type ?\
))
2408 (file buffer-file-name
)
2409 (buffer (get-buffer-create "*Org Export Visible*"))
2411 ;; Need to hack the drawers here.
2413 (goto-char (point-min))
2414 (while (re-search-forward org-drawer-regexp nil t
)
2415 (goto-char (match-beginning 1))
2416 (or (org-invisible-p) (org-flag-drawer nil
))))
2417 (with-current-buffer buffer
(erase-buffer))
2419 (setq s
(goto-char (point-min)))
2420 (while (not (= (point) (point-max)))
2421 (goto-char (org-find-invisible))
2422 (append-to-buffer buffer s
(point))
2423 (setq s
(goto-char (org-find-visible))))
2424 (org-cycle-hide-drawers 'all
)
2425 (goto-char (point-min))
2427 ;; Copy all comment lines to the end, to make sure #+ settings are
2428 ;; still available for the second export step. Kind of a hack, but
2429 ;; does do the trick.
2430 (if (looking-at "#[^\r\n]*")
2431 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2432 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2433 (append-to-buffer buffer
(1+ (match-beginning 0))
2434 (min (point-max) (1+ (match-end 0))))))
2436 (let ((buffer-file-name file
)
2437 (org-inhibit-startup t
))
2440 (unless keepp
(funcall binding arg
))))
2442 (kill-buffer buffer
)
2443 (switch-to-buffer-other-window buffer
)
2444 (goto-char (point-min)))))
2446 (defun org-find-visible ()
2448 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2449 (get-char-property s
'invisible
)))
2451 (defun org-find-invisible ()
2453 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2454 (not (get-char-property s
'invisible
))))
2457 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2460 (defun org-export-as-org (arg &optional hidden ext-plist
2461 to-buffer body-only pub-dir
)
2462 "Make a copy with not-exporting stuff removed.
2463 The purpose of this function is to provide a way to export the source
2464 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2465 stuff removed. This command will remove the following:
2467 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2468 - comment blocks and trees starting with the COMMENT keyword
2469 - only trees that are consistent with `org-export-select-tags'
2470 and `org-export-exclude-tags'.
2472 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2473 all the others will be ignored (but are present so that the general
2474 mechanism to call publishing functions will work).
2476 EXT-PLIST is a property list with external parameters overriding
2477 org-mode's default settings, but still inferior to file-local
2478 settings. When PUB-DIR is set, use this as the publishing
2481 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2483 (org-infile-export-plist)))
2484 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2485 (filename (concat (file-name-as-directory
2487 (org-export-directory :org opt-plist
)))
2488 (file-name-sans-extension
2489 (file-name-nondirectory bfname
))
2491 (filename (and filename
2492 (if (equal (file-truename filename
)
2493 (file-truename bfname
))
2494 (concat (file-name-sans-extension filename
)
2496 (file-name-extension filename
))
2498 (backup-inhibited t
)
2499 (buffer (find-file-noselect filename
))
2500 (region (buffer-string))
2503 (switch-to-buffer buffer
)
2506 (let ((org-inhibit-startup t
)) (org-mode))
2507 (org-install-letbind)
2509 ;; Get rid of archived trees
2510 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2512 ;; Remove comment environment and comment subtrees
2513 (org-export-remove-comment-blocks-and-subtrees)
2515 ;; Get rid of excluded trees
2516 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2517 (plist-get opt-plist
:exclude-tags
))
2519 (when (or (plist-get opt-plist
:plain-source
)
2520 (not (or (plist-get opt-plist
:plain-source
)
2521 (plist-get opt-plist
:htmlized-source
))))
2522 ;; Either nothing special is requested (default call)
2523 ;; or the plain source is explicitly requested
2526 (when (plist-get opt-plist
:htmlized-source
)
2527 ;; Make the htmlized version
2530 (font-lock-fontify-buffer)
2531 (let* ((htmlize-output-type 'css
)
2532 (newbuf (htmlize-buffer)))
2533 (with-current-buffer newbuf
2534 (when org-export-htmlized-org-css-url
2535 (goto-char (point-min))
2536 (and (re-search-forward
2537 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2541 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2542 org-export-htmlized-org-css-url
)
2544 (write-file (concat filename
".html")))
2545 (kill-buffer newbuf
)))
2546 (set-buffer-modified-p nil
)
2547 (if (equal to-buffer
'string
)
2548 (progn (setq str-ret
(buffer-string))
2549 (kill-buffer (current-buffer))
2551 (kill-buffer (current-buffer))))))
2553 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2554 (defun org-get-current-options ()
2555 "Return a string with current options as keyword options.
2556 Does include HTML export options as well as TODO and CATEGORY stuff."
2557 (require 'org-archive
)
2566 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2567 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2569 #+EXPORT_SELECT_TAGS: %s
2570 #+EXPORT_EXCLUDE_TAGS: %s
2576 #+PRIORITIES: %c %c %c
2578 #+STARTUP: %s %s %s %s %s
2584 (buffer-name) (user-full-name) user-mail-address
2585 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2586 org-export-default-language
2587 org-export-headline-levels
2588 org-export-with-section-numbers
2590 org-export-preserve-breaks
2591 org-export-html-expand
2592 org-export-with-fixed-width
2593 org-export-with-tables
2594 org-export-with-sub-superscripts
2595 org-export-with-special-strings
2596 org-export-with-footnotes
2597 org-export-with-emphasize
2598 org-export-with-timestamps
2599 org-export-with-TeX-macros
2600 org-export-with-LaTeX-fragments
2601 org-export-skip-text-before-1st-heading
2602 org-export-with-drawers
2603 org-export-with-todo-keywords
2604 org-export-with-priority
2605 org-export-with-tags
2606 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2607 (mapconcat 'identity org-export-select-tags
" ")
2608 (mapconcat 'identity org-export-exclude-tags
" ")
2609 org-export-html-link-up
2610 org-export-html-link-home
2612 (file-name-sans-extension
2613 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2615 "TODO FEEDBACK VERIFY DONE"
2616 "Me Jason Marie DONE"
2617 org-highest-priority org-lowest-priority org-default-priority
2618 (mapconcat 'identity org-drawers
" ")
2619 (cdr (assoc org-startup-folded
2620 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2621 (if org-odd-levels-only
"odd" "oddeven")
2622 (if org-hide-leading-stars
"hidestars" "showstars")
2623 (if org-startup-align-all-tables
"align" "noalign")
2624 (cond ((eq org-log-done t
) "logdone")
2625 ((equal org-log-done
'note
) "lognotedone")
2626 ((not org-log-done
) "nologdone"))
2627 (or (mapconcat (lambda (x)
2629 ((equal :startgroup
(car x
)) "{")
2630 ((equal :endgroup
(car x
)) "}")
2631 ((equal :newline
(car x
)) "")
2632 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2634 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2635 (mapconcat 'identity org-file-tags
" ")
2636 org-archive-location
2637 "org file:~/org/%s.org"
2641 (defun org-insert-export-options-template ()
2642 "Insert into the buffer a template with information for exporting."
2644 (if (not (bolp)) (newline))
2645 (let ((s (org-get-current-options)))
2646 (and (string-match "#\\+CATEGORY" s
)
2647 (setq s
(substring s
0 (match-beginning 0))))
2650 (defvar org-table-colgroup-info nil
)
2652 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2653 "Check if the table has a marking column.
2654 If yes remove the column and the special lines."
2655 (setq org-table-colgroup-info nil
)
2658 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2661 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2662 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2665 ;; No special marking column
2667 (setq org-table-clean-did-remove-column nil
)
2672 ((org-table-colgroup-line-p x
)
2673 ;; This line contains colgroup info, extract it
2674 ;; and then discard the line
2675 (setq org-table-colgroup-info
2677 (cond ((member x
'("<" "<")) :start
)
2678 ((member x
'(">" ">")) :end
)
2679 ((member x
'("<>" "<>")) :startend
)
2681 (org-split-string x
"[ \t]*|[ \t]*")))
2683 ((org-table-cookie-line-p x
)
2684 ;; This line contains formatting cookies, discard it
2688 ;; there is a special marking column
2689 (setq org-table-clean-did-remove-column t
)
2694 ((org-table-colgroup-line-p x
)
2695 ;; This line contains colgroup info, extract it
2696 ;; and then discard the line
2697 (setq org-table-colgroup-info
2699 (cond ((member x
'("<" "<")) :start
)
2700 ((member x
'(">" ">")) :end
)
2701 ((member x
'("<>" "<>")) :startend
)
2703 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2705 ((org-table-cookie-line-p x
)
2706 ;; This line contains formatting cookies, discard it
2708 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2711 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2712 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2713 ;; remove the first column
2714 (replace-match "\\1|" t nil x
))))
2717 (defun org-export-cleanup-toc-line (s)
2718 "Remove tags and timestamps from lines going into the toc."
2719 (when (memq org-export-with-tags
'(not-in-toc nil
))
2720 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2721 (setq s
(replace-match "" t t s
))))
2722 (when org-export-remove-timestamps-from-toc
2723 (while (string-match org-maybe-keyword-time-regexp s
)
2724 (setq s
(replace-match "" t t s
))))
2725 (while (string-match org-bracket-link-regexp s
)
2726 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2728 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
2729 (setq s
(replace-match "" t t s
)))
2732 (defun org-create-multibrace-regexp (left right n
)
2733 "Create a regular expression which will match a balanced sexp.
2734 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2735 as single character strings.
2736 The regexp returned will match the entire expression including the
2737 delimiters. It will also define a single group which contains the
2738 match except for the outermost delimiters. The maximum depth of
2739 stacked delimiters is N. Escaping delimiters is not possible."
2740 (let* ((nothing (concat "[^" left right
"]*?"))
2743 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
2746 re
(concat re or next
)
2747 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
2748 (concat left
"\\(" re
"\\)" right
)))
2750 (defvar org-match-substring-regexp
2752 "\\([^\\]\\)\\([_^]\\)\\("
2753 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2755 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
2757 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2758 "The regular expression matching a sub- or superscript.")
2760 (defvar org-match-substring-with-braces-regexp
2762 "\\([^\\]\\)\\([_^]\\)\\("
2763 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2765 "The regular expression matching a sub- or superscript, forcing braces.")
2768 (defun org-get-text-property-any (pos prop
&optional object
)
2769 (or (get-text-property pos prop object
)
2770 (and (setq pos
(next-single-property-change pos prop object
))
2771 (get-text-property pos prop object
))))
2773 (defun org-export-get-coderef-format (path desc
)
2775 (if (and desc
(string-match
2776 (regexp-quote (concat "(" path
")"))
2778 (replace-match "%s" t t desc
)
2781 (defun org-export-push-to-kill-ring (format)
2782 "Push buffer content to kill ring.
2783 The depends on the variable `org-export-copy-to-kill'."
2784 (when org-export-copy-to-kill-ring
2785 (org-kill-new (buffer-string))
2786 (when (fboundp 'x-set-selection
)
2787 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
2788 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
2789 (message "%s export done, pushed to kill ring and clipboard" format
)))
2793 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2795 ;;; org-exp.el ends here