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