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