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