Configurable faces for clock problems
[org-mode.git] / lisp / org-exp.el
blob8eb814935b9a0ebbc19c840e264a787d8dae5dbc
1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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: 7.5
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 ;;; Code:
31 (require 'org)
32 (require 'org-macs)
33 (require 'org-agenda)
34 (require 'org-exp-blocks)
35 (require 'ob-exp)
36 (require 'org-src)
38 (eval-when-compile
39 (require 'cl))
41 (declare-function org-export-latex-preprocess "org-latex" (parameters))
42 (declare-function org-export-ascii-preprocess "org-ascii" (parameters))
43 (declare-function org-export-html-preprocess "org-html" (parameters))
44 (declare-function org-export-docbook-preprocess "org-docbook" (parameters))
45 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
46 (declare-function org-export-htmlize-region-for-paste "org-html" (beg end))
47 (declare-function htmlize-buffer "ext:htmlize" (&optional buffer))
48 (declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
49 (declare-function org-table-cookie-line-p "org-table" (line))
50 (declare-function org-table-colgroup-line-p "org-table" (line))
51 (autoload 'org-export-generic "org-export-generic" "Export using the generic exporter" t)
52 (defgroup org-export nil
53 "Options for exporting org-listings."
54 :tag "Org Export"
55 :group 'org)
57 (defgroup org-export-general nil
58 "General options for exporting Org-mode files."
59 :tag "Org Export General"
60 :group 'org-export)
62 (defcustom org-export-allow-BIND 'confirm
63 "Non-nil means allow #+BIND to define local variable values for export.
64 This is a potential security risk, which is why the user must confirm the
65 use of these lines."
66 :group 'org-export-general
67 :type '(choice
68 (const :tag "Never" nil)
69 (const :tag "Always" t)
70 (const :tag "Make the user confirm for each file" confirm)))
72 ;; FIXME
73 (defvar org-export-publishing-directory nil)
75 (defcustom org-export-show-temporary-export-buffer t
76 "Non-nil means show buffer after exporting to temp buffer.
77 When Org exports to a file, the buffer visiting that file is ever
78 shown, but remains buried. However, when exporting to a temporary
79 buffer, that buffer is popped up in a second window. When this variable
80 is nil, the buffer remains buried also in these cases."
81 :group 'org-export-general
82 :type 'boolean)
84 (defcustom org-export-copy-to-kill-ring t
85 "Non-nil means exported stuff will also be pushed onto the kill ring."
86 :group 'org-export-general
87 :type 'boolean)
89 (defcustom org-export-kill-product-buffer-when-displayed nil
90 "Non-nil means kill the product buffer if it is displayed immediately.
91 This applied to the commands `org-export-as-html-and-open' and
92 `org-export-as-pdf-and-open'."
93 :group 'org-export-general
94 :type 'boolean)
96 (defcustom org-export-run-in-background nil
97 "Non-nil means export and publishing commands will run in background.
98 This works by starting up a separate Emacs process visiting the same file
99 and doing the export from there.
100 Not all export commands are affected by this - only the ones which
101 actually write to a file, and that do not depend on the buffer state.
102 \\<org-mode-map>
103 If this option is nil, you can still get background export by calling
104 `org-export' with a double prefix arg: \
105 \\[universal-argument] \\[universal-argument] \\[org-export].
107 If this option is t, the double prefix can be used to exceptionally
108 force an export command into the current process."
109 :group 'org-export-general
110 :type 'boolean)
112 (defcustom org-export-initial-scope 'buffer
113 "The initial scope when exporting with `org-export'.
114 This variable can be either set to 'buffer or 'subtree."
115 :group 'org-export-general
116 :type '(choice
117 (const :tag "Export current buffer" 'buffer)
118 (const :tag "Export current subtree" 'subtree)))
120 (defcustom org-export-select-tags '("export")
121 "Tags that select a tree for export.
122 If any such tag is found in a buffer, all trees that do not carry one
123 of these tags will be deleted before export.
124 Inside trees that are selected like this, you can still deselect a
125 subtree by tagging it with one of the `org-export-exclude-tags'."
126 :group 'org-export-general
127 :type '(repeat (string :tag "Tag")))
129 (defcustom org-export-exclude-tags '("noexport")
130 "Tags that exclude a tree from export.
131 All trees carrying any of these tags will be excluded from export.
132 This is without condition, so even subtrees inside that carry one of the
133 `org-export-select-tags' will be removed."
134 :group 'org-export-general
135 :type '(repeat (string :tag "Tag")))
137 ;; FIXME: rename, this is a general variable
138 (defcustom org-export-html-expand t
139 "Non-nil means for HTML export, treat @<...> as HTML tag.
140 When nil, these tags will be exported as plain text and therefore
141 not be interpreted by a browser.
143 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
144 :group 'org-export-html
145 :group 'org-export-general
146 :type 'boolean)
148 (defcustom org-export-with-special-strings t
149 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
150 When this option is turned on, these strings will be exported as:
152 Org HTML LaTeX
153 -----+----------+--------
154 \\- &shy; \\-
155 -- &ndash; --
156 --- &mdash; ---
157 ... &hellip; \ldots
159 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
160 :group 'org-export-translation
161 :type 'boolean)
163 (defcustom org-export-html-link-up ""
164 "Where should the \"UP\" link of exported HTML pages lead?"
165 :group 'org-export-html
166 :group 'org-export-general
167 :type '(string :tag "File or URL"))
169 (defcustom org-export-html-link-home ""
170 "Where should the \"HOME\" link of exported HTML pages lead?"
171 :group 'org-export-html
172 :group 'org-export-general
173 :type '(string :tag "File or URL"))
175 (defcustom org-export-language-setup
176 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
177 ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
178 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
179 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
180 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
181 ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
182 ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
183 ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
184 ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
185 ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
186 ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
187 ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
188 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
189 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
190 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
191 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
192 ("pl" "Autor" "Data" "Spis tre&#x015b;ci" "Przypis")
193 ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
194 "Terms used in export text, translated to different languages.
195 Use the variable `org-export-default-language' to set the language,
196 or use the +OPTION lines for a per-file setting."
197 :group 'org-export-general
198 :type '(repeat
199 (list
200 (string :tag "HTML language tag")
201 (string :tag "Author")
202 (string :tag "Date")
203 (string :tag "Table of Contents")
204 (string :tag "Footnotes"))))
206 (defcustom org-export-default-language "en"
207 "The default language for export and clocktable translations, as a string.
208 This should have an association in `org-export-language-setup'
209 and in `org-clock-clocktable-language-setup'."
210 :group 'org-export-general
211 :type 'string)
213 (defvar org-export-page-description ""
214 "The page description, for the XHTML meta tag.
215 This is best set with the #+DESCRIPTION line in a file, it does not make
216 sense to set this globally.")
218 (defvar org-export-page-keywords ""
219 "The page description, for the XHTML meta tag.
220 This is best set with the #+KEYWORDS line in a file, it does not make
221 sense to set this globally.")
223 (defcustom org-export-skip-text-before-1st-heading nil
224 "Non-nil means skip all text before the first headline when exporting.
225 When nil, that text is exported as well."
226 :group 'org-export-general
227 :type 'boolean)
229 (defcustom org-export-headline-levels 3
230 "The last level which is still exported as a headline.
231 Inferior levels will produce itemize lists when exported.
232 Note that a numeric prefix argument to an exporter function overrides
233 this setting.
235 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
236 :group 'org-export-general
237 :type 'integer)
239 (defcustom org-export-with-section-numbers t
240 "Non-nil means add section numbers to headlines when exporting.
242 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
243 :group 'org-export-general
244 :type 'boolean)
246 (defcustom org-export-section-number-format '((("1" ".")) . "")
247 "Format of section numbers for export.
248 The variable has two components.
249 1. A list of lists, each indicating a counter type and a separator.
250 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
251 It causes causes numeric, alphabetic, or roman counters, respectively.
252 The separator is only used if another counter for a subsection is being
253 added.
254 If there are more numbered section levels than entries in this lists,
255 then the last entry will be reused.
256 2. A terminator string that will be added after the entire
257 section number."
258 :group 'org-export-general
259 :type '(cons
260 (repeat
261 (list
262 (string :tag "Counter Type")
263 (string :tag "Separator ")))
264 (string :tag "Terminator")))
266 (defcustom org-export-with-toc t
267 "Non-nil means create a table of contents in exported files.
268 The TOC contains headlines with levels up to`org-export-headline-levels'.
269 When an integer, include levels up to N in the toc, this may then be
270 different from `org-export-headline-levels', but it will not be allowed
271 to be larger than the number of headline levels.
272 When nil, no table of contents is made.
274 Headlines which contain any TODO items will be marked with \"(*)\" in
275 ASCII export, and with red color in HTML output, if the option
276 `org-export-mark-todo-in-toc' is set.
278 In HTML output, the TOC will be clickable.
280 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
281 or \"toc:3\"."
282 :group 'org-export-general
283 :type '(choice
284 (const :tag "No Table of Contents" nil)
285 (const :tag "Full Table of Contents" t)
286 (integer :tag "TOC to level")))
288 (defcustom org-export-mark-todo-in-toc nil
289 "Non-nil means mark TOC lines that contain any open TODO items."
290 :group 'org-export-general
291 :type 'boolean)
293 (defcustom org-export-with-todo-keywords t
294 "Non-nil means include TODO keywords in export.
295 When nil, remove all these keywords from the export."
296 :group 'org-export-general
297 :type 'boolean)
299 (defcustom org-export-with-tasks t
300 "Non-nil means include TODO items for export.
301 This may have the following values:
302 t include tasks independent of state.
303 todo include only tasks that are not yet done.
304 done include only tasks that are already done.
305 nil remove all tasks before export
306 list of TODO kwds keep only tasks with these keywords"
307 :group 'org-export-general
308 :type '(choice
309 (const :tag "All tasks" t)
310 (const :tag "No tasks" nil)
311 (const :tag "Not-done tasks" todo)
312 (const :tag "Only done tasks" done)
313 (repeat :tag "Specific TODO keywords"
314 (string :tag "Keyword"))))
316 (defcustom org-export-with-priority nil
317 "Non-nil means include priority cookies in export.
318 When nil, remove priority cookies for export."
319 :group 'org-export-general
320 :type 'boolean)
322 (defcustom org-export-preserve-breaks nil
323 "Non-nil means preserve all line breaks when exporting.
324 Normally, in HTML output paragraphs will be reformatted. In ASCII
325 export, line breaks will always be preserved, regardless of this variable.
327 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
328 :group 'org-export-general
329 :type 'boolean)
331 (defcustom org-export-with-archived-trees 'headline
332 "Whether subtrees with the ARCHIVE tag should be exported.
333 This can have three different values
334 nil Do not export, pretend this tree is not present
335 t Do export the entire tree
336 headline Only export the headline, but skip the tree below it."
337 :group 'org-export-general
338 :group 'org-archive
339 :type '(choice
340 (const :tag "not at all" nil)
341 (const :tag "headline only" 'headline)
342 (const :tag "entirely" t)))
344 (defcustom org-export-author-info t
345 "Non-nil means insert author name and email into the exported file.
347 This option can also be set with the +OPTIONS line,
348 e.g. \"author:nil\"."
349 :group 'org-export-general
350 :type 'boolean)
352 (defcustom org-export-email-info nil
353 "Non-nil means insert author name and email into the exported file.
355 This option can also be set with the +OPTIONS line,
356 e.g. \"email:t\"."
357 :group 'org-export-general
358 :type 'boolean)
360 (defcustom org-export-creator-info t
361 "Non-nil means the postamble should contain a creator sentence.
362 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
363 :group 'org-export-general
364 :type 'boolean)
366 (defcustom org-export-time-stamp-file t
367 "Non-nil means insert a time stamp into the exported file.
368 The time stamp shows when the file was created.
370 This option can also be set with the +OPTIONS line,
371 e.g. \"timestamp:nil\"."
372 :group 'org-export-general
373 :type 'boolean)
375 (defcustom org-export-with-timestamps t
376 "If nil, do not export time stamps and associated keywords."
377 :group 'org-export-general
378 :type 'boolean)
380 (defcustom org-export-remove-timestamps-from-toc t
381 "If t, remove timestamps from the table of contents entries."
382 :group 'org-export-general
383 :type 'boolean)
385 (defcustom org-export-with-tags 'not-in-toc
386 "If nil, do not export tags, just remove them from headlines.
387 If this is the symbol `not-in-toc', tags will be removed from table of
388 contents entries, but still be shown in the headlines of the document.
390 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
391 :group 'org-export-general
392 :type '(choice
393 (const :tag "Off" nil)
394 (const :tag "Not in TOC" not-in-toc)
395 (const :tag "On" t)))
397 (defcustom org-export-with-drawers nil
398 "Non-nil means export with drawers like the property drawer.
399 When t, all drawers are exported. This may also be a list of
400 drawer names to export."
401 :group 'org-export-general
402 :type '(choice
403 (const :tag "All drawers" t)
404 (const :tag "None" nil)
405 (repeat :tag "Selected drawers"
406 (string :tag "Drawer name"))))
408 (defvar org-export-first-hook nil
409 "Hook called as the first thing in each exporter.
410 Point will be still in the original buffer.
411 Good for general initialization")
413 (defvar org-export-preprocess-hook nil
414 "Hook for preprocessing an export buffer.
415 Pretty much the first thing when exporting is running this hook.
416 Point will be in a temporary buffer that contains a copy of
417 the original buffer, or of the section that is being exported.
418 All the other hooks in the org-export-preprocess... category
419 also work in that temporary buffer, already modified by various
420 stages of the processing.")
422 (defvar org-export-preprocess-after-include-files-hook nil
423 "Hook for preprocessing an export buffer.
424 This is run after the contents of included files have been inserted.")
426 (defvar org-export-preprocess-after-tree-selection-hook nil
427 "Hook for preprocessing an export buffer.
428 This is run after selection of trees to be exported has happened.
429 This selection includes tags-based selection, as well as removal
430 of commented and archived trees.")
432 (defvar org-export-preprocess-after-headline-targets-hook nil
433 "Hook for preprocessing export buffer.
434 This is run just after the headline targets have been defined and
435 the target-alist has been set up.")
437 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
438 "Hook for preprocessing an export buffer.
439 This is run just before backend-specific blocks get selected.")
441 (defvar org-export-preprocess-after-blockquote-hook nil
442 "Hook for preprocessing an export buffer.
443 This is run after blockquote/quote/verse/center have been marked
444 with cookies.")
446 (defvar org-export-preprocess-after-radio-targets-hook nil
447 "Hook for preprocessing an export buffer.
448 This is run after radio target processing.")
450 (defvar org-export-preprocess-before-normalizing-links-hook nil
451 "Hook for preprocessing an export buffer.
452 This hook is run before links are normalized.")
454 (defvar org-export-preprocess-before-backend-specifics-hook nil
455 "Hook run before backend-specific functions are called during preprocessing.")
457 (defvar org-export-preprocess-final-hook nil
458 "Hook for preprocessing an export buffer.
459 This is run as the last thing in the preprocessing buffer, just before
460 returning the buffer string to the backend.")
462 (defgroup org-export-translation nil
463 "Options for translating special ascii sequences for the export backends."
464 :tag "Org Export Translation"
465 :group 'org-export)
467 (defcustom org-export-with-emphasize t
468 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
469 If the export target supports emphasizing text, the word will be
470 typeset in bold, italic, or underlined, respectively. Works only for
471 single words, but you can say: I *really* *mean* *this*.
472 Not all export backends support this.
474 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
475 :group 'org-export-translation
476 :type 'boolean)
478 (defcustom org-export-with-footnotes t
479 "If nil, export [1] as a footnote marker.
480 Lines starting with [1] will be formatted as footnotes.
482 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
483 :group 'org-export-translation
484 :type 'boolean)
486 (defcustom org-export-with-TeX-macros t
487 "Non-nil means interpret simple TeX-like macros when exporting.
488 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
489 Not only real TeX macros will work here, but the standard HTML entities
490 for math can be used as macro names as well. For a list of supported
491 names in HTML export, see the constant `org-entities' and the user option
492 `org-entities-user'.
493 Not all export backends support this.
495 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
496 :group 'org-export-translation
497 :group 'org-export-latex
498 :type 'boolean)
500 (defcustom org-export-with-LaTeX-fragments t
501 "Non-nil means process LaTeX math fragments for HTML display.
502 When set, the exporter will find and process LaTeX environments if the
503 \\begin line is the first non-white thing on a line. It will also find
504 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
505 $$a=b$$ and \\=\\[ a=b \\] for display math.
507 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
509 Allowed values are:
511 nil Don't do anything.
512 verbatim Keep everything in verbatim
513 dvipng Process the LaTeX fragments to images.
514 This will also include processing of non-math environments.
515 t Do MathJax preprocessing if there is at least on math snippet,
516 and arrange for MathJax.js to be loaded.
518 The default is nil, because this option needs the `dvipng' program which
519 is not available on all systems."
520 :group 'org-export-translation
521 :group 'org-export-latex
522 :type '(choice
523 (const :tag "Do not process math in any way" nil)
524 (const :tag "Obsolete, use dvipng setting" t)
525 (const :tag "Use dvipng to make images" dvipng)
526 (const :tag "Use MathJax to display math" mathjax)
527 (const :tag "Leave math verbatim" verbatim)))
529 (defcustom org-export-with-fixed-width t
530 "Non-nil means lines starting with \":\" will be in fixed width font.
531 This can be used to have pre-formatted text, fragments of code etc. For
532 example:
533 : ;; Some Lisp examples
534 : (while (defc cnt)
535 : (ding))
536 will be looking just like this in also HTML. See also the QUOTE keyword.
537 Not all export backends support this.
539 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
540 :group 'org-export-translation
541 :type 'boolean)
543 (defgroup org-export-tables nil
544 "Options for exporting tables in Org-mode."
545 :tag "Org Export Tables"
546 :group 'org-export)
548 (defcustom org-export-with-tables t
549 "If non-nil, lines starting with \"|\" define a table.
550 For example:
552 | Name | Address | Birthday |
553 |-------------+----------+-----------|
554 | Arthur Dent | England | 29.2.2100 |
556 Not all export backends support this.
558 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
559 :group 'org-export-tables
560 :type 'boolean)
562 (defcustom org-export-highlight-first-table-line t
563 "Non-nil means highlight the first table line.
564 In HTML export, this means use <th> instead of <td>.
565 In tables created with table.el, this applies to the first table line.
566 In Org-mode tables, all lines before the first horizontal separator
567 line will be formatted with <th> tags."
568 :group 'org-export-tables
569 :type 'boolean)
571 (defcustom org-export-table-remove-special-lines t
572 "Remove special lines and marking characters in calculating tables.
573 This removes the special marking character column from tables that are set
574 up for spreadsheet calculations. It also removes the entire lines
575 marked with `!', `_', or `^'. The lines with `$' are kept, because
576 the values of constants may be useful to have."
577 :group 'org-export-tables
578 :type 'boolean)
580 (defcustom org-export-table-remove-empty-lines t
581 "Remove empty lines when exporting tables.
582 This is the global equivalent of the :remove-nil-lines option
583 when locally sending a table with #+ORGTBL."
584 :group 'org-export-tables
585 :type 'boolean)
587 (defcustom org-export-prefer-native-exporter-for-tables nil
588 "Non-nil means always export tables created with table.el natively.
589 Natively means use the HTML code generator in table.el.
590 When nil, Org-mode's own HTML generator is used when possible (i.e. if
591 the table does not use row- or column-spanning). This has the
592 advantage, that the automatic HTML conversions for math symbols and
593 sub/superscripts can be applied. Org-mode's HTML generator is also
594 much faster. The LaTeX exporter always use the native exporter for
595 table.el tables."
596 :group 'org-export-tables
597 :type 'boolean)
599 ;;;; Exporting
601 ;;; Variables, constants, and parameter plists
603 (defconst org-level-max 20)
605 (defvar org-export-current-backend nil
606 "During export, this will be bound to a symbol such as 'html,
607 'latex, 'docbook, 'ascii, etc, indicating which of the export
608 backends is in use. Otherwise it has the value nil. Users
609 should not attempt to change the value of this variable
610 directly, but it can be used in code to test whether export is
611 in progress, and if so, what the backend is.")
613 (defvar org-current-export-file nil) ; dynamically scoped parameter
614 (defvar org-current-export-dir nil) ; dynamically scoped parameter
615 (defvar org-export-opt-plist nil
616 "Contains the current option plist.")
617 (defvar org-last-level nil) ; dynamically scoped variable
618 (defvar org-min-level nil) ; dynamically scoped variable
619 (defvar org-levels-open nil) ; dynamically scoped parameter
621 (defconst org-export-plist-vars
622 '((:link-up nil org-export-html-link-up)
623 (:link-home nil org-export-html-link-home)
624 (:language nil org-export-default-language)
625 (:keywords nil org-export-page-keywords)
626 (:description nil org-export-page-description)
627 (:customtime nil org-display-custom-times)
628 (:headline-levels "H" org-export-headline-levels)
629 (:section-numbers "num" org-export-with-section-numbers)
630 (:section-number-format nil org-export-section-number-format)
631 (:table-of-contents "toc" org-export-with-toc)
632 (:preserve-breaks "\\n" org-export-preserve-breaks)
633 (:archived-trees nil org-export-with-archived-trees)
634 (:emphasize "*" org-export-with-emphasize)
635 (:sub-superscript "^" org-export-with-sub-superscripts)
636 (:special-strings "-" org-export-with-special-strings)
637 (:footnotes "f" org-export-with-footnotes)
638 (:drawers "d" org-export-with-drawers)
639 (:tags "tags" org-export-with-tags)
640 (:todo-keywords "todo" org-export-with-todo-keywords)
641 (:tasks "tasks" org-export-with-tasks)
642 (:priority "pri" org-export-with-priority)
643 (:TeX-macros "TeX" org-export-with-TeX-macros)
644 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
645 (:latex-listings nil org-export-latex-listings)
646 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
647 (:fixed-width ":" org-export-with-fixed-width)
648 (:timestamps "<" org-export-with-timestamps)
649 (:author nil user-full-name)
650 (:email nil user-mail-address)
651 (:author-info "author" org-export-author-info)
652 (:email-info "email" org-export-email-info)
653 (:creator-info "creator" org-export-creator-info)
654 (:time-stamp-file "timestamp" org-export-time-stamp-file)
655 (:tables "|" org-export-with-tables)
656 (:table-auto-headline nil org-export-highlight-first-table-line)
657 (:style-include-default nil org-export-html-style-include-default)
658 (:style-include-scripts nil org-export-html-style-include-scripts)
659 (:style nil org-export-html-style)
660 (:style-extra nil org-export-html-style-extra)
661 (:agenda-style nil org-agenda-export-html-style)
662 (:convert-org-links nil org-export-html-link-org-files-as-html)
663 (:inline-images nil org-export-html-inline-images)
664 (:html-extension nil org-export-html-extension)
665 (:html-preamble nil org-export-html-preamble)
666 (:html-postamble nil org-export-html-postamble)
667 (:xml-declaration nil org-export-html-xml-declaration)
668 (:html-table-tag nil org-export-html-table-tag)
669 (:expand-quoted-html "@" org-export-html-expand)
670 (:timestamp nil org-export-html-with-timestamp)
671 (:publishing-directory nil org-export-publishing-directory)
672 (:select-tags nil org-export-select-tags)
673 (:exclude-tags nil org-export-exclude-tags)
675 (:latex-image-options nil org-export-latex-image-default-option))
676 "List of properties that represent export/publishing variables.
677 Each element is a list of 3 items:
678 1. The property that is used internally, and also for org-publish-project-alist
679 2. The string that can be used in the OPTION lines to set this option,
680 or nil if this option cannot be changed in this way
681 3. The customization variable that sets the default for this option."
684 (defun org-default-export-plist ()
685 "Return the property list with default settings for the export variables."
686 (let* ((infile (org-infile-export-plist))
687 (letbind (plist-get infile :let-bind))
688 (l org-export-plist-vars) rtn e s v)
689 (while (setq e (pop l))
690 (setq s (nth 2 e)
691 v (cond
692 ((assq s letbind) (nth 1 (assq s letbind)))
693 ((boundp s) (symbol-value s))
694 (t nil))
695 rtn (cons (car e) (cons v rtn))))
696 rtn))
698 (defvar org-export-inbuffer-options-extra nil
699 "List of additional in-buffer options that should be detected.
700 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
701 etc. Extensions can add to this list to get their options detected, and they
702 can then add a function to `org-export-options-filters' to process these
703 options.
704 Each element in this list must be a list, with the in-buffer keyword as car,
705 and a property (a symbol) as the next element. All occurrences of the
706 keyword will be found, the values concatenated with a space character
707 in between, and the result stored in the export options property list.")
709 (defvar org-export-options-filters nil
710 "Functions to be called to finalize the export/publishing options.
711 All these options are stored in a property list, and each of the functions
712 in this hook gets a chance to modify this property list. Each function
713 must accept the property list as an argument, and must return the (possibly
714 modified) list.")
716 ;; FIXME: should we fold case here?
717 (defun org-infile-export-plist ()
718 "Return the property list with file-local settings for export."
719 (save-excursion
720 (save-restriction
721 (widen)
722 (goto-char (point-min))
723 (let ((re (org-make-options-regexp
724 (append
725 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
726 "MATHJAX"
727 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
728 "LATEX_HEADER" "LATEX_CLASS"
729 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
730 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
731 (mapcar 'car org-export-inbuffer-options-extra))))
732 (case-fold-search t)
733 p key val text options mathjax a pr style
734 latex-header latex-class macros letbind
735 ext-setup-or-nil setup-contents (start 0))
736 (while (or (and ext-setup-or-nil
737 (string-match re ext-setup-or-nil start)
738 (setq start (match-end 0)))
739 (and (setq ext-setup-or-nil nil start 0)
740 (re-search-forward re nil t)))
741 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
742 val (org-match-string-no-properties 2 ext-setup-or-nil))
743 (cond
744 ((setq a (assoc key org-export-inbuffer-options-extra))
745 (setq pr (nth 1 a))
746 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
747 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
748 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
749 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
750 ((string-equal key "DATE") (setq p (plist-put p :date val)))
751 ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
752 ((string-equal key "DESCRIPTION")
753 (setq p (plist-put p :description val)))
754 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
755 ((string-equal key "STYLE")
756 (setq style (concat style "\n" val)))
757 ((string-equal key "LATEX_HEADER")
758 (setq latex-header (concat latex-header "\n" val)))
759 ((string-equal key "LATEX_CLASS")
760 (setq latex-class val))
761 ((string-equal key "TEXT")
762 (setq text (if text (concat text "\n" val) val)))
763 ((string-equal key "OPTIONS")
764 (setq options (concat val " " options)))
765 ((string-equal key "MATHJAX")
766 (setq mathjax (concat val " " mathjax)))
767 ((string-equal key "BIND")
768 (push (read (concat "(" val ")")) letbind))
769 ((string-equal key "XSLT")
770 (setq p (plist-put p :xslt val)))
771 ((string-equal key "LINK_UP")
772 (setq p (plist-put p :link-up val)))
773 ((string-equal key "LINK_HOME")
774 (setq p (plist-put p :link-home val)))
775 ((string-equal key "EXPORT_SELECT_TAGS")
776 (setq p (plist-put p :select-tags (org-split-string val))))
777 ((string-equal key "EXPORT_EXCLUDE_TAGS")
778 (setq p (plist-put p :exclude-tags (org-split-string val))))
779 ((string-equal key "MACRO")
780 (push val macros))
781 ((equal key "SETUPFILE")
782 (setq setup-contents (org-file-contents
783 (expand-file-name
784 (org-remove-double-quotes
785 (org-trim val)))
786 'noerror))
787 (if (not ext-setup-or-nil)
788 (setq ext-setup-or-nil setup-contents start 0)
789 (setq ext-setup-or-nil
790 (concat (substring ext-setup-or-nil 0 start)
791 "\n" setup-contents "\n"
792 (substring ext-setup-or-nil start)))))))
793 (setq p (plist-put p :text text))
794 (when (and letbind (org-export-confirm-letbind))
795 (setq p (plist-put p :let-bind letbind)))
796 (when style (setq p (plist-put p :style-extra style)))
797 (when latex-header
798 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
799 (when latex-class
800 (setq p (plist-put p :latex-class latex-class)))
801 (when options
802 (setq p (org-export-add-options-to-plist p options)))
803 (when mathjax
804 (setq p (plist-put p :mathjax mathjax)))
805 ;; Add macro definitions
806 (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
807 (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
808 (setq p (plist-put p :macro-property "(eval (org-entry-get nil \"$1\" 'selective))"))
809 (setq p (plist-put
810 p :macro-modification-time
811 (and (buffer-file-name)
812 (file-exists-p (buffer-file-name))
813 (concat
814 "(eval (format-time-string \"$1\" '"
815 (prin1-to-string (nth 5 (file-attributes
816 (buffer-file-name))))
817 "))"))))
818 (setq p (plist-put p :macro-input-file (and (buffer-file-name)
819 (file-name-nondirectory
820 (buffer-file-name)))))
821 (while (setq val (pop macros))
822 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val)
823 (setq p (plist-put
824 p (intern
825 (concat ":macro-" (downcase (match-string 1 val))))
826 (org-export-interpolate-newlines (match-string 2 val))))))
827 p))))
829 (defun org-export-interpolate-newlines (s)
830 (while (string-match "\\\\n" s)
831 (setq s (replace-match "\n" t t s)))
834 (defvar org-export-allow-BIND-local nil)
835 (defun org-export-confirm-letbind ()
836 "Can we use #+BIND values during export?
837 By default this will ask for confirmation by the user, to divert possible
838 security risks."
839 (cond
840 ((not org-export-allow-BIND) nil)
841 ((eq org-export-allow-BIND t) t)
842 ((local-variable-p 'org-export-allow-BIND-local (current-buffer))
843 org-export-allow-BIND-local)
844 (t (org-set-local 'org-export-allow-BIND-local
845 (yes-or-no-p "Allow BIND values in this buffer? ")))))
847 (defun org-install-letbind ()
848 "Install the values from #+BIND lines as local variables."
849 (let ((letbind (plist-get org-export-opt-plist :let-bind))
850 pair)
851 (while (setq pair (pop letbind))
852 (org-set-local (car pair) (nth 1 pair)))))
854 (defun org-export-add-options-to-plist (p options)
855 "Parse an OPTIONS line and set values in the property list P."
856 (let (o)
857 (when options
858 (let ((op org-export-plist-vars))
859 (while (setq o (pop op))
860 (if (and (nth 1 o)
861 (string-match (concat "\\<" (regexp-quote (nth 1 o))
862 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
863 options))
864 (setq p (plist-put p (car o)
865 (car (read-from-string
866 (match-string 1 options))))))))))
869 (defun org-export-add-subtree-options (p pos)
870 "Add options in subtree at position POS to property list P."
871 (save-excursion
872 (goto-char pos)
873 (when (org-at-heading-p)
874 (let (a)
875 ;; This is actually read in `org-export-get-title-from-subtree'
876 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
877 ;; (setq p (plist-put p :title a)))
878 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
879 (setq p (plist-put p :text a)))
880 (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
881 (setq p (plist-put p :author a)))
882 (when (setq a (org-entry-get pos "EXPORT_DATE"))
883 (setq p (plist-put p :date a)))
884 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
885 (setq p (org-export-add-options-to-plist p a)))))
888 (defun org-export-directory (type plist)
889 (let* ((val (plist-get plist :publishing-directory))
890 (dir (if (listp val)
891 (or (cdr (assoc type val)) ".")
892 val)))
893 dir))
895 (defun org-export-process-option-filters (plist)
896 (let ((functions org-export-options-filters) f)
897 (while (setq f (pop functions))
898 (setq plist (funcall f plist))))
899 plist)
901 ;;;###autoload
902 (defun org-export (&optional arg)
903 "Export dispatcher for Org-mode.
904 When `org-export-run-in-background' is non-nil, try to run the command
905 in the background. This will be done only for commands that write
906 to a file. For details see the docstring of `org-export-run-in-background'.
908 The prefix argument ARG will be passed to the exporter. However, if
909 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
910 that means to inverse the
911 value of `org-export-run-in-background'.
913 If `org-export-initial-scope' is set to 'subtree, try to export
914 the current subtree, otherwise try to export the whole buffer.
915 Pressing `1' will switch between these two options."
916 (interactive "P")
917 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
918 (subtree-p (or (org-region-active-p)
919 (eq org-export-initial-scope 'subtree)))
920 (help "[t] insert the export option template
921 \[v] limit export to visible part of outline tree
922 \[1] switch buffer/subtree export
923 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
925 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
927 \[h] export as HTML [H] to temporary buffer [R] export region
928 \[b] export as HTML and open in browser
930 \[l] export as LaTeX [L] to temporary buffer
931 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
933 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
935 \[j] export as TaskJuggler [J] ... and open
937 \[m] export as Freemind mind map
938 \[x] export as XOXO
939 \[g] export using Wes Hardaker's generic exporter
941 \[i] export current file as iCalendar file
942 \[I] export all agenda files as iCalendar files [c] ...as one combined file
944 \[F] publish current file [P] publish current project
945 \[X] publish a project... [E] publish every projects")
946 (cmds
947 '((?t org-insert-export-options-template nil)
948 (?v org-export-visible nil)
949 (?a org-export-as-ascii t)
950 (?A org-export-as-ascii-to-buffer t)
951 (?n org-export-as-latin1 t)
952 (?N org-export-as-latin1-to-buffer t)
953 (?u org-export-as-utf8 t)
954 (?U org-export-as-utf8-to-buffer t)
955 (?h org-export-as-html t)
956 (?b org-export-as-html-and-open t)
957 (?H org-export-as-html-to-buffer nil)
958 (?R org-export-region-as-html nil)
959 (?x org-export-as-xoxo t)
960 (?g org-export-generic t)
961 (?D org-export-as-docbook t)
962 (?V org-export-as-docbook-pdf-and-open t)
963 (?j org-export-as-taskjuggler t)
964 (?J org-export-as-taskjuggler-and-open t)
965 (?m org-export-as-freemind t)
966 (?l org-export-as-latex t)
967 (?p org-export-as-pdf t)
968 (?d org-export-as-pdf-and-open t)
969 (?L org-export-as-latex-to-buffer nil)
970 (?i org-export-icalendar-this-file t)
971 (?I org-export-icalendar-all-agenda-files t)
972 (?c org-export-icalendar-combine-agenda-files t)
973 (?F org-publish-current-file t)
974 (?P org-publish-current-project t)
975 (?X org-publish t)
976 (?E org-publish-all t)))
977 r1 r2 ass
978 (cpos (point)) (cbuf (current-buffer)) bpos)
979 (save-excursion
980 (save-window-excursion
981 (if subtree-p
982 (message "Export subtree: ")
983 (message "Export buffer: "))
984 (delete-other-windows)
985 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
986 (princ help))
987 (org-fit-window-to-buffer (get-buffer-window
988 "*Org Export/Publishing Help*"))
989 (while (eq (setq r1 (read-char-exclusive)) ?1)
990 (cond (subtree-p
991 (setq subtree-p nil)
992 (message "Export buffer: "))
993 ((not subtree-p)
994 (setq subtree-p t)
995 (message "Export subtree: "))))
996 (when (eq r1 ?\ )
997 (let ((case-fold-search t)
998 (end (save-excursion (while (org-up-heading-safe)) (point))))
999 (outline-next-heading)
1000 (if (re-search-backward
1001 "^[ \t]+\\(:latex_class:\\|:export_title:\\|:export_file_name:\\)[ \t]+\\S-"
1002 end t)
1003 (progn
1004 (org-back-to-heading t)
1005 (setq subtree-p t)
1006 (setq bpos (point))
1007 (message "Select command (for subtree): ")
1008 (setq r1 (read-char-exclusive)))
1009 (error "No enclosing node with LaTeX_CLASS or EXPORT_TITLE or EXPORT_FILE_NAME")
1010 )))))
1011 (redisplay)
1012 (and bpos (goto-char bpos))
1013 (setq r2 (if (< r1 27) (+ r1 96) r1))
1014 (unless (setq ass (assq r2 cmds))
1015 (error "No command associated with key %c" r1))
1016 (if (and bg (nth 2 ass)
1017 (not (buffer-base-buffer))
1018 (not (org-region-active-p)))
1019 ;; execute in background
1020 (let ((p (start-process
1021 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1022 "*Org Processes*"
1023 (expand-file-name invocation-name invocation-directory)
1024 "-batch"
1025 "-l" user-init-file
1026 "--eval" "(require 'org-exp)"
1027 "--eval" "(setq org-wait .2)"
1028 (buffer-file-name)
1029 "-f" (symbol-name (nth 1 ass)))))
1030 (set-process-sentinel p 'org-export-process-sentinel)
1031 (message "Background process \"%s\": started" p))
1032 ;; background processing not requested, or not possible
1033 (if subtree-p (progn (org-mark-subtree) (activate-mark)))
1034 (call-interactively (nth 1 ass))
1035 (when (and bpos (get-buffer-window cbuf))
1036 (let ((cw (selected-window)))
1037 (select-window (get-buffer-window cbuf))
1038 (goto-char cpos)
1039 (deactivate-mark)
1040 (select-window cw))))))
1042 (defun org-export-process-sentinel (process status)
1043 (if (string-match "\n+\\'" status)
1044 (setq status (substring status 0 -1)))
1045 (message "Background process \"%s\": %s" process status))
1047 ;;; General functions for all backends
1049 (defvar org-export-target-aliases nil
1050 "Alist of targets with invisible aliases.")
1051 (defvar org-export-preferred-target-alist nil
1052 "Alist of section id's with preferred aliases.")
1053 (defvar org-export-id-target-alist nil
1054 "Alist of section id's with preferred aliases.")
1055 (defvar org-export-code-refs nil
1056 "Alist of code references and line numbers.")
1058 (defun org-export-preprocess-string (string &rest parameters)
1059 "Cleanup STRING so that the true exported has a more consistent source.
1060 This function takes STRING, which should be a buffer-string of an org-file
1061 to export. It then creates a temporary buffer where it does its job.
1062 The result is then again returned as a string, and the exporter works
1063 on this string to produce the exported version."
1064 (interactive)
1065 (let* ((org-export-current-backend (plist-get parameters :for-backend))
1066 (archived-trees (plist-get parameters :archived-trees))
1067 (inhibit-read-only t)
1068 (drawers org-drawers)
1069 (outline-regexp "\\*+ ")
1070 (source-buffer (current-buffer))
1071 target-alist rtn)
1073 (setq org-export-target-aliases nil
1074 org-export-preferred-target-alist nil
1075 org-export-id-target-alist nil
1076 org-export-code-refs nil)
1078 (with-current-buffer (get-buffer-create " org-mode-tmp")
1079 (erase-buffer)
1080 (insert string)
1081 (setq case-fold-search t)
1083 (let ((inhibit-read-only t))
1084 (remove-text-properties (point-min) (point-max)
1085 '(read-only t)))
1087 ;; Remove license-to-kill stuff
1088 ;; The caller marks some stuff for killing, stuff that has been
1089 ;; used to create the page title, for example.
1090 (org-export-kill-licensed-text)
1092 (let ((org-inhibit-startup t)) (org-mode))
1093 (setq case-fold-search t)
1094 (org-clone-local-variables source-buffer "^\\(org-\\|orgtbl-\\)")
1095 (org-install-letbind)
1097 ;; Call the hook
1098 (run-hooks 'org-export-preprocess-hook)
1100 (untabify (point-min) (point-max))
1102 ;; Handle include files, and call a hook
1103 (org-export-handle-include-files-recurse)
1104 (run-hooks 'org-export-preprocess-after-include-files-hook)
1106 ;; Process the macros
1107 (org-export-preprocess-apply-macros)
1108 (run-hooks 'org-export-preprocess-after-macros-hook)
1110 ;; Get rid of archived trees
1111 (org-export-remove-archived-trees archived-trees)
1113 ;; Remove comment environment and comment subtrees
1114 (org-export-remove-comment-blocks-and-subtrees)
1116 ;; Get rid of excluded trees, and call a hook
1117 (org-export-handle-export-tags (plist-get parameters :select-tags)
1118 (plist-get parameters :exclude-tags))
1119 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1121 ;; Get rid of tasks, depending on configuration
1122 (org-export-remove-tasks (plist-get parameters :tasks))
1124 ;; Change lists ending. Other parts of export may insert blank
1125 ;; lines and lists' structure could be altered.
1126 (org-export-mark-list-end)
1128 ;; Export code blocks
1129 (org-export-blocks-preprocess)
1131 ;; Mark lists with properties
1132 (org-export-mark-list-properties)
1134 ;; Handle source code snippets
1135 (org-export-replace-src-segments-and-examples)
1137 ;; Protect short examples marked by a leading colon
1138 (org-export-protect-colon-examples)
1140 ;; Protected spaces
1141 (org-export-convert-protected-spaces)
1143 ;; Normalize footnotes
1144 (when (plist-get parameters :footnotes)
1145 (org-footnote-normalize nil t))
1147 ;; Find all headings and compute the targets for them
1148 (setq target-alist (org-export-define-heading-targets target-alist))
1150 (run-hooks 'org-export-preprocess-after-headline-targets-hook)
1152 ;; Find HTML special classes for headlines
1153 (org-export-remember-html-container-classes)
1155 ;; Get rid of drawers
1156 (org-export-remove-or-extract-drawers
1157 drawers (plist-get parameters :drawers))
1159 ;; Get the correct stuff before the first headline
1160 (when (plist-get parameters :skip-before-1st-heading)
1161 (goto-char (point-min))
1162 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1163 (delete-region (point-min) (match-beginning 0))
1164 (goto-char (point-min))
1165 (insert "\n")))
1166 (when (plist-get parameters :add-text)
1167 (goto-char (point-min))
1168 (insert (plist-get parameters :add-text) "\n"))
1170 ;; Remove todo-keywords before exporting, if the user has requested so
1171 (org-export-remove-headline-metadata parameters)
1173 ;; Find targets in comments and move them out of comments,
1174 ;; but mark them as targets that should be invisible
1175 (setq target-alist (org-export-handle-invisible-targets target-alist))
1177 ;; Select and protect backend specific stuff, throw away stuff
1178 ;; that is specific for other backends
1179 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook)
1180 (org-export-select-backend-specific-text)
1182 ;; Protect quoted subtrees
1183 (org-export-protect-quoted-subtrees)
1185 ;; Remove clock lines
1186 (org-export-remove-clock-lines)
1188 ;; Protect verbatim elements
1189 (org-export-protect-verbatim)
1191 ;; Blockquotes, verse, and center
1192 (org-export-mark-blockquote-verse-center)
1193 (run-hooks 'org-export-preprocess-after-blockquote-hook)
1195 ;; Remove timestamps, if the user has requested so
1196 (unless (plist-get parameters :timestamps)
1197 (org-export-remove-timestamps))
1199 ;; Attach captions to the correct object
1200 (setq target-alist (org-export-attach-captions-and-attributes target-alist))
1202 ;; Find matches for radio targets and turn them into internal links
1203 (org-export-mark-radio-links)
1204 (run-hooks 'org-export-preprocess-after-radio-targets-hook)
1206 ;; Find all links that contain a newline and put them into a single line
1207 (org-export-concatenate-multiline-links)
1209 ;; Normalize links: Convert angle and plain links into bracket links
1210 ;; and expand link abbreviations
1211 (run-hooks 'org-export-preprocess-before-normalizing-links-hook)
1212 (org-export-normalize-links)
1214 ;; Find all internal links. If they have a fuzzy match (i.e. not
1215 ;; a *dedicated* target match, let the link point to the
1216 ;; corresponding section.
1217 (org-export-target-internal-links target-alist)
1219 ;; Find multiline emphasis and put them into single line
1220 (when (plist-get parameters :emph-multiline)
1221 (org-export-concatenate-multiline-emphasis))
1223 ;; Remove special table lines, and store alignment information
1224 (org-store-forced-table-alignment)
1225 (when org-export-table-remove-special-lines
1226 (org-export-remove-special-table-lines))
1228 ;; Another hook
1229 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1231 ;; Backend-specific preprocessing
1232 (let* ((backend-name (symbol-name org-export-current-backend))
1233 (f (intern (format "org-export-%s-preprocess" backend-name))))
1234 (require (intern (concat "org-" backend-name)) nil)
1235 (funcall f parameters))
1237 ;; Remove or replace comments
1238 (org-export-handle-comments (plist-get parameters :comments))
1240 ;; Remove #+TBLFM and #+TBLNAME lines
1241 (org-export-handle-table-metalines)
1243 ;; Run the final hook
1244 (run-hooks 'org-export-preprocess-final-hook)
1246 (setq rtn (buffer-string)))
1247 (kill-buffer " org-mode-tmp")
1248 rtn))
1250 (defun org-export-kill-licensed-text ()
1251 "Remove all text that is marked with a :org-license-to-kill property."
1252 (let (p)
1253 (while (setq p (text-property-any (point-min) (point-max)
1254 :org-license-to-kill t))
1255 (delete-region
1256 p (or (next-single-property-change p :org-license-to-kill)
1257 (point-max))))))
1259 (defvar org-export-define-heading-targets-headline-hook nil
1260 "Hook that is run when a headline was matched during target search.
1261 This is part of the preprocessing for export.")
1263 (defun org-export-define-heading-targets (target-alist)
1264 "Find all headings and define the targets for them.
1265 The new targets are added to TARGET-ALIST, which is also returned.
1266 Also find all ID and CUSTOM_ID properties and store them."
1267 (goto-char (point-min))
1268 (org-init-section-numbers)
1269 (let ((re (concat "^" org-outline-regexp
1270 "\\|"
1271 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1272 level target last-section-target a id)
1273 (while (re-search-forward re nil t)
1274 (org-if-unprotected-at (match-beginning 0)
1275 (if (match-end 2)
1276 (progn
1277 (setq id (org-match-string-no-properties 2))
1278 (push (cons id target) target-alist)
1279 (setq a (or (assoc last-section-target org-export-target-aliases)
1280 (progn
1281 (push (list last-section-target)
1282 org-export-target-aliases)
1283 (car org-export-target-aliases))))
1284 (push (caar target-alist) (cdr a))
1285 (when (equal (match-string 1) "CUSTOM_ID")
1286 (if (not (assoc last-section-target
1287 org-export-preferred-target-alist))
1288 (push (cons last-section-target id)
1289 org-export-preferred-target-alist)))
1290 (when (equal (match-string 1) "ID")
1291 (if (not (assoc last-section-target
1292 org-export-id-target-alist))
1293 (push (cons last-section-target (concat "ID-" id))
1294 org-export-id-target-alist))))
1295 (setq level (org-reduced-level
1296 (save-excursion (goto-char (point-at-bol))
1297 (org-outline-level))))
1298 (setq target (org-solidify-link-text
1299 (format "sec-%s" (replace-regexp-in-string
1300 "\\." "_"
1301 (org-section-number level)))))
1302 (setq last-section-target target)
1303 (push (cons target target) target-alist)
1304 (add-text-properties
1305 (point-at-bol) (point-at-eol)
1306 (list 'target target))
1307 (run-hooks 'org-export-define-heading-targets-headline-hook)))))
1308 target-alist)
1310 (defun org-export-handle-invisible-targets (target-alist)
1311 "Find targets in comments and move them out of comments.
1312 Mark them as invisible targets."
1313 (let (target tmp a)
1314 (goto-char (point-min))
1315 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1316 ;; Check if the line before or after is a headline with a target
1317 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1318 (get-text-property (point-at-bol 2) 'target)))
1319 (progn
1320 ;; use the existing target in a neighboring line
1321 (setq tmp (match-string 2))
1322 (replace-match "")
1323 (and (looking-at "\n") (delete-char 1))
1324 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1325 target-alist)
1326 (setq a (or (assoc target org-export-target-aliases)
1327 (progn
1328 (push (list target) org-export-target-aliases)
1329 (car org-export-target-aliases))))
1330 (push tmp (cdr a)))
1331 ;; Make an invisible target
1332 (replace-match "\\1(INVISIBLE)"))))
1333 target-alist)
1335 (defun org-export-target-internal-links (target-alist)
1336 "Find all internal links and assign targets to them.
1337 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1338 let the link point to the corresponding section.
1339 This function also handles the id links, if they have a match in
1340 the current file."
1341 (goto-char (point-min))
1342 (while (re-search-forward org-bracket-link-regexp nil t)
1343 (org-if-unprotected-at (1+ (match-beginning 0))
1344 (let* ((org-link-search-must-match-exact-headline t)
1345 (md (match-data))
1346 (desc (match-end 2))
1347 (link (org-link-unescape (match-string 1)))
1348 (slink (org-solidify-link-text link))
1349 found props pos cref
1350 (target
1351 (cond
1352 ((= (string-to-char link) ?#)
1353 ;; user wants exactly this link
1354 link)
1355 ((cdr (assoc slink target-alist))
1356 (or (cdr (assoc (assoc slink target-alist)
1357 org-export-preferred-target-alist))
1358 (cdr (assoc slink target-alist))))
1359 ((and (string-match "^id:" link)
1360 (cdr (assoc (substring link 3) target-alist))))
1361 ((string-match "^(\\(.*\\))$" link)
1362 (setq cref (match-string 1 link))
1363 (concat "coderef:" cref))
1364 ((string-match org-link-types-re link) nil)
1365 ((or (file-name-absolute-p link)
1366 (string-match "^\\." link))
1367 nil)
1369 (let ((org-link-search-inhibit-query t))
1370 (save-excursion
1371 (setq found (condition-case nil (org-link-search link)
1372 (error nil)))
1373 (when (and found
1374 (or (org-on-heading-p)
1375 (not (eq found 'dedicated))))
1376 (or (get-text-property (point) 'target)
1377 (get-text-property
1378 (max (point-min)
1379 (1- (or (previous-single-property-change
1380 (point) 'target) 0)))
1381 'target)))))))))
1382 (when target
1383 (set-match-data md)
1384 (goto-char (match-beginning 1))
1385 (setq props (text-properties-at (point)))
1386 (delete-region (match-beginning 1) (match-end 1))
1387 (setq pos (point))
1388 (insert target)
1389 (unless desc (insert "][" link))
1390 (add-text-properties pos (point) props))))))
1392 (defun org-export-remember-html-container-classes ()
1393 "Store the HTML_CONTAINER_CLASS properties in a text property."
1394 (goto-char (point-min))
1395 (let (class)
1396 (while (re-search-forward
1397 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t)
1398 (setq class (match-string 1))
1399 (save-excursion
1400 (org-back-to-heading t)
1401 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class)))))
1403 (defvar org-export-format-drawer-function nil
1404 "Function to be called to format the contents of a drawer.
1405 The function must accept three parameters:
1406 NAME the drawer name, like \"PROPERTIES\"
1407 CONTENT the content of the drawer.
1408 You can check the export backend through `org-export-current-backend'.
1409 The function should return the text to be inserted into the buffer.
1410 If this is nil, `org-export-format-drawer' is used as a default.")
1412 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1413 "Remove drawers, or extract and format the content.
1414 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1415 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1416 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1417 EXP-DRAWERS will be removed."
1418 (goto-char (point-min))
1419 (let ((re (concat "^[ \t]*:\\("
1420 (mapconcat 'identity all-drawers "\\|")
1421 "\\):[ \t]*$"))
1422 name beg beg-content eol content)
1423 (while (re-search-forward re nil t)
1424 (org-if-unprotected
1425 (setq name (match-string 1))
1426 (setq beg (match-beginning 0)
1427 beg-content (1+ (point-at-eol))
1428 eol (point-at-eol))
1429 (if (not (and (re-search-forward
1430 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t)
1431 (match-end 1)))
1432 (goto-char eol)
1433 (goto-char (match-beginning 0))
1434 (and (looking-at ".*\n?") (replace-match ""))
1435 (setq content (buffer-substring beg-content (point)))
1436 (delete-region beg (point))
1437 (when (or (eq exp-drawers t)
1438 (member name exp-drawers))
1439 (setq content (funcall (or org-export-format-drawer-function
1440 'org-export-format-drawer)
1441 name content))
1442 (insert content)))))))
1444 (defun org-export-format-drawer (name content)
1445 "Format the content of a drawer as a colon example."
1446 (if (string-match "[ \t]+\\'" content)
1447 (setq content (substring content (match-beginning 0))))
1448 (while (string-match "\\`[ \t]*\n" content)
1449 (setq content (substring content (match-end 0))))
1450 (setq content (org-remove-indentation content))
1451 (setq content (concat ": " (mapconcat 'identity
1452 (org-split-string content "\n")
1453 "\n: ")
1454 "\n"))
1455 (setq content (concat " : " (upcase name) "\n" content))
1456 (org-add-props content nil 'org-protected t))
1458 (defun org-export-handle-export-tags (select-tags exclude-tags)
1459 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1460 Both arguments are lists of tags.
1461 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1462 will be removed.
1463 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1464 removed as well."
1465 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1466 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1467 select-tags "\\|")
1468 "\\):"))
1469 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1470 exclude-tags "\\|")
1471 "\\):"))
1472 beg end cont)
1473 (goto-char (point-min))
1474 (when (and select-tags
1475 (re-search-forward
1476 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1477 ;; At least one tree is marked for export, this means
1478 ;; all the unmarked stuff needs to go.
1479 ;; Dig out the trees that should be exported
1480 (goto-char (point-min))
1481 (outline-next-heading)
1482 (setq beg (point))
1483 (put-text-property beg (point-max) :org-delete t)
1484 (while (re-search-forward re-sel nil t)
1485 (when (org-on-heading-p)
1486 (org-back-to-heading)
1487 (remove-text-properties
1488 (max (1- (point)) (point-min))
1489 (setq cont (save-excursion (org-end-of-subtree t t)))
1490 '(:org-delete t))
1491 (while (and (org-up-heading-safe)
1492 (get-text-property (point) :org-delete))
1493 (remove-text-properties (max (1- (point)) (point-min))
1494 (point-at-eol) '(:org-delete t)))
1495 (goto-char cont))))
1496 ;; Remove the trees explicitly marked for noexport
1497 (when exclude-tags
1498 (goto-char (point-min))
1499 (while (re-search-forward re-excl nil t)
1500 (when (org-at-heading-p)
1501 (org-back-to-heading t)
1502 (setq beg (point))
1503 (org-end-of-subtree t t)
1504 (delete-region beg (point))
1505 (when (featurep 'org-inlinetask)
1506 (org-inlinetask-remove-END-maybe)))))
1507 ;; Remove everything that is now still marked for deletion
1508 (goto-char (point-min))
1509 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1510 (setq end (or (next-single-property-change beg :org-delete)
1511 (point-max)))
1512 (delete-region beg end))))
1514 (defun org-export-remove-tasks (keep)
1515 "Remove tasks depending on configuration.
1516 When KEEP is nil, remove all tasks.
1517 When KEEP is `todo', remove the tasks that are DONE.
1518 When KEEP is `done', remove the tasks that are not yet done.
1519 When it is a list of strings, keep only tasks with these TODO keywords."
1520 (when (or (listp keep) (memq keep '(todo done nil)))
1521 (let ((re (concat "^\\*+[ \t]+\\("
1522 (mapconcat
1523 'regexp-quote
1524 (cond ((not keep) org-todo-keywords-1)
1525 ((eq keep 'todo) org-done-keywords)
1526 ((eq keep 'done) org-not-done-keywords)
1527 ((listp keep)
1528 (org-delete-all keep (copy-sequence
1529 org-todo-keywords-1))))
1530 "\\|")
1531 "\\)\\($\\|[ \t]\\)"))
1532 (case-fold-search nil)
1533 beg)
1534 (goto-char (point-min))
1535 (while (re-search-forward re nil t)
1536 (org-if-unprotected
1537 (setq beg (match-beginning 0))
1538 (org-end-of-subtree t t)
1539 (if (looking-at "^\\*+[ \t]+END[ \t]*$")
1540 ;; Kill the END line of the inline task
1541 (goto-char (min (point-max) (1+ (match-end 0)))))
1542 (delete-region beg (point)))))))
1544 (defun org-export-remove-archived-trees (export-archived-trees)
1545 "Remove archived trees.
1546 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1547 When it is t, the entire archived tree will be exported.
1548 When it is nil the entire tree including the headline will be removed
1549 from the buffer."
1550 (let ((re-archive (concat ":" org-archive-tag ":"))
1551 a b)
1552 (when (not (eq export-archived-trees t))
1553 (goto-char (point-min))
1554 (while (re-search-forward re-archive nil t)
1555 (if (not (org-on-heading-p t))
1556 (goto-char (point-at-eol))
1557 (beginning-of-line 1)
1558 (setq a (if export-archived-trees
1559 (1+ (point-at-eol)) (point))
1560 b (org-end-of-subtree t))
1561 (if (> b a) (delete-region a b)))))))
1563 (defun org-export-remove-headline-metadata (opts)
1564 "Remove meta data from the headline, according to user options."
1565 (let ((re org-complex-heading-regexp)
1566 (todo (plist-get opts :todo-keywords))
1567 (tags (plist-get opts :tags))
1568 (pri (plist-get opts :priority))
1569 (elts '(1 2 3 4 5))
1570 (case-fold-search nil)
1571 rpl)
1572 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1573 (when (or (not todo) (not tags) (not pri))
1574 (goto-char (point-min))
1575 (while (re-search-forward re nil t)
1576 (org-if-unprotected
1577 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1578 elts " "))
1579 (replace-match rpl t t))))))
1581 (defun org-export-remove-timestamps ()
1582 "Remove timestamps and keywords for export."
1583 (goto-char (point-min))
1584 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1585 (backward-char 1)
1586 (org-if-unprotected
1587 (unless (save-match-data (org-at-table-p))
1588 (replace-match "")
1589 (beginning-of-line 1)
1590 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1591 (replace-match ""))))))
1593 (defun org-export-remove-clock-lines ()
1594 "Remove clock lines for export."
1595 (goto-char (point-min))
1596 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1597 (while (re-search-forward re nil t)
1598 (org-if-unprotected
1599 (replace-match "")))))
1601 (defun org-export-protect-quoted-subtrees ()
1602 "Mark quoted subtrees with the protection property."
1603 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1604 (goto-char (point-min))
1605 (while (re-search-forward re-quote nil t)
1606 (goto-char (match-beginning 0))
1607 (end-of-line 1)
1608 (add-text-properties (point) (org-end-of-subtree t)
1609 '(org-protected t)))))
1611 (defun org-export-convert-protected-spaces ()
1612 "Convert strings like \\____ to protected spaces in all backends."
1613 (goto-char (point-min))
1614 (while (re-search-forward "\\\\__+" nil t)
1615 (org-if-unprotected-1
1616 (replace-match
1617 (org-add-props
1618 (cond
1619 ((eq org-export-current-backend 'latex)
1620 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1621 ((eq org-export-current-backend 'html)
1622 (org-add-props (match-string 0) nil
1623 'org-whitespace (- (match-end 0) (match-beginning 0))))
1624 ;; ((eq org-export-current-backend 'docbook))
1625 ((eq org-export-current-backend 'ascii)
1626 (org-add-props (match-string 0) '(org-whitespace t)))
1627 (t (make-string (- (match-end 0) (match-beginning 0)) ?\ )))
1628 '(org-protected t))
1629 t t))))
1631 (defun org-export-protect-verbatim ()
1632 "Mark verbatim snippets with the protection property."
1633 (goto-char (point-min))
1634 (while (re-search-forward org-verbatim-re nil t)
1635 (org-if-unprotected
1636 (add-text-properties (match-beginning 4) (match-end 4)
1637 '(org-protected t org-verbatim-emph t))
1638 (goto-char (1+ (match-end 4))))))
1640 (defun org-export-protect-colon-examples ()
1641 "Protect lines starting with a colon."
1642 (goto-char (point-min))
1643 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1644 (while (re-search-forward re nil t)
1645 (beginning-of-line 1)
1646 (setq beg (point))
1647 (while (looking-at re)
1648 (end-of-line 1)
1649 (or (eobp) (forward-char 1)))
1650 (add-text-properties beg (if (bolp) (1- (point)) (point))
1651 '(org-protected t)))))
1653 (defun org-export-select-backend-specific-text ()
1654 (let ((formatters
1655 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1656 (html "HTML" "BEGIN_HTML" "END_HTML")
1657 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1658 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1659 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1660 (case-fold-search t)
1661 fmt beg beg-content end end-content ind)
1663 (while formatters
1664 (setq fmt (pop formatters))
1665 ;; Handle #+backend: stuff
1666 (goto-char (point-min))
1667 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
1668 ":[ \t]*\\(.*\\)") nil t)
1669 (if (not (eq (car fmt) org-export-current-backend))
1670 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1671 (replace-match "\\1\\2" t)
1672 (add-text-properties
1673 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1674 `(org-protected t original-indentation ,ind))))
1675 ;; Delete #+attr_Backend: stuff of another backend. Those
1676 ;; matching the current backend will be taken care of by
1677 ;; `org-export-attach-captions-and-attributes'
1678 (goto-char (point-min))
1679 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt)
1680 ":[ \t]*\\(.*\\)") nil t)
1681 (setq ind (org-get-indentation))
1682 (when (not (eq (car fmt) org-export-current-backend))
1683 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1684 ;; Handle #+begin_backend and #+end_backend stuff
1685 (goto-char (point-min))
1686 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt) "\\>.*\n?")
1687 nil t)
1688 (setq beg (match-beginning 0) beg-content (match-end 0))
1689 (setq ind (save-excursion (goto-char beg) (org-get-indentation)))
1690 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?")
1691 nil t)
1692 (setq end (match-end 0) end-content (match-beginning 0))
1693 (if (eq (car fmt) org-export-current-backend)
1694 ;; yes, keep this
1695 (progn
1696 (add-text-properties
1697 beg-content end-content
1698 `(org-protected t original-indentation ,ind))
1699 (delete-region (match-beginning 0) (match-end 0))
1700 (save-excursion
1701 (goto-char beg)
1702 (delete-region (point) (1+ (point-at-eol)))))
1703 ;; No, this is for a different backend, kill it
1704 (delete-region beg end)))))))
1706 (defun org-export-mark-blockquote-verse-center ()
1707 "Mark block quote and verse environments with special cookies.
1708 These special cookies will later be interpreted by the backend."
1709 ;; Blockquotes
1710 (let (type t1 ind beg end beg1 end1 content)
1711 (goto-char (point-min))
1712 (while (re-search-forward
1713 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1714 nil t)
1715 (setq ind (length (match-string 1))
1716 type (downcase (match-string 3))
1717 t1 (if (equal type "quote") "blockquote" type))
1718 (setq beg (match-beginning 0)
1719 beg1 (1+ (match-end 0)))
1720 (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
1721 (setq end1 (1- (match-beginning 0))
1722 end (+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1723 (setq content (org-remove-indentation (buffer-substring beg1 end1)))
1724 (setq content (concat "ORG-" (upcase t1) "-START\n"
1725 content "\n"
1726 "ORG-" (upcase t1) "-END\n"))
1727 (delete-region beg end)
1728 (insert (org-add-props content nil 'original-indentation ind))))))
1730 (defun org-export-mark-list-end ()
1731 "Mark all list endings with a special string."
1732 (unless (eq org-export-current-backend 'ascii)
1733 (mapc
1734 (lambda (e)
1735 ;; For each type allowing list export, find every list, remove
1736 ;; ending regexp if needed, and insert org-list-end.
1737 (goto-char (point-min))
1738 (while (re-search-forward (org-item-beginning-re) nil t)
1739 (when (eq (nth 2 (org-list-context)) e)
1740 (let* ((struct (org-list-struct))
1741 (bottom (org-list-get-bottom-point struct))
1742 (top (point-at-bol))
1743 (top-ind (org-list-get-ind top struct)))
1744 (goto-char bottom)
1745 (when (and (not (eq org-list-ending-method 'indent))
1746 (looking-at org-list-end-re))
1747 (replace-match ""))
1748 (unless (bolp) (insert "\n"))
1749 ;; As org-list-end is inserted at column 0, it would end
1750 ;; by indentation any list. It can be problematic when
1751 ;; there are lists within lists: the inner list end would
1752 ;; also become the outer list end. To avoid this, text
1753 ;; property `original-indentation' is added, as
1754 ;; `org-list-struct' pays attention to it when reading a
1755 ;; list.
1756 (insert (org-add-props
1757 "ORG-LIST-END-MARKER\n"
1758 (list 'original-indentation top-ind)))))))
1759 (cons nil org-list-export-context))))
1761 (defun org-export-mark-list-properties ()
1762 "Mark list with special properties.
1763 These special properties will later be interpreted by the backend."
1764 (let ((mark-list
1765 (function
1766 ;; Mark a list with 3 properties: `list-item' which is
1767 ;; position at beginning of line, `list-struct' which is
1768 ;; list structure, and `list-prevs' which is the alist of
1769 ;; item and its predecessor. Leave point at list ending.
1770 (lambda (ctxt)
1771 (let* ((struct (org-list-struct))
1772 (top (org-list-get-top-point struct))
1773 (bottom (org-list-get-bottom-point struct))
1774 (prevs (org-list-prevs-alist struct))
1775 poi)
1776 ;; Get every item and ending position, without dups and
1777 ;; without bottom point of list.
1778 (mapc (lambda (e)
1779 (let ((pos (car e))
1780 (end (nth 6 e)))
1781 (unless (memq pos poi)
1782 (push pos poi))
1783 (unless (or (= end bottom) (memq end poi))
1784 (push end poi))))
1785 struct)
1786 (setq poi (sort poi '<))
1787 ;; For every point of interest, mark the whole line with
1788 ;; its position in list.
1789 (mapc
1790 (lambda (e)
1791 (goto-char e)
1792 (add-text-properties (point-at-bol) (point-at-eol)
1793 (list 'list-item (point-at-bol)
1794 'list-struct struct
1795 'list-prevs prevs)))
1796 poi)
1797 ;; Take care of bottom point. As babel may have inserted
1798 ;; a new list in buffer, list ending isn't always
1799 ;; marked. Now mark every list ending and add properties
1800 ;; useful to line processing exporters.
1801 (goto-char bottom)
1802 (when (or (looking-at "^ORG-LIST-END-MARKER\n")
1803 (and (not (eq org-list-ending-method 'indent))
1804 (looking-at org-list-end-re)))
1805 (replace-match ""))
1806 (unless (bolp) (insert "\n"))
1807 (insert
1808 (org-add-props "ORG-LIST-END-MARKER\n" (list 'list-item bottom
1809 'list-struct struct
1810 'list-prevs prevs)))
1811 ;; Following property is used by LaTeX exporter.
1812 (add-text-properties top (point) (list 'list-context ctxt)))))))
1813 ;; Mark lists except for backends not interpreting them.
1814 (unless (eq org-export-current-backend 'ascii)
1815 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
1816 (mapc
1817 (lambda (e)
1818 (goto-char (point-min))
1819 (while (re-search-forward (org-item-beginning-re) nil t)
1820 (when (eq (nth 2 (org-list-context)) e) (funcall mark-list e))))
1821 (cons nil org-list-export-context))))))
1823 (defun org-export-attach-captions-and-attributes (target-alist)
1824 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1825 If the next thing following is a table, add the text properties to the first
1826 table line. If it is a link, add it to the line containing the link."
1827 (goto-char (point-min))
1828 (remove-text-properties (point-min) (point-max)
1829 '(org-caption nil org-attributes nil))
1830 (let ((case-fold-search t)
1831 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1832 "\\|"
1833 "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend) ":[ \t]+\\(.*\\)"
1834 "\\|"
1835 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1836 "\\|"
1837 "^[ \t]*\\(|[^-]\\)"
1838 "\\|"
1839 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1840 cap shortn attr label end)
1841 (while (re-search-forward re nil t)
1842 (cond
1843 ;; there is a caption
1844 ((match-end 1)
1845 (progn
1846 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1))))
1847 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap)
1848 (setq shortn (match-string 1 cap)
1849 cap (match-string 2 cap)))
1850 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1851 ;; there is an attribute
1852 ((match-end 2)
1853 (progn
1854 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2))))
1855 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1856 ;; there is a label
1857 ((match-end 3)
1858 (progn
1859 (setq label (org-trim (match-string 3)))
1860 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1862 (setq end (if (match-end 4)
1863 (let ((ee (org-table-end)))
1864 (prog1 (1- (marker-position ee)) (move-marker ee nil)))
1865 (point-at-eol)))
1866 (add-text-properties (point-at-bol) end
1867 (list 'org-caption cap
1868 'org-caption-shortn shortn
1869 'org-attributes attr
1870 'org-label label))
1871 (if label (push (cons label label) target-alist))
1872 (goto-char end)
1873 (setq cap nil attr nil label nil)))))
1874 target-alist)
1876 (defun org-export-remove-comment-blocks-and-subtrees ()
1877 "Remove the comment environment, and also commented subtrees."
1878 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1879 case-fold-search)
1880 ;; Remove comment environment
1881 (goto-char (point-min))
1882 (setq case-fold-search t)
1883 (while (re-search-forward
1884 "^#\\+begin_comment[ \t]*\n[^\000]*?\n#\\+end_comment\\>.*" nil t)
1885 (replace-match "" t t))
1886 ;; Remove subtrees that are commented
1887 (goto-char (point-min))
1888 (setq case-fold-search nil)
1889 (while (re-search-forward re-commented nil t)
1890 (goto-char (match-beginning 0))
1891 (delete-region (point) (org-end-of-subtree t)))))
1893 (defun org-export-handle-comments (commentsp)
1894 "Remove comments, or convert to backend-specific format.
1895 COMMENTSP can be a format string for publishing comments.
1896 When it is nil, all comments will be removed."
1897 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1898 pos)
1899 (goto-char (point-min))
1900 (while (or (looking-at re)
1901 (re-search-forward re nil t))
1902 (setq pos (match-beginning 0))
1903 (if (get-text-property pos 'org-protected)
1904 (goto-char (1+ pos))
1905 (if (and commentsp
1906 (not (equal (char-before (match-end 1)) ?+)))
1907 (progn (add-text-properties
1908 (match-beginning 0) (match-end 0) '(org-protected t))
1909 (replace-match (org-add-props
1910 (format commentsp (match-string 2))
1911 nil 'org-protected t)
1912 t t))
1913 (goto-char (1+ pos))
1914 (replace-match "")
1915 (goto-char (max (point-min) (1- pos))))))))
1917 (defun org-export-handle-table-metalines ()
1918 "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
1919 (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
1920 pos)
1921 (goto-char (point-min))
1922 (while (or (looking-at re)
1923 (re-search-forward re nil t))
1924 (setq pos (match-beginning 0))
1925 (if (get-text-property (match-beginning 1) 'org-protected)
1926 (goto-char (1+ pos))
1927 (goto-char (1+ pos))
1928 (replace-match "")
1929 (goto-char (max (point-min) (1- pos)))))))
1931 (defun org-export-mark-radio-links ()
1932 "Find all matches for radio targets and turn them into internal links."
1933 (let ((re-radio (and org-target-link-regexp
1934 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1935 (goto-char (point-min))
1936 (when re-radio
1937 (while (re-search-forward re-radio nil t)
1938 (unless
1939 (save-match-data
1940 (or (org-in-regexp org-bracket-link-regexp)
1941 (org-in-regexp org-plain-link-re)
1942 (org-in-regexp "<<[^<>]+>>")))
1943 (org-if-unprotected
1944 (replace-match "\\1[[\\2]]")))))))
1946 (defun org-store-forced-table-alignment ()
1947 "Find table lines which force alignment, store the results in properties."
1948 (let (line cnt aligns)
1949 (goto-char (point-min))
1950 (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t)
1951 ;; OK, this looks like a table line with an alignment cookie
1952 (org-if-unprotected
1953 (setq line (buffer-substring (point-at-bol) (point-at-eol)))
1954 (when (and (org-at-table-p)
1955 (org-table-cookie-line-p line))
1956 (setq cnt 0 aligns nil)
1957 (mapc
1958 (lambda (x)
1959 (setq cnt (1+ cnt))
1960 (if (string-match "\\`<\\([lrc]\\)" x)
1961 (push (cons cnt (downcase (match-string 1 x))) aligns)))
1962 (org-split-string line "[ \t]*|[ \t]*"))
1963 (add-text-properties (org-table-begin) (org-table-end)
1964 (list 'org-forced-aligns aligns))))
1965 (goto-char (point-at-eol)))))
1967 (defun org-export-remove-special-table-lines ()
1968 "Remove tables lines that are used for internal purposes.
1969 Also, store forced alignment information found in such lines."
1970 (goto-char (point-min))
1971 (while (re-search-forward "^[ \t]*|" nil t)
1972 (org-if-unprotected-at (1- (point))
1973 (beginning-of-line 1)
1974 (if (or (looking-at "[ \t]*| *[!_^] *|")
1975 (not
1976 (memq
1978 (mapcar
1979 (lambda (f)
1980 (or (and org-export-table-remove-empty-lines (= (length f) 0))
1981 (string-match
1982 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f)))
1983 (org-split-string ;; FIXME, can't we do without splitting???
1984 (buffer-substring (point-at-bol) (point-at-eol))
1985 "[ \t]*|[ \t]*")))))
1986 (delete-region (max (point-min) (1- (point-at-bol)))
1987 (point-at-eol))
1988 (end-of-line 1)))))
1990 (defun org-export-protect-sub-super (s)
1991 (save-match-data
1992 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s)
1993 (setq s (replace-match "\\1\\\\\\2" nil nil s)))
1996 (defun org-export-normalize-links ()
1997 "Convert all links to bracket links, and expand link abbreviations."
1998 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
1999 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
2000 nodesc)
2001 (goto-char (point-min))
2002 (while (re-search-forward re-plain-link nil t)
2003 (unless (org-string-match-p
2004 "\\[\\[\\S-+:\\S-*?\\<"
2005 (buffer-substring (point-at-bol) (match-beginning 0)))
2006 (goto-char (1- (match-end 0)))
2007 (org-if-unprotected-at (1+ (match-beginning 0))
2008 (let* ((s (concat (match-string 1)
2009 "[[" (match-string 2) ":" (match-string 3)
2010 "][" (match-string 2) ":" (org-export-protect-sub-super
2011 (match-string 3))
2012 "]]")))
2013 ;; added 'org-link face to links
2014 (put-text-property 0 (length s) 'face 'org-link s)
2015 (replace-match s t t)))))
2016 (goto-char (point-min))
2017 (while (re-search-forward re-angle-link nil t)
2018 (goto-char (1- (match-end 0)))
2019 (org-if-unprotected
2020 (let* ((s (concat (match-string 1)
2021 "[[" (match-string 2) ":" (match-string 3)
2022 "][" (match-string 2) ":" (org-export-protect-sub-super
2023 (match-string 3))
2024 "]]")))
2025 (put-text-property 0 (length s) 'face 'org-link s)
2026 (replace-match s t t))))
2027 (goto-char (point-min))
2028 (while (re-search-forward org-bracket-link-regexp nil t)
2029 (goto-char (1- (match-end 0)))
2030 (setq nodesc (not (match-end 3)))
2031 (org-if-unprotected
2032 (let* ((xx (save-match-data
2033 (org-translate-link
2034 (org-link-expand-abbrev (match-string 1)))))
2035 (s (concat
2036 "[[" (org-add-props (copy-sequence xx)
2037 nil 'org-protected t 'org-no-description nodesc)
2039 (if (match-end 3)
2040 (match-string 2)
2041 (concat "[" (copy-sequence xx)
2042 "]"))
2043 "]")))
2044 (put-text-property 0 (length s) 'face 'org-link s)
2045 (replace-match s t t))))))
2047 (defun org-export-concatenate-multiline-links ()
2048 "Find multi-line links and put it all into a single line.
2049 This is to make sure that the line-processing export backends
2050 can work correctly."
2051 (goto-char (point-min))
2052 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
2053 (org-if-unprotected-at (match-beginning 1)
2054 (replace-match "\\1 \\3")
2055 (goto-char (match-beginning 0)))))
2057 (defun org-export-concatenate-multiline-emphasis ()
2058 "Find multi-line emphasis and put it all into a single line.
2059 This is to make sure that the line-processing export backends
2060 can work correctly."
2061 (goto-char (point-min))
2062 (while (re-search-forward org-emph-re nil t)
2063 (if (and (not (= (char-after (match-beginning 3))
2064 (char-after (match-beginning 4))))
2065 (save-excursion (goto-char (match-beginning 0))
2066 (save-match-data
2067 (and (not (org-at-table-p))
2068 (not (org-at-heading-p))))))
2069 (org-if-unprotected
2070 (subst-char-in-region (match-beginning 0) (match-end 0)
2071 ?\n ?\ t)
2072 (goto-char (1- (match-end 0))))
2073 (goto-char (1+ (match-beginning 0))))))
2075 (defun org-export-grab-title-from-buffer ()
2076 "Get a title for the current document, from looking at the buffer."
2077 (let ((inhibit-read-only t))
2078 (save-excursion
2079 (goto-char (point-min))
2080 (let ((end (if (looking-at org-outline-regexp)
2081 (point)
2082 (save-excursion (outline-next-heading) (point)))))
2083 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
2084 ;; Mark the line so that it will not be exported as normal text.
2085 (org-unmodified
2086 (add-text-properties (match-beginning 0) (match-end 0)
2087 (list :org-license-to-kill t)))
2088 ;; Return the title string
2089 (org-trim (match-string 0)))))))
2091 (defun org-export-get-title-from-subtree ()
2092 "Return subtree title and exclude it from export."
2093 (let ((rbeg (region-beginning)) (rend (region-end))
2094 (inhibit-read-only t) title)
2095 (save-excursion
2096 (goto-char rbeg)
2097 (when (and (org-at-heading-p)
2098 (>= (org-end-of-subtree t t) rend))
2099 ;; This is a subtree, we take the title from the first heading
2100 (goto-char rbeg)
2101 (looking-at org-todo-line-regexp)
2102 (setq title (match-string 3))
2103 (org-unmodified
2104 (add-text-properties (point) (1+ (point-at-eol))
2105 (list :org-license-to-kill t)))
2106 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
2107 title))
2109 (defun org-solidify-link-text (s &optional alist)
2110 "Take link text and make a safe target out of it."
2111 (save-match-data
2112 (let* ((rtn
2113 (mapconcat
2114 'identity
2115 (org-split-string s "[^a-zA-Z0-9_\\.-]+") "-"))
2116 (a (assoc rtn alist)))
2117 (or (cdr a) rtn))))
2119 (defun org-get-min-level (lines &optional offset)
2120 "Get the minimum level in LINES."
2121 (let ((re "^\\(\\*+\\) ") l)
2122 (catch 'exit
2123 (while (setq l (pop lines))
2124 (if (string-match re l)
2125 (throw 'exit (org-tr-level (- (length (match-string 1 l))
2126 (or offset 0))))))
2127 1)))
2129 ;; Variable holding the vector with section numbers
2130 (defvar org-section-numbers (make-vector org-level-max 0))
2132 (defun org-init-section-numbers ()
2133 "Initialize the vector for the section numbers."
2134 (let* ((level -1)
2135 (numbers (nreverse (org-split-string "" "\\.")))
2136 (depth (1- (length org-section-numbers)))
2137 (i depth) number-string)
2138 (while (>= i 0)
2139 (if (> i level)
2140 (aset org-section-numbers i 0)
2141 (setq number-string (or (car numbers) "0"))
2142 (if (string-match "\\`[A-Z]\\'" number-string)
2143 (aset org-section-numbers i
2144 (- (string-to-char number-string) ?A -1))
2145 (aset org-section-numbers i (string-to-number number-string)))
2146 (pop numbers))
2147 (setq i (1- i)))))
2149 (defun org-section-number (&optional level)
2150 "Return a string with the current section number.
2151 When LEVEL is non-nil, increase section numbers on that level."
2152 (let* ((depth (1- (length org-section-numbers)))
2153 (string "")
2154 (fmts (car org-export-section-number-format))
2155 (term (cdr org-export-section-number-format))
2156 (sep "")
2157 ctype fmt idx n)
2158 (when level
2159 (when (> level -1)
2160 (aset org-section-numbers
2161 level (1+ (aref org-section-numbers level))))
2162 (setq idx (1+ level))
2163 (while (<= idx depth)
2164 (if (not (= idx 1))
2165 (aset org-section-numbers idx 0))
2166 (setq idx (1+ idx))))
2167 (setq idx 0)
2168 (while (<= idx depth)
2169 (when (> (aref org-section-numbers idx) 0)
2170 (setq fmt (or (pop fmts) fmt)
2171 ctype (car fmt)
2172 n (aref org-section-numbers idx)
2173 string (if (> n 0)
2174 (concat string sep (org-number-to-counter n ctype))
2175 (concat string ".0"))
2176 sep (nth 1 fmt)))
2177 (setq idx (1+ idx)))
2178 (save-match-data
2179 (if (string-match "\\`\\([@0]\\.\\)+" string)
2180 (setq string (replace-match "" t nil string)))
2181 (if (string-match "\\(\\.0\\)+\\'" string)
2182 (setq string (replace-match "" t nil string))))
2183 (concat string term)))
2185 (defun org-number-to-counter (n type)
2186 "Concert number N to a string counter, according to TYPE.
2187 TYPE must be a string, any of:
2188 1 number
2189 A A,B,....
2190 a a,b,....
2191 I upper case roman numeral
2192 i lower case roman numeral"
2193 (cond
2194 ((equal type "1") (number-to-string n))
2195 ((equal type "A") (char-to-string (+ ?A n -1)))
2196 ((equal type "a") (char-to-string (+ ?a n -1)))
2197 ((equal type "I") (org-number-to-roman n))
2198 ((equal type "i") (downcase (org-number-to-roman n)))
2199 (t (error "Invalid counter type `%s'" type))))
2201 (defun org-number-to-roman (n)
2202 "Convert integer N into a roman numeral."
2203 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2204 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2205 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2206 ( 1 . "I")))
2207 (res ""))
2208 (if (<= n 0)
2209 (number-to-string n)
2210 (while roman
2211 (if (>= n (caar roman))
2212 (setq n (- n (caar roman))
2213 res (concat res (cdar roman)))
2214 (pop roman)))
2215 res)))
2217 ;;; Macros
2219 (defun org-export-preprocess-apply-macros ()
2220 "Replace macro references."
2221 (goto-char (point-min))
2222 (let (sy val key args args2 s n)
2223 (while (re-search-forward
2224 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2225 nil t)
2226 (unless (save-match-data
2227 (save-excursion
2228 (goto-char (point-at-bol))
2229 (looking-at "[ \t]*#\\+macro")))
2230 (setq key (downcase (match-string 1))
2231 args (match-string 3))
2232 (when (setq val (or (plist-get org-export-opt-plist
2233 (intern (concat ":macro-" key)))
2234 (plist-get org-export-opt-plist
2235 (intern (concat ":" key)))))
2236 (save-match-data
2237 (when args
2238 (setq args (org-split-string args ",") args2 nil)
2239 (while args
2240 (while (string-match "\\\\\\'" (car args))
2241 ;; repair bad splits
2242 (setcar (cdr args) (concat (substring (car args) 0 -1)
2243 "," (nth 1 args)))
2244 (pop args))
2245 (push (pop args) args2))
2246 (setq args (mapcar 'org-trim (nreverse args2)))
2247 (setq s 0)
2248 (while (string-match "\\$\\([0-9]+\\)" val s)
2249 (setq s (1+ (match-beginning 0))
2250 n (string-to-number (match-string 1 val)))
2251 (and (>= (length args) n)
2252 (setq val (replace-match (nth (1- n) args) t t val)))))
2253 (when (string-match "\\`(eval\\>" val)
2254 (setq val (eval (read val))))
2255 (if (and val (not (stringp val)))
2256 (setq val (format "%s" val))))
2257 (and (stringp val)
2258 (prog1 (replace-match val t t)
2259 (goto-char (match-beginning 0)))))))))
2261 (defun org-export-apply-macros-in-string (s)
2262 "Apply the macros in string S."
2263 (when s
2264 (with-temp-buffer
2265 (insert s)
2266 (org-export-preprocess-apply-macros)
2267 (buffer-string))))
2269 ;;; Include files
2271 (defun org-export-handle-include-files ()
2272 "Include the contents of include files, with proper formatting."
2273 (let ((case-fold-search t)
2274 params file markup lang start end prefix prefix1 switches all minlevel lines)
2275 (goto-char (point-min))
2276 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2277 (setq params (read (concat "(" (match-string 1) ")"))
2278 prefix (org-get-and-remove-property 'params :prefix)
2279 prefix1 (org-get-and-remove-property 'params :prefix1)
2280 minlevel (org-get-and-remove-property 'params :minlevel)
2281 lines (org-get-and-remove-property 'params :lines)
2282 file (org-symname-or-string (pop params))
2283 markup (org-symname-or-string (pop params))
2284 lang (and (member markup '("src" "SRC"))
2285 (org-symname-or-string (pop params)))
2286 switches (mapconcat '(lambda (x) (format "%s" x)) params " ")
2287 start nil end nil)
2288 (delete-region (match-beginning 0) (match-end 0))
2289 (if (or (not file)
2290 (not (file-exists-p file))
2291 (not (file-readable-p file)))
2292 (insert (format "CANNOT INCLUDE FILE %s" file))
2293 (setq all (cons file all))
2294 (when markup
2295 (if (equal (downcase markup) "src")
2296 (setq start (format "#+begin_src %s %s\n"
2297 (or lang "fundamental")
2298 (or switches ""))
2299 end "#+end_src")
2300 (setq start (format "#+begin_%s %s\n" markup switches)
2301 end (format "#+end_%s" markup))))
2302 (insert (or start ""))
2303 (insert (org-get-file-contents (expand-file-name file)
2304 prefix prefix1 markup minlevel lines))
2305 (or (bolp) (newline))
2306 (insert (or end ""))))
2307 all))
2309 (defun org-export-handle-include-files-recurse ()
2310 "Recursively include files aborting on circular inclusion."
2311 (let ((now (list org-current-export-file)) all)
2312 (while now
2313 (setq all (append now all))
2314 (setq now (org-export-handle-include-files))
2315 (let ((intersection
2316 (delq nil
2317 (mapcar (lambda (el) (when (member el all) el)) now))))
2318 (when intersection
2319 (error "Recursive #+INCLUDE: %S" intersection))))))
2321 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel lines)
2322 "Get the contents of FILE and return them as a string.
2323 If PREFIX is a string, prepend it to each line. If PREFIX1
2324 is a string, prepend it to the first line instead of PREFIX.
2325 If MARKUP, don't protect org-like lines, the exporter will
2326 take care of the block they are in. If LINES is a string
2327 specifying a range of lines, include only those lines ."
2328 (if (stringp markup) (setq markup (downcase markup)))
2329 (with-temp-buffer
2330 (insert-file-contents file)
2331 (when lines
2332 (let* ((lines (split-string lines "-"))
2333 (lbeg (string-to-number (car lines)))
2334 (lend (string-to-number (cadr lines)))
2335 (beg (if (zerop lbeg) (point-min)
2336 (goto-char (point-min))
2337 (forward-line (1- lbeg))
2338 (point)))
2339 (end (if (zerop lend) (point-max)
2340 (goto-char (point-min))
2341 (forward-line (1- lend))
2342 (point))))
2343 (narrow-to-region beg end)))
2344 (when (or prefix prefix1)
2345 (goto-char (point-min))
2346 (while (not (eobp))
2347 (insert (or prefix1 prefix))
2348 (setq prefix1 "")
2349 (beginning-of-line 2)))
2350 (buffer-string)
2351 (when (member markup '("src" "example"))
2352 (goto-char (point-min))
2353 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t)
2354 (goto-char (match-beginning 0))
2355 (insert ",")
2356 (end-of-line 1)))
2357 (when minlevel
2358 (dotimes (lvl minlevel)
2359 (org-map-region 'org-demote (point-min) (point-max))))
2360 (buffer-string)))
2362 (defun org-get-and-remove-property (listvar prop)
2363 "Check if the value of LISTVAR contains PROP as a property.
2364 If yes, return the value of that property (i.e. the element following
2365 in the list) and remove property and value from the list in LISTVAR."
2366 (let ((list (symbol-value listvar)) m v)
2367 (when (setq m (member prop list))
2368 (setq v (nth 1 m))
2369 (if (equal (car list) prop)
2370 (set listvar (cddr list))
2371 (setcdr (nthcdr (- (length list) (length m) 1) list)
2372 (cddr m))
2373 (set listvar list)))
2376 (defun org-symname-or-string (s)
2377 (if (symbolp s)
2378 (if s (symbol-name s) s)
2381 ;;; Fontification and line numbers for code examples
2383 (defvar org-export-last-code-line-counter-value 0)
2385 (defun org-export-replace-src-segments-and-examples ()
2386 "Replace source code segments with special code for export."
2387 (setq org-export-last-code-line-counter-value 0)
2388 (let ((case-fold-search t)
2389 lang code trans opts indent caption)
2390 (goto-char (point-min))
2391 (while (re-search-forward
2392 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2393 nil t)
2394 (if (match-end 1)
2395 (if (not (match-string 4))
2396 (error "Source block missing language specification: %s"
2397 (let* ((body (match-string 6))
2398 (nothing (message "body:%s" body))
2399 (preview (or (and (string-match
2400 "^[ \t]*\\([^\n\r]*\\)" body)
2401 (match-string 1 body)) body)))
2402 (if (> (length preview) 35)
2403 (concat (substring preview 0 32) "...")
2404 preview)))
2405 ;; src segments
2406 (setq lang (match-string 4)
2407 opts (match-string 5)
2408 code (match-string 6)
2409 indent (length (match-string 2))
2410 caption (get-text-property 0 'org-caption (match-string 0))))
2411 (setq lang nil
2412 opts (match-string 9)
2413 code (match-string 10)
2414 indent (length (match-string 8))
2415 caption (get-text-property 0 'org-caption (match-string 0))))
2417 (setq trans (org-export-format-source-code-or-example
2418 lang code opts indent caption))
2419 (replace-match trans t t))))
2421 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
2422 (defvar org-export-latex-listings) ;; defined in org-latex.el
2423 (defvar org-export-latex-listings-langs) ;; defined in org-latex.el
2424 (defvar org-export-latex-listings-w-names) ;; defined in org-latex.el
2425 (defvar org-export-latex-minted-langs) ;; defined in org-latex.el
2426 (defvar org-export-latex-custom-lang-environments) ;; defined in org-latex.el
2427 (defvar org-export-latex-listings-options) ;; defined in org-latex.el
2428 (defvar org-export-latex-minted-options) ;; defined in org-latex.el
2430 (defun org-export-format-source-code-or-example
2431 (lang code &optional opts indent caption)
2432 "Format CODE from language LANG and return it formatted for export.
2433 If LANG is nil, do not add any fontification.
2434 OPTS contains formatting options, like `-n' for triggering numbering lines,
2435 and `+n' for continuing previous numbering.
2436 Code formatting according to language currently only works for HTML.
2437 Numbering lines works for all three major backends (html, latex, and ascii).
2438 INDENT was the original indentation of the block."
2439 (save-match-data
2440 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
2441 (setq opts (or opts "")
2442 num (string-match "[-+]n\\>" opts)
2443 cont (string-match "\\+n\\>" opts)
2444 rpllbl (string-match "-r\\>" opts)
2445 keepp (string-match "-k\\>" opts)
2446 textareap (string-match "-t\\>" opts)
2447 preserve-indentp (or org-src-preserve-indentation
2448 (string-match "-i\\>" opts))
2449 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2450 (string-to-number (match-string 1 opts))
2452 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2453 (string-to-number (match-string 1 opts))
2454 (org-count-lines code))
2455 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2456 (match-string 1 opts)))
2457 (when (and textareap (eq org-export-current-backend 'html))
2458 ;; we cannot use numbering or highlighting.
2459 (setq num nil cont nil lang nil))
2460 (if keepp (setq rpllbl 'keep))
2461 (setq rtn (if preserve-indentp code (org-remove-indentation code)))
2462 (when (string-match "^," rtn)
2463 (setq rtn (with-temp-buffer
2464 (insert rtn)
2465 ;; Free up the protected lines
2466 (goto-char (point-min))
2467 (while (re-search-forward "^," nil t)
2468 (if (or (equal lang "org")
2469 (save-match-data
2470 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2471 (replace-match ""))
2472 (end-of-line 1))
2473 (buffer-string))))
2474 ;; Now backend-specific coding
2475 (setq rtn
2476 (cond
2477 ((eq org-export-current-backend 'docbook)
2478 (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
2479 (concat "\n#+BEGIN_DOCBOOK\n"
2480 (org-add-props (concat "<programlisting><![CDATA["
2482 "]]></programlisting>\n")
2483 '(org-protected t org-example t))
2484 "#+END_DOCBOOK\n"))
2485 ((eq org-export-current-backend 'html)
2486 ;; We are exporting to HTML
2487 (when lang
2488 (if (featurep 'xemacs)
2489 (require 'htmlize)
2490 (require 'htmlize nil t))
2491 (when (not (fboundp 'htmlize-region-for-paste))
2492 ;; we do not have htmlize.el, or an old version of it
2493 (setq lang nil)
2494 (message
2495 "htmlize.el 1.34 or later is needed for source code formatting")))
2497 (if lang
2498 (let* ((lang-m (when lang
2499 (or (cdr (assoc lang org-src-lang-modes))
2500 lang)))
2501 (mode (and lang-m (intern
2502 (concat
2503 (if (symbolp lang-m)
2504 (symbol-name lang-m)
2505 lang-m)
2506 "-mode"))))
2507 (org-inhibit-startup t)
2508 (org-startup-folded nil))
2509 (setq rtn
2510 (with-temp-buffer
2511 (insert rtn)
2512 (if (functionp mode)
2513 (funcall mode)
2514 (fundamental-mode))
2515 (font-lock-fontify-buffer)
2516 (org-src-mode)
2517 (set-buffer-modified-p nil)
2518 (org-export-htmlize-region-for-paste
2519 (point-min) (point-max))))
2520 (if (string-match "<pre\\([^>]*\\)>\n*" rtn)
2521 (setq rtn
2522 (concat
2523 (if caption
2524 (concat
2525 "<div class=\"org-src-container\">"
2526 (format
2527 "<label class=\"org-src-name\">%s</label>"
2528 caption))
2530 (replace-match
2531 (format "<pre class=\"src src-%s\">\n" lang)
2532 t t rtn)
2533 (if caption "</div>" "")))))
2534 (if textareap
2535 (setq rtn (concat
2536 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2537 cols rows)
2538 rtn "</textarea>\n</p>\n"))
2539 (with-temp-buffer
2540 (insert rtn)
2541 (goto-char (point-min))
2542 (while (re-search-forward "[<>&]" nil t)
2543 (replace-match (cdr (assq (char-before)
2544 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2545 t t))
2546 (setq rtn (buffer-string)))
2547 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2548 (unless textareap
2549 (setq rtn (org-export-number-lines rtn 1 1 num cont rpllbl fmt)))
2550 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn)
2551 (setq rtn (replace-match "\\1" t nil rtn)))
2552 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t org-example t)) "\n#+END_HTML\n\n"))
2553 ((eq org-export-current-backend 'latex)
2554 (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
2555 (concat
2556 "#+BEGIN_LaTeX\n"
2557 (org-add-props
2558 (cond
2559 ((and lang org-export-latex-listings)
2560 (flet ((make-option-string
2561 (pair)
2562 (concat (first pair)
2563 (if (> (length (second pair)) 0)
2564 (concat "=" (second pair))))))
2565 (let* ((lang-sym (intern lang))
2566 (minted-p (eq org-export-latex-listings 'minted))
2567 (listings-p (not minted-p))
2568 (backend-lang
2569 (or (cadr
2570 (assq
2571 lang-sym
2572 (cond
2573 (minted-p org-export-latex-minted-langs)
2574 (listings-p org-export-latex-listings-langs))))
2575 lang))
2576 (custom-environment
2577 (cadr
2578 (assq
2579 lang-sym
2580 org-export-latex-custom-lang-environments))))
2581 (concat
2582 (when (and listings-p (not custom-environment))
2583 (format
2584 "\\lstset{%s}\n"
2585 (mapconcat
2586 #'make-option-string
2587 (append org-export-latex-listings-options
2588 `(("language" ,backend-lang))) ",")))
2589 (when (and caption org-export-latex-listings-w-names)
2590 (format
2591 "\n%s $\\equiv$ \n"
2592 (replace-regexp-in-string "_" "\\\\_" caption)))
2593 (cond
2594 (custom-environment
2595 (format "\\begin{%s}\n%s\\end{%s}\n"
2596 custom-environment rtn custom-environment))
2597 (listings-p
2598 (format "\\begin{%s}\n%s\\end{%s}\n"
2599 "lstlisting" rtn "lstlisting"))
2600 (minted-p
2601 (format
2602 "\\begin{minted}[%s]{%s}\n%s\\end{minted}\n"
2603 (mapconcat #'make-option-string
2604 org-export-latex-minted-options ",")
2605 backend-lang rtn)))))))
2606 (t (concat (car org-export-latex-verbatim-wrap)
2607 rtn (cdr org-export-latex-verbatim-wrap))))
2608 '(org-protected t org-example t))
2609 "#+END_LaTeX\n"))
2610 ((eq org-export-current-backend 'ascii)
2611 ;; This is not HTML or LaTeX, so just make it an example.
2612 (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
2613 (concat caption "\n"
2614 "#+BEGIN_ASCII\n"
2615 (org-add-props
2616 (concat
2617 (mapconcat
2618 (lambda (l) (concat " " l))
2619 (org-split-string rtn "\n")
2620 "\n")
2621 "\n")
2622 '(org-protected t org-example t))
2623 "#+END_ASCII\n"))))
2624 (org-add-props rtn nil 'original-indentation indent))))
2626 (defun org-export-number-lines (text &optional skip1 skip2 number cont
2627 replace-labels label-format)
2628 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2629 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2630 (with-temp-buffer
2631 (insert text)
2632 (goto-char (point-max))
2633 (skip-chars-backward " \t\n\r")
2634 (delete-region (point) (point-max))
2635 (beginning-of-line (- 1 skip2))
2636 (let* ((last (org-current-line))
2637 (n org-export-last-code-line-counter-value)
2638 (nmax (+ n (- last skip1)))
2639 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2641 (cond
2642 ((eq org-export-current-backend 'html) (format "<span class=\"linenr\">%s</span>"
2643 fmt))
2644 ((eq org-export-current-backend 'ascii) fmt)
2645 ((eq org-export-current-backend 'latex) fmt)
2646 ((eq org-export-current-backend 'docbook) fmt)
2647 (t "")))
2648 (label-format (or label-format org-coderef-label-format))
2649 (label-pre (if (string-match "%s" label-format)
2650 (substring label-format 0 (match-beginning 0))
2651 label-format))
2652 (label-post (if (string-match "%s" label-format)
2653 (substring label-format (match-end 0))
2654 ""))
2655 (lbl-re
2656 (concat
2657 ".*?\\S-.*?\\([ \t]*\\("
2658 (regexp-quote label-pre)
2659 "\\([-a-zA-Z0-9_ ]+\\)"
2660 (regexp-quote label-post)
2661 "\\)\\)"))
2662 ref)
2664 (org-goto-line (1+ skip1))
2665 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2666 (if number
2667 (insert (format fm (incf n)))
2668 (forward-char 1))
2669 (when (looking-at lbl-re)
2670 (setq ref (match-string 3))
2671 (cond ((numberp replace-labels)
2672 ;; remove labels; use numbers for references when lines
2673 ;; are numbered, use labels otherwise
2674 (delete-region (match-beginning 1) (match-end 1))
2675 (push (cons ref (if (> n 0) n ref)) org-export-code-refs))
2676 ((eq replace-labels 'keep)
2677 ;; don't remove labels; use numbers for references when
2678 ;; lines are numbered, use labels otherwise
2679 (goto-char (match-beginning 2))
2680 (delete-region (match-beginning 2) (match-end 2))
2681 (insert "(" ref ")")
2682 (push (cons ref (if (> n 0) n (concat "(" ref ")")))
2683 org-export-code-refs))
2685 ;; don't remove labels and don't use numbers for
2686 ;; references
2687 (goto-char (match-beginning 2))
2688 (delete-region (match-beginning 2) (match-end 2))
2689 (insert "(" ref ")")
2690 (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
2691 (when (eq org-export-current-backend 'html)
2692 (save-excursion
2693 (beginning-of-line 1)
2694 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2695 ref))
2696 (end-of-line 1)
2697 (insert "</span>")))))
2698 (setq org-export-last-code-line-counter-value n)
2699 (goto-char (point-max))
2700 (newline)
2701 (buffer-string))))
2703 (defun org-search-todo-below (line lines level)
2704 "Search the subtree below LINE for any TODO entries."
2705 (let ((rest (cdr (memq line lines)))
2706 (re org-todo-line-regexp)
2707 line lv todo)
2708 (catch 'exit
2709 (while (setq line (pop rest))
2710 (if (string-match re line)
2711 (progn
2712 (setq lv (- (match-end 1) (match-beginning 1))
2713 todo (and (match-beginning 2)
2714 (not (member (match-string 2 line)
2715 org-done-keywords))))
2716 ; TODO, not DONE
2717 (if (<= lv level) (throw 'exit nil))
2718 (if todo (throw 'exit t))))))))
2720 ;;;###autoload
2721 (defun org-export-visible (type arg)
2722 "Create a copy of the visible part of the current buffer, and export it.
2723 The copy is created in a temporary buffer and removed after use.
2724 TYPE is the final key (as a string) that also selects the export command in
2725 the \\<org-mode-map>\\[org-export] export dispatcher.
2726 As a special case, if the you type SPC at the prompt, the temporary
2727 org-mode file will not be removed but presented to you so that you can
2728 continue to use it. The prefix arg ARG is passed through to the exporting
2729 command."
2730 (interactive
2731 (list (progn
2732 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]buffer with HTML [D]ocBook [l]atex [p]df [d]view pdf [L]atex buffer [x]OXO [ ]keep buffer")
2733 (read-char-exclusive))
2734 current-prefix-arg))
2735 (if (not (member type '(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L ?H ?R)))
2736 (error "Invalid export key"))
2737 (let* ((binding (cdr (assoc type
2739 (?a . org-export-as-ascii)
2740 (?A . org-export-as-ascii-to-buffer)
2741 (?n . org-export-as-latin1)
2742 (?N . org-export-as-latin1-to-buffer)
2743 (?u . org-export-as-utf8)
2744 (?U . org-export-as-utf8-to-buffer)
2745 (?\C-a . org-export-as-ascii)
2746 (?b . org-export-as-html-and-open)
2747 (?\C-b . org-export-as-html-and-open)
2748 (?h . org-export-as-html)
2749 (?H . org-export-as-html-to-buffer)
2750 (?R . org-export-region-as-html)
2751 (?D . org-export-as-docbook)
2753 (?l . org-export-as-latex)
2754 (?p . org-export-as-pdf)
2755 (?d . org-export-as-pdf-and-open)
2756 (?L . org-export-as-latex-to-buffer)
2758 (?x . org-export-as-xoxo)))))
2759 (keepp (equal type ?\ ))
2760 (file buffer-file-name)
2761 (buffer (get-buffer-create "*Org Export Visible*"))
2762 s e)
2763 ;; Need to hack the drawers here.
2764 (save-excursion
2765 (goto-char (point-min))
2766 (while (re-search-forward org-drawer-regexp nil t)
2767 (goto-char (match-beginning 1))
2768 (or (outline-invisible-p) (org-flag-drawer nil))))
2769 (with-current-buffer buffer (erase-buffer))
2770 (save-excursion
2771 (setq s (goto-char (point-min)))
2772 (while (not (= (point) (point-max)))
2773 (goto-char (org-find-invisible))
2774 (append-to-buffer buffer s (point))
2775 (setq s (goto-char (org-find-visible))))
2776 (org-cycle-hide-drawers 'all)
2777 (goto-char (point-min))
2778 (unless keepp
2779 ;; Copy all comment lines to the end, to make sure #+ settings are
2780 ;; still available for the second export step. Kind of a hack, but
2781 ;; does do the trick.
2782 (if (looking-at "#[^\r\n]*")
2783 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2784 (when (re-search-forward "^\\*+[ \t]+" nil t)
2785 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t)
2786 (append-to-buffer buffer (1+ (match-beginning 0))
2787 (min (point-max) (1+ (match-end 0)))))))
2788 (set-buffer buffer)
2789 (let ((buffer-file-name file)
2790 (org-inhibit-startup t))
2791 (org-mode)
2792 (show-all)
2793 (unless keepp (funcall binding arg))))
2794 (if (not keepp)
2795 (kill-buffer buffer)
2796 (switch-to-buffer-other-window buffer)
2797 (goto-char (point-min)))))
2799 (defun org-find-visible ()
2800 (let ((s (point)))
2801 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2802 (get-char-property s 'invisible)))
2804 (defun org-find-invisible ()
2805 (let ((s (point)))
2806 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2807 (not (get-char-property s 'invisible))))
2810 (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
2812 (defun org-export-string (string fmt &optional dir)
2813 "Export STRING to FMT using existing export facilities.
2814 During export STRING is saved to a temporary file whose location
2815 could vary. Optional argument DIR can be used to force the
2816 directory in which the temporary file is created during export
2817 which can be useful for resolving relative paths. Dir defaults
2818 to the value of `temporary-file-directory'."
2819 (let ((temporary-file-directory (or dir temporary-file-directory))
2820 (tmp-file (make-temp-file "org-")))
2821 (unwind-protect
2822 (with-temp-buffer
2823 (insert string)
2824 (write-file tmp-file)
2825 (org-load-modules-maybe)
2826 (unless org-local-vars
2827 (setq org-local-vars (org-get-local-variables)))
2828 (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
2829 (list 'let org-local-vars
2830 (list (intern (format "org-export-as-%s" fmt))
2831 nil nil nil ''string t))))
2832 (delete-file tmp-file))))
2834 ;;;###autoload
2835 (defun org-export-as-org (arg &optional hidden ext-plist
2836 to-buffer body-only pub-dir)
2837 "Make a copy with not-exporting stuff removed.
2838 The purpose of this function is to provide a way to export the source
2839 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2840 stuff removed. This command will remove the following:
2842 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2843 - comment blocks and trees starting with the COMMENT keyword
2844 - only trees that are consistent with `org-export-select-tags'
2845 and `org-export-exclude-tags'.
2847 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2848 all the others will be ignored (but are present so that the general
2849 mechanism to call publishing functions will work).
2851 EXT-PLIST is a property list with external parameters overriding
2852 org-mode's default settings, but still inferior to file-local
2853 settings. When PUB-DIR is set, use this as the publishing
2854 directory."
2855 (interactive "P")
2856 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2857 ext-plist
2858 (org-infile-export-plist)))
2859 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2860 (filename (concat (file-name-as-directory
2861 (or pub-dir
2862 (org-export-directory :org opt-plist)))
2863 (file-name-sans-extension
2864 (file-name-nondirectory bfname))
2865 ".org"))
2866 (filename (and filename
2867 (if (equal (file-truename filename)
2868 (file-truename bfname))
2869 (concat (file-name-sans-extension filename)
2870 "-source."
2871 (file-name-extension filename))
2872 filename)))
2873 (backup-inhibited t)
2874 (buffer (find-file-noselect filename))
2875 (region (buffer-string))
2876 str-ret)
2877 (save-excursion
2878 (switch-to-buffer buffer)
2879 (erase-buffer)
2880 (insert region)
2881 (let ((org-inhibit-startup t)) (org-mode))
2882 (org-install-letbind)
2884 ;; Get rid of archived trees
2885 (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
2887 ;; Remove comment environment and comment subtrees
2888 (org-export-remove-comment-blocks-and-subtrees)
2890 ;; Get rid of excluded trees
2891 (org-export-handle-export-tags (plist-get opt-plist :select-tags)
2892 (plist-get opt-plist :exclude-tags))
2894 (when (or (plist-get opt-plist :plain-source)
2895 (not (or (plist-get opt-plist :plain-source)
2896 (plist-get opt-plist :htmlized-source))))
2897 ;; Either nothing special is requested (default call)
2898 ;; or the plain source is explicitly requested
2899 ;; so: save it
2900 (save-buffer))
2901 (when (plist-get opt-plist :htmlized-source)
2902 ;; Make the htmlized version
2903 (require 'htmlize)
2904 (require 'org-html)
2905 (font-lock-fontify-buffer)
2906 (let* ((htmlize-output-type 'css)
2907 (newbuf (htmlize-buffer)))
2908 (with-current-buffer newbuf
2909 (when org-export-htmlized-org-css-url
2910 (goto-char (point-min))
2911 (and (re-search-forward
2912 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2913 nil t)
2914 (replace-match
2915 (format
2916 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2917 org-export-htmlized-org-css-url)
2918 t t)))
2919 (write-file (concat filename ".html")))
2920 (kill-buffer newbuf)))
2921 (set-buffer-modified-p nil)
2922 (if (equal to-buffer 'string)
2923 (progn (setq str-ret (buffer-string))
2924 (kill-buffer (current-buffer))
2925 str-ret)
2926 (kill-buffer (current-buffer))))))
2928 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2929 (defun org-get-current-options ()
2930 "Return a string with current options as keyword options.
2931 Does include HTML export options as well as TODO and CATEGORY stuff."
2932 (require 'org-archive)
2933 (format
2934 "#+TITLE: %s
2935 #+AUTHOR: %s
2936 #+EMAIL: %s
2937 #+DATE: %s
2938 #+DESCRIPTION:
2939 #+KEYWORDS:
2940 #+LANGUAGE: %s
2941 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2942 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2944 #+EXPORT_SELECT_TAGS: %s
2945 #+EXPORT_EXCLUDE_TAGS: %s
2946 #+LINK_UP: %s
2947 #+LINK_HOME: %s
2948 #+XSLT:
2949 #+CATEGORY: %s
2950 #+SEQ_TODO: %s
2951 #+TYP_TODO: %s
2952 #+PRIORITIES: %c %c %c
2953 #+DRAWERS: %s
2954 #+STARTUP: %s %s %s %s %s
2955 #+TAGS: %s
2956 #+FILETAGS: %s
2957 #+ARCHIVE: %s
2958 #+LINK: %s
2960 (buffer-name) (user-full-name) user-mail-address
2961 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2962 org-export-default-language
2963 org-export-headline-levels
2964 org-export-with-section-numbers
2965 org-export-with-toc
2966 org-export-preserve-breaks
2967 org-export-html-expand
2968 org-export-with-fixed-width
2969 org-export-with-tables
2970 org-export-with-sub-superscripts
2971 org-export-with-special-strings
2972 org-export-with-footnotes
2973 org-export-with-emphasize
2974 org-export-with-timestamps
2975 org-export-with-TeX-macros
2976 org-export-with-LaTeX-fragments
2977 org-export-skip-text-before-1st-heading
2978 org-export-with-drawers
2979 org-export-with-todo-keywords
2980 org-export-with-priority
2981 org-export-with-tags
2982 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2983 (mapconcat 'identity org-export-select-tags " ")
2984 (mapconcat 'identity org-export-exclude-tags " ")
2985 org-export-html-link-up
2986 org-export-html-link-home
2987 (or (ignore-errors
2988 (file-name-sans-extension
2989 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2990 "NOFILENAME")
2991 "TODO FEEDBACK VERIFY DONE"
2992 "Me Jason Marie DONE"
2993 org-highest-priority org-lowest-priority org-default-priority
2994 (mapconcat 'identity org-drawers " ")
2995 (cdr (assoc org-startup-folded
2996 '((nil . "showall") (t . "overview") (content . "content"))))
2997 (if org-odd-levels-only "odd" "oddeven")
2998 (if org-hide-leading-stars "hidestars" "showstars")
2999 (if org-startup-align-all-tables "align" "noalign")
3000 (cond ((eq org-log-done t) "logdone")
3001 ((equal org-log-done 'note) "lognotedone")
3002 ((not org-log-done) "nologdone"))
3003 (or (mapconcat (lambda (x)
3004 (cond
3005 ((equal :startgroup (car x)) "{")
3006 ((equal :endgroup (car x)) "}")
3007 ((equal :newline (car x)) "")
3008 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
3009 (t (car x))))
3010 (or org-tag-alist (org-get-buffer-tags)) " ") "")
3011 (mapconcat 'identity org-file-tags " ")
3012 org-archive-location
3013 "org file:~/org/%s.org"
3016 ;;;###autoload
3017 (defun org-insert-export-options-template ()
3018 "Insert into the buffer a template with information for exporting."
3019 (interactive)
3020 (if (not (bolp)) (newline))
3021 (let ((s (org-get-current-options)))
3022 (and (string-match "#\\+CATEGORY" s)
3023 (setq s (substring s 0 (match-beginning 0))))
3024 (insert s)))
3026 (defvar org-table-colgroup-info nil)
3028 (defun org-table-clean-before-export (lines &optional maybe-quoted)
3029 "Check if the table has a marking column.
3030 If yes remove the column and the special lines."
3031 (setq org-table-colgroup-info nil)
3032 (if (memq nil
3033 (mapcar
3034 (lambda (x) (or (string-match "^[ \t]*|-" x)
3035 (string-match
3036 (if maybe-quoted
3037 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
3038 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
3039 x)))
3040 lines))
3041 ;; No special marking column
3042 (progn
3043 (setq org-table-clean-did-remove-column nil)
3044 (delq nil
3045 (mapcar
3046 (lambda (x)
3047 (cond
3048 ((org-table-colgroup-line-p x)
3049 ;; This line contains colgroup info, extract it
3050 ;; and then discard the line
3051 (setq org-table-colgroup-info
3052 (mapcar (lambda (x)
3053 (cond ((member x '("<" "&lt;")) :start)
3054 ((member x '(">" "&gt;")) :end)
3055 ((member x '("<>" "&lt;&gt;")) :startend)
3056 (t nil)))
3057 (org-split-string x "[ \t]*|[ \t]*")))
3058 nil)
3059 ((org-table-cookie-line-p x)
3060 ;; This line contains formatting cookies, discard it
3061 nil)
3062 (t x)))
3063 lines)))
3064 ;; there is a special marking column
3065 (setq org-table-clean-did-remove-column t)
3066 (delq nil
3067 (mapcar
3068 (lambda (x)
3069 (cond
3070 ((org-table-colgroup-line-p x)
3071 ;; This line contains colgroup info, extract it
3072 ;; and then discard the line
3073 (setq org-table-colgroup-info
3074 (mapcar (lambda (x)
3075 (cond ((member x '("<" "&lt;")) :start)
3076 ((member x '(">" "&gt;")) :end)
3077 ((member x '("<>" "&lt;&gt;")) :startend)
3078 (t nil)))
3079 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3080 nil)
3081 ((org-table-cookie-line-p x)
3082 ;; This line contains formatting cookies, discard it
3083 nil)
3084 ((string-match "^[ \t]*| *[!_^/] *|" x)
3085 ;; ignore this line
3086 nil)
3087 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3088 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3089 ;; remove the first column
3090 (replace-match "\\1|" t nil x))))
3091 lines))))
3093 (defun org-export-cleanup-toc-line (s)
3094 "Remove tags and timestamps from lines going into the toc."
3095 (when (memq org-export-with-tags '(not-in-toc nil))
3096 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s)
3097 (setq s (replace-match "" t t s))))
3098 (when org-export-remove-timestamps-from-toc
3099 (while (string-match org-maybe-keyword-time-regexp s)
3100 (setq s (replace-match "" t t s))))
3101 (while (string-match org-bracket-link-regexp s)
3102 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
3103 t t s)))
3104 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s)
3105 (setq s (replace-match "" t t s)))
3109 (defun org-get-text-property-any (pos prop &optional object)
3110 (or (get-text-property pos prop object)
3111 (and (setq pos (next-single-property-change pos prop object))
3112 (get-text-property pos prop object))))
3114 (defun org-export-get-coderef-format (path desc)
3115 (save-match-data
3116 (if (and desc (string-match
3117 (regexp-quote (concat "(" path ")"))
3118 desc))
3119 (replace-match "%s" t t desc)
3120 (or desc "%s"))))
3122 (defun org-export-push-to-kill-ring (format)
3123 "Push buffer content to kill ring.
3124 The depends on the variable `org-export-copy-to-kill'."
3125 (when org-export-copy-to-kill-ring
3126 (org-kill-new (buffer-string))
3127 (when (fboundp 'x-set-selection)
3128 (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
3129 (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
3130 (message "%s export done, pushed to kill ring and clipboard" format)))
3132 (provide 'org-exp)
3134 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3136 ;;; org-exp.el ends here