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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (require 'org-exp-blocks
)
41 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
42 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
43 (declare-function org-export-html-preprocess
"org-html" (parameters))
44 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
45 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
46 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
47 (declare-function htmlize-buffer
"ext:htmlize" (&optional buffer
))
48 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
49 (declare-function org-table-cookie-line-p
"org-table" (line))
50 (declare-function org-table-colgroup-line-p
"org-table" (line))
51 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
52 (defgroup org-export nil
53 "Options for exporting org-listings."
57 (defgroup org-export-general nil
58 "General options for exporting Org-mode files."
59 :tag
"Org Export General"
62 (defcustom org-export-allow-BIND
'confirm
63 "Non-nil means allow #+BIND to define local variable values for export.
64 This is a potential security risk, which is why the user must confirm the
66 :group
'org-export-general
68 (const :tag
"Never" nil
)
69 (const :tag
"Always" t
)
70 (const :tag
"Make the user confirm for each file" confirm
)))
73 (defvar org-export-publishing-directory nil
)
75 (defcustom org-export-show-temporary-export-buffer t
76 "Non-nil means show buffer after exporting to temp buffer.
77 When Org exports to a file, the buffer visiting that file is ever
78 shown, but remains buried. However, when exporting to a temporary
79 buffer, that buffer is popped up in a second window. When this variable
80 is nil, the buffer remains buried also in these cases."
81 :group
'org-export-general
84 (defcustom org-export-copy-to-kill-ring t
85 "Non-nil means exported stuff will also be pushed onto the kill ring."
86 :group
'org-export-general
89 (defcustom org-export-kill-product-buffer-when-displayed nil
90 "Non-nil means kill the product buffer if it is displayed immediately.
91 This applied to the commands `org-export-html-and-open' and
92 `org-export-as-pdf-and-open'."
93 :group
'org-export-general
96 (defcustom org-export-run-in-background nil
97 "Non-nil means export and publishing commands will run in background.
98 This works by starting up a separate Emacs process visiting the same file
99 and doing the export from there.
100 Not all export commands are affected by this - only the ones which
101 actually write to a file, and that do not depend on the buffer state.
103 If this option is nil, you can still get background export by calling
104 `org-export' with a double prefix arg: \
105 \\[universal-argument] \\[universal-argument] \\[org-export].
107 If this option is t, the double prefix can be used to exceptionally
108 force an export command into the current process."
109 :group
'org-export-general
112 (defcustom org-export-select-tags
'("export")
113 "Tags that select a tree for export.
114 If any such tag is found in a buffer, all trees that do not carry one
115 of these tags will be deleted before export.
116 Inside trees that are selected like this, you can still deselect a
117 subtree by tagging it with one of the `org-export-exclude-tags'."
118 :group
'org-export-general
119 :type
'(repeat (string :tag
"Tag")))
121 (defcustom org-export-exclude-tags
'("noexport")
122 "Tags that exclude a tree from export.
123 All trees carrying any of these tags will be excluded from export.
124 This is without condition, so even subtrees inside that carry one of the
125 `org-export-select-tags' will be removed."
126 :group
'org-export-general
127 :type
'(repeat (string :tag
"Tag")))
129 ;; FIXME: rename, this is a general variable
130 (defcustom org-export-html-expand t
131 "Non-nil means for HTML export, treat @<...> as HTML tag.
132 When nil, these tags will be exported as plain text and therefore
133 not be interpreted by a browser.
135 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
136 :group
'org-export-html
137 :group
'org-export-general
140 (defcustom org-export-with-special-strings t
141 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
142 When this option is turned on, these strings will be exported as:
145 -----+----------+--------
151 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
152 :group
'org-export-translation
155 (defcustom org-export-html-link-up
""
156 "Where should the \"UP\" link of exported HTML pages lead?"
157 :group
'org-export-html
158 :group
'org-export-general
159 :type
'(string :tag
"File or URL"))
161 (defcustom org-export-html-link-home
""
162 "Where should the \"HOME\" link of exported HTML pages lead?"
163 :group
'org-export-html
164 :group
'org-export-general
165 :type
'(string :tag
"File or URL"))
167 (defcustom org-export-language-setup
168 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
169 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
170 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
171 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
172 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
173 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
174 ("es" "Autor" "Fecha" "Índice" "Pies de página")
175 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
176 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
177 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
178 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
179 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
180 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
181 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
182 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
183 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
184 ("pl" "Autor" "Data" "Spis treści" "Przypis")
185 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
186 "Terms used in export text, translated to different languages.
187 Use the variable `org-export-default-language' to set the language,
188 or use the +OPTION lines for a per-file setting."
189 :group
'org-export-general
192 (string :tag
"HTML language tag")
193 (string :tag
"Author")
195 (string :tag
"Table of Contents")
196 (string :tag
"Footnotes"))))
198 (defcustom org-export-default-language
"en"
199 "The default language of HTML export, as a string.
200 This should have an association in `org-export-language-setup'."
201 :group
'org-export-general
204 (defvar org-export-page-description
""
205 "The page description, for the XHTML meta tag.
206 This is best set with the #+DESCRIPTION line in a file, it does not make
207 sense to set this globally.")
209 (defvar org-export-page-keywords
""
210 "The page description, for the XHTML meta tag.
211 This is best set with the #+KEYWORDS line in a file, it does not make
212 sense to set this globally.")
214 (defcustom org-export-skip-text-before-1st-heading nil
215 "Non-nil means skip all text before the first headline when exporting.
216 When nil, that text is exported as well."
217 :group
'org-export-general
220 (defcustom org-export-headline-levels
3
221 "The last level which is still exported as a headline.
222 Inferior levels will produce itemize lists when exported.
223 Note that a numeric prefix argument to an exporter function overrides
226 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
227 :group
'org-export-general
230 (defcustom org-export-with-section-numbers t
231 "Non-nil means add section numbers to headlines when exporting.
233 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
234 :group
'org-export-general
237 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
238 "Format of section numbers for export.
239 The variable has two components.
240 1. A list of lists, each indicating a counter type and a separator.
241 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
242 It causes causes numeric, alphabetic, or roman counters, respectively.
243 The separator is only used if another counter for a subsection is being
245 If there are more numbered section levels than entries in this lists,
246 then the last entry will be reused.
247 2. A terminator string that will be added after the entire
249 :group
'org-export-general
253 (string :tag
"Counter Type")
254 (string :tag
"Separator ")))
255 (string :tag
"Terminator")))
257 (defcustom org-export-with-toc t
258 "Non-nil means create a table of contents in exported files.
259 The TOC contains headlines with levels up to`org-export-headline-levels'.
260 When an integer, include levels up to N in the toc, this may then be
261 different from `org-export-headline-levels', but it will not be allowed
262 to be larger than the number of headline levels.
263 When nil, no table of contents is made.
265 Headlines which contain any TODO items will be marked with \"(*)\" in
266 ASCII export, and with red color in HTML output, if the option
267 `org-export-mark-todo-in-toc' is set.
269 In HTML output, the TOC will be clickable.
271 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
273 :group
'org-export-general
275 (const :tag
"No Table of Contents" nil
)
276 (const :tag
"Full Table of Contents" t
)
277 (integer :tag
"TOC to level")))
279 (defcustom org-export-mark-todo-in-toc nil
280 "Non-nil means mark TOC lines that contain any open TODO items."
281 :group
'org-export-general
284 (defcustom org-export-with-todo-keywords t
285 "Non-nil means include TODO keywords in export.
286 When nil, remove all these keywords from the export."
287 :group
'org-export-general
290 (defcustom org-export-with-priority nil
291 "Non-nil means include priority cookies in export.
292 When nil, remove priority cookies for export."
293 :group
'org-export-general
296 (defcustom org-export-preserve-breaks nil
297 "Non-nil means preserve all line breaks when exporting.
298 Normally, in HTML output paragraphs will be reformatted. In ASCII
299 export, line breaks will always be preserved, regardless of this variable.
301 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
302 :group
'org-export-general
305 (defcustom org-export-with-archived-trees
'headline
306 "Whether subtrees with the ARCHIVE tag should be exported.
307 This can have three different values
308 nil Do not export, pretend this tree is not present
309 t Do export the entire tree
310 headline Only export the headline, but skip the tree below it."
311 :group
'org-export-general
314 (const :tag
"not at all" nil
)
315 (const :tag
"headline only" 'headline
)
316 (const :tag
"entirely" t
)))
318 (defcustom org-export-author-info t
319 "Non-nil means insert author name and email into the exported file.
321 This option can also be set with the +OPTIONS line,
322 e.g. \"author:nil\"."
323 :group
'org-export-general
326 (defcustom org-export-email-info nil
327 "Non-nil means insert author name and email into the exported file.
329 This option can also be set with the +OPTIONS line,
331 :group
'org-export-general
334 (defcustom org-export-creator-info t
335 "Non-nil means the postamble should contain a creator sentence.
336 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
337 :group
'org-export-general
340 (defcustom org-export-time-stamp-file t
341 "Non-nil means insert a time stamp into the exported file.
342 The time stamp shows when the file was created.
344 This option can also be set with the +OPTIONS line,
345 e.g. \"timestamp:nil\"."
346 :group
'org-export-general
349 (defcustom org-export-with-timestamps t
350 "If nil, do not export time stamps and associated keywords."
351 :group
'org-export-general
354 (defcustom org-export-remove-timestamps-from-toc t
355 "If t, remove timestamps from the table of contents entries."
356 :group
'org-export-general
359 (defcustom org-export-with-tags
'not-in-toc
360 "If nil, do not export tags, just remove them from headlines.
361 If this is the symbol `not-in-toc', tags will be removed from table of
362 contents entries, but still be shown in the headlines of the document.
364 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
365 :group
'org-export-general
367 (const :tag
"Off" nil
)
368 (const :tag
"Not in TOC" not-in-toc
)
369 (const :tag
"On" t
)))
371 (defcustom org-export-with-drawers nil
372 "Non-nil means export with drawers like the property drawer.
373 When t, all drawers are exported. This may also be a list of
374 drawer names to export."
375 :group
'org-export-general
377 (const :tag
"All drawers" t
)
378 (const :tag
"None" nil
)
379 (repeat :tag
"Selected drawers"
380 (string :tag
"Drawer name"))))
382 (defvar org-export-first-hook nil
383 "Hook called as the first thing in each exporter.
384 Point will be still in the original buffer.
385 Good for general initialization")
387 (defvar org-export-preprocess-hook nil
388 "Hook for preprocessing an export buffer.
389 Pretty much the first thing when exporting is running this hook.
390 Point will be in a temporary buffer that contains a copy of
391 the original buffer, or of the section that is being export.
392 All the other hooks in the org-export-preprocess... category
393 also work in that temporary buffer, already modified by various
394 stages of the processing.")
396 (defvar org-export-preprocess-after-include-files-hook nil
397 "Hook for preprocessing an export buffer.
398 This is run after the contents of included files have been inserted.")
400 (defvar org-export-preprocess-after-tree-selection-hook nil
401 "Hook for preprocessing an export buffer.
402 This is run after selection of trees to be exported has happened.
403 This selection includes tags-based selection, as well as removal
404 of commented and archived trees.")
406 (defvar org-export-preprocess-after-headline-targets-hook nil
407 "Hook for preprocessing export buffer.
408 This is run just after the headline targets have been defined and
409 the target-alist has been set up.")
411 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
412 "Hook for preprocessing an export buffer.
413 This is run just before backend-specific blocks get selected.")
415 (defvar org-export-preprocess-after-blockquote-hook nil
416 "Hook for preprocessing an export buffer.
417 This is run after blockquote/quote/verse/center have been marked
420 (defvar org-export-preprocess-after-radio-targets-hook nil
421 "Hook for preprocessing an export buffer.
422 This is run after radio target processing.")
424 (defvar org-export-preprocess-before-normalizing-links-hook nil
425 "Hook for preprocessing an export buffer.
426 This hook is run before links are normalized.")
428 (defvar org-export-preprocess-before-backend-specifics-hook nil
429 "Hook run before backend-specific functions are called during preprocessing.")
431 (defvar org-export-preprocess-final-hook nil
432 "Hook for preprocessing an export buffer.
433 This is run as the last thing in the preprocessing buffer, just before
434 returning the buffer string to the backend.")
436 (defgroup org-export-translation nil
437 "Options for translating special ascii sequences for the export backends."
438 :tag
"Org Export Translation"
441 (defcustom org-export-with-emphasize t
442 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
443 If the export target supports emphasizing text, the word will be
444 typeset in bold, italic, or underlined, respectively. Works only for
445 single words, but you can say: I *really* *mean* *this*.
446 Not all export backends support this.
448 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
449 :group
'org-export-translation
452 (defcustom org-export-with-footnotes t
453 "If nil, export [1] as a footnote marker.
454 Lines starting with [1] will be formatted as footnotes.
456 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
457 :group
'org-export-translation
460 (defcustom org-export-with-TeX-macros t
461 "Non-nil means interpret simple TeX-like macros when exporting.
462 For example, HTML export converts \\alpha to α and \\AA to Å.
463 Not only real TeX macros will work here, but the standard HTML entities
464 for math can be used as macro names as well. For a list of supported
465 names in HTML export, see the constant `org-entities' and the user option
467 Not all export backends support this.
469 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
470 :group
'org-export-translation
471 :group
'org-export-latex
474 (defcustom org-export-with-LaTeX-fragments t
475 "Non-nil means process LaTeX math fragments for HTML display.
476 When set, the exporter will find and process LaTeX environments if the
477 \\begin line is the first non-white thing on a line. It will also find
478 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
479 $$a=b$$ and \\[ a=b \\] for display math.
481 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
485 nil Don't do anything.
486 verbatim Keep eveything in verbatim
487 dvipng Process the LaTeX fragments to images.
488 This will also include processing of non-math environments.
489 t Do MathJax preprocessing if there is at least on math snippet,
490 and arrange for MathJax.js to be loaded.
492 The default is nil, because this option needs the `dvipng' program which
493 is not available on all systems."
494 :group
'org-export-translation
495 :group
'org-export-latex
497 (const :tag
"Do not process math in any way" nil
)
498 (const :tag
"Obsolete, use dvipng setting" t
)
499 (const :tag
"Use dvipng to make images" dvipng
)
500 (const :tag
"Use MathJax to display math" mathjax
)
501 (const :tag
"Leave math verbatim" verbatim
)))
503 (defcustom org-export-with-fixed-width t
504 "Non-nil means lines starting with \":\" will be in fixed width font.
505 This can be used to have pre-formatted text, fragments of code etc. For
507 : ;; Some Lisp examples
510 will be looking just like this in also HTML. See also the QUOTE keyword.
511 Not all export backends support this.
513 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
514 :group
'org-export-translation
517 (defgroup org-export-tables nil
518 "Options for exporting tables in Org-mode."
519 :tag
"Org Export Tables"
522 (defcustom org-export-with-tables t
523 "If non-nil, lines starting with \"|\" define a table.
526 | Name | Address | Birthday |
527 |-------------+----------+-----------|
528 | Arthur Dent | England | 29.2.2100 |
530 Not all export backends support this.
532 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
533 :group
'org-export-tables
536 (defcustom org-export-highlight-first-table-line t
537 "Non-nil means highlight the first table line.
538 In HTML export, this means use <th> instead of <td>.
539 In tables created with table.el, this applies to the first table line.
540 In Org-mode tables, all lines before the first horizontal separator
541 line will be formatted with <th> tags."
542 :group
'org-export-tables
545 (defcustom org-export-table-remove-special-lines t
546 "Remove special lines and marking characters in calculating tables.
547 This removes the special marking character column from tables that are set
548 up for spreadsheet calculations. It also removes the entire lines
549 marked with `!', `_', or `^'. The lines with `$' are kept, because
550 the values of constants may be useful to have."
551 :group
'org-export-tables
554 (defcustom org-export-prefer-native-exporter-for-tables nil
555 "Non-nil means always export tables created with table.el natively.
556 Natively means use the HTML code generator in table.el.
557 When nil, Org-mode's own HTML generator is used when possible (i.e. if
558 the table does not use row- or column-spanning). This has the
559 advantage, that the automatic HTML conversions for math symbols and
560 sub/superscripts can be applied. Org-mode's HTML generator is also
561 much faster. The LaTeX exporter always use the native exporter for
563 :group
'org-export-tables
567 (defgroup org-export-xml nil
568 "Options specific for XML export of Org-mode files."
569 :tag
"Org Export XML"
574 ;;; Variables, constants, and parameter plists
576 (defconst org-level-max
20)
578 (defvar org-current-export-file nil
) ; dynamically scoped parameter
579 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
580 (defvar org-export-opt-plist nil
581 "Contains the current option plist.")
582 (defvar org-last-level nil
) ; dynamically scoped variable
583 (defvar org-min-level nil
) ; dynamically scoped variable
584 (defvar org-levels-open nil
) ; dynamically scoped parameter
586 (defconst org-export-plist-vars
587 '((:link-up nil org-export-html-link-up
)
588 (:link-home nil org-export-html-link-home
)
589 (:language nil org-export-default-language
)
590 (:keywords nil org-export-page-keywords
)
591 (:description nil org-export-page-description
)
592 (:customtime nil org-display-custom-times
)
593 (:headline-levels
"H" org-export-headline-levels
)
594 (:section-numbers
"num" org-export-with-section-numbers
)
595 (:section-number-format nil org-export-section-number-format
)
596 (:table-of-contents
"toc" org-export-with-toc
)
597 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
598 (:archived-trees nil org-export-with-archived-trees
)
599 (:emphasize
"*" org-export-with-emphasize
)
600 (:sub-superscript
"^" org-export-with-sub-superscripts
)
601 (:special-strings
"-" org-export-with-special-strings
)
602 (:footnotes
"f" org-export-with-footnotes
)
603 (:drawers
"d" org-export-with-drawers
)
604 (:tags
"tags" org-export-with-tags
)
605 (:todo-keywords
"todo" org-export-with-todo-keywords
)
606 (:priority
"pri" org-export-with-priority
)
607 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
608 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
609 (:latex-listings nil org-export-latex-listings
)
610 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
611 (:fixed-width
":" org-export-with-fixed-width
)
612 (:timestamps
"<" org-export-with-timestamps
)
613 (:author-info
"author" org-export-author-info
)
614 (:email-info
"email" org-export-email-info
)
615 (:creator-info
"creator" org-export-creator-info
)
616 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
617 (:tables
"|" org-export-with-tables
)
618 (:table-auto-headline nil org-export-highlight-first-table-line
)
619 (:style-include-default nil org-export-html-style-include-default
)
620 (:style-include-scripts nil org-export-html-style-include-scripts
)
621 (:style nil org-export-html-style
)
622 (:style-extra nil org-export-html-style-extra
)
623 (:agenda-style nil org-agenda-export-html-style
)
624 (:convert-org-links nil org-export-html-link-org-files-as-html
)
625 (:inline-images nil org-export-html-inline-images
)
626 (:html-extension nil org-export-html-extension
)
627 (:xml-declaration nil org-export-html-xml-declaration
)
628 (:html-table-tag nil org-export-html-table-tag
)
629 (:expand-quoted-html
"@" org-export-html-expand
)
630 (:timestamp nil org-export-html-with-timestamp
)
631 (:publishing-directory nil org-export-publishing-directory
)
632 (:preamble nil org-export-html-preamble
)
633 (:postamble nil org-export-html-postamble
)
634 (:auto-preamble nil org-export-html-auto-preamble
)
635 (:auto-postamble nil org-export-html-auto-postamble
)
636 (:author nil user-full-name
)
637 (:email nil user-mail-address
)
638 (:select-tags nil org-export-select-tags
)
639 (:exclude-tags nil org-export-exclude-tags
)
641 (:latex-image-options nil org-export-latex-image-default-option
))
642 "List of properties that represent export/publishing variables.
643 Each element is a list of 3 items:
644 1. The property that is used internally, and also for org-publish-project-alist
645 2. The string that can be used in the OPTION lines to set this option,
646 or nil if this option cannot be changed in this way
647 3. The customization variable that sets the default for this option."
650 (defun org-default-export-plist ()
651 "Return the property list with default settings for the export variables."
652 (let* ((infile (org-infile-export-plist))
653 (letbind (plist-get infile
:let-bind
))
654 (l org-export-plist-vars
) rtn e s v
)
655 (while (setq e
(pop l
))
658 ((assq s letbind
) (nth 1 (assq s letbind
)))
659 ((boundp s
) (symbol-value s
))
661 rtn
(cons (car e
) (cons v rtn
))))
664 (defvar org-export-inbuffer-options-extra nil
665 "List of additional in-buffer options that should be detected.
666 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
667 etc. Extensions can add to this list to get their options detected, and they
668 can then add a function to `org-export-options-filters' to process these
670 Each element in this list must be a list, with the in-buffer keyword as car,
671 and a property (a symbol) as the next element. All occurrences of the
672 keyword will be found, the values concatenated with a space character
673 in between, and the result stored in the export options property list.")
675 (defvar org-export-options-filters nil
676 "Functions to be called to finalize the export/publishing options.
677 All these options are stored in a property list, and each of the functions
678 in this hook gets a chance to modify this property list. Each function
679 must accept the property list as an argument, and must return the (possibly
682 ;; FIXME: should we fold case here?
683 (defun org-infile-export-plist ()
684 "Return the property list with file-local settings for export."
688 (goto-char (point-min))
689 (let ((re (org-make-options-regexp
691 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
693 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
694 "LATEX_HEADER" "LATEX_CLASS"
695 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
696 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
697 (mapcar 'car org-export-inbuffer-options-extra
))))
699 p key val text options mathjax a pr style
700 latex-header latex-class macros letbind
701 ext-setup-or-nil setup-contents
(start 0))
702 (while (or (and ext-setup-or-nil
703 (string-match re ext-setup-or-nil start
)
704 (setq start
(match-end 0)))
705 (and (setq ext-setup-or-nil nil start
0)
706 (re-search-forward re nil t
)))
707 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
708 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
710 ((setq a
(assoc key org-export-inbuffer-options-extra
))
712 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
713 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
714 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
715 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
716 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
717 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
718 ((string-equal key
"DESCRIPTION")
719 (setq p
(plist-put p
:description val
)))
720 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
721 ((string-equal key
"STYLE")
722 (setq style
(concat style
"\n" val
)))
723 ((string-equal key
"LATEX_HEADER")
724 (setq latex-header
(concat latex-header
"\n" val
)))
725 ((string-equal key
"LATEX_CLASS")
726 (setq latex-class val
))
727 ((string-equal key
"TEXT")
728 (setq text
(if text
(concat text
"\n" val
) val
)))
729 ((string-equal key
"OPTIONS")
730 (setq options
(concat val
" " options
)))
731 ((string-equal key
"MATHJAX")
732 (setq mathjax
(concat val
" " mathjax
)))
733 ((string-equal key
"BIND")
734 (push (read (concat "(" val
")")) letbind
))
735 ((string-equal key
"XSLT")
736 (setq p
(plist-put p
:xslt val
)))
737 ((string-equal key
"LINK_UP")
738 (setq p
(plist-put p
:link-up val
)))
739 ((string-equal key
"LINK_HOME")
740 (setq p
(plist-put p
:link-home val
)))
741 ((string-equal key
"EXPORT_SELECT_TAGS")
742 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
743 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
744 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
745 ((string-equal key
"MACRO")
747 ((equal key
"SETUPFILE")
748 (setq setup-contents
(org-file-contents
750 (org-remove-double-quotes
753 (if (not ext-setup-or-nil
)
754 (setq ext-setup-or-nil setup-contents start
0)
755 (setq ext-setup-or-nil
756 (concat (substring ext-setup-or-nil
0 start
)
757 "\n" setup-contents
"\n"
758 (substring ext-setup-or-nil start
)))))))
759 (setq p
(plist-put p
:text text
))
760 (when (and letbind
(org-export-confirm-letbind))
761 (setq p
(plist-put p
:let-bind letbind
)))
762 (when style
(setq p
(plist-put p
:style-extra style
)))
764 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
766 (setq p
(plist-put p
:latex-class latex-class
)))
768 (setq p
(org-export-add-options-to-plist p options
)))
770 (setq p
(plist-put p
:mathjax mathjax
)))
771 ;; Add macro definitions
772 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
773 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
774 (setq p
(plist-put p
:macro-property
"(eval (org-entry-get nil \"$1\" 'selective))"))
776 p
:macro-modification-time
777 (and (buffer-file-name)
778 (file-exists-p (buffer-file-name))
780 "(eval (format-time-string \"$1\" '"
781 (prin1-to-string (nth 5 (file-attributes
782 (buffer-file-name))))
784 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
785 (file-name-nondirectory
786 (buffer-file-name)))))
787 (while (setq val
(pop macros
))
788 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
791 (concat ":macro-" (downcase (match-string 1 val
))))
792 (org-export-interpolate-newlines (match-string 2 val
))))))
795 (defun org-export-interpolate-newlines (s)
796 (while (string-match "\\\\n" s
)
797 (setq s
(replace-match "\n" t t s
)))
800 (defvar org-export-allow-BIND-local nil
)
801 (defun org-export-confirm-letbind ()
802 "Can we use #+BIND values during export?
803 By default this will ask fro confirmation by the user, to divert possible
806 ((not org-export-allow-BIND
) nil
)
807 ((eq org-export-allow-BIND t
) t
)
808 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
809 org-export-allow-BIND-local
)
810 (t (org-set-local 'org-export-allow-BIND-local
811 (yes-or-no-p "Allow BIND values in this buffer? ")))))
813 (defun org-install-letbind ()
814 "Install the values from #+BIND lines as local variables."
815 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
817 (while (setq pair
(pop letbind
))
818 (org-set-local (car pair
) (nth 1 pair
)))))
820 (defun org-export-add-options-to-plist (p options
)
821 "Parse an OPTIONS line and set values in the property list P."
824 (let ((op org-export-plist-vars
))
825 (while (setq o
(pop op
))
827 (string-match (concat (regexp-quote (nth 1 o
))
828 ":\\([^ \t\n\r;,.]*\\)")
830 (setq p
(plist-put p
(car o
)
831 (car (read-from-string
832 (match-string 1 options
))))))))))
835 (defun org-export-add-subtree-options (p pos
)
836 "Add options in subtree at position POS to property list P."
839 (when (org-at-heading-p)
841 ;; This is actually read in `org-export-get-title-from-subtree'
842 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
843 ;; (setq p (plist-put p :title a)))
844 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
845 (setq p
(plist-put p
:text a
)))
846 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
847 (setq p
(plist-put p
:author a
)))
848 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
849 (setq p
(plist-put p
:date a
)))
850 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
851 (setq p
(org-export-add-options-to-plist p a
)))))
854 (defun org-export-directory (type plist
)
855 (let* ((val (plist-get plist
:publishing-directory
))
857 (or (cdr (assoc type val
)) ".")
861 (defun org-export-process-option-filters (plist)
862 (let ((functions org-export-options-filters
) f
)
863 (while (setq f
(pop functions
))
864 (setq plist
(funcall f plist
))))
868 (defun org-export (&optional arg
)
869 "Export dispatcher for Org-mode.
870 When `org-export-run-in-background' is non-nil, try to run the command
871 in the background. This will be done only for commands that write
872 to a file. For details see the docstring of `org-export-run-in-background'.
874 The prefix argument ARG will be passed to the exporter. However, if
875 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
876 that means to inverse the
877 value of `org-export-run-in-background'."
879 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
881 (help "[t] insert the export option template
882 \[v] limit export to visible part of outline tree
883 \[1] only export the current subtree
884 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
886 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
888 \[h] export as HTML [H] to temporary buffer [R] export region
889 \[b] export as HTML and open in browser
891 \[l] export as LaTeX [L] to temporary buffer
892 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
894 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
896 \[j] export as TaskJuggler [J] ... and open
898 \[m] export as Freemind mind map
900 \[g] export using Wes Hardaker's generic exporter
902 \[i] export current file as iCalendar file
903 \[I] export all agenda files as iCalendar files [c] ...as one combined file
905 \[F] publish current file [P] publish current project
906 \[X] publish a project... [E] publish every projects")
908 '((?t org-insert-export-options-template nil
)
909 (?v org-export-visible nil
)
910 (?a org-export-as-ascii t
)
911 (?A org-export-as-ascii-to-buffer t
)
912 (?n org-export-as-latin1 t
)
913 (?N org-export-as-latin1-to-buffer t
)
914 (?u org-export-as-utf8 t
)
915 (?U org-export-as-utf8-to-buffer t
)
916 (?h org-export-as-html t
)
917 (?b org-export-as-html-and-open t
)
918 (?H org-export-as-html-to-buffer nil
)
919 (?R org-export-region-as-html nil
)
920 (?x org-export-as-xoxo t
)
921 (?g org-export-generic t
)
922 (?D org-export-as-docbook t
)
923 (?V org-export-as-docbook-pdf-and-open t
)
924 (?j org-export-as-taskjuggler t
)
925 (?J org-export-as-taskjuggler-and-open t
)
926 (?m org-export-as-freemind t
)
927 (?l org-export-as-latex t
)
928 (?p org-export-as-pdf t
)
929 (?d org-export-as-pdf-and-open t
)
930 (?L org-export-as-latex-to-buffer nil
)
931 (?i org-export-icalendar-this-file t
)
932 (?I org-export-icalendar-all-agenda-files t
)
933 (?c org-export-icalendar-combine-agenda-files t
)
934 (?F org-publish-current-file t
)
935 (?P org-publish-current-project t
)
937 (?E org-publish-all t
)))
939 (cpos (point)) (cbuf (current-buffer)) bpos
)
941 (save-window-excursion
942 (delete-other-windows)
943 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
945 (org-fit-window-to-buffer (get-buffer-window
946 "*Org Export/Publishing Help*"))
947 (message "Select command: ")
948 (setq r1
(read-char-exclusive))
951 (message "Select command (for subtree): ")
952 (setq r1
(read-char-exclusive)))
954 (let ((case-fold-search t
))
955 (if (re-search-backward
956 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
959 (org-back-to-heading t
)
962 (message "Select command (for subtree): ")
963 (setq r1
(read-char-exclusive)))
964 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
966 (and bpos
(goto-char bpos
))
967 (setq r2
(if (< r1
27) (+ r1
96) r1
))
968 (unless (setq ass
(assq r2 cmds
))
969 (error "No command associated with key %c" r1
))
970 (if (and bg
(nth 2 ass
)
971 (not (buffer-base-buffer))
972 (not (org-region-active-p)))
973 ;; execute in background
974 (let ((p (start-process
975 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
977 (expand-file-name invocation-name invocation-directory
)
980 "--eval" "(require 'org-exp)"
981 "--eval" "(setq org-wait .2)"
983 "-f" (symbol-name (nth 1 ass
)))))
984 (set-process-sentinel p
'org-export-process-sentinel
)
985 (message "Background process \"%s\": started" p
))
986 ;; background processing not requested, or not possible
987 (if subtree-p
(progn (outline-mark-subtree) (activate-mark)))
988 (call-interactively (nth 1 ass
))
989 (when (and bpos
(get-buffer-window cbuf
))
990 (let ((cw (selected-window)))
991 (select-window (get-buffer-window cbuf
))
994 (select-window cw
))))))
996 (defun org-export-process-sentinel (process status
)
997 (if (string-match "\n+\\'" status
)
998 (setq status
(substring status
0 -
1)))
999 (message "Background process \"%s\": %s" process status
))
1001 ;;; General functions for all backends
1003 (defvar org-export-target-aliases nil
1004 "Alist of targets with invisible aliases.")
1005 (defvar org-export-preferred-target-alist nil
1006 "Alist of section id's with preferred aliases.")
1007 (defvar org-export-id-target-alist nil
1008 "Alist of section id's with preferred aliases.")
1009 (defvar org-export-code-refs nil
1010 "Alist of code references and line numbers.")
1012 (defun org-export-preprocess-string (string &rest parameters
)
1013 "Cleanup STRING so that that the true exported has a more consistent source.
1014 This function takes STRING, which should be a buffer-string of an org-file
1015 to export. It then creates a temporary buffer where it does its job.
1016 The result is then again returned as a string, and the exporter works
1017 on this string to produce the exported version."
1019 (let* ((htmlp (plist-get parameters
:for-html
))
1020 (asciip (plist-get parameters
:for-ascii
))
1021 (latexp (plist-get parameters
:for-LaTeX
))
1022 (docbookp (plist-get parameters
:for-docbook
))
1023 (backend (cond (htmlp 'html
)
1026 (docbookp 'docbook
)))
1027 (archived-trees (plist-get parameters
:archived-trees
))
1028 (inhibit-read-only t
)
1029 (drawers org-drawers
)
1030 (outline-regexp "\\*+ ")
1033 (setq org-export-target-aliases nil
1034 org-export-preferred-target-alist nil
1035 org-export-id-target-alist nil
1036 org-export-code-refs nil
)
1038 (with-current-buffer (get-buffer-create " org-mode-tmp")
1041 (setq case-fold-search t
)
1043 (let ((inhibit-read-only t
))
1044 (remove-text-properties (point-min) (point-max)
1047 ;; Remove license-to-kill stuff
1048 ;; The caller marks some stuff for killing, stuff that has been
1049 ;; used to create the page title, for example.
1050 (org-export-kill-licensed-text)
1052 (let ((org-inhibit-startup t
)) (org-mode))
1053 (setq case-fold-search t
)
1054 (org-install-letbind)
1057 (run-hooks 'org-export-preprocess-hook
)
1059 ;; Process the macros
1060 (org-export-preprocess-apply-macros)
1061 (run-hooks 'org-export-preprocess-after-macros-hook
)
1063 (untabify (point-min) (point-max))
1065 ;; Handle include files, and call a hook
1066 (org-export-handle-include-files-recurse)
1067 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1069 ;; Get rid of archived trees
1070 (org-export-remove-archived-trees archived-trees
)
1072 ;; Remove comment environment and comment subtrees
1073 (org-export-remove-comment-blocks-and-subtrees)
1075 ;; Get rid of excluded trees, and call a hook
1076 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1077 (plist-get parameters
:exclude-tags
))
1078 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1080 ;; Mark end of lists
1081 (org-export-mark-list-ending backend
)
1083 ;; Export code blocks
1084 (org-export-blocks-preprocess)
1086 ;; Handle source code snippets
1087 (org-export-replace-src-segments-and-examples backend
)
1089 ;; Protect short examples marked by a leading colon
1090 (org-export-protect-colon-examples)
1093 (org-export-convert-protected-spaces backend
)
1095 ;; Normalize footnotes
1096 (when (plist-get parameters
:footnotes
)
1097 (org-footnote-normalize nil t
))
1099 ;; Find all headings and compute the targets for them
1100 (setq target-alist
(org-export-define-heading-targets target-alist
))
1102 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1104 ;; Find HTML special classes for headlines
1105 (org-export-remember-html-container-classes)
1107 ;; Get rid of drawers
1108 (org-export-remove-or-extract-drawers
1109 drawers
(plist-get parameters
:drawers
) backend
)
1111 ;; Get the correct stuff before the first headline
1112 (when (plist-get parameters
:skip-before-1st-heading
)
1113 (goto-char (point-min))
1114 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1115 (delete-region (point-min) (match-beginning 0))
1116 (goto-char (point-min))
1118 (when (plist-get parameters
:add-text
)
1119 (goto-char (point-min))
1120 (insert (plist-get parameters
:add-text
) "\n"))
1122 ;; Remove todo-keywords before exporting, if the user has requested so
1123 (org-export-remove-headline-metadata parameters
)
1125 ;; Find targets in comments and move them out of comments,
1126 ;; but mark them as targets that should be invisible
1127 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1129 ;; Select and protect backend specific stuff, throw away stuff
1130 ;; that is specific for other backends
1131 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1132 (org-export-select-backend-specific-text backend
)
1134 ;; Protect quoted subtrees
1135 (org-export-protect-quoted-subtrees)
1137 ;; Remove clock lines
1138 (org-export-remove-clock-lines)
1140 ;; Protect verbatim elements
1141 (org-export-protect-verbatim)
1143 ;; Blockquotes, verse, and center
1144 (org-export-mark-blockquote-verse-center)
1145 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1147 ;; Remove timestamps, if the user has requested so
1148 (unless (plist-get parameters
:timestamps
)
1149 (org-export-remove-timestamps))
1151 ;; Attach captions to the correct object
1152 (setq target-alist
(org-export-attach-captions-and-attributes
1153 backend target-alist
))
1155 ;; Find matches for radio targets and turn them into internal links
1156 (org-export-mark-radio-links)
1157 (run-hooks 'org-export-preprocess-after-radio-targets-hook
)
1159 ;; Find all links that contain a newline and put them into a single line
1160 (org-export-concatenate-multiline-links)
1162 ;; Normalize links: Convert angle and plain links into bracket links
1163 ;; and expand link abbreviations
1164 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1165 (org-export-normalize-links)
1167 ;; Find all internal links. If they have a fuzzy match (i.e. not
1168 ;; a *dedicated* target match, let the link point to the
1169 ;; corresponding section.
1170 (org-export-target-internal-links target-alist
)
1172 ;; Find multiline emphasis and put them into single line
1173 (when (plist-get parameters
:emph-multiline
)
1174 (org-export-concatenate-multiline-emphasis))
1176 ;; Remove special table lines, and store alignment information
1177 (org-store-forced-table-alignment)
1178 (when org-export-table-remove-special-lines
1179 (org-export-remove-special-table-lines))
1182 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1184 ;; LaTeX-specific preprocessing
1186 (require 'org-latex nil
)
1187 (org-export-latex-preprocess parameters
))
1189 ;; ASCII-specific preprocessing
1191 (org-export-ascii-preprocess parameters
))
1193 ;; HTML-specific preprocessing
1195 (org-export-html-preprocess parameters
))
1197 ;; DocBook-specific preprocessing
1199 (require 'org-docbook nil
)
1200 (org-export-docbook-preprocess parameters
))
1202 ;; Remove or replace comments
1203 (org-export-handle-comments (plist-get parameters
:comments
))
1205 ;; Remove #+TBLFM and #+TBLNAME lines
1206 (org-export-handle-table-metalines)
1208 ;; Run the final hook
1209 (run-hooks 'org-export-preprocess-final-hook
)
1211 (setq rtn
(buffer-string)))
1212 (kill-buffer " org-mode-tmp")
1215 (defun org-export-kill-licensed-text ()
1216 "Remove all text that is marked with a :org-license-to-kill property."
1218 (while (setq p
(text-property-any (point-min) (point-max)
1219 :org-license-to-kill t
))
1221 p
(or (next-single-property-change p
:org-license-to-kill
)
1224 (defvar org-export-define-heading-targets-headline-hook nil
1225 "Hook that is run when a headline was matched during target search.
1226 This is part of the preprocessing for export.")
1228 (defun org-export-define-heading-targets (target-alist)
1229 "Find all headings and define the targets for them.
1230 The new targets are added to TARGET-ALIST, which is also returned.
1231 Also find all ID and CUSTOM_ID properties and store them."
1232 (goto-char (point-min))
1233 (org-init-section-numbers)
1234 (let ((re (concat "^" org-outline-regexp
1236 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1237 level target last-section-target a id
)
1238 (while (re-search-forward re nil t
)
1239 (org-if-unprotected-at (match-beginning 0)
1242 (setq id
(org-match-string-no-properties 2))
1243 (push (cons id target
) target-alist
)
1244 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1246 (push (list last-section-target
)
1247 org-export-target-aliases
)
1248 (car org-export-target-aliases
))))
1249 (push (caar target-alist
) (cdr a
))
1250 (when (equal (match-string 1) "CUSTOM_ID")
1251 (if (not (assoc last-section-target
1252 org-export-preferred-target-alist
))
1253 (push (cons last-section-target id
)
1254 org-export-preferred-target-alist
)))
1255 (when (equal (match-string 1) "ID")
1256 (if (not (assoc last-section-target
1257 org-export-id-target-alist
))
1258 (push (cons last-section-target
(concat "ID-" id
))
1259 org-export-id-target-alist
))))
1260 (setq level
(org-reduced-level
1261 (save-excursion (goto-char (point-at-bol))
1262 (org-outline-level))))
1263 (setq target
(org-solidify-link-text
1264 (format "sec-%s" (replace-regexp-in-string
1266 (org-section-number level
)))))
1267 (setq last-section-target target
)
1268 (push (cons target target
) target-alist
)
1269 (add-text-properties
1270 (point-at-bol) (point-at-eol)
1271 (list 'target target
))
1272 (run-hooks 'org-export-define-heading-targets-headline-hook
)))))
1275 (defun org-export-handle-invisible-targets (target-alist)
1276 "Find targets in comments and move them out of comments.
1277 Mark them as invisible targets."
1279 (goto-char (point-min))
1280 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1281 ;; Check if the line before or after is a headline with a target
1282 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1283 (get-text-property (point-at-bol 2) 'target
)))
1285 ;; use the existing target in a neighboring line
1286 (setq tmp
(match-string 2))
1288 (and (looking-at "\n") (delete-char 1))
1289 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1291 (setq a
(or (assoc target org-export-target-aliases
)
1293 (push (list target
) org-export-target-aliases
)
1294 (car org-export-target-aliases
))))
1296 ;; Make an invisible target
1297 (replace-match "\\1(INVISIBLE)"))))
1300 (defun org-export-target-internal-links (target-alist)
1301 "Find all internal links and assign targets to them.
1302 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1303 let the link point to the corresponding section.
1304 This function also handles the id links, if they have a match in
1306 (goto-char (point-min))
1307 (while (re-search-forward org-bracket-link-regexp nil t
)
1308 (org-if-unprotected-at (1+ (match-beginning 0))
1309 (let* ((md (match-data))
1310 (desc (match-end 2))
1311 (link (org-link-unescape (match-string 1)))
1312 (slink (org-solidify-link-text link
))
1313 found props pos cref
1316 ((= (string-to-char link
) ?
#)
1317 ;; user wants exactly this link
1319 ((cdr (assoc slink target-alist
))
1320 (or (cdr (assoc (assoc slink target-alist
)
1321 org-export-preferred-target-alist
))
1322 (cdr (assoc slink target-alist
))))
1323 ((and (string-match "^id:" link
)
1324 (cdr (assoc (substring link
3) target-alist
))))
1325 ((string-match "^(\\(.*\\))$" link
)
1326 (setq cref
(match-string 1 link
))
1327 (concat "coderef:" cref
))
1328 ((string-match org-link-types-re link
) nil
)
1329 ((or (file-name-absolute-p link
)
1330 (string-match "^\\." link
))
1333 (let ((org-link-search-inhibit-query t
))
1335 (setq found
(condition-case nil
(org-link-search link
)
1338 (or (org-on-heading-p)
1339 (not (eq found
'dedicated
))))
1340 (or (get-text-property (point) 'target
)
1343 (1- (or (previous-single-property-change
1344 (point) 'target
) 0)))
1348 (goto-char (match-beginning 1))
1349 (setq props
(text-properties-at (point)))
1350 (delete-region (match-beginning 1) (match-end 1))
1353 (unless desc
(insert "][" link
))
1354 (add-text-properties pos
(point) props
))))))
1356 (defun org-export-remember-html-container-classes ()
1357 "Store the HTML_CONTAINER_CLASS properties in a text property."
1358 (goto-char (point-min))
1360 (while (re-search-forward
1361 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t
)
1362 (setq class
(match-string 1))
1364 (org-back-to-heading t
)
1365 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1367 (defvar org-export-format-drawer-function nil
1368 "Function to be called to format the contents of a drawer.
1369 The function must accept three parameters:
1370 NAME the drawer name, like \"PROPERTIES\"
1371 CONTENT the content of the drawer.
1372 BACKEND one of the symbols html, docbook, latex, ascii, xoxo
1373 The function should return the text to be inserted into the buffer.
1374 If this is nil, `org-export-format-drawer' is used as a default.")
1376 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend
)
1377 "Remove drawers, or extract and format the content.
1378 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1379 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1380 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1381 EXP-DRAWERS will be removed.
1382 BACKEND is the current export backend."
1383 (goto-char (point-min))
1384 (let ((re (concat "^[ \t]*:\\("
1385 (mapconcat 'identity all-drawers
"\\|")
1387 name beg beg-content eol content
)
1388 (while (re-search-forward re nil t
)
1390 (setq name
(match-string 1))
1391 (setq beg
(match-beginning 0)
1392 beg-content
(1+ (point-at-eol))
1394 (if (not (and (re-search-forward
1395 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1398 (goto-char (match-beginning 0))
1399 (and (looking-at ".*\n?") (replace-match ""))
1400 (setq content
(buffer-substring beg-content
(point)))
1401 (delete-region beg
(point))
1402 (when (or (eq exp-drawers t
)
1403 (member name exp-drawers
))
1404 (setq content
(funcall (or org-export-format-drawer-function
1405 'org-export-format-drawer
)
1406 name content backend
))
1407 (insert content
)))))))
1409 (defun org-export-format-drawer (name content backend
)
1410 "Format the content of a drawer as a colon example."
1411 (if (string-match "[ \t]+\\'" content
)
1412 (setq content
(substring content
(match-beginning 0))))
1413 (while (string-match "\\`[ \t]*\n" content
)
1414 (setq content
(substring content
(match-end 0))))
1415 (setq content
(org-remove-indentation content
))
1416 (setq content
(concat ": " (mapconcat 'identity
1417 (org-split-string content
"\n")
1420 (setq content
(concat " : " (upcase name
) "\n" content
))
1421 (org-add-props content nil
'org-protected t
))
1423 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1424 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1425 Both arguments are lists of tags.
1426 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1428 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1430 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1431 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1434 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1438 (goto-char (point-min))
1439 (when (and select-tags
1441 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1442 ;; At least one tree is marked for export, this means
1443 ;; all the unmarked stuff needs to go.
1444 ;; Dig out the trees that should be exported
1445 (goto-char (point-min))
1446 (outline-next-heading)
1448 (put-text-property beg
(point-max) :org-delete t
)
1449 (while (re-search-forward re-sel nil t
)
1450 (when (org-on-heading-p)
1451 (org-back-to-heading)
1452 (remove-text-properties
1453 (max (1- (point)) (point-min))
1454 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1456 (while (and (org-up-heading-safe)
1457 (get-text-property (point) :org-delete
))
1458 (remove-text-properties (max (1- (point)) (point-min))
1459 (point-at-eol) '(:org-delete t
)))
1461 ;; Remove the trees explicitly marked for noexport
1463 (goto-char (point-min))
1464 (while (re-search-forward re-excl nil t
)
1465 (when (org-at-heading-p)
1466 (org-back-to-heading t
)
1468 (org-end-of-subtree t t
)
1469 (delete-region beg
(point))
1470 (when (featurep 'org-inlinetask
)
1471 (org-inlinetask-remove-END-maybe)))))
1472 ;; Remove everything that is now still marked for deletion
1473 (goto-char (point-min))
1474 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1475 (setq end
(or (next-single-property-change beg
:org-delete
)
1477 (delete-region beg end
))))
1479 (defun org-export-remove-archived-trees (export-archived-trees)
1480 "Remove archived trees.
1481 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1482 When it is t, the entire archived tree will be exported.
1483 When it is nil the entire tree including the headline will be removed
1485 (let ((re-archive (concat ":" org-archive-tag
":"))
1487 (when (not (eq export-archived-trees t
))
1488 (goto-char (point-min))
1489 (while (re-search-forward re-archive nil t
)
1490 (if (not (org-on-heading-p t
))
1491 (goto-char (point-at-eol))
1492 (beginning-of-line 1)
1493 (setq a
(if export-archived-trees
1494 (1+ (point-at-eol)) (point))
1495 b
(org-end-of-subtree t
))
1496 (if (> b a
) (delete-region a b
)))))))
1498 (defun org-export-remove-headline-metadata (opts)
1499 "Remove meta data from the headline, according to user options."
1500 (let ((re org-complex-heading-regexp
)
1501 (todo (plist-get opts
:todo-keywords
))
1502 (tags (plist-get opts
:tags
))
1503 (pri (plist-get opts
:priority
))
1506 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1507 (when (or (not todo
) (not tags
) (not pri
))
1508 (goto-char (point-min))
1509 (while (re-search-forward re nil t
)
1511 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1513 (replace-match rpl t t
))))))
1515 (defun org-export-remove-timestamps ()
1516 "Remove timestamps and keywords for export."
1517 (goto-char (point-min))
1518 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1521 (unless (save-match-data (org-at-table-p))
1523 (beginning-of-line 1)
1524 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1525 (replace-match ""))))))
1527 (defun org-export-remove-clock-lines ()
1528 "Remove clock lines for export."
1529 (goto-char (point-min))
1530 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1531 (while (re-search-forward re nil t
)
1533 (replace-match "")))))
1535 (defun org-export-protect-quoted-subtrees ()
1536 "Mark quoted subtrees with the protection property."
1537 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1538 (goto-char (point-min))
1539 (while (re-search-forward re-quote nil t
)
1540 (goto-char (match-beginning 0))
1542 (add-text-properties (point) (org-end-of-subtree t
)
1543 '(org-protected t
)))))
1545 (defun org-export-convert-protected-spaces (backend)
1546 "Convert strings like \\____ to protected spaces in all backends."
1547 (goto-char (point-min))
1548 (while (re-search-forward "\\\\__+" nil t
)
1549 (org-if-unprotected-1
1553 ((eq backend
'latex
)
1554 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1556 (org-add-props (match-string 0) nil
1557 'org-whitespace
(- (match-end 0) (match-beginning 0))))
1558 ;; ((eq backend 'docbook))
1559 ((eq backend
'ascii
)
1560 (org-add-props (match-string 0) '(org-whitespace t
)))
1561 (t (make-string (- (match-end 0) (match-beginning 0)) ?\
)))
1565 (defun org-export-protect-verbatim ()
1566 "Mark verbatim snippets with the protection property."
1567 (goto-char (point-min))
1568 (while (re-search-forward org-verbatim-re nil t
)
1570 (add-text-properties (match-beginning 4) (match-end 4)
1571 '(org-protected t org-verbatim-emph t
))
1572 (goto-char (1+ (match-end 4))))))
1574 (defun org-export-protect-colon-examples ()
1575 "Protect lines starting with a colon."
1576 (goto-char (point-min))
1577 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1578 (while (re-search-forward re nil t
)
1579 (beginning-of-line 1)
1581 (while (looking-at re
)
1583 (or (eobp) (forward-char 1)))
1584 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1585 '(org-protected t
)))))
1587 (defun org-export-select-backend-specific-text (backend)
1589 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1590 (html "HTML" "BEGIN_HTML" "END_HTML")
1591 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1592 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1593 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1594 (case-fold-search t
)
1595 fmt beg beg-content end end-content
)
1598 (setq fmt
(pop formatters
))
1599 ;; Handle #+Backend: stuff
1600 (goto-char (point-min))
1601 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1602 ":[ \t]*\\(.*\\)") nil t
)
1603 (if (not (eq (car fmt
) backend
))
1604 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1605 (replace-match "\\1\\2" t
)
1606 (add-text-properties
1607 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1608 '(org-protected t
))))
1609 ;; Delete #+attr_Backend: stuff of another backend. Those
1610 ;; matching the current backend will be taken care of by
1611 ;; `org-export-attach-captions-and-attributes'
1612 (goto-char (point-min))
1613 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt
)
1614 ":[ \t]*\\(.*\\)") nil t
)
1615 (when (not (eq (car fmt
) backend
))
1616 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1617 ;; Handle #+begin_Backend and #+end_Backend stuff
1618 (goto-char (point-min))
1619 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt
) "\\>.*\n?")
1621 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1622 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt
) "\\>.*\n?")
1624 (setq end
(match-end 0) end-content
(match-beginning 0))
1625 (if (eq (car fmt
) backend
)
1628 (add-text-properties beg-content end-content
'(org-protected t
))
1629 (delete-region (match-beginning 0) (match-end 0))
1632 (delete-region (point) (1+ (point-at-eol)))))
1633 ;; No, this is for a different backend, kill it
1634 (delete-region beg end
)))))))
1636 (defun org-export-mark-blockquote-verse-center ()
1637 "Mark block quote and verse environments with special cookies.
1638 These special cookies will later be interpreted by the backend."
1640 (let (type t1 ind beg end beg1 end1 content
)
1641 (goto-char (point-min))
1642 (while (re-search-forward
1643 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1645 (setq ind
(length (match-string 1))
1646 type
(downcase (match-string 3))
1647 t1
(if (equal type
"quote") "blockquote" type
))
1648 (setq beg
(match-beginning 0)
1649 beg1
(1+ (match-end 0)))
1650 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1651 (setq end1
(1- (match-beginning 0))
1652 end
(+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1653 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1654 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1656 "ORG-" (upcase t1
) "-END\n"))
1657 (delete-region beg end
)
1658 (insert (org-add-props content nil
'original-indentation ind
))))))
1660 (defun org-export-mark-list-ending (backend)
1661 "Mark list endings with special cookies.
1662 These special cookies will later be interpreted by the backend.
1663 `org-list-end-re' is replaced by a blank line in the process."
1664 (let ((process-buffer
1665 (lambda (end-list-marker)
1666 (goto-char (point-min))
1667 (while (org-search-forward-unenclosed org-item-beginning-re nil t
)
1668 (goto-char (org-list-bottom-point))
1669 (when (and (not (eq org-list-ending-method
'indent
))
1670 (looking-at (org-list-end-re)))
1671 (replace-match "\n"))
1672 (insert end-list-marker
)))))
1673 ;; We need to divide backends into 3 categories.
1675 ;; 1. Backends using `org-list-parse-list' do not need markers.
1676 ((memq backend
'(latex))
1678 ;; 2. Line-processing backends need to be told where lists end.
1679 ((memq backend
'(html docbook
))
1680 (funcall process-buffer
"ORG-LIST-END\n"))
1681 ;; 3. Others backends do not need to know this: clean list enders.
1683 (funcall process-buffer
"")))))
1685 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1686 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1687 If the next thing following is a table, add the text properties to the first
1688 table line. If it is a link, add it to the line containing the link."
1689 (goto-char (point-min))
1690 (remove-text-properties (point-min) (point-max)
1691 '(org-caption nil org-attributes nil
))
1692 (let ((case-fold-search t
)
1693 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1695 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1697 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1699 "^[ \t]*\\(|[^-]\\)"
1701 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1702 cap shortn attr label end
)
1703 (while (re-search-forward re nil t
)
1707 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1))))
1708 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap
)
1709 (setq shortn
(match-string 1 cap
)
1710 cap
(match-string 2 cap
)))
1711 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1714 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2))))
1715 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1718 (setq label
(org-trim (match-string 3)))
1719 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1721 (setq end
(if (match-end 4)
1722 (let ((ee (org-table-end)))
1723 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1725 (add-text-properties (point-at-bol) end
1726 (list 'org-caption cap
1727 'org-caption-shortn shortn
1728 'org-attributes attr
1730 (if label
(push (cons label label
) target-alist
))
1732 (setq cap nil attr nil label nil
)))))
1735 (defun org-export-remove-comment-blocks-and-subtrees ()
1736 "Remove the comment environment, and also commented subtrees."
1737 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1739 ;; Remove comment environment
1740 (goto-char (point-min))
1741 (setq case-fold-search t
)
1742 (while (re-search-forward
1743 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t
)
1744 (replace-match "" t t
))
1745 ;; Remove subtrees that are commented
1746 (goto-char (point-min))
1747 (setq case-fold-search nil
)
1748 (while (re-search-forward re-commented nil t
)
1749 (goto-char (match-beginning 0))
1750 (delete-region (point) (org-end-of-subtree t
)))))
1752 (defun org-export-handle-comments (commentsp)
1753 "Remove comments, or convert to backend-specific format.
1754 COMMENTSP can be a format string for publishing comments.
1755 When it is nil, all comments will be removed."
1756 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1758 (goto-char (point-min))
1759 (while (or (looking-at re
)
1760 (re-search-forward re nil t
))
1761 (setq pos
(match-beginning 0))
1762 (if (get-text-property pos
'org-protected
)
1763 (goto-char (1+ pos
))
1765 (not (equal (char-before (match-end 1)) ?
+)))
1766 (progn (add-text-properties
1767 (match-beginning 0) (match-end 0) '(org-protected t
))
1768 (replace-match (format commentsp
(match-string 2)) t t
))
1769 (goto-char (1+ pos
))
1771 (goto-char (max (point-min) (1- pos
))))))))
1773 (defun org-export-handle-table-metalines ()
1774 "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
1775 (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
1777 (goto-char (point-min))
1778 (while (or (looking-at re
)
1779 (re-search-forward re nil t
))
1780 (setq pos
(match-beginning 0))
1781 (if (get-text-property (match-beginning 1) 'org-protected
)
1782 (goto-char (1+ pos
))
1783 (goto-char (1+ pos
))
1785 (goto-char (max (point-min) (1- pos
)))))))
1787 (defun org-export-mark-radio-links ()
1788 "Find all matches for radio targets and turn them into internal links."
1789 (let ((re-radio (and org-target-link-regexp
1790 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1791 (goto-char (point-min))
1793 (while (re-search-forward re-radio nil t
)
1796 (or (org-in-regexp org-bracket-link-regexp
)
1797 (org-in-regexp org-plain-link-re
)
1798 (org-in-regexp "<<[^<>]+>>")))
1800 (replace-match "\\1[[\\2]]")))))))
1802 (defun org-store-forced-table-alignment ()
1803 "Find table lines which force alignment, store the results in properties."
1804 (let (line cnt aligns
)
1805 (goto-char (point-min))
1806 (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t
)
1807 ;; OK, this looks like a table line with an alignment cookie
1809 (setq line
(buffer-substring (point-at-bol) (point-at-eol)))
1810 (when (and (org-at-table-p)
1811 (org-table-cookie-line-p line
))
1812 (setq cnt
0 aligns nil
)
1816 (if (string-match "\\`<\\([lrc]\\)" x
)
1817 (push (cons cnt
(downcase (match-string 1 x
))) aligns
)))
1818 (org-split-string line
"[ \t]*|[ \t]*"))
1819 (add-text-properties (org-table-begin) (org-table-end)
1820 (list 'org-forced-aligns aligns
))))
1821 (goto-char (point-at-eol)))))
1823 (defun org-export-remove-special-table-lines ()
1824 "Remove tables lines that are used for internal purposes.
1825 Also, store forcedalignment information found in such lines."
1826 (goto-char (point-min))
1827 (while (re-search-forward "^[ \t]*|" nil t
)
1828 (org-if-unprotected-at (1- (point))
1829 (beginning-of-line 1)
1830 (if (or (looking-at "[ \t]*| *[!_^] *|")
1836 (or (= (length f
) 0)
1838 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f
)))
1839 (org-split-string ;; FIXME, can't we do without splitting???
1840 (buffer-substring (point-at-bol) (point-at-eol))
1841 "[ \t]*|[ \t]*")))))
1842 (delete-region (max (point-min) (1- (point-at-bol)))
1846 (defun org-export-protect-sub-super (s)
1848 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
1849 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
1852 (defun org-export-normalize-links ()
1853 "Convert all links to bracket links, and expand link abbreviations."
1854 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1855 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1857 (goto-char (point-min))
1858 (while (re-search-forward re-plain-link nil t
)
1859 (unless (org-string-match-p
1860 "\\[\\[\\S+:\\S-*?\\<"
1861 (buffer-substring (point-at-bol) (match-beginning 0)))
1862 (goto-char (1- (match-end 0)))
1863 (org-if-unprotected-at (1+ (match-beginning 0))
1864 (let* ((s (concat (match-string 1)
1865 "[[" (match-string 2) ":" (match-string 3)
1866 "][" (match-string 2) ":" (org-export-protect-sub-super
1869 ;; added 'org-link face to links
1870 (put-text-property 0 (length s
) 'face
'org-link s
)
1871 (replace-match s t t
)))))
1872 (goto-char (point-min))
1873 (while (re-search-forward re-angle-link nil t
)
1874 (goto-char (1- (match-end 0)))
1876 (let* ((s (concat (match-string 1)
1877 "[[" (match-string 2) ":" (match-string 3)
1878 "][" (match-string 2) ":" (org-export-protect-sub-super
1881 (put-text-property 0 (length s
) 'face
'org-link s
)
1882 (replace-match s t t
))))
1883 (goto-char (point-min))
1884 (while (re-search-forward org-bracket-link-regexp nil t
)
1885 (goto-char (1- (match-end 0)))
1886 (setq nodesc
(not (match-end 3)))
1888 (let* ((xx (save-match-data
1890 (org-link-expand-abbrev (match-string 1)))))
1892 "[[" (org-add-props (copy-sequence xx
)
1893 nil
'org-protected t
'org-no-description nodesc
)
1897 (concat "[" (copy-sequence xx
)
1900 (put-text-property 0 (length s
) 'face
'org-link s
)
1901 (replace-match s t t
))))))
1903 (defun org-export-concatenate-multiline-links ()
1904 "Find multi-line links and put it all into a single line.
1905 This is to make sure that the line-processing export backends
1906 can work correctly."
1907 (goto-char (point-min))
1908 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1909 (org-if-unprotected-at (match-beginning 1)
1910 (replace-match "\\1 \\3")
1911 (goto-char (match-beginning 0)))))
1913 (defun org-export-concatenate-multiline-emphasis ()
1914 "Find multi-line emphasis and put it all into a single line.
1915 This is to make sure that the line-processing export backends
1916 can work correctly."
1917 (goto-char (point-min))
1918 (while (re-search-forward org-emph-re nil t
)
1919 (if (and (not (= (char-after (match-beginning 3))
1920 (char-after (match-beginning 4))))
1921 (save-excursion (goto-char (match-beginning 0))
1923 (and (not (org-at-table-p))
1924 (not (org-at-heading-p))))))
1926 (subst-char-in-region (match-beginning 0) (match-end 0)
1928 (goto-char (1- (match-end 0))))
1929 (goto-char (1+ (match-beginning 0))))))
1931 (defun org-export-grab-title-from-buffer ()
1932 "Get a title for the current document, from looking at the buffer."
1933 (let ((inhibit-read-only t
))
1935 (goto-char (point-min))
1936 (let ((end (if (looking-at org-outline-regexp
)
1938 (save-excursion (outline-next-heading) (point)))))
1939 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1940 ;; Mark the line so that it will not be exported as normal text.
1942 (add-text-properties (match-beginning 0) (match-end 0)
1943 (list :org-license-to-kill t
)))
1944 ;; Return the title string
1945 (org-trim (match-string 0)))))))
1947 (defun org-export-get-title-from-subtree ()
1948 "Return subtree title and exclude it from export."
1949 (let (title (rbeg (region-beginning)) (rend (region-end)))
1952 (when (and (org-at-heading-p)
1953 (>= (org-end-of-subtree t t
) rend
))
1954 ;; This is a subtree, we take the title from the first heading
1956 (looking-at org-todo-line-regexp
)
1957 (setq title
(match-string 3))
1959 (add-text-properties (point) (1+ (point-at-eol))
1960 (list :org-license-to-kill t
)))
1961 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1964 (defun org-solidify-link-text (s &optional alist
)
1965 "Take link text and make a safe target out of it."
1970 (org-split-string s
"[ \t\r\n]+") "=="))
1971 (a (assoc rtn alist
)))
1974 (defun org-get-min-level (lines &optional offset
)
1975 "Get the minimum level in LINES."
1976 (let ((re "^\\(\\*+\\) ") l
)
1978 (while (setq l
(pop lines
))
1979 (if (string-match re l
)
1980 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1984 ;; Variable holding the vector with section numbers
1985 (defvar org-section-numbers
(make-vector org-level-max
0))
1987 (defun org-init-section-numbers ()
1988 "Initialize the vector for the section numbers."
1990 (numbers (nreverse (org-split-string "" "\\.")))
1991 (depth (1- (length org-section-numbers
)))
1992 (i depth
) number-string
)
1995 (aset org-section-numbers i
0)
1996 (setq number-string
(or (car numbers
) "0"))
1997 (if (string-match "\\`[A-Z]\\'" number-string
)
1998 (aset org-section-numbers i
1999 (- (string-to-char number-string
) ?A -
1))
2000 (aset org-section-numbers i
(string-to-number number-string
)))
2004 (defun org-section-number (&optional level
)
2005 "Return a string with the current section number.
2006 When LEVEL is non-nil, increase section numbers on that level."
2007 (let* ((depth (1- (length org-section-numbers
)))
2009 (fmts (car org-export-section-number-format
))
2010 (term (cdr org-export-section-number-format
))
2015 (aset org-section-numbers
2016 level
(1+ (aref org-section-numbers level
))))
2017 (setq idx
(1+ level
))
2018 (while (<= idx depth
)
2020 (aset org-section-numbers idx
0))
2021 (setq idx
(1+ idx
))))
2023 (while (<= idx depth
)
2024 (when (> (aref org-section-numbers idx
) 0)
2025 (setq fmt
(or (pop fmts
) fmt
)
2027 n
(aref org-section-numbers idx
)
2029 (concat string sep
(org-number-to-counter n ctype
))
2030 (concat string
".0"))
2032 (setq idx
(1+ idx
)))
2034 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2035 (setq string
(replace-match "" t nil string
)))
2036 (if (string-match "\\(\\.0\\)+\\'" string
)
2037 (setq string
(replace-match "" t nil string
))))
2038 (concat string term
)))
2040 (defun org-number-to-counter (n type
)
2041 "Concert number N to a string counter, according to TYPE.
2042 TYPE must be a string, any of:
2046 I upper case roman numeral
2047 i lower case roman numeral"
2049 ((equal type
"1") (number-to-string n
))
2050 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2051 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2052 ((equal type
"I") (org-number-to-roman n
))
2053 ((equal type
"i") (downcase (org-number-to-roman n
)))
2054 (t (error "Invalid counter type `%s'" type
))))
2056 (defun org-number-to-roman (n)
2057 "Convert integer N into a roman numeral."
2058 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2059 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2060 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2064 (number-to-string n
)
2066 (if (>= n
(caar roman
))
2067 (setq n
(- n
(caar roman
))
2068 res
(concat res
(cdar roman
)))
2074 (defun org-export-preprocess-apply-macros ()
2075 "Replace macro references."
2076 (goto-char (point-min))
2077 (let (sy val key args args2 s n
)
2078 (while (re-search-forward
2079 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2081 (unless (save-match-data
2083 (goto-char (point-at-bol))
2084 (looking-at "[ \t]*#\\+macro")))
2085 (setq key
(downcase (match-string 1))
2086 args
(match-string 3))
2087 (when (setq val
(or (plist-get org-export-opt-plist
2088 (intern (concat ":macro-" key
)))
2089 (plist-get org-export-opt-plist
2090 (intern (concat ":" key
)))))
2093 (setq args
(org-split-string args
",") args2 nil
)
2095 (while (string-match "\\\\\\'" (car args
))
2096 ;; repair bad splits
2097 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2100 (push (pop args
) args2
))
2101 (setq args
(mapcar 'org-trim
(nreverse args2
)))
2103 (while (string-match "\\$\\([0-9]+\\)" val s
)
2104 (setq s
(1+ (match-beginning 0))
2105 n
(string-to-number (match-string 1 val
)))
2106 (and (>= (length args
) n
)
2107 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2108 (when (string-match "\\`(eval\\>" val
)
2109 (setq val
(eval (read val
))))
2110 (if (and val
(not (stringp val
)))
2111 (setq val
(format "%s" val
))))
2113 (prog1 (replace-match val t t
)
2114 (goto-char (match-beginning 0)))))))))
2116 (defun org-export-apply-macros-in-string (s)
2117 "Apply the macros in string S."
2121 (org-export-preprocess-apply-macros)
2126 (defun org-export-handle-include-files ()
2127 "Include the contents of include files, with proper formatting."
2128 (let ((case-fold-search t
)
2129 params file markup lang start end prefix prefix1 switches all
)
2130 (goto-char (point-min))
2131 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2132 (setq params
(read (concat "(" (match-string 1) ")"))
2133 prefix
(org-get-and-remove-property 'params
:prefix
)
2134 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2135 file
(org-symname-or-string (pop params
))
2136 markup
(org-symname-or-string (pop params
))
2137 lang
(and (member markup
'("src" "SRC"))
2138 (org-symname-or-string (pop params
)))
2139 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" ")
2141 (delete-region (match-beginning 0) (match-end 0))
2143 (not (file-exists-p file
))
2144 (not (file-readable-p file
)))
2145 (insert (format "CANNOT INCLUDE FILE %s" file
))
2146 (setq all
(cons file all
))
2148 (if (equal (downcase markup
) "src")
2149 (setq start
(format "#+begin_src %s %s\n"
2150 (or lang
"fundamental")
2153 (setq start
(format "#+begin_%s %s\n" markup switches
)
2154 end
(format "#+end_%s" markup
))))
2155 (insert (or start
""))
2156 (insert (org-get-file-contents (expand-file-name file
)
2157 prefix prefix1 markup
))
2158 (or (bolp) (newline))
2159 (insert (or end
""))))
2162 (defun org-export-handle-include-files-recurse ()
2163 "Recursively include files aborting on circular inclusion."
2164 (let ((now (list org-current-export-file
)) all
)
2166 (setq all
(append now all
))
2167 (setq now
(org-export-handle-include-files))
2170 (mapcar (lambda (el) (when (member el all
) el
)) now
))))
2172 (error "Recursive #+INCLUDE: %S" intersection
))))))
2174 (defun org-get-file-contents (file &optional prefix prefix1 markup
)
2175 "Get the contents of FILE and return them as a string.
2176 If PREFIX is a string, prepend it to each line. If PREFIX1
2177 is a string, prepend it to the first line instead of PREFIX.
2178 If MARKUP, don't protect org-like lines, the exporter will
2179 take care of the block they are in."
2180 (if (stringp markup
) (setq markup
(downcase markup
)))
2182 (insert-file-contents file
)
2183 (when (or prefix prefix1
)
2184 (goto-char (point-min))
2186 (insert (or prefix1 prefix
))
2188 (beginning-of-line 2)))
2190 (when (member markup
'("src" "example"))
2191 (goto-char (point-min))
2192 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2193 (goto-char (match-beginning 0))
2198 (defun org-get-and-remove-property (listvar prop
)
2199 "Check if the value of LISTVAR contains PROP as a property.
2200 If yes, return the value of that property (i.e. the element following
2201 in the list) and remove property and value from the list in LISTVAR."
2202 (let ((list (symbol-value listvar
)) m v
)
2203 (when (setq m
(member prop list
))
2205 (if (equal (car list
) prop
)
2206 (set listvar
(cddr list
))
2207 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2209 (set listvar list
)))
2212 (defun org-symname-or-string (s)
2214 (if s
(symbol-name s
) s
)
2217 ;;; Fontification and line numbers for code examples
2219 (defvar org-export-last-code-line-counter-value
0)
2221 (defun org-export-replace-src-segments-and-examples (backend)
2222 "Replace source code segments with special code for export."
2223 (setq org-export-last-code-line-counter-value
0)
2224 (let ((case-fold-search t
)
2225 lang code trans opts indent caption
)
2226 (goto-char (point-min))
2227 (while (re-search-forward
2228 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2231 (if (not (match-string 4))
2232 (error "Source block missing language specification: %s"
2233 (let* ((body (match-string 6))
2234 (nothing (message "body:%s" body
))
2235 (preview (or (and (string-match
2236 "^[ \t]*\\([^\n\r]*\\)" body
)
2237 (match-string 1 body
)) body
)))
2238 (if (> (length preview
) 35)
2239 (concat (substring preview
0 32) "...")
2242 (setq lang
(match-string 4)
2243 opts
(match-string 5)
2244 code
(match-string 6)
2245 indent
(length (match-string 2))
2246 caption
(get-text-property 0 'org-caption
(match-string 0))))
2248 opts
(match-string 9)
2249 code
(match-string 10)
2250 indent
(length (match-string 8))
2251 caption
(get-text-property 0 'org-caption
(match-string 0))))
2253 (setq trans
(org-export-format-source-code-or-example
2254 backend lang code opts indent caption
))
2255 (replace-match trans t t
))))
2257 (defvar htmlp
) ;; dynamically scoped
2258 (defvar latexp
) ;; dynamically scoped
2259 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2260 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2261 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2262 (defvar org-export-latex-listings-w-names
) ;; defined in org-latex.el
2263 (defvar org-export-latex-minted-langs
) ;; defined in org-latex.el
2264 (defun org-export-format-source-code-or-example
2265 (backend lang code
&optional opts indent caption
)
2266 "Format CODE from language LANG and return it formatted for export.
2267 If LANG is nil, do not add any fontification.
2268 OPTS contains formatting options, like `-n' for triggering numbering lines,
2269 and `+n' for continuing previous numbering.
2270 Code formatting according to language currently only works for HTML.
2271 Numbering lines works for all three major backends (html, latex, and ascii).
2272 INDENT was the original indentation of the block."
2274 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2275 (setq opts
(or opts
"")
2276 num
(string-match "[-+]n\\>" opts
)
2277 cont
(string-match "\\+n\\>" opts
)
2278 rpllbl
(string-match "-r\\>" opts
)
2279 keepp
(string-match "-k\\>" opts
)
2280 textareap
(string-match "-t\\>" opts
)
2281 preserve-indentp
(or org-src-preserve-indentation
2282 (string-match "-i\\>" opts
))
2283 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2284 (string-to-number (match-string 1 opts
))
2286 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2287 (string-to-number (match-string 1 opts
))
2288 (org-count-lines code
))
2289 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2290 (match-string 1 opts
)))
2291 (when (and textareap
(eq backend
'html
))
2292 ;; we cannot use numbering or highlighting.
2293 (setq num nil cont nil lang nil
))
2294 (if keepp
(setq rpllbl
'keep
))
2295 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2296 (when (string-match "^," rtn
)
2297 (setq rtn
(with-temp-buffer
2299 ;; Free up the protected lines
2300 (goto-char (point-min))
2301 (while (re-search-forward "^," nil t
)
2302 (if (or (equal lang
"org")
2304 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2308 ;; Now backend-specific coding
2311 ((eq backend
'docbook
)
2312 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2313 (concat "\n#+BEGIN_DOCBOOK\n"
2314 (org-add-props (concat "<programlisting><![CDATA["
2316 "]]></programlisting>\n")
2317 '(org-protected t org-example t
))
2320 ;; We are exporting to HTML
2322 (if (featurep 'xemacs
)
2324 (require 'htmlize nil t
))
2325 (when (not (fboundp 'htmlize-region-for-paste
))
2326 ;; we do not have htmlize.el, or an old version of it
2329 "htmlize.el 1.34 or later is needed for source code formatting")))
2332 (let* ((lang-m (when lang
2333 (or (cdr (assoc lang org-src-lang-modes
))
2335 (mode (and lang-m
(intern
2337 (if (symbolp lang-m
)
2338 (symbol-name lang-m
)
2341 (org-inhibit-startup t
)
2342 (org-startup-folded nil
))
2346 (if (functionp mode
)
2349 (font-lock-fontify-buffer)
2351 (set-buffer-modified-p nil
)
2352 (org-export-htmlize-region-for-paste
2353 (point-min) (point-max))))
2354 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2359 "<div class=\"org-src-container\">"
2361 "<label class=\"org-src-name\">%s</label>"
2365 (format "<pre class=\"src src-%s\">\n" lang
)
2367 (if caption
"</div>" "")))))
2370 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2372 rtn
"</textarea>\n</p>\n"))
2375 (goto-char (point-min))
2376 (while (re-search-forward "[<>&]" nil t
)
2377 (replace-match (cdr (assq (char-before)
2378 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2380 (setq rtn
(buffer-string)))
2381 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2383 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2385 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2386 (setq rtn
(replace-match "\\1" t nil rtn
)))
2387 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t org-example t
)) "\n#+END_HTML\n\n"))
2388 ((eq backend
'latex
)
2389 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2390 (concat "#+BEGIN_LaTeX\n"
2393 ((and org-export-latex-listings
2394 (not (eq org-export-latex-listings
'minted
)))
2398 ((lang-sym (intern lang
))
2403 org-export-latex-listings-langs
))
2405 (format "\\lstset{language=%s}\n" lstlang
))
2408 org-export-latex-listings-w-names
)
2409 (format "\n%s $\\equiv$ \n"
2410 (replace-regexp-in-string
2411 "_" "\\\\_" caption
)))
2412 "\\begin{lstlisting}\n"
2413 rtn
"\\end{lstlisting}\n"))
2414 ((eq org-export-latex-listings
'minted
)
2417 ((lang-sym (intern lang
))
2422 org-export-latex-minted-langs
))
2426 org-export-latex-listings-w-names
)
2427 (format "\n%s $\\equiv$ \n"
2428 (replace-regexp-in-string
2429 "_" "\\\\_" caption
)))
2430 (format "\\begin{minted}{%s}\n" minted-lang
)
2431 rtn
"\\end{minted}\n"))))
2432 (t (concat (car org-export-latex-verbatim-wrap
)
2433 rtn
(cdr org-export-latex-verbatim-wrap
))))
2434 '(org-protected t org-example t
))
2436 ((eq backend
'ascii
)
2437 ;; This is not HTML or LaTeX, so just make it an example.
2438 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2439 (concat caption
"\n"
2444 (lambda (l) (concat " " l
))
2445 (org-split-string rtn
"\n")
2448 '(org-protected t org-example t
))
2450 (org-add-props rtn nil
'original-indentation indent
))))
2452 (defun org-export-number-lines (text backend
2453 &optional skip1 skip2 number cont
2454 replace-labels label-format
)
2455 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2456 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2459 (goto-char (point-max))
2460 (skip-chars-backward " \t\n\r")
2461 (delete-region (point) (point-max))
2462 (beginning-of-line (- 1 skip2
))
2463 (let* ((last (org-current-line))
2464 (n org-export-last-code-line-counter-value
)
2465 (nmax (+ n
(- last skip1
)))
2466 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2469 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2471 ((eq backend
'ascii
) fmt
)
2472 ((eq backend
'latex
) fmt
)
2473 ((eq backend
'docbook
) fmt
)
2475 (label-format (or label-format org-coderef-label-format
))
2476 (label-pre (if (string-match "%s" label-format
)
2477 (substring label-format
0 (match-beginning 0))
2479 (label-post (if (string-match "%s" label-format
)
2480 (substring label-format
(match-end 0))
2484 ".*?\\S-.*?\\([ \t]*\\("
2485 (regexp-quote label-pre
)
2486 "\\([-a-zA-Z0-9_ ]+\\)"
2487 (regexp-quote label-post
)
2491 (org-goto-line (1+ skip1
))
2492 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2494 (insert (format fm
(incf n
)))
2496 (when (looking-at lbl-re
)
2497 (setq ref
(match-string 3))
2498 (cond ((numberp replace-labels
)
2499 ;; remove labels; use numbers for references when lines
2500 ;; are numbered, use labels otherwise
2501 (delete-region (match-beginning 1) (match-end 1))
2502 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2503 ((eq replace-labels
'keep
)
2504 ;; don't remove labels; use numbers for references when
2505 ;; lines are numbered, use labels otherwise
2506 (goto-char (match-beginning 2))
2507 (delete-region (match-beginning 2) (match-end 2))
2508 (insert "(" ref
")")
2509 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2510 org-export-code-refs
))
2512 ;; don't remove labels and don't use numbers for
2514 (goto-char (match-beginning 2))
2515 (delete-region (match-beginning 2) (match-end 2))
2516 (insert "(" ref
")")
2517 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2518 (when (eq backend
'html
)
2520 (beginning-of-line 1)
2521 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2524 (insert "</span>")))))
2525 (setq org-export-last-code-line-counter-value n
)
2526 (goto-char (point-max))
2530 (defun org-search-todo-below (line lines level
)
2531 "Search the subtree below LINE for any TODO entries."
2532 (let ((rest (cdr (memq line lines
)))
2533 (re org-todo-line-regexp
)
2536 (while (setq line
(pop rest
))
2537 (if (string-match re line
)
2539 (setq lv
(- (match-end 1) (match-beginning 1))
2540 todo
(and (match-beginning 2)
2541 (not (member (match-string 2 line
)
2542 org-done-keywords
))))
2544 (if (<= lv level
) (throw 'exit nil
))
2545 (if todo
(throw 'exit t
))))))))
2548 (defun org-export-visible (type arg
)
2549 "Create a copy of the visible part of the current buffer, and export it.
2550 The copy is created in a temporary buffer and removed after use.
2551 TYPE is the final key (as a string) that also selects the export command in
2552 the \\<org-mode-map>\\[org-export] export dispatcher.
2553 As a special case, if the you type SPC at the prompt, the temporary
2554 org-mode file will not be removed but presented to you so that you can
2555 continue to use it. The prefix arg ARG is passed through to the exporting
2559 (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")
2560 (read-char-exclusive))
2561 current-prefix-arg
))
2562 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L
)))
2563 (error "Invalid export key"))
2564 (let* ((binding (cdr (assoc type
2566 (?a . org-export-as-ascii
)
2567 (?A . org-export-as-ascii-to-buffer
)
2568 (?n . org-export-as-latin1
)
2569 (?N . org-export-as-latin1-to-buffer
)
2570 (?u . org-export-as-utf8
)
2571 (?U . org-export-as-utf8-to-buffer
)
2572 (?\C-a . org-export-as-ascii
)
2573 (?b . org-export-as-html-and-open
)
2574 (?\C-b . org-export-as-html-and-open
)
2575 (?h . org-export-as-html
)
2576 (?H . org-export-as-html-to-buffer
)
2577 (?R . org-export-region-as-html
)
2578 (?D . org-export-as-docbook
)
2580 (?l . org-export-as-latex
)
2581 (?p . org-export-as-pdf
)
2582 (?d . org-export-as-pdf-and-open
)
2583 (?L . org-export-as-latex-to-buffer
)
2585 (?x . org-export-as-xoxo
)))))
2586 (keepp (equal type ?\
))
2587 (file buffer-file-name
)
2588 (buffer (get-buffer-create "*Org Export Visible*"))
2590 ;; Need to hack the drawers here.
2592 (goto-char (point-min))
2593 (while (re-search-forward org-drawer-regexp nil t
)
2594 (goto-char (match-beginning 1))
2595 (or (org-invisible-p) (org-flag-drawer nil
))))
2596 (with-current-buffer buffer
(erase-buffer))
2598 (setq s
(goto-char (point-min)))
2599 (while (not (= (point) (point-max)))
2600 (goto-char (org-find-invisible))
2601 (append-to-buffer buffer s
(point))
2602 (setq s
(goto-char (org-find-visible))))
2603 (org-cycle-hide-drawers 'all
)
2604 (goto-char (point-min))
2606 ;; Copy all comment lines to the end, to make sure #+ settings are
2607 ;; still available for the second export step. Kind of a hack, but
2608 ;; does do the trick.
2609 (if (looking-at "#[^\r\n]*")
2610 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2611 (when (re-search-forward "^\\*+[ \t]+" nil t
)
2612 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t
)
2613 (append-to-buffer buffer
(1+ (match-beginning 0))
2614 (min (point-max) (1+ (match-end 0)))))))
2616 (let ((buffer-file-name file
)
2617 (org-inhibit-startup t
))
2620 (unless keepp
(funcall binding arg
))))
2622 (kill-buffer buffer
)
2623 (switch-to-buffer-other-window buffer
)
2624 (goto-char (point-min)))))
2626 (defun org-find-visible ()
2628 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2629 (get-char-property s
'invisible
)))
2631 (defun org-find-invisible ()
2633 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2634 (not (get-char-property s
'invisible
))))
2637 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2639 (defun org-export-string (string fmt
&optional dir
)
2640 "Export STRING to FMT using existing export facilities.
2641 During export STRING is saved to a temporary file whose location
2642 could vary. Optional argument DIR can be used to force the
2643 directory in which the temporary file is created during export
2644 which can be useful for resolving relative paths. Dir defaults
2645 to the value of `temporary-file-directory'."
2646 (let ((temporary-file-directory (or dir temporary-file-directory
))
2647 (tmp-file (make-temp-file "org-")))
2651 (write-file tmp-file
)
2652 (org-load-modules-maybe)
2653 (unless org-local-vars
2654 (setq org-local-vars
(org-get-local-variables)))
2655 (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
2656 (list 'let org-local-vars
2657 (list (intern (concat "org-export-as-" fmt
))
2658 nil nil nil
''string t
))))
2659 (delete-file tmp-file
))))
2662 (defun org-export-as-org (arg &optional hidden ext-plist
2663 to-buffer body-only pub-dir
)
2664 "Make a copy with not-exporting stuff removed.
2665 The purpose of this function is to provide a way to export the source
2666 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2667 stuff removed. This command will remove the following:
2669 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2670 - comment blocks and trees starting with the COMMENT keyword
2671 - only trees that are consistent with `org-export-select-tags'
2672 and `org-export-exclude-tags'.
2674 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2675 all the others will be ignored (but are present so that the general
2676 mechanism to call publishing functions will work).
2678 EXT-PLIST is a property list with external parameters overriding
2679 org-mode's default settings, but still inferior to file-local
2680 settings. When PUB-DIR is set, use this as the publishing
2683 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2685 (org-infile-export-plist)))
2686 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2687 (filename (concat (file-name-as-directory
2689 (org-export-directory :org opt-plist
)))
2690 (file-name-sans-extension
2691 (file-name-nondirectory bfname
))
2693 (filename (and filename
2694 (if (equal (file-truename filename
)
2695 (file-truename bfname
))
2696 (concat (file-name-sans-extension filename
)
2698 (file-name-extension filename
))
2700 (backup-inhibited t
)
2701 (buffer (find-file-noselect filename
))
2702 (region (buffer-string))
2705 (switch-to-buffer buffer
)
2708 (let ((org-inhibit-startup t
)) (org-mode))
2709 (org-install-letbind)
2711 ;; Get rid of archived trees
2712 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2714 ;; Remove comment environment and comment subtrees
2715 (org-export-remove-comment-blocks-and-subtrees)
2717 ;; Get rid of excluded trees
2718 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2719 (plist-get opt-plist
:exclude-tags
))
2721 (when (or (plist-get opt-plist
:plain-source
)
2722 (not (or (plist-get opt-plist
:plain-source
)
2723 (plist-get opt-plist
:htmlized-source
))))
2724 ;; Either nothing special is requested (default call)
2725 ;; or the plain source is explicitly requested
2728 (when (plist-get opt-plist
:htmlized-source
)
2729 ;; Make the htmlized version
2732 (font-lock-fontify-buffer)
2733 (let* ((htmlize-output-type 'css
)
2734 (newbuf (htmlize-buffer)))
2735 (with-current-buffer newbuf
2736 (when org-export-htmlized-org-css-url
2737 (goto-char (point-min))
2738 (and (re-search-forward
2739 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2743 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2744 org-export-htmlized-org-css-url
)
2746 (write-file (concat filename
".html")))
2747 (kill-buffer newbuf
)))
2748 (set-buffer-modified-p nil
)
2749 (if (equal to-buffer
'string
)
2750 (progn (setq str-ret
(buffer-string))
2751 (kill-buffer (current-buffer))
2753 (kill-buffer (current-buffer))))))
2755 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2756 (defun org-get-current-options ()
2757 "Return a string with current options as keyword options.
2758 Does include HTML export options as well as TODO and CATEGORY stuff."
2759 (require 'org-archive
)
2768 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2769 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2771 #+EXPORT_SELECT_TAGS: %s
2772 #+EXPORT_EXCLUDE_TAGS: %s
2779 #+PRIORITIES: %c %c %c
2781 #+STARTUP: %s %s %s %s %s
2787 (buffer-name) (user-full-name) user-mail-address
2788 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2789 org-export-default-language
2790 org-export-headline-levels
2791 org-export-with-section-numbers
2793 org-export-preserve-breaks
2794 org-export-html-expand
2795 org-export-with-fixed-width
2796 org-export-with-tables
2797 org-export-with-sub-superscripts
2798 org-export-with-special-strings
2799 org-export-with-footnotes
2800 org-export-with-emphasize
2801 org-export-with-timestamps
2802 org-export-with-TeX-macros
2803 org-export-with-LaTeX-fragments
2804 org-export-skip-text-before-1st-heading
2805 org-export-with-drawers
2806 org-export-with-todo-keywords
2807 org-export-with-priority
2808 org-export-with-tags
2809 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2810 (mapconcat 'identity org-export-select-tags
" ")
2811 (mapconcat 'identity org-export-exclude-tags
" ")
2812 org-export-html-link-up
2813 org-export-html-link-home
2815 (file-name-sans-extension
2816 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2818 "TODO FEEDBACK VERIFY DONE"
2819 "Me Jason Marie DONE"
2820 org-highest-priority org-lowest-priority org-default-priority
2821 (mapconcat 'identity org-drawers
" ")
2822 (cdr (assoc org-startup-folded
2823 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2824 (if org-odd-levels-only
"odd" "oddeven")
2825 (if org-hide-leading-stars
"hidestars" "showstars")
2826 (if org-startup-align-all-tables
"align" "noalign")
2827 (cond ((eq org-log-done t
) "logdone")
2828 ((equal org-log-done
'note
) "lognotedone")
2829 ((not org-log-done
) "nologdone"))
2830 (or (mapconcat (lambda (x)
2832 ((equal :startgroup
(car x
)) "{")
2833 ((equal :endgroup
(car x
)) "}")
2834 ((equal :newline
(car x
)) "")
2835 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2837 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2838 (mapconcat 'identity org-file-tags
" ")
2839 org-archive-location
2840 "org file:~/org/%s.org"
2844 (defun org-insert-export-options-template ()
2845 "Insert into the buffer a template with information for exporting."
2847 (if (not (bolp)) (newline))
2848 (let ((s (org-get-current-options)))
2849 (and (string-match "#\\+CATEGORY" s
)
2850 (setq s
(substring s
0 (match-beginning 0))))
2853 (defvar org-table-colgroup-info nil
)
2855 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2856 "Check if the table has a marking column.
2857 If yes remove the column and the special lines."
2858 (setq org-table-colgroup-info nil
)
2861 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2864 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2865 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2868 ;; No special marking column
2870 (setq org-table-clean-did-remove-column nil
)
2875 ((org-table-colgroup-line-p x
)
2876 ;; This line contains colgroup info, extract it
2877 ;; and then discard the line
2878 (setq org-table-colgroup-info
2880 (cond ((member x
'("<" "<")) :start
)
2881 ((member x
'(">" ">")) :end
)
2882 ((member x
'("<>" "<>")) :startend
)
2884 (org-split-string x
"[ \t]*|[ \t]*")))
2886 ((org-table-cookie-line-p x
)
2887 ;; This line contains formatting cookies, discard it
2891 ;; there is a special marking column
2892 (setq org-table-clean-did-remove-column t
)
2897 ((org-table-colgroup-line-p x
)
2898 ;; This line contains colgroup info, extract it
2899 ;; and then discard the line
2900 (setq org-table-colgroup-info
2902 (cond ((member x
'("<" "<")) :start
)
2903 ((member x
'(">" ">")) :end
)
2904 ((member x
'("<>" "<>")) :startend
)
2906 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2908 ((org-table-cookie-line-p x
)
2909 ;; This line contains formatting cookies, discard it
2911 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2914 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2915 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2916 ;; remove the first column
2917 (replace-match "\\1|" t nil x
))))
2920 (defun org-export-cleanup-toc-line (s)
2921 "Remove tags and timestamps from lines going into the toc."
2922 (when (memq org-export-with-tags
'(not-in-toc nil
))
2923 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s
)
2924 (setq s
(replace-match "" t t s
))))
2925 (when org-export-remove-timestamps-from-toc
2926 (while (string-match org-maybe-keyword-time-regexp s
)
2927 (setq s
(replace-match "" t t s
))))
2928 (while (string-match org-bracket-link-regexp s
)
2929 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2931 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
2932 (setq s
(replace-match "" t t s
)))
2936 (defun org-get-text-property-any (pos prop
&optional object
)
2937 (or (get-text-property pos prop object
)
2938 (and (setq pos
(next-single-property-change pos prop object
))
2939 (get-text-property pos prop object
))))
2941 (defun org-export-get-coderef-format (path desc
)
2943 (if (and desc
(string-match
2944 (regexp-quote (concat "(" path
")"))
2946 (replace-match "%s" t t desc
)
2949 (defun org-export-push-to-kill-ring (format)
2950 "Push buffer content to kill ring.
2951 The depends on the variable `org-export-copy-to-kill'."
2952 (when org-export-copy-to-kill-ring
2953 (org-kill-new (buffer-string))
2954 (when (fboundp 'x-set-selection
)
2955 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
2956 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
2957 (message "%s export done, pushed to kill ring and clipboard" format
)))
2961 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2963 ;;; org-exp.el ends here