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