Release 6.29a
[org-mode.git] / lisp / org-exp.el
blob04fc3e64e46b48f7110bba6568a82569ba43ce49
1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
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.29a
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-agenda)
31 (require 'org-exp-blocks)
32 (eval-and-compile
33 (require 'cl))
35 (declare-function org-export-latex-preprocess "org-latex" (parameters))
36 (declare-function org-export-ascii-preprocess "org-ascii" (parameters))
37 (declare-function org-export-html-preprocess "org-html" (parameters))
38 (declare-function org-export-docbook-preprocess "org-docbook" (parameters))
39 (declare-function org-agenda-skip "org-agenda" ())
40 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
41 (declare-function org-export-htmlize-region-for-paste "org-html" (beg end))
42 (declare-function htmlize-buffer "htmlize" (&optional buffer))
43 (autoload 'org-export-generic "org-export-generic" "Export using the generic exporter" t)
44 (defgroup org-export nil
45 "Options for exporting org-listings."
46 :tag "Org Export"
47 :group 'org)
49 (defgroup org-export-general nil
50 "General options for exporting Org-mode files."
51 :tag "Org Export General"
52 :group 'org-export)
54 ;; FIXME
55 (defvar org-export-publishing-directory nil)
57 (defcustom org-export-show-temporary-export-buffer t
58 "Non-nil means, show buffer after exporting to temp buffer.
59 When Org exports to a file, the buffer visiting that file is ever
60 shown, but remains buried. However, when exporting to a temporary
61 buffer, that buffer is popped up in a second window. When this variable
62 is nil, the buffer remains buried also in these cases."
63 :group 'org-export-general
64 :type 'boolean)
66 (defcustom org-export-copy-to-kill-ring t
67 "Non-nil means, exported stuff will also be pushed onto the kill ring."
68 :group 'org-export-general
69 :type 'boolean)
71 (defcustom org-export-run-in-background nil
72 "Non-nil means export and publishing commands will run in background.
73 This works by starting up a separate Emacs process visiting the same file
74 and doing the export from there.
75 Not all export commands are affected by this - only the ones which
76 actually write to a file, and that do not depend on the buffer state.
78 If this option is nil, you can still get background export by calling
79 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
81 If this option is t, the double prefix can be used to exceptionally
82 force an export command into the current process."
83 :group 'org-export-general
84 :type 'boolean)
86 (defcustom org-export-select-tags '("export")
87 "Tags that select a tree for export.
88 If any such tag is found in a buffer, all trees that do not carry one
89 of these tags will be deleted before export.
90 Inside trees that are selected like this, you can still deselect a
91 subtree by tagging it with one of the `org-export-exclude-tags'."
92 :group 'org-export-general
93 :type '(repeat (string :tag "Tag")))
95 (defcustom org-export-exclude-tags '("noexport")
96 "Tags that exclude a tree from export.
97 All trees carrying any of these tags will be excluded from export.
98 This is without condition, so even subtrees inside that carry one of the
99 `org-export-select-tags' will be removed."
100 :group 'org-export-general
101 :type '(repeat (string :tag "Tag")))
103 ;; FIXME: rename, this is a general variable
104 (defcustom org-export-html-expand t
105 "Non-nil means, for HTML export, treat @<...> as HTML tag.
106 When nil, these tags will be exported as plain text and therefore
107 not be interpreted by a browser.
109 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
110 :group 'org-export-html
111 :group 'org-export-general
112 :type 'boolean)
114 (defcustom org-export-with-special-strings t
115 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
116 When this option is turned on, these strings will be exported as:
118 Org HTML LaTeX
119 -----+----------+--------
120 \\- &shy; \\-
121 -- &ndash; --
122 --- &mdash; ---
123 ... &hellip; \ldots
125 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
126 :group 'org-export-translation
127 :type 'boolean)
129 (defcustom org-export-html-link-up ""
130 "Where should the \"UP\" link of exported HTML pages lead?"
131 :group 'org-export-html
132 :group 'org-export-general
133 :type '(string :tag "File or URL"))
135 (defcustom org-export-html-link-home ""
136 "Where should the \"HOME\" link of exported HTML pages lead?"
137 :group 'org-export-html
138 :group 'org-export-general
139 :type '(string :tag "File or URL"))
141 (defcustom org-export-language-setup
142 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
143 ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
144 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
145 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
146 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
147 ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
148 ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
149 ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
150 ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
151 ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
152 ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
153 ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
154 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
155 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
156 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
157 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
158 ("pl" "Autor" "Data" "Spis tre&sacute;ci" "Przypis")
159 ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
160 "Terms used in export text, translated to different languages.
161 Use the variable `org-export-default-language' to set the language,
162 or use the +OPTION lines for a per-file setting."
163 :group 'org-export-general
164 :type '(repeat
165 (list
166 (string :tag "HTML language tag")
167 (string :tag "Author")
168 (string :tag "Date")
169 (string :tag "Table of Contents")
170 (string :tag "Footnotes"))))
172 (defcustom org-export-default-language "en"
173 "The default language of HTML export, as a string.
174 This should have an association in `org-export-language-setup'."
175 :group 'org-export-general
176 :type 'string)
178 (defvar org-export-page-description ""
179 "The page description, for the XHTML meta tag.
180 This is best set with the #+DESCRIPTION line in a file, it does not make
181 sense to set this globally.")
183 (defvar org-export-page-keywords ""
184 "The page description, for the XHTML meta tag.
185 This is best set with the #+KEYWORDS line in a file, it does not make
186 sense to set this globally.")
188 (defcustom org-export-skip-text-before-1st-heading nil
189 "Non-nil means, skip all text before the first headline when exporting.
190 When nil, that text is exported as well."
191 :group 'org-export-general
192 :type 'boolean)
194 (defcustom org-export-headline-levels 3
195 "The last level which is still exported as a headline.
196 Inferior levels will produce itemize lists when exported.
197 Note that a numeric prefix argument to an exporter function overrides
198 this setting.
200 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
201 :group 'org-export-general
202 :type 'integer)
204 (defcustom org-export-with-section-numbers t
205 "Non-nil means, add section numbers to headlines when exporting.
207 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
208 :group 'org-export-general
209 :type 'boolean)
211 (defcustom org-export-section-number-format '((("1" ".")) . "")
212 "Format of section numbers for export.
213 The variable has two components.
214 1. A list of lists, each indicating a counter type and a separator.
215 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
216 It causes causes numeric, alphabetic, or roman counters, respectively.
217 The separator is only used if another counter for a subsection is being
218 added.
219 If there are more numbered section levels than entries in this lists,
220 then the last entry will be reused.
221 2. A terminator string that will be added after the entire
222 section number."
223 :group 'org-export-general
224 :type '(cons
225 (repeat
226 (list
227 (string :tag "Counter Type")
228 (string :tag "Separator ")))
229 (string :tag "Terminator")))
231 (defcustom org-export-with-toc t
232 "Non-nil means, create a table of contents in exported files.
233 The TOC contains headlines with levels up to`org-export-headline-levels'.
234 When an integer, include levels up to N in the toc, this may then be
235 different from `org-export-headline-levels', but it will not be allowed
236 to be larger than the number of headline levels.
237 When nil, no table of contents is made.
239 Headlines which contain any TODO items will be marked with \"(*)\" in
240 ASCII export, and with red color in HTML output, if the option
241 `org-export-mark-todo-in-toc' is set.
243 In HTML output, the TOC will be clickable.
245 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
246 or \"toc:3\"."
247 :group 'org-export-general
248 :type '(choice
249 (const :tag "No Table of Contents" nil)
250 (const :tag "Full Table of Contents" t)
251 (integer :tag "TOC to level")))
253 (defcustom org-export-mark-todo-in-toc nil
254 "Non-nil means, mark TOC lines that contain any open TODO items."
255 :group 'org-export-general
256 :type 'boolean)
258 (defcustom org-export-with-todo-keywords t
259 "Non-nil means, include TODO keywords in export.
260 When nil, remove all these keywords from the export."
261 :group 'org-export-general
262 :type 'boolean)
264 (defcustom org-export-with-priority nil
265 "Non-nil means, include priority cookies in export.
266 When nil, remove priority cookies for export."
267 :group 'org-export-general
268 :type 'boolean)
270 (defcustom org-export-preserve-breaks nil
271 "Non-nil means, preserve all line breaks when exporting.
272 Normally, in HTML output paragraphs will be reformatted. In ASCII
273 export, line breaks will always be preserved, regardless of this variable.
275 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
276 :group 'org-export-general
277 :type 'boolean)
279 (defcustom org-export-with-archived-trees 'headline
280 "Whether subtrees with the ARCHIVE tag should be exported.
281 This can have three different values
282 nil Do not export, pretend this tree is not present
283 t Do export the entire tree
284 headline Only export the headline, but skip the tree below it."
285 :group 'org-export-general
286 :group 'org-archive
287 :type '(choice
288 (const :tag "not at all" nil)
289 (const :tag "headline only" 'headline)
290 (const :tag "entirely" t)))
292 (defcustom org-export-author-info t
293 "Non-nil means, insert author name and email into the exported file.
295 This option can also be set with the +OPTIONS line,
296 e.g. \"author-info:nil\"."
297 :group 'org-export-general
298 :type 'boolean)
300 (defcustom org-export-creator-info t
301 "Non-nil means, the postamble should contain a creator sentence.
302 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
303 :group 'org-export-general
304 :type 'boolean)
306 (defcustom org-export-time-stamp-file t
307 "Non-nil means, insert a time stamp into the exported file.
308 The time stamp shows when the file was created.
310 This option can also be set with the +OPTIONS line,
311 e.g. \"timestamp:nil\"."
312 :group 'org-export-general
313 :type 'boolean)
315 (defcustom org-export-with-timestamps t
316 "If nil, do not export time stamps and associated keywords."
317 :group 'org-export-general
318 :type 'boolean)
320 (defcustom org-export-remove-timestamps-from-toc t
321 "If t, remove timestamps from the table of contents entries."
322 :group 'org-export-general
323 :type 'boolean)
325 (defcustom org-export-with-tags 'not-in-toc
326 "If nil, do not export tags, just remove them from headlines.
327 If this is the symbol `not-in-toc', tags will be removed from table of
328 contents entries, but still be shown in the headlines of the document.
330 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
331 :group 'org-export-general
332 :type '(choice
333 (const :tag "Off" nil)
334 (const :tag "Not in TOC" not-in-toc)
335 (const :tag "On" t)))
337 (defcustom org-export-with-drawers nil
338 "Non-nil means, export with drawers like the property drawer.
339 When t, all drawers are exported. This may also be a list of
340 drawer names to export."
341 :group 'org-export-general
342 :type '(choice
343 (const :tag "All drawers" t)
344 (const :tag "None" nil)
345 (repeat :tag "Selected drawers"
346 (string :tag "Drawer name"))))
348 (defvar org-export-preprocess-hook nil
349 "Hook for preprocessing an export buffer.
350 Pretty much the first thing when exporting is running this hook.")
352 (defvar org-export-preprocess-after-include-files-hook nil
353 "Hook for preprocessing an export buffer.
354 This is run after the contents of included files have been inserted.")
356 (defvar org-export-preprocess-after-tree-selection-hook nil
357 "Hook for preprocessing an export buffer.
358 This is run after selection of trees to be exported has happened.
359 This selection includes tags-based selection, as well as removal
360 of commented and archived trees.")
362 (defvar org-export-preprocess-after-blockquote-hook nil
363 "Hook for preprocessing an export buffer.
364 This is run after blockquote/quote/verse/center have been marked
365 with cookies.")
367 (defvar org-export-preprocess-before-backend-specifics-hook nil
368 "Hook run before backend-specific functions are called during preprocessing.")
370 (defvar org-export-preprocess-final-hook nil
371 "Hook for preprocessing an export buffer.
372 This is run as the last thing in the preprocessing buffer, just before
373 returning the buffer string to the backend.")
375 (defgroup org-export-translation nil
376 "Options for translating special ascii sequences for the export backends."
377 :tag "Org Export Translation"
378 :group 'org-export)
380 (defcustom org-export-with-emphasize t
381 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
382 If the export target supports emphasizing text, the word will be
383 typeset in bold, italic, or underlined, respectively. Works only for
384 single words, but you can say: I *really* *mean* *this*.
385 Not all export backends support this.
387 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
388 :group 'org-export-translation
389 :type 'boolean)
391 (defcustom org-export-with-footnotes t
392 "If nil, export [1] as a footnote marker.
393 Lines starting with [1] will be formatted as footnotes.
395 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
396 :group 'org-export-translation
397 :type 'boolean)
399 (defcustom org-export-with-sub-superscripts t
400 "Non-nil means, interpret \"_\" and \"^\" for export.
401 When this option is turned on, you can use TeX-like syntax for sub- and
402 superscripts. Several characters after \"_\" or \"^\" will be
403 considered as a single item - so grouping with {} is normally not
404 needed. For example, the following things will be parsed as single
405 sub- or superscripts.
407 10^24 or 10^tau several digits will be considered 1 item.
408 10^-12 or 10^-tau a leading sign with digits or a word
409 x^2-y^3 will be read as x^2 - y^3, because items are
410 terminated by almost any nonword/nondigit char.
411 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
413 Still, ambiguity is possible - so when in doubt use {} to enclose the
414 sub/superscript. If you set this variable to the symbol `{}',
415 the braces are *required* in order to trigger interpretations as
416 sub/superscript. This can be helpful in documents that need \"_\"
417 frequently in plain text.
419 Not all export backends support this, but HTML does.
421 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
422 :group 'org-export-translation
423 :type '(choice
424 (const :tag "Always interpret" t)
425 (const :tag "Only with braces" {})
426 (const :tag "Never interpret" nil)))
428 (defcustom org-export-with-TeX-macros t
429 "Non-nil means, interpret simple TeX-like macros when exporting.
430 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
431 Not only real TeX macros will work here, but the standard HTML entities
432 for math can be used as macro names as well. For a list of supported
433 names in HTML export, see the constant `org-html-entities'.
434 Not all export backends support this.
436 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
437 :group 'org-export-translation
438 :group 'org-export-latex
439 :type 'boolean)
441 (defcustom org-export-with-LaTeX-fragments nil
442 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
443 When set, the exporter will find LaTeX environments if the \\begin line is
444 the first non-white thing on a line. It will also find the math delimiters
445 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
446 display math.
448 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
450 The default is nil, because this option needs the `dvipng' program which
451 is not available on all systems."
452 :group 'org-export-translation
453 :group 'org-export-latex
454 :type 'boolean)
456 (defcustom org-export-with-fixed-width t
457 "Non-nil means, lines starting with \":\" will be in fixed width font.
458 This can be used to have pre-formatted text, fragments of code etc. For
459 example:
460 : ;; Some Lisp examples
461 : (while (defc cnt)
462 : (ding))
463 will be looking just like this in also HTML. See also the QUOTE keyword.
464 Not all export backends support this.
466 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
467 :group 'org-export-translation
468 :type 'boolean)
470 (defcustom org-match-sexp-depth 3
471 "Number of stacked braces for sub/superscript matching.
472 This has to be set before loading org.el to be effective."
473 :group 'org-export-translation
474 :type 'integer)
476 (defgroup org-export-tables nil
477 "Options for exporting tables in Org-mode."
478 :tag "Org Export Tables"
479 :group 'org-export)
481 (defcustom org-export-with-tables t
482 "If non-nil, lines starting with \"|\" define a table.
483 For example:
485 | Name | Address | Birthday |
486 |-------------+----------+-----------|
487 | Arthur Dent | England | 29.2.2100 |
489 Not all export backends support this.
491 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
492 :group 'org-export-tables
493 :type 'boolean)
495 (defcustom org-export-highlight-first-table-line t
496 "Non-nil means, highlight the first table line.
497 In HTML export, this means use <th> instead of <td>.
498 In tables created with table.el, this applies to the first table line.
499 In Org-mode tables, all lines before the first horizontal separator
500 line will be formatted with <th> tags."
501 :group 'org-export-tables
502 :type 'boolean)
504 (defcustom org-export-table-remove-special-lines t
505 "Remove special lines and marking characters in calculating tables.
506 This removes the special marking character column from tables that are set
507 up for spreadsheet calculations. It also removes the entire lines
508 marked with `!', `_', or `^'. The lines with `$' are kept, because
509 the values of constants may be useful to have."
510 :group 'org-export-tables
511 :type 'boolean)
513 (defcustom org-export-prefer-native-exporter-for-tables nil
514 "Non-nil means, always export tables created with table.el natively.
515 Natively means, use the HTML code generator in table.el.
516 When nil, Org-mode's own HTML generator is used when possible (i.e. if
517 the table does not use row- or column-spanning). This has the
518 advantage, that the automatic HTML conversions for math symbols and
519 sub/superscripts can be applied. Org-mode's HTML generator is also
520 much faster."
521 :group 'org-export-tables
522 :type 'boolean)
525 (defgroup org-export-xml nil
526 "Options specific for XML export of Org-mode files."
527 :tag "Org Export XML"
528 :group 'org-export)
530 ;;;; Exporting
532 ;;; Variables, constants, and parameter plists
534 (defconst org-level-max 20)
536 (defvar org-current-export-file nil) ; dynamically scoped parameter
537 (defvar org-current-export-dir nil) ; dynamically scoped parameter
538 (defvar org-export-opt-plist nil
539 "Contains the current option plist.")
540 (defvar org-last-level nil) ; dynamically scoped variable
541 (defvar org-min-level nil) ; dynamically scoped variable
542 (defvar org-levels-open nil) ; dynamically scoped parameter
544 (defconst org-export-plist-vars
545 '((:link-up nil org-export-html-link-up)
546 (:link-home nil org-export-html-link-home)
547 (:language nil org-export-default-language)
548 (:keywords nil org-export-page-keywords)
549 (:description nil org-export-page-description)
550 (:customtime nil org-display-custom-times)
551 (:headline-levels "H" org-export-headline-levels)
552 (:section-numbers "num" org-export-with-section-numbers)
553 (:section-number-format nil org-export-section-number-format)
554 (:table-of-contents "toc" org-export-with-toc)
555 (:preserve-breaks "\\n" org-export-preserve-breaks)
556 (:archived-trees nil org-export-with-archived-trees)
557 (:emphasize "*" org-export-with-emphasize)
558 (:sub-superscript "^" org-export-with-sub-superscripts)
559 (:special-strings "-" org-export-with-special-strings)
560 (:footnotes "f" org-export-with-footnotes)
561 (:drawers "d" org-export-with-drawers)
562 (:tags "tags" org-export-with-tags)
563 (:todo-keywords "todo" org-export-with-todo-keywords)
564 (:priority "pri" org-export-with-priority)
565 (:TeX-macros "TeX" org-export-with-TeX-macros)
566 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
567 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
568 (:fixed-width ":" org-export-with-fixed-width)
569 (:timestamps "<" org-export-with-timestamps)
570 (:author-info "author" org-export-author-info)
571 (:creator-info "creator" org-export-creator-info)
572 (:time-stamp-file "timestamp" org-export-time-stamp-file)
573 (:tables "|" org-export-with-tables)
574 (:table-auto-headline nil org-export-highlight-first-table-line)
575 (:style-include-default nil org-export-html-style-include-default)
576 (:style-include-scripts nil org-export-html-style-include-scripts)
577 (:style nil org-export-html-style)
578 (:style-extra nil org-export-html-style-extra)
579 (:agenda-style nil org-agenda-export-html-style)
580 (:convert-org-links nil org-export-html-link-org-files-as-html)
581 (:inline-images nil org-export-html-inline-images)
582 (:html-extension nil org-export-html-extension)
583 (:xml-declaration nil org-export-html-xml-declaration)
584 (:html-table-tag nil org-export-html-table-tag)
585 (:expand-quoted-html "@" org-export-html-expand)
586 (:timestamp nil org-export-html-with-timestamp)
587 (:publishing-directory nil org-export-publishing-directory)
588 (:preamble nil org-export-html-preamble)
589 (:postamble nil org-export-html-postamble)
590 (:auto-preamble nil org-export-html-auto-preamble)
591 (:auto-postamble nil org-export-html-auto-postamble)
592 (:author nil user-full-name)
593 (:email nil user-mail-address)
594 (:select-tags nil org-export-select-tags)
595 (:exclude-tags nil org-export-exclude-tags)
597 (:latex-image-options nil org-export-latex-image-default-option))
598 "List of properties that represent export/publishing variables.
599 Each element is a list of 3 items:
600 1. The property that is used internally, and also for org-publish-project-alist
601 2. The string that can be used in the OPTION lines to set this option,
602 or nil if this option cannot be changed in this way
603 3. The customization variable that sets the default for this option."
606 (defun org-default-export-plist ()
607 "Return the property list with default settings for the export variables."
608 (let ((l org-export-plist-vars) rtn e s v)
609 (while (setq e (pop l))
610 (setq s (nth 2 e)
611 v (if (boundp s) (symbol-value s) nil)
612 rtn (cons (car e) (cons v rtn))))
613 rtn))
615 (defvar org-export-inbuffer-options-extra nil
616 "List of additional in-buffer options that should be detected.
617 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
618 etc. Extensions can add to this list to get their options detected, and they
619 can then add a function to `org-export-options-filters' to process these
620 options.
621 Each element in this list must be a list, with the in-buffer keyword as car,
622 and a property (a symbol) as the next element. All occurrences of the
623 keyword will be found, the values concatenated with a space character
624 in between, and the result stored in the export options property list.")
626 (defvar org-export-options-filters nil
627 "Functions to be called to finalize the export/publishing options.
628 All these options are stored in a property list, and each of the functions
629 in this hook gets a chance to modify this property list. Each function
630 must accept the property list as an argument, and must return the (possibly
631 modified) list.")
633 ;; FIXME: should we fold case here?
634 (defun org-infile-export-plist ()
635 "Return the property list with file-local settings for export."
636 (save-excursion
637 (save-restriction
638 (widen)
639 (goto-char (point-min))
640 (let ((re (org-make-options-regexp
641 (append
642 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
643 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
644 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
645 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND")
646 (mapcar 'car org-export-inbuffer-options-extra))))
647 p key val text options a pr style
648 latex-header macros letbind
649 ext-setup-or-nil setup-contents (start 0))
650 (while (or (and ext-setup-or-nil
651 (string-match re ext-setup-or-nil start)
652 (setq start (match-end 0)))
653 (and (setq ext-setup-or-nil nil start 0)
654 (re-search-forward re nil t)))
655 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
656 val (org-match-string-no-properties 2 ext-setup-or-nil))
657 (cond
658 ((setq a (assoc key org-export-inbuffer-options-extra))
659 (setq pr (nth 1 a))
660 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
661 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
662 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
663 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
664 ((string-equal key "DATE") (setq p (plist-put p :date val)))
665 ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
666 ((string-equal key "DESCRIPTION")
667 (setq p (plist-put p :description val)))
668 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
669 ((string-equal key "STYLE")
670 (setq style (concat style "\n" val)))
671 ((string-equal key "LATEX_HEADER")
672 (setq latex-header (concat latex-header "\n" val)))
673 ((string-equal key "TEXT")
674 (setq text (if text (concat text "\n" val) val)))
675 ((string-equal key "OPTIONS")
676 (setq options (concat val " " options)))
677 ((string-equal key "BIND")
678 (push (read (concat "(" val ")")) letbind))
679 ((string-equal key "LINK_UP")
680 (setq p (plist-put p :link-up val)))
681 ((string-equal key "LINK_HOME")
682 (setq p (plist-put p :link-home val)))
683 ((string-equal key "EXPORT_SELECT_TAGS")
684 (setq p (plist-put p :select-tags (org-split-string val))))
685 ((string-equal key "EXPORT_EXCLUDE_TAGS")
686 (setq p (plist-put p :exclude-tags (org-split-string val))))
687 ((string-equal key "MACRO")
688 (push val macros))
689 ((equal key "SETUPFILE")
690 (setq setup-contents (org-file-contents
691 (expand-file-name
692 (org-remove-double-quotes
693 (org-trim val)))
694 'noerror))
695 (if (not ext-setup-or-nil)
696 (setq ext-setup-or-nil setup-contents start 0)
697 (setq ext-setup-or-nil
698 (concat (substring ext-setup-or-nil 0 start)
699 "\n" setup-contents "\n"
700 (substring ext-setup-or-nil start)))))))
701 (setq p (plist-put p :text text))
702 (setq p (plist-put p :let-bind letbind))
703 (when style (setq p (plist-put p :style-extra style)))
704 (when latex-header
705 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
706 (when options
707 (setq p (org-export-add-options-to-plist p options)))
708 ;; Add macro definitions
709 (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
710 (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
711 (setq p (plist-put
712 p :macro-modification-time
713 (and (buffer-file-name)
714 (file-exists-p (buffer-file-name))
715 (concat
716 "(eval (format-time-string \"$1\" '"
717 (prin1-to-string (nth 5 (file-attributes
718 (buffer-file-name))))
719 "))"))))
720 (setq p (plist-put p :macro-input-file (and (buffer-file-name)
721 (file-name-nondirectory
722 (buffer-file-name)))))
723 (while (setq val (pop macros))
724 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val)
725 (setq p (plist-put
726 p (intern
727 (concat ":macro-" (downcase (match-string 1 val))))
728 (match-string 2 val)))))
729 p))))
731 (defun org-install-letbind ()
732 "Install the values from #+BIND lines as local variables."
733 (let ((letbind (plist-get org-export-opt-plist :let-bind)))
734 (while letbind
735 (org-set-local (caar letbind) (nth 1 (pop letbind))))))
737 (defun org-export-add-options-to-plist (p options)
738 "Parse an OPTIONS line and set values in the property list P."
739 (let (o)
740 (when options
741 (let ((op org-export-plist-vars))
742 (while (setq o (pop op))
743 (if (and (nth 1 o)
744 (string-match (concat (regexp-quote (nth 1 o))
745 ":\\([^ \t\n\r;,.]*\\)")
746 options))
747 (setq p (plist-put p (car o)
748 (car (read-from-string
749 (match-string 1 options))))))))))
752 (defun org-export-add-subtree-options (p pos)
753 "Add options in subtree at position POS to property list P."
754 (save-excursion
755 (goto-char pos)
756 (when (org-at-heading-p)
757 (let (a)
758 ;; This is actually read in `org-export-get-title-from-subtree'
759 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
760 ;; (setq p (plist-put p :title a)))
761 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
762 (setq p (plist-put p :text a)))
763 (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
764 (setq p (plist-put p :author a)))
765 (when (setq a (org-entry-get pos "EXPORT_DATE"))
766 (setq p (plist-put p :date a)))
767 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
768 (setq p (org-export-add-options-to-plist p a)))))
771 (defun org-export-directory (type plist)
772 (let* ((val (plist-get plist :publishing-directory))
773 (dir (if (listp val)
774 (or (cdr (assoc type val)) ".")
775 val)))
776 dir))
778 (defun org-export-process-option-filters (plist)
779 (let ((functions org-export-options-filters) f)
780 (while (setq f (pop functions))
781 (setq plist (funcall f plist))))
782 plist)
784 ;;;###autoload
785 (defun org-export (&optional arg)
786 "Export dispatcher for Org-mode.
787 When `org-export-run-in-background' is non-nil, try to run the command
788 in the background. This will be done only for commands that write
789 to a file. For details see the docstring of `org-export-run-in-background'.
791 The prefix argument ARG will be passed to the exporter. However, if
792 ARG is a double universal prefix `C-u C-u', that means to inverse the
793 value of `org-export-run-in-background'."
794 (interactive "P")
795 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
796 (help "[t] insert the export option template
797 \[v] limit export to visible part of outline tree
799 \[a] export as ASCII [A] to temporary buffer
801 \[h] export as HTML [H] to temporary buffer [R] export region
802 \[b] export as HTML and open in browser
804 \[l] export as LaTeX [L] to temporary buffer
805 \[p] export as LaTeX and process to PDF
806 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
808 \[D] export as DocBook
809 \[V] export as DocBook, process to PDF, and open the resulting PDF document
811 \[x] export as XOXO
812 \[g] export using Wes Hardaker's generic exporter
814 \[i] export current file as iCalendar file
815 \[I] export all agenda files as iCalendar files
816 \[c] export agenda files into combined iCalendar file
818 \[F] publish current file [P] publish current project
819 \[X] publish a project... [E] publish every projects")
820 (cmds
821 '((?t org-insert-export-options-template nil)
822 (?v org-export-visible nil)
823 (?a org-export-as-ascii t)
824 (?A org-export-as-ascii-to-buffer t)
825 (?h org-export-as-html t)
826 (?b org-export-as-html-and-open t)
827 (?H org-export-as-html-to-buffer nil)
828 (?R org-export-region-as-html nil)
829 (?x org-export-as-xoxo t)
830 (?g org-export-generic t)
831 (?D org-export-as-docbook t)
832 (?V org-export-as-docbook-pdf-and-open t)
833 (?l org-export-as-latex t)
834 (?p org-export-as-pdf t)
835 (?d org-export-as-pdf-and-open t)
836 (?L org-export-as-latex-to-buffer nil)
837 (?i org-export-icalendar-this-file t)
838 (?I org-export-icalendar-all-agenda-files t)
839 (?c org-export-icalendar-combine-agenda-files t)
840 (?F org-publish-current-file t)
841 (?P org-publish-current-project t)
842 (?X org-publish t)
843 (?E org-publish-all t)))
844 r1 r2 ass)
845 (save-excursion
846 (save-window-excursion
847 (delete-other-windows)
848 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
849 (princ help))
850 (org-fit-window-to-buffer (get-buffer-window
851 "*Org Export/Publishing Help*"))
852 (message "Select command: ")
853 (setq r1 (read-char-exclusive))))
854 (setq r2 (if (< r1 27) (+ r1 96) r1))
855 (unless (setq ass (assq r2 cmds))
856 (error "No command associated with key %c" r1))
857 (if (and bg (nth 2 ass)
858 (not (buffer-base-buffer))
859 (not (org-region-active-p)))
860 ;; execute in background
861 (let ((p (start-process
862 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
863 "*Org Processes*"
864 (expand-file-name invocation-name invocation-directory)
865 "-batch"
866 "-l" user-init-file
867 "--eval" "(require 'org-exp)"
868 "--eval" "(setq org-wait .2)"
869 (buffer-file-name)
870 "-f" (symbol-name (nth 1 ass)))))
871 (set-process-sentinel p 'org-export-process-sentinel)
872 (message "Background process \"%s\": started" p))
873 ;; background processing not requested, or not possible
874 (call-interactively (nth 1 ass)))))
876 (defun org-export-process-sentinel (process status)
877 (if (string-match "\n+\\'" status)
878 (setq status (substring status 0 -1)))
879 (message "Background process \"%s\": %s" process status))
881 (defconst org-html-entities
882 '(("nbsp")
883 ("iexcl")
884 ("cent")
885 ("pound")
886 ("curren")
887 ("yen")
888 ("brvbar")
889 ("vert" . "&#124;")
890 ("sect")
891 ("uml")
892 ("copy")
893 ("ordf")
894 ("laquo")
895 ("not")
896 ("shy")
897 ("reg")
898 ("macr")
899 ("deg")
900 ("pm" . "&plusmn;")
901 ("plusmn")
902 ("sup2")
903 ("sup3")
904 ("acute")
905 ("micro")
906 ("para")
907 ("middot")
908 ("odot"."o")
909 ("star"."*")
910 ("cedil")
911 ("sup1")
912 ("ordm")
913 ("raquo")
914 ("frac14")
915 ("frac12")
916 ("frac34")
917 ("iquest")
918 ("Agrave")
919 ("Aacute")
920 ("Acirc")
921 ("Atilde")
922 ("Auml")
923 ("Aring") ("AA"."&Aring;")
924 ("AElig")
925 ("Ccedil")
926 ("Egrave")
927 ("Eacute")
928 ("Ecirc")
929 ("Euml")
930 ("Igrave")
931 ("Iacute")
932 ("Icirc")
933 ("Iuml")
934 ("ETH")
935 ("Ntilde")
936 ("Ograve")
937 ("Oacute")
938 ("Ocirc")
939 ("Otilde")
940 ("Ouml")
941 ("times")
942 ("Oslash")
943 ("Ugrave")
944 ("Uacute")
945 ("Ucirc")
946 ("Uuml")
947 ("Yacute")
948 ("THORN")
949 ("szlig")
950 ("agrave")
951 ("aacute")
952 ("acirc")
953 ("atilde")
954 ("auml")
955 ("aring")
956 ("aelig")
957 ("ccedil")
958 ("egrave")
959 ("eacute")
960 ("ecirc")
961 ("euml")
962 ("igrave")
963 ("iacute")
964 ("icirc")
965 ("iuml")
966 ("eth")
967 ("ntilde")
968 ("ograve")
969 ("oacute")
970 ("ocirc")
971 ("otilde")
972 ("ouml")
973 ("divide")
974 ("oslash")
975 ("ugrave")
976 ("uacute")
977 ("ucirc")
978 ("uuml")
979 ("yacute")
980 ("thorn")
981 ("yuml")
982 ("fnof")
983 ("Alpha")
984 ("Beta")
985 ("Gamma")
986 ("Delta")
987 ("Epsilon")
988 ("Zeta")
989 ("Eta")
990 ("Theta")
991 ("Iota")
992 ("Kappa")
993 ("Lambda")
994 ("Mu")
995 ("Nu")
996 ("Xi")
997 ("Omicron")
998 ("Pi")
999 ("Rho")
1000 ("Sigma")
1001 ("Tau")
1002 ("Upsilon")
1003 ("Phi")
1004 ("Chi")
1005 ("Psi")
1006 ("Omega")
1007 ("alpha")
1008 ("beta")
1009 ("gamma")
1010 ("delta")
1011 ("epsilon")
1012 ("varepsilon"."&epsilon;")
1013 ("zeta")
1014 ("eta")
1015 ("theta")
1016 ("iota")
1017 ("kappa")
1018 ("lambda")
1019 ("mu")
1020 ("nu")
1021 ("xi")
1022 ("omicron")
1023 ("pi")
1024 ("rho")
1025 ("sigmaf") ("varsigma"."&sigmaf;")
1026 ("sigma")
1027 ("tau")
1028 ("upsilon")
1029 ("phi")
1030 ("chi")
1031 ("psi")
1032 ("omega")
1033 ("thetasym") ("vartheta"."&thetasym;")
1034 ("upsih")
1035 ("piv")
1036 ("bull") ("bullet"."&bull;")
1037 ("hellip") ("dots"."&hellip;")
1038 ("prime")
1039 ("Prime")
1040 ("oline")
1041 ("frasl")
1042 ("weierp")
1043 ("image")
1044 ("real")
1045 ("trade")
1046 ("alefsym")
1047 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1048 ("uarr") ("uparrow"."&uarr;")
1049 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1050 ("darr")("downarrow"."&darr;")
1051 ("harr") ("leftrightarrow"."&harr;")
1052 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1053 ("lArr") ("Leftarrow"."&lArr;")
1054 ("uArr") ("Uparrow"."&uArr;")
1055 ("rArr") ("Rightarrow"."&rArr;")
1056 ("dArr") ("Downarrow"."&dArr;")
1057 ("hArr") ("Leftrightarrow"."&hArr;")
1058 ("forall")
1059 ("part") ("partial"."&part;")
1060 ("exist") ("exists"."&exist;")
1061 ("empty") ("emptyset"."&empty;")
1062 ("nabla")
1063 ("isin") ("in"."&isin;")
1064 ("notin")
1065 ("ni")
1066 ("prod")
1067 ("sum")
1068 ("minus")
1069 ("lowast") ("ast"."&lowast;")
1070 ("radic")
1071 ("prop") ("proptp"."&prop;")
1072 ("infin") ("infty"."&infin;")
1073 ("ang") ("angle"."&ang;")
1074 ("and") ("wedge"."&and;")
1075 ("or") ("vee"."&or;")
1076 ("cap")
1077 ("cup")
1078 ("int")
1079 ("there4")
1080 ("sim")
1081 ("cong") ("simeq"."&cong;")
1082 ("asymp")("approx"."&asymp;")
1083 ("ne") ("neq"."&ne;")
1084 ("equiv")
1085 ("le")
1086 ("ge")
1087 ("sub") ("subset"."&sub;")
1088 ("sup") ("supset"."&sup;")
1089 ("nsub")
1090 ("sube")
1091 ("supe")
1092 ("oplus")
1093 ("otimes")
1094 ("perp")
1095 ("sdot") ("cdot"."&sdot;")
1096 ("lceil")
1097 ("rceil")
1098 ("lfloor")
1099 ("rfloor")
1100 ("lang")
1101 ("rang")
1102 ("loz") ("Diamond"."&loz;")
1103 ("spades") ("spadesuit"."&spades;")
1104 ("clubs") ("clubsuit"."&clubs;")
1105 ("hearts") ("diamondsuit"."&hearts;")
1106 ("diams") ("diamondsuit"."&diams;")
1107 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1108 ("quot")
1109 ("amp")
1110 ("lt")
1111 ("gt")
1112 ("OElig")
1113 ("oelig")
1114 ("Scaron")
1115 ("scaron")
1116 ("Yuml")
1117 ("circ")
1118 ("tilde")
1119 ("ensp")
1120 ("emsp")
1121 ("thinsp")
1122 ("zwnj")
1123 ("zwj")
1124 ("lrm")
1125 ("rlm")
1126 ("ndash")
1127 ("mdash")
1128 ("lsquo")
1129 ("rsquo")
1130 ("sbquo")
1131 ("ldquo")
1132 ("rdquo")
1133 ("bdquo")
1134 ("dagger")
1135 ("Dagger")
1136 ("permil")
1137 ("lsaquo")
1138 ("rsaquo")
1139 ("euro")
1141 ("arccos"."arccos")
1142 ("arcsin"."arcsin")
1143 ("arctan"."arctan")
1144 ("arg"."arg")
1145 ("cos"."cos")
1146 ("cosh"."cosh")
1147 ("cot"."cot")
1148 ("coth"."coth")
1149 ("csc"."csc")
1150 ("deg"."deg")
1151 ("det"."det")
1152 ("dim"."dim")
1153 ("exp"."exp")
1154 ("gcd"."gcd")
1155 ("hom"."hom")
1156 ("inf"."inf")
1157 ("ker"."ker")
1158 ("lg"."lg")
1159 ("lim"."lim")
1160 ("liminf"."liminf")
1161 ("limsup"."limsup")
1162 ("ln"."ln")
1163 ("log"."log")
1164 ("max"."max")
1165 ("min"."min")
1166 ("Pr"."Pr")
1167 ("sec"."sec")
1168 ("sin"."sin")
1169 ("sinh"."sinh")
1170 ("sup"."sup")
1171 ("tan"."tan")
1172 ("tanh"."tanh")
1174 "Entities for TeX->HTML translation.
1175 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1176 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1177 In that case, \"\\ent\" will be translated to \"&other;\".
1178 The list contains HTML entities for Latin-1, Greek and other symbols.
1179 It is supplemented by a number of commonly used TeX macros with appropriate
1180 translations. There is currently no way for users to extend this.")
1182 ;;; General functions for all backends
1184 (defvar org-export-target-aliases nil
1185 "Alist of targets with invisible aliases.")
1186 (defvar org-export-preferred-target-alist nil
1187 "Alist of section id's with preferred aliases.")
1188 (defvar org-export-code-refs nil
1189 "Alist of code references and line numbers")
1191 (defun org-export-preprocess-string (string &rest parameters)
1192 "Cleanup STRING so that that the true exported has a more consistent source.
1193 This function takes STRING, which should be a buffer-string of an org-file
1194 to export. It then creates a temporary buffer where it does its job.
1195 The result is then again returned as a string, and the exporter works
1196 on this string to produce the exported version."
1197 (interactive)
1198 (let* ((htmlp (plist-get parameters :for-html))
1199 (asciip (plist-get parameters :for-ascii))
1200 (latexp (plist-get parameters :for-LaTeX))
1201 (docbookp (plist-get parameters :for-docbook))
1202 (backend (cond (htmlp 'html)
1203 (latexp 'latex)
1204 (asciip 'ascii)
1205 (docbookp 'docbook)))
1206 (archived-trees (plist-get parameters :archived-trees))
1207 (inhibit-read-only t)
1208 (drawers org-drawers)
1209 (outline-regexp "\\*+ ")
1210 target-alist rtn)
1212 (setq org-export-target-aliases nil)
1213 (setq org-export-preferred-target-alist nil)
1214 (setq org-export-code-refs nil)
1216 (with-current-buffer (get-buffer-create " org-mode-tmp")
1217 (erase-buffer)
1218 (insert string)
1219 (setq case-fold-search t)
1221 ;; Remove license-to-kill stuff
1222 ;; The caller marks some stuff for killing, stuff that has been
1223 ;; used to create the page title, for example.
1224 (org-export-kill-licensed-text)
1226 (let ((org-inhibit-startup t)) (org-mode))
1227 (setq case-fold-search t)
1228 (org-install-letbind)
1230 ;; Call the hook
1231 (run-hooks 'org-export-preprocess-hook)
1233 ;; Process the macros
1234 (org-export-preprocess-apply-macros)
1235 (run-hooks 'org-export-preprocess-after-macros-hook)
1237 (untabify (point-min) (point-max))
1239 ;; Handle include files, and call a hook
1240 (org-export-handle-include-files)
1241 (run-hooks 'org-export-preprocess-after-include-files-hook)
1243 ;; Get rid of archived trees
1244 (org-export-remove-archived-trees archived-trees)
1246 ;; Remove comment environment and comment subtrees
1247 (org-export-remove-comment-blocks-and-subtrees)
1249 ;; Get rid of excluded trees, and call a hook
1250 (org-export-handle-export-tags (plist-get parameters :select-tags)
1251 (plist-get parameters :exclude-tags))
1252 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1254 ;; Handle source code snippets
1255 (org-export-replace-src-segments-and-examples backend)
1257 ;; Protect short examples marked by a leading colon
1258 (org-export-protect-colon-examples)
1260 ;; Normalize footnotes
1261 (when (plist-get parameters :footnotes)
1262 (org-footnote-normalize nil t))
1264 ;; Find all headings and compute the targets for them
1265 (setq target-alist (org-export-define-heading-targets target-alist))
1267 ;; Get rid of drawers
1268 (org-export-remove-or-extract-drawers drawers
1269 (plist-get parameters :drawers))
1271 ;; Get the correct stuff before the first headline
1272 (when (plist-get parameters :skip-before-1st-heading)
1273 (goto-char (point-min))
1274 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1275 (delete-region (point-min) (match-beginning 0))
1276 (goto-char (point-min))
1277 (insert "\n")))
1278 (when (plist-get parameters :add-text)
1279 (goto-char (point-min))
1280 (insert (plist-get parameters :add-text) "\n"))
1282 ;; Remove todo-keywords before exporting, if the user has requested so
1283 (org-export-remove-headline-metadata parameters)
1285 ;; Find targets in comments and move them out of comments,
1286 ;; but mark them as targets that should be invisible
1287 (setq target-alist (org-export-handle-invisible-targets target-alist))
1289 ;; Select and protect backend specific stuff, throw away stuff
1290 ;; that is specific for other backends
1291 (org-export-select-backend-specific-text backend)
1293 ;; Protect quoted subtrees
1294 (org-export-protect-quoted-subtrees)
1296 ;; Remove clock lines
1297 (org-export-remove-clock-lines)
1299 ;; Protect verbatim elements
1300 (org-export-protect-verbatim)
1302 ;; Blockquotes, verse, and center
1303 (org-export-mark-blockquote-verse-center)
1304 (run-hooks 'org-export-preprocess-after-blockquote-hook)
1306 ;; Remove timestamps, if the user has requested so
1307 (unless (plist-get parameters :timestamps)
1308 (org-export-remove-timestamps))
1310 ;; Attach captions to the correct object
1311 (setq target-alist (org-export-attach-captions-and-attributes
1312 backend target-alist))
1314 ;; Find matches for radio targets and turn them into internal links
1315 (org-export-mark-radio-links)
1317 ;; Find all links that contain a newline and put them into a single line
1318 (org-export-concatenate-multiline-links)
1320 ;; Normalize links: Convert angle and plain links into bracket links
1321 ;; and expand link abbreviations
1322 (org-export-normalize-links)
1324 ;; Find all internal links. If they have a fuzzy match (i.e. not
1325 ;; a *dedicated* target match, let the link point to the
1326 ;; corresponding section.
1327 (org-export-target-internal-links target-alist)
1329 ;; Find multiline emphasis and put them into single line
1330 (when (plist-get parameters :emph-multiline)
1331 (org-export-concatenate-multiline-emphasis))
1333 ;; Remove special table lines
1334 (when org-export-table-remove-special-lines
1335 (org-export-remove-special-table-lines))
1337 ;; Another hook
1338 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1340 ;; LaTeX-specific preprocessing
1341 (when latexp
1342 (require 'org-latex nil)
1343 (org-export-latex-preprocess parameters))
1345 ;; ASCII-specific preprocessing
1346 (when asciip
1347 (org-export-ascii-preprocess parameters))
1349 ;; HTML-specific preprocessing
1350 (when htmlp
1351 (org-export-html-preprocess parameters))
1353 ;; DocBook-specific preprocessing
1354 (when docbookp
1355 (require 'org-docbook nil)
1356 (org-export-docbook-preprocess parameters))
1358 ;; Remove or replace comments
1359 (org-export-handle-comments (plist-get parameters :comments))
1361 ;; Run the final hook
1362 (run-hooks 'org-export-preprocess-final-hook)
1364 (setq rtn (buffer-string)))
1365 (kill-buffer " org-mode-tmp")
1366 rtn))
1368 (defun org-export-kill-licensed-text ()
1369 "Remove all text that is marked with a :org-license-to-kill property."
1370 (let (p)
1371 (while (setq p (text-property-any (point-min) (point-max)
1372 :org-license-to-kill t))
1373 (delete-region
1374 p (or (next-single-property-change p :org-license-to-kill)
1375 (point-max))))))
1377 (defun org-export-define-heading-targets (target-alist)
1378 "Find all headings and define the targets for them.
1379 The new targets are added to TARGET-ALIST, which is also returned."
1380 (goto-char (point-min))
1381 (org-init-section-numbers)
1382 (let ((re (concat "^" org-outline-regexp
1383 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1384 level target last-section-target a id)
1385 (while (re-search-forward re nil t)
1386 (if (match-end 2)
1387 (progn
1388 (setq id (org-match-string-no-properties 2))
1389 (push (cons id target) target-alist)
1390 (setq a (or (assoc last-section-target org-export-target-aliases)
1391 (progn
1392 (push (list last-section-target)
1393 org-export-target-aliases)
1394 (car org-export-target-aliases))))
1395 (push (caar target-alist) (cdr a))
1396 (when (equal (match-string 1) "CUSTOM_ID")
1397 (if (not (assoc last-section-target
1398 org-export-preferred-target-alist))
1399 (push (cons last-section-target id)
1400 org-export-preferred-target-alist))))
1401 (setq level (org-reduced-level
1402 (save-excursion (goto-char (point-at-bol))
1403 (org-outline-level))))
1404 (setq target (org-solidify-link-text
1405 (format "sec-%s" (org-section-number level))))
1406 (setq last-section-target target)
1407 (push (cons target target) target-alist)
1408 (add-text-properties
1409 (point-at-bol) (point-at-eol)
1410 (list 'target target)))))
1411 target-alist)
1413 (defun org-export-handle-invisible-targets (target-alist)
1414 "Find targets in comments and move them out of comments.
1415 Mark them as invisible targets."
1416 (let (target tmp a)
1417 (goto-char (point-min))
1418 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1419 ;; Check if the line before or after is a headline with a target
1420 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1421 (get-text-property (point-at-bol 2) 'target)))
1422 (progn
1423 ;; use the existing target in a neighboring line
1424 (setq tmp (match-string 2))
1425 (replace-match "")
1426 (and (looking-at "\n") (delete-char 1))
1427 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1428 target-alist)
1429 (setq a (or (assoc target org-export-target-aliases)
1430 (progn
1431 (push (list target) org-export-target-aliases)
1432 (car org-export-target-aliases))))
1433 (push tmp (cdr a)))
1434 ;; Make an invisible target
1435 (replace-match "\\1(INVISIBLE)"))))
1436 target-alist)
1438 (defun org-export-target-internal-links (target-alist)
1439 "Find all internal links and assign targets to them.
1440 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1441 let the link point to the corresponding section.
1442 This function also handles the id links, if they have a match in
1443 the current file."
1444 (goto-char (point-min))
1445 (while (re-search-forward org-bracket-link-regexp nil t)
1446 (org-if-unprotected
1447 (let* ((md (match-data))
1448 (desc (match-end 2))
1449 (link (org-link-unescape (match-string 1)))
1450 (slink (org-solidify-link-text link))
1451 found props pos cref
1452 (target
1453 (cond
1454 ((= (string-to-char link) ?#)
1455 ;; user wants exactly this link
1456 link)
1457 ((cdr (assoc slink target-alist))
1458 (or (cdr (assoc (assoc slink target-alist)
1459 org-export-preferred-target-alist))
1460 (cdr (assoc slink target-alist))))
1461 ((and (string-match "^id:" link)
1462 (cdr (assoc (substring link 3) target-alist))))
1463 ((string-match "^(\\(.*\\))$" link)
1464 (setq cref (match-string 1 link))
1465 (concat "coderef:" cref))
1466 ((string-match org-link-types-re link) nil)
1467 ((or (file-name-absolute-p link)
1468 (string-match "^\\." link))
1469 nil)
1471 (save-excursion
1472 (setq found (condition-case nil (org-link-search link)
1473 (error nil)))
1474 (when (and found
1475 (or (org-on-heading-p)
1476 (not (eq found 'dedicated))))
1477 (or (get-text-property (point) 'target)
1478 (get-text-property
1479 (max (point-min)
1480 (1- (or (previous-single-property-change
1481 (point) 'target) 0)))
1482 'target))))))))
1483 (when target
1484 (set-match-data md)
1485 (goto-char (match-beginning 1))
1486 (setq props (text-properties-at (point)))
1487 (delete-region (match-beginning 1) (match-end 1))
1488 (setq pos (point))
1489 (insert target)
1490 (unless desc (insert "][" link))
1491 (add-text-properties pos (point) props))))))
1493 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1494 "Remove drawers, or extract the content.
1495 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1496 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1497 whose content to keep."
1498 (unless (eq t exp-drawers)
1499 (goto-char (point-min))
1500 (let ((re (concat "^[ \t]*:\\("
1501 (mapconcat
1502 'identity
1503 (org-delete-all exp-drawers
1504 (copy-sequence all-drawers))
1505 "\\|")
1506 "\\):[ \t]*$"))
1507 beg eol)
1508 (while (re-search-forward re nil t)
1509 (org-if-unprotected
1510 (setq beg (match-beginning 0)
1511 eol (match-end 0))
1512 (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
1513 nil t)
1514 (if (match-end 1)
1515 ;; terminated in this entry
1516 (progn
1517 (delete-region beg (match-end 1))
1518 (goto-char beg))
1519 (goto-char eol))))))))
1521 (defun org-export-handle-export-tags (select-tags exclude-tags)
1522 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1523 Both arguments are lists of tags.
1524 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1525 will be removed.
1526 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1527 removed as well."
1528 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1529 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1530 select-tags "\\|")
1531 "\\):"))
1532 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1533 exclude-tags "\\|")
1534 "\\):"))
1535 beg end cont)
1536 (goto-char (point-min))
1537 (when (and select-tags
1538 (re-search-forward
1539 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1540 ;; At least one tree is marked for export, this means
1541 ;; all the unmarked stuff needs to go.
1542 ;; Dig out the trees that should be exported
1543 (goto-char (point-min))
1544 (outline-next-heading)
1545 (setq beg (point))
1546 (put-text-property beg (point-max) :org-delete t)
1547 (while (re-search-forward re-sel nil t)
1548 (when (org-on-heading-p)
1549 (org-back-to-heading)
1550 (remove-text-properties
1551 (max (1- (point)) (point-min))
1552 (setq cont (save-excursion (org-end-of-subtree t t)))
1553 '(:org-delete t))
1554 (while (and (org-up-heading-safe)
1555 (get-text-property (point) :org-delete))
1556 (remove-text-properties (max (1- (point)) (point-min))
1557 (point-at-eol) '(:org-delete t)))
1558 (goto-char cont))))
1559 ;; Remove the trees explicitly marked for noexport
1560 (when exclude-tags
1561 (goto-char (point-min))
1562 (while (re-search-forward re-excl nil t)
1563 (when (org-at-heading-p)
1564 (org-back-to-heading t)
1565 (setq beg (point))
1566 (org-end-of-subtree t)
1567 (delete-region beg (point)))))
1568 ;; Remove everything that is now still marked for deletion
1569 (goto-char (point-min))
1570 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1571 (setq end (or (next-single-property-change beg :org-delete)
1572 (point-max)))
1573 (delete-region beg end))))
1575 (defun org-export-remove-archived-trees (export-archived-trees)
1576 "Remove archived trees.
1577 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1578 When it is t, the entire archived tree will be exported.
1579 When it is nil the entire tree including the headline will be removed
1580 from the buffer."
1581 (let ((re-archive (concat ":" org-archive-tag ":"))
1582 a b)
1583 (when (not (eq export-archived-trees t))
1584 (goto-char (point-min))
1585 (while (re-search-forward re-archive nil t)
1586 (if (not (org-on-heading-p t))
1587 (org-end-of-subtree t)
1588 (beginning-of-line 1)
1589 (setq a (if export-archived-trees
1590 (1+ (point-at-eol)) (point))
1591 b (org-end-of-subtree t))
1592 (if (> b a) (delete-region a b)))))))
1594 (defun org-export-remove-headline-metadata (opts)
1595 "Remove meta data from the headline, according to user options."
1596 (let ((re org-complex-heading-regexp)
1597 (todo (plist-get opts :todo-keywords))
1598 (tags (plist-get opts :tags))
1599 (pri (plist-get opts :priority))
1600 (elts '(1 2 3 4 5))
1601 rpl)
1602 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1603 (when (or (not todo) (not tags) (not pri))
1604 (goto-char (point-min))
1605 (while (re-search-forward re nil t)
1606 (org-if-unprotected
1607 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1608 elts " "))
1609 (replace-match rpl t t))))))
1611 (defun org-export-remove-timestamps ()
1612 "Remove timestamps and keywords for export."
1613 (goto-char (point-min))
1614 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1615 (backward-char 1)
1616 (org-if-unprotected
1617 (unless (save-match-data (org-at-table-p))
1618 (replace-match "")
1619 (beginning-of-line 1)
1620 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1621 (replace-match ""))))))
1623 (defun org-export-remove-clock-lines ()
1624 "Remove clock lines for export."
1625 (goto-char (point-min))
1626 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1627 (while (re-search-forward re nil t)
1628 (org-if-unprotected
1629 (replace-match "")))))
1631 (defun org-export-protect-quoted-subtrees ()
1632 "Mark quoted subtrees with the protection property."
1633 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1634 (goto-char (point-min))
1635 (while (re-search-forward re-quote nil t)
1636 (goto-char (match-beginning 0))
1637 (end-of-line 1)
1638 (add-text-properties (point) (org-end-of-subtree t)
1639 '(org-protected t)))))
1641 (defun org-export-protect-verbatim ()
1642 "Mark verbatim snippets with the protection property."
1643 (goto-char (point-min))
1644 (while (re-search-forward org-verbatim-re nil t)
1645 (add-text-properties (match-beginning 4) (match-end 4)
1646 '(org-protected t))
1647 (goto-char (1+ (match-end 4)))))
1649 (defun org-export-protect-colon-examples ()
1650 "Protect lines starting with a colon."
1651 (goto-char (point-min))
1652 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1653 (while (re-search-forward re nil t)
1654 (beginning-of-line 1)
1655 (setq beg (point))
1656 (while (looking-at re)
1657 (end-of-line 1)
1658 (or (eobp) (forward-char 1)))
1659 (add-text-properties beg (if (bolp) (1- (point)) (point))
1660 '(org-protected t)))))
1662 (defun org-export-select-backend-specific-text (backend)
1663 (let ((formatters
1664 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1665 (html "HTML" "BEGIN_HTML" "END_HTML")
1666 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1667 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1668 (case-fold-search t)
1669 fmt)
1671 (while formatters
1672 (setq fmt (pop formatters))
1673 (when (eq (car fmt) backend)
1674 ;; This is selected code, put it into the file for real
1675 (goto-char (point-min))
1676 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
1677 ":[ \t]*\\(.*\\)") nil t)
1678 (replace-match "\\1\\2" t)
1679 (add-text-properties
1680 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1681 '(org-protected t))))
1682 (goto-char (point-min))
1683 (while (re-search-forward
1684 (concat "^[ \t]*#\\+" (caddr fmt)
1685 "\\>.*\\(\\(\n.*\\)*?\n\\)[ \t]*#\\+" (cadddr fmt)
1686 "\\>.*\n?") nil t)
1687 (if (eq (car fmt) backend)
1688 ;; yes, keep this
1689 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1690 '(org-protected t))
1691 ;; No, this is for a different backend, kill it
1692 (delete-region (match-beginning 0) (match-end 0)))))))
1694 (defun org-export-mark-blockquote-verse-center ()
1695 "Mark block quote and verse environments with special cookies.
1696 These special cookies will later be interpreted by the backend."
1697 ;; Blockquotes
1698 (let (type t1 ind beg end beg1 end1 content)
1699 (goto-char (point-min))
1700 (while (re-search-forward
1701 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1702 nil t)
1703 (setq ind (length (match-string 1))
1704 type (downcase (match-string 3))
1705 t1 (if (equal type "quote") "blockquote" type))
1706 (setq beg (match-beginning 0)
1707 beg1 (1+ (match-end 0)))
1708 (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
1709 (setq end (1+ (point-at-eol))
1710 end1 (1- (match-beginning 0)))
1711 (setq content (org-remove-indentation (buffer-substring beg1 end1)))
1712 (setq content (concat "ORG-" (upcase t1) "-START\n"
1713 content "\n"
1714 "ORG-" (upcase t1) "-END\n"))
1715 (delete-region beg end)
1716 (insert (org-add-props content nil 'original-indentation ind))))))
1718 (defun org-export-attach-captions-and-attributes (backend target-alist)
1719 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1720 If the next thing following is a table, add the text properties to the first
1721 table line. If it is a link, add it to the line containing the link."
1722 (goto-char (point-min))
1723 (remove-text-properties (point-min) (point-max)
1724 '(org-caption nil org-attributes nil))
1725 (let ((case-fold-search t)
1726 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1727 "\\|"
1728 "^[ \t]*#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
1729 "\\|"
1730 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1731 "\\|"
1732 "^[ \t]*|[^-]"
1733 "\\|"
1734 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1735 cap attr label)
1736 (while (re-search-forward re nil t)
1737 (cond
1738 ((match-end 1)
1739 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
1740 ((match-end 2)
1741 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
1742 ((match-end 3)
1743 (setq label (org-trim (match-string 3))))
1745 (add-text-properties (point-at-bol) (point-at-eol)
1746 (list 'org-caption cap
1747 'org-attributes attr
1748 'org-label label))
1749 (if label (push (cons label label) target-alist))
1750 (setq cap nil attr nil label nil)))))
1751 target-alist)
1753 (defun org-export-remove-comment-blocks-and-subtrees ()
1754 "Remove the comment environment, and also commented subtrees."
1755 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1756 (case-fold-search nil))
1757 ;; Remove comment environment
1758 (goto-char (point-min))
1759 (while (re-search-forward
1760 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1761 (replace-match "" t t))
1762 ;; Remove subtrees that are commented
1763 (goto-char (point-min))
1764 (while (re-search-forward re-commented nil t)
1765 (goto-char (match-beginning 0))
1766 (delete-region (point) (org-end-of-subtree t)))))
1768 (defun org-export-handle-comments (commentsp)
1769 "Remove comments, or convert to backend-specific format.
1770 COMMENTSP can be a format string for publishing comments.
1771 When it is nil, all comments will be removed."
1772 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1773 pos)
1774 (goto-char (point-min))
1775 (while (or (looking-at re)
1776 (re-search-forward re nil t))
1777 (setq pos (match-beginning 0))
1778 (if (and commentsp
1779 (not (equal (char-before (match-end 1)) ?+)))
1780 (progn (add-text-properties
1781 (match-beginning 0) (match-end 0) '(org-protected t))
1782 (replace-match (format commentsp (match-string 2)) t t))
1783 (goto-char (1+ pos))
1784 (org-if-unprotected
1785 (replace-match "")
1786 (goto-char (max (point-min) (1- pos))))))))
1788 (defun org-export-mark-radio-links ()
1789 "Find all matches for radio targets and turn them into internal links."
1790 (let ((re-radio (and org-target-link-regexp
1791 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1792 (goto-char (point-min))
1793 (when re-radio
1794 (while (re-search-forward re-radio nil t)
1795 (unless
1796 (save-match-data
1797 (or (org-in-regexp org-bracket-link-regexp)
1798 (org-in-regexp org-plain-link-re)))
1799 (org-if-unprotected
1800 (replace-match "\\1[[\\2]]")))))))
1802 (defun org-export-remove-special-table-lines ()
1803 "Remove tables lines that are used for internal purposes."
1804 (goto-char (point-min))
1805 (while (re-search-forward "^[ \t]*|" nil t)
1806 (beginning-of-line 1)
1807 (if (or (looking-at "[ \t]*| *[!_^] *|")
1808 (and (looking-at ".*?| *<[0-9]+> *|")
1809 (not (looking-at ".*?| *[^ <|]"))))
1810 (delete-region (max (point-min) (1- (point-at-bol)))
1811 (point-at-eol))
1812 (end-of-line 1))))
1814 (defun org-export-normalize-links ()
1815 "Convert all links to bracket links, and expand link abbreviations."
1816 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1817 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1818 nodesc)
1819 (goto-char (point-min))
1820 (while (re-search-forward re-plain-link nil t)
1821 (goto-char (1- (match-end 0)))
1822 (org-if-unprotected-at (1+ (match-beginning 0))
1823 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1824 ":" (match-string 3) "]]")))
1825 ;; added 'org-link face to links
1826 (put-text-property 0 (length s) 'face 'org-link s)
1827 (replace-match s t t))))
1828 (goto-char (point-min))
1829 (while (re-search-forward re-angle-link nil t)
1830 (goto-char (1- (match-end 0)))
1831 (org-if-unprotected
1832 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1833 ":" (match-string 3) "]]")))
1834 (put-text-property 0 (length s) 'face 'org-link s)
1835 (replace-match s t t))))
1836 (goto-char (point-min))
1837 (while (re-search-forward org-bracket-link-regexp nil t)
1838 (goto-char (1- (match-end 0)))
1839 (setq nodesc (not (match-end 3)))
1840 (org-if-unprotected
1841 (let* ((xx (save-match-data
1842 (org-translate-link
1843 (org-link-expand-abbrev (match-string 1)))))
1844 (s (concat
1845 "[[" (org-add-props (copy-sequence xx)
1846 nil 'org-protected t 'org-no-description nodesc)
1848 (if (match-end 3)
1849 (match-string 2)
1850 (concat "[" (copy-sequence xx)
1851 "]"))
1852 "]")))
1853 (put-text-property 0 (length s) 'face 'org-link s)
1854 (replace-match s t t))))))
1856 (defun org-export-concatenate-multiline-links ()
1857 "Find multi-line links and put it all into a single line.
1858 This is to make sure that the line-processing export backends
1859 can work correctly."
1860 (goto-char (point-min))
1861 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1862 (org-if-unprotected
1863 (replace-match "\\1 \\3")
1864 (goto-char (match-beginning 0)))))
1866 (defun org-export-concatenate-multiline-emphasis ()
1867 "Find multi-line emphasis and put it all into a single line.
1868 This is to make sure that the line-processing export backends
1869 can work correctly."
1870 (goto-char (point-min))
1871 (while (re-search-forward org-emph-re nil t)
1872 (if (and (not (= (char-after (match-beginning 3))
1873 (char-after (match-beginning 4))))
1874 (save-excursion (goto-char (match-beginning 0))
1875 (save-match-data (not (org-at-table-p)))))
1876 (org-if-unprotected
1877 (subst-char-in-region (match-beginning 0) (match-end 0)
1878 ?\n ?\ t)
1879 (goto-char (1- (match-end 0))))
1880 (goto-char (1+ (match-beginning 0))))))
1882 (defun org-export-grab-title-from-buffer ()
1883 "Get a title for the current document, from looking at the buffer."
1884 (let ((inhibit-read-only t))
1885 (save-excursion
1886 (goto-char (point-min))
1887 (let ((end (if (looking-at org-outline-regexp)
1888 (point)
1889 (save-excursion (outline-next-heading) (point)))))
1890 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1891 ;; Mark the line so that it will not be exported as normal text.
1892 (org-unmodified
1893 (add-text-properties (match-beginning 0) (match-end 0)
1894 (list :org-license-to-kill t)))
1895 ;; Return the title string
1896 (org-trim (match-string 0)))))))
1898 (defun org-export-get-title-from-subtree ()
1899 "Return subtree title and exclude it from export."
1900 (let (title (rbeg (region-beginning)) (rend (region-end)))
1901 (save-excursion
1902 (goto-char rbeg)
1903 (when (and (org-at-heading-p)
1904 (>= (org-end-of-subtree t t) rend))
1905 ;; This is a subtree, we take the title from the first heading
1906 (goto-char rbeg)
1907 (looking-at org-todo-line-regexp)
1908 (setq title (match-string 3))
1909 (org-unmodified
1910 (add-text-properties (point) (1+ (point-at-eol))
1911 (list :org-license-to-kill t)))
1912 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1913 title))
1915 (defun org-solidify-link-text (s &optional alist)
1916 "Take link text and make a safe target out of it."
1917 (save-match-data
1918 (let* ((rtn
1919 (mapconcat
1920 'identity
1921 (org-split-string s "[ \t\r\n]+") "=="))
1922 (a (assoc rtn alist)))
1923 (or (cdr a) rtn))))
1925 (defun org-get-min-level (lines &optional offset)
1926 "Get the minimum level in LINES."
1927 (let ((re "^\\(\\*+\\) ") l)
1928 (catch 'exit
1929 (while (setq l (pop lines))
1930 (if (string-match re l)
1931 (throw 'exit (org-tr-level (- (length (match-string 1 l))
1932 (or offset 0))))))
1933 1)))
1935 ;; Variable holding the vector with section numbers
1936 (defvar org-section-numbers (make-vector org-level-max 0))
1938 (defun org-init-section-numbers ()
1939 "Initialize the vector for the section numbers."
1940 (let* ((level -1)
1941 (numbers (nreverse (org-split-string "" "\\.")))
1942 (depth (1- (length org-section-numbers)))
1943 (i depth) number-string)
1944 (while (>= i 0)
1945 (if (> i level)
1946 (aset org-section-numbers i 0)
1947 (setq number-string (or (car numbers) "0"))
1948 (if (string-match "\\`[A-Z]\\'" number-string)
1949 (aset org-section-numbers i
1950 (- (string-to-char number-string) ?A -1))
1951 (aset org-section-numbers i (string-to-number number-string)))
1952 (pop numbers))
1953 (setq i (1- i)))))
1955 (defun org-section-number (&optional level)
1956 "Return a string with the current section number.
1957 When LEVEL is non-nil, increase section numbers on that level."
1958 (let* ((depth (1- (length org-section-numbers)))
1959 (string "")
1960 (fmts (car org-export-section-number-format))
1961 (term (cdr org-export-section-number-format))
1962 (sep "")
1963 ctype fmt idx n)
1964 (when level
1965 (when (> level -1)
1966 (aset org-section-numbers
1967 level (1+ (aref org-section-numbers level))))
1968 (setq idx (1+ level))
1969 (while (<= idx depth)
1970 (if (not (= idx 1))
1971 (aset org-section-numbers idx 0))
1972 (setq idx (1+ idx))))
1973 (setq idx 0)
1974 (while (<= idx depth)
1975 (when (> (aref org-section-numbers idx) 0)
1976 (setq fmt (or (pop fmts) fmt)
1977 ctype (car fmt)
1978 n (aref org-section-numbers idx)
1979 string (if (> n 0)
1980 (concat string sep (org-number-to-counter n ctype))
1981 (concat string ".0"))
1982 sep (nth 1 fmt)))
1983 (setq idx (1+ idx)))
1984 (save-match-data
1985 (if (string-match "\\`\\([@0]\\.\\)+" string)
1986 (setq string (replace-match "" t nil string)))
1987 (if (string-match "\\(\\.0\\)+\\'" string)
1988 (setq string (replace-match "" t nil string))))
1989 (concat string term)))
1991 (defun org-number-to-counter (n type)
1992 "Concert number N to a string counter, according to TYPE.
1993 TYPE must be a string, any of:
1994 1 number
1995 A A,B,....
1996 a a,b,....
1997 I upper case roman numeral
1998 i lower case roman numeral"
1999 (cond
2000 ((equal type "1") (number-to-string n))
2001 ((equal type "A") (char-to-string (+ ?A n -1)))
2002 ((equal type "a") (char-to-string (+ ?a n -1)))
2003 ((equal type "I") (org-number-to-roman n))
2004 ((equal type "i") (downcase (org-number-to-roman n)))
2005 (t (error "Invalid counter type `%s'" type))))
2007 (defun org-number-to-roman (n)
2008 "Convert integer N into a roman numeral."
2009 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2010 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2011 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2012 ( 1 . "I")))
2013 (res ""))
2014 (if (<= n 0)
2015 (number-to-string n)
2016 (while roman
2017 (if (>= n (caar roman))
2018 (setq n (- n (caar roman))
2019 res (concat res (cdar roman)))
2020 (pop roman)))
2021 res)))
2023 ;;; Macros
2025 (defun org-export-preprocess-apply-macros ()
2026 "Replace macro references."
2027 (goto-char (point-min))
2028 (let (sy val key args args2 s n)
2029 (while (re-search-forward
2030 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\(.*?\\))\\)?}}}"
2031 nil t)
2032 (setq key (downcase (match-string 1))
2033 args (match-string 3))
2034 (when (setq val (or (plist-get org-export-opt-plist
2035 (intern (concat ":macro-" key)))
2036 (plist-get org-export-opt-plist
2037 (intern (concat ":" key)))))
2038 (save-match-data
2039 (when args
2040 (setq args (org-split-string args ",[ \t]*") args2 nil)
2041 (while args
2042 (while (string-match "\\\\\\'" (car args))
2043 ;; repair bad splits
2044 (setcar (cdr args) (concat (substring (car args) 0 -1)
2045 ";" (nth 1 args)))
2046 (pop args))
2047 (push (pop args) args2))
2048 (setq args (nreverse args2))
2049 (setq s 0)
2050 (while (string-match "\\$\\([0-9]+\\)" val s)
2051 (setq s (1+ (match-beginning 0))
2052 n (string-to-number (match-string 1 val)))
2053 (and (>= (length args) n)
2054 (setq val (replace-match (nth (1- n) args) t t val)))))
2055 (when (string-match "\\`(eval\\>" val)
2056 (setq val (eval (read val))))
2057 (if (and val (not (stringp val)))
2058 (setq val (format "%s" val))))
2059 (and (stringp val)
2060 (replace-match val t t))))))
2062 (defun org-export-apply-macros-in-string (s)
2063 "Apply the macros in string S."
2064 (when s
2065 (with-temp-buffer
2066 (insert s)
2067 (org-export-preprocess-apply-macros)
2068 (buffer-string))))
2070 ;;; Include files
2072 (defun org-export-handle-include-files ()
2073 "Include the contents of include files, with proper formatting."
2074 (let ((case-fold-search t)
2075 params file markup lang start end prefix prefix1 switches)
2076 (goto-char (point-min))
2077 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2078 (setq params (read (concat "(" (match-string 1) ")"))
2079 prefix (org-get-and-remove-property 'params :prefix)
2080 prefix1 (org-get-and-remove-property 'params :prefix1)
2081 file (org-symname-or-string (pop params))
2082 markup (org-symname-or-string (pop params))
2083 lang (and (member markup '("src" "SRC"))
2084 (org-symname-or-string (pop params)))
2085 switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
2086 (delete-region (match-beginning 0) (match-end 0))
2087 (if (or (not file)
2088 (not (file-exists-p file))
2089 (not (file-readable-p file)))
2090 (insert (format "CANNOT INCLUDE FILE %s" file))
2091 (when markup
2092 (if (equal (downcase markup) "src")
2093 (setq start (format "#+begin_src %s %s\n"
2094 (or lang "fundamental")
2095 (or switches ""))
2096 end "#+end_src")
2097 (setq start (format "#+begin_%s %s\n" markup switches)
2098 end (format "#+end_%s" markup))))
2099 (insert (or start ""))
2100 (insert (org-get-file-contents (expand-file-name file) prefix prefix1 markup))
2101 (or (bolp) (newline))
2102 (insert (or end ""))))))
2104 (defun org-get-file-contents (file &optional prefix prefix1 markup)
2105 "Get the contents of FILE and return them as a string.
2106 If PREFIX is a string, prepend it to each line. If PREFIX1
2107 is a string, prepend it to the first line instead of PREFIX.
2108 If MARKUP, don't protect org-like lines, the exporter will
2109 take care of the block they are in."
2110 (with-temp-buffer
2111 (insert-file-contents file)
2112 (when (or prefix prefix1)
2113 (goto-char (point-min))
2114 (while (not (eobp))
2115 (insert (or prefix1 prefix))
2116 (setq prefix1 nil)
2117 (beginning-of-line 2)))
2118 (buffer-string)
2119 (unless markup
2120 (goto-char (point-min))
2121 (while (re-search-forward "^\\(\\*\\|[ \t]*#\\)" nil t)
2122 (goto-char (match-beginning 0))
2123 (insert ",")
2124 (end-of-line 1)))
2125 (buffer-string)))
2127 (defun org-get-and-remove-property (listvar prop)
2128 "Check if the value of LISTVAR contains PROP as a property.
2129 If yes, return the value of that property (i.e. the element following
2130 in the list) and remove property and value from the list in LISTVAR."
2131 (let ((list (symbol-value listvar)) m v)
2132 (when (setq m (member prop list))
2133 (setq v (nth 1 m))
2134 (if (equal (car list) prop)
2135 (set listvar (cddr list))
2136 (setcdr (nthcdr (- (length list) (length m) 1) list)
2137 (cddr m))
2138 (set listvar list)))
2141 (defun org-symname-or-string (s)
2142 (if (symbolp s)
2143 (if s (symbol-name s) s)
2146 ;;; Fontification and line numbers for code examples
2148 (defvar org-export-last-code-line-counter-value 0)
2150 (defun org-export-replace-src-segments-and-examples (backend)
2151 "Replace source code segments with special code for export."
2152 (setq org-export-last-code-line-counter-value 0)
2153 (let ((case-fold-search t)
2154 lang code trans opts indent)
2155 (goto-char (point-min))
2156 (while (re-search-forward
2157 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
2158 nil t)
2159 (if (match-end 1)
2160 ;; src segments
2161 (setq lang (match-string 3)
2162 opts (match-string 4)
2163 code (match-string 5)
2164 indent (length (match-string 2)))
2165 (setq lang nil
2166 opts (match-string 8)
2167 code (match-string 9)
2168 indent (length (match-string 7))))
2170 (setq trans (org-export-format-source-code-or-example
2171 backend lang code opts indent))
2172 (replace-match trans t t))))
2174 (defvar htmlp) ;; dynamically scoped
2175 (defvar latexp) ;; dynamically scoped
2176 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
2178 (defun org-export-format-source-code-or-example
2179 (backend lang code &optional opts indent)
2180 "Format CODE from language LANG and return it formatted for export.
2181 If LANG is nil, do not add any fontification.
2182 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2183 and `+n' for continuing previous numering.
2184 Code formatting according to language currently only works for HTML.
2185 Numbering lines works for all three major backends (html, latex, and ascii).
2186 INDENT was the original indentation of the block."
2187 (save-match-data
2188 (let (num cont rtn rpllbl keepp textareap cols rows fmt)
2189 (setq opts (or opts "")
2190 num (string-match "[-+]n\\>" opts)
2191 cont (string-match "\\+n\\>" opts)
2192 rpllbl (string-match "-r\\>" opts)
2193 keepp (string-match "-k\\>" opts)
2194 textareap (string-match "-t\\>" opts)
2195 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2196 (string-to-number (match-string 1 opts))
2198 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2199 (string-to-number (match-string 1 opts))
2200 (org-count-lines code))
2201 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2202 (match-string 1 opts)))
2203 (when (and textareap (eq backend 'html))
2204 ;; we cannot use numbering or highlighting.
2205 (setq num nil cont nil lang nil))
2206 (if keepp (setq rpllbl 'keep))
2207 (setq rtn (org-remove-indentation code))
2208 (when (string-match "^," rtn)
2209 (setq rtn (with-temp-buffer
2210 (insert rtn)
2211 ;; Free up the protected lines
2212 (goto-char (point-min))
2213 (while (re-search-forward "^," nil t)
2214 (if (or (equal lang "org")
2215 (save-match-data
2216 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2217 (replace-match ""))
2218 (end-of-line 1))
2219 (buffer-string))))
2220 ;; Now backend-specific coding
2221 (setq rtn
2222 (cond
2223 ((eq backend 'docbook)
2224 (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
2225 (concat "\n#+BEGIN_DOCBOOK\n"
2226 (org-add-props (concat "<programlisting><![CDATA["
2228 "]]>\n</programlisting>\n")
2229 '(org-protected t))
2230 "#+END_DOCBOOK\n"))
2231 ((eq backend 'html)
2232 ;; We are exporting to HTML
2233 (when lang
2234 (require 'htmlize nil t)
2235 (when (not (fboundp 'htmlize-region-for-paste))
2236 ;; we do not have htmlize.el, or an old version of it
2237 (setq lang nil)
2238 (message
2239 "htmlize.el 1.34 or later is needed for source code formatting")))
2241 (if lang
2242 (let* ((mode (and lang (intern (concat lang "-mode"))))
2243 (org-inhibit-startup t)
2244 (org-startup-folded nil))
2245 (setq rtn
2246 (with-temp-buffer
2247 (insert rtn)
2248 (if (functionp mode)
2249 (funcall mode)
2250 (fundamental-mode))
2251 (font-lock-fontify-buffer)
2252 (org-src-mode)
2253 (set-buffer-modified-p nil)
2254 (org-export-htmlize-region-for-paste
2255 (point-min) (point-max))))
2256 (if (string-match "<pre\\([^>]*\\)>\n*" rtn)
2257 (setq rtn (replace-match
2258 (format "<pre class=\"src src-%s\">\n" lang)
2259 t t rtn))))
2260 (if textareap
2261 (setq rtn (concat
2262 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2263 cols rows)
2264 rtn "</textarea>\n</p>\n"))
2265 (with-temp-buffer
2266 (insert rtn)
2267 (goto-char (point-min))
2268 (while (re-search-forward "[<>&]" nil t)
2269 (replace-match (cdr (assq (char-before)
2270 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2271 t t))
2272 (setq rtn (buffer-string)))
2273 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2274 (unless textareap
2275 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2276 cont rpllbl fmt)))
2277 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn)
2278 (setq rtn (replace-match "\\1" t nil rtn)))
2279 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2280 ((eq backend 'latex)
2281 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2282 (concat "\n#+BEGIN_LaTeX\n"
2283 (org-add-props (concat (car org-export-latex-verbatim-wrap)
2284 rtn (cdr org-export-latex-verbatim-wrap))
2285 '(org-protected t))
2286 "#+END_LaTeX\n\n"))
2287 ((eq backend 'ascii)
2288 ;; This is not HTML or LaTeX, so just make it an example.
2289 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2290 (concat "#+BEGIN_ASCII\n"
2291 (org-add-props
2292 (concat
2293 (mapconcat
2294 (lambda (l) (concat " " l))
2295 (org-split-string rtn "\n")
2296 "\n")
2297 "\n")
2298 '(org-protected t))
2299 "#+END_ASCII\n"))))
2300 (org-add-props rtn nil 'original-indentation indent))))
2302 (defun org-export-number-lines (text backend
2303 &optional skip1 skip2 number cont
2304 replace-labels label-format)
2305 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2306 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2307 (with-temp-buffer
2308 (insert text)
2309 (goto-char (point-max))
2310 (skip-chars-backward " \t\n\r")
2311 (delete-region (point) (point-max))
2312 (beginning-of-line (- 1 skip2))
2313 (let* ((last (org-current-line))
2314 (n org-export-last-code-line-counter-value)
2315 (nmax (+ n (- last skip1)))
2316 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2318 (cond
2319 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2320 fmt))
2321 ((eq backend 'ascii) fmt)
2322 ((eq backend 'latex) fmt)
2323 ((eq backend 'docbook) fmt)
2324 (t "")))
2325 (label-format (or label-format org-coderef-label-format))
2326 (label-pre (if (string-match "%s" label-format)
2327 (substring label-format 0 (match-beginning 0))
2328 label-format))
2329 (label-post (if (string-match "%s" label-format)
2330 (substring label-format (match-end 0))
2331 ""))
2332 (lbl-re
2333 (concat
2334 ".*?\\S-.*?\\([ \t]*\\("
2335 (regexp-quote label-pre)
2336 "\\([-a-zA-Z0-9_ ]+\\)"
2337 (regexp-quote label-post)
2338 "\\)\\)"))
2339 ref)
2341 (goto-line (1+ skip1))
2342 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2343 (if number
2344 (insert (format fm (incf n)))
2345 (forward-char 1))
2346 (when (looking-at lbl-re)
2347 (setq ref (match-string 3))
2348 (cond ((numberp replace-labels)
2349 ;; remove labels; use numbers for references when lines
2350 ;; are numbered, use labels otherwise
2351 (delete-region (match-beginning 1) (match-end 1))
2352 (push (cons ref (if (> n 0) n ref)) org-export-code-refs))
2353 ((eq replace-labels 'keep)
2354 ;; don't remove labels; use numbers for references when
2355 ;; lines are numbered, use labels otherwise
2356 (goto-char (match-beginning 2))
2357 (delete-region (match-beginning 2) (match-end 2))
2358 (insert "(" ref ")")
2359 (push (cons ref (if (> n 0) n (concat "(" ref ")")))
2360 org-export-code-refs))
2362 ;; don't remove labels and don't use numbers for
2363 ;; references
2364 (goto-char (match-beginning 2))
2365 (delete-region (match-beginning 2) (match-end 2))
2366 (insert "(" ref ")")
2367 (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
2368 (when (eq backend 'html)
2369 (save-excursion
2370 (beginning-of-line 1)
2371 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2372 ref))
2373 (end-of-line 1)
2374 (insert "</span>")))))
2375 (setq org-export-last-code-line-counter-value n)
2376 (goto-char (point-max))
2377 (newline)
2378 (buffer-string))))
2380 (defun org-search-todo-below (line lines level)
2381 "Search the subtree below LINE for any TODO entries."
2382 (let ((rest (cdr (memq line lines)))
2383 (re org-todo-line-regexp)
2384 line lv todo)
2385 (catch 'exit
2386 (while (setq line (pop rest))
2387 (if (string-match re line)
2388 (progn
2389 (setq lv (- (match-end 1) (match-beginning 1))
2390 todo (and (match-beginning 2)
2391 (not (member (match-string 2 line)
2392 org-done-keywords))))
2393 ; TODO, not DONE
2394 (if (<= lv level) (throw 'exit nil))
2395 (if todo (throw 'exit t))))))))
2397 ;;;###autoload
2398 (defun org-export-visible (type arg)
2399 "Create a copy of the visible part of the current buffer, and export it.
2400 The copy is created in a temporary buffer and removed after use.
2401 TYPE is the final key (as a string) that also select the export command in
2402 the `C-c C-e' export dispatcher.
2403 As a special case, if the you type SPC at the prompt, the temporary
2404 org-mode file will not be removed but presented to you so that you can
2405 continue to use it. The prefix arg ARG is passed through to the exporting
2406 command."
2407 (interactive
2408 (list (progn
2409 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2410 (read-char-exclusive))
2411 current-prefix-arg))
2412 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ )))
2413 (error "Invalid export key"))
2414 (let* ((binding (cdr (assoc type
2415 '((?a . org-export-as-ascii)
2416 (?A . org-export-as-ascii-to-buffer)
2417 (?\C-a . org-export-as-ascii)
2418 (?b . org-export-as-html-and-open)
2419 (?\C-b . org-export-as-html-and-open)
2420 (?h . org-export-as-html)
2421 (?H . org-export-as-html-to-buffer)
2422 (?R . org-export-region-as-html)
2423 (?D . org-export-as-docbook)
2424 (?x . org-export-as-xoxo)))))
2425 (keepp (equal type ?\ ))
2426 (file buffer-file-name)
2427 (buffer (get-buffer-create "*Org Export Visible*"))
2428 s e)
2429 ;; Need to hack the drawers here.
2430 (save-excursion
2431 (goto-char (point-min))
2432 (while (re-search-forward org-drawer-regexp nil t)
2433 (goto-char (match-beginning 1))
2434 (or (org-invisible-p) (org-flag-drawer nil))))
2435 (with-current-buffer buffer (erase-buffer))
2436 (save-excursion
2437 (setq s (goto-char (point-min)))
2438 (while (not (= (point) (point-max)))
2439 (goto-char (org-find-invisible))
2440 (append-to-buffer buffer s (point))
2441 (setq s (goto-char (org-find-visible))))
2442 (org-cycle-hide-drawers 'all)
2443 (goto-char (point-min))
2444 (unless keepp
2445 ;; Copy all comment lines to the end, to make sure #+ settings are
2446 ;; still available for the second export step. Kind of a hack, but
2447 ;; does do the trick.
2448 (if (looking-at "#[^\r\n]*")
2449 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2450 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2451 (append-to-buffer buffer (1+ (match-beginning 0))
2452 (min (point-max) (1+ (match-end 0))))))
2453 (set-buffer buffer)
2454 (let ((buffer-file-name file)
2455 (org-inhibit-startup t))
2456 (org-mode)
2457 (show-all)
2458 (unless keepp (funcall binding arg))))
2459 (if (not keepp)
2460 (kill-buffer buffer)
2461 (switch-to-buffer-other-window buffer)
2462 (goto-char (point-min)))))
2464 (defun org-find-visible ()
2465 (let ((s (point)))
2466 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2467 (get-char-property s 'invisible)))
2469 (defun org-find-invisible ()
2470 (let ((s (point)))
2471 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2472 (not (get-char-property s 'invisible))))
2475 (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
2477 ;;;###autoload
2478 (defun org-export-as-org (arg &optional hidden ext-plist
2479 to-buffer body-only pub-dir)
2480 "Make a copy with not-exporting stuff removed.
2481 The purpose of this function is to provide a way to export the source
2482 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2483 stuff removed. This command will remove the following:
2485 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2486 - comment blocks and trees starting with the COMMENT keyword
2487 - only trees that are consistent with `org-export-select-tags'
2488 and `org-export-exclude-tags'.
2490 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2491 all the others will be ignored (but are present so that the general
2492 mechanism to call publishing functions will work).
2494 EXT-PLIST is a property list with external parameters overriding
2495 org-mode's default settings, but still inferior to file-local
2496 settings. When PUB-DIR is set, use this as the publishing
2497 directory."
2498 (interactive "P")
2499 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2500 ext-plist
2501 (org-infile-export-plist)))
2502 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2503 (filename (concat (file-name-as-directory
2504 (or pub-dir
2505 (org-export-directory :org opt-plist)))
2506 (file-name-sans-extension
2507 (file-name-nondirectory bfname))
2508 ".org"))
2509 (filename (and filename
2510 (if (equal (file-truename filename)
2511 (file-truename bfname))
2512 (concat (file-name-sans-extension filename)
2513 "-source."
2514 (file-name-extension filename))
2515 filename)))
2516 (backup-inhibited t)
2517 (buffer (find-file-noselect filename))
2518 (region (buffer-string)))
2519 (save-excursion
2520 (switch-to-buffer buffer)
2521 (erase-buffer)
2522 (insert region)
2523 (let ((org-inhibit-startup t)) (org-mode))
2524 (org-install-letbind)
2526 ;; Get rid of archived trees
2527 (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
2529 ;; Remove comment environment and comment subtrees
2530 (org-export-remove-comment-blocks-and-subtrees)
2532 ;; Get rid of excluded trees
2533 (org-export-handle-export-tags (plist-get opt-plist :select-tags)
2534 (plist-get opt-plist :exclude-tags))
2536 (when (or (plist-get opt-plist :plain-source)
2537 (not (or (plist-get opt-plist :plain-source)
2538 (plist-get opt-plist :htmlized-source))))
2539 ;; Either nothing special is requested (default call)
2540 ;; or the plain source is explicitly requested
2541 ;; so: save it
2542 (save-buffer))
2543 (when (plist-get opt-plist :htmlized-source)
2544 ;; Make the htmlized version
2545 (require 'htmlize)
2546 (require 'org-html)
2547 (font-lock-fontify-buffer)
2548 (let* ((htmlize-output-type 'css)
2549 (newbuf (htmlize-buffer)))
2550 (with-current-buffer newbuf
2551 (when org-export-htmlized-org-css-url
2552 (goto-char (point-min))
2553 (and (re-search-forward
2554 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2555 nil t)
2556 (replace-match
2557 (format
2558 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2559 org-export-htmlized-org-css-url)
2560 t t)))
2561 (write-file (concat filename ".html")))
2562 (kill-buffer newbuf)))
2563 (set-buffer-modified-p nil)
2564 (kill-buffer (current-buffer)))))
2566 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2567 (defun org-get-current-options ()
2568 "Return a string with current options as keyword options.
2569 Does include HTML export options as well as TODO and CATEGORY stuff."
2570 (require 'org-archive)
2571 (format
2572 "#+TITLE: %s
2573 #+AUTHOR: %s
2574 #+EMAIL: %s
2575 #+DATE: %s
2576 #+DESCRIPTION:
2577 #+KEYWORDS:
2578 #+LANGUAGE: %s
2579 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2580 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2582 #+EXPORT_SELECT_TAGS: %s
2583 #+EXPORT_EXCLUDE_TAGS: %s
2584 #+LINK_UP: %s
2585 #+LINK_HOME: %s
2586 #+CATEGORY: %s
2587 #+SEQ_TODO: %s
2588 #+TYP_TODO: %s
2589 #+PRIORITIES: %c %c %c
2590 #+DRAWERS: %s
2591 #+STARTUP: %s %s %s %s %s
2592 #+TAGS: %s
2593 #+FILETAGS: %s
2594 #+ARCHIVE: %s
2595 #+LINK: %s
2597 (buffer-name) (user-full-name) user-mail-address
2598 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2599 org-export-default-language
2600 org-export-headline-levels
2601 org-export-with-section-numbers
2602 org-export-with-toc
2603 org-export-preserve-breaks
2604 org-export-html-expand
2605 org-export-with-fixed-width
2606 org-export-with-tables
2607 org-export-with-sub-superscripts
2608 org-export-with-special-strings
2609 org-export-with-footnotes
2610 org-export-with-emphasize
2611 org-export-with-timestamps
2612 org-export-with-TeX-macros
2613 org-export-with-LaTeX-fragments
2614 org-export-skip-text-before-1st-heading
2615 org-export-with-drawers
2616 org-export-with-todo-keywords
2617 org-export-with-priority
2618 org-export-with-tags
2619 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2620 (mapconcat 'identity org-export-select-tags " ")
2621 (mapconcat 'identity org-export-exclude-tags " ")
2622 org-export-html-link-up
2623 org-export-html-link-home
2624 (or (ignore-errors
2625 (file-name-sans-extension
2626 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2627 "NOFILENAME")
2628 "TODO FEEDBACK VERIFY DONE"
2629 "Me Jason Marie DONE"
2630 org-highest-priority org-lowest-priority org-default-priority
2631 (mapconcat 'identity org-drawers " ")
2632 (cdr (assoc org-startup-folded
2633 '((nil . "showall") (t . "overview") (content . "content"))))
2634 (if org-odd-levels-only "odd" "oddeven")
2635 (if org-hide-leading-stars "hidestars" "showstars")
2636 (if org-startup-align-all-tables "align" "noalign")
2637 (cond ((eq org-log-done t) "logdone")
2638 ((equal org-log-done 'note) "lognotedone")
2639 ((not org-log-done) "nologdone"))
2640 (or (mapconcat (lambda (x)
2641 (cond
2642 ((equal '(:startgroup) x) "{")
2643 ((equal '(:endgroup) x) "}")
2644 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2645 (t (car x))))
2646 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2647 (mapconcat 'identity org-file-tags " ")
2648 org-archive-location
2649 "org file:~/org/%s.org"
2652 ;;;###autoload
2653 (defun org-insert-export-options-template ()
2654 "Insert into the buffer a template with information for exporting."
2655 (interactive)
2656 (if (not (bolp)) (newline))
2657 (let ((s (org-get-current-options)))
2658 (and (string-match "#\\+CATEGORY" s)
2659 (setq s (substring s 0 (match-beginning 0))))
2660 (insert s)))
2662 (defvar org-table-colgroup-info nil)
2664 (defun org-table-clean-before-export (lines &optional maybe-quoted)
2665 "Check if the table has a marking column.
2666 If yes remove the column and the special lines."
2667 (setq org-table-colgroup-info nil)
2668 (if (memq nil
2669 (mapcar
2670 (lambda (x) (or (string-match "^[ \t]*|-" x)
2671 (string-match
2672 (if maybe-quoted
2673 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2674 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2675 x)))
2676 lines))
2677 (progn
2678 (setq org-table-clean-did-remove-column nil)
2679 (delq nil
2680 (mapcar
2681 (lambda (x)
2682 (cond
2683 ((string-match "^[ \t]*| */ *|" x)
2684 (setq org-table-colgroup-info
2685 (mapcar (lambda (x)
2686 (cond ((member x '("<" "&lt;")) :start)
2687 ((member x '(">" "&gt;")) :end)
2688 ((member x '("<>" "&lt;&gt;")) :startend)
2689 (t nil)))
2690 (org-split-string x "[ \t]*|[ \t]*")))
2691 nil)
2692 (t x)))
2693 lines)))
2694 (setq org-table-clean-did-remove-column t)
2695 (delq nil
2696 (mapcar
2697 (lambda (x)
2698 (cond
2699 ((string-match "^[ \t]*| */ *|" x)
2700 (setq org-table-colgroup-info
2701 (mapcar (lambda (x)
2702 (cond ((member x '("<" "&lt;")) :start)
2703 ((member x '(">" "&gt;")) :end)
2704 ((member x '("<>" "&lt;&gt;")) :startend)
2705 (t nil)))
2706 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2707 nil)
2708 ((string-match "^[ \t]*| *[!_^/] *|" x)
2709 nil) ; ignore this line
2710 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2711 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2712 ;; remove the first column
2713 (replace-match "\\1|" t nil x))))
2714 lines))))
2716 (defun org-export-cleanup-toc-line (s)
2717 "Remove tags and timestamps from lines going into the toc."
2718 (when (memq org-export-with-tags '(not-in-toc nil))
2719 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
2720 (setq s (replace-match "" t t s))))
2721 (when org-export-remove-timestamps-from-toc
2722 (while (string-match org-maybe-keyword-time-regexp s)
2723 (setq s (replace-match "" t t s))))
2724 (while (string-match org-bracket-link-regexp s)
2725 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
2726 t t s)))
2729 (defun org-create-multibrace-regexp (left right n)
2730 "Create a regular expression which will match a balanced sexp.
2731 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2732 as single character strings.
2733 The regexp returned will match the entire expression including the
2734 delimiters. It will also define a single group which contains the
2735 match except for the outermost delimiters. The maximum depth of
2736 stacked delimiters is N. Escaping delimiters is not possible."
2737 (let* ((nothing (concat "[^" left right "]*?"))
2738 (or "\\|")
2739 (re nothing)
2740 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
2741 (while (> n 1)
2742 (setq n (1- n)
2743 re (concat re or next)
2744 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
2745 (concat left "\\(" re "\\)" right)))
2747 (defvar org-match-substring-regexp
2748 (concat
2749 "\\([^\\]\\)\\([_^]\\)\\("
2750 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2751 "\\|"
2752 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
2753 "\\|"
2754 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2755 "The regular expression matching a sub- or superscript.")
2757 (defvar org-match-substring-with-braces-regexp
2758 (concat
2759 "\\([^\\]\\)\\([_^]\\)\\("
2760 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2761 "\\)")
2762 "The regular expression matching a sub- or superscript, forcing braces.")
2765 (defun org-get-text-property-any (pos prop &optional object)
2766 (or (get-text-property pos prop object)
2767 (and (setq pos (next-single-property-change pos prop object))
2768 (get-text-property pos prop object))))
2770 (defun org-export-get-coderef-format (path desc)
2771 (save-match-data
2772 (if (and desc (string-match
2773 (regexp-quote (concat "(" path ")"))
2774 desc))
2775 (replace-match "%s" t t desc)
2776 (or desc "%s"))))
2778 (defun org-export-push-to-kill-ring (format)
2779 "Push buffer content to kill ring.
2780 The depends on the variable `org-export-copy-to-kill'."
2781 (when org-export-copy-to-kill-ring
2782 (org-kill-new (buffer-string))
2783 (when (fboundp 'x-set-selection)
2784 (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
2785 (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
2786 (message "%s export done, pushed to kill ring and clipboard" format)))
2788 (provide 'org-exp)
2790 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2792 ;;; org-exp.el ends here