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