Release 6.28e
[org-mode/org-tableheadings.git] / lisp / org-exp.el
blob36d1821512bd3b42f3b7815ecff10bbd6eabe9b9
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.28e
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 nil, 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")
646 (mapcar 'car org-export-inbuffer-options-extra))))
647 p key val text options a pr style
648 latex-header macros
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 "LINK_UP")
678 (setq p (plist-put p :link-up val)))
679 ((string-equal key "LINK_HOME")
680 (setq p (plist-put p :link-home val)))
681 ((string-equal key "EXPORT_SELECT_TAGS")
682 (setq p (plist-put p :select-tags (org-split-string val))))
683 ((string-equal key "EXPORT_EXCLUDE_TAGS")
684 (setq p (plist-put p :exclude-tags (org-split-string val))))
685 ((string-equal key "MACRO")
686 (push val macros))
687 ((equal key "SETUPFILE")
688 (setq setup-contents (org-file-contents
689 (expand-file-name
690 (org-remove-double-quotes
691 (org-trim val)))
692 'noerror))
693 (if (not ext-setup-or-nil)
694 (setq ext-setup-or-nil setup-contents start 0)
695 (setq ext-setup-or-nil
696 (concat (substring ext-setup-or-nil 0 start)
697 "\n" setup-contents "\n"
698 (substring ext-setup-or-nil start)))))))
699 (setq p (plist-put p :text text))
700 (when style (setq p (plist-put p :style-extra style)))
701 (when latex-header
702 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
703 (when options
704 (setq p (org-export-add-options-to-plist p options)))
705 ;; Add macro definitions
706 (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
707 (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
708 (setq p (plist-put
709 p :macro-modification-time
710 (and (buffer-file-name)
711 (file-exists-p (buffer-file-name))
712 (concat
713 "(eval (format-time-string \"$1\" '"
714 (prin1-to-string (nth 5 (file-attributes
715 (buffer-file-name))))
716 "))"))))
717 (setq p (plist-put p :macro-input-file (and (buffer-file-name)
718 (file-name-nondirectory
719 (buffer-file-name)))))
720 (while (setq val (pop macros))
721 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val)
722 (setq p (plist-put
723 p (intern
724 (concat ":macro-" (downcase (match-string 1 val))))
725 (match-string 2 val)))))
726 p))))
728 (defun org-export-add-options-to-plist (p options)
729 "Parse an OPTIONS line and set values in the property list P."
730 (let (o)
731 (when options
732 (let ((op org-export-plist-vars))
733 (while (setq o (pop op))
734 (if (and (nth 1 o)
735 (string-match (concat (regexp-quote (nth 1 o))
736 ":\\([^ \t\n\r;,.]*\\)")
737 options))
738 (setq p (plist-put p (car o)
739 (car (read-from-string
740 (match-string 1 options))))))))))
743 (defun org-export-add-subtree-options (p pos)
744 "Add options in subtree at position POS to property list P."
745 (save-excursion
746 (goto-char pos)
747 (when (org-at-heading-p)
748 (let (a)
749 ;; This is actually read in `org-export-get-title-from-subtree'
750 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
751 ;; (setq p (plist-put p :title a)))
752 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
753 (setq p (plist-put p :text a)))
754 (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
755 (setq p (plist-put p :author a)))
756 (when (setq a (org-entry-get pos "EXPORT_DATE"))
757 (setq p (plist-put p :date a)))
758 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
759 (setq p (org-export-add-options-to-plist p a)))))
762 (defun org-export-directory (type plist)
763 (let* ((val (plist-get plist :publishing-directory))
764 (dir (if (listp val)
765 (or (cdr (assoc type val)) ".")
766 val)))
767 dir))
769 (defun org-export-process-option-filters (plist)
770 (let ((functions org-export-options-filters) f)
771 (while (setq f (pop functions))
772 (setq plist (funcall f plist))))
773 plist)
775 ;;;###autoload
776 (defun org-export (&optional arg)
777 "Export dispatcher for Org-mode.
778 When `org-export-run-in-background' is non-nil, try to run the command
779 in the background. This will be done only for commands that write
780 to a file. For details see the docstring of `org-export-run-in-background'.
782 The prefix argument ARG will be passed to the exporter. However, if
783 ARG is a double universal prefix `C-u C-u', that means to inverse the
784 value of `org-export-run-in-background'."
785 (interactive "P")
786 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
787 (help "[t] insert the export option template
788 \[v] limit export to visible part of outline tree
790 \[a] export as ASCII [A] to temporary buffer
792 \[h] export as HTML [H] to temporary buffer [R] export region
793 \[b] export as HTML and open in browser
795 \[l] export as LaTeX [L] to temporary buffer
796 \[p] export as LaTeX and process to PDF
797 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
799 \[D] export as DocBook
800 \[V] export as DocBook, process to PDF, and open the resulting PDF document
802 \[x] export as XOXO
803 \[g] export using Wes Hardaker's generic exporter
805 \[i] export current file as iCalendar file
806 \[I] export all agenda files as iCalendar files
807 \[c] export agenda files into combined iCalendar file
809 \[F] publish current file [P] publish current project
810 \[X] publish a project... [E] publish every projects")
811 (cmds
812 '((?t org-insert-export-options-template nil)
813 (?v org-export-visible nil)
814 (?a org-export-as-ascii t)
815 (?A org-export-as-ascii-to-buffer t)
816 (?h org-export-as-html t)
817 (?b org-export-as-html-and-open t)
818 (?H org-export-as-html-to-buffer nil)
819 (?R org-export-region-as-html nil)
820 (?x org-export-as-xoxo t)
821 (?g org-export-generic t)
822 (?D org-export-as-docbook t)
823 (?V org-export-as-docbook-pdf-and-open t)
824 (?l org-export-as-latex t)
825 (?p org-export-as-pdf t)
826 (?d org-export-as-pdf-and-open t)
827 (?L org-export-as-latex-to-buffer nil)
828 (?i org-export-icalendar-this-file t)
829 (?I org-export-icalendar-all-agenda-files t)
830 (?c org-export-icalendar-combine-agenda-files t)
831 (?F org-publish-current-file t)
832 (?P org-publish-current-project t)
833 (?X org-publish t)
834 (?E org-publish-all t)))
835 r1 r2 ass)
836 (save-excursion
837 (save-window-excursion
838 (delete-other-windows)
839 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
840 (princ help))
841 (org-fit-window-to-buffer (get-buffer-window
842 "*Org Export/Publishing Help*"))
843 (message "Select command: ")
844 (setq r1 (read-char-exclusive))))
845 (setq r2 (if (< r1 27) (+ r1 96) r1))
846 (unless (setq ass (assq r2 cmds))
847 (error "No command associated with key %c" r1))
848 (if (and bg (nth 2 ass)
849 (not (buffer-base-buffer))
850 (not (org-region-active-p)))
851 ;; execute in background
852 (let ((p (start-process
853 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
854 "*Org Processes*"
855 (expand-file-name invocation-name invocation-directory)
856 "-batch"
857 "-l" user-init-file
858 "--eval" "(require 'org-exp)"
859 "--eval" "(setq org-wait .2)"
860 (buffer-file-name)
861 "-f" (symbol-name (nth 1 ass)))))
862 (set-process-sentinel p 'org-export-process-sentinel)
863 (message "Background process \"%s\": started" p))
864 ;; background processing not requested, or not possible
865 (call-interactively (nth 1 ass)))))
867 (defun org-export-process-sentinel (process status)
868 (if (string-match "\n+\\'" status)
869 (setq status (substring status 0 -1)))
870 (message "Background process \"%s\": %s" process status))
872 (defconst org-html-entities
873 '(("nbsp")
874 ("iexcl")
875 ("cent")
876 ("pound")
877 ("curren")
878 ("yen")
879 ("brvbar")
880 ("vert" . "&#124;")
881 ("sect")
882 ("uml")
883 ("copy")
884 ("ordf")
885 ("laquo")
886 ("not")
887 ("shy")
888 ("reg")
889 ("macr")
890 ("deg")
891 ("pm" . "&plusmn;")
892 ("plusmn")
893 ("sup2")
894 ("sup3")
895 ("acute")
896 ("micro")
897 ("para")
898 ("middot")
899 ("odot"."o")
900 ("star"."*")
901 ("cedil")
902 ("sup1")
903 ("ordm")
904 ("raquo")
905 ("frac14")
906 ("frac12")
907 ("frac34")
908 ("iquest")
909 ("Agrave")
910 ("Aacute")
911 ("Acirc")
912 ("Atilde")
913 ("Auml")
914 ("Aring") ("AA"."&Aring;")
915 ("AElig")
916 ("Ccedil")
917 ("Egrave")
918 ("Eacute")
919 ("Ecirc")
920 ("Euml")
921 ("Igrave")
922 ("Iacute")
923 ("Icirc")
924 ("Iuml")
925 ("ETH")
926 ("Ntilde")
927 ("Ograve")
928 ("Oacute")
929 ("Ocirc")
930 ("Otilde")
931 ("Ouml")
932 ("times")
933 ("Oslash")
934 ("Ugrave")
935 ("Uacute")
936 ("Ucirc")
937 ("Uuml")
938 ("Yacute")
939 ("THORN")
940 ("szlig")
941 ("agrave")
942 ("aacute")
943 ("acirc")
944 ("atilde")
945 ("auml")
946 ("aring")
947 ("aelig")
948 ("ccedil")
949 ("egrave")
950 ("eacute")
951 ("ecirc")
952 ("euml")
953 ("igrave")
954 ("iacute")
955 ("icirc")
956 ("iuml")
957 ("eth")
958 ("ntilde")
959 ("ograve")
960 ("oacute")
961 ("ocirc")
962 ("otilde")
963 ("ouml")
964 ("divide")
965 ("oslash")
966 ("ugrave")
967 ("uacute")
968 ("ucirc")
969 ("uuml")
970 ("yacute")
971 ("thorn")
972 ("yuml")
973 ("fnof")
974 ("Alpha")
975 ("Beta")
976 ("Gamma")
977 ("Delta")
978 ("Epsilon")
979 ("Zeta")
980 ("Eta")
981 ("Theta")
982 ("Iota")
983 ("Kappa")
984 ("Lambda")
985 ("Mu")
986 ("Nu")
987 ("Xi")
988 ("Omicron")
989 ("Pi")
990 ("Rho")
991 ("Sigma")
992 ("Tau")
993 ("Upsilon")
994 ("Phi")
995 ("Chi")
996 ("Psi")
997 ("Omega")
998 ("alpha")
999 ("beta")
1000 ("gamma")
1001 ("delta")
1002 ("epsilon")
1003 ("varepsilon"."&epsilon;")
1004 ("zeta")
1005 ("eta")
1006 ("theta")
1007 ("iota")
1008 ("kappa")
1009 ("lambda")
1010 ("mu")
1011 ("nu")
1012 ("xi")
1013 ("omicron")
1014 ("pi")
1015 ("rho")
1016 ("sigmaf") ("varsigma"."&sigmaf;")
1017 ("sigma")
1018 ("tau")
1019 ("upsilon")
1020 ("phi")
1021 ("chi")
1022 ("psi")
1023 ("omega")
1024 ("thetasym") ("vartheta"."&thetasym;")
1025 ("upsih")
1026 ("piv")
1027 ("bull") ("bullet"."&bull;")
1028 ("hellip") ("dots"."&hellip;")
1029 ("prime")
1030 ("Prime")
1031 ("oline")
1032 ("frasl")
1033 ("weierp")
1034 ("image")
1035 ("real")
1036 ("trade")
1037 ("alefsym")
1038 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1039 ("uarr") ("uparrow"."&uarr;")
1040 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1041 ("darr")("downarrow"."&darr;")
1042 ("harr") ("leftrightarrow"."&harr;")
1043 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1044 ("lArr") ("Leftarrow"."&lArr;")
1045 ("uArr") ("Uparrow"."&uArr;")
1046 ("rArr") ("Rightarrow"."&rArr;")
1047 ("dArr") ("Downarrow"."&dArr;")
1048 ("hArr") ("Leftrightarrow"."&hArr;")
1049 ("forall")
1050 ("part") ("partial"."&part;")
1051 ("exist") ("exists"."&exist;")
1052 ("empty") ("emptyset"."&empty;")
1053 ("nabla")
1054 ("isin") ("in"."&isin;")
1055 ("notin")
1056 ("ni")
1057 ("prod")
1058 ("sum")
1059 ("minus")
1060 ("lowast") ("ast"."&lowast;")
1061 ("radic")
1062 ("prop") ("proptp"."&prop;")
1063 ("infin") ("infty"."&infin;")
1064 ("ang") ("angle"."&ang;")
1065 ("and") ("wedge"."&and;")
1066 ("or") ("vee"."&or;")
1067 ("cap")
1068 ("cup")
1069 ("int")
1070 ("there4")
1071 ("sim")
1072 ("cong") ("simeq"."&cong;")
1073 ("asymp")("approx"."&asymp;")
1074 ("ne") ("neq"."&ne;")
1075 ("equiv")
1076 ("le")
1077 ("ge")
1078 ("sub") ("subset"."&sub;")
1079 ("sup") ("supset"."&sup;")
1080 ("nsub")
1081 ("sube")
1082 ("supe")
1083 ("oplus")
1084 ("otimes")
1085 ("perp")
1086 ("sdot") ("cdot"."&sdot;")
1087 ("lceil")
1088 ("rceil")
1089 ("lfloor")
1090 ("rfloor")
1091 ("lang")
1092 ("rang")
1093 ("loz") ("Diamond"."&loz;")
1094 ("spades") ("spadesuit"."&spades;")
1095 ("clubs") ("clubsuit"."&clubs;")
1096 ("hearts") ("diamondsuit"."&hearts;")
1097 ("diams") ("diamondsuit"."&diams;")
1098 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1099 ("quot")
1100 ("amp")
1101 ("lt")
1102 ("gt")
1103 ("OElig")
1104 ("oelig")
1105 ("Scaron")
1106 ("scaron")
1107 ("Yuml")
1108 ("circ")
1109 ("tilde")
1110 ("ensp")
1111 ("emsp")
1112 ("thinsp")
1113 ("zwnj")
1114 ("zwj")
1115 ("lrm")
1116 ("rlm")
1117 ("ndash")
1118 ("mdash")
1119 ("lsquo")
1120 ("rsquo")
1121 ("sbquo")
1122 ("ldquo")
1123 ("rdquo")
1124 ("bdquo")
1125 ("dagger")
1126 ("Dagger")
1127 ("permil")
1128 ("lsaquo")
1129 ("rsaquo")
1130 ("euro")
1132 ("arccos"."arccos")
1133 ("arcsin"."arcsin")
1134 ("arctan"."arctan")
1135 ("arg"."arg")
1136 ("cos"."cos")
1137 ("cosh"."cosh")
1138 ("cot"."cot")
1139 ("coth"."coth")
1140 ("csc"."csc")
1141 ("deg"."deg")
1142 ("det"."det")
1143 ("dim"."dim")
1144 ("exp"."exp")
1145 ("gcd"."gcd")
1146 ("hom"."hom")
1147 ("inf"."inf")
1148 ("ker"."ker")
1149 ("lg"."lg")
1150 ("lim"."lim")
1151 ("liminf"."liminf")
1152 ("limsup"."limsup")
1153 ("ln"."ln")
1154 ("log"."log")
1155 ("max"."max")
1156 ("min"."min")
1157 ("Pr"."Pr")
1158 ("sec"."sec")
1159 ("sin"."sin")
1160 ("sinh"."sinh")
1161 ("sup"."sup")
1162 ("tan"."tan")
1163 ("tanh"."tanh")
1165 "Entities for TeX->HTML translation.
1166 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1167 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1168 In that case, \"\\ent\" will be translated to \"&other;\".
1169 The list contains HTML entities for Latin-1, Greek and other symbols.
1170 It is supplemented by a number of commonly used TeX macros with appropriate
1171 translations. There is currently no way for users to extend this.")
1173 ;;; General functions for all backends
1175 (defvar org-export-target-aliases nil
1176 "Alist of targets with invisible aliases.")
1177 (defvar org-export-preferred-target-alist nil
1178 "Alist of section id's with preferred aliases.")
1179 (defvar org-export-code-refs nil
1180 "Alist of code references and line numbers")
1182 (defun org-export-preprocess-string (string &rest parameters)
1183 "Cleanup STRING so that that the true exported has a more consistent source.
1184 This function takes STRING, which should be a buffer-string of an org-file
1185 to export. It then creates a temporary buffer where it does its job.
1186 The result is then again returned as a string, and the exporter works
1187 on this string to produce the exported version."
1188 (interactive)
1189 (let* ((htmlp (plist-get parameters :for-html))
1190 (asciip (plist-get parameters :for-ascii))
1191 (latexp (plist-get parameters :for-LaTeX))
1192 (docbookp (plist-get parameters :for-docbook))
1193 (backend (cond (htmlp 'html)
1194 (latexp 'latex)
1195 (asciip 'ascii)
1196 (docbookp 'docbook)))
1197 (archived-trees (plist-get parameters :archived-trees))
1198 (inhibit-read-only t)
1199 (drawers org-drawers)
1200 (outline-regexp "\\*+ ")
1201 target-alist rtn)
1203 (setq org-export-target-aliases nil)
1204 (setq org-export-preferred-target-alist nil)
1205 (setq org-export-code-refs nil)
1207 (with-current-buffer (get-buffer-create " org-mode-tmp")
1208 (erase-buffer)
1209 (insert string)
1210 (setq case-fold-search t)
1212 ;; Remove license-to-kill stuff
1213 ;; The caller marks some stuff for killing, stuff that has been
1214 ;; used to create the page title, for example.
1215 (org-export-kill-licensed-text)
1217 (let ((org-inhibit-startup t)) (org-mode))
1218 (setq case-fold-search t)
1220 ;; Call the hook
1221 (run-hooks 'org-export-preprocess-hook)
1223 ;; Process the macros
1224 (org-export-preprocess-apply-macros)
1225 (run-hooks 'org-export-preprocess-after-macros-hook)
1227 (untabify (point-min) (point-max))
1229 ;; Handle include files, and call a hook
1230 (org-export-handle-include-files)
1231 (run-hooks 'org-export-preprocess-after-include-files-hook)
1233 ;; Get rid of archived trees
1234 (org-export-remove-archived-trees archived-trees)
1236 ;; Remove comment environment and comment subtrees
1237 (org-export-remove-comment-blocks-and-subtrees)
1239 ;; Get rid of excluded trees, and call a hook
1240 (org-export-handle-export-tags (plist-get parameters :select-tags)
1241 (plist-get parameters :exclude-tags))
1242 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1244 ;; Handle source code snippets
1245 (org-export-replace-src-segments-and-examples backend)
1247 ;; Protect short examples marked by a leading colon
1248 (org-export-protect-colon-examples)
1250 ;; Normalize footnotes
1251 (when (plist-get parameters :footnotes)
1252 (org-footnote-normalize nil t))
1254 ;; Find all headings and compute the targets for them
1255 (setq target-alist (org-export-define-heading-targets target-alist))
1257 ;; Get rid of drawers
1258 (org-export-remove-or-extract-drawers drawers
1259 (plist-get parameters :drawers))
1261 ;; Get the correct stuff before the first headline
1262 (when (plist-get parameters :skip-before-1st-heading)
1263 (goto-char (point-min))
1264 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1265 (delete-region (point-min) (match-beginning 0))
1266 (goto-char (point-min))
1267 (insert "\n")))
1268 (when (plist-get parameters :add-text)
1269 (goto-char (point-min))
1270 (insert (plist-get parameters :add-text) "\n"))
1272 ;; Remove todo-keywords before exporting, if the user has requested so
1273 (org-export-remove-headline-metadata parameters)
1275 ;; Find targets in comments and move them out of comments,
1276 ;; but mark them as targets that should be invisible
1277 (setq target-alist (org-export-handle-invisible-targets target-alist))
1279 ;; Select and protect backend specific stuff, throw away stuff
1280 ;; that is specific for other backends
1281 (org-export-select-backend-specific-text backend)
1283 ;; Protect quoted subtrees
1284 (org-export-protect-quoted-subtrees)
1286 ;; Remove clock lines
1287 (org-export-remove-clock-lines)
1289 ;; Protect verbatim elements
1290 (org-export-protect-verbatim)
1292 ;; Blockquotes, verse, and center
1293 (org-export-mark-blockquote-verse-center)
1294 (run-hooks 'org-export-preprocess-after-blockquote-hook)
1296 ;; Remove timestamps, if the user has requested so
1297 (unless (plist-get parameters :timestamps)
1298 (org-export-remove-timestamps))
1300 ;; Attach captions to the correct object
1301 (setq target-alist (org-export-attach-captions-and-attributes
1302 backend target-alist))
1304 ;; Find matches for radio targets and turn them into internal links
1305 (org-export-mark-radio-links)
1307 ;; Find all links that contain a newline and put them into a single line
1308 (org-export-concatenate-multiline-links)
1310 ;; Normalize links: Convert angle and plain links into bracket links
1311 ;; and expand link abbreviations
1312 (org-export-normalize-links)
1314 ;; Find all internal links. If they have a fuzzy match (i.e. not
1315 ;; a *dedicated* target match, let the link point to the
1316 ;; corresponding section.
1317 (org-export-target-internal-links target-alist)
1319 ;; Find multiline emphasis and put them into single line
1320 (when (plist-get parameters :emph-multiline)
1321 (org-export-concatenate-multiline-emphasis))
1323 ;; Remove special table lines
1324 (when org-export-table-remove-special-lines
1325 (org-export-remove-special-table-lines))
1327 ;; Another hook
1328 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1330 ;; LaTeX-specific preprocessing
1331 (when latexp
1332 (require 'org-latex nil)
1333 (org-export-latex-preprocess parameters))
1335 ;; ASCII-specific preprocessing
1336 (when asciip
1337 (org-export-ascii-preprocess parameters))
1339 ;; HTML-specific preprocessing
1340 (when htmlp
1341 (org-export-html-preprocess parameters))
1343 ;; DocBook-specific preprocessing
1344 (when docbookp
1345 (require 'org-docbook nil)
1346 (org-export-docbook-preprocess parameters))
1348 ;; Remove or replace comments
1349 (org-export-handle-comments (plist-get parameters :comments))
1351 ;; Run the final hook
1352 (run-hooks 'org-export-preprocess-final-hook)
1354 (setq rtn (buffer-string)))
1355 (kill-buffer " org-mode-tmp")
1356 rtn))
1358 (defun org-export-kill-licensed-text ()
1359 "Remove all text that is marked with a :org-license-to-kill property."
1360 (let (p)
1361 (while (setq p (text-property-any (point-min) (point-max)
1362 :org-license-to-kill t))
1363 (delete-region
1364 p (or (next-single-property-change p :org-license-to-kill)
1365 (point-max))))))
1367 (defun org-export-define-heading-targets (target-alist)
1368 "Find all headings and define the targets for them.
1369 The new targets are added to TARGET-ALIST, which is also returned."
1370 (goto-char (point-min))
1371 (org-init-section-numbers)
1372 (let ((re (concat "^" org-outline-regexp
1373 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1374 level target last-section-target a id)
1375 (while (re-search-forward re nil t)
1376 (if (match-end 2)
1377 (progn
1378 (setq id (org-match-string-no-properties 2))
1379 (push (cons id target) target-alist)
1380 (setq a (or (assoc last-section-target org-export-target-aliases)
1381 (progn
1382 (push (list last-section-target)
1383 org-export-target-aliases)
1384 (car org-export-target-aliases))))
1385 (push (caar target-alist) (cdr a))
1386 (when (equal (match-string 1) "CUSTOM_ID")
1387 (if (not (assoc last-section-target
1388 org-export-preferred-target-alist))
1389 (push (cons last-section-target id)
1390 org-export-preferred-target-alist))))
1391 (setq level (org-reduced-level
1392 (save-excursion (goto-char (point-at-bol))
1393 (org-outline-level))))
1394 (setq target (org-solidify-link-text
1395 (format "sec-%s" (org-section-number level))))
1396 (setq last-section-target target)
1397 (push (cons target target) target-alist)
1398 (add-text-properties
1399 (point-at-bol) (point-at-eol)
1400 (list 'target target)))))
1401 target-alist)
1403 (defun org-export-handle-invisible-targets (target-alist)
1404 "Find targets in comments and move them out of comments.
1405 Mark them as invisible targets."
1406 (let (target tmp a)
1407 (goto-char (point-min))
1408 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1409 ;; Check if the line before or after is a headline with a target
1410 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1411 (get-text-property (point-at-bol 2) 'target)))
1412 (progn
1413 ;; use the existing target in a neighboring line
1414 (setq tmp (match-string 2))
1415 (replace-match "")
1416 (and (looking-at "\n") (delete-char 1))
1417 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1418 target-alist)
1419 (setq a (or (assoc target org-export-target-aliases)
1420 (progn
1421 (push (list target) org-export-target-aliases)
1422 (car org-export-target-aliases))))
1423 (push tmp (cdr a)))
1424 ;; Make an invisible target
1425 (replace-match "\\1(INVISIBLE)"))))
1426 target-alist)
1428 (defun org-export-target-internal-links (target-alist)
1429 "Find all internal links and assign targets to them.
1430 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1431 let the link point to the corresponding section.
1432 This function also handles the id links, if they have a match in
1433 the current file."
1434 (goto-char (point-min))
1435 (while (re-search-forward org-bracket-link-regexp nil t)
1436 (org-if-unprotected
1437 (let* ((md (match-data))
1438 (desc (match-end 2))
1439 (link (org-link-unescape (match-string 1)))
1440 (slink (org-solidify-link-text link))
1441 found props pos cref
1442 (target
1443 (cond
1444 ((= (string-to-char link) ?#)
1445 ;; user wants exactly this link
1446 link)
1447 ((cdr (assoc slink target-alist))
1448 (or (cdr (assoc (assoc slink target-alist)
1449 org-export-preferred-target-alist))
1450 (cdr (assoc slink target-alist))))
1451 ((and (string-match "^id:" link)
1452 (cdr (assoc (substring link 3) target-alist))))
1453 ((string-match "^(\\(.*\\))$" link)
1454 (setq cref (match-string 1 link))
1455 (concat "coderef:" cref))
1456 ((string-match org-link-types-re link) nil)
1457 ((or (file-name-absolute-p link)
1458 (string-match "^\\." link))
1459 nil)
1461 (save-excursion
1462 (setq found (condition-case nil (org-link-search link)
1463 (error nil)))
1464 (when (and found
1465 (or (org-on-heading-p)
1466 (not (eq found 'dedicated))))
1467 (or (get-text-property (point) 'target)
1468 (get-text-property
1469 (max (point-min)
1470 (1- (or (previous-single-property-change
1471 (point) 'target) 0)))
1472 'target))))))))
1473 (when target
1474 (set-match-data md)
1475 (goto-char (match-beginning 1))
1476 (setq props (text-properties-at (point)))
1477 (delete-region (match-beginning 1) (match-end 1))
1478 (setq pos (point))
1479 (insert target)
1480 (unless desc (insert "][" link))
1481 (add-text-properties pos (point) props))))))
1483 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1484 "Remove drawers, or extract the content.
1485 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1486 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1487 whose content to keep."
1488 (unless (eq t exp-drawers)
1489 (goto-char (point-min))
1490 (let ((re (concat "^[ \t]*:\\("
1491 (mapconcat
1492 'identity
1493 (org-delete-all exp-drawers
1494 (copy-sequence all-drawers))
1495 "\\|")
1496 "\\):[ \t]*$"))
1497 beg eol)
1498 (while (re-search-forward re nil t)
1499 (org-if-unprotected
1500 (setq beg (match-beginning 0)
1501 eol (match-end 0))
1502 (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
1503 nil t)
1504 (if (match-end 1)
1505 ;; terminated in this entry
1506 (progn
1507 (delete-region beg (match-end 1))
1508 (goto-char beg))
1509 (goto-char eol))))))))
1511 (defun org-export-handle-export-tags (select-tags exclude-tags)
1512 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1513 Both arguments are lists of tags.
1514 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1515 will be removed.
1516 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1517 removed as well."
1518 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1519 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1520 select-tags "\\|")
1521 "\\):"))
1522 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1523 exclude-tags "\\|")
1524 "\\):"))
1525 beg end cont)
1526 (goto-char (point-min))
1527 (when (and select-tags
1528 (re-search-forward
1529 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1530 ;; At least one tree is marked for export, this means
1531 ;; all the unmarked stuff needs to go.
1532 ;; Dig out the trees that should be exported
1533 (goto-char (point-min))
1534 (outline-next-heading)
1535 (setq beg (point))
1536 (put-text-property beg (point-max) :org-delete t)
1537 (while (re-search-forward re-sel nil t)
1538 (when (org-on-heading-p)
1539 (org-back-to-heading)
1540 (remove-text-properties
1541 (max (1- (point)) (point-min))
1542 (setq cont (save-excursion (org-end-of-subtree t t)))
1543 '(:org-delete t))
1544 (while (and (org-up-heading-safe)
1545 (get-text-property (point) :org-delete))
1546 (remove-text-properties (max (1- (point)) (point-min))
1547 (point-at-eol) '(:org-delete t)))
1548 (goto-char cont))))
1549 ;; Remove the trees explicitly marked for noexport
1550 (when exclude-tags
1551 (goto-char (point-min))
1552 (while (re-search-forward re-excl nil t)
1553 (when (org-at-heading-p)
1554 (org-back-to-heading t)
1555 (setq beg (point))
1556 (org-end-of-subtree t)
1557 (delete-region beg (point)))))
1558 ;; Remove everything that is now still marked for deletion
1559 (goto-char (point-min))
1560 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1561 (setq end (or (next-single-property-change beg :org-delete)
1562 (point-max)))
1563 (delete-region beg end))))
1565 (defun org-export-remove-archived-trees (export-archived-trees)
1566 "Remove archived trees.
1567 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1568 When it is t, the entire archived tree will be exported.
1569 When it is nil the entire tree including the headline will be removed
1570 from the buffer."
1571 (let ((re-archive (concat ":" org-archive-tag ":"))
1572 a b)
1573 (when (not (eq export-archived-trees t))
1574 (goto-char (point-min))
1575 (while (re-search-forward re-archive nil t)
1576 (if (not (org-on-heading-p t))
1577 (org-end-of-subtree t)
1578 (beginning-of-line 1)
1579 (setq a (if export-archived-trees
1580 (1+ (point-at-eol)) (point))
1581 b (org-end-of-subtree t))
1582 (if (> b a) (delete-region a b)))))))
1584 (defun org-export-remove-headline-metadata (opts)
1585 "Remove meta data from the headline, according to user options."
1586 (let ((re org-complex-heading-regexp)
1587 (todo (plist-get opts :todo-keywords))
1588 (tags (plist-get opts :tags))
1589 (pri (plist-get opts :priority))
1590 (elts '(1 2 3 4 5))
1591 rpl)
1592 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1593 (when (or (not todo) (not tags) (not pri))
1594 (goto-char (point-min))
1595 (while (re-search-forward re nil t)
1596 (org-if-unprotected
1597 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1598 elts " "))
1599 (replace-match rpl t t))))))
1601 (defun org-export-remove-timestamps ()
1602 "Remove timestamps and keywords for export."
1603 (goto-char (point-min))
1604 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1605 (backward-char 1)
1606 (org-if-unprotected
1607 (unless (save-match-data (org-at-table-p))
1608 (replace-match "")
1609 (beginning-of-line 1)
1610 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1611 (replace-match ""))))))
1613 (defun org-export-remove-clock-lines ()
1614 "Remove clock lines for export."
1615 (goto-char (point-min))
1616 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1617 (while (re-search-forward re nil t)
1618 (org-if-unprotected
1619 (replace-match "")))))
1621 (defun org-export-protect-quoted-subtrees ()
1622 "Mark quoted subtrees with the protection property."
1623 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1624 (goto-char (point-min))
1625 (while (re-search-forward re-quote nil t)
1626 (goto-char (match-beginning 0))
1627 (end-of-line 1)
1628 (add-text-properties (point) (org-end-of-subtree t)
1629 '(org-protected t)))))
1631 (defun org-export-protect-verbatim ()
1632 "Mark verbatim snippets with the protection property."
1633 (goto-char (point-min))
1634 (while (re-search-forward org-verbatim-re nil t)
1635 (add-text-properties (match-beginning 4) (match-end 4)
1636 '(org-protected t))
1637 (goto-char (1+ (match-end 4)))))
1639 (defun org-export-protect-colon-examples ()
1640 "Protect lines starting with a colon."
1641 (goto-char (point-min))
1642 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1643 (while (re-search-forward re nil t)
1644 (beginning-of-line 1)
1645 (setq beg (point))
1646 (while (looking-at re)
1647 (end-of-line 1)
1648 (or (eobp) (forward-char 1)))
1649 (add-text-properties beg (if (bolp) (1- (point)) (point))
1650 '(org-protected t)))))
1652 (defun org-export-select-backend-specific-text (backend)
1653 (let ((formatters
1654 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1655 (html "HTML" "BEGIN_HTML" "END_HTML")
1656 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1657 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1658 (case-fold-search t)
1659 fmt)
1661 (while formatters
1662 (setq fmt (pop formatters))
1663 (when (eq (car fmt) backend)
1664 ;; This is selected code, put it into the file for real
1665 (goto-char (point-min))
1666 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
1667 ":[ \t]*\\(.*\\)") nil t)
1668 (replace-match "\\1\\2" t)
1669 (add-text-properties
1670 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1671 '(org-protected t))))
1672 (goto-char (point-min))
1673 (while (re-search-forward
1674 (concat "^[ \t]*#\\+" (caddr fmt)
1675 "\\>.*\\(\\(\n.*\\)*?\n\\)[ \t]*#\\+" (cadddr fmt)
1676 "\\>.*\n?") nil t)
1677 (if (eq (car fmt) backend)
1678 ;; yes, keep this
1679 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1680 '(org-protected t))
1681 ;; No, this is for a different backend, kill it
1682 (delete-region (match-beginning 0) (match-end 0)))))))
1684 (defun org-export-mark-blockquote-verse-center ()
1685 "Mark block quote and verse environments with special cookies.
1686 These special cookies will later be interpreted by the backend."
1687 ;; Blockquotes
1688 (let (type t1 ind beg end beg1 end1 content)
1689 (goto-char (point-min))
1690 (while (re-search-forward
1691 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1692 nil t)
1693 (setq ind (length (match-string 1))
1694 type (downcase (match-string 3))
1695 t1 (if (equal type "quote") "blockquote" type))
1696 (setq beg (match-beginning 0)
1697 beg1 (1+ (match-end 0)))
1698 (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
1699 (setq end (1+ (point-at-eol))
1700 end1 (1- (match-beginning 0)))
1701 (setq content (org-remove-indentation (buffer-substring beg1 end1)))
1702 (setq content (concat "ORG-" (upcase t1) "-START\n"
1703 content "\n"
1704 "ORG-" (upcase t1) "-END\n"))
1705 (delete-region beg end)
1706 (insert (org-add-props content nil 'original-indentation ind))))))
1708 (defun org-export-attach-captions-and-attributes (backend target-alist)
1709 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1710 If the next thing following is a table, add the text properties to the first
1711 table line. If it is a link, add it to the line containing the link."
1712 (goto-char (point-min))
1713 (remove-text-properties (point-min) (point-max)
1714 '(org-caption nil org-attributes nil))
1715 (let ((case-fold-search t)
1716 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1717 "\\|"
1718 "^[ \t]*#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
1719 "\\|"
1720 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1721 "\\|"
1722 "^[ \t]*|[^-]"
1723 "\\|"
1724 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1725 cap attr label)
1726 (while (re-search-forward re nil t)
1727 (cond
1728 ((match-end 1)
1729 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
1730 ((match-end 2)
1731 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
1732 ((match-end 3)
1733 (setq label (org-trim (match-string 3))))
1735 (add-text-properties (point-at-bol) (point-at-eol)
1736 (list 'org-caption cap
1737 'org-attributes attr
1738 'org-label label))
1739 (if label (push (cons label label) target-alist))
1740 (setq cap nil attr nil label nil)))))
1741 target-alist)
1743 (defun org-export-remove-comment-blocks-and-subtrees ()
1744 "Remove the comment environment, and also commented subtrees."
1745 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1746 (case-fold-search nil))
1747 ;; Remove comment environment
1748 (goto-char (point-min))
1749 (while (re-search-forward
1750 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1751 (replace-match "" t t))
1752 ;; Remove subtrees that are commented
1753 (goto-char (point-min))
1754 (while (re-search-forward re-commented nil t)
1755 (goto-char (match-beginning 0))
1756 (delete-region (point) (org-end-of-subtree t)))))
1758 (defun org-export-handle-comments (commentsp)
1759 "Remove comments, or convert to backend-specific format.
1760 COMMENTSP can be a format string for publishing comments.
1761 When it is nil, all comments will be removed."
1762 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1763 pos)
1764 (goto-char (point-min))
1765 (while (or (looking-at re)
1766 (re-search-forward re nil t))
1767 (setq pos (match-beginning 0))
1768 (if (and commentsp
1769 (not (equal (char-before (match-end 1)) ?+)))
1770 (progn (add-text-properties
1771 (match-beginning 0) (match-end 0) '(org-protected t))
1772 (replace-match (format commentsp (match-string 2)) t t))
1773 (goto-char (1+ pos))
1774 (org-if-unprotected
1775 (replace-match "")
1776 (goto-char (max (point-min) (1- pos))))))))
1778 (defun org-export-mark-radio-links ()
1779 "Find all matches for radio targets and turn them into internal links."
1780 (let ((re-radio (and org-target-link-regexp
1781 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1782 (goto-char (point-min))
1783 (when re-radio
1784 (while (re-search-forward re-radio nil t)
1785 (org-if-unprotected
1786 (replace-match "\\1[[\\2]]"))))))
1788 (defun org-export-remove-special-table-lines ()
1789 "Remove tables lines that are used for internal purposes."
1790 (goto-char (point-min))
1791 (while (re-search-forward "^[ \t]*|" nil t)
1792 (beginning-of-line 1)
1793 (if (or (looking-at "[ \t]*| *[!_^] *|")
1794 (and (looking-at ".*?| *<[0-9]+> *|")
1795 (not (looking-at ".*?| *[^ <|]"))))
1796 (delete-region (max (point-min) (1- (point-at-bol)))
1797 (point-at-eol))
1798 (end-of-line 1))))
1800 (defun org-export-normalize-links ()
1801 "Convert all links to bracket links, and expand link abbreviations."
1802 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1803 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
1804 nodesc)
1805 (goto-char (point-min))
1806 (while (re-search-forward re-plain-link nil t)
1807 (goto-char (1- (match-end 0)))
1808 (org-if-unprotected-at (1+ (match-beginning 0))
1809 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1810 ":" (match-string 3) "]]")))
1811 ;; added 'org-link face to links
1812 (put-text-property 0 (length s) 'face 'org-link s)
1813 (replace-match s t t))))
1814 (goto-char (point-min))
1815 (while (re-search-forward re-angle-link nil t)
1816 (goto-char (1- (match-end 0)))
1817 (org-if-unprotected
1818 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1819 ":" (match-string 3) "]]")))
1820 (put-text-property 0 (length s) 'face 'org-link s)
1821 (replace-match s t t))))
1822 (goto-char (point-min))
1823 (while (re-search-forward org-bracket-link-regexp nil t)
1824 (goto-char (1- (match-end 0)))
1825 (setq nodesc (not (match-end 3)))
1826 (org-if-unprotected
1827 (let* ((xx (save-match-data
1828 (org-translate-link
1829 (org-link-expand-abbrev (match-string 1)))))
1830 (s (concat
1831 "[[" (org-add-props (copy-sequence xx)
1832 nil 'org-protected t 'org-no-description nodesc)
1834 (if (match-end 3)
1835 (match-string 2)
1836 (concat "[" (copy-sequence xx)
1837 "]"))
1838 "]")))
1839 (put-text-property 0 (length s) 'face 'org-link s)
1840 (replace-match s t t))))))
1842 (defun org-export-concatenate-multiline-links ()
1843 "Find multi-line links and put it all into a single line.
1844 This is to make sure that the line-processing export backends
1845 can work correctly."
1846 (goto-char (point-min))
1847 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
1848 (org-if-unprotected
1849 (replace-match "\\1 \\3")
1850 (goto-char (match-beginning 0)))))
1852 (defun org-export-concatenate-multiline-emphasis ()
1853 "Find multi-line emphasis and put it all into a single line.
1854 This is to make sure that the line-processing export backends
1855 can work correctly."
1856 (goto-char (point-min))
1857 (while (re-search-forward org-emph-re nil t)
1858 (if (and (not (= (char-after (match-beginning 3))
1859 (char-after (match-beginning 4))))
1860 (save-excursion (goto-char (match-beginning 0))
1861 (save-match-data (not (org-at-table-p)))))
1862 (org-if-unprotected
1863 (subst-char-in-region (match-beginning 0) (match-end 0)
1864 ?\n ?\ t)
1865 (goto-char (1- (match-end 0))))
1866 (goto-char (1+ (match-beginning 0))))))
1868 (defun org-export-grab-title-from-buffer ()
1869 "Get a title for the current document, from looking at the buffer."
1870 (let ((inhibit-read-only t))
1871 (save-excursion
1872 (goto-char (point-min))
1873 (let ((end (if (looking-at org-outline-regexp)
1874 (point)
1875 (save-excursion (outline-next-heading) (point)))))
1876 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
1877 ;; Mark the line so that it will not be exported as normal text.
1878 (org-unmodified
1879 (add-text-properties (match-beginning 0) (match-end 0)
1880 (list :org-license-to-kill t)))
1881 ;; Return the title string
1882 (org-trim (match-string 0)))))))
1884 (defun org-export-get-title-from-subtree ()
1885 "Return subtree title and exclude it from export."
1886 (let (title (rbeg (region-beginning)) (rend (region-end)))
1887 (save-excursion
1888 (goto-char rbeg)
1889 (when (and (org-at-heading-p)
1890 (>= (org-end-of-subtree t t) rend))
1891 ;; This is a subtree, we take the title from the first heading
1892 (goto-char rbeg)
1893 (looking-at org-todo-line-regexp)
1894 (setq title (match-string 3))
1895 (org-unmodified
1896 (add-text-properties (point) (1+ (point-at-eol))
1897 (list :org-license-to-kill t)))
1898 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
1899 title))
1901 (defun org-solidify-link-text (s &optional alist)
1902 "Take link text and make a safe target out of it."
1903 (save-match-data
1904 (let* ((rtn
1905 (mapconcat
1906 'identity
1907 (org-split-string s "[ \t\r\n]+") "=="))
1908 (a (assoc rtn alist)))
1909 (or (cdr a) rtn))))
1911 (defun org-get-min-level (lines &optional offset)
1912 "Get the minimum level in LINES."
1913 (let ((re "^\\(\\*+\\) ") l)
1914 (catch 'exit
1915 (while (setq l (pop lines))
1916 (if (string-match re l)
1917 (throw 'exit (org-tr-level (- (length (match-string 1 l))
1918 (or offset 0))))))
1919 1)))
1921 ;; Variable holding the vector with section numbers
1922 (defvar org-section-numbers (make-vector org-level-max 0))
1924 (defun org-init-section-numbers ()
1925 "Initialize the vector for the section numbers."
1926 (let* ((level -1)
1927 (numbers (nreverse (org-split-string "" "\\.")))
1928 (depth (1- (length org-section-numbers)))
1929 (i depth) number-string)
1930 (while (>= i 0)
1931 (if (> i level)
1932 (aset org-section-numbers i 0)
1933 (setq number-string (or (car numbers) "0"))
1934 (if (string-match "\\`[A-Z]\\'" number-string)
1935 (aset org-section-numbers i
1936 (- (string-to-char number-string) ?A -1))
1937 (aset org-section-numbers i (string-to-number number-string)))
1938 (pop numbers))
1939 (setq i (1- i)))))
1941 (defun org-section-number (&optional level)
1942 "Return a string with the current section number.
1943 When LEVEL is non-nil, increase section numbers on that level."
1944 (let* ((depth (1- (length org-section-numbers)))
1945 (string "")
1946 (fmts (car org-export-section-number-format))
1947 (term (cdr org-export-section-number-format))
1948 (sep "")
1949 ctype fmt idx n)
1950 (when level
1951 (when (> level -1)
1952 (aset org-section-numbers
1953 level (1+ (aref org-section-numbers level))))
1954 (setq idx (1+ level))
1955 (while (<= idx depth)
1956 (if (not (= idx 1))
1957 (aset org-section-numbers idx 0))
1958 (setq idx (1+ idx))))
1959 (setq idx 0)
1960 (while (<= idx depth)
1961 (when (> (aref org-section-numbers idx) 0)
1962 (setq fmt (or (pop fmts) fmt)
1963 ctype (car fmt)
1964 n (aref org-section-numbers idx)
1965 string (if (> n 0)
1966 (concat string sep (org-number-to-counter n ctype))
1967 (concat string ".0"))
1968 sep (nth 1 fmt)))
1969 (setq idx (1+ idx)))
1970 (save-match-data
1971 (if (string-match "\\`\\([@0]\\.\\)+" string)
1972 (setq string (replace-match "" t nil string)))
1973 (if (string-match "\\(\\.0\\)+\\'" string)
1974 (setq string (replace-match "" t nil string))))
1975 (concat string term)))
1977 (defun org-number-to-counter (n type)
1978 "Concert number N to a string counter, according to TYPE.
1979 TYPE must be a string, any of:
1980 1 number
1981 A A,B,....
1982 a a,b,....
1983 I upper case roman numeral
1984 i lower case roman numeral"
1985 (cond
1986 ((equal type "1") (number-to-string n))
1987 ((equal type "A") (char-to-string (+ ?A n -1)))
1988 ((equal type "a") (char-to-string (+ ?a n -1)))
1989 ((equal type "I") (org-number-to-roman n))
1990 ((equal type "i") (downcase (org-number-to-roman n)))
1991 (t (error "Invalid counter type `%s'" type))))
1993 (defun org-number-to-roman (n)
1994 "Convert integer N into a roman numeral."
1995 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
1996 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1997 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1998 ( 1 . "I")))
1999 (res ""))
2000 (if (<= n 0)
2001 (number-to-string n)
2002 (while roman
2003 (if (>= n (caar roman))
2004 (setq n (- n (caar roman))
2005 res (concat res (cdar roman)))
2006 (pop roman)))
2007 res)))
2009 ;;; Macros
2011 (defun org-export-preprocess-apply-macros ()
2012 "Replace macro references."
2013 (goto-char (point-min))
2014 (let (sy val key args args2 s n)
2015 (while (re-search-forward
2016 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\(.*?\\))\\)?}}}"
2017 nil t)
2018 (setq key (downcase (match-string 1))
2019 args (match-string 3))
2020 (when (setq val (or (plist-get org-export-opt-plist
2021 (intern (concat ":macro-" key)))
2022 (plist-get org-export-opt-plist
2023 (intern (concat ":" key)))))
2024 (save-match-data
2025 (when args
2026 (setq args (org-split-string args ",[ \t]*") args2 nil)
2027 (while args
2028 (while (string-match "\\\\\\'" (car args))
2029 ;; repair bad splits
2030 (setcar (cdr args) (concat (substring (car args) 0 -1)
2031 ";" (nth 1 args)))
2032 (pop args))
2033 (push (pop args) args2))
2034 (setq args (nreverse args2))
2035 (setq s 0)
2036 (while (string-match "\\$\\([0-9]+\\)" val s)
2037 (setq s (1+ (match-beginning 0))
2038 n (string-to-number (match-string 1 val)))
2039 (and (>= (length args) n)
2040 (setq val (replace-match (nth (1- n) args) t t val)))))
2041 (when (string-match "\\`(eval\\>" val)
2042 (setq val (eval (read val))))
2043 (if (and val (not (stringp val)))
2044 (setq val (format "%s" val))))
2045 (and (stringp val)
2046 (replace-match val t t))))))
2048 (defun org-export-apply-macros-in-string (s)
2049 "Apply the macros in string S."
2050 (when s
2051 (with-temp-buffer
2052 (insert s)
2053 (org-export-preprocess-apply-macros)
2054 (buffer-string))))
2056 ;;; Include files
2058 (defun org-export-handle-include-files ()
2059 "Include the contents of include files, with proper formatting."
2060 (let ((case-fold-search t)
2061 params file markup lang start end prefix prefix1 switches)
2062 (goto-char (point-min))
2063 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2064 (setq params (read (concat "(" (match-string 1) ")"))
2065 prefix (org-get-and-remove-property 'params :prefix)
2066 prefix1 (org-get-and-remove-property 'params :prefix1)
2067 file (org-symname-or-string (pop params))
2068 markup (org-symname-or-string (pop params))
2069 lang (and (member markup '("src" "SRC"))
2070 (org-symname-or-string (pop params)))
2071 switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
2072 (delete-region (match-beginning 0) (match-end 0))
2073 (if (or (not file)
2074 (not (file-exists-p file))
2075 (not (file-readable-p file)))
2076 (insert (format "CANNOT INCLUDE FILE %s" file))
2077 (when markup
2078 (if (equal (downcase markup) "src")
2079 (setq start (format "#+begin_src %s %s\n"
2080 (or lang "fundamental")
2081 (or switches ""))
2082 end "#+end_src")
2083 (setq start (format "#+begin_%s %s\n" markup switches)
2084 end (format "#+end_%s" markup))))
2085 (insert (or start ""))
2086 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2087 (or (bolp) (newline))
2088 (insert (or end ""))))))
2090 (defun org-get-file-contents (file &optional prefix prefix1)
2091 "Get the contents of FILE and return them as a string.
2092 If PREFIX is a string, prepend it to each line. If PREFIX1
2093 is a string, prepend it to the first line instead of PREFIX."
2094 (with-temp-buffer
2095 (insert-file-contents file)
2096 (when (or prefix prefix1)
2097 (goto-char (point-min))
2098 (while (not (eobp))
2099 (insert (or prefix1 prefix))
2100 (setq prefix1 nil)
2101 (beginning-of-line 2)))
2102 (buffer-string)
2103 (goto-char (point-min))
2104 (while (re-search-forward "^\\(\\*\\|[ \t]*#\\)" nil t)
2105 (goto-char (match-beginning 0))
2106 (insert ",")
2107 (end-of-line 1))
2108 (buffer-string)))
2110 (defun org-get-and-remove-property (listvar prop)
2111 "Check if the value of LISTVAR contains PROP as a property.
2112 If yes, return the value of that property (i.e. the element following
2113 in the list) and remove property and value from the list in LISTVAR."
2114 (let ((list (symbol-value listvar)) m v)
2115 (when (setq m (member prop list))
2116 (setq v (nth 1 m))
2117 (if (equal (car list) prop)
2118 (set listvar (cddr list))
2119 (setcdr (nthcdr (- (length list) (length m) 1) list)
2120 (cddr m))
2121 (set listvar list)))
2124 (defun org-symname-or-string (s)
2125 (if (symbolp s)
2126 (if s (symbol-name s) s)
2129 ;;; Fontification and line numbers for code examples
2131 (defvar org-export-last-code-line-counter-value 0)
2133 (defun org-export-replace-src-segments-and-examples (backend)
2134 "Replace source code segments with special code for export."
2135 (setq org-export-last-code-line-counter-value 0)
2136 (let ((case-fold-search t)
2137 lang code trans opts indent)
2138 (goto-char (point-min))
2139 (while (re-search-forward
2140 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
2141 nil t)
2142 (if (match-end 1)
2143 ;; src segments
2144 (setq lang (match-string 3)
2145 opts (match-string 4)
2146 code (match-string 5)
2147 indent (length (match-string 2)))
2148 (setq lang nil
2149 opts (match-string 8)
2150 code (match-string 9)
2151 indent (length (match-string 7))))
2153 (setq trans (org-export-format-source-code-or-example
2154 backend lang code opts indent))
2155 (replace-match trans t t))))
2157 (defvar htmlp) ;; dynamically scoped
2158 (defvar latexp) ;; dynamically scoped
2159 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
2161 (defun org-export-format-source-code-or-example
2162 (backend lang code &optional opts indent)
2163 "Format CODE from language LANG and return it formatted for export.
2164 If LANG is nil, do not add any fontification.
2165 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2166 and `+n' for continuing previous numering.
2167 Code formatting according to language currently only works for HTML.
2168 Numbering lines works for all three major backends (html, latex, and ascii).
2169 INDENT was the original indentation of the block."
2170 (save-match-data
2171 (let (num cont rtn rpllbl keepp textareap cols rows fmt)
2172 (setq opts (or opts "")
2173 num (string-match "[-+]n\\>" opts)
2174 cont (string-match "\\+n\\>" opts)
2175 rpllbl (string-match "-r\\>" opts)
2176 keepp (string-match "-k\\>" opts)
2177 textareap (string-match "-t\\>" opts)
2178 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2179 (string-to-number (match-string 1 opts))
2181 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2182 (string-to-number (match-string 1 opts))
2183 (org-count-lines code))
2184 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2185 (match-string 1 opts)))
2186 (when (and textareap (eq backend 'html))
2187 ;; we cannot use numbering or highlighting.
2188 (setq num nil cont nil lang nil))
2189 (if keepp (setq rpllbl 'keep))
2190 (setq rtn (org-remove-indentation code))
2191 (when (string-match "^," rtn)
2192 (setq rtn (with-temp-buffer
2193 (insert rtn)
2194 ;; Free up the protected lines
2195 (goto-char (point-min))
2196 (while (re-search-forward "^," nil t)
2197 (if (or (equal lang "org")
2198 (save-match-data
2199 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2200 (replace-match ""))
2201 (end-of-line 1))
2202 (buffer-string))))
2203 ;; Now backend-specific coding
2204 (setq rtn
2205 (cond
2206 ((eq backend 'docbook)
2207 (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
2208 (concat "\n#+BEGIN_DOCBOOK\n"
2209 (org-add-props (concat "<programlisting><![CDATA["
2211 "]]>\n</programlisting>\n")
2212 '(org-protected t))
2213 "#+END_DOCBOOK\n"))
2214 ((eq backend 'html)
2215 ;; We are exporting to HTML
2216 (when lang
2217 (require 'htmlize nil t)
2218 (when (not (fboundp 'htmlize-region-for-paste))
2219 ;; we do not have htmlize.el, or an old version of it
2220 (setq lang nil)
2221 (message
2222 "htmlize.el 1.34 or later is needed for source code formatting")))
2224 (if lang
2225 (let* ((mode (and lang (intern (concat lang "-mode"))))
2226 (org-inhibit-startup t)
2227 (org-startup-folded nil))
2228 (setq rtn
2229 (with-temp-buffer
2230 (insert rtn)
2231 (if (functionp mode)
2232 (funcall mode)
2233 (fundamental-mode))
2234 (font-lock-fontify-buffer)
2235 (org-src-mode)
2236 (set-buffer-modified-p nil)
2237 (org-export-htmlize-region-for-paste
2238 (point-min) (point-max))))
2239 (if (string-match "<pre\\([^>]*\\)>\n*" rtn)
2240 (setq rtn (replace-match
2241 (format "<pre class=\"src src-%s\">" lang)
2242 t t rtn))))
2243 (if textareap
2244 (setq rtn (concat
2245 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2246 cols rows)
2247 rtn "</textarea>\n</p>\n"))
2248 (with-temp-buffer
2249 (insert rtn)
2250 (goto-char (point-min))
2251 (while (re-search-forward "[<>&]" nil t)
2252 (replace-match (cdr (assq (char-before)
2253 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2254 t t))
2255 (setq rtn (buffer-string)))
2256 (setq rtn (concat "<pre class=\"example\">" rtn "</pre>\n"))))
2257 (unless textareap
2258 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2259 cont rpllbl fmt)))
2260 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2261 ((eq backend 'latex)
2262 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2263 (concat "\n#+BEGIN_LaTeX\n"
2264 (org-add-props (concat (car org-export-latex-verbatim-wrap)
2265 rtn (cdr org-export-latex-verbatim-wrap))
2266 '(org-protected t))
2267 "#+END_LaTeX\n\n"))
2268 ((eq backend 'ascii)
2269 ;; This is not HTML or LaTeX, so just make it an example.
2270 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2271 (concat "#+BEGIN_ASCII\n"
2272 (org-add-props
2273 (concat
2274 (mapconcat
2275 (lambda (l) (concat " " l))
2276 (org-split-string rtn "\n")
2277 "\n")
2278 "\n")
2279 '(org-protected t))
2280 "#+END_ASCII\n"))))
2281 (org-add-props rtn nil 'original-indentation indent))))
2283 (defun org-export-number-lines (text backend
2284 &optional skip1 skip2 number cont
2285 replace-labels label-format)
2286 (if (and (not number) (not (eq replace-labels 'keep)))
2287 (setq replace-labels nil)) ;; must use names if no numbers
2288 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2289 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2290 (with-temp-buffer
2291 (insert text)
2292 (goto-char (point-max))
2293 (skip-chars-backward " \t\n\r")
2294 (delete-region (point) (point-max))
2295 (beginning-of-line (- 1 skip2))
2296 (let* ((last (org-current-line))
2297 (n org-export-last-code-line-counter-value)
2298 (nmax (+ n (- last skip1)))
2299 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2301 (cond
2302 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2303 fmt))
2304 ((eq backend 'ascii) fmt)
2305 ((eq backend 'latex) fmt)
2306 ((eq backend 'docbook) fmt)
2307 (t "")))
2308 (label-format (or label-format org-coderef-label-format))
2309 (label-pre (if (string-match "%s" label-format)
2310 (substring label-format 0 (match-beginning 0))
2311 label-format))
2312 (label-post (if (string-match "%s" label-format)
2313 (substring label-format (match-end 0))
2314 ""))
2315 (lbl-re
2316 (concat
2317 ".*?\\S-.*?\\([ \t]*\\("
2318 (regexp-quote label-pre)
2319 "\\([-a-zA-Z0-9_]+\\)"
2320 (regexp-quote label-post)
2321 "\\)\\)"))
2322 ref)
2324 (goto-line (1+ skip1))
2325 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2326 (if number
2327 (insert (format fm (incf n)))
2328 (forward-char 1))
2329 (when (and (not (eq replace-labels 'keep))
2330 (looking-at lbl-re))
2331 (setq ref (match-string 3))
2332 (if replace-labels
2333 (progn
2334 (delete-region (match-beginning 1) (match-end 1))
2335 (push (cons ref n) org-export-code-refs))
2336 (goto-char (match-beginning 2))
2337 (delete-region (match-beginning 2) (match-end 2))
2338 (insert "(" ref ")")
2339 (push (cons ref (concat "(" ref ")")) org-export-code-refs))
2340 (when (eq backend 'html)
2341 (save-excursion
2342 (beginning-of-line 1)
2343 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2344 ref))
2345 (end-of-line 1)
2346 (insert "</span>")))))
2347 (setq org-export-last-code-line-counter-value n)
2348 (goto-char (point-max))
2349 (newline)
2350 (buffer-string))))
2352 (defun org-search-todo-below (line lines level)
2353 "Search the subtree below LINE for any TODO entries."
2354 (let ((rest (cdr (memq line lines)))
2355 (re org-todo-line-regexp)
2356 line lv todo)
2357 (catch 'exit
2358 (while (setq line (pop rest))
2359 (if (string-match re line)
2360 (progn
2361 (setq lv (- (match-end 1) (match-beginning 1))
2362 todo (and (match-beginning 2)
2363 (not (member (match-string 2 line)
2364 org-done-keywords))))
2365 ; TODO, not DONE
2366 (if (<= lv level) (throw 'exit nil))
2367 (if todo (throw 'exit t))))))))
2369 ;;;###autoload
2370 (defun org-export-visible (type arg)
2371 "Create a copy of the visible part of the current buffer, and export it.
2372 The copy is created in a temporary buffer and removed after use.
2373 TYPE is the final key (as a string) that also select the export command in
2374 the `C-c C-e' export dispatcher.
2375 As a special case, if the you type SPC at the prompt, the temporary
2376 org-mode file will not be removed but presented to you so that you can
2377 continue to use it. The prefix arg ARG is passed through to the exporting
2378 command."
2379 (interactive
2380 (list (progn
2381 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2382 (read-char-exclusive))
2383 current-prefix-arg))
2384 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ )))
2385 (error "Invalid export key"))
2386 (let* ((binding (cdr (assoc type
2387 '((?a . org-export-as-ascii)
2388 (?A . org-export-as-ascii-to-buffer)
2389 (?\C-a . org-export-as-ascii)
2390 (?b . org-export-as-html-and-open)
2391 (?\C-b . org-export-as-html-and-open)
2392 (?h . org-export-as-html)
2393 (?H . org-export-as-html-to-buffer)
2394 (?R . org-export-region-as-html)
2395 (?D . org-export-as-docbook)
2396 (?x . org-export-as-xoxo)))))
2397 (keepp (equal type ?\ ))
2398 (file buffer-file-name)
2399 (buffer (get-buffer-create "*Org Export Visible*"))
2400 s e)
2401 ;; Need to hack the drawers here.
2402 (save-excursion
2403 (goto-char (point-min))
2404 (while (re-search-forward org-drawer-regexp nil t)
2405 (goto-char (match-beginning 1))
2406 (or (org-invisible-p) (org-flag-drawer nil))))
2407 (with-current-buffer buffer (erase-buffer))
2408 (save-excursion
2409 (setq s (goto-char (point-min)))
2410 (while (not (= (point) (point-max)))
2411 (goto-char (org-find-invisible))
2412 (append-to-buffer buffer s (point))
2413 (setq s (goto-char (org-find-visible))))
2414 (org-cycle-hide-drawers 'all)
2415 (goto-char (point-min))
2416 (unless keepp
2417 ;; Copy all comment lines to the end, to make sure #+ settings are
2418 ;; still available for the second export step. Kind of a hack, but
2419 ;; does do the trick.
2420 (if (looking-at "#[^\r\n]*")
2421 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2422 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2423 (append-to-buffer buffer (1+ (match-beginning 0))
2424 (min (point-max) (1+ (match-end 0))))))
2425 (set-buffer buffer)
2426 (let ((buffer-file-name file)
2427 (org-inhibit-startup t))
2428 (org-mode)
2429 (show-all)
2430 (unless keepp (funcall binding arg))))
2431 (if (not keepp)
2432 (kill-buffer buffer)
2433 (switch-to-buffer-other-window buffer)
2434 (goto-char (point-min)))))
2436 (defun org-find-visible ()
2437 (let ((s (point)))
2438 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2439 (get-char-property s 'invisible)))
2441 (defun org-find-invisible ()
2442 (let ((s (point)))
2443 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2444 (not (get-char-property s 'invisible))))
2447 (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
2449 ;;;###autoload
2450 (defun org-export-as-org (arg &optional hidden ext-plist
2451 to-buffer body-only pub-dir)
2452 "Make a copy wiht not-exporting stuff removed.
2453 The purpose of this function is to provide a way to export the source
2454 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2455 stuff removed. This command will remove the following:
2457 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2458 - comment blocks and trees starting with the COMMENT keyword
2459 - only trees that are consistent with `org-export-select-tags'
2460 and `org-export-exclude-tags'.
2462 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2463 all the others will be ignored (but are present so that the general
2464 mechanism to call publishing functions will work).
2466 EXT-PLIST is a property list with external parameters overriding
2467 org-mode's default settings, but still inferior to file-local
2468 settings. When PUB-DIR is set, use this as the publishing
2469 directory."
2470 (interactive "P")
2471 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2472 ext-plist
2473 (org-infile-export-plist)))
2474 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2475 (filename (concat (file-name-as-directory
2476 (or pub-dir
2477 (org-export-directory :org opt-plist)))
2478 (file-name-sans-extension
2479 (file-name-nondirectory bfname))
2480 ".org"))
2481 (filename (and filename
2482 (if (equal (file-truename filename)
2483 (file-truename bfname))
2484 (concat filename "-source")
2485 filename)))
2486 (backup-inhibited t)
2487 (buffer (find-file-noselect filename))
2488 (region (buffer-string)))
2489 (save-excursion
2490 (switch-to-buffer buffer)
2491 (erase-buffer)
2492 (insert region)
2493 (let ((org-inhibit-startup t)) (org-mode))
2495 ;; Get rid of archived trees
2496 (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
2498 ;; Remove comment environment and comment subtrees
2499 (org-export-remove-comment-blocks-and-subtrees)
2501 ;; Get rid of excluded trees
2502 (org-export-handle-export-tags (plist-get opt-plist :select-tags)
2503 (plist-get opt-plist :exclude-tags))
2505 (when (or (plist-get opt-plist :plain-source)
2506 (not (or (plist-get opt-plist :plain-source)
2507 (plist-get opt-plist :htmlized-source))))
2508 ;; Either nothing special is requested (default call)
2509 ;; or the plain source is explicitly requested
2510 ;; so: save it
2511 (save-buffer))
2512 (when (plist-get opt-plist :htmlized-source)
2513 ;; Make the htmlized version
2514 (require 'htmlize)
2515 (require 'org-html)
2516 (font-lock-fontify-buffer)
2517 (let* ((htmlize-output-type 'css)
2518 (newbuf (htmlize-buffer)))
2519 (with-current-buffer newbuf
2520 (when org-export-htmlized-org-css-url
2521 (goto-char (point-min))
2522 (and (re-search-forward
2523 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2524 nil t)
2525 (replace-match
2526 (format
2527 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2528 org-export-htmlized-org-css-url)
2529 t t)))
2530 (write-file (concat filename ".html")))
2531 (kill-buffer newbuf)))
2532 (set-buffer-modified-p nil)
2533 (kill-buffer (current-buffer)))))
2535 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2536 (defun org-get-current-options ()
2537 "Return a string with current options as keyword options.
2538 Does include HTML export options as well as TODO and CATEGORY stuff."
2539 (require 'org-archive)
2540 (format
2541 "#+TITLE: %s
2542 #+AUTHOR: %s
2543 #+EMAIL: %s
2544 #+DATE: %s
2545 #+DESCRIPTION:
2546 #+KEYWORDS:
2547 #+LANGUAGE: %s
2548 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2549 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2551 #+EXPORT_SELECT_TAGS: %s
2552 #+EXPORT_EXCLUDE_TAGS: %s
2553 #+LINK_UP: %s
2554 #+LINK_HOME: %s
2555 #+CATEGORY: %s
2556 #+SEQ_TODO: %s
2557 #+TYP_TODO: %s
2558 #+PRIORITIES: %c %c %c
2559 #+DRAWERS: %s
2560 #+STARTUP: %s %s %s %s %s
2561 #+TAGS: %s
2562 #+FILETAGS: %s
2563 #+ARCHIVE: %s
2564 #+LINK: %s
2566 (buffer-name) (user-full-name) user-mail-address
2567 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2568 org-export-default-language
2569 org-export-headline-levels
2570 org-export-with-section-numbers
2571 org-export-with-toc
2572 org-export-preserve-breaks
2573 org-export-html-expand
2574 org-export-with-fixed-width
2575 org-export-with-tables
2576 org-export-with-sub-superscripts
2577 org-export-with-special-strings
2578 org-export-with-footnotes
2579 org-export-with-emphasize
2580 org-export-with-timestamps
2581 org-export-with-TeX-macros
2582 org-export-with-LaTeX-fragments
2583 org-export-skip-text-before-1st-heading
2584 org-export-with-drawers
2585 org-export-with-todo-keywords
2586 org-export-with-priority
2587 org-export-with-tags
2588 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2589 (mapconcat 'identity org-export-select-tags " ")
2590 (mapconcat 'identity org-export-exclude-tags " ")
2591 org-export-html-link-up
2592 org-export-html-link-home
2593 (or (ignore-errors
2594 (file-name-sans-extension
2595 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2596 "NOFILENAME")
2597 "TODO FEEDBACK VERIFY DONE"
2598 "Me Jason Marie DONE"
2599 org-highest-priority org-lowest-priority org-default-priority
2600 (mapconcat 'identity org-drawers " ")
2601 (cdr (assoc org-startup-folded
2602 '((nil . "showall") (t . "overview") (content . "content"))))
2603 (if org-odd-levels-only "odd" "oddeven")
2604 (if org-hide-leading-stars "hidestars" "showstars")
2605 (if org-startup-align-all-tables "align" "noalign")
2606 (cond ((eq org-log-done t) "logdone")
2607 ((equal org-log-done 'note) "lognotedone")
2608 ((not org-log-done) "nologdone"))
2609 (or (mapconcat (lambda (x)
2610 (cond
2611 ((equal '(:startgroup) x) "{")
2612 ((equal '(:endgroup) x) "}")
2613 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2614 (t (car x))))
2615 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2616 (mapconcat 'identity org-file-tags " ")
2617 org-archive-location
2618 "org file:~/org/%s.org"
2621 ;;;###autoload
2622 (defun org-insert-export-options-template ()
2623 "Insert into the buffer a template with information for exporting."
2624 (interactive)
2625 (if (not (bolp)) (newline))
2626 (let ((s (org-get-current-options)))
2627 (and (string-match "#\\+CATEGORY" s)
2628 (setq s (substring s 0 (match-beginning 0))))
2629 (insert s)))
2631 (defvar org-table-colgroup-info nil)
2633 (defun org-table-clean-before-export (lines &optional maybe-quoted)
2634 "Check if the table has a marking column.
2635 If yes remove the column and the special lines."
2636 (setq org-table-colgroup-info nil)
2637 (if (memq nil
2638 (mapcar
2639 (lambda (x) (or (string-match "^[ \t]*|-" x)
2640 (string-match
2641 (if maybe-quoted
2642 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2643 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2644 x)))
2645 lines))
2646 (progn
2647 (setq org-table-clean-did-remove-column nil)
2648 (delq nil
2649 (mapcar
2650 (lambda (x)
2651 (cond
2652 ((string-match "^[ \t]*| */ *|" x)
2653 (setq org-table-colgroup-info
2654 (mapcar (lambda (x)
2655 (cond ((member x '("<" "&lt;")) :start)
2656 ((member x '(">" "&gt;")) :end)
2657 ((member x '("<>" "&lt;&gt;")) :startend)
2658 (t nil)))
2659 (org-split-string x "[ \t]*|[ \t]*")))
2660 nil)
2661 (t x)))
2662 lines)))
2663 (setq org-table-clean-did-remove-column t)
2664 (delq nil
2665 (mapcar
2666 (lambda (x)
2667 (cond
2668 ((string-match "^[ \t]*| */ *|" x)
2669 (setq org-table-colgroup-info
2670 (mapcar (lambda (x)
2671 (cond ((member x '("<" "&lt;")) :start)
2672 ((member x '(">" "&gt;")) :end)
2673 ((member x '("<>" "&lt;&gt;")) :startend)
2674 (t nil)))
2675 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
2676 nil)
2677 ((string-match "^[ \t]*| *[!_^/] *|" x)
2678 nil) ; ignore this line
2679 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
2680 (string-match "^\\([ \t]*\\)|[^|]*|" x))
2681 ;; remove the first column
2682 (replace-match "\\1|" t nil x))))
2683 lines))))
2685 (defun org-export-cleanup-toc-line (s)
2686 "Remove tags and timestamps from lines going into the toc."
2687 (when (memq org-export-with-tags '(not-in-toc nil))
2688 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
2689 (setq s (replace-match "" t t s))))
2690 (when org-export-remove-timestamps-from-toc
2691 (while (string-match org-maybe-keyword-time-regexp s)
2692 (setq s (replace-match "" t t s))))
2693 (while (string-match org-bracket-link-regexp s)
2694 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
2695 t t s)))
2698 (defun org-create-multibrace-regexp (left right n)
2699 "Create a regular expression which will match a balanced sexp.
2700 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2701 as single character strings.
2702 The regexp returned will match the entire expression including the
2703 delimiters. It will also define a single group which contains the
2704 match except for the outermost delimiters. The maximum depth of
2705 stacked delimiters is N. Escaping delimiters is not possible."
2706 (let* ((nothing (concat "[^" left right "]*?"))
2707 (or "\\|")
2708 (re nothing)
2709 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
2710 (while (> n 1)
2711 (setq n (1- n)
2712 re (concat re or next)
2713 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
2714 (concat left "\\(" re "\\)" right)))
2716 (defvar org-match-substring-regexp
2717 (concat
2718 "\\([^\\]\\)\\([_^]\\)\\("
2719 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2720 "\\|"
2721 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
2722 "\\|"
2723 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2724 "The regular expression matching a sub- or superscript.")
2726 (defvar org-match-substring-with-braces-regexp
2727 (concat
2728 "\\([^\\]\\)\\([_^]\\)\\("
2729 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
2730 "\\)")
2731 "The regular expression matching a sub- or superscript, forcing braces.")
2734 (defun org-get-text-property-any (pos prop &optional object)
2735 (or (get-text-property pos prop object)
2736 (and (setq pos (next-single-property-change pos prop object))
2737 (get-text-property pos prop object))))
2739 (defun org-export-get-coderef-format (path desc)
2740 (save-match-data
2741 (if (and desc (string-match
2742 (regexp-quote (concat "(" path ")"))
2743 desc))
2744 (replace-match "%s" t t desc)
2745 (or desc "%s"))))
2747 (defun org-export-push-to-kill-ring (format)
2748 "Push buffer content to kill ring.
2749 The depends on the variable `org-export-copy-to-kill'."
2750 (when org-export-copy-to-kill-ring
2751 (kill-new (buffer-string))
2752 (when (fboundp 'x-set-selection)
2753 (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
2754 (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
2755 (message "%s export done, pushed to kill ring and clipboard" format)))
2757 (provide 'org-exp)
2759 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2761 ;;; org-exp.el ends here