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-TeX-macros t
452 "Non-nil means interpret simple TeX-like macros when exporting.
453 For example, HTML export converts \\alpha to α and \\AA to Å.
454 Not only real TeX macros will work here, but the standard HTML entities
455 for math can be used as macro names as well. For a list of supported
456 names in HTML export, see the constant `org-entities' and the user option
458 Not all export backends support this.
460 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
461 :group
'org-export-translation
462 :group
'org-export-latex
465 (defcustom org-export-with-LaTeX-fragments nil
466 "Non-nil means convert LaTeX fragments to images when exporting to HTML.
467 When set, the exporter will find LaTeX environments if the \\begin line is
468 the first non-white thing on a line. It will also find the math delimiters
469 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
472 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
474 The default is nil, because this option needs the `dvipng' program which
475 is not available on all systems."
476 :group
'org-export-translation
477 :group
'org-export-latex
480 (defcustom org-export-with-fixed-width t
481 "Non-nil means lines starting with \":\" will be in fixed width font.
482 This can be used to have pre-formatted text, fragments of code etc. For
484 : ;; Some Lisp examples
487 will be looking just like this in also HTML. See also the QUOTE keyword.
488 Not all export backends support this.
490 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
491 :group
'org-export-translation
494 (defgroup org-export-tables nil
495 "Options for exporting tables in Org-mode."
496 :tag
"Org Export Tables"
499 (defcustom org-export-with-tables t
500 "If non-nil, lines starting with \"|\" define a table.
503 | Name | Address | Birthday |
504 |-------------+----------+-----------|
505 | Arthur Dent | England | 29.2.2100 |
507 Not all export backends support this.
509 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
510 :group
'org-export-tables
513 (defcustom org-export-highlight-first-table-line t
514 "Non-nil means highlight the first table line.
515 In HTML export, this means use <th> instead of <td>.
516 In tables created with table.el, this applies to the first table line.
517 In Org-mode tables, all lines before the first horizontal separator
518 line will be formatted with <th> tags."
519 :group
'org-export-tables
522 (defcustom org-export-table-remove-special-lines t
523 "Remove special lines and marking characters in calculating tables.
524 This removes the special marking character column from tables that are set
525 up for spreadsheet calculations. It also removes the entire lines
526 marked with `!', `_', or `^'. The lines with `$' are kept, because
527 the values of constants may be useful to have."
528 :group
'org-export-tables
531 (defcustom org-export-prefer-native-exporter-for-tables nil
532 "Non-nil means always export tables created with table.el natively.
533 Natively means use the HTML code generator in table.el.
534 When nil, Org-mode's own HTML generator is used when possible (i.e. if
535 the table does not use row- or column-spanning). This has the
536 advantage, that the automatic HTML conversions for math symbols and
537 sub/superscripts can be applied. Org-mode's HTML generator is also
538 much faster. The LaTeX exporter always use the native exporter for
540 :group
'org-export-tables
544 (defgroup org-export-xml nil
545 "Options specific for XML export of Org-mode files."
546 :tag
"Org Export XML"
551 ;;; Variables, constants, and parameter plists
553 (defconst org-level-max
20)
555 (defvar org-current-export-file nil
) ; dynamically scoped parameter
556 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
557 (defvar org-export-opt-plist nil
558 "Contains the current option plist.")
559 (defvar org-last-level nil
) ; dynamically scoped variable
560 (defvar org-min-level nil
) ; dynamically scoped variable
561 (defvar org-levels-open nil
) ; dynamically scoped parameter
563 (defconst org-export-plist-vars
564 '((:link-up nil org-export-html-link-up
)
565 (:link-home nil org-export-html-link-home
)
566 (:language nil org-export-default-language
)
567 (:keywords nil org-export-page-keywords
)
568 (:description nil org-export-page-description
)
569 (:customtime nil org-display-custom-times
)
570 (:headline-levels
"H" org-export-headline-levels
)
571 (:section-numbers
"num" org-export-with-section-numbers
)
572 (:section-number-format nil org-export-section-number-format
)
573 (:table-of-contents
"toc" org-export-with-toc
)
574 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
575 (:archived-trees nil org-export-with-archived-trees
)
576 (:emphasize
"*" org-export-with-emphasize
)
577 (:sub-superscript
"^" org-export-with-sub-superscripts
)
578 (:special-strings
"-" org-export-with-special-strings
)
579 (:footnotes
"f" org-export-with-footnotes
)
580 (:drawers
"d" org-export-with-drawers
)
581 (:tags
"tags" org-export-with-tags
)
582 (:todo-keywords
"todo" org-export-with-todo-keywords
)
583 (:priority
"pri" org-export-with-priority
)
584 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
585 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
586 (:latex-listings nil org-export-latex-listings
)
587 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
588 (:fixed-width
":" org-export-with-fixed-width
)
589 (:timestamps
"<" org-export-with-timestamps
)
590 (:author-info
"author" org-export-author-info
)
591 (:email-info
"email" org-export-email-info
)
592 (:creator-info
"creator" org-export-creator-info
)
593 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
594 (:tables
"|" org-export-with-tables
)
595 (:table-auto-headline nil org-export-highlight-first-table-line
)
596 (:style-include-default nil org-export-html-style-include-default
)
597 (:style-include-scripts nil org-export-html-style-include-scripts
)
598 (:style nil org-export-html-style
)
599 (:style-extra nil org-export-html-style-extra
)
600 (:agenda-style nil org-agenda-export-html-style
)
601 (:convert-org-links nil org-export-html-link-org-files-as-html
)
602 (:inline-images nil org-export-html-inline-images
)
603 (:html-extension nil org-export-html-extension
)
604 (:xml-declaration nil org-export-html-xml-declaration
)
605 (:html-table-tag nil org-export-html-table-tag
)
606 (:expand-quoted-html
"@" org-export-html-expand
)
607 (:timestamp nil org-export-html-with-timestamp
)
608 (:publishing-directory nil org-export-publishing-directory
)
609 (:preamble nil org-export-html-preamble
)
610 (:postamble nil org-export-html-postamble
)
611 (:auto-preamble nil org-export-html-auto-preamble
)
612 (:auto-postamble nil org-export-html-auto-postamble
)
613 (:author nil user-full-name
)
614 (:email nil user-mail-address
)
615 (:select-tags nil org-export-select-tags
)
616 (:exclude-tags nil org-export-exclude-tags
)
618 (:latex-image-options nil org-export-latex-image-default-option
))
619 "List of properties that represent export/publishing variables.
620 Each element is a list of 3 items:
621 1. The property that is used internally, and also for org-publish-project-alist
622 2. The string that can be used in the OPTION lines to set this option,
623 or nil if this option cannot be changed in this way
624 3. The customization variable that sets the default for this option."
627 (defun org-default-export-plist ()
628 "Return the property list with default settings for the export variables."
629 (let* ((infile (org-infile-export-plist))
630 (letbind (plist-get infile
:let-bind
))
631 (l org-export-plist-vars
) rtn e s v
)
632 (while (setq e
(pop l
))
635 ((assq s letbind
) (nth 1 (assq s letbind
)))
636 ((boundp s
) (symbol-value s
))
638 rtn
(cons (car e
) (cons v rtn
))))
641 (defvar org-export-inbuffer-options-extra nil
642 "List of additional in-buffer options that should be detected.
643 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
644 etc. Extensions can add to this list to get their options detected, and they
645 can then add a function to `org-export-options-filters' to process these
647 Each element in this list must be a list, with the in-buffer keyword as car,
648 and a property (a symbol) as the next element. All occurrences of the
649 keyword will be found, the values concatenated with a space character
650 in between, and the result stored in the export options property list.")
652 (defvar org-export-options-filters nil
653 "Functions to be called to finalize the export/publishing options.
654 All these options are stored in a property list, and each of the functions
655 in this hook gets a chance to modify this property list. Each function
656 must accept the property list as an argument, and must return the (possibly
659 ;; FIXME: should we fold case here?
660 (defun org-infile-export-plist ()
661 "Return the property list with file-local settings for export."
665 (goto-char (point-min))
666 (let ((re (org-make-options-regexp
668 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
669 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
670 "LATEX_HEADER" "LATEX_CLASS"
671 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
672 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
673 (mapcar 'car org-export-inbuffer-options-extra
))))
674 p key val text options a pr style
675 latex-header latex-class macros letbind
676 ext-setup-or-nil setup-contents
(start 0))
677 (while (or (and ext-setup-or-nil
678 (string-match re ext-setup-or-nil start
)
679 (setq start
(match-end 0)))
680 (and (setq ext-setup-or-nil nil start
0)
681 (re-search-forward re nil t
)))
682 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
683 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
685 ((setq a
(assoc key org-export-inbuffer-options-extra
))
687 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
688 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
689 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
690 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
691 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
692 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
693 ((string-equal key
"DESCRIPTION")
694 (setq p
(plist-put p
:description val
)))
695 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
696 ((string-equal key
"STYLE")
697 (setq style
(concat style
"\n" val
)))
698 ((string-equal key
"LATEX_HEADER")
699 (setq latex-header
(concat latex-header
"\n" val
)))
700 ((string-equal key
"LATEX_CLASS")
701 (setq latex-class val
))
702 ((string-equal key
"TEXT")
703 (setq text
(if text
(concat text
"\n" val
) val
)))
704 ((string-equal key
"OPTIONS")
705 (setq options
(concat val
" " options
)))
706 ((string-equal key
"BIND")
707 (push (read (concat "(" val
")")) letbind
))
708 ((string-equal key
"XSLT")
709 (setq p
(plist-put p
:xslt val
)))
710 ((string-equal key
"LINK_UP")
711 (setq p
(plist-put p
:link-up val
)))
712 ((string-equal key
"LINK_HOME")
713 (setq p
(plist-put p
:link-home val
)))
714 ((string-equal key
"EXPORT_SELECT_TAGS")
715 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
716 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
717 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
718 ((string-equal key
"MACRO")
720 ((equal key
"SETUPFILE")
721 (setq setup-contents
(org-file-contents
723 (org-remove-double-quotes
726 (if (not ext-setup-or-nil
)
727 (setq ext-setup-or-nil setup-contents start
0)
728 (setq ext-setup-or-nil
729 (concat (substring ext-setup-or-nil
0 start
)
730 "\n" setup-contents
"\n"
731 (substring ext-setup-or-nil start
)))))))
732 (setq p
(plist-put p
:text text
))
733 (when (and letbind
(org-export-confirm-letbind))
734 (setq p
(plist-put p
:let-bind letbind
)))
735 (when style
(setq p
(plist-put p
:style-extra style
)))
737 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
739 (setq p
(plist-put p
:latex-class latex-class
)))
741 (setq p
(org-export-add-options-to-plist p options
)))
742 ;; Add macro definitions
743 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
744 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
746 p
:macro-modification-time
747 (and (buffer-file-name)
748 (file-exists-p (buffer-file-name))
750 "(eval (format-time-string \"$1\" '"
751 (prin1-to-string (nth 5 (file-attributes
752 (buffer-file-name))))
754 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
755 (file-name-nondirectory
756 (buffer-file-name)))))
757 (while (setq val
(pop macros
))
758 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
761 (concat ":macro-" (downcase (match-string 1 val
))))
762 (org-export-interpolate-newlines (match-string 2 val
))))))
765 (defun org-export-interpolate-newlines (s)
766 (while (string-match "\\\\n" s
)
767 (setq s
(replace-match "\n" t t s
)))
770 (defvar org-export-allow-BIND-local nil
)
771 (defun org-export-confirm-letbind ()
772 "Can we use #+BIND values during export?
773 By default this will ask fro confirmation by the user, to divert possible
776 ((not org-export-allow-BIND
) nil
)
777 ((eq org-export-allow-BIND t
) t
)
778 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
779 org-export-allow-BIND-local
)
780 (t (org-set-local 'org-export-allow-BIND-local
781 (yes-or-no-p "Allow BIND values in this buffer? ")))))
783 (defun org-install-letbind ()
784 "Install the values from #+BIND lines as local variables."
785 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
787 (while (setq pair
(pop letbind
))
788 (org-set-local (car pair
) (nth 1 pair
)))))
790 (defun org-export-add-options-to-plist (p options
)
791 "Parse an OPTIONS line and set values in the property list P."
794 (let ((op org-export-plist-vars
))
795 (while (setq o
(pop op
))
797 (string-match (concat (regexp-quote (nth 1 o
))
798 ":\\([^ \t\n\r;,.]*\\)")
800 (setq p
(plist-put p
(car o
)
801 (car (read-from-string
802 (match-string 1 options
))))))))))
805 (defun org-export-add-subtree-options (p pos
)
806 "Add options in subtree at position POS to property list P."
809 (when (org-at-heading-p)
811 ;; This is actually read in `org-export-get-title-from-subtree'
812 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
813 ;; (setq p (plist-put p :title a)))
814 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
815 (setq p
(plist-put p
:text a
)))
816 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
817 (setq p
(plist-put p
:author a
)))
818 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
819 (setq p
(plist-put p
:date a
)))
820 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
821 (setq p
(org-export-add-options-to-plist p a
)))))
824 (defun org-export-directory (type plist
)
825 (let* ((val (plist-get plist
:publishing-directory
))
827 (or (cdr (assoc type val
)) ".")
831 (defun org-export-process-option-filters (plist)
832 (let ((functions org-export-options-filters
) f
)
833 (while (setq f
(pop functions
))
834 (setq plist
(funcall f plist
))))
838 (defun org-export (&optional arg
)
839 "Export dispatcher for Org-mode.
840 When `org-export-run-in-background' is non-nil, try to run the command
841 in the background. This will be done only for commands that write
842 to a file. For details see the docstring of `org-export-run-in-background'.
844 The prefix argument ARG will be passed to the exporter. However, if
845 ARG is a double universal prefix `C-u C-u', that means to inverse the
846 value of `org-export-run-in-background'."
848 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
850 (help "[t] insert the export option template
851 \[v] limit export to visible part of outline tree
852 \[1] only export the current subtree
853 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
855 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
857 \[h] export as HTML [H] to temporary buffer [R] export region
858 \[b] export as HTML and open in browser
860 \[l] export as LaTeX [L] to temporary buffer
861 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
863 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
865 \[j] export as TaskJuggler [J] ... and open
867 \[m] export as Freemind mind map
869 \[g] export using Wes Hardaker's generic exporter
871 \[i] export current file as iCalendar file
872 \[I] export all agenda files as iCalendar files [c] ...as one combined file
874 \[F] publish current file [P] publish current project
875 \[X] publish a project... [E] publish every projects")
877 '((?t org-insert-export-options-template nil
)
878 (?v org-export-visible nil
)
879 (?a org-export-as-ascii t
)
880 (?A org-export-as-ascii-to-buffer t
)
881 (?n org-export-as-latin1 t
)
882 (?N org-export-as-latin1-to-buffer t
)
883 (?u org-export-as-utf8 t
)
884 (?U org-export-as-utf8-to-buffer t
)
885 (?h org-export-as-html t
)
886 (?b org-export-as-html-and-open t
)
887 (?H org-export-as-html-to-buffer nil
)
888 (?R org-export-region-as-html nil
)
889 (?x org-export-as-xoxo t
)
890 (?g org-export-generic t
)
891 (?D org-export-as-docbook t
)
892 (?V org-export-as-docbook-pdf-and-open t
)
893 (?j org-export-as-taskjuggler t
)
894 (?J org-export-as-taskjuggler-and-open t
)
895 (?m org-export-as-freemind t
)
896 (?l org-export-as-latex t
)
897 (?p org-export-as-pdf t
)
898 (?d org-export-as-pdf-and-open t
)
899 (?L org-export-as-latex-to-buffer nil
)
900 (?i org-export-icalendar-this-file t
)
901 (?I org-export-icalendar-all-agenda-files t
)
902 (?c org-export-icalendar-combine-agenda-files t
)
903 (?F org-publish-current-file t
)
904 (?P org-publish-current-project t
)
906 (?E org-publish-all t
)))
908 (cpos (point)) (cbuf (current-buffer)) bpos
)
910 (save-window-excursion
911 (delete-other-windows)
912 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
914 (org-fit-window-to-buffer (get-buffer-window
915 "*Org Export/Publishing Help*"))
916 (message "Select command: ")
917 (setq r1
(read-char-exclusive))
920 (message "Select command (for subtree): ")
921 (setq r1
(read-char-exclusive)))
923 (let ((case-fold-search t
))
924 (if (re-search-backward
925 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
928 (org-back-to-heading t
)
931 (message "Select command (for subtree): ")
932 (setq r1
(read-char-exclusive)))
933 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
935 (and bpos
(goto-char bpos
))
936 (setq r2
(if (< r1
27) (+ r1
96) r1
))
937 (unless (setq ass
(assq r2 cmds
))
938 (error "No command associated with key %c" r1
))
939 (if (and bg
(nth 2 ass
)
940 (not (buffer-base-buffer))
941 (not (org-region-active-p)))
942 ;; execute in background
943 (let ((p (start-process
944 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
946 (expand-file-name invocation-name invocation-directory
)
949 "--eval" "(require 'org-exp)"
950 "--eval" "(setq org-wait .2)"
952 "-f" (symbol-name (nth 1 ass
)))))
953 (set-process-sentinel p
'org-export-process-sentinel
)
954 (message "Background process \"%s\": started" p
))
955 ;; background processing not requested, or not possible
956 (if subtree-p
(progn (outline-mark-subtree) (activate-mark)))
957 (call-interactively (nth 1 ass
))
958 (when (and bpos
(get-buffer-window cbuf
))
959 (let ((cw (selected-window)))
960 (select-window (get-buffer-window cbuf
))
963 (select-window cw
))))))
965 (defun org-export-process-sentinel (process status
)
966 (if (string-match "\n+\\'" status
)
967 (setq status
(substring status
0 -
1)))
968 (message "Background process \"%s\": %s" process status
))
970 ;;; General functions for all backends
972 (defvar org-export-target-aliases nil
973 "Alist of targets with invisible aliases.")
974 (defvar org-export-preferred-target-alist nil
975 "Alist of section id's with preferred aliases.")
976 (defvar org-export-id-target-alist nil
977 "Alist of section id's with preferred aliases.")
978 (defvar org-export-code-refs nil
979 "Alist of code references and line numbers")
981 (defun org-export-preprocess-string (string &rest parameters
)
982 "Cleanup STRING so that that the true exported has a more consistent source.
983 This function takes STRING, which should be a buffer-string of an org-file
984 to export. It then creates a temporary buffer where it does its job.
985 The result is then again returned as a string, and the exporter works
986 on this string to produce the exported version."
988 (let* ((htmlp (plist-get parameters
:for-html
))
989 (asciip (plist-get parameters
:for-ascii
))
990 (latexp (plist-get parameters
:for-LaTeX
))
991 (docbookp (plist-get parameters
:for-docbook
))
992 (backend (cond (htmlp 'html
)
995 (docbookp 'docbook
)))
996 (archived-trees (plist-get parameters
:archived-trees
))
997 (inhibit-read-only t
)
998 (drawers org-drawers
)
999 (outline-regexp "\\*+ ")
1002 (setq org-export-target-aliases nil
1003 org-export-preferred-target-alist nil
1004 org-export-id-target-alist nil
1005 org-export-code-refs nil
)
1007 (with-current-buffer (get-buffer-create " org-mode-tmp")
1010 (setq case-fold-search t
)
1012 (let ((inhibit-read-only t
))
1013 (remove-text-properties (point-min) (point-max)
1016 ;; Remove license-to-kill stuff
1017 ;; The caller marks some stuff for killing, stuff that has been
1018 ;; used to create the page title, for example.
1019 (org-export-kill-licensed-text)
1021 (let ((org-inhibit-startup t
)) (org-mode))
1022 (setq case-fold-search t
)
1023 (org-install-letbind)
1026 (run-hooks 'org-export-preprocess-hook
)
1028 ;; Process the macros
1029 (org-export-preprocess-apply-macros)
1030 (run-hooks 'org-export-preprocess-after-macros-hook
)
1032 (untabify (point-min) (point-max))
1034 ;; Handle include files, and call a hook
1035 (org-export-handle-include-files-recurse)
1036 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1038 ;; Get rid of archived trees
1039 (org-export-remove-archived-trees archived-trees
)
1041 ;; Remove comment environment and comment subtrees
1042 (org-export-remove-comment-blocks-and-subtrees)
1044 ;; Get rid of excluded trees, and call a hook
1045 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1046 (plist-get parameters
:exclude-tags
))
1047 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1049 ;; Handle source code snippets
1050 (org-export-replace-src-segments-and-examples backend
)
1052 ;; Protect short examples marked by a leading colon
1053 (org-export-protect-colon-examples)
1055 ;; Normalize footnotes
1056 (when (plist-get parameters
:footnotes
)
1057 (org-footnote-normalize nil t
))
1059 ;; Find all headings and compute the targets for them
1060 (setq target-alist
(org-export-define-heading-targets target-alist
))
1062 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1064 ;; Find HTML special classes for headlines
1065 (org-export-remember-html-container-classes)
1067 ;; Get rid of drawers
1068 (org-export-remove-or-extract-drawers
1069 drawers
(plist-get parameters
:drawers
) backend
)
1071 ;; Get the correct stuff before the first headline
1072 (when (plist-get parameters
:skip-before-1st-heading
)
1073 (goto-char (point-min))
1074 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1075 (delete-region (point-min) (match-beginning 0))
1076 (goto-char (point-min))
1078 (when (plist-get parameters
:add-text
)
1079 (goto-char (point-min))
1080 (insert (plist-get parameters
:add-text
) "\n"))
1082 ;; Remove todo-keywords before exporting, if the user has requested so
1083 (org-export-remove-headline-metadata parameters
)
1085 ;; Find targets in comments and move them out of comments,
1086 ;; but mark them as targets that should be invisible
1087 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1089 ;; Select and protect backend specific stuff, throw away stuff
1090 ;; that is specific for other backends
1091 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1092 (org-export-select-backend-specific-text backend
)
1094 ;; Protect quoted subtrees
1095 (org-export-protect-quoted-subtrees)
1097 ;; Remove clock lines
1098 (org-export-remove-clock-lines)
1100 ;; Protect verbatim elements
1101 (org-export-protect-verbatim)
1103 ;; Blockquotes, verse, and center
1104 (org-export-mark-blockquote-verse-center)
1105 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1107 ;; Remove timestamps, if the user has requested so
1108 (unless (plist-get parameters
:timestamps
)
1109 (org-export-remove-timestamps))
1111 ;; Attach captions to the correct object
1112 (setq target-alist
(org-export-attach-captions-and-attributes
1113 backend target-alist
))
1115 ;; Find matches for radio targets and turn them into internal links
1116 (org-export-mark-radio-links)
1118 ;; Find all links that contain a newline and put them into a single line
1119 (org-export-concatenate-multiline-links)
1121 ;; Normalize links: Convert angle and plain links into bracket links
1122 ;; and expand link abbreviations
1123 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1124 (org-export-normalize-links)
1126 ;; Find all internal links. If they have a fuzzy match (i.e. not
1127 ;; a *dedicated* target match, let the link point to the
1128 ;; corresponding section.
1129 (org-export-target-internal-links target-alist
)
1131 ;; Find multiline emphasis and put them into single line
1132 (when (plist-get parameters
:emph-multiline
)
1133 (org-export-concatenate-multiline-emphasis))
1135 ;; Remove special table lines
1136 (when org-export-table-remove-special-lines
1137 (org-export-remove-special-table-lines))
1140 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1142 ;; LaTeX-specific preprocessing
1144 (require 'org-latex nil
)
1145 (org-export-latex-preprocess parameters
))
1147 ;; ASCII-specific preprocessing
1149 (org-export-ascii-preprocess parameters
))
1151 ;; HTML-specific preprocessing
1153 (org-export-html-preprocess parameters
))
1155 ;; DocBook-specific preprocessing
1157 (require 'org-docbook nil
)
1158 (org-export-docbook-preprocess parameters
))
1160 ;; Remove or replace comments
1161 (org-export-handle-comments (plist-get parameters
:comments
))
1163 ;; Run the final hook
1164 (run-hooks 'org-export-preprocess-final-hook
)
1166 (setq rtn
(buffer-string)))
1167 (kill-buffer " org-mode-tmp")
1170 (defun org-export-kill-licensed-text ()
1171 "Remove all text that is marked with a :org-license-to-kill property."
1173 (while (setq p
(text-property-any (point-min) (point-max)
1174 :org-license-to-kill t
))
1176 p
(or (next-single-property-change p
:org-license-to-kill
)
1179 (defun org-export-define-heading-targets (target-alist)
1180 "Find all headings and define the targets for them.
1181 The new targets are added to TARGET-ALIST, which is also returned.
1182 Also find all ID and CUSTOM_ID propertiess and store them."
1183 (goto-char (point-min))
1184 (org-init-section-numbers)
1185 (let ((re (concat "^" org-outline-regexp
1187 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1188 level target last-section-target a id
)
1189 (while (re-search-forward re nil t
)
1190 (org-if-unprotected-at (match-beginning 0)
1193 (setq id
(org-match-string-no-properties 2))
1194 (push (cons id target
) target-alist
)
1195 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1197 (push (list last-section-target
)
1198 org-export-target-aliases
)
1199 (car org-export-target-aliases
))))
1200 (push (caar target-alist
) (cdr a
))
1201 (when (equal (match-string 1) "CUSTOM_ID")
1202 (if (not (assoc last-section-target
1203 org-export-preferred-target-alist
))
1204 (push (cons last-section-target id
)
1205 org-export-preferred-target-alist
)))
1206 (when (equal (match-string 1) "ID")
1207 (if (not (assoc last-section-target
1208 org-export-id-target-alist
))
1209 (push (cons last-section-target
(concat "ID-" id
))
1210 org-export-id-target-alist
))))
1211 (setq level
(org-reduced-level
1212 (save-excursion (goto-char (point-at-bol))
1213 (org-outline-level))))
1214 (setq target
(org-solidify-link-text
1215 (format "sec-%s" (replace-regexp-in-string
1217 (org-section-number level
)))))
1218 (setq last-section-target target
)
1219 (push (cons target target
) target-alist
)
1220 (add-text-properties
1221 (point-at-bol) (point-at-eol)
1222 (list 'target target
))))))
1225 (defun org-export-handle-invisible-targets (target-alist)
1226 "Find targets in comments and move them out of comments.
1227 Mark them as invisible targets."
1229 (goto-char (point-min))
1230 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1231 ;; Check if the line before or after is a headline with a target
1232 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1233 (get-text-property (point-at-bol 2) 'target
)))
1235 ;; use the existing target in a neighboring line
1236 (setq tmp
(match-string 2))
1238 (and (looking-at "\n") (delete-char 1))
1239 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1241 (setq a
(or (assoc target org-export-target-aliases
)
1243 (push (list target
) org-export-target-aliases
)
1244 (car org-export-target-aliases
))))
1246 ;; Make an invisible target
1247 (replace-match "\\1(INVISIBLE)"))))
1250 (defun org-export-target-internal-links (target-alist)
1251 "Find all internal links and assign targets to them.
1252 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1253 let the link point to the corresponding section.
1254 This function also handles the id links, if they have a match in
1256 (goto-char (point-min))
1257 (while (re-search-forward org-bracket-link-regexp nil t
)
1258 (org-if-unprotected-at (1+ (match-beginning 0))
1259 (let* ((md (match-data))
1260 (desc (match-end 2))
1261 (link (org-link-unescape (match-string 1)))
1262 (slink (org-solidify-link-text link
))
1263 found props pos cref
1266 ((= (string-to-char link
) ?
#)
1267 ;; user wants exactly this link
1269 ((cdr (assoc slink target-alist
))
1270 (or (cdr (assoc (assoc slink target-alist
)
1271 org-export-preferred-target-alist
))
1272 (cdr (assoc slink target-alist
))))
1273 ((and (string-match "^id:" link
)
1274 (cdr (assoc (substring link
3) target-alist
))))
1275 ((string-match "^(\\(.*\\))$" link
)
1276 (setq cref
(match-string 1 link
))
1277 (concat "coderef:" cref
))
1278 ((string-match org-link-types-re link
) nil
)
1279 ((or (file-name-absolute-p link
)
1280 (string-match "^\\." link
))
1284 (setq found
(condition-case nil
(org-link-search link
)
1287 (or (org-on-heading-p)
1288 (not (eq found
'dedicated
))))
1289 (or (get-text-property (point) 'target
)
1292 (1- (or (previous-single-property-change
1293 (point) 'target
) 0)))
1297 (goto-char (match-beginning 1))
1298 (setq props
(text-properties-at (point)))
1299 (delete-region (match-beginning 1) (match-end 1))
1302 (unless desc
(insert "][" link
))
1303 (add-text-properties pos
(point) props
))))))
1305 (defun org-export-remember-html-container-classes ()
1306 "Store the HTML_CONTAINER_CLASS properties in a text property."
1307 (goto-char (point-min))
1309 (while (re-search-forward
1310 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(\\S-+\\)" nil t
)
1311 (setq class
(match-string 1))
1313 (org-back-to-heading t
)
1314 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1316 (defvar org-export-format-drawer-function nil
1317 "Function to be called to format the contents of a drawer.
1318 The function must accept three parameters:
1319 NAME the drawer name, like \"PROPERTIES\"
1320 CONTENT the content of the drawer.
1321 BACKEND one of the symbols html, docbook, latex, ascii, xoxo
1322 The function should return the text to be inserted into the buffer.
1323 If this is nil, `org-export-format-drawer' is used as a default.")
1325 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend
)
1326 "Remove drawers, or extract and format the content.
1327 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1328 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1329 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1330 EXP-DRAWERS will be removed.
1331 BACKEND is the current export backend."
1332 (goto-char (point-min))
1333 (let ((re (concat "^[ \t]*:\\("
1334 (mapconcat 'identity all-drawers
"\\|")
1336 name beg beg-content eol content
)
1337 (while (re-search-forward re nil t
)
1339 (setq name
(match-string 1))
1340 (setq beg
(match-beginning 0)
1341 beg-content
(1+ (point-at-eol))
1343 (if (not (and (re-search-forward
1344 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1347 (goto-char (match-beginning 0))
1348 (and (looking-at ".*\n?") (replace-match ""))
1349 (setq content
(buffer-substring beg-content
(point)))
1350 (delete-region beg
(point))
1351 (when (or (eq exp-drawers t
)
1352 (member name exp-drawers
))
1353 (setq content
(funcall (or org-export-format-drawer-function
1354 'org-export-format-drawer
)
1355 name content backend
))
1356 (insert content
)))))))
1358 (defun org-export-format-drawer (name content backend
)
1359 "Format the content of a drawer as a colon example."
1360 (if (string-match "[ \t]+\\'" content
)
1361 (setq content
(substring content
(match-beginning 0))))
1362 (while (string-match "\\`[ \t]*\n" content
)
1363 (setq content
(substring content
(match-end 0))))
1364 (setq content
(org-remove-indentation content
))
1365 (setq content
(concat ": " (mapconcat 'identity
1366 (org-split-string content
"\n")
1369 (setq content
(concat " : " (upcase name
) "\n" content
))
1370 (org-add-props content nil
'org-protected t
))
1372 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1373 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1374 Both arguments are lists of tags.
1375 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1377 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1379 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1380 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1383 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1387 (goto-char (point-min))
1388 (when (and select-tags
1390 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1391 ;; At least one tree is marked for export, this means
1392 ;; all the unmarked stuff needs to go.
1393 ;; Dig out the trees that should be exported
1394 (goto-char (point-min))
1395 (outline-next-heading)
1397 (put-text-property beg
(point-max) :org-delete t
)
1398 (while (re-search-forward re-sel nil t
)
1399 (when (org-on-heading-p)
1400 (org-back-to-heading)
1401 (remove-text-properties
1402 (max (1- (point)) (point-min))
1403 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1405 (while (and (org-up-heading-safe)
1406 (get-text-property (point) :org-delete
))
1407 (remove-text-properties (max (1- (point)) (point-min))
1408 (point-at-eol) '(:org-delete t
)))
1410 ;; Remove the trees explicitly marked for noexport
1412 (goto-char (point-min))
1413 (while (re-search-forward re-excl nil t
)
1414 (when (org-at-heading-p)
1415 (org-back-to-heading t
)
1417 (org-end-of-subtree t t
)
1418 (delete-region beg
(point))
1419 (when (featurep 'org-inlinetask
)
1420 (org-inlinetask-remove-END-maybe)))))
1421 ;; Remove everything that is now still marked for deletion
1422 (goto-char (point-min))
1423 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1424 (setq end
(or (next-single-property-change beg
:org-delete
)
1426 (delete-region beg end
))))
1428 (defun org-export-remove-archived-trees (export-archived-trees)
1429 "Remove archived trees.
1430 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1431 When it is t, the entire archived tree will be exported.
1432 When it is nil the entire tree including the headline will be removed
1434 (let ((re-archive (concat ":" org-archive-tag
":"))
1436 (when (not (eq export-archived-trees t
))
1437 (goto-char (point-min))
1438 (while (re-search-forward re-archive nil t
)
1439 (if (not (org-on-heading-p t
))
1440 (org-end-of-subtree t
)
1441 (beginning-of-line 1)
1442 (setq a
(if export-archived-trees
1443 (1+ (point-at-eol)) (point))
1444 b
(org-end-of-subtree t
))
1445 (if (> b a
) (delete-region a b
)))))))
1447 (defun org-export-remove-headline-metadata (opts)
1448 "Remove meta data from the headline, according to user options."
1449 (let ((re org-complex-heading-regexp
)
1450 (todo (plist-get opts
:todo-keywords
))
1451 (tags (plist-get opts
:tags
))
1452 (pri (plist-get opts
:priority
))
1455 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1456 (when (or (not todo
) (not tags
) (not pri
))
1457 (goto-char (point-min))
1458 (while (re-search-forward re nil t
)
1460 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1462 (replace-match rpl t t
))))))
1464 (defun org-export-remove-timestamps ()
1465 "Remove timestamps and keywords for export."
1466 (goto-char (point-min))
1467 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1470 (unless (save-match-data (org-at-table-p))
1472 (beginning-of-line 1)
1473 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1474 (replace-match ""))))))
1476 (defun org-export-remove-clock-lines ()
1477 "Remove clock lines for export."
1478 (goto-char (point-min))
1479 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1480 (while (re-search-forward re nil t
)
1482 (replace-match "")))))
1484 (defun org-export-protect-quoted-subtrees ()
1485 "Mark quoted subtrees with the protection property."
1486 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1487 (goto-char (point-min))
1488 (while (re-search-forward re-quote nil t
)
1489 (goto-char (match-beginning 0))
1491 (add-text-properties (point) (org-end-of-subtree t
)
1492 '(org-protected t
)))))
1494 (defun org-export-protect-verbatim ()
1495 "Mark verbatim snippets with the protection property."
1496 (goto-char (point-min))
1497 (while (re-search-forward org-verbatim-re nil t
)
1499 (add-text-properties (match-beginning 4) (match-end 4)
1500 '(org-protected t org-verbatim-emph t
))
1501 (goto-char (1+ (match-end 4))))))
1503 (defun org-export-protect-colon-examples ()
1504 "Protect lines starting with a colon."
1505 (goto-char (point-min))
1506 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1507 (while (re-search-forward re nil t
)
1508 (beginning-of-line 1)
1510 (while (looking-at re
)
1512 (or (eobp) (forward-char 1)))
1513 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1514 '(org-protected t
)))))
1516 (defun org-export-select-backend-specific-text (backend)
1518 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1519 (html "HTML" "BEGIN_HTML" "END_HTML")
1520 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1521 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1522 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1523 (case-fold-search t
)
1524 fmt beg beg-content end end-content
)
1527 (setq fmt
(pop formatters
))
1528 (when (eq (car fmt
) backend
)
1529 ;; This is selected code, put it into the file for real
1530 (goto-char (point-min))
1531 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1532 ":[ \t]*\\(.*\\)") nil t
)
1533 (replace-match "\\1\\2" t
)
1534 (add-text-properties
1535 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1536 '(org-protected t
))))
1537 (goto-char (point-min))
1538 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt
) "\\>.*\n?")
1540 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1541 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt
) "\\>.*\n?")
1543 (setq end
(match-end 0) end-content
(match-beginning 0))
1544 (if (eq (car fmt
) backend
)
1547 (add-text-properties beg-content end-content
'(org-protected t
))
1548 (delete-region (match-beginning 0) (match-end 0))
1551 (delete-region (point) (1+ (point-at-eol)))))
1552 ;; No, this is for a different backend, kill it
1553 (delete-region beg end
)))))))
1555 (defun org-export-mark-blockquote-verse-center ()
1556 "Mark block quote and verse environments with special cookies.
1557 These special cookies will later be interpreted by the backend."
1559 (let (type t1 ind beg end beg1 end1 content
)
1560 (goto-char (point-min))
1561 (while (re-search-forward
1562 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1564 (setq ind
(length (match-string 1))
1565 type
(downcase (match-string 3))
1566 t1
(if (equal type
"quote") "blockquote" type
))
1567 (setq beg
(match-beginning 0)
1568 beg1
(1+ (match-end 0)))
1569 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1570 (setq end
(+ (point-at-eol) (if (looking-at "\n$") 1 0))
1571 end1
(1- (match-beginning 0)))
1572 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1573 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1575 "ORG-" (upcase t1
) "-END\n"))
1576 (delete-region beg end
)
1577 (insert (org-add-props content nil
'original-indentation ind
))))))
1579 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1580 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1581 If the next thing following is a table, add the text properties to the first
1582 table line. If it is a link, add it to the line containing the link."
1583 (goto-char (point-min))
1584 (remove-text-properties (point-min) (point-max)
1585 '(org-caption nil org-attributes nil
))
1586 (let ((case-fold-search t
)
1587 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1589 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1591 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1593 "^[ \t]*\\(|[^-]\\)"
1595 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1597 (while (re-search-forward re nil t
)
1600 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1602 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1604 (setq label
(org-trim (match-string 3))))
1606 (setq end
(if (match-end 4)
1607 (let ((ee (org-table-end)))
1608 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1610 (add-text-properties (point-at-bol) end
1611 (list 'org-caption cap
1612 'org-attributes attr
1614 (if label
(push (cons label label
) target-alist
))
1616 (setq cap nil attr nil label nil
)))))
1619 (defun org-export-remove-comment-blocks-and-subtrees ()
1620 "Remove the comment environment, and also commented subtrees."
1621 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1623 ;; Remove comment environment
1624 (goto-char (point-min))
1625 (setq case-fold-search t
)
1626 (while (re-search-forward
1627 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t
)
1628 (replace-match "" t t
))
1629 ;; Remove subtrees that are commented
1630 (goto-char (point-min))
1631 (setq case-fold-search nil
)
1632 (while (re-search-forward re-commented nil t
)
1633 (goto-char (match-beginning 0))
1634 (delete-region (point) (org-end-of-subtree t
)))))
1636 (defun org-export-handle-comments (commentsp)
1637 "Remove comments, or convert to backend-specific format.
1638 COMMENTSP can be a format string for publishing comments.
1639 When it is nil, all comments will be removed."
1640 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1642 (goto-char (point-min))
1643 (while (or (looking-at re
)
1644 (re-search-forward re nil t
))
1645 (setq pos
(match-beginning 0))
1647 (not (equal (char-before (match-end 1)) ?
+)))
1648 (progn (add-text-properties
1649 (match-beginning 0) (match-end 0) '(org-protected t
))
1650 (replace-match (format commentsp
(match-string 2)) t t
))
1651 (goto-char (1+ pos
))
1653 (goto-char (max (point-min) (1- pos
)))))))
1655 (defun org-export-mark-radio-links ()
1656 "Find all matches for radio targets and turn them into internal links."
1657 (let ((re-radio (and org-target-link-regexp
1658 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1659 (goto-char (point-min))
1661 (while (re-search-forward re-radio nil t
)
1664 (or (org-in-regexp org-bracket-link-regexp
)
1665 (org-in-regexp org-plain-link-re
)
1666 (org-in-regexp "<<[^<>]+>>")))
1668 (replace-match "\\1[[\\2]]")))))))
1670 (defun org-export-remove-special-table-lines ()
1671 "Remove tables lines that are used for internal purposes."
1672 (goto-char (point-min))
1673 (while (re-search-forward "^[ \t]*|" nil t
)
1674 (org-if-unprotected-at (1- (point))
1675 (beginning-of-line 1)
1676 (if (or (looking-at "[ \t]*| *[!_^] *|")
1682 (or (= (length f
) 0)
1684 "\\`<\\([0-9]\\|[rl]\\|[rl][0-9]+\\)>\\'" f
)))
1685 (org-split-string ;; FIXME, can't we do without splitting???
1686 (buffer-substring (point-at-bol) (point-at-eol))
1687 "[ \t]*|[ \t]*")))))
1688 (delete-region (max (point-min) (1- (point-at-bol)))
1692 (defun org-export-protect-sub-super (s)
1694 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
1695 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
1698 (defun org-export-normalize-links ()
1699 "Convert all links to bracket links, and expand link abbreviations."
1700 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1701 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1703 (goto-char (point-min))
1704 (while (re-search-forward re-plain-link nil t
)
1705 (goto-char (1- (match-end 0)))
1706 (org-if-unprotected-at (1+ (match-beginning 0))
1707 (let* ((s (concat (match-string 1)
1708 "[[" (match-string 2) ":" (match-string 3)
1709 "][" (match-string 2) ":" (org-export-protect-sub-super
1712 ;; added 'org-link face to links
1713 (put-text-property 0 (length s
) 'face
'org-link s
)
1714 (replace-match s t t
))))
1715 (goto-char (point-min))
1716 (while (re-search-forward re-angle-link nil t
)
1717 (goto-char (1- (match-end 0)))
1719 (let* ((s (concat (match-string 1)
1720 "[[" (match-string 2) ":" (match-string 3)
1721 "][" (match-string 2) ":" (org-export-protect-sub-super
1724 (put-text-property 0 (length s
) 'face
'org-link s
)
1725 (replace-match s t t
))))
1726 (goto-char (point-min))
1727 (while (re-search-forward org-bracket-link-regexp nil t
)
1728 (goto-char (1- (match-end 0)))
1729 (setq nodesc
(not (match-end 3)))
1731 (let* ((xx (save-match-data
1733 (org-link-expand-abbrev (match-string 1)))))
1735 "[[" (org-add-props (copy-sequence xx
)
1736 nil
'org-protected t
'org-no-description nodesc
)
1740 (concat "[" (copy-sequence xx
)
1743 (put-text-property 0 (length s
) 'face
'org-link s
)
1744 (replace-match s t t
))))))
1746 (defun org-export-concatenate-multiline-links ()
1747 "Find multi-line links and put it all into a single line.
1748 This is to make sure that the line-processing export backends
1749 can work correctly."
1750 (goto-char (point-min))
1751 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1752 (org-if-unprotected-at (match-beginning 1)
1753 (replace-match "\\1 \\3")
1754 (goto-char (match-beginning 0)))))
1756 (defun org-export-concatenate-multiline-emphasis ()
1757 "Find multi-line emphasis and put it all into a single line.
1758 This is to make sure that the line-processing export backends
1759 can work correctly."
1760 (goto-char (point-min))
1761 (while (re-search-forward org-emph-re nil t
)
1762 (if (and (not (= (char-after (match-beginning 3))
1763 (char-after (match-beginning 4))))
1764 (save-excursion (goto-char (match-beginning 0))
1765 (save-match-data (not (org-at-table-p)))))
1767 (subst-char-in-region (match-beginning 0) (match-end 0)
1769 (goto-char (1- (match-end 0))))
1770 (goto-char (1+ (match-beginning 0))))))
1772 (defun org-export-grab-title-from-buffer ()
1773 "Get a title for the current document, from looking at the buffer."
1774 (let ((inhibit-read-only t
))
1776 (goto-char (point-min))
1777 (let ((end (if (looking-at org-outline-regexp
)
1779 (save-excursion (outline-next-heading) (point)))))
1780 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1781 ;; Mark the line so that it will not be exported as normal text.
1783 (add-text-properties (match-beginning 0) (match-end 0)
1784 (list :org-license-to-kill t
)))
1785 ;; Return the title string
1786 (org-trim (match-string 0)))))))
1788 (defun org-export-get-title-from-subtree ()
1789 "Return subtree title and exclude it from export."
1790 (let (title (rbeg (region-beginning)) (rend (region-end)))
1793 (when (and (org-at-heading-p)
1794 (>= (org-end-of-subtree t t
) rend
))
1795 ;; This is a subtree, we take the title from the first heading
1797 (looking-at org-todo-line-regexp
)
1798 (setq title
(match-string 3))
1800 (add-text-properties (point) (1+ (point-at-eol))
1801 (list :org-license-to-kill t
)))
1802 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1805 (defun org-solidify-link-text (s &optional alist
)
1806 "Take link text and make a safe target out of it."
1811 (org-split-string s
"[ \t\r\n]+") "=="))
1812 (a (assoc rtn alist
)))
1815 (defun org-get-min-level (lines &optional offset
)
1816 "Get the minimum level in LINES."
1817 (let ((re "^\\(\\*+\\) ") l
)
1819 (while (setq l
(pop lines
))
1820 (if (string-match re l
)
1821 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1825 ;; Variable holding the vector with section numbers
1826 (defvar org-section-numbers
(make-vector org-level-max
0))
1828 (defun org-init-section-numbers ()
1829 "Initialize the vector for the section numbers."
1831 (numbers (nreverse (org-split-string "" "\\.")))
1832 (depth (1- (length org-section-numbers
)))
1833 (i depth
) number-string
)
1836 (aset org-section-numbers i
0)
1837 (setq number-string
(or (car numbers
) "0"))
1838 (if (string-match "\\`[A-Z]\\'" number-string
)
1839 (aset org-section-numbers i
1840 (- (string-to-char number-string
) ?A -
1))
1841 (aset org-section-numbers i
(string-to-number number-string
)))
1845 (defun org-section-number (&optional level
)
1846 "Return a string with the current section number.
1847 When LEVEL is non-nil, increase section numbers on that level."
1848 (let* ((depth (1- (length org-section-numbers
)))
1850 (fmts (car org-export-section-number-format
))
1851 (term (cdr org-export-section-number-format
))
1856 (aset org-section-numbers
1857 level
(1+ (aref org-section-numbers level
))))
1858 (setq idx
(1+ level
))
1859 (while (<= idx depth
)
1861 (aset org-section-numbers idx
0))
1862 (setq idx
(1+ idx
))))
1864 (while (<= idx depth
)
1865 (when (> (aref org-section-numbers idx
) 0)
1866 (setq fmt
(or (pop fmts
) fmt
)
1868 n
(aref org-section-numbers idx
)
1870 (concat string sep
(org-number-to-counter n ctype
))
1871 (concat string
".0"))
1873 (setq idx
(1+ idx
)))
1875 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1876 (setq string
(replace-match "" t nil string
)))
1877 (if (string-match "\\(\\.0\\)+\\'" string
)
1878 (setq string
(replace-match "" t nil string
))))
1879 (concat string term
)))
1881 (defun org-number-to-counter (n type
)
1882 "Concert number N to a string counter, according to TYPE.
1883 TYPE must be a string, any of:
1887 I upper case roman numeral
1888 i lower case roman numeral"
1890 ((equal type
"1") (number-to-string n
))
1891 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1892 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1893 ((equal type
"I") (org-number-to-roman n
))
1894 ((equal type
"i") (downcase (org-number-to-roman n
)))
1895 (t (error "Invalid counter type `%s'" type
))))
1897 (defun org-number-to-roman (n)
1898 "Convert integer N into a roman numeral."
1899 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1900 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1901 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1905 (number-to-string n
)
1907 (if (>= n
(caar roman
))
1908 (setq n
(- n
(caar roman
))
1909 res
(concat res
(cdar roman
)))
1915 (defun org-export-preprocess-apply-macros ()
1916 "Replace macro references."
1917 (goto-char (point-min))
1918 (let (sy val key args args2 s n
)
1919 (while (re-search-forward
1920 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
1922 (unless (save-match-data
1924 (goto-char (point-at-bol))
1925 (looking-at "[ \t]*#\\+macro")))
1926 (setq key
(downcase (match-string 1))
1927 args
(match-string 3))
1928 (when (setq val
(or (plist-get org-export-opt-plist
1929 (intern (concat ":macro-" key
)))
1930 (plist-get org-export-opt-plist
1931 (intern (concat ":" key
)))))
1934 (setq args
(org-split-string args
",[ \t\n]*") args2 nil
)
1935 (setq args
(mapcar 'org-trim args
))
1937 (while (string-match "\\\\\\'" (car args
))
1938 ;; repair bad splits
1939 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
1942 (push (pop args
) args2
))
1943 (setq args
(nreverse args2
))
1945 (while (string-match "\\$\\([0-9]+\\)" val s
)
1946 (setq s
(1+ (match-beginning 0))
1947 n
(string-to-number (match-string 1 val
)))
1948 (and (>= (length args
) n
)
1949 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
1950 (when (string-match "\\`(eval\\>" val
)
1951 (setq val
(eval (read val
))))
1952 (if (and val
(not (stringp val
)))
1953 (setq val
(format "%s" val
))))
1955 (prog1 (replace-match val t t
)
1956 (goto-char (match-beginning 0)))))))))
1958 (defun org-export-apply-macros-in-string (s)
1959 "Apply the macros in string S."
1963 (org-export-preprocess-apply-macros)
1968 (defun org-export-handle-include-files ()
1969 "Include the contents of include files, with proper formatting."
1970 (let ((case-fold-search t
)
1971 params file markup lang start end prefix prefix1 switches all
)
1972 (goto-char (point-min))
1973 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1974 (setq params
(read (concat "(" (match-string 1) ")"))
1975 prefix
(org-get-and-remove-property 'params
:prefix
)
1976 prefix1
(org-get-and-remove-property 'params
:prefix1
)
1977 file
(org-symname-or-string (pop params
))
1978 markup
(org-symname-or-string (pop params
))
1979 lang
(and (member markup
'("src" "SRC"))
1980 (org-symname-or-string (pop params
)))
1981 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" ")
1983 (delete-region (match-beginning 0) (match-end 0))
1985 (not (file-exists-p file
))
1986 (not (file-readable-p file
)))
1987 (insert (format "CANNOT INCLUDE FILE %s" file
))
1988 (setq all
(cons file all
))
1990 (if (equal (downcase markup
) "src")
1991 (setq start
(format "#+begin_src %s %s\n"
1992 (or lang
"fundamental")
1995 (setq start
(format "#+begin_%s %s\n" markup switches
)
1996 end
(format "#+end_%s" markup
))))
1997 (insert (or start
""))
1998 (insert (org-get-file-contents (expand-file-name file
)
1999 prefix prefix1 markup
))
2000 (or (bolp) (newline))
2001 (insert (or end
""))))
2004 (defun org-export-handle-include-files-recurse ()
2005 "Recursively include files aborting on circular inclusion."
2006 (let ((now (list org-current-export-file
)) all
)
2008 (setq all
(append now all
))
2009 (setq now
(org-export-handle-include-files))
2012 (mapcar (lambda (el) (when (member el all
) el
)) now
))))
2014 (error "recursive #+INCLUDE: %S" intersection
))))))
2016 (defun org-get-file-contents (file &optional prefix prefix1 markup
)
2017 "Get the contents of FILE and return them as a string.
2018 If PREFIX is a string, prepend it to each line. If PREFIX1
2019 is a string, prepend it to the first line instead of PREFIX.
2020 If MARKUP, don't protect org-like lines, the exporter will
2021 take care of the block they are in."
2022 (if (stringp markup
) (setq markup
(downcase markup
)))
2024 (insert-file-contents file
)
2025 (when (or prefix prefix1
)
2026 (goto-char (point-min))
2028 (insert (or prefix1 prefix
))
2030 (beginning-of-line 2)))
2032 (when (member markup
'("src" "example"))
2033 (goto-char (point-min))
2034 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2035 (goto-char (match-beginning 0))
2040 (defun org-get-and-remove-property (listvar prop
)
2041 "Check if the value of LISTVAR contains PROP as a property.
2042 If yes, return the value of that property (i.e. the element following
2043 in the list) and remove property and value from the list in LISTVAR."
2044 (let ((list (symbol-value listvar
)) m v
)
2045 (when (setq m
(member prop list
))
2047 (if (equal (car list
) prop
)
2048 (set listvar
(cddr list
))
2049 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2051 (set listvar list
)))
2054 (defun org-symname-or-string (s)
2056 (if s
(symbol-name s
) s
)
2059 ;;; Fontification and line numbers for code examples
2061 (defvar org-export-last-code-line-counter-value
0)
2063 (defun org-export-replace-src-segments-and-examples (backend)
2064 "Replace source code segments with special code for export."
2065 (setq org-export-last-code-line-counter-value
0)
2066 (let ((case-fold-search t
)
2067 lang code trans opts indent caption
)
2068 (goto-char (point-min))
2069 (while (re-search-forward
2070 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2074 (setq lang
(match-string 3)
2075 opts
(match-string 4)
2076 code
(match-string 5)
2077 indent
(length (match-string 2))
2078 caption
(get-text-property 0 'org-caption
(match-string 0)))
2080 opts
(match-string 8)
2081 code
(match-string 9)
2082 indent
(length (match-string 7))
2083 caption
(get-text-property 0 'org-caption
(match-string 0))))
2085 (setq trans
(org-export-format-source-code-or-example
2086 backend lang code opts indent caption
))
2087 (replace-match trans t t
))))
2089 (defvar htmlp
) ;; dynamically scoped
2090 (defvar latexp
) ;; dynamically scoped
2091 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2092 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2093 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2095 (defun org-export-format-source-code-or-example
2096 (backend lang code
&optional opts indent caption
)
2097 "Format CODE from language LANG and return it formatted for export.
2098 If LANG is nil, do not add any fontification.
2099 OPTS contains formatting options, like `-n' for triggering numbering lines,
2100 and `+n' for continuing previous numbering.
2101 Code formatting according to language currently only works for HTML.
2102 Numbering lines works for all three major backends (html, latex, and ascii).
2103 INDENT was the original indentation of the block."
2105 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2106 (setq opts
(or opts
"")
2107 num
(string-match "[-+]n\\>" opts
)
2108 cont
(string-match "\\+n\\>" opts
)
2109 rpllbl
(string-match "-r\\>" opts
)
2110 keepp
(string-match "-k\\>" opts
)
2111 textareap
(string-match "-t\\>" opts
)
2112 preserve-indentp
(or org-src-preserve-indentation
2113 (string-match "-i\\>" opts
))
2114 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2115 (string-to-number (match-string 1 opts
))
2117 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2118 (string-to-number (match-string 1 opts
))
2119 (org-count-lines code
))
2120 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2121 (match-string 1 opts
)))
2122 (when (and textareap
(eq backend
'html
))
2123 ;; we cannot use numbering or highlighting.
2124 (setq num nil cont nil lang nil
))
2125 (if keepp
(setq rpllbl
'keep
))
2126 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2127 (when (string-match "^," rtn
)
2128 (setq rtn
(with-temp-buffer
2130 ;; Free up the protected lines
2131 (goto-char (point-min))
2132 (while (re-search-forward "^," nil t
)
2133 (if (or (equal lang
"org")
2135 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2139 ;; Now backend-specific coding
2142 ((eq backend
'docbook
)
2143 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2144 (concat "\n#+BEGIN_DOCBOOK\n"
2145 (org-add-props (concat "<programlisting><![CDATA["
2147 "]]></programlisting>\n")
2148 '(org-protected t org-example t
))
2151 ;; We are exporting to HTML
2153 (if (featurep 'xemacs
)
2155 (require 'htmlize nil t
))
2156 (when (not (fboundp 'htmlize-region-for-paste
))
2157 ;; we do not have htmlize.el, or an old version of it
2160 "htmlize.el 1.34 or later is needed for source code formatting")))
2163 (let* ((lang-m (when lang
2164 (or (cdr (assoc lang org-src-lang-modes
))
2166 (mode (and lang-m
(intern
2168 (if (symbolp lang-m
)
2169 (symbol-name lang-m
)
2172 (org-inhibit-startup t
)
2173 (org-startup-folded nil
))
2177 (if (functionp mode
)
2180 (font-lock-fontify-buffer)
2182 (set-buffer-modified-p nil
)
2183 (org-export-htmlize-region-for-paste
2184 (point-min) (point-max))))
2185 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2190 "<div class=\"org-src-container\">"
2192 "<label class=\"org-src-name\">%s</label>"
2196 (format "<pre class=\"src src-%s\">\n" lang
)
2198 (if caption
"</div>" "")))))
2201 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2203 rtn
"</textarea>\n</p>\n"))
2206 (goto-char (point-min))
2207 (while (re-search-forward "[<>&]" nil t
)
2208 (replace-match (cdr (assq (char-before)
2209 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2211 (setq rtn
(buffer-string)))
2212 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2214 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2216 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2217 (setq rtn
(replace-match "\\1" t nil rtn
)))
2218 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t org-example t
)) "\n#+END_HTML\n\n"))
2219 ((eq backend
'latex
)
2220 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2221 (concat "#+BEGIN_LaTeX\n"
2223 (if org-export-latex-listings
2227 ((lang-sym (intern lang
))
2232 org-export-latex-listings-langs
))
2234 (format "\\lstset{language=%s}\n" lstlang
))
2237 (format "\n%s $\\equiv$ \n" caption
))
2238 "\\begin{lstlisting}\n"
2239 rtn
"\\end{lstlisting}\n")
2240 (concat (car org-export-latex-verbatim-wrap
)
2241 rtn
(cdr org-export-latex-verbatim-wrap
)))
2242 '(org-protected t org-example t
))
2244 ((eq backend
'ascii
)
2245 ;; This is not HTML or LaTeX, so just make it an example.
2246 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2247 (concat caption
"\n"
2252 (lambda (l) (concat " " l
))
2253 (org-split-string rtn
"\n")
2256 '(org-protected t org-example t
))
2258 (org-add-props rtn nil
'original-indentation indent
))))
2260 (defun org-export-number-lines (text backend
2261 &optional skip1 skip2 number cont
2262 replace-labels label-format
)
2263 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2264 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2267 (goto-char (point-max))
2268 (skip-chars-backward " \t\n\r")
2269 (delete-region (point) (point-max))
2270 (beginning-of-line (- 1 skip2
))
2271 (let* ((last (org-current-line))
2272 (n org-export-last-code-line-counter-value
)
2273 (nmax (+ n
(- last skip1
)))
2274 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2277 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2279 ((eq backend
'ascii
) fmt
)
2280 ((eq backend
'latex
) fmt
)
2281 ((eq backend
'docbook
) fmt
)
2283 (label-format (or label-format org-coderef-label-format
))
2284 (label-pre (if (string-match "%s" label-format
)
2285 (substring label-format
0 (match-beginning 0))
2287 (label-post (if (string-match "%s" label-format
)
2288 (substring label-format
(match-end 0))
2292 ".*?\\S-.*?\\([ \t]*\\("
2293 (regexp-quote label-pre
)
2294 "\\([-a-zA-Z0-9_ ]+\\)"
2295 (regexp-quote label-post
)
2299 (org-goto-line (1+ skip1
))
2300 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2302 (insert (format fm
(incf n
)))
2304 (when (looking-at lbl-re
)
2305 (setq ref
(match-string 3))
2306 (cond ((numberp replace-labels
)
2307 ;; remove labels; use numbers for references when lines
2308 ;; are numbered, use labels otherwise
2309 (delete-region (match-beginning 1) (match-end 1))
2310 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2311 ((eq replace-labels
'keep
)
2312 ;; don't remove labels; use numbers for references when
2313 ;; lines are numbered, use labels otherwise
2314 (goto-char (match-beginning 2))
2315 (delete-region (match-beginning 2) (match-end 2))
2316 (insert "(" ref
")")
2317 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2318 org-export-code-refs
))
2320 ;; don't remove labels and don't use numbers for
2322 (goto-char (match-beginning 2))
2323 (delete-region (match-beginning 2) (match-end 2))
2324 (insert "(" ref
")")
2325 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2326 (when (eq backend
'html
)
2328 (beginning-of-line 1)
2329 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2332 (insert "</span>")))))
2333 (setq org-export-last-code-line-counter-value n
)
2334 (goto-char (point-max))
2338 (defun org-search-todo-below (line lines level
)
2339 "Search the subtree below LINE for any TODO entries."
2340 (let ((rest (cdr (memq line lines
)))
2341 (re org-todo-line-regexp
)
2344 (while (setq line
(pop rest
))
2345 (if (string-match re line
)
2347 (setq lv
(- (match-end 1) (match-beginning 1))
2348 todo
(and (match-beginning 2)
2349 (not (member (match-string 2 line
)
2350 org-done-keywords
))))
2352 (if (<= lv level
) (throw 'exit nil
))
2353 (if todo
(throw 'exit t
))))))))
2356 (defun org-export-visible (type arg
)
2357 "Create a copy of the visible part of the current buffer, and export it.
2358 The copy is created in a temporary buffer and removed after use.
2359 TYPE is the final key (as a string) that also select the export command in
2360 the `C-c C-e' export dispatcher.
2361 As a special case, if the you type SPC at the prompt, the temporary
2362 org-mode file will not be removed but presented to you so that you can
2363 continue to use it. The prefix arg ARG is passed through to the exporting
2367 (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")
2368 (read-char-exclusive))
2369 current-prefix-arg
))
2370 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L
)))
2371 (error "Invalid export key"))
2372 (let* ((binding (cdr (assoc type
2374 (?a . org-export-as-ascii
)
2375 (?A . org-export-as-ascii-to-buffer
)
2376 (?n . org-export-as-latin1
)
2377 (?N . org-export-as-latin1-to-buffer
)
2378 (?u . org-export-as-utf8
)
2379 (?U . org-export-as-utf8-to-buffer
)
2380 (?\C-a . org-export-as-ascii
)
2381 (?b . org-export-as-html-and-open
)
2382 (?\C-b . org-export-as-html-and-open
)
2383 (?h . org-export-as-html
)
2384 (?H . org-export-as-html-to-buffer
)
2385 (?R . org-export-region-as-html
)
2386 (?D . org-export-as-docbook
)
2388 (?l . org-export-as-latex
)
2389 (?p . org-export-as-pdf
)
2390 (?d . org-export-as-pdf-and-open
)
2391 (?L . org-export-as-latex-to-buffer
)
2393 (?x . org-export-as-xoxo
)))))
2394 (keepp (equal type ?\
))
2395 (file buffer-file-name
)
2396 (buffer (get-buffer-create "*Org Export Visible*"))
2398 ;; Need to hack the drawers here.
2400 (goto-char (point-min))
2401 (while (re-search-forward org-drawer-regexp nil t
)
2402 (goto-char (match-beginning 1))
2403 (or (org-invisible-p) (org-flag-drawer nil
))))
2404 (with-current-buffer buffer
(erase-buffer))
2406 (setq s
(goto-char (point-min)))
2407 (while (not (= (point) (point-max)))
2408 (goto-char (org-find-invisible))
2409 (append-to-buffer buffer s
(point))
2410 (setq s
(goto-char (org-find-visible))))
2411 (org-cycle-hide-drawers 'all
)
2412 (goto-char (point-min))
2414 ;; Copy all comment lines to the end, to make sure #+ settings are
2415 ;; still available for the second export step. Kind of a hack, but
2416 ;; does do the trick.
2417 (if (looking-at "#[^\r\n]*")
2418 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2419 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2420 (append-to-buffer buffer
(1+ (match-beginning 0))
2421 (min (point-max) (1+ (match-end 0))))))
2423 (let ((buffer-file-name file
)
2424 (org-inhibit-startup t
))
2427 (unless keepp
(funcall binding arg
))))
2429 (kill-buffer buffer
)
2430 (switch-to-buffer-other-window buffer
)
2431 (goto-char (point-min)))))
2433 (defun org-find-visible ()
2435 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2436 (get-char-property s
'invisible
)))
2438 (defun org-find-invisible ()
2440 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2441 (not (get-char-property s
'invisible
))))
2444 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2447 (defun org-export-as-org (arg &optional hidden ext-plist
2448 to-buffer body-only pub-dir
)
2449 "Make a copy with not-exporting stuff removed.
2450 The purpose of this function is to provide a way to export the source
2451 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2452 stuff removed. This command will remove the following:
2454 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2455 - comment blocks and trees starting with the COMMENT keyword
2456 - only trees that are consistent with `org-export-select-tags'
2457 and `org-export-exclude-tags'.
2459 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2460 all the others will be ignored (but are present so that the general
2461 mechanism to call publishing functions will work).
2463 EXT-PLIST is a property list with external parameters overriding
2464 org-mode's default settings, but still inferior to file-local
2465 settings. When PUB-DIR is set, use this as the publishing
2468 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2470 (org-infile-export-plist)))
2471 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2472 (filename (concat (file-name-as-directory
2474 (org-export-directory :org opt-plist
)))
2475 (file-name-sans-extension
2476 (file-name-nondirectory bfname
))
2478 (filename (and filename
2479 (if (equal (file-truename filename
)
2480 (file-truename bfname
))
2481 (concat (file-name-sans-extension filename
)
2483 (file-name-extension filename
))
2485 (backup-inhibited t
)
2486 (buffer (find-file-noselect filename
))
2487 (region (buffer-string))
2490 (switch-to-buffer buffer
)
2493 (let ((org-inhibit-startup t
)) (org-mode))
2494 (org-install-letbind)
2496 ;; Get rid of archived trees
2497 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2499 ;; Remove comment environment and comment subtrees
2500 (org-export-remove-comment-blocks-and-subtrees)
2502 ;; Get rid of excluded trees
2503 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2504 (plist-get opt-plist
:exclude-tags
))
2506 (when (or (plist-get opt-plist
:plain-source
)
2507 (not (or (plist-get opt-plist
:plain-source
)
2508 (plist-get opt-plist
:htmlized-source
))))
2509 ;; Either nothing special is requested (default call)
2510 ;; or the plain source is explicitly requested
2513 (when (plist-get opt-plist
:htmlized-source
)
2514 ;; Make the htmlized version
2517 (font-lock-fontify-buffer)
2518 (let* ((htmlize-output-type 'css
)
2519 (newbuf (htmlize-buffer)))
2520 (with-current-buffer newbuf
2521 (when org-export-htmlized-org-css-url
2522 (goto-char (point-min))
2523 (and (re-search-forward
2524 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2528 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2529 org-export-htmlized-org-css-url
)
2531 (write-file (concat filename
".html")))
2532 (kill-buffer newbuf
)))
2533 (set-buffer-modified-p nil
)
2534 (if (equal to-buffer
'string
)
2535 (progn (setq str-ret
(buffer-string))
2536 (kill-buffer (current-buffer))
2538 (kill-buffer (current-buffer))))))
2540 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2541 (defun org-get-current-options ()
2542 "Return a string with current options as keyword options.
2543 Does include HTML export options as well as TODO and CATEGORY stuff."
2544 (require 'org-archive
)
2553 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2554 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2556 #+EXPORT_SELECT_TAGS: %s
2557 #+EXPORT_EXCLUDE_TAGS: %s
2564 #+PRIORITIES: %c %c %c
2566 #+STARTUP: %s %s %s %s %s
2572 (buffer-name) (user-full-name) user-mail-address
2573 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2574 org-export-default-language
2575 org-export-headline-levels
2576 org-export-with-section-numbers
2578 org-export-preserve-breaks
2579 org-export-html-expand
2580 org-export-with-fixed-width
2581 org-export-with-tables
2582 org-export-with-sub-superscripts
2583 org-export-with-special-strings
2584 org-export-with-footnotes
2585 org-export-with-emphasize
2586 org-export-with-timestamps
2587 org-export-with-TeX-macros
2588 org-export-with-LaTeX-fragments
2589 org-export-skip-text-before-1st-heading
2590 org-export-with-drawers
2591 org-export-with-todo-keywords
2592 org-export-with-priority
2593 org-export-with-tags
2594 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2595 (mapconcat 'identity org-export-select-tags
" ")
2596 (mapconcat 'identity org-export-exclude-tags
" ")
2597 org-export-html-link-up
2598 org-export-html-link-home
2600 (file-name-sans-extension
2601 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2603 "TODO FEEDBACK VERIFY DONE"
2604 "Me Jason Marie DONE"
2605 org-highest-priority org-lowest-priority org-default-priority
2606 (mapconcat 'identity org-drawers
" ")
2607 (cdr (assoc org-startup-folded
2608 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2609 (if org-odd-levels-only
"odd" "oddeven")
2610 (if org-hide-leading-stars
"hidestars" "showstars")
2611 (if org-startup-align-all-tables
"align" "noalign")
2612 (cond ((eq org-log-done t
) "logdone")
2613 ((equal org-log-done
'note
) "lognotedone")
2614 ((not org-log-done
) "nologdone"))
2615 (or (mapconcat (lambda (x)
2617 ((equal :startgroup
(car x
)) "{")
2618 ((equal :endgroup
(car x
)) "}")
2619 ((equal :newline
(car x
)) "")
2620 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2622 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2623 (mapconcat 'identity org-file-tags
" ")
2624 org-archive-location
2625 "org file:~/org/%s.org"
2629 (defun org-insert-export-options-template ()
2630 "Insert into the buffer a template with information for exporting."
2632 (if (not (bolp)) (newline))
2633 (let ((s (org-get-current-options)))
2634 (and (string-match "#\\+CATEGORY" s
)
2635 (setq s
(substring s
0 (match-beginning 0))))
2638 (defvar org-table-colgroup-info nil
)
2640 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2641 "Check if the table has a marking column.
2642 If yes remove the column and the special lines."
2643 (setq org-table-colgroup-info nil
)
2646 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2649 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2650 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2653 ;; No special marking column
2655 (setq org-table-clean-did-remove-column nil
)
2660 ((org-table-colgroup-line-p x
)
2661 ;; This line contains colgroup info, extract it
2662 ;; and then discard the line
2663 (setq org-table-colgroup-info
2665 (cond ((member x
'("<" "<")) :start
)
2666 ((member x
'(">" ">")) :end
)
2667 ((member x
'("<>" "<>")) :startend
)
2669 (org-split-string x
"[ \t]*|[ \t]*")))
2671 ((org-table-cookie-line-p x
)
2672 ;; This line contains formatting cookies, discard it
2676 ;; there is a special marking column
2677 (setq org-table-clean-did-remove-column t
)
2682 ((org-table-colgroup-line-p x
)
2683 ;; This line contains colgroup info, extract it
2684 ;; and then discard the line
2685 (setq org-table-colgroup-info
2687 (cond ((member x
'("<" "<")) :start
)
2688 ((member x
'(">" ">")) :end
)
2689 ((member x
'("<>" "<>")) :startend
)
2691 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2693 ((org-table-cookie-line-p x
)
2694 ;; This line contains formatting cookies, discard it
2696 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2699 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2700 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2701 ;; remove the first column
2702 (replace-match "\\1|" t nil x
))))
2705 (defun org-export-cleanup-toc-line (s)
2706 "Remove tags and timestamps from lines going into the toc."
2707 (when (memq org-export-with-tags
'(not-in-toc nil
))
2708 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2709 (setq s
(replace-match "" t t s
))))
2710 (when org-export-remove-timestamps-from-toc
2711 (while (string-match org-maybe-keyword-time-regexp s
)
2712 (setq s
(replace-match "" t t s
))))
2713 (while (string-match org-bracket-link-regexp s
)
2714 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2716 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
2717 (setq s
(replace-match "" t t s
)))
2721 (defun org-get-text-property-any (pos prop
&optional object
)
2722 (or (get-text-property pos prop object
)
2723 (and (setq pos
(next-single-property-change pos prop object
))
2724 (get-text-property pos prop object
))))
2726 (defun org-export-get-coderef-format (path desc
)
2728 (if (and desc
(string-match
2729 (regexp-quote (concat "(" path
")"))
2731 (replace-match "%s" t t desc
)
2734 (defun org-export-push-to-kill-ring (format)
2735 "Push buffer content to kill ring.
2736 The depends on the variable `org-export-copy-to-kill'."
2737 (when org-export-copy-to-kill-ring
2738 (org-kill-new (buffer-string))
2739 (when (fboundp 'x-set-selection
)
2740 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
2741 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
2742 (message "%s export done, pushed to kill ring and clipboard" format
)))
2746 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2748 ;;; org-exp.el ends here