Introduce a help function for entities
[org-mode.git] / lisp / org-exp.el
blob3003cf8c854bfa23d4a2044d528f9c50657c5235
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
9 ;; Version: 6.36trans
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 (require 'org)
30 (require 'org-macs)
31 (require 'org-agenda)
32 (require 'org-exp-blocks)
33 (require 'org-src)
34 (eval-when-compile
35 (require 'cl))
37 (declare-function org-export-latex-preprocess "org-latex" (parameters))
38 (declare-function org-export-ascii-preprocess "org-ascii" (parameters))
39 (declare-function org-export-html-preprocess "org-html" (parameters))
40 (declare-function org-export-docbook-preprocess "org-docbook" (parameters))
41 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
42 (declare-function org-export-htmlize-region-for-paste "org-html" (beg end))
43 (declare-function htmlize-buffer "ext:htmlize" (&optional buffer))
44 (declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
45 (declare-function org-table-cookie-line-p "org-table" (line))
46 (declare-function org-table-colgroup-line-p "org-table" (line))
47 (autoload 'org-export-generic "org-export-generic" "Export using the generic exporter" t)
48 (defgroup org-export nil
49 "Options for exporting org-listings."
50 :tag "Org Export"
51 :group 'org)
53 (defgroup org-export-general nil
54 "General options for exporting Org-mode files."
55 :tag "Org Export General"
56 :group 'org-export)
58 (defcustom org-export-allow-BIND 'confirm
59 "Non-nil means allow #+BIND to define local variable values for export.
60 This is a potential security risk, which is why the user must confirm the
61 use of these lines."
62 :group 'org-export-general
63 :type '(choice
64 (const :tag "Never" nil)
65 (const :tag "Always" t)
66 (const :tag "Make the user confirm for each file" confirm)))
68 ;; FIXME
69 (defvar org-export-publishing-directory nil)
71 (defcustom org-export-show-temporary-export-buffer t
72 "Non-nil means show buffer after exporting to temp buffer.
73 When Org exports to a file, the buffer visiting that file is ever
74 shown, but remains buried. However, when exporting to a temporary
75 buffer, that buffer is popped up in a second window. When this variable
76 is nil, the buffer remains buried also in these cases."
77 :group 'org-export-general
78 :type 'boolean)
80 (defcustom org-export-copy-to-kill-ring t
81 "Non-nil means exported stuff will also be pushed onto the kill ring."
82 :group 'org-export-general
83 :type 'boolean)
85 (defcustom org-export-kill-product-buffer-when-displayed nil
86 "Non-nil means kill the product buffer if it is displayed immediately.
87 This applied to the commands `org-export-html-and-open' and
88 `org-export-as-pdf-and-open'."
89 :group 'org-export-general
90 :type 'boolean)
92 (defcustom org-export-run-in-background nil
93 "Non-nil means export and publishing commands will run in background.
94 This works by starting up a separate Emacs process visiting the same file
95 and doing the export from there.
96 Not all export commands are affected by this - only the ones which
97 actually write to a file, and that do not depend on the buffer state.
99 If this option is nil, you can still get background export by calling
100 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
102 If this option is t, the double prefix can be used to exceptionally
103 force an export command into the current process."
104 :group 'org-export-general
105 :type 'boolean)
107 (defcustom org-export-select-tags '("export")
108 "Tags that select a tree for export.
109 If any such tag is found in a buffer, all trees that do not carry one
110 of these tags will be deleted before export.
111 Inside trees that are selected like this, you can still deselect a
112 subtree by tagging it with one of the `org-export-exclude-tags'."
113 :group 'org-export-general
114 :type '(repeat (string :tag "Tag")))
116 (defcustom org-export-exclude-tags '("noexport")
117 "Tags that exclude a tree from export.
118 All trees carrying any of these tags will be excluded from export.
119 This is without condition, so even subtrees inside that carry one of the
120 `org-export-select-tags' will be removed."
121 :group 'org-export-general
122 :type '(repeat (string :tag "Tag")))
124 ;; FIXME: rename, this is a general variable
125 (defcustom org-export-html-expand t
126 "Non-nil means for HTML export, treat @<...> as HTML tag.
127 When nil, these tags will be exported as plain text and therefore
128 not be interpreted by a browser.
130 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
131 :group 'org-export-html
132 :group 'org-export-general
133 :type 'boolean)
135 (defcustom org-export-with-special-strings t
136 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
137 When this option is turned on, these strings will be exported as:
139 Org HTML LaTeX
140 -----+----------+--------
141 \\- &shy; \\-
142 -- &ndash; --
143 --- &mdash; ---
144 ... &hellip; \ldots
146 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
147 :group 'org-export-translation
148 :type 'boolean)
150 (defcustom org-export-html-link-up ""
151 "Where should the \"UP\" link of exported HTML pages lead?"
152 :group 'org-export-html
153 :group 'org-export-general
154 :type '(string :tag "File or URL"))
156 (defcustom org-export-html-link-home ""
157 "Where should the \"HOME\" link of exported HTML pages lead?"
158 :group 'org-export-html
159 :group 'org-export-general
160 :type '(string :tag "File or URL"))
162 (defcustom org-export-language-setup
163 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
164 ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
165 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
166 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
167 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
168 ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
169 ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
170 ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
171 ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
172 ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
173 ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
174 ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
175 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
176 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
177 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
178 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
179 ("pl" "Autor" "Data" "Spis tre&sacute;ci" "Przypis")
180 ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
181 "Terms used in export text, translated to different languages.
182 Use the variable `org-export-default-language' to set the language,
183 or use the +OPTION lines for a per-file setting."
184 :group 'org-export-general
185 :type '(repeat
186 (list
187 (string :tag "HTML language tag")
188 (string :tag "Author")
189 (string :tag "Date")
190 (string :tag "Table of Contents")
191 (string :tag "Footnotes"))))
193 (defcustom org-export-default-language "en"
194 "The default language of HTML export, as a string.
195 This should have an association in `org-export-language-setup'."
196 :group 'org-export-general
197 :type 'string)
199 (defvar org-export-page-description ""
200 "The page description, for the XHTML meta tag.
201 This is best set with the #+DESCRIPTION line in a file, it does not make
202 sense to set this globally.")
204 (defvar org-export-page-keywords ""
205 "The page description, for the XHTML meta tag.
206 This is best set with the #+KEYWORDS line in a file, it does not make
207 sense to set this globally.")
209 (defcustom org-export-skip-text-before-1st-heading nil
210 "Non-nil means skip all text before the first headline when exporting.
211 When nil, that text is exported as well."
212 :group 'org-export-general
213 :type 'boolean)
215 (defcustom org-export-headline-levels 3
216 "The last level which is still exported as a headline.
217 Inferior levels will produce itemize lists when exported.
218 Note that a numeric prefix argument to an exporter function overrides
219 this setting.
221 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
222 :group 'org-export-general
223 :type 'integer)
225 (defcustom org-export-with-section-numbers t
226 "Non-nil means add section numbers to headlines when exporting.
228 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
229 :group 'org-export-general
230 :type 'boolean)
232 (defcustom org-export-section-number-format '((("1" ".")) . "")
233 "Format of section numbers for export.
234 The variable has two components.
235 1. A list of lists, each indicating a counter type and a separator.
236 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
237 It causes causes numeric, alphabetic, or roman counters, respectively.
238 The separator is only used if another counter for a subsection is being
239 added.
240 If there are more numbered section levels than entries in this lists,
241 then the last entry will be reused.
242 2. A terminator string that will be added after the entire
243 section number."
244 :group 'org-export-general
245 :type '(cons
246 (repeat
247 (list
248 (string :tag "Counter Type")
249 (string :tag "Separator ")))
250 (string :tag "Terminator")))
252 (defcustom org-export-with-toc t
253 "Non-nil means create a table of contents in exported files.
254 The TOC contains headlines with levels up to`org-export-headline-levels'.
255 When an integer, include levels up to N in the toc, this may then be
256 different from `org-export-headline-levels', but it will not be allowed
257 to be larger than the number of headline levels.
258 When nil, no table of contents is made.
260 Headlines which contain any TODO items will be marked with \"(*)\" in
261 ASCII export, and with red color in HTML output, if the option
262 `org-export-mark-todo-in-toc' is set.
264 In HTML output, the TOC will be clickable.
266 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
267 or \"toc:3\"."
268 :group 'org-export-general
269 :type '(choice
270 (const :tag "No Table of Contents" nil)
271 (const :tag "Full Table of Contents" t)
272 (integer :tag "TOC to level")))
274 (defcustom org-export-mark-todo-in-toc nil
275 "Non-nil means mark TOC lines that contain any open TODO items."
276 :group 'org-export-general
277 :type 'boolean)
279 (defcustom org-export-with-todo-keywords t
280 "Non-nil means include TODO keywords in export.
281 When nil, remove all these keywords from the export."
282 :group 'org-export-general
283 :type 'boolean)
285 (defcustom org-export-with-priority nil
286 "Non-nil means include priority cookies in export.
287 When nil, remove priority cookies for export."
288 :group 'org-export-general
289 :type 'boolean)
291 (defcustom org-export-preserve-breaks nil
292 "Non-nil means preserve all line breaks when exporting.
293 Normally, in HTML output paragraphs will be reformatted. In ASCII
294 export, line breaks will always be preserved, regardless of this variable.
296 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
297 :group 'org-export-general
298 :type 'boolean)
300 (defcustom org-export-with-archived-trees 'headline
301 "Whether subtrees with the ARCHIVE tag should be exported.
302 This can have three different values
303 nil Do not export, pretend this tree is not present
304 t Do export the entire tree
305 headline Only export the headline, but skip the tree below it."
306 :group 'org-export-general
307 :group 'org-archive
308 :type '(choice
309 (const :tag "not at all" nil)
310 (const :tag "headline only" 'headline)
311 (const :tag "entirely" t)))
313 (defcustom org-export-author-info t
314 "Non-nil means insert author name and email into the exported file.
316 This option can also be set with the +OPTIONS line,
317 e.g. \"author:nil\"."
318 :group 'org-export-general
319 :type 'boolean)
321 (defcustom org-export-email-info nil
322 "Non-nil means insert author name and email into the exported file.
324 This option can also be set with the +OPTIONS line,
325 e.g. \"email:t\"."
326 :group 'org-export-general
327 :type 'boolean)
329 (defcustom org-export-creator-info t
330 "Non-nil means the postamble should contain a creator sentence.
331 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
332 :group 'org-export-general
333 :type 'boolean)
335 (defcustom org-export-time-stamp-file t
336 "Non-nil means insert a time stamp into the exported file.
337 The time stamp shows when the file was created.
339 This option can also be set with the +OPTIONS line,
340 e.g. \"timestamp:nil\"."
341 :group 'org-export-general
342 :type 'boolean)
344 (defcustom org-export-with-timestamps t
345 "If nil, do not export time stamps and associated keywords."
346 :group 'org-export-general
347 :type 'boolean)
349 (defcustom org-export-remove-timestamps-from-toc t
350 "If t, remove timestamps from the table of contents entries."
351 :group 'org-export-general
352 :type 'boolean)
354 (defcustom org-export-with-tags 'not-in-toc
355 "If nil, do not export tags, just remove them from headlines.
356 If this is the symbol `not-in-toc', tags will be removed from table of
357 contents entries, but still be shown in the headlines of the document.
359 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
360 :group 'org-export-general
361 :type '(choice
362 (const :tag "Off" nil)
363 (const :tag "Not in TOC" not-in-toc)
364 (const :tag "On" t)))
366 (defcustom org-export-with-drawers nil
367 "Non-nil means export with drawers like the property drawer.
368 When t, all drawers are exported. This may also be a list of
369 drawer names to export."
370 :group 'org-export-general
371 :type '(choice
372 (const :tag "All drawers" t)
373 (const :tag "None" nil)
374 (repeat :tag "Selected drawers"
375 (string :tag "Drawer name"))))
377 (defvar org-export-first-hook nil
378 "Hook called as the first thing in each exporter.
379 Point will be still in the original buffer.
380 Good for general initialization")
382 (defvar org-export-preprocess-hook nil
383 "Hook for preprocessing an export buffer.
384 Pretty much the first thing when exporting is running this hook.
385 Point will be in a temporary buffer that contains a copy of
386 the original buffer, or of the section that is being export.
387 All the other hooks in the org-export-preprocess... category
388 also work in that temporary buffer, already modified by various
389 stages of the processing.")
391 (defvar org-export-preprocess-after-include-files-hook nil
392 "Hook for preprocessing an export buffer.
393 This is run after the contents of included files have been inserted.")
395 (defvar org-export-preprocess-after-tree-selection-hook nil
396 "Hook for preprocessing an export buffer.
397 This is run after selection of trees to be exported has happened.
398 This selection includes tags-based selection, as well as removal
399 of commented and archived trees.")
401 (defvar org-export-preprocess-after-headline-targets-hook nil
402 "Hook for preprocessing export buffer.
403 This is run just after the headline targets have been defined and
404 the target-alist has been set up.")
406 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
407 "Hook for preprocessing an export buffer.
408 This is run just before backend-specific blocks get selected.")
410 (defvar org-export-preprocess-after-blockquote-hook nil
411 "Hook for preprocessing an export buffer.
412 This is run after blockquote/quote/verse/center have been marked
413 with cookies.")
415 (defvar org-export-preprocess-before-normalizing-links-hook nil
416 "Hook for preprocessing an export buffer.
417 This hook is run before links are normalized.")
419 (defvar org-export-preprocess-before-backend-specifics-hook nil
420 "Hook run before backend-specific functions are called during preprocessing.")
422 (defvar org-export-preprocess-final-hook nil
423 "Hook for preprocessing an export buffer.
424 This is run as the last thing in the preprocessing buffer, just before
425 returning the buffer string to the backend.")
427 (defgroup org-export-translation nil
428 "Options for translating special ascii sequences for the export backends."
429 :tag "Org Export Translation"
430 :group 'org-export)
432 (defcustom org-export-with-emphasize t
433 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
434 If the export target supports emphasizing text, the word will be
435 typeset in bold, italic, or underlined, respectively. Works only for
436 single words, but you can say: I *really* *mean* *this*.
437 Not all export backends support this.
439 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
440 :group 'org-export-translation
441 :type 'boolean)
443 (defcustom org-export-with-footnotes t
444 "If nil, export [1] as a footnote marker.
445 Lines starting with [1] will be formatted as footnotes.
447 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
448 :group 'org-export-translation
449 :type 'boolean)
451 (defcustom org-export-with-TeX-macros t
452 "Non-nil means interpret simple TeX-like macros when exporting.
453 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
454 Not only real TeX macros will work here, but the standard HTML entities
455 for math can be used as macro names as well. For a list of supported
456 names in HTML export, see the constant `org-entities' and the user option
457 `org-entities-user'.
458 Not all export backends support this.
460 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
461 :group 'org-export-translation
462 :group 'org-export-latex
463 :type 'boolean)
465 (defcustom org-export-with-LaTeX-fragments nil
466 "Non-nil means convert LaTeX fragments to images when exporting to HTML.
467 When set, the exporter will find LaTeX environments if the \\begin line is
468 the first non-white thing on a line. It will also find the math delimiters
469 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
470 display math.
472 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
474 The default is nil, because this option needs the `dvipng' program which
475 is not available on all systems."
476 :group 'org-export-translation
477 :group 'org-export-latex
478 :type 'boolean)
480 (defcustom org-export-with-fixed-width t
481 "Non-nil means lines starting with \":\" will be in fixed width font.
482 This can be used to have pre-formatted text, fragments of code etc. For
483 example:
484 : ;; Some Lisp examples
485 : (while (defc cnt)
486 : (ding))
487 will be looking just like this in also HTML. See also the QUOTE keyword.
488 Not all export backends support this.
490 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
491 :group 'org-export-translation
492 :type 'boolean)
494 (defgroup org-export-tables nil
495 "Options for exporting tables in Org-mode."
496 :tag "Org Export Tables"
497 :group 'org-export)
499 (defcustom org-export-with-tables t
500 "If non-nil, lines starting with \"|\" define a table.
501 For example:
503 | Name | Address | Birthday |
504 |-------------+----------+-----------|
505 | Arthur Dent | England | 29.2.2100 |
507 Not all export backends support this.
509 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
510 :group 'org-export-tables
511 :type 'boolean)
513 (defcustom org-export-highlight-first-table-line t
514 "Non-nil means highlight the first table line.
515 In HTML export, this means use <th> instead of <td>.
516 In tables created with table.el, this applies to the first table line.
517 In Org-mode tables, all lines before the first horizontal separator
518 line will be formatted with <th> tags."
519 :group 'org-export-tables
520 :type 'boolean)
522 (defcustom org-export-table-remove-special-lines t
523 "Remove special lines and marking characters in calculating tables.
524 This removes the special marking character column from tables that are set
525 up for spreadsheet calculations. It also removes the entire lines
526 marked with `!', `_', or `^'. The lines with `$' are kept, because
527 the values of constants may be useful to have."
528 :group 'org-export-tables
529 :type 'boolean)
531 (defcustom org-export-prefer-native-exporter-for-tables nil
532 "Non-nil means always export tables created with table.el natively.
533 Natively means use the HTML code generator in table.el.
534 When nil, Org-mode's own HTML generator is used when possible (i.e. if
535 the table does not use row- or column-spanning). This has the
536 advantage, that the automatic HTML conversions for math symbols and
537 sub/superscripts can be applied. Org-mode's HTML generator is also
538 much faster. The LaTeX exporter always use the native exporter for
539 table.el tables."
540 :group 'org-export-tables
541 :type 'boolean)
544 (defgroup org-export-xml nil
545 "Options specific for XML export of Org-mode files."
546 :tag "Org Export XML"
547 :group 'org-export)
549 ;;;; Exporting
551 ;;; Variables, constants, and parameter plists
553 (defconst org-level-max 20)
555 (defvar org-current-export-file nil) ; dynamically scoped parameter
556 (defvar org-current-export-dir nil) ; dynamically scoped parameter
557 (defvar org-export-opt-plist nil
558 "Contains the current option plist.")
559 (defvar org-last-level nil) ; dynamically scoped variable
560 (defvar org-min-level nil) ; dynamically scoped variable
561 (defvar org-levels-open nil) ; dynamically scoped parameter
563 (defconst org-export-plist-vars
564 '((:link-up nil org-export-html-link-up)
565 (:link-home nil org-export-html-link-home)
566 (:language nil org-export-default-language)
567 (:keywords nil org-export-page-keywords)
568 (:description nil org-export-page-description)
569 (:customtime nil org-display-custom-times)
570 (:headline-levels "H" org-export-headline-levels)
571 (:section-numbers "num" org-export-with-section-numbers)
572 (:section-number-format nil org-export-section-number-format)
573 (:table-of-contents "toc" org-export-with-toc)
574 (:preserve-breaks "\\n" org-export-preserve-breaks)
575 (:archived-trees nil org-export-with-archived-trees)
576 (:emphasize "*" org-export-with-emphasize)
577 (:sub-superscript "^" org-export-with-sub-superscripts)
578 (:special-strings "-" org-export-with-special-strings)
579 (:footnotes "f" org-export-with-footnotes)
580 (:drawers "d" org-export-with-drawers)
581 (:tags "tags" org-export-with-tags)
582 (:todo-keywords "todo" org-export-with-todo-keywords)
583 (:priority "pri" org-export-with-priority)
584 (:TeX-macros "TeX" org-export-with-TeX-macros)
585 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
586 (:latex-listings nil org-export-latex-listings)
587 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
588 (:fixed-width ":" org-export-with-fixed-width)
589 (:timestamps "<" org-export-with-timestamps)
590 (:author-info "author" org-export-author-info)
591 (:email-info "email" org-export-email-info)
592 (:creator-info "creator" org-export-creator-info)
593 (:time-stamp-file "timestamp" org-export-time-stamp-file)
594 (:tables "|" org-export-with-tables)
595 (:table-auto-headline nil org-export-highlight-first-table-line)
596 (:style-include-default nil org-export-html-style-include-default)
597 (:style-include-scripts nil org-export-html-style-include-scripts)
598 (:style nil org-export-html-style)
599 (:style-extra nil org-export-html-style-extra)
600 (:agenda-style nil org-agenda-export-html-style)
601 (:convert-org-links nil org-export-html-link-org-files-as-html)
602 (:inline-images nil org-export-html-inline-images)
603 (:html-extension nil org-export-html-extension)
604 (:xml-declaration nil org-export-html-xml-declaration)
605 (:html-table-tag nil org-export-html-table-tag)
606 (:expand-quoted-html "@" org-export-html-expand)
607 (:timestamp nil org-export-html-with-timestamp)
608 (:publishing-directory nil org-export-publishing-directory)
609 (:preamble nil org-export-html-preamble)
610 (:postamble nil org-export-html-postamble)
611 (:auto-preamble nil org-export-html-auto-preamble)
612 (:auto-postamble nil org-export-html-auto-postamble)
613 (:author nil user-full-name)
614 (:email nil user-mail-address)
615 (:select-tags nil org-export-select-tags)
616 (:exclude-tags nil org-export-exclude-tags)
618 (:latex-image-options nil org-export-latex-image-default-option))
619 "List of properties that represent export/publishing variables.
620 Each element is a list of 3 items:
621 1. The property that is used internally, and also for org-publish-project-alist
622 2. The string that can be used in the OPTION lines to set this option,
623 or nil if this option cannot be changed in this way
624 3. The customization variable that sets the default for this option."
627 (defun org-default-export-plist ()
628 "Return the property list with default settings for the export variables."
629 (let* ((infile (org-infile-export-plist))
630 (letbind (plist-get infile :let-bind))
631 (l org-export-plist-vars) rtn e s v)
632 (while (setq e (pop l))
633 (setq s (nth 2 e)
634 v (cond
635 ((assq s letbind) (nth 1 (assq s letbind)))
636 ((boundp s) (symbol-value s))
637 (t nil))
638 rtn (cons (car e) (cons v rtn))))
639 rtn))
641 (defvar org-export-inbuffer-options-extra nil
642 "List of additional in-buffer options that should be detected.
643 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
644 etc. Extensions can add to this list to get their options detected, and they
645 can then add a function to `org-export-options-filters' to process these
646 options.
647 Each element in this list must be a list, with the in-buffer keyword as car,
648 and a property (a symbol) as the next element. All occurrences of the
649 keyword will be found, the values concatenated with a space character
650 in between, and the result stored in the export options property list.")
652 (defvar org-export-options-filters nil
653 "Functions to be called to finalize the export/publishing options.
654 All these options are stored in a property list, and each of the functions
655 in this hook gets a chance to modify this property list. Each function
656 must accept the property list as an argument, and must return the (possibly
657 modified) list.")
659 ;; FIXME: should we fold case here?
660 (defun org-infile-export-plist ()
661 "Return the property list with file-local settings for export."
662 (save-excursion
663 (save-restriction
664 (widen)
665 (goto-char (point-min))
666 (let ((re (org-make-options-regexp
667 (append
668 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
669 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
670 "LATEX_HEADER" "LATEX_CLASS"
671 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
672 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
673 (mapcar 'car org-export-inbuffer-options-extra))))
674 p key val text options a pr style
675 latex-header latex-class macros letbind
676 ext-setup-or-nil setup-contents (start 0))
677 (while (or (and ext-setup-or-nil
678 (string-match re ext-setup-or-nil start)
679 (setq start (match-end 0)))
680 (and (setq ext-setup-or-nil nil start 0)
681 (re-search-forward re nil t)))
682 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
683 val (org-match-string-no-properties 2 ext-setup-or-nil))
684 (cond
685 ((setq a (assoc key org-export-inbuffer-options-extra))
686 (setq pr (nth 1 a))
687 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
688 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
689 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
690 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
691 ((string-equal key "DATE") (setq p (plist-put p :date val)))
692 ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
693 ((string-equal key "DESCRIPTION")
694 (setq p (plist-put p :description val)))
695 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
696 ((string-equal key "STYLE")
697 (setq style (concat style "\n" val)))
698 ((string-equal key "LATEX_HEADER")
699 (setq latex-header (concat latex-header "\n" val)))
700 ((string-equal key "LATEX_CLASS")
701 (setq latex-class val))
702 ((string-equal key "TEXT")
703 (setq text (if text (concat text "\n" val) val)))
704 ((string-equal key "OPTIONS")
705 (setq options (concat val " " options)))
706 ((string-equal key "BIND")
707 (push (read (concat "(" val ")")) letbind))
708 ((string-equal key "XSLT")
709 (setq p (plist-put p :xslt val)))
710 ((string-equal key "LINK_UP")
711 (setq p (plist-put p :link-up val)))
712 ((string-equal key "LINK_HOME")
713 (setq p (plist-put p :link-home val)))
714 ((string-equal key "EXPORT_SELECT_TAGS")
715 (setq p (plist-put p :select-tags (org-split-string val))))
716 ((string-equal key "EXPORT_EXCLUDE_TAGS")
717 (setq p (plist-put p :exclude-tags (org-split-string val))))
718 ((string-equal key "MACRO")
719 (push val macros))
720 ((equal key "SETUPFILE")
721 (setq setup-contents (org-file-contents
722 (expand-file-name
723 (org-remove-double-quotes
724 (org-trim val)))
725 'noerror))
726 (if (not ext-setup-or-nil)
727 (setq ext-setup-or-nil setup-contents start 0)
728 (setq ext-setup-or-nil
729 (concat (substring ext-setup-or-nil 0 start)
730 "\n" setup-contents "\n"
731 (substring ext-setup-or-nil start)))))))
732 (setq p (plist-put p :text text))
733 (when (and letbind (org-export-confirm-letbind))
734 (setq p (plist-put p :let-bind letbind)))
735 (when style (setq p (plist-put p :style-extra style)))
736 (when latex-header
737 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
738 (when latex-class
739 (setq p (plist-put p :latex-class latex-class)))
740 (when options
741 (setq p (org-export-add-options-to-plist p options)))
742 ;; Add macro definitions
743 (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
744 (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
745 (setq p (plist-put
746 p :macro-modification-time
747 (and (buffer-file-name)
748 (file-exists-p (buffer-file-name))
749 (concat
750 "(eval (format-time-string \"$1\" '"
751 (prin1-to-string (nth 5 (file-attributes
752 (buffer-file-name))))
753 "))"))))
754 (setq p (plist-put p :macro-input-file (and (buffer-file-name)
755 (file-name-nondirectory
756 (buffer-file-name)))))
757 (while (setq val (pop macros))
758 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val)
759 (setq p (plist-put
760 p (intern
761 (concat ":macro-" (downcase (match-string 1 val))))
762 (org-export-interpolate-newlines (match-string 2 val))))))
763 p))))
765 (defun org-export-interpolate-newlines (s)
766 (while (string-match "\\\\n" s)
767 (setq s (replace-match "\n" t t s)))
770 (defvar org-export-allow-BIND-local nil)
771 (defun org-export-confirm-letbind ()
772 "Can we use #+BIND values during export?
773 By default this will ask fro confirmation by the user, to divert possible
774 security risks."
775 (cond
776 ((not org-export-allow-BIND) nil)
777 ((eq org-export-allow-BIND t) t)
778 ((local-variable-p 'org-export-allow-BIND-local (current-buffer))
779 org-export-allow-BIND-local)
780 (t (org-set-local 'org-export-allow-BIND-local
781 (yes-or-no-p "Allow BIND values in this buffer? ")))))
783 (defun org-install-letbind ()
784 "Install the values from #+BIND lines as local variables."
785 (let ((letbind (plist-get org-export-opt-plist :let-bind))
786 pair)
787 (while (setq pair (pop letbind))
788 (org-set-local (car pair) (nth 1 pair)))))
790 (defun org-export-add-options-to-plist (p options)
791 "Parse an OPTIONS line and set values in the property list P."
792 (let (o)
793 (when options
794 (let ((op org-export-plist-vars))
795 (while (setq o (pop op))
796 (if (and (nth 1 o)
797 (string-match (concat (regexp-quote (nth 1 o))
798 ":\\([^ \t\n\r;,.]*\\)")
799 options))
800 (setq p (plist-put p (car o)
801 (car (read-from-string
802 (match-string 1 options))))))))))
805 (defun org-export-add-subtree-options (p pos)
806 "Add options in subtree at position POS to property list P."
807 (save-excursion
808 (goto-char pos)
809 (when (org-at-heading-p)
810 (let (a)
811 ;; This is actually read in `org-export-get-title-from-subtree'
812 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
813 ;; (setq p (plist-put p :title a)))
814 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
815 (setq p (plist-put p :text a)))
816 (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
817 (setq p (plist-put p :author a)))
818 (when (setq a (org-entry-get pos "EXPORT_DATE"))
819 (setq p (plist-put p :date a)))
820 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
821 (setq p (org-export-add-options-to-plist p a)))))
824 (defun org-export-directory (type plist)
825 (let* ((val (plist-get plist :publishing-directory))
826 (dir (if (listp val)
827 (or (cdr (assoc type val)) ".")
828 val)))
829 dir))
831 (defun org-export-process-option-filters (plist)
832 (let ((functions org-export-options-filters) f)
833 (while (setq f (pop functions))
834 (setq plist (funcall f plist))))
835 plist)
837 ;;;###autoload
838 (defun org-export (&optional arg)
839 "Export dispatcher for Org-mode.
840 When `org-export-run-in-background' is non-nil, try to run the command
841 in the background. This will be done only for commands that write
842 to a file. For details see the docstring of `org-export-run-in-background'.
844 The prefix argument ARG will be passed to the exporter. However, if
845 ARG is a double universal prefix `C-u C-u', that means to inverse the
846 value of `org-export-run-in-background'."
847 (interactive "P")
848 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
849 subtree-p
850 (help "[t] insert the export option template
851 \[v] limit export to visible part of outline tree
852 \[1] only export the current subtree
853 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
855 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
857 \[h] export as HTML [H] to temporary buffer [R] export region
858 \[b] export as HTML and open in browser
860 \[l] export as LaTeX [L] to temporary buffer
861 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
863 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
865 \[m] export as Freemind mind map
866 \[x] export as XOXO
867 \[g] export using Wes Hardaker's generic exporter
869 \[i] export current file as iCalendar file
870 \[I] export all agenda files as iCalendar files [c] ...as one combined file
872 \[F] publish current file [P] publish current project
873 \[X] publish a project... [E] publish every projects")
874 (cmds
875 '((?t org-insert-export-options-template nil)
876 (?v org-export-visible nil)
877 (?a org-export-as-ascii t)
878 (?A org-export-as-ascii-to-buffer t)
879 (?n org-export-as-latin1 t)
880 (?N org-export-as-latin1-to-buffer t)
881 (?u org-export-as-utf8 t)
882 (?U org-export-as-utf8-to-buffer t)
883 (?h org-export-as-html t)
884 (?b org-export-as-html-and-open t)
885 (?H org-export-as-html-to-buffer nil)
886 (?R org-export-region-as-html nil)
887 (?x org-export-as-xoxo t)
888 (?g org-export-generic t)
889 (?D org-export-as-docbook t)
890 (?V org-export-as-docbook-pdf-and-open t)
891 (?m org-export-as-freemind t)
892 (?l org-export-as-latex t)
893 (?p org-export-as-pdf t)
894 (?d org-export-as-pdf-and-open t)
895 (?L org-export-as-latex-to-buffer nil)
896 (?i org-export-icalendar-this-file t)
897 (?I org-export-icalendar-all-agenda-files t)
898 (?c org-export-icalendar-combine-agenda-files t)
899 (?F org-publish-current-file t)
900 (?P org-publish-current-project t)
901 (?X org-publish t)
902 (?E org-publish-all t)))
903 r1 r2 ass
904 (cpos (point)) (cbuf (current-buffer)) bpos)
905 (save-excursion
906 (save-window-excursion
907 (delete-other-windows)
908 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
909 (princ help))
910 (org-fit-window-to-buffer (get-buffer-window
911 "*Org Export/Publishing Help*"))
912 (message "Select command: ")
913 (setq r1 (read-char-exclusive))
914 (when (eq r1 ?1)
915 (setq subtree-p t)
916 (message "Select command (for subtree): ")
917 (setq r1 (read-char-exclusive)))
918 (when (eq r1 ?\ )
919 (let ((case-fold-search t))
920 (if (re-search-backward
921 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
922 nil t)
923 (progn
924 (org-back-to-heading t)
925 (setq subtree-p t)
926 (setq bpos (point))
927 (message "Select command (for subtree): ")
928 (setq r1 (read-char-exclusive)))
929 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
930 )))))
931 (and bpos (goto-char bpos))
932 (setq r2 (if (< r1 27) (+ r1 96) r1))
933 (unless (setq ass (assq r2 cmds))
934 (error "No command associated with key %c" r1))
935 (if (and bg (nth 2 ass)
936 (not (buffer-base-buffer))
937 (not (org-region-active-p)))
938 ;; execute in background
939 (let ((p (start-process
940 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
941 "*Org Processes*"
942 (expand-file-name invocation-name invocation-directory)
943 "-batch"
944 "-l" user-init-file
945 "--eval" "(require 'org-exp)"
946 "--eval" "(setq org-wait .2)"
947 (buffer-file-name)
948 "-f" (symbol-name (nth 1 ass)))))
949 (set-process-sentinel p 'org-export-process-sentinel)
950 (message "Background process \"%s\": started" p))
951 ;; background processing not requested, or not possible
952 (if subtree-p (progn (outline-mark-subtree) (activate-mark)))
953 (call-interactively (nth 1 ass))
954 (when (and bpos (get-buffer-window cbuf))
955 (let ((cw (selected-window)))
956 (select-window (get-buffer-window cbuf))
957 (goto-char cpos)
958 (deactivate-mark)
959 (select-window cw))))))
961 (defun org-export-process-sentinel (process status)
962 (if (string-match "\n+\\'" status)
963 (setq status (substring status 0 -1)))
964 (message "Background process \"%s\": %s" process status))
966 ;;; General functions for all backends
968 (defvar org-export-target-aliases nil
969 "Alist of targets with invisible aliases.")
970 (defvar org-export-preferred-target-alist nil
971 "Alist of section id's with preferred aliases.")
972 (defvar org-export-id-target-alist nil
973 "Alist of section id's with preferred aliases.")
974 (defvar org-export-code-refs nil
975 "Alist of code references and line numbers")
977 (defun org-export-preprocess-string (string &rest parameters)
978 "Cleanup STRING so that that the true exported has a more consistent source.
979 This function takes STRING, which should be a buffer-string of an org-file
980 to export. It then creates a temporary buffer where it does its job.
981 The result is then again returned as a string, and the exporter works
982 on this string to produce the exported version."
983 (interactive)
984 (let* ((htmlp (plist-get parameters :for-html))
985 (asciip (plist-get parameters :for-ascii))
986 (latexp (plist-get parameters :for-LaTeX))
987 (docbookp (plist-get parameters :for-docbook))
988 (backend (cond (htmlp 'html)
989 (latexp 'latex)
990 (asciip 'ascii)
991 (docbookp 'docbook)))
992 (archived-trees (plist-get parameters :archived-trees))
993 (inhibit-read-only t)
994 (drawers org-drawers)
995 (outline-regexp "\\*+ ")
996 target-alist rtn)
998 (setq org-export-target-aliases nil
999 org-export-preferred-target-alist nil
1000 org-export-id-target-alist nil
1001 org-export-code-refs nil)
1003 (with-current-buffer (get-buffer-create " org-mode-tmp")
1004 (erase-buffer)
1005 (insert string)
1006 (setq case-fold-search t)
1008 (let ((inhibit-read-only t))
1009 (remove-text-properties (point-min) (point-max)
1010 '(read-only t)))
1012 ;; Remove license-to-kill stuff
1013 ;; The caller marks some stuff for killing, stuff that has been
1014 ;; used to create the page title, for example.
1015 (org-export-kill-licensed-text)
1017 (let ((org-inhibit-startup t)) (org-mode))
1018 (setq case-fold-search t)
1019 (org-install-letbind)
1021 ;; Call the hook
1022 (run-hooks 'org-export-preprocess-hook)
1024 ;; Process the macros
1025 (org-export-preprocess-apply-macros)
1026 (run-hooks 'org-export-preprocess-after-macros-hook)
1028 (untabify (point-min) (point-max))
1030 ;; Handle include files, and call a hook
1031 (org-export-handle-include-files)
1032 (run-hooks 'org-export-preprocess-after-include-files-hook)
1034 ;; Get rid of archived trees
1035 (org-export-remove-archived-trees archived-trees)
1037 ;; Remove comment environment and comment subtrees
1038 (org-export-remove-comment-blocks-and-subtrees)
1040 ;; Get rid of excluded trees, and call a hook
1041 (org-export-handle-export-tags (plist-get parameters :select-tags)
1042 (plist-get parameters :exclude-tags))
1043 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1045 ;; Handle source code snippets
1046 (org-export-replace-src-segments-and-examples backend)
1048 ;; Protect short examples marked by a leading colon
1049 (org-export-protect-colon-examples)
1051 ;; Normalize footnotes
1052 (when (plist-get parameters :footnotes)
1053 (org-footnote-normalize nil t))
1055 ;; Find all headings and compute the targets for them
1056 (setq target-alist (org-export-define-heading-targets target-alist))
1058 (run-hooks 'org-export-preprocess-after-headline-targets-hook)
1060 ;; Find HTML special classes for headlines
1061 (org-export-remember-html-container-classes)
1063 ;; Get rid of drawers
1064 (org-export-remove-or-extract-drawers
1065 drawers (plist-get parameters :drawers) backend)
1067 ;; Get the correct stuff before the first headline
1068 (when (plist-get parameters :skip-before-1st-heading)
1069 (goto-char (point-min))
1070 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1071 (delete-region (point-min) (match-beginning 0))
1072 (goto-char (point-min))
1073 (insert "\n")))
1074 (when (plist-get parameters :add-text)
1075 (goto-char (point-min))
1076 (insert (plist-get parameters :add-text) "\n"))
1078 ;; Remove todo-keywords before exporting, if the user has requested so
1079 (org-export-remove-headline-metadata parameters)
1081 ;; Find targets in comments and move them out of comments,
1082 ;; but mark them as targets that should be invisible
1083 (setq target-alist (org-export-handle-invisible-targets target-alist))
1085 ;; Select and protect backend specific stuff, throw away stuff
1086 ;; that is specific for other backends
1087 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook)
1088 (org-export-select-backend-specific-text backend)
1090 ;; Protect quoted subtrees
1091 (org-export-protect-quoted-subtrees)
1093 ;; Remove clock lines
1094 (org-export-remove-clock-lines)
1096 ;; Protect verbatim elements
1097 (org-export-protect-verbatim)
1099 ;; Blockquotes, verse, and center
1100 (org-export-mark-blockquote-verse-center)
1101 (run-hooks 'org-export-preprocess-after-blockquote-hook)
1103 ;; Remove timestamps, if the user has requested so
1104 (unless (plist-get parameters :timestamps)
1105 (org-export-remove-timestamps))
1107 ;; Attach captions to the correct object
1108 (setq target-alist (org-export-attach-captions-and-attributes
1109 backend target-alist))
1111 ;; Find matches for radio targets and turn them into internal links
1112 (org-export-mark-radio-links)
1114 ;; Find all links that contain a newline and put them into a single line
1115 (org-export-concatenate-multiline-links)
1117 ;; Normalize links: Convert angle and plain links into bracket links
1118 ;; and expand link abbreviations
1119 (run-hooks 'org-export-preprocess-before-normalizing-links-hook)
1120 (org-export-normalize-links)
1122 ;; Find all internal links. If they have a fuzzy match (i.e. not
1123 ;; a *dedicated* target match, let the link point to the
1124 ;; corresponding section.
1125 (org-export-target-internal-links target-alist)
1127 ;; Find multiline emphasis and put them into single line
1128 (when (plist-get parameters :emph-multiline)
1129 (org-export-concatenate-multiline-emphasis))
1131 ;; Remove special table lines
1132 (when org-export-table-remove-special-lines
1133 (org-export-remove-special-table-lines))
1135 ;; Another hook
1136 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1138 ;; LaTeX-specific preprocessing
1139 (when latexp
1140 (require 'org-latex nil)
1141 (org-export-latex-preprocess parameters))
1143 ;; ASCII-specific preprocessing
1144 (when asciip
1145 (org-export-ascii-preprocess parameters))
1147 ;; HTML-specific preprocessing
1148 (when htmlp
1149 (org-export-html-preprocess parameters))
1151 ;; DocBook-specific preprocessing
1152 (when docbookp
1153 (require 'org-docbook nil)
1154 (org-export-docbook-preprocess parameters))
1156 ;; Remove or replace comments
1157 (org-export-handle-comments (plist-get parameters :comments))
1159 ;; Run the final hook
1160 (run-hooks 'org-export-preprocess-final-hook)
1162 (setq rtn (buffer-string)))
1163 (kill-buffer " org-mode-tmp")
1164 rtn))
1166 (defun org-export-kill-licensed-text ()
1167 "Remove all text that is marked with a :org-license-to-kill property."
1168 (let (p)
1169 (while (setq p (text-property-any (point-min) (point-max)
1170 :org-license-to-kill t))
1171 (delete-region
1172 p (or (next-single-property-change p :org-license-to-kill)
1173 (point-max))))))
1175 (defun org-export-define-heading-targets (target-alist)
1176 "Find all headings and define the targets for them.
1177 The new targets are added to TARGET-ALIST, which is also returned.
1178 Also find all ID and CUSTOM_ID propertiess and store them."
1179 (goto-char (point-min))
1180 (org-init-section-numbers)
1181 (let ((re (concat "^" org-outline-regexp
1182 "\\|"
1183 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1184 level target last-section-target a id)
1185 (while (re-search-forward re nil t)
1186 (org-if-unprotected-at (match-beginning 0)
1187 (if (match-end 2)
1188 (progn
1189 (setq id (org-match-string-no-properties 2))
1190 (push (cons id target) target-alist)
1191 (setq a (or (assoc last-section-target org-export-target-aliases)
1192 (progn
1193 (push (list last-section-target)
1194 org-export-target-aliases)
1195 (car org-export-target-aliases))))
1196 (push (caar target-alist) (cdr a))
1197 (when (equal (match-string 1) "CUSTOM_ID")
1198 (if (not (assoc last-section-target
1199 org-export-preferred-target-alist))
1200 (push (cons last-section-target id)
1201 org-export-preferred-target-alist)))
1202 (when (equal (match-string 1) "ID")
1203 (if (not (assoc last-section-target
1204 org-export-id-target-alist))
1205 (push (cons last-section-target (concat "ID-" id))
1206 org-export-id-target-alist))))
1207 (setq level (org-reduced-level
1208 (save-excursion (goto-char (point-at-bol))
1209 (org-outline-level))))
1210 (setq target (org-solidify-link-text
1211 (format "sec-%s" (replace-regexp-in-string
1212 "\\." "_"
1213 (org-section-number level)))))
1214 (setq last-section-target target)
1215 (push (cons target target) target-alist)
1216 (add-text-properties
1217 (point-at-bol) (point-at-eol)
1218 (list 'target target))))))
1219 target-alist)
1221 (defun org-export-handle-invisible-targets (target-alist)
1222 "Find targets in comments and move them out of comments.
1223 Mark them as invisible targets."
1224 (let (target tmp a)
1225 (goto-char (point-min))
1226 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1227 ;; Check if the line before or after is a headline with a target
1228 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1229 (get-text-property (point-at-bol 2) 'target)))
1230 (progn
1231 ;; use the existing target in a neighboring line
1232 (setq tmp (match-string 2))
1233 (replace-match "")
1234 (and (looking-at "\n") (delete-char 1))
1235 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1236 target-alist)
1237 (setq a (or (assoc target org-export-target-aliases)
1238 (progn
1239 (push (list target) org-export-target-aliases)
1240 (car org-export-target-aliases))))
1241 (push tmp (cdr a)))
1242 ;; Make an invisible target
1243 (replace-match "\\1(INVISIBLE)"))))
1244 target-alist)
1246 (defun org-export-target-internal-links (target-alist)
1247 "Find all internal links and assign targets to them.
1248 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1249 let the link point to the corresponding section.
1250 This function also handles the id links, if they have a match in
1251 the current file."
1252 (goto-char (point-min))
1253 (while (re-search-forward org-bracket-link-regexp nil t)
1254 (org-if-unprotected-at (1+ (match-beginning 0))
1255 (let* ((md (match-data))
1256 (desc (match-end 2))
1257 (link (org-link-unescape (match-string 1)))
1258 (slink (org-solidify-link-text link))
1259 found props pos cref
1260 (target
1261 (cond
1262 ((= (string-to-char link) ?#)
1263 ;; user wants exactly this link
1264 link)
1265 ((cdr (assoc slink target-alist))
1266 (or (cdr (assoc (assoc slink target-alist)
1267 org-export-preferred-target-alist))
1268 (cdr (assoc slink target-alist))))
1269 ((and (string-match "^id:" link)
1270 (cdr (assoc (substring link 3) target-alist))))
1271 ((string-match "^(\\(.*\\))$" link)
1272 (setq cref (match-string 1 link))
1273 (concat "coderef:" cref))
1274 ((string-match org-link-types-re link) nil)
1275 ((or (file-name-absolute-p link)
1276 (string-match "^\\." link))
1277 nil)
1279 (save-excursion
1280 (setq found (condition-case nil (org-link-search link)
1281 (error nil)))
1282 (when (and found
1283 (or (org-on-heading-p)
1284 (not (eq found 'dedicated))))
1285 (or (get-text-property (point) 'target)
1286 (get-text-property
1287 (max (point-min)
1288 (1- (or (previous-single-property-change
1289 (point) 'target) 0)))
1290 'target))))))))
1291 (when target
1292 (set-match-data md)
1293 (goto-char (match-beginning 1))
1294 (setq props (text-properties-at (point)))
1295 (delete-region (match-beginning 1) (match-end 1))
1296 (setq pos (point))
1297 (insert target)
1298 (unless desc (insert "][" link))
1299 (add-text-properties pos (point) props))))))
1301 (defun org-export-remember-html-container-classes ()
1302 "Store the HTML_CONTAINER_CLASS properties in a text property."
1303 (goto-char (point-min))
1304 (let (class)
1305 (while (re-search-forward
1306 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(\\S-+\\)" nil t)
1307 (setq class (match-string 1))
1308 (save-excursion
1309 (org-back-to-heading t)
1310 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class)))))
1312 (defvar org-export-format-drawer-function nil
1313 "Function to be called to format the contents of a drawer.
1314 The function must accept three parameters:
1315 NAME the drawer name, like \"PROPERTIES\"
1316 CONTENT the content of the drawer.
1317 BACKEND one of the symbols html, docbook, latex, ascii, xoxo
1318 The function should return the text to be inserted into the buffer.
1319 If this is nil, `org-export-format-drawer' is used as a default.")
1321 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend)
1322 "Remove drawers, or extract and format the content.
1323 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1324 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1325 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1326 EXP-DRAWERS will be removed.
1327 BACKEND is the current export backend."
1328 (goto-char (point-min))
1329 (let ((re (concat "^[ \t]*:\\("
1330 (mapconcat 'identity all-drawers "\\|")
1331 "\\):[ \t]*$"))
1332 name beg beg-content eol content)
1333 (while (re-search-forward re nil t)
1334 (org-if-unprotected
1335 (setq name (match-string 1))
1336 (setq beg (match-beginning 0)
1337 beg-content (1+ (point-at-eol))
1338 eol (point-at-eol))
1339 (if (not (and (re-search-forward
1340 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t)
1341 (match-end 1)))
1342 (goto-char eol)
1343 (goto-char (match-beginning 0))
1344 (and (looking-at ".*\n?") (replace-match ""))
1345 (setq content (buffer-substring beg-content (point)))
1346 (delete-region beg (point))
1347 (when (or (eq exp-drawers t)
1348 (member name exp-drawers))
1349 (setq content (funcall (or org-export-format-drawer-function
1350 'org-export-format-drawer)
1351 name content backend))
1352 (insert content)))))))
1354 (defun org-export-format-drawer (name content backend)
1355 "Format the content of a drawer as a colon example."
1356 (if (string-match "[ \t]+\\'" content)
1357 (setq content (substring content (match-beginning 0))))
1358 (while (string-match "\\`[ \t]*\n" content)
1359 (setq content (substring content (match-end 0))))
1360 (setq content (org-remove-indentation content))
1361 (setq content (concat ": " (mapconcat 'identity
1362 (org-split-string content "\n")
1363 "\n: ")
1364 "\n"))
1365 (setq content (concat " : " (upcase name) "\n" content))
1366 (org-add-props content nil 'org-protected t))
1368 (defun org-export-handle-export-tags (select-tags exclude-tags)
1369 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1370 Both arguments are lists of tags.
1371 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1372 will be removed.
1373 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1374 removed as well."
1375 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1376 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1377 select-tags "\\|")
1378 "\\):"))
1379 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1380 exclude-tags "\\|")
1381 "\\):"))
1382 beg end cont)
1383 (goto-char (point-min))
1384 (when (and select-tags
1385 (re-search-forward
1386 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1387 ;; At least one tree is marked for export, this means
1388 ;; all the unmarked stuff needs to go.
1389 ;; Dig out the trees that should be exported
1390 (goto-char (point-min))
1391 (outline-next-heading)
1392 (setq beg (point))
1393 (put-text-property beg (point-max) :org-delete t)
1394 (while (re-search-forward re-sel nil t)
1395 (when (org-on-heading-p)
1396 (org-back-to-heading)
1397 (remove-text-properties
1398 (max (1- (point)) (point-min))
1399 (setq cont (save-excursion (org-end-of-subtree t t)))
1400 '(:org-delete t))
1401 (while (and (org-up-heading-safe)
1402 (get-text-property (point) :org-delete))
1403 (remove-text-properties (max (1- (point)) (point-min))
1404 (point-at-eol) '(:org-delete t)))
1405 (goto-char cont))))
1406 ;; Remove the trees explicitly marked for noexport
1407 (when exclude-tags
1408 (goto-char (point-min))
1409 (while (re-search-forward re-excl nil t)
1410 (when (org-at-heading-p)
1411 (org-back-to-heading t)
1412 (setq beg (point))
1413 (org-end-of-subtree t t)
1414 (delete-region beg (point))
1415 (when (featurep 'org-inlinetask)
1416 (org-inlinetask-remove-END-maybe)))))
1417 ;; Remove everything that is now still marked for deletion
1418 (goto-char (point-min))
1419 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1420 (setq end (or (next-single-property-change beg :org-delete)
1421 (point-max)))
1422 (delete-region beg end))))
1424 (defun org-export-remove-archived-trees (export-archived-trees)
1425 "Remove archived trees.
1426 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1427 When it is t, the entire archived tree will be exported.
1428 When it is nil the entire tree including the headline will be removed
1429 from the buffer."
1430 (let ((re-archive (concat ":" org-archive-tag ":"))
1431 a b)
1432 (when (not (eq export-archived-trees t))
1433 (goto-char (point-min))
1434 (while (re-search-forward re-archive nil t)
1435 (if (not (org-on-heading-p t))
1436 (org-end-of-subtree t)
1437 (beginning-of-line 1)
1438 (setq a (if export-archived-trees
1439 (1+ (point-at-eol)) (point))
1440 b (org-end-of-subtree t))
1441 (if (> b a) (delete-region a b)))))))
1443 (defun org-export-remove-headline-metadata (opts)
1444 "Remove meta data from the headline, according to user options."
1445 (let ((re org-complex-heading-regexp)
1446 (todo (plist-get opts :todo-keywords))
1447 (tags (plist-get opts :tags))
1448 (pri (plist-get opts :priority))
1449 (elts '(1 2 3 4 5))
1450 rpl)
1451 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1452 (when (or (not todo) (not tags) (not pri))
1453 (goto-char (point-min))
1454 (while (re-search-forward re nil t)
1455 (org-if-unprotected
1456 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1457 elts " "))
1458 (replace-match rpl t t))))))
1460 (defun org-export-remove-timestamps ()
1461 "Remove timestamps and keywords for export."
1462 (goto-char (point-min))
1463 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1464 (backward-char 1)
1465 (org-if-unprotected
1466 (unless (save-match-data (org-at-table-p))
1467 (replace-match "")
1468 (beginning-of-line 1)
1469 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1470 (replace-match ""))))))
1472 (defun org-export-remove-clock-lines ()
1473 "Remove clock lines for export."
1474 (goto-char (point-min))
1475 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1476 (while (re-search-forward re nil t)
1477 (org-if-unprotected
1478 (replace-match "")))))
1480 (defun org-export-protect-quoted-subtrees ()
1481 "Mark quoted subtrees with the protection property."
1482 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1483 (goto-char (point-min))
1484 (while (re-search-forward re-quote nil t)
1485 (goto-char (match-beginning 0))
1486 (end-of-line 1)
1487 (add-text-properties (point) (org-end-of-subtree t)
1488 '(org-protected t)))))
1490 (defun org-export-protect-verbatim ()
1491 "Mark verbatim snippets with the protection property."
1492 (goto-char (point-min))
1493 (while (re-search-forward org-verbatim-re nil t)
1494 (org-if-unprotected
1495 (add-text-properties (match-beginning 4) (match-end 4)
1496 '(org-protected t org-verbatim-emph t))
1497 (goto-char (1+ (match-end 4))))))
1499 (defun org-export-protect-colon-examples ()
1500 "Protect lines starting with a colon."
1501 (goto-char (point-min))
1502 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1503 (while (re-search-forward re nil t)
1504 (beginning-of-line 1)
1505 (setq beg (point))
1506 (while (looking-at re)
1507 (end-of-line 1)
1508 (or (eobp) (forward-char 1)))
1509 (add-text-properties beg (if (bolp) (1- (point)) (point))
1510 '(org-protected t)))))
1512 (defun org-export-select-backend-specific-text (backend)
1513 (let ((formatters
1514 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1515 (html "HTML" "BEGIN_HTML" "END_HTML")
1516 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1517 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1518 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1519 (case-fold-search t)
1520 fmt beg beg-content end end-content)
1522 (while formatters
1523 (setq fmt (pop formatters))
1524 (when (eq (car fmt) backend)
1525 ;; This is selected code, put it into the file for real
1526 (goto-char (point-min))
1527 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
1528 ":[ \t]*\\(.*\\)") nil t)
1529 (replace-match "\\1\\2" t)
1530 (add-text-properties
1531 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1532 '(org-protected t))))
1533 (goto-char (point-min))
1534 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt) "\\>.*\n?")
1535 nil t)
1536 (setq beg (match-beginning 0) beg-content (match-end 0))
1537 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?")
1538 nil t)
1539 (setq end (match-end 0) end-content (match-beginning 0))
1540 (if (eq (car fmt) backend)
1541 ;; yes, keep this
1542 (progn
1543 (add-text-properties beg-content end-content '(org-protected t))
1544 (delete-region (match-beginning 0) (match-end 0))
1545 (save-excursion
1546 (goto-char beg)
1547 (delete-region (point) (1+ (point-at-eol)))))
1548 ;; No, this is for a different backend, kill it
1549 (delete-region beg end)))))))
1551 (defun org-export-mark-blockquote-verse-center ()
1552 "Mark block quote and verse environments with special cookies.
1553 These special cookies will later be interpreted by the backend."
1554 ;; Blockquotes
1555 (let (type t1 ind beg end beg1 end1 content)
1556 (goto-char (point-min))
1557 (while (re-search-forward
1558 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1559 nil t)
1560 (setq ind (length (match-string 1))
1561 type (downcase (match-string 3))
1562 t1 (if (equal type "quote") "blockquote" type))
1563 (setq beg (match-beginning 0)
1564 beg1 (1+ (match-end 0)))
1565 (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
1566 (setq end (1+ (point-at-eol))
1567 end1 (1- (match-beginning 0)))
1568 (setq content (org-remove-indentation (buffer-substring beg1 end1)))
1569 (setq content (concat "ORG-" (upcase t1) "-START\n"
1570 content "\n"
1571 "ORG-" (upcase t1) "-END\n"))
1572 (delete-region beg end)
1573 (insert (org-add-props content nil 'original-indentation ind))))))
1575 (defun org-export-attach-captions-and-attributes (backend target-alist)
1576 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1577 If the next thing following is a table, add the text properties to the first
1578 table line. If it is a link, add it to the line containing the link."
1579 (goto-char (point-min))
1580 (remove-text-properties (point-min) (point-max)
1581 '(org-caption nil org-attributes nil))
1582 (let ((case-fold-search t)
1583 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1584 "\\|"
1585 "^[ \t]*#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
1586 "\\|"
1587 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1588 "\\|"
1589 "^[ \t]*\\(|[^-]\\)"
1590 "\\|"
1591 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1592 cap attr label end)
1593 (while (re-search-forward re nil t)
1594 (cond
1595 ((match-end 1)
1596 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
1597 ((match-end 2)
1598 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
1599 ((match-end 3)
1600 (setq label (org-trim (match-string 3))))
1602 (setq end (if (match-end 4)
1603 (let ((ee (org-table-end)))
1604 (prog1 (1- (marker-position ee)) (move-marker ee nil)))
1605 (point-at-eol)))
1606 (add-text-properties (point-at-bol) end
1607 (list 'org-caption cap
1608 'org-attributes attr
1609 'org-label label))
1610 (if label (push (cons label label) target-alist))
1611 (goto-char end)
1612 (setq cap nil attr nil label nil)))))
1613 target-alist)
1615 (defun org-export-remove-comment-blocks-and-subtrees ()
1616 "Remove the comment environment, and also commented subtrees."
1617 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1618 case-fold-search)
1619 ;; Remove comment environment
1620 (goto-char (point-min))
1621 (setq case-fold-search t)
1622 (while (re-search-forward
1623 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t)
1624 (replace-match "" t t))
1625 ;; Remove subtrees that are commented
1626 (goto-char (point-min))
1627 (setq case-fold-search nil)
1628 (while (re-search-forward re-commented nil t)
1629 (goto-char (match-beginning 0))
1630 (delete-region (point) (org-end-of-subtree t)))))
1632 (defun org-export-handle-comments (commentsp)
1633 "Remove comments, or convert to backend-specific format.
1634 COMMENTSP can be a format string for publishing comments.
1635 When it is nil, all comments will be removed."
1636 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1637 pos)
1638 (goto-char (point-min))
1639 (while (or (looking-at re)
1640 (re-search-forward re nil t))
1641 (setq pos (match-beginning 0))
1642 (if (and commentsp
1643 (not (equal (char-before (match-end 1)) ?+)))
1644 (progn (add-text-properties
1645 (match-beginning 0) (match-end 0) '(org-protected t))
1646 (replace-match (format commentsp (match-string 2)) t t))
1647 (goto-char (1+ pos))
1648 (org-if-unprotected
1649 (replace-match "")
1650 (goto-char (max (point-min) (1- pos))))))))
1652 (defun org-export-mark-radio-links ()
1653 "Find all matches for radio targets and turn them into internal links."
1654 (let ((re-radio (and org-target-link-regexp
1655 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1656 (goto-char (point-min))
1657 (when re-radio
1658 (while (re-search-forward re-radio nil t)
1659 (unless
1660 (save-match-data
1661 (or (org-in-regexp org-bracket-link-regexp)
1662 (org-in-regexp org-plain-link-re)
1663 (org-in-regexp "<<[^<>]+>>")))
1664 (org-if-unprotected
1665 (replace-match "\\1[[\\2]]")))))))
1667 (defun org-export-remove-special-table-lines ()
1668 "Remove tables lines that are used for internal purposes."
1669 (goto-char (point-min))
1670 (while (re-search-forward "^[ \t]*|" nil t)
1671 (beginning-of-line 1)
1672 (if (or (looking-at "[ \t]*| *[!_^] *|")
1673 (not
1674 (memq
1676 (mapcar
1677 (lambda (f)
1678 (or (= (length f) 0)
1679 (string-match
1680 "\\`<\\([0-9]\\|[rl]\\|[rl][0-9]+\\)>\\'" f)))
1681 (org-split-string ;; FIXME, can't we do this without splitting???
1682 (buffer-substring (point-at-bol) (point-at-eol))
1683 "[ \t]*|[ \t]*")))))
1684 (delete-region (max (point-min) (1- (point-at-bol)))
1685 (point-at-eol))
1686 (end-of-line 1))))
1688 (defun org-export-protect-sub-super (s)
1689 (save-match-data
1690 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s)
1691 (setq s (replace-match "\\1\\\\\\2" nil nil s)))
1694 (defun org-export-normalize-links ()
1695 "Convert all links to bracket links, and expand link abbreviations."
1696 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1697 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1698 nodesc)
1699 (goto-char (point-min))
1700 (while (re-search-forward re-plain-link nil t)
1701 (goto-char (1- (match-end 0)))
1702 (org-if-unprotected-at (1+ (match-beginning 0))
1703 (let* ((s (concat (match-string 1)
1704 "[[" (match-string 2) ":" (match-string 3)
1705 "][" (match-string 2) ":" (org-export-protect-sub-super
1706 (match-string 3))
1707 "]]")))
1708 ;; added 'org-link face to links
1709 (put-text-property 0 (length s) 'face 'org-link s)
1710 (replace-match s t t))))
1711 (goto-char (point-min))
1712 (while (re-search-forward re-angle-link nil t)
1713 (goto-char (1- (match-end 0)))
1714 (org-if-unprotected
1715 (let* ((s (concat (match-string 1)
1716 "[[" (match-string 2) ":" (match-string 3)
1717 "][" (match-string 2) ":" (org-export-protect-sub-super
1718 (match-string 3))
1719 "]]")))
1720 (put-text-property 0 (length s) 'face 'org-link s)
1721 (replace-match s t t))))
1722 (goto-char (point-min))
1723 (while (re-search-forward org-bracket-link-regexp nil t)
1724 (goto-char (1- (match-end 0)))
1725 (setq nodesc (not (match-end 3)))
1726 (org-if-unprotected
1727 (let* ((xx (save-match-data
1728 (org-translate-link
1729 (org-link-expand-abbrev (match-string 1)))))
1730 (s (concat
1731 "[[" (org-add-props (copy-sequence xx)
1732 nil 'org-protected t 'org-no-description nodesc)
1734 (if (match-end 3)
1735 (match-string 2)
1736 (concat "[" (copy-sequence xx)
1737 "]"))
1738 "]")))
1739 (put-text-property 0 (length s) 'face 'org-link s)
1740 (replace-match s t t))))))
1742 (defun org-export-concatenate-multiline-links ()
1743 "Find multi-line links and put it all into a single line.
1744 This is to make sure that the line-processing export backends
1745 can work correctly."
1746 (goto-char (point-min))
1747 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1748 (org-if-unprotected-at (match-beginning 1)
1749 (replace-match "\\1 \\3")
1750 (goto-char (match-beginning 0)))))
1752 (defun org-export-concatenate-multiline-emphasis ()
1753 "Find multi-line emphasis and put it all into a single line.
1754 This is to make sure that the line-processing export backends
1755 can work correctly."
1756 (goto-char (point-min))
1757 (while (re-search-forward org-emph-re nil t)
1758 (if (and (not (= (char-after (match-beginning 3))
1759 (char-after (match-beginning 4))))
1760 (save-excursion (goto-char (match-beginning 0))
1761 (save-match-data (not (org-at-table-p)))))
1762 (org-if-unprotected
1763 (subst-char-in-region (match-beginning 0) (match-end 0)
1764 ?\n ?\ t)
1765 (goto-char (1- (match-end 0))))
1766 (goto-char (1+ (match-beginning 0))))))
1768 (defun org-export-grab-title-from-buffer ()
1769 "Get a title for the current document, from looking at the buffer."
1770 (let ((inhibit-read-only t))
1771 (save-excursion
1772 (goto-char (point-min))
1773 (let ((end (if (looking-at org-outline-regexp)
1774 (point)
1775 (save-excursion (outline-next-heading) (point)))))
1776 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1777 ;; Mark the line so that it will not be exported as normal text.
1778 (org-unmodified
1779 (add-text-properties (match-beginning 0) (match-end 0)
1780 (list :org-license-to-kill t)))
1781 ;; Return the title string
1782 (org-trim (match-string 0)))))))
1784 (defun org-export-get-title-from-subtree ()
1785 "Return subtree title and exclude it from export."
1786 (let (title (rbeg (region-beginning)) (rend (region-end)))
1787 (save-excursion
1788 (goto-char rbeg)
1789 (when (and (org-at-heading-p)
1790 (>= (org-end-of-subtree t t) rend))
1791 ;; This is a subtree, we take the title from the first heading
1792 (goto-char rbeg)
1793 (looking-at org-todo-line-regexp)
1794 (setq title (match-string 3))
1795 (org-unmodified
1796 (add-text-properties (point) (1+ (point-at-eol))
1797 (list :org-license-to-kill t)))
1798 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1799 title))
1801 (defun org-solidify-link-text (s &optional alist)
1802 "Take link text and make a safe target out of it."
1803 (save-match-data
1804 (let* ((rtn
1805 (mapconcat
1806 'identity
1807 (org-split-string s "[ \t\r\n]+") "=="))
1808 (a (assoc rtn alist)))
1809 (or (cdr a) rtn))))
1811 (defun org-get-min-level (lines &optional offset)
1812 "Get the minimum level in LINES."
1813 (let ((re "^\\(\\*+\\) ") l)
1814 (catch 'exit
1815 (while (setq l (pop lines))
1816 (if (string-match re l)
1817 (throw 'exit (org-tr-level (- (length (match-string 1 l))
1818 (or offset 0))))))
1819 1)))
1821 ;; Variable holding the vector with section numbers
1822 (defvar org-section-numbers (make-vector org-level-max 0))
1824 (defun org-init-section-numbers ()
1825 "Initialize the vector for the section numbers."
1826 (let* ((level -1)
1827 (numbers (nreverse (org-split-string "" "\\.")))
1828 (depth (1- (length org-section-numbers)))
1829 (i depth) number-string)
1830 (while (>= i 0)
1831 (if (> i level)
1832 (aset org-section-numbers i 0)
1833 (setq number-string (or (car numbers) "0"))
1834 (if (string-match "\\`[A-Z]\\'" number-string)
1835 (aset org-section-numbers i
1836 (- (string-to-char number-string) ?A -1))
1837 (aset org-section-numbers i (string-to-number number-string)))
1838 (pop numbers))
1839 (setq i (1- i)))))
1841 (defun org-section-number (&optional level)
1842 "Return a string with the current section number.
1843 When LEVEL is non-nil, increase section numbers on that level."
1844 (let* ((depth (1- (length org-section-numbers)))
1845 (string "")
1846 (fmts (car org-export-section-number-format))
1847 (term (cdr org-export-section-number-format))
1848 (sep "")
1849 ctype fmt idx n)
1850 (when level
1851 (when (> level -1)
1852 (aset org-section-numbers
1853 level (1+ (aref org-section-numbers level))))
1854 (setq idx (1+ level))
1855 (while (<= idx depth)
1856 (if (not (= idx 1))
1857 (aset org-section-numbers idx 0))
1858 (setq idx (1+ idx))))
1859 (setq idx 0)
1860 (while (<= idx depth)
1861 (when (> (aref org-section-numbers idx) 0)
1862 (setq fmt (or (pop fmts) fmt)
1863 ctype (car fmt)
1864 n (aref org-section-numbers idx)
1865 string (if (> n 0)
1866 (concat string sep (org-number-to-counter n ctype))
1867 (concat string ".0"))
1868 sep (nth 1 fmt)))
1869 (setq idx (1+ idx)))
1870 (save-match-data
1871 (if (string-match "\\`\\([@0]\\.\\)+" string)
1872 (setq string (replace-match "" t nil string)))
1873 (if (string-match "\\(\\.0\\)+\\'" string)
1874 (setq string (replace-match "" t nil string))))
1875 (concat string term)))
1877 (defun org-number-to-counter (n type)
1878 "Concert number N to a string counter, according to TYPE.
1879 TYPE must be a string, any of:
1880 1 number
1881 A A,B,....
1882 a a,b,....
1883 I upper case roman numeral
1884 i lower case roman numeral"
1885 (cond
1886 ((equal type "1") (number-to-string n))
1887 ((equal type "A") (char-to-string (+ ?A n -1)))
1888 ((equal type "a") (char-to-string (+ ?a n -1)))
1889 ((equal type "I") (org-number-to-roman n))
1890 ((equal type "i") (downcase (org-number-to-roman n)))
1891 (t (error "Invalid counter type `%s'" type))))
1893 (defun org-number-to-roman (n)
1894 "Convert integer N into a roman numeral."
1895 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
1896 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1897 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1898 ( 1 . "I")))
1899 (res ""))
1900 (if (<= n 0)
1901 (number-to-string n)
1902 (while roman
1903 (if (>= n (caar roman))
1904 (setq n (- n (caar roman))
1905 res (concat res (cdar roman)))
1906 (pop roman)))
1907 res)))
1909 ;;; Macros
1911 (defun org-export-preprocess-apply-macros ()
1912 "Replace macro references."
1913 (goto-char (point-min))
1914 (let (sy val key args args2 s n)
1915 (while (re-search-forward
1916 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
1917 nil t)
1918 (unless (save-match-data
1919 (save-excursion
1920 (goto-char (point-at-bol))
1921 (looking-at "[ \t]*#\\+macro")))
1922 (setq key (downcase (match-string 1))
1923 args (match-string 3))
1924 (when (setq val (or (plist-get org-export-opt-plist
1925 (intern (concat ":macro-" key)))
1926 (plist-get org-export-opt-plist
1927 (intern (concat ":" key)))))
1928 (save-match-data
1929 (when args
1930 (setq args (org-split-string args ",[ \t\n]*") args2 nil)
1931 (setq args (mapcar 'org-trim args))
1932 (while args
1933 (while (string-match "\\\\\\'" (car args))
1934 ;; repair bad splits
1935 (setcar (cdr args) (concat (substring (car args) 0 -1)
1936 ";" (nth 1 args)))
1937 (pop args))
1938 (push (pop args) args2))
1939 (setq args (nreverse args2))
1940 (setq s 0)
1941 (while (string-match "\\$\\([0-9]+\\)" val s)
1942 (setq s (1+ (match-beginning 0))
1943 n (string-to-number (match-string 1 val)))
1944 (and (>= (length args) n)
1945 (setq val (replace-match (nth (1- n) args) t t val)))))
1946 (when (string-match "\\`(eval\\>" val)
1947 (setq val (eval (read val))))
1948 (if (and val (not (stringp val)))
1949 (setq val (format "%s" val))))
1950 (and (stringp val)
1951 (prog1 (replace-match val t t)
1952 (goto-char (match-beginning 0)))))))))
1954 (defun org-export-apply-macros-in-string (s)
1955 "Apply the macros in string S."
1956 (when s
1957 (with-temp-buffer
1958 (insert s)
1959 (org-export-preprocess-apply-macros)
1960 (buffer-string))))
1962 ;;; Include files
1964 (defun org-export-handle-include-files ()
1965 "Include the contents of include files, with proper formatting."
1966 (let ((case-fold-search t)
1967 params file markup lang start end prefix prefix1 switches)
1968 (goto-char (point-min))
1969 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
1970 (setq params (read (concat "(" (match-string 1) ")"))
1971 prefix (org-get-and-remove-property 'params :prefix)
1972 prefix1 (org-get-and-remove-property 'params :prefix1)
1973 file (org-symname-or-string (pop params))
1974 markup (org-symname-or-string (pop params))
1975 lang (and (member markup '("src" "SRC"))
1976 (org-symname-or-string (pop params)))
1977 switches (mapconcat '(lambda (x) (format "%s" x)) params " ")
1978 start nil end nil)
1979 (delete-region (match-beginning 0) (match-end 0))
1980 (if (or (not file)
1981 (not (file-exists-p file))
1982 (not (file-readable-p file)))
1983 (insert (format "CANNOT INCLUDE FILE %s" file))
1984 (when markup
1985 (if (equal (downcase markup) "src")
1986 (setq start (format "#+begin_src %s %s\n"
1987 (or lang "fundamental")
1988 (or switches ""))
1989 end "#+end_src")
1990 (setq start (format "#+begin_%s %s\n" markup switches)
1991 end (format "#+end_%s" markup))))
1992 (insert (or start ""))
1993 (insert (org-get-file-contents (expand-file-name file)
1994 prefix prefix1 markup))
1995 (or (bolp) (newline))
1996 (insert (or end ""))))))
1998 (defun org-get-file-contents (file &optional prefix prefix1 markup)
1999 "Get the contents of FILE and return them as a string.
2000 If PREFIX is a string, prepend it to each line. If PREFIX1
2001 is a string, prepend it to the first line instead of PREFIX.
2002 If MARKUP, don't protect org-like lines, the exporter will
2003 take care of the block they are in."
2004 (if (stringp markup) (setq markup (downcase markup)))
2005 (with-temp-buffer
2006 (insert-file-contents file)
2007 (when (or prefix prefix1)
2008 (goto-char (point-min))
2009 (while (not (eobp))
2010 (insert (or prefix1 prefix))
2011 (setq prefix1 nil)
2012 (beginning-of-line 2)))
2013 (buffer-string)
2014 (when (member markup '("src" "example"))
2015 (goto-char (point-min))
2016 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t)
2017 (goto-char (match-beginning 0))
2018 (insert ",")
2019 (end-of-line 1)))
2020 (buffer-string)))
2022 (defun org-get-and-remove-property (listvar prop)
2023 "Check if the value of LISTVAR contains PROP as a property.
2024 If yes, return the value of that property (i.e. the element following
2025 in the list) and remove property and value from the list in LISTVAR."
2026 (let ((list (symbol-value listvar)) m v)
2027 (when (setq m (member prop list))
2028 (setq v (nth 1 m))
2029 (if (equal (car list) prop)
2030 (set listvar (cddr list))
2031 (setcdr (nthcdr (- (length list) (length m) 1) list)
2032 (cddr m))
2033 (set listvar list)))
2036 (defun org-symname-or-string (s)
2037 (if (symbolp s)
2038 (if s (symbol-name s) s)
2041 ;;; Fontification and line numbers for code examples
2043 (defvar org-export-last-code-line-counter-value 0)
2045 (defun org-export-replace-src-segments-and-examples (backend)
2046 "Replace source code segments with special code for export."
2047 (setq org-export-last-code-line-counter-value 0)
2048 (let ((case-fold-search t)
2049 lang code trans opts indent caption)
2050 (goto-char (point-min))
2051 (while (re-search-forward
2052 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2053 nil t)
2054 (if (match-end 1)
2055 ;; src segments
2056 (setq lang (match-string 3)
2057 opts (match-string 4)
2058 code (match-string 5)
2059 indent (length (match-string 2))
2060 caption (get-text-property 0 'org-caption (match-string 0)))
2061 (setq lang nil
2062 opts (match-string 8)
2063 code (match-string 9)
2064 indent (length (match-string 7))
2065 caption (get-text-property 0 'org-caption (match-string 0))))
2067 (setq trans (org-export-format-source-code-or-example
2068 backend lang code opts indent caption))
2069 (replace-match trans t t))))
2071 (defvar htmlp) ;; dynamically scoped
2072 (defvar latexp) ;; dynamically scoped
2073 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
2074 (defvar org-export-latex-listings) ;; defined in org-latex.el
2075 (defvar org-export-latex-listings-langs) ;; defined in org-latex.el
2077 (defun org-export-format-source-code-or-example
2078 (backend lang code &optional opts indent caption)
2079 "Format CODE from language LANG and return it formatted for export.
2080 If LANG is nil, do not add any fontification.
2081 OPTS contains formatting options, like `-n' for triggering numbering lines,
2082 and `+n' for continuing previous numbering.
2083 Code formatting according to language currently only works for HTML.
2084 Numbering lines works for all three major backends (html, latex, and ascii).
2085 INDENT was the original indentation of the block."
2086 (save-match-data
2087 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
2088 (setq opts (or opts "")
2089 num (string-match "[-+]n\\>" opts)
2090 cont (string-match "\\+n\\>" opts)
2091 rpllbl (string-match "-r\\>" opts)
2092 keepp (string-match "-k\\>" opts)
2093 textareap (string-match "-t\\>" opts)
2094 preserve-indentp (or org-src-preserve-indentation
2095 (string-match "-i\\>" opts))
2096 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2097 (string-to-number (match-string 1 opts))
2099 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2100 (string-to-number (match-string 1 opts))
2101 (org-count-lines code))
2102 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2103 (match-string 1 opts)))
2104 (when (and textareap (eq backend 'html))
2105 ;; we cannot use numbering or highlighting.
2106 (setq num nil cont nil lang nil))
2107 (if keepp (setq rpllbl 'keep))
2108 (setq rtn (if preserve-indentp code (org-remove-indentation code)))
2109 (when (string-match "^," rtn)
2110 (setq rtn (with-temp-buffer
2111 (insert rtn)
2112 ;; Free up the protected lines
2113 (goto-char (point-min))
2114 (while (re-search-forward "^," nil t)
2115 (if (or (equal lang "org")
2116 (save-match-data
2117 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2118 (replace-match ""))
2119 (end-of-line 1))
2120 (buffer-string))))
2121 ;; Now backend-specific coding
2122 (setq rtn
2123 (cond
2124 ((eq backend 'docbook)
2125 (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
2126 (concat "\n#+BEGIN_DOCBOOK\n"
2127 (org-add-props (concat "<programlisting><![CDATA["
2129 "]]></programlisting>\n")
2130 '(org-protected t))
2131 "#+END_DOCBOOK\n"))
2132 ((eq backend 'html)
2133 ;; We are exporting to HTML
2134 (when lang
2135 (if (featurep 'xemacs)
2136 (require 'htmlize)
2137 (require 'htmlize nil t))
2138 (when (not (fboundp 'htmlize-region-for-paste))
2139 ;; we do not have htmlize.el, or an old version of it
2140 (setq lang nil)
2141 (message
2142 "htmlize.el 1.34 or later is needed for source code formatting")))
2144 (if lang
2145 (let* ((lang-m (when lang
2146 (or (cdr (assoc lang org-src-lang-modes))
2147 lang)))
2148 (mode (and lang-m (intern
2149 (concat
2150 (if (symbolp lang-m)
2151 (symbol-name lang-m)
2152 lang-m)
2153 "-mode"))))
2154 (org-inhibit-startup t)
2155 (org-startup-folded nil))
2156 (setq rtn
2157 (with-temp-buffer
2158 (insert rtn)
2159 (if (functionp mode)
2160 (funcall mode)
2161 (fundamental-mode))
2162 (font-lock-fontify-buffer)
2163 (org-src-mode)
2164 (set-buffer-modified-p nil)
2165 (org-export-htmlize-region-for-paste
2166 (point-min) (point-max))))
2167 (if (string-match "<pre\\([^>]*\\)>\n*" rtn)
2168 (setq rtn
2169 (concat
2170 (if caption
2171 (concat
2172 "<div class=\"org-src-container\">"
2173 (format
2174 "<label class=\"org-src-name\">%s</label>"
2175 caption))
2177 (replace-match
2178 (format "<pre class=\"src src-%s\">\n" lang)
2179 t t rtn)
2180 (if caption "</div>" "")))))
2181 (if textareap
2182 (setq rtn (concat
2183 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2184 cols rows)
2185 rtn "</textarea>\n</p>\n"))
2186 (with-temp-buffer
2187 (insert rtn)
2188 (goto-char (point-min))
2189 (while (re-search-forward "[<>&]" nil t)
2190 (replace-match (cdr (assq (char-before)
2191 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2192 t t))
2193 (setq rtn (buffer-string)))
2194 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2195 (unless textareap
2196 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2197 cont rpllbl fmt)))
2198 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn)
2199 (setq rtn (replace-match "\\1" t nil rtn)))
2200 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2201 ((eq backend 'latex)
2202 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2203 (concat "#+BEGIN_LaTeX\n"
2204 (org-add-props
2205 (if org-export-latex-listings
2206 (concat
2207 (if lang
2208 (let*
2209 ((lang-sym (intern lang))
2210 (lstlang
2211 (or (cadr
2212 (assq
2213 lang-sym
2214 org-export-latex-listings-langs))
2215 lang)))
2216 (format "\\lstset{language=%s}\n" lstlang))
2217 "\n")
2218 (when caption
2219 (format "\n%s $\\equiv$ \n" caption))
2220 "\\begin{lstlisting}\n"
2221 rtn "\\end{lstlisting}\n")
2222 (concat (car org-export-latex-verbatim-wrap)
2223 rtn (cdr org-export-latex-verbatim-wrap)))
2224 '(org-protected t))
2225 "#+END_LaTeX\n"))
2226 ((eq backend 'ascii)
2227 ;; This is not HTML or LaTeX, so just make it an example.
2228 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2229 (concat caption "\n"
2230 "#+BEGIN_ASCII\n"
2231 (org-add-props
2232 (concat
2233 (mapconcat
2234 (lambda (l) (concat " " l))
2235 (org-split-string rtn "\n")
2236 "\n")
2237 "\n")
2238 '(org-protected t))
2239 "#+END_ASCII\n"))))
2240 (org-add-props rtn nil 'original-indentation indent))))
2242 (defun org-export-number-lines (text backend
2243 &optional skip1 skip2 number cont
2244 replace-labels label-format)
2245 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2246 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2247 (with-temp-buffer
2248 (insert text)
2249 (goto-char (point-max))
2250 (skip-chars-backward " \t\n\r")
2251 (delete-region (point) (point-max))
2252 (beginning-of-line (- 1 skip2))
2253 (let* ((last (org-current-line))
2254 (n org-export-last-code-line-counter-value)
2255 (nmax (+ n (- last skip1)))
2256 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2258 (cond
2259 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2260 fmt))
2261 ((eq backend 'ascii) fmt)
2262 ((eq backend 'latex) fmt)
2263 ((eq backend 'docbook) fmt)
2264 (t "")))
2265 (label-format (or label-format org-coderef-label-format))
2266 (label-pre (if (string-match "%s" label-format)
2267 (substring label-format 0 (match-beginning 0))
2268 label-format))
2269 (label-post (if (string-match "%s" label-format)
2270 (substring label-format (match-end 0))
2271 ""))
2272 (lbl-re
2273 (concat
2274 ".*?\\S-.*?\\([ \t]*\\("
2275 (regexp-quote label-pre)
2276 "\\([-a-zA-Z0-9_ ]+\\)"
2277 (regexp-quote label-post)
2278 "\\)\\)"))
2279 ref)
2281 (org-goto-line (1+ skip1))
2282 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2283 (if number
2284 (insert (format fm (incf n)))
2285 (forward-char 1))
2286 (when (looking-at lbl-re)
2287 (setq ref (match-string 3))
2288 (cond ((numberp replace-labels)
2289 ;; remove labels; use numbers for references when lines
2290 ;; are numbered, use labels otherwise
2291 (delete-region (match-beginning 1) (match-end 1))
2292 (push (cons ref (if (> n 0) n ref)) org-export-code-refs))
2293 ((eq replace-labels 'keep)
2294 ;; don't remove labels; use numbers for references when
2295 ;; lines are numbered, use labels otherwise
2296 (goto-char (match-beginning 2))
2297 (delete-region (match-beginning 2) (match-end 2))
2298 (insert "(" ref ")")
2299 (push (cons ref (if (> n 0) n (concat "(" ref ")")))
2300 org-export-code-refs))
2302 ;; don't remove labels and don't use numbers for
2303 ;; references
2304 (goto-char (match-beginning 2))
2305 (delete-region (match-beginning 2) (match-end 2))
2306 (insert "(" ref ")")
2307 (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
2308 (when (eq backend 'html)
2309 (save-excursion
2310 (beginning-of-line 1)
2311 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2312 ref))
2313 (end-of-line 1)
2314 (insert "</span>")))))
2315 (setq org-export-last-code-line-counter-value n)
2316 (goto-char (point-max))
2317 (newline)
2318 (buffer-string))))
2320 (defun org-search-todo-below (line lines level)
2321 "Search the subtree below LINE for any TODO entries."
2322 (let ((rest (cdr (memq line lines)))
2323 (re org-todo-line-regexp)
2324 line lv todo)
2325 (catch 'exit
2326 (while (setq line (pop rest))
2327 (if (string-match re line)
2328 (progn
2329 (setq lv (- (match-end 1) (match-beginning 1))
2330 todo (and (match-beginning 2)
2331 (not (member (match-string 2 line)
2332 org-done-keywords))))
2333 ; TODO, not DONE
2334 (if (<= lv level) (throw 'exit nil))
2335 (if todo (throw 'exit t))))))))
2337 ;;;###autoload
2338 (defun org-export-visible (type arg)
2339 "Create a copy of the visible part of the current buffer, and export it.
2340 The copy is created in a temporary buffer and removed after use.
2341 TYPE is the final key (as a string) that also select the export command in
2342 the `C-c C-e' export dispatcher.
2343 As a special case, if the you type SPC at the prompt, the temporary
2344 org-mode file will not be removed but presented to you so that you can
2345 continue to use it. The prefix arg ARG is passed through to the exporting
2346 command."
2347 (interactive
2348 (list (progn
2349 (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")
2350 (read-char-exclusive))
2351 current-prefix-arg))
2352 (if (not (member type '(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L)))
2353 (error "Invalid export key"))
2354 (let* ((binding (cdr (assoc type
2356 (?a . org-export-as-ascii)
2357 (?A . org-export-as-ascii-to-buffer)
2358 (?n . org-export-as-latin1)
2359 (?N . org-export-as-latin1-to-buffer)
2360 (?u . org-export-as-utf8)
2361 (?U . org-export-as-utf8-to-buffer)
2362 (?\C-a . org-export-as-ascii)
2363 (?b . org-export-as-html-and-open)
2364 (?\C-b . org-export-as-html-and-open)
2365 (?h . org-export-as-html)
2366 (?H . org-export-as-html-to-buffer)
2367 (?R . org-export-region-as-html)
2368 (?D . org-export-as-docbook)
2370 (?l . org-export-as-latex)
2371 (?p . org-export-as-pdf)
2372 (?d . org-export-as-pdf-and-open)
2373 (?L . org-export-as-latex-to-buffer)
2375 (?x . org-export-as-xoxo)))))
2376 (keepp (equal type ?\ ))
2377 (file buffer-file-name)
2378 (buffer (get-buffer-create "*Org Export Visible*"))
2379 s e)
2380 ;; Need to hack the drawers here.
2381 (save-excursion
2382 (goto-char (point-min))
2383 (while (re-search-forward org-drawer-regexp nil t)
2384 (goto-char (match-beginning 1))
2385 (or (org-invisible-p) (org-flag-drawer nil))))
2386 (with-current-buffer buffer (erase-buffer))
2387 (save-excursion
2388 (setq s (goto-char (point-min)))
2389 (while (not (= (point) (point-max)))
2390 (goto-char (org-find-invisible))
2391 (append-to-buffer buffer s (point))
2392 (setq s (goto-char (org-find-visible))))
2393 (org-cycle-hide-drawers 'all)
2394 (goto-char (point-min))
2395 (unless keepp
2396 ;; Copy all comment lines to the end, to make sure #+ settings are
2397 ;; still available for the second export step. Kind of a hack, but
2398 ;; does do the trick.
2399 (if (looking-at "#[^\r\n]*")
2400 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2401 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2402 (append-to-buffer buffer (1+ (match-beginning 0))
2403 (min (point-max) (1+ (match-end 0))))))
2404 (set-buffer buffer)
2405 (let ((buffer-file-name file)
2406 (org-inhibit-startup t))
2407 (org-mode)
2408 (show-all)
2409 (unless keepp (funcall binding arg))))
2410 (if (not keepp)
2411 (kill-buffer buffer)
2412 (switch-to-buffer-other-window buffer)
2413 (goto-char (point-min)))))
2415 (defun org-find-visible ()
2416 (let ((s (point)))
2417 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2418 (get-char-property s 'invisible)))
2420 (defun org-find-invisible ()
2421 (let ((s (point)))
2422 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2423 (not (get-char-property s 'invisible))))
2426 (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
2428 ;;;###autoload
2429 (defun org-export-as-org (arg &optional hidden ext-plist
2430 to-buffer body-only pub-dir)
2431 "Make a copy with not-exporting stuff removed.
2432 The purpose of this function is to provide a way to export the source
2433 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2434 stuff removed. This command will remove the following:
2436 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2437 - comment blocks and trees starting with the COMMENT keyword
2438 - only trees that are consistent with `org-export-select-tags'
2439 and `org-export-exclude-tags'.
2441 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2442 all the others will be ignored (but are present so that the general
2443 mechanism to call publishing functions will work).
2445 EXT-PLIST is a property list with external parameters overriding
2446 org-mode's default settings, but still inferior to file-local
2447 settings. When PUB-DIR is set, use this as the publishing
2448 directory."
2449 (interactive "P")
2450 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2451 ext-plist
2452 (org-infile-export-plist)))
2453 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2454 (filename (concat (file-name-as-directory
2455 (or pub-dir
2456 (org-export-directory :org opt-plist)))
2457 (file-name-sans-extension
2458 (file-name-nondirectory bfname))
2459 ".org"))
2460 (filename (and filename
2461 (if (equal (file-truename filename)
2462 (file-truename bfname))
2463 (concat (file-name-sans-extension filename)
2464 "-source."
2465 (file-name-extension filename))
2466 filename)))
2467 (backup-inhibited t)
2468 (buffer (find-file-noselect filename))
2469 (region (buffer-string))
2470 str-ret)
2471 (save-excursion
2472 (switch-to-buffer buffer)
2473 (erase-buffer)
2474 (insert region)
2475 (let ((org-inhibit-startup t)) (org-mode))
2476 (org-install-letbind)
2478 ;; Get rid of archived trees
2479 (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
2481 ;; Remove comment environment and comment subtrees
2482 (org-export-remove-comment-blocks-and-subtrees)
2484 ;; Get rid of excluded trees
2485 (org-export-handle-export-tags (plist-get opt-plist :select-tags)
2486 (plist-get opt-plist :exclude-tags))
2488 (when (or (plist-get opt-plist :plain-source)
2489 (not (or (plist-get opt-plist :plain-source)
2490 (plist-get opt-plist :htmlized-source))))
2491 ;; Either nothing special is requested (default call)
2492 ;; or the plain source is explicitly requested
2493 ;; so: save it
2494 (save-buffer))
2495 (when (plist-get opt-plist :htmlized-source)
2496 ;; Make the htmlized version
2497 (require 'htmlize)
2498 (require 'org-html)
2499 (font-lock-fontify-buffer)
2500 (let* ((htmlize-output-type 'css)
2501 (newbuf (htmlize-buffer)))
2502 (with-current-buffer newbuf
2503 (when org-export-htmlized-org-css-url
2504 (goto-char (point-min))
2505 (and (re-search-forward
2506 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2507 nil t)
2508 (replace-match
2509 (format
2510 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2511 org-export-htmlized-org-css-url)
2512 t t)))
2513 (write-file (concat filename ".html")))
2514 (kill-buffer newbuf)))
2515 (set-buffer-modified-p nil)
2516 (if (equal to-buffer 'string)
2517 (progn (setq str-ret (buffer-string))
2518 (kill-buffer (current-buffer))
2519 str-ret)
2520 (kill-buffer (current-buffer))))))
2522 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2523 (defun org-get-current-options ()
2524 "Return a string with current options as keyword options.
2525 Does include HTML export options as well as TODO and CATEGORY stuff."
2526 (require 'org-archive)
2527 (format
2528 "#+TITLE: %s
2529 #+AUTHOR: %s
2530 #+EMAIL: %s
2531 #+DATE: %s
2532 #+DESCRIPTION:
2533 #+KEYWORDS:
2534 #+LANGUAGE: %s
2535 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2536 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2538 #+EXPORT_SELECT_TAGS: %s
2539 #+EXPORT_EXCLUDE_TAGS: %s
2540 #+LINK_UP: %s
2541 #+LINK_HOME: %s
2542 #+XSLT:
2543 #+CATEGORY: %s
2544 #+SEQ_TODO: %s
2545 #+TYP_TODO: %s
2546 #+PRIORITIES: %c %c %c
2547 #+DRAWERS: %s
2548 #+STARTUP: %s %s %s %s %s
2549 #+TAGS: %s
2550 #+FILETAGS: %s
2551 #+ARCHIVE: %s
2552 #+LINK: %s
2554 (buffer-name) (user-full-name) user-mail-address
2555 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2556 org-export-default-language
2557 org-export-headline-levels
2558 org-export-with-section-numbers
2559 org-export-with-toc
2560 org-export-preserve-breaks
2561 org-export-html-expand
2562 org-export-with-fixed-width
2563 org-export-with-tables
2564 org-export-with-sub-superscripts
2565 org-export-with-special-strings
2566 org-export-with-footnotes
2567 org-export-with-emphasize
2568 org-export-with-timestamps
2569 org-export-with-TeX-macros
2570 org-export-with-LaTeX-fragments
2571 org-export-skip-text-before-1st-heading
2572 org-export-with-drawers
2573 org-export-with-todo-keywords
2574 org-export-with-priority
2575 org-export-with-tags
2576 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2577 (mapconcat 'identity org-export-select-tags " ")
2578 (mapconcat 'identity org-export-exclude-tags " ")
2579 org-export-html-link-up
2580 org-export-html-link-home
2581 (or (ignore-errors
2582 (file-name-sans-extension
2583 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2584 "NOFILENAME")
2585 "TODO FEEDBACK VERIFY DONE"
2586 "Me Jason Marie DONE"
2587 org-highest-priority org-lowest-priority org-default-priority
2588 (mapconcat 'identity org-drawers " ")
2589 (cdr (assoc org-startup-folded
2590 '((nil . "showall") (t . "overview") (content . "content"))))
2591 (if org-odd-levels-only "odd" "oddeven")
2592 (if org-hide-leading-stars "hidestars" "showstars")
2593 (if org-startup-align-all-tables "align" "noalign")
2594 (cond ((eq org-log-done t) "logdone")
2595 ((equal org-log-done 'note) "lognotedone")
2596 ((not org-log-done) "nologdone"))
2597 (or (mapconcat (lambda (x)
2598 (cond
2599 ((equal :startgroup (car x)) "{")
2600 ((equal :endgroup (car x)) "}")
2601 ((equal :newline (car x)) "")
2602 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2603 (t (car x))))
2604 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2605 (mapconcat 'identity org-file-tags " ")
2606 org-archive-location
2607 "org file:~/org/%s.org"
2610 ;;;###autoload
2611 (defun org-insert-export-options-template ()
2612 "Insert into the buffer a template with information for exporting."
2613 (interactive)
2614 (if (not (bolp)) (newline))
2615 (let ((s (org-get-current-options)))
2616 (and (string-match "#\\+CATEGORY" s)
2617 (setq s (substring s 0 (match-beginning 0))))
2618 (insert s)))
2620 (defvar org-table-colgroup-info nil)
2622 (defun org-table-clean-before-export (lines &optional maybe-quoted)
2623 "Check if the table has a marking column.
2624 If yes remove the column and the special lines."
2625 (setq org-table-colgroup-info nil)
2626 (if (memq nil
2627 (mapcar
2628 (lambda (x) (or (string-match "^[ \t]*|-" x)
2629 (string-match
2630 (if maybe-quoted
2631 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2632 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2633 x)))
2634 lines))
2635 ;; No special marking column
2636 (progn
2637 (setq org-table-clean-did-remove-column nil)
2638 (delq nil
2639 (mapcar
2640 (lambda (x)
2641 (cond
2642 ((org-table-colgroup-line-p x)
2643 ;; This line contains colgroup info, extract it
2644 ;; and then discard the line
2645 (setq org-table-colgroup-info
2646 (mapcar (lambda (x)
2647 (cond ((member x '("<" "&lt;")) :start)
2648 ((member x '(">" "&gt;")) :end)
2649 ((member x '("<>" "&lt;&gt;")) :startend)
2650 (t nil)))
2651 (org-split-string x "[ \t]*|[ \t]*")))
2652 nil)
2653 ((org-table-cookie-line-p x)
2654 ;; This line contains formatting cookies, discard it
2655 nil)
2656 (t x)))
2657 lines)))
2658 ;; there is a special marking column
2659 (setq org-table-clean-did-remove-column t)
2660 (delq nil
2661 (mapcar
2662 (lambda (x)
2663 (cond
2664 ((org-table-colgroup-line-p x)
2665 ;; This line contains colgroup info, extract it
2666 ;; and then discard the line
2667 (setq org-table-colgroup-info
2668 (mapcar (lambda (x)
2669 (cond ((member x '("<" "&lt;")) :start)
2670 ((member x '(">" "&gt;")) :end)
2671 ((member x '("<>" "&lt;&gt;")) :startend)
2672 (t nil)))
2673 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2674 nil)
2675 ((org-table-cookie-line-p x)
2676 ;; This line contains formatting cookies, discard it
2677 nil)
2678 ((string-match "^[ \t]*| *[!_^/] *|" x)
2679 ;; ignore this line
2680 nil)
2681 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2682 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2683 ;; remove the first column
2684 (replace-match "\\1|" t nil x))))
2685 lines))))
2687 (defun org-export-cleanup-toc-line (s)
2688 "Remove tags and timestamps from lines going into the toc."
2689 (when (memq org-export-with-tags '(not-in-toc nil))
2690 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
2691 (setq s (replace-match "" t t s))))
2692 (when org-export-remove-timestamps-from-toc
2693 (while (string-match org-maybe-keyword-time-regexp s)
2694 (setq s (replace-match "" t t s))))
2695 (while (string-match org-bracket-link-regexp s)
2696 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
2697 t t s)))
2698 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s)
2699 (setq s (replace-match "" t t s)))
2703 (defun org-get-text-property-any (pos prop &optional object)
2704 (or (get-text-property pos prop object)
2705 (and (setq pos (next-single-property-change pos prop object))
2706 (get-text-property pos prop object))))
2708 (defun org-export-get-coderef-format (path desc)
2709 (save-match-data
2710 (if (and desc (string-match
2711 (regexp-quote (concat "(" path ")"))
2712 desc))
2713 (replace-match "%s" t t desc)
2714 (or desc "%s"))))
2716 (defun org-export-push-to-kill-ring (format)
2717 "Push buffer content to kill ring.
2718 The depends on the variable `org-export-copy-to-kill'."
2719 (when org-export-copy-to-kill-ring
2720 (org-kill-new (buffer-string))
2721 (when (fboundp 'x-set-selection)
2722 (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
2723 (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
2724 (message "%s export done, pushed to kill ring and clipboard" format)))
2726 (provide 'org-exp)
2728 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2730 ;;; org-exp.el ends here