1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004-2011 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (require 'org-exp-blocks
)
40 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
41 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
42 (declare-function org-export-html-preprocess
"org-html" (parameters))
43 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
44 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
45 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
46 (declare-function htmlize-buffer
"ext:htmlize" (&optional buffer
))
47 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
48 (declare-function org-table-cookie-line-p
"org-table" (line))
49 (declare-function org-table-colgroup-line-p
"org-table" (line))
50 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
51 (defgroup org-export nil
52 "Options for exporting org-listings."
56 (defgroup org-export-general nil
57 "General options for exporting Org-mode files."
58 :tag
"Org Export General"
61 (defcustom org-export-allow-BIND
'confirm
62 "Non-nil means allow #+BIND to define local variable values for export.
63 This is a potential security risk, which is why the user must confirm the
65 :group
'org-export-general
67 (const :tag
"Never" nil
)
68 (const :tag
"Always" t
)
69 (const :tag
"Make the user confirm for each file" confirm
)))
72 (defvar org-export-publishing-directory nil
)
74 (defcustom org-export-show-temporary-export-buffer t
75 "Non-nil means show buffer after exporting to temp buffer.
76 When Org exports to a file, the buffer visiting that file is ever
77 shown, but remains buried. However, when exporting to a temporary
78 buffer, that buffer is popped up in a second window. When this variable
79 is nil, the buffer remains buried also in these cases."
80 :group
'org-export-general
83 (defcustom org-export-copy-to-kill-ring t
84 "Non-nil means exported stuff will also be pushed onto the kill ring."
85 :group
'org-export-general
88 (defcustom org-export-kill-product-buffer-when-displayed nil
89 "Non-nil means kill the product buffer if it is displayed immediately.
90 This applied to the commands `org-export-html-and-open' and
91 `org-export-as-pdf-and-open'."
92 :group
'org-export-general
95 (defcustom org-export-run-in-background nil
96 "Non-nil means export and publishing commands will run in background.
97 This works by starting up a separate Emacs process visiting the same file
98 and doing the export from there.
99 Not all export commands are affected by this - only the ones which
100 actually write to a file, and that do not depend on the buffer state.
102 If this option is nil, you can still get background export by calling
103 `org-export' with a double prefix arg: \
104 \\[universal-argument] \\[universal-argument] \\[org-export].
106 If this option is t, the double prefix can be used to exceptionally
107 force an export command into the current process."
108 :group
'org-export-general
111 (defcustom org-export-select-tags
'("export")
112 "Tags that select a tree for export.
113 If any such tag is found in a buffer, all trees that do not carry one
114 of these tags will be deleted before export.
115 Inside trees that are selected like this, you can still deselect a
116 subtree by tagging it with one of the `org-export-exclude-tags'."
117 :group
'org-export-general
118 :type
'(repeat (string :tag
"Tag")))
120 (defcustom org-export-exclude-tags
'("noexport")
121 "Tags that exclude a tree from export.
122 All trees carrying any of these tags will be excluded from export.
123 This is without condition, so even subtrees inside that carry one of the
124 `org-export-select-tags' will be removed."
125 :group
'org-export-general
126 :type
'(repeat (string :tag
"Tag")))
128 ;; FIXME: rename, this is a general variable
129 (defcustom org-export-html-expand t
130 "Non-nil means for HTML export, treat @<...> as HTML tag.
131 When nil, these tags will be exported as plain text and therefore
132 not be interpreted by a browser.
134 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
135 :group
'org-export-html
136 :group
'org-export-general
139 (defcustom org-export-with-special-strings t
140 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
141 When this option is turned on, these strings will be exported as:
144 -----+----------+--------
150 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
151 :group
'org-export-translation
154 (defcustom org-export-html-link-up
""
155 "Where should the \"UP\" link of exported HTML pages lead?"
156 :group
'org-export-html
157 :group
'org-export-general
158 :type
'(string :tag
"File or URL"))
160 (defcustom org-export-html-link-home
""
161 "Where should the \"HOME\" link of exported HTML pages lead?"
162 :group
'org-export-html
163 :group
'org-export-general
164 :type
'(string :tag
"File or URL"))
166 (defcustom org-export-language-setup
167 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
168 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
169 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
170 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
171 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
172 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
173 ("es" "Autor" "Fecha" "Índice" "Pies de página")
174 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
175 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
176 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
177 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
178 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
179 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
180 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
181 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
182 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
183 ("pl" "Autor" "Data" "Spis treści" "Przypis")
184 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
185 "Terms used in export text, translated to different languages.
186 Use the variable `org-export-default-language' to set the language,
187 or use the +OPTION lines for a per-file setting."
188 :group
'org-export-general
191 (string :tag
"HTML language tag")
192 (string :tag
"Author")
194 (string :tag
"Table of Contents")
195 (string :tag
"Footnotes"))))
197 (defcustom org-export-default-language
"en"
198 "The default language of HTML export, as a string.
199 This should have an association in `org-export-language-setup'."
200 :group
'org-export-general
203 (defvar org-export-page-description
""
204 "The page description, for the XHTML meta tag.
205 This is best set with the #+DESCRIPTION line in a file, it does not make
206 sense to set this globally.")
208 (defvar org-export-page-keywords
""
209 "The page description, for the XHTML meta tag.
210 This is best set with the #+KEYWORDS line in a file, it does not make
211 sense to set this globally.")
213 (defcustom org-export-skip-text-before-1st-heading nil
214 "Non-nil means skip all text before the first headline when exporting.
215 When nil, that text is exported as well."
216 :group
'org-export-general
219 (defcustom org-export-headline-levels
3
220 "The last level which is still exported as a headline.
221 Inferior levels will produce itemize lists when exported.
222 Note that a numeric prefix argument to an exporter function overrides
225 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
226 :group
'org-export-general
229 (defcustom org-export-with-section-numbers t
230 "Non-nil means add section numbers to headlines when exporting.
232 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
233 :group
'org-export-general
236 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
237 "Format of section numbers for export.
238 The variable has two components.
239 1. A list of lists, each indicating a counter type and a separator.
240 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
241 It causes causes numeric, alphabetic, or roman counters, respectively.
242 The separator is only used if another counter for a subsection is being
244 If there are more numbered section levels than entries in this lists,
245 then the last entry will be reused.
246 2. A terminator string that will be added after the entire
248 :group
'org-export-general
252 (string :tag
"Counter Type")
253 (string :tag
"Separator ")))
254 (string :tag
"Terminator")))
256 (defcustom org-export-with-toc t
257 "Non-nil means create a table of contents in exported files.
258 The TOC contains headlines with levels up to`org-export-headline-levels'.
259 When an integer, include levels up to N in the toc, this may then be
260 different from `org-export-headline-levels', but it will not be allowed
261 to be larger than the number of headline levels.
262 When nil, no table of contents is made.
264 Headlines which contain any TODO items will be marked with \"(*)\" in
265 ASCII export, and with red color in HTML output, if the option
266 `org-export-mark-todo-in-toc' is set.
268 In HTML output, the TOC will be clickable.
270 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
272 :group
'org-export-general
274 (const :tag
"No Table of Contents" nil
)
275 (const :tag
"Full Table of Contents" t
)
276 (integer :tag
"TOC to level")))
278 (defcustom org-export-mark-todo-in-toc nil
279 "Non-nil means mark TOC lines that contain any open TODO items."
280 :group
'org-export-general
283 (defcustom org-export-with-todo-keywords t
284 "Non-nil means include TODO keywords in export.
285 When nil, remove all these keywords from the export."
286 :group
'org-export-general
289 (defcustom org-export-with-priority nil
290 "Non-nil means include priority cookies in export.
291 When nil, remove priority cookies for export."
292 :group
'org-export-general
295 (defcustom org-export-preserve-breaks nil
296 "Non-nil means preserve all line breaks when exporting.
297 Normally, in HTML output paragraphs will be reformatted. In ASCII
298 export, line breaks will always be preserved, regardless of this variable.
300 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
301 :group
'org-export-general
304 (defcustom org-export-with-archived-trees
'headline
305 "Whether subtrees with the ARCHIVE tag should be exported.
306 This can have three different values
307 nil Do not export, pretend this tree is not present
308 t Do export the entire tree
309 headline Only export the headline, but skip the tree below it."
310 :group
'org-export-general
313 (const :tag
"not at all" nil
)
314 (const :tag
"headline only" 'headline
)
315 (const :tag
"entirely" t
)))
317 (defcustom org-export-author-info t
318 "Non-nil means insert author name and email into the exported file.
320 This option can also be set with the +OPTIONS line,
321 e.g. \"author:nil\"."
322 :group
'org-export-general
325 (defcustom org-export-email-info nil
326 "Non-nil means insert author name and email into the exported file.
328 This option can also be set with the +OPTIONS line,
330 :group
'org-export-general
333 (defcustom org-export-creator-info t
334 "Non-nil means the postamble should contain a creator sentence.
335 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
336 :group
'org-export-general
339 (defcustom org-export-time-stamp-file t
340 "Non-nil means insert a time stamp into the exported file.
341 The time stamp shows when the file was created.
343 This option can also be set with the +OPTIONS line,
344 e.g. \"timestamp:nil\"."
345 :group
'org-export-general
348 (defcustom org-export-with-timestamps t
349 "If nil, do not export time stamps and associated keywords."
350 :group
'org-export-general
353 (defcustom org-export-remove-timestamps-from-toc t
354 "If t, remove timestamps from the table of contents entries."
355 :group
'org-export-general
358 (defcustom org-export-with-tags
'not-in-toc
359 "If nil, do not export tags, just remove them from headlines.
360 If this is the symbol `not-in-toc', tags will be removed from table of
361 contents entries, but still be shown in the headlines of the document.
363 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
364 :group
'org-export-general
366 (const :tag
"Off" nil
)
367 (const :tag
"Not in TOC" not-in-toc
)
368 (const :tag
"On" t
)))
370 (defcustom org-export-with-drawers nil
371 "Non-nil means export with drawers like the property drawer.
372 When t, all drawers are exported. This may also be a list of
373 drawer names to export."
374 :group
'org-export-general
376 (const :tag
"All drawers" t
)
377 (const :tag
"None" nil
)
378 (repeat :tag
"Selected drawers"
379 (string :tag
"Drawer name"))))
381 (defvar org-export-first-hook nil
382 "Hook called as the first thing in each exporter.
383 Point will be still in the original buffer.
384 Good for general initialization")
386 (defvar org-export-preprocess-hook nil
387 "Hook for preprocessing an export buffer.
388 Pretty much the first thing when exporting is running this hook.
389 Point will be in a temporary buffer that contains a copy of
390 the original buffer, or of the section that is being export.
391 All the other hooks in the org-export-preprocess... category
392 also work in that temporary buffer, already modified by various
393 stages of the processing.")
395 (defvar org-export-preprocess-after-include-files-hook nil
396 "Hook for preprocessing an export buffer.
397 This is run after the contents of included files have been inserted.")
399 (defvar org-export-preprocess-after-tree-selection-hook nil
400 "Hook for preprocessing an export buffer.
401 This is run after selection of trees to be exported has happened.
402 This selection includes tags-based selection, as well as removal
403 of commented and archived trees.")
405 (defvar org-export-preprocess-after-headline-targets-hook nil
406 "Hook for preprocessing export buffer.
407 This is run just after the headline targets have been defined and
408 the target-alist has been set up.")
410 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
411 "Hook for preprocessing an export buffer.
412 This is run just before backend-specific blocks get selected.")
414 (defvar org-export-preprocess-after-blockquote-hook nil
415 "Hook for preprocessing an export buffer.
416 This is run after blockquote/quote/verse/center have been marked
419 (defvar org-export-preprocess-after-radio-targets-hook nil
420 "Hook for preprocessing an export buffer.
421 This is run after radio target processing.")
423 (defvar org-export-preprocess-before-normalizing-links-hook nil
424 "Hook for preprocessing an export buffer.
425 This hook is run before links are normalized.")
427 (defvar org-export-preprocess-before-backend-specifics-hook nil
428 "Hook run before backend-specific functions are called during preprocessing.")
430 (defvar org-export-preprocess-final-hook nil
431 "Hook for preprocessing an export buffer.
432 This is run as the last thing in the preprocessing buffer, just before
433 returning the buffer string to the backend.")
435 (defgroup org-export-translation nil
436 "Options for translating special ascii sequences for the export backends."
437 :tag
"Org Export Translation"
440 (defcustom org-export-with-emphasize t
441 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
442 If the export target supports emphasizing text, the word will be
443 typeset in bold, italic, or underlined, respectively. Works only for
444 single words, but you can say: I *really* *mean* *this*.
445 Not all export backends support this.
447 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
448 :group
'org-export-translation
451 (defcustom org-export-with-footnotes t
452 "If nil, export [1] as a footnote marker.
453 Lines starting with [1] will be formatted as footnotes.
455 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
456 :group
'org-export-translation
459 (defcustom org-export-with-TeX-macros t
460 "Non-nil means interpret simple TeX-like macros when exporting.
461 For example, HTML export converts \\alpha to α and \\AA to Å.
462 Not only real TeX macros will work here, but the standard HTML entities
463 for math can be used as macro names as well. For a list of supported
464 names in HTML export, see the constant `org-entities' and the user option
466 Not all export backends support this.
468 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
469 :group
'org-export-translation
470 :group
'org-export-latex
473 (defcustom org-export-with-LaTeX-fragments t
474 "Non-nil means process LaTeX math fragments for HTML display.
475 When set, the exporter will find and process LaTeX environments if the
476 \\begin line is the first non-white thing on a line. It will also find
477 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
478 $$a=b$$ and \\[ a=b \\] for display math.
480 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
484 nil Don't do anything.
485 verbatim Keep eveything in verbatim
486 dvipng Process the LaTeX fragments to images.
487 This will also include processing of non-math environments.
488 t Do MathJax preprocessing if there is at least on math snippet,
489 and arrange for MathJax.js to be loaded.
491 The default is nil, because this option needs the `dvipng' program which
492 is not available on all systems."
493 :group
'org-export-translation
494 :group
'org-export-latex
496 (const :tag
"Do not process math in any way" nil
)
497 (const :tag
"Obsolete, use dvipng setting" t
)
498 (const :tag
"Use dvipng to make images" dvipng
)
499 (const :tag
"Use MathJax to display math" mathjax
)
500 (const :tag
"Leave math verbatim" verbatim
)))
502 (defcustom org-export-with-fixed-width t
503 "Non-nil means lines starting with \":\" will be in fixed width font.
504 This can be used to have pre-formatted text, fragments of code etc. For
506 : ;; Some Lisp examples
509 will be looking just like this in also HTML. See also the QUOTE keyword.
510 Not all export backends support this.
512 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
513 :group
'org-export-translation
516 (defgroup org-export-tables nil
517 "Options for exporting tables in Org-mode."
518 :tag
"Org Export Tables"
521 (defcustom org-export-with-tables t
522 "If non-nil, lines starting with \"|\" define a table.
525 | Name | Address | Birthday |
526 |-------------+----------+-----------|
527 | Arthur Dent | England | 29.2.2100 |
529 Not all export backends support this.
531 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
532 :group
'org-export-tables
535 (defcustom org-export-highlight-first-table-line t
536 "Non-nil means highlight the first table line.
537 In HTML export, this means use <th> instead of <td>.
538 In tables created with table.el, this applies to the first table line.
539 In Org-mode tables, all lines before the first horizontal separator
540 line will be formatted with <th> tags."
541 :group
'org-export-tables
544 (defcustom org-export-table-remove-special-lines t
545 "Remove special lines and marking characters in calculating tables.
546 This removes the special marking character column from tables that are set
547 up for spreadsheet calculations. It also removes the entire lines
548 marked with `!', `_', or `^'. The lines with `$' are kept, because
549 the values of constants may be useful to have."
550 :group
'org-export-tables
553 (defcustom org-export-prefer-native-exporter-for-tables nil
554 "Non-nil means always export tables created with table.el natively.
555 Natively means use the HTML code generator in table.el.
556 When nil, Org-mode's own HTML generator is used when possible (i.e. if
557 the table does not use row- or column-spanning). This has the
558 advantage, that the automatic HTML conversions for math symbols and
559 sub/superscripts can be applied. Org-mode's HTML generator is also
560 much faster. The LaTeX exporter always use the native exporter for
562 :group
'org-export-tables
566 (defgroup org-export-xml nil
567 "Options specific for XML export of Org-mode files."
568 :tag
"Org Export XML"
573 ;;; Variables, constants, and parameter plists
575 (defconst org-level-max
20)
577 (defvar org-current-export-file nil
) ; dynamically scoped parameter
578 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
579 (defvar org-export-opt-plist nil
580 "Contains the current option plist.")
581 (defvar org-last-level nil
) ; dynamically scoped variable
582 (defvar org-min-level nil
) ; dynamically scoped variable
583 (defvar org-levels-open nil
) ; dynamically scoped parameter
585 (defconst org-export-plist-vars
586 '((:link-up nil org-export-html-link-up
)
587 (:link-home nil org-export-html-link-home
)
588 (:language nil org-export-default-language
)
589 (:keywords nil org-export-page-keywords
)
590 (:description nil org-export-page-description
)
591 (:customtime nil org-display-custom-times
)
592 (:headline-levels
"H" org-export-headline-levels
)
593 (:section-numbers
"num" org-export-with-section-numbers
)
594 (:section-number-format nil org-export-section-number-format
)
595 (:table-of-contents
"toc" org-export-with-toc
)
596 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
597 (:archived-trees nil org-export-with-archived-trees
)
598 (:emphasize
"*" org-export-with-emphasize
)
599 (:sub-superscript
"^" org-export-with-sub-superscripts
)
600 (:special-strings
"-" org-export-with-special-strings
)
601 (:footnotes
"f" org-export-with-footnotes
)
602 (:drawers
"d" org-export-with-drawers
)
603 (:tags
"tags" org-export-with-tags
)
604 (:todo-keywords
"todo" org-export-with-todo-keywords
)
605 (:priority
"pri" org-export-with-priority
)
606 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
607 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
608 (:latex-listings nil org-export-latex-listings
)
609 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
610 (:fixed-width
":" org-export-with-fixed-width
)
611 (:timestamps
"<" org-export-with-timestamps
)
612 (:author-info
"author" org-export-author-info
)
613 (:email-info
"email" org-export-email-info
)
614 (:creator-info
"creator" org-export-creator-info
)
615 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
616 (:tables
"|" org-export-with-tables
)
617 (:table-auto-headline nil org-export-highlight-first-table-line
)
618 (:style-include-default nil org-export-html-style-include-default
)
619 (:style-include-scripts nil org-export-html-style-include-scripts
)
620 (:style nil org-export-html-style
)
621 (:style-extra nil org-export-html-style-extra
)
622 (:agenda-style nil org-agenda-export-html-style
)
623 (:convert-org-links nil org-export-html-link-org-files-as-html
)
624 (:inline-images nil org-export-html-inline-images
)
625 (:html-extension nil org-export-html-extension
)
626 (:xml-declaration nil org-export-html-xml-declaration
)
627 (:html-table-tag nil org-export-html-table-tag
)
628 (:expand-quoted-html
"@" org-export-html-expand
)
629 (:timestamp nil org-export-html-with-timestamp
)
630 (:publishing-directory nil org-export-publishing-directory
)
631 (:preamble nil org-export-html-preamble
)
632 (:postamble nil org-export-html-postamble
)
633 (:auto-preamble nil org-export-html-auto-preamble
)
634 (:auto-postamble nil org-export-html-auto-postamble
)
635 (:author nil user-full-name
)
636 (:email nil user-mail-address
)
637 (:select-tags nil org-export-select-tags
)
638 (:exclude-tags nil org-export-exclude-tags
)
640 (:latex-image-options nil org-export-latex-image-default-option
))
641 "List of properties that represent export/publishing variables.
642 Each element is a list of 3 items:
643 1. The property that is used internally, and also for org-publish-project-alist
644 2. The string that can be used in the OPTION lines to set this option,
645 or nil if this option cannot be changed in this way
646 3. The customization variable that sets the default for this option."
649 (defun org-default-export-plist ()
650 "Return the property list with default settings for the export variables."
651 (let* ((infile (org-infile-export-plist))
652 (letbind (plist-get infile
:let-bind
))
653 (l org-export-plist-vars
) rtn e s v
)
654 (while (setq e
(pop l
))
657 ((assq s letbind
) (nth 1 (assq s letbind
)))
658 ((boundp s
) (symbol-value s
))
660 rtn
(cons (car e
) (cons v rtn
))))
663 (defvar org-export-inbuffer-options-extra nil
664 "List of additional in-buffer options that should be detected.
665 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
666 etc. Extensions can add to this list to get their options detected, and they
667 can then add a function to `org-export-options-filters' to process these
669 Each element in this list must be a list, with the in-buffer keyword as car,
670 and a property (a symbol) as the next element. All occurrences of the
671 keyword will be found, the values concatenated with a space character
672 in between, and the result stored in the export options property list.")
674 (defvar org-export-options-filters nil
675 "Functions to be called to finalize the export/publishing options.
676 All these options are stored in a property list, and each of the functions
677 in this hook gets a chance to modify this property list. Each function
678 must accept the property list as an argument, and must return the (possibly
681 ;; FIXME: should we fold case here?
682 (defun org-infile-export-plist ()
683 "Return the property list with file-local settings for export."
687 (goto-char (point-min))
688 (let ((re (org-make-options-regexp
690 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
692 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
693 "LATEX_HEADER" "LATEX_CLASS"
694 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
695 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
696 (mapcar 'car org-export-inbuffer-options-extra
))))
698 p key val text options mathjax a pr style
699 latex-header latex-class macros letbind
700 ext-setup-or-nil setup-contents
(start 0))
701 (while (or (and ext-setup-or-nil
702 (string-match re ext-setup-or-nil start
)
703 (setq start
(match-end 0)))
704 (and (setq ext-setup-or-nil nil start
0)
705 (re-search-forward re nil t
)))
706 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
707 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
709 ((setq a
(assoc key org-export-inbuffer-options-extra
))
711 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
712 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
713 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
714 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
715 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
716 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
717 ((string-equal key
"DESCRIPTION")
718 (setq p
(plist-put p
:description val
)))
719 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
720 ((string-equal key
"STYLE")
721 (setq style
(concat style
"\n" val
)))
722 ((string-equal key
"LATEX_HEADER")
723 (setq latex-header
(concat latex-header
"\n" val
)))
724 ((string-equal key
"LATEX_CLASS")
725 (setq latex-class val
))
726 ((string-equal key
"TEXT")
727 (setq text
(if text
(concat text
"\n" val
) val
)))
728 ((string-equal key
"OPTIONS")
729 (setq options
(concat val
" " options
)))
730 ((string-equal key
"MATHJAX")
731 (setq mathjax
(concat val
" " mathjax
)))
732 ((string-equal key
"BIND")
733 (push (read (concat "(" val
")")) letbind
))
734 ((string-equal key
"XSLT")
735 (setq p
(plist-put p
:xslt val
)))
736 ((string-equal key
"LINK_UP")
737 (setq p
(plist-put p
:link-up val
)))
738 ((string-equal key
"LINK_HOME")
739 (setq p
(plist-put p
:link-home val
)))
740 ((string-equal key
"EXPORT_SELECT_TAGS")
741 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
742 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
743 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
744 ((string-equal key
"MACRO")
746 ((equal key
"SETUPFILE")
747 (setq setup-contents
(org-file-contents
749 (org-remove-double-quotes
752 (if (not ext-setup-or-nil
)
753 (setq ext-setup-or-nil setup-contents start
0)
754 (setq ext-setup-or-nil
755 (concat (substring ext-setup-or-nil
0 start
)
756 "\n" setup-contents
"\n"
757 (substring ext-setup-or-nil start
)))))))
758 (setq p
(plist-put p
:text text
))
759 (when (and letbind
(org-export-confirm-letbind))
760 (setq p
(plist-put p
:let-bind letbind
)))
761 (when style
(setq p
(plist-put p
:style-extra style
)))
763 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
765 (setq p
(plist-put p
:latex-class latex-class
)))
767 (setq p
(org-export-add-options-to-plist p options
)))
769 (setq p
(plist-put p
:mathjax mathjax
)))
770 ;; Add macro definitions
771 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
772 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
773 (setq p
(plist-put p
:macro-property
"(eval (org-entry-get nil \"$1\" 'selective))"))
775 p
:macro-modification-time
776 (and (buffer-file-name)
777 (file-exists-p (buffer-file-name))
779 "(eval (format-time-string \"$1\" '"
780 (prin1-to-string (nth 5 (file-attributes
781 (buffer-file-name))))
783 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
784 (file-name-nondirectory
785 (buffer-file-name)))))
786 (while (setq val
(pop macros
))
787 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
790 (concat ":macro-" (downcase (match-string 1 val
))))
791 (org-export-interpolate-newlines (match-string 2 val
))))))
794 (defun org-export-interpolate-newlines (s)
795 (while (string-match "\\\\n" s
)
796 (setq s
(replace-match "\n" t t s
)))
799 (defvar org-export-allow-BIND-local nil
)
800 (defun org-export-confirm-letbind ()
801 "Can we use #+BIND values during export?
802 By default this will ask fro confirmation by the user, to divert possible
805 ((not org-export-allow-BIND
) nil
)
806 ((eq org-export-allow-BIND t
) t
)
807 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
808 org-export-allow-BIND-local
)
809 (t (org-set-local 'org-export-allow-BIND-local
810 (yes-or-no-p "Allow BIND values in this buffer? ")))))
812 (defun org-install-letbind ()
813 "Install the values from #+BIND lines as local variables."
814 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
816 (while (setq pair
(pop letbind
))
817 (org-set-local (car pair
) (nth 1 pair
)))))
819 (defun org-export-add-options-to-plist (p options
)
820 "Parse an OPTIONS line and set values in the property list P."
823 (let ((op org-export-plist-vars
))
824 (while (setq o
(pop op
))
826 (string-match (concat (regexp-quote (nth 1 o
))
827 ":\\([^ \t\n\r;,.]*\\)")
829 (setq p
(plist-put p
(car o
)
830 (car (read-from-string
831 (match-string 1 options
))))))))))
834 (defun org-export-add-subtree-options (p pos
)
835 "Add options in subtree at position POS to property list P."
838 (when (org-at-heading-p)
840 ;; This is actually read in `org-export-get-title-from-subtree'
841 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
842 ;; (setq p (plist-put p :title a)))
843 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
844 (setq p
(plist-put p
:text a
)))
845 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
846 (setq p
(plist-put p
:author a
)))
847 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
848 (setq p
(plist-put p
:date a
)))
849 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
850 (setq p
(org-export-add-options-to-plist p a
)))))
853 (defun org-export-directory (type plist
)
854 (let* ((val (plist-get plist
:publishing-directory
))
856 (or (cdr (assoc type val
)) ".")
860 (defun org-export-process-option-filters (plist)
861 (let ((functions org-export-options-filters
) f
)
862 (while (setq f
(pop functions
))
863 (setq plist
(funcall f plist
))))
867 (defun org-export (&optional arg
)
868 "Export dispatcher for Org-mode.
869 When `org-export-run-in-background' is non-nil, try to run the command
870 in the background. This will be done only for commands that write
871 to a file. For details see the docstring of `org-export-run-in-background'.
873 The prefix argument ARG will be passed to the exporter. However, if
874 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
875 that means to inverse the
876 value of `org-export-run-in-background'."
878 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
880 (help "[t] insert the export option template
881 \[v] limit export to visible part of outline tree
882 \[1] only export the current subtree
883 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
885 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
887 \[h] export as HTML [H] to temporary buffer [R] export region
888 \[b] export as HTML and open in browser
890 \[l] export as LaTeX [L] to temporary buffer
891 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
893 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
895 \[j] export as TaskJuggler [J] ... and open
897 \[m] export as Freemind mind map
899 \[g] export using Wes Hardaker's generic exporter
901 \[i] export current file as iCalendar file
902 \[I] export all agenda files as iCalendar files [c] ...as one combined file
904 \[F] publish current file [P] publish current project
905 \[X] publish a project... [E] publish every projects")
907 '((?t org-insert-export-options-template nil
)
908 (?v org-export-visible nil
)
909 (?a org-export-as-ascii t
)
910 (?A org-export-as-ascii-to-buffer t
)
911 (?n org-export-as-latin1 t
)
912 (?N org-export-as-latin1-to-buffer t
)
913 (?u org-export-as-utf8 t
)
914 (?U org-export-as-utf8-to-buffer t
)
915 (?h org-export-as-html t
)
916 (?b org-export-as-html-and-open t
)
917 (?H org-export-as-html-to-buffer nil
)
918 (?R org-export-region-as-html nil
)
919 (?x org-export-as-xoxo t
)
920 (?g org-export-generic t
)
921 (?D org-export-as-docbook t
)
922 (?V org-export-as-docbook-pdf-and-open t
)
923 (?j org-export-as-taskjuggler t
)
924 (?J org-export-as-taskjuggler-and-open t
)
925 (?m org-export-as-freemind t
)
926 (?l org-export-as-latex t
)
927 (?p org-export-as-pdf t
)
928 (?d org-export-as-pdf-and-open t
)
929 (?L org-export-as-latex-to-buffer nil
)
930 (?i org-export-icalendar-this-file t
)
931 (?I org-export-icalendar-all-agenda-files t
)
932 (?c org-export-icalendar-combine-agenda-files t
)
933 (?F org-publish-current-file t
)
934 (?P org-publish-current-project t
)
936 (?E org-publish-all t
)))
938 (cpos (point)) (cbuf (current-buffer)) bpos
)
940 (save-window-excursion
941 (delete-other-windows)
942 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
944 (org-fit-window-to-buffer (get-buffer-window
945 "*Org Export/Publishing Help*"))
946 (message "Select command: ")
947 (setq r1
(read-char-exclusive))
950 (message "Select command (for subtree): ")
951 (setq r1
(read-char-exclusive)))
953 (let ((case-fold-search t
))
954 (if (re-search-backward
955 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
958 (org-back-to-heading t
)
961 (message "Select command (for subtree): ")
962 (setq r1
(read-char-exclusive)))
963 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
965 (and bpos
(goto-char bpos
))
966 (setq r2
(if (< r1
27) (+ r1
96) r1
))
967 (unless (setq ass
(assq r2 cmds
))
968 (error "No command associated with key %c" r1
))
969 (if (and bg
(nth 2 ass
)
970 (not (buffer-base-buffer))
971 (not (org-region-active-p)))
972 ;; execute in background
973 (let ((p (start-process
974 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
976 (expand-file-name invocation-name invocation-directory
)
979 "--eval" "(require 'org-exp)"
980 "--eval" "(setq org-wait .2)"
982 "-f" (symbol-name (nth 1 ass
)))))
983 (set-process-sentinel p
'org-export-process-sentinel
)
984 (message "Background process \"%s\": started" p
))
985 ;; background processing not requested, or not possible
986 (if subtree-p
(progn (org-mark-subtree) (activate-mark)))
987 (call-interactively (nth 1 ass
))
988 (when (and bpos
(get-buffer-window cbuf
))
989 (let ((cw (selected-window)))
990 (select-window (get-buffer-window cbuf
))
993 (select-window cw
))))))
995 (defun org-export-process-sentinel (process status
)
996 (if (string-match "\n+\\'" status
)
997 (setq status
(substring status
0 -
1)))
998 (message "Background process \"%s\": %s" process status
))
1000 ;;; General functions for all backends
1002 (defvar org-export-target-aliases nil
1003 "Alist of targets with invisible aliases.")
1004 (defvar org-export-preferred-target-alist nil
1005 "Alist of section id's with preferred aliases.")
1006 (defvar org-export-id-target-alist nil
1007 "Alist of section id's with preferred aliases.")
1008 (defvar org-export-code-refs nil
1009 "Alist of code references and line numbers.")
1011 (defun org-export-preprocess-string (string &rest parameters
)
1012 "Cleanup STRING so that that the true exported has a more consistent source.
1013 This function takes STRING, which should be a buffer-string of an org-file
1014 to export. It then creates a temporary buffer where it does its job.
1015 The result is then again returned as a string, and the exporter works
1016 on this string to produce the exported version."
1018 (let* ((htmlp (plist-get parameters
:for-html
))
1019 (asciip (plist-get parameters
:for-ascii
))
1020 (latexp (plist-get parameters
:for-LaTeX
))
1021 (docbookp (plist-get parameters
:for-docbook
))
1022 (backend (cond (htmlp 'html
)
1025 (docbookp 'docbook
)))
1026 (archived-trees (plist-get parameters
:archived-trees
))
1027 (inhibit-read-only t
)
1028 (drawers org-drawers
)
1029 (outline-regexp "\\*+ ")
1032 (setq org-export-target-aliases nil
1033 org-export-preferred-target-alist nil
1034 org-export-id-target-alist nil
1035 org-export-code-refs nil
)
1037 (with-current-buffer (get-buffer-create " org-mode-tmp")
1040 (setq case-fold-search t
)
1042 (let ((inhibit-read-only t
))
1043 (remove-text-properties (point-min) (point-max)
1046 ;; Remove license-to-kill stuff
1047 ;; The caller marks some stuff for killing, stuff that has been
1048 ;; used to create the page title, for example.
1049 (org-export-kill-licensed-text)
1051 (let ((org-inhibit-startup t
)) (org-mode))
1052 (setq case-fold-search t
)
1053 (org-install-letbind)
1056 (run-hooks 'org-export-preprocess-hook
)
1058 ;; Process the macros
1059 (org-export-preprocess-apply-macros)
1060 (run-hooks 'org-export-preprocess-after-macros-hook
)
1062 (untabify (point-min) (point-max))
1064 ;; Handle include files, and call a hook
1065 (org-export-handle-include-files-recurse)
1066 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1068 ;; Get rid of archived trees
1069 (org-export-remove-archived-trees archived-trees
)
1071 ;; Remove comment environment and comment subtrees
1072 (org-export-remove-comment-blocks-and-subtrees)
1074 ;; Get rid of excluded trees, and call a hook
1075 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1076 (plist-get parameters
:exclude-tags
))
1077 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1079 ;; Mark end of lists
1080 (org-export-mark-list-ending backend
)
1082 ;; Export code blocks
1083 (org-export-blocks-preprocess)
1085 ;; Handle source code snippets
1086 (org-export-replace-src-segments-and-examples backend
)
1088 ;; Protect short examples marked by a leading colon
1089 (org-export-protect-colon-examples)
1092 (org-export-convert-protected-spaces backend
)
1094 ;; Normalize footnotes
1095 (when (plist-get parameters
:footnotes
)
1096 (org-footnote-normalize nil t
))
1098 ;; Find all headings and compute the targets for them
1099 (setq target-alist
(org-export-define-heading-targets target-alist
))
1101 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1103 ;; Find HTML special classes for headlines
1104 (org-export-remember-html-container-classes)
1106 ;; Get rid of drawers
1107 (org-export-remove-or-extract-drawers
1108 drawers
(plist-get parameters
:drawers
) backend
)
1110 ;; Get the correct stuff before the first headline
1111 (when (plist-get parameters
:skip-before-1st-heading
)
1112 (goto-char (point-min))
1113 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1114 (delete-region (point-min) (match-beginning 0))
1115 (goto-char (point-min))
1117 (when (plist-get parameters
:add-text
)
1118 (goto-char (point-min))
1119 (insert (plist-get parameters
:add-text
) "\n"))
1121 ;; Remove todo-keywords before exporting, if the user has requested so
1122 (org-export-remove-headline-metadata parameters
)
1124 ;; Find targets in comments and move them out of comments,
1125 ;; but mark them as targets that should be invisible
1126 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1128 ;; Select and protect backend specific stuff, throw away stuff
1129 ;; that is specific for other backends
1130 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1131 (org-export-select-backend-specific-text backend
)
1133 ;; Protect quoted subtrees
1134 (org-export-protect-quoted-subtrees)
1136 ;; Remove clock lines
1137 (org-export-remove-clock-lines)
1139 ;; Protect verbatim elements
1140 (org-export-protect-verbatim)
1142 ;; Blockquotes, verse, and center
1143 (org-export-mark-blockquote-verse-center)
1144 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1146 ;; Remove timestamps, if the user has requested so
1147 (unless (plist-get parameters
:timestamps
)
1148 (org-export-remove-timestamps))
1150 ;; Attach captions to the correct object
1151 (setq target-alist
(org-export-attach-captions-and-attributes
1152 backend target-alist
))
1154 ;; Find matches for radio targets and turn them into internal links
1155 (org-export-mark-radio-links)
1156 (run-hooks 'org-export-preprocess-after-radio-targets-hook
)
1158 ;; Find all links that contain a newline and put them into a single line
1159 (org-export-concatenate-multiline-links)
1161 ;; Normalize links: Convert angle and plain links into bracket links
1162 ;; and expand link abbreviations
1163 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1164 (org-export-normalize-links)
1166 ;; Find all internal links. If they have a fuzzy match (i.e. not
1167 ;; a *dedicated* target match, let the link point to the
1168 ;; corresponding section.
1169 (org-export-target-internal-links target-alist
)
1171 ;; Find multiline emphasis and put them into single line
1172 (when (plist-get parameters
:emph-multiline
)
1173 (org-export-concatenate-multiline-emphasis))
1175 ;; Remove special table lines, and store alignment information
1176 (org-store-forced-table-alignment)
1177 (when org-export-table-remove-special-lines
1178 (org-export-remove-special-table-lines))
1181 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1183 ;; LaTeX-specific preprocessing
1185 (require 'org-latex nil
)
1186 (org-export-latex-preprocess parameters
))
1188 ;; ASCII-specific preprocessing
1190 (org-export-ascii-preprocess parameters
))
1192 ;; HTML-specific preprocessing
1194 (org-export-html-preprocess parameters
))
1196 ;; DocBook-specific preprocessing
1198 (require 'org-docbook nil
)
1199 (org-export-docbook-preprocess parameters
))
1201 ;; Remove or replace comments
1202 (org-export-handle-comments (plist-get parameters
:comments
))
1204 ;; Remove #+TBLFM and #+TBLNAME lines
1205 (org-export-handle-table-metalines)
1207 ;; Run the final hook
1208 (run-hooks 'org-export-preprocess-final-hook
)
1210 (setq rtn
(buffer-string)))
1211 (kill-buffer " org-mode-tmp")
1214 (defun org-export-kill-licensed-text ()
1215 "Remove all text that is marked with a :org-license-to-kill property."
1217 (while (setq p
(text-property-any (point-min) (point-max)
1218 :org-license-to-kill t
))
1220 p
(or (next-single-property-change p
:org-license-to-kill
)
1223 (defvar org-export-define-heading-targets-headline-hook nil
1224 "Hook that is run when a headline was matched during target search.
1225 This is part of the preprocessing for export.")
1227 (defun org-export-define-heading-targets (target-alist)
1228 "Find all headings and define the targets for them.
1229 The new targets are added to TARGET-ALIST, which is also returned.
1230 Also find all ID and CUSTOM_ID properties and store them."
1231 (goto-char (point-min))
1232 (org-init-section-numbers)
1233 (let ((re (concat "^" org-outline-regexp
1235 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1236 level target last-section-target a id
)
1237 (while (re-search-forward re nil t
)
1238 (org-if-unprotected-at (match-beginning 0)
1241 (setq id
(org-match-string-no-properties 2))
1242 (push (cons id target
) target-alist
)
1243 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1245 (push (list last-section-target
)
1246 org-export-target-aliases
)
1247 (car org-export-target-aliases
))))
1248 (push (caar target-alist
) (cdr a
))
1249 (when (equal (match-string 1) "CUSTOM_ID")
1250 (if (not (assoc last-section-target
1251 org-export-preferred-target-alist
))
1252 (push (cons last-section-target id
)
1253 org-export-preferred-target-alist
)))
1254 (when (equal (match-string 1) "ID")
1255 (if (not (assoc last-section-target
1256 org-export-id-target-alist
))
1257 (push (cons last-section-target
(concat "ID-" id
))
1258 org-export-id-target-alist
))))
1259 (setq level
(org-reduced-level
1260 (save-excursion (goto-char (point-at-bol))
1261 (org-outline-level))))
1262 (setq target
(org-solidify-link-text
1263 (format "sec-%s" (replace-regexp-in-string
1265 (org-section-number level
)))))
1266 (setq last-section-target target
)
1267 (push (cons target target
) target-alist
)
1268 (add-text-properties
1269 (point-at-bol) (point-at-eol)
1270 (list 'target target
))
1271 (run-hooks 'org-export-define-heading-targets-headline-hook
)))))
1274 (defun org-export-handle-invisible-targets (target-alist)
1275 "Find targets in comments and move them out of comments.
1276 Mark them as invisible targets."
1278 (goto-char (point-min))
1279 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1280 ;; Check if the line before or after is a headline with a target
1281 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1282 (get-text-property (point-at-bol 2) 'target
)))
1284 ;; use the existing target in a neighboring line
1285 (setq tmp
(match-string 2))
1287 (and (looking-at "\n") (delete-char 1))
1288 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1290 (setq a
(or (assoc target org-export-target-aliases
)
1292 (push (list target
) org-export-target-aliases
)
1293 (car org-export-target-aliases
))))
1295 ;; Make an invisible target
1296 (replace-match "\\1(INVISIBLE)"))))
1299 (defun org-export-target-internal-links (target-alist)
1300 "Find all internal links and assign targets to them.
1301 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1302 let the link point to the corresponding section.
1303 This function also handles the id links, if they have a match in
1305 (goto-char (point-min))
1306 (while (re-search-forward org-bracket-link-regexp nil t
)
1307 (org-if-unprotected-at (1+ (match-beginning 0))
1308 (let* ((md (match-data))
1309 (desc (match-end 2))
1310 (link (org-link-unescape (match-string 1)))
1311 (slink (org-solidify-link-text link
))
1312 found props pos cref
1315 ((= (string-to-char link
) ?
#)
1316 ;; user wants exactly this link
1318 ((cdr (assoc slink target-alist
))
1319 (or (cdr (assoc (assoc slink target-alist
)
1320 org-export-preferred-target-alist
))
1321 (cdr (assoc slink target-alist
))))
1322 ((and (string-match "^id:" link
)
1323 (cdr (assoc (substring link
3) target-alist
))))
1324 ((string-match "^(\\(.*\\))$" link
)
1325 (setq cref
(match-string 1 link
))
1326 (concat "coderef:" cref
))
1327 ((string-match org-link-types-re link
) nil
)
1328 ((or (file-name-absolute-p link
)
1329 (string-match "^\\." link
))
1332 (let ((org-link-search-inhibit-query t
))
1334 (setq found
(condition-case nil
(org-link-search link
)
1337 (or (org-on-heading-p)
1338 (not (eq found
'dedicated
))))
1339 (or (get-text-property (point) 'target
)
1342 (1- (or (previous-single-property-change
1343 (point) 'target
) 0)))
1347 (goto-char (match-beginning 1))
1348 (setq props
(text-properties-at (point)))
1349 (delete-region (match-beginning 1) (match-end 1))
1352 (unless desc
(insert "][" link
))
1353 (add-text-properties pos
(point) props
))))))
1355 (defun org-export-remember-html-container-classes ()
1356 "Store the HTML_CONTAINER_CLASS properties in a text property."
1357 (goto-char (point-min))
1359 (while (re-search-forward
1360 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t
)
1361 (setq class
(match-string 1))
1363 (org-back-to-heading t
)
1364 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1366 (defvar org-export-format-drawer-function nil
1367 "Function to be called to format the contents of a drawer.
1368 The function must accept three parameters:
1369 NAME the drawer name, like \"PROPERTIES\"
1370 CONTENT the content of the drawer.
1371 BACKEND one of the symbols html, docbook, latex, ascii, xoxo
1372 The function should return the text to be inserted into the buffer.
1373 If this is nil, `org-export-format-drawer' is used as a default.")
1375 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend
)
1376 "Remove drawers, or extract and format the content.
1377 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1378 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1379 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1380 EXP-DRAWERS will be removed.
1381 BACKEND is the current export backend."
1382 (goto-char (point-min))
1383 (let ((re (concat "^[ \t]*:\\("
1384 (mapconcat 'identity all-drawers
"\\|")
1386 name beg beg-content eol content
)
1387 (while (re-search-forward re nil t
)
1389 (setq name
(match-string 1))
1390 (setq beg
(match-beginning 0)
1391 beg-content
(1+ (point-at-eol))
1393 (if (not (and (re-search-forward
1394 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1397 (goto-char (match-beginning 0))
1398 (and (looking-at ".*\n?") (replace-match ""))
1399 (setq content
(buffer-substring beg-content
(point)))
1400 (delete-region beg
(point))
1401 (when (or (eq exp-drawers t
)
1402 (member name exp-drawers
))
1403 (setq content
(funcall (or org-export-format-drawer-function
1404 'org-export-format-drawer
)
1405 name content backend
))
1406 (insert content
)))))))
1408 (defun org-export-format-drawer (name content backend
)
1409 "Format the content of a drawer as a colon example."
1410 (if (string-match "[ \t]+\\'" content
)
1411 (setq content
(substring content
(match-beginning 0))))
1412 (while (string-match "\\`[ \t]*\n" content
)
1413 (setq content
(substring content
(match-end 0))))
1414 (setq content
(org-remove-indentation content
))
1415 (setq content
(concat ": " (mapconcat 'identity
1416 (org-split-string content
"\n")
1419 (setq content
(concat " : " (upcase name
) "\n" content
))
1420 (org-add-props content nil
'org-protected t
))
1422 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1423 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1424 Both arguments are lists of tags.
1425 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1427 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1429 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1430 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1433 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1437 (goto-char (point-min))
1438 (when (and select-tags
1440 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1441 ;; At least one tree is marked for export, this means
1442 ;; all the unmarked stuff needs to go.
1443 ;; Dig out the trees that should be exported
1444 (goto-char (point-min))
1445 (outline-next-heading)
1447 (put-text-property beg
(point-max) :org-delete t
)
1448 (while (re-search-forward re-sel nil t
)
1449 (when (org-on-heading-p)
1450 (org-back-to-heading)
1451 (remove-text-properties
1452 (max (1- (point)) (point-min))
1453 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1455 (while (and (org-up-heading-safe)
1456 (get-text-property (point) :org-delete
))
1457 (remove-text-properties (max (1- (point)) (point-min))
1458 (point-at-eol) '(:org-delete t
)))
1460 ;; Remove the trees explicitly marked for noexport
1462 (goto-char (point-min))
1463 (while (re-search-forward re-excl nil t
)
1464 (when (org-at-heading-p)
1465 (org-back-to-heading t
)
1467 (org-end-of-subtree t t
)
1468 (delete-region beg
(point))
1469 (when (featurep 'org-inlinetask
)
1470 (org-inlinetask-remove-END-maybe)))))
1471 ;; Remove everything that is now still marked for deletion
1472 (goto-char (point-min))
1473 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1474 (setq end
(or (next-single-property-change beg
:org-delete
)
1476 (delete-region beg end
))))
1478 (defun org-export-remove-archived-trees (export-archived-trees)
1479 "Remove archived trees.
1480 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1481 When it is t, the entire archived tree will be exported.
1482 When it is nil the entire tree including the headline will be removed
1484 (let ((re-archive (concat ":" org-archive-tag
":"))
1486 (when (not (eq export-archived-trees t
))
1487 (goto-char (point-min))
1488 (while (re-search-forward re-archive nil t
)
1489 (if (not (org-on-heading-p t
))
1490 (goto-char (point-at-eol))
1491 (beginning-of-line 1)
1492 (setq a
(if export-archived-trees
1493 (1+ (point-at-eol)) (point))
1494 b
(org-end-of-subtree t
))
1495 (if (> b a
) (delete-region a b
)))))))
1497 (defun org-export-remove-headline-metadata (opts)
1498 "Remove meta data from the headline, according to user options."
1499 (let ((re org-complex-heading-regexp
)
1500 (todo (plist-get opts
:todo-keywords
))
1501 (tags (plist-get opts
:tags
))
1502 (pri (plist-get opts
:priority
))
1505 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1506 (when (or (not todo
) (not tags
) (not pri
))
1507 (goto-char (point-min))
1508 (while (re-search-forward re nil t
)
1510 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1512 (replace-match rpl t t
))))))
1514 (defun org-export-remove-timestamps ()
1515 "Remove timestamps and keywords for export."
1516 (goto-char (point-min))
1517 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1520 (unless (save-match-data (org-at-table-p))
1522 (beginning-of-line 1)
1523 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1524 (replace-match ""))))))
1526 (defun org-export-remove-clock-lines ()
1527 "Remove clock lines for export."
1528 (goto-char (point-min))
1529 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1530 (while (re-search-forward re nil t
)
1532 (replace-match "")))))
1534 (defun org-export-protect-quoted-subtrees ()
1535 "Mark quoted subtrees with the protection property."
1536 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1537 (goto-char (point-min))
1538 (while (re-search-forward re-quote nil t
)
1539 (goto-char (match-beginning 0))
1541 (add-text-properties (point) (org-end-of-subtree t
)
1542 '(org-protected t
)))))
1544 (defun org-export-convert-protected-spaces (backend)
1545 "Convert strings like \\____ to protected spaces in all backends."
1546 (goto-char (point-min))
1547 (while (re-search-forward "\\\\__+" nil t
)
1548 (org-if-unprotected-1
1552 ((eq backend
'latex
)
1553 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1555 (org-add-props (match-string 0) nil
1556 'org-whitespace
(- (match-end 0) (match-beginning 0))))
1557 ;; ((eq backend 'docbook))
1558 ((eq backend
'ascii
)
1559 (org-add-props (match-string 0) '(org-whitespace t
)))
1560 (t (make-string (- (match-end 0) (match-beginning 0)) ?\
)))
1564 (defun org-export-protect-verbatim ()
1565 "Mark verbatim snippets with the protection property."
1566 (goto-char (point-min))
1567 (while (re-search-forward org-verbatim-re nil t
)
1569 (add-text-properties (match-beginning 4) (match-end 4)
1570 '(org-protected t org-verbatim-emph t
))
1571 (goto-char (1+ (match-end 4))))))
1573 (defun org-export-protect-colon-examples ()
1574 "Protect lines starting with a colon."
1575 (goto-char (point-min))
1576 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1577 (while (re-search-forward re nil t
)
1578 (beginning-of-line 1)
1580 (while (looking-at re
)
1582 (or (eobp) (forward-char 1)))
1583 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1584 '(org-protected t
)))))
1586 (defun org-export-select-backend-specific-text (backend)
1588 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1589 (html "HTML" "BEGIN_HTML" "END_HTML")
1590 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1591 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1592 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1593 (case-fold-search t
)
1594 fmt beg beg-content end end-content
)
1597 (setq fmt
(pop formatters
))
1598 ;; Handle #+Backend: stuff
1599 (goto-char (point-min))
1600 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1601 ":[ \t]*\\(.*\\)") nil t
)
1602 (if (not (eq (car fmt
) backend
))
1603 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1604 (replace-match "\\1\\2" t
)
1605 (add-text-properties
1606 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1607 '(org-protected t
))))
1608 ;; Delete #+attr_Backend: stuff of another backend. Those
1609 ;; matching the current backend will be taken care of by
1610 ;; `org-export-attach-captions-and-attributes'
1611 (goto-char (point-min))
1612 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt
)
1613 ":[ \t]*\\(.*\\)") nil t
)
1614 (when (not (eq (car fmt
) backend
))
1615 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1616 ;; Handle #+begin_Backend and #+end_Backend stuff
1617 (goto-char (point-min))
1618 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt
) "\\>.*\n?")
1620 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1621 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt
) "\\>.*\n?")
1623 (setq end
(match-end 0) end-content
(match-beginning 0))
1624 (if (eq (car fmt
) backend
)
1627 (add-text-properties beg-content end-content
'(org-protected t
))
1628 (delete-region (match-beginning 0) (match-end 0))
1631 (delete-region (point) (1+ (point-at-eol)))))
1632 ;; No, this is for a different backend, kill it
1633 (delete-region beg end
)))))))
1635 (defun org-export-mark-blockquote-verse-center ()
1636 "Mark block quote and verse environments with special cookies.
1637 These special cookies will later be interpreted by the backend."
1639 (let (type t1 ind beg end beg1 end1 content
)
1640 (goto-char (point-min))
1641 (while (re-search-forward
1642 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1644 (setq ind
(length (match-string 1))
1645 type
(downcase (match-string 3))
1646 t1
(if (equal type
"quote") "blockquote" type
))
1647 (setq beg
(match-beginning 0)
1648 beg1
(1+ (match-end 0)))
1649 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1650 (setq end1
(1- (match-beginning 0))
1651 end
(+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1652 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1653 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1655 "ORG-" (upcase t1
) "-END\n"))
1656 (delete-region beg end
)
1657 (insert (org-add-props content nil
'original-indentation ind
))))))
1659 (defun org-export-mark-list-ending (backend)
1660 "Mark list endings with special cookies.
1661 These special cookies will later be interpreted by the backend.
1662 `org-list-end-re' is replaced by a blank line in the process."
1663 (let ((process-buffer
1664 (lambda (end-list-marker)
1665 (goto-char (point-min))
1666 (while (org-search-forward-unenclosed org-item-beginning-re nil t
)
1667 (goto-char (org-list-bottom-point))
1668 (when (and (not (eq org-list-ending-method
'indent
))
1669 (looking-at (org-list-end-re)))
1670 (replace-match "\n"))
1671 (insert end-list-marker
)))))
1672 ;; We need to divide backends into 3 categories.
1674 ;; 1. Backends using `org-list-parse-list' do not need markers.
1675 ((memq backend
'(latex))
1677 ;; 2. Line-processing backends need to be told where lists end.
1678 ((memq backend
'(html docbook
))
1679 (funcall process-buffer
"ORG-LIST-END\n"))
1680 ;; 3. Others backends do not need to know this: clean list enders.
1682 (funcall process-buffer
"")))))
1684 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1685 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1686 If the next thing following is a table, add the text properties to the first
1687 table line. If it is a link, add it to the line containing the link."
1688 (goto-char (point-min))
1689 (remove-text-properties (point-min) (point-max)
1690 '(org-caption nil org-attributes nil
))
1691 (let ((case-fold-search t
)
1692 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1694 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1696 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1698 "^[ \t]*\\(|[^-]\\)"
1700 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1701 cap shortn attr label end
)
1702 (while (re-search-forward re nil t
)
1706 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1))))
1707 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap
)
1708 (setq shortn
(match-string 1 cap
)
1709 cap
(match-string 2 cap
)))
1710 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1713 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2))))
1714 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1717 (setq label
(org-trim (match-string 3)))
1718 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1720 (setq end
(if (match-end 4)
1721 (let ((ee (org-table-end)))
1722 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1724 (add-text-properties (point-at-bol) end
1725 (list 'org-caption cap
1726 'org-caption-shortn shortn
1727 'org-attributes attr
1729 (if label
(push (cons label label
) target-alist
))
1731 (setq cap nil attr nil label nil
)))))
1734 (defun org-export-remove-comment-blocks-and-subtrees ()
1735 "Remove the comment environment, and also commented subtrees."
1736 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1738 ;; Remove comment environment
1739 (goto-char (point-min))
1740 (setq case-fold-search t
)
1741 (while (re-search-forward
1742 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t
)
1743 (replace-match "" t t
))
1744 ;; Remove subtrees that are commented
1745 (goto-char (point-min))
1746 (setq case-fold-search nil
)
1747 (while (re-search-forward re-commented nil t
)
1748 (goto-char (match-beginning 0))
1749 (delete-region (point) (org-end-of-subtree t
)))))
1751 (defun org-export-handle-comments (commentsp)
1752 "Remove comments, or convert to backend-specific format.
1753 COMMENTSP can be a format string for publishing comments.
1754 When it is nil, all comments will be removed."
1755 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1757 (goto-char (point-min))
1758 (while (or (looking-at re
)
1759 (re-search-forward re nil t
))
1760 (setq pos
(match-beginning 0))
1761 (if (get-text-property pos
'org-protected
)
1762 (goto-char (1+ pos
))
1764 (not (equal (char-before (match-end 1)) ?
+)))
1765 (progn (add-text-properties
1766 (match-beginning 0) (match-end 0) '(org-protected t
))
1767 (replace-match (format commentsp
(match-string 2)) t t
))
1768 (goto-char (1+ pos
))
1770 (goto-char (max (point-min) (1- pos
))))))))
1772 (defun org-export-handle-table-metalines ()
1773 "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
1774 (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
1776 (goto-char (point-min))
1777 (while (or (looking-at re
)
1778 (re-search-forward re nil t
))
1779 (setq pos
(match-beginning 0))
1780 (if (get-text-property (match-beginning 1) 'org-protected
)
1781 (goto-char (1+ pos
))
1782 (goto-char (1+ pos
))
1784 (goto-char (max (point-min) (1- pos
)))))))
1786 (defun org-export-mark-radio-links ()
1787 "Find all matches for radio targets and turn them into internal links."
1788 (let ((re-radio (and org-target-link-regexp
1789 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1790 (goto-char (point-min))
1792 (while (re-search-forward re-radio nil t
)
1795 (or (org-in-regexp org-bracket-link-regexp
)
1796 (org-in-regexp org-plain-link-re
)
1797 (org-in-regexp "<<[^<>]+>>")))
1799 (replace-match "\\1[[\\2]]")))))))
1801 (defun org-store-forced-table-alignment ()
1802 "Find table lines which force alignment, store the results in properties."
1803 (let (line cnt aligns
)
1804 (goto-char (point-min))
1805 (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t
)
1806 ;; OK, this looks like a table line with an alignment cookie
1808 (setq line
(buffer-substring (point-at-bol) (point-at-eol)))
1809 (when (and (org-at-table-p)
1810 (org-table-cookie-line-p line
))
1811 (setq cnt
0 aligns nil
)
1815 (if (string-match "\\`<\\([lrc]\\)" x
)
1816 (push (cons cnt
(downcase (match-string 1 x
))) aligns
)))
1817 (org-split-string line
"[ \t]*|[ \t]*"))
1818 (add-text-properties (org-table-begin) (org-table-end)
1819 (list 'org-forced-aligns aligns
))))
1820 (goto-char (point-at-eol)))))
1822 (defun org-export-remove-special-table-lines ()
1823 "Remove tables lines that are used for internal purposes.
1824 Also, store forcedalignment information found in such lines."
1825 (goto-char (point-min))
1826 (while (re-search-forward "^[ \t]*|" nil t
)
1827 (org-if-unprotected-at (1- (point))
1828 (beginning-of-line 1)
1829 (if (or (looking-at "[ \t]*| *[!_^] *|")
1835 (or (= (length f
) 0)
1837 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f
)))
1838 (org-split-string ;; FIXME, can't we do without splitting???
1839 (buffer-substring (point-at-bol) (point-at-eol))
1840 "[ \t]*|[ \t]*")))))
1841 (delete-region (max (point-min) (1- (point-at-bol)))
1845 (defun org-export-protect-sub-super (s)
1847 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
1848 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
1851 (defun org-export-normalize-links ()
1852 "Convert all links to bracket links, and expand link abbreviations."
1853 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1854 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1856 (goto-char (point-min))
1857 (while (re-search-forward re-plain-link nil t
)
1858 (unless (org-string-match-p
1859 "\\[\\[\\S+:\\S-*?\\<"
1860 (buffer-substring (point-at-bol) (match-beginning 0)))
1861 (goto-char (1- (match-end 0)))
1862 (org-if-unprotected-at (1+ (match-beginning 0))
1863 (let* ((s (concat (match-string 1)
1864 "[[" (match-string 2) ":" (match-string 3)
1865 "][" (match-string 2) ":" (org-export-protect-sub-super
1868 ;; added 'org-link face to links
1869 (put-text-property 0 (length s
) 'face
'org-link s
)
1870 (replace-match s t t
)))))
1871 (goto-char (point-min))
1872 (while (re-search-forward re-angle-link nil t
)
1873 (goto-char (1- (match-end 0)))
1875 (let* ((s (concat (match-string 1)
1876 "[[" (match-string 2) ":" (match-string 3)
1877 "][" (match-string 2) ":" (org-export-protect-sub-super
1880 (put-text-property 0 (length s
) 'face
'org-link s
)
1881 (replace-match s t t
))))
1882 (goto-char (point-min))
1883 (while (re-search-forward org-bracket-link-regexp nil t
)
1884 (goto-char (1- (match-end 0)))
1885 (setq nodesc
(not (match-end 3)))
1887 (let* ((xx (save-match-data
1889 (org-link-expand-abbrev (match-string 1)))))
1891 "[[" (org-add-props (copy-sequence xx
)
1892 nil
'org-protected t
'org-no-description nodesc
)
1896 (concat "[" (copy-sequence xx
)
1899 (put-text-property 0 (length s
) 'face
'org-link s
)
1900 (replace-match s t t
))))))
1902 (defun org-export-concatenate-multiline-links ()
1903 "Find multi-line links and put it all into a single line.
1904 This is to make sure that the line-processing export backends
1905 can work correctly."
1906 (goto-char (point-min))
1907 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1908 (org-if-unprotected-at (match-beginning 1)
1909 (replace-match "\\1 \\3")
1910 (goto-char (match-beginning 0)))))
1912 (defun org-export-concatenate-multiline-emphasis ()
1913 "Find multi-line emphasis and put it all into a single line.
1914 This is to make sure that the line-processing export backends
1915 can work correctly."
1916 (goto-char (point-min))
1917 (while (re-search-forward org-emph-re nil t
)
1918 (if (and (not (= (char-after (match-beginning 3))
1919 (char-after (match-beginning 4))))
1920 (save-excursion (goto-char (match-beginning 0))
1922 (and (not (org-at-table-p))
1923 (not (org-at-heading-p))))))
1925 (subst-char-in-region (match-beginning 0) (match-end 0)
1927 (goto-char (1- (match-end 0))))
1928 (goto-char (1+ (match-beginning 0))))))
1930 (defun org-export-grab-title-from-buffer ()
1931 "Get a title for the current document, from looking at the buffer."
1932 (let ((inhibit-read-only t
))
1934 (goto-char (point-min))
1935 (let ((end (if (looking-at org-outline-regexp
)
1937 (save-excursion (outline-next-heading) (point)))))
1938 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1939 ;; Mark the line so that it will not be exported as normal text.
1941 (add-text-properties (match-beginning 0) (match-end 0)
1942 (list :org-license-to-kill t
)))
1943 ;; Return the title string
1944 (org-trim (match-string 0)))))))
1946 (defun org-export-get-title-from-subtree ()
1947 "Return subtree title and exclude it from export."
1948 (let (title (rbeg (region-beginning)) (rend (region-end)))
1951 (when (and (org-at-heading-p)
1952 (>= (org-end-of-subtree t t
) rend
))
1953 ;; This is a subtree, we take the title from the first heading
1955 (looking-at org-todo-line-regexp
)
1956 (setq title
(match-string 3))
1958 (add-text-properties (point) (1+ (point-at-eol))
1959 (list :org-license-to-kill t
)))
1960 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1963 (defun org-solidify-link-text (s &optional alist
)
1964 "Take link text and make a safe target out of it."
1969 (org-split-string s
"[ \t\r\n]+") "=="))
1970 (a (assoc rtn alist
)))
1973 (defun org-get-min-level (lines &optional offset
)
1974 "Get the minimum level in LINES."
1975 (let ((re "^\\(\\*+\\) ") l
)
1977 (while (setq l
(pop lines
))
1978 (if (string-match re l
)
1979 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1983 ;; Variable holding the vector with section numbers
1984 (defvar org-section-numbers
(make-vector org-level-max
0))
1986 (defun org-init-section-numbers ()
1987 "Initialize the vector for the section numbers."
1989 (numbers (nreverse (org-split-string "" "\\.")))
1990 (depth (1- (length org-section-numbers
)))
1991 (i depth
) number-string
)
1994 (aset org-section-numbers i
0)
1995 (setq number-string
(or (car numbers
) "0"))
1996 (if (string-match "\\`[A-Z]\\'" number-string
)
1997 (aset org-section-numbers i
1998 (- (string-to-char number-string
) ?A -
1))
1999 (aset org-section-numbers i
(string-to-number number-string
)))
2003 (defun org-section-number (&optional level
)
2004 "Return a string with the current section number.
2005 When LEVEL is non-nil, increase section numbers on that level."
2006 (let* ((depth (1- (length org-section-numbers
)))
2008 (fmts (car org-export-section-number-format
))
2009 (term (cdr org-export-section-number-format
))
2014 (aset org-section-numbers
2015 level
(1+ (aref org-section-numbers level
))))
2016 (setq idx
(1+ level
))
2017 (while (<= idx depth
)
2019 (aset org-section-numbers idx
0))
2020 (setq idx
(1+ idx
))))
2022 (while (<= idx depth
)
2023 (when (> (aref org-section-numbers idx
) 0)
2024 (setq fmt
(or (pop fmts
) fmt
)
2026 n
(aref org-section-numbers idx
)
2028 (concat string sep
(org-number-to-counter n ctype
))
2029 (concat string
".0"))
2031 (setq idx
(1+ idx
)))
2033 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2034 (setq string
(replace-match "" t nil string
)))
2035 (if (string-match "\\(\\.0\\)+\\'" string
)
2036 (setq string
(replace-match "" t nil string
))))
2037 (concat string term
)))
2039 (defun org-number-to-counter (n type
)
2040 "Concert number N to a string counter, according to TYPE.
2041 TYPE must be a string, any of:
2045 I upper case roman numeral
2046 i lower case roman numeral"
2048 ((equal type
"1") (number-to-string n
))
2049 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2050 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2051 ((equal type
"I") (org-number-to-roman n
))
2052 ((equal type
"i") (downcase (org-number-to-roman n
)))
2053 (t (error "Invalid counter type `%s'" type
))))
2055 (defun org-number-to-roman (n)
2056 "Convert integer N into a roman numeral."
2057 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2058 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2059 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2063 (number-to-string n
)
2065 (if (>= n
(caar roman
))
2066 (setq n
(- n
(caar roman
))
2067 res
(concat res
(cdar roman
)))
2073 (defun org-export-preprocess-apply-macros ()
2074 "Replace macro references."
2075 (goto-char (point-min))
2076 (let (sy val key args args2 s n
)
2077 (while (re-search-forward
2078 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2080 (unless (save-match-data
2082 (goto-char (point-at-bol))
2083 (looking-at "[ \t]*#\\+macro")))
2084 (setq key
(downcase (match-string 1))
2085 args
(match-string 3))
2086 (when (setq val
(or (plist-get org-export-opt-plist
2087 (intern (concat ":macro-" key
)))
2088 (plist-get org-export-opt-plist
2089 (intern (concat ":" key
)))))
2092 (setq args
(org-split-string args
",") args2 nil
)
2094 (while (string-match "\\\\\\'" (car args
))
2095 ;; repair bad splits
2096 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2099 (push (pop args
) args2
))
2100 (setq args
(mapcar 'org-trim
(nreverse args2
)))
2102 (while (string-match "\\$\\([0-9]+\\)" val s
)
2103 (setq s
(1+ (match-beginning 0))
2104 n
(string-to-number (match-string 1 val
)))
2105 (and (>= (length args
) n
)
2106 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2107 (when (string-match "\\`(eval\\>" val
)
2108 (setq val
(eval (read val
))))
2109 (if (and val
(not (stringp val
)))
2110 (setq val
(format "%s" val
))))
2112 (prog1 (replace-match val t t
)
2113 (goto-char (match-beginning 0)))))))))
2115 (defun org-export-apply-macros-in-string (s)
2116 "Apply the macros in string S."
2120 (org-export-preprocess-apply-macros)
2125 (defun org-export-handle-include-files ()
2126 "Include the contents of include files, with proper formatting."
2127 (let ((case-fold-search t
)
2128 params file markup lang start end prefix prefix1 switches all minlevel
)
2129 (goto-char (point-min))
2130 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2131 (setq params
(read (concat "(" (match-string 1) ")"))
2132 prefix
(org-get-and-remove-property 'params
:prefix
)
2133 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2134 minlevel
(org-get-and-remove-property 'params
:minlevel
)
2135 file
(org-symname-or-string (pop params
))
2136 markup
(org-symname-or-string (pop params
))
2137 lang
(and (member markup
'("src" "SRC"))
2138 (org-symname-or-string (pop params
)))
2139 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" ")
2141 (delete-region (match-beginning 0) (match-end 0))
2143 (not (file-exists-p file
))
2144 (not (file-readable-p file
)))
2145 (insert (format "CANNOT INCLUDE FILE %s" file
))
2146 (setq all
(cons file all
))
2148 (if (equal (downcase markup
) "src")
2149 (setq start
(format "#+begin_src %s %s\n"
2150 (or lang
"fundamental")
2153 (setq start
(format "#+begin_%s %s\n" markup switches
)
2154 end
(format "#+end_%s" markup
))))
2155 (insert (or start
""))
2156 (insert (org-get-file-contents (expand-file-name file
)
2157 prefix prefix1 markup minlevel
))
2158 (or (bolp) (newline))
2159 (insert (or end
""))))
2162 (defun org-export-handle-include-files-recurse ()
2163 "Recursively include files aborting on circular inclusion."
2164 (let ((now (list org-current-export-file
)) all
)
2166 (setq all
(append now all
))
2167 (setq now
(org-export-handle-include-files))
2170 (mapcar (lambda (el) (when (member el all
) el
)) now
))))
2172 (error "Recursive #+INCLUDE: %S" intersection
))))))
2174 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel
)
2175 "Get the contents of FILE and return them as a string.
2176 If PREFIX is a string, prepend it to each line. If PREFIX1
2177 is a string, prepend it to the first line instead of PREFIX.
2178 If MARKUP, don't protect org-like lines, the exporter will
2179 take care of the block they are in."
2180 (if (stringp markup
) (setq markup
(downcase markup
)))
2182 (insert-file-contents file
)
2183 (when (or prefix prefix1
)
2184 (goto-char (point-min))
2186 (insert (or prefix1 prefix
))
2188 (beginning-of-line 2)))
2190 (when (member markup
'("src" "example"))
2191 (goto-char (point-min))
2192 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2193 (goto-char (match-beginning 0))
2197 (dotimes (lvl minlevel
)
2198 (org-map-region 'org-demote
(point-min) (point-max))))
2201 (defun org-get-and-remove-property (listvar prop
)
2202 "Check if the value of LISTVAR contains PROP as a property.
2203 If yes, return the value of that property (i.e. the element following
2204 in the list) and remove property and value from the list in LISTVAR."
2205 (let ((list (symbol-value listvar
)) m v
)
2206 (when (setq m
(member prop list
))
2208 (if (equal (car list
) prop
)
2209 (set listvar
(cddr list
))
2210 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2212 (set listvar list
)))
2215 (defun org-symname-or-string (s)
2217 (if s
(symbol-name s
) s
)
2220 ;;; Fontification and line numbers for code examples
2222 (defvar org-export-last-code-line-counter-value
0)
2224 (defun org-export-replace-src-segments-and-examples (backend)
2225 "Replace source code segments with special code for export."
2226 (setq org-export-last-code-line-counter-value
0)
2227 (let ((case-fold-search t
)
2228 lang code trans opts indent caption
)
2229 (goto-char (point-min))
2230 (while (re-search-forward
2231 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2234 (if (not (match-string 4))
2235 (error "Source block missing language specification: %s"
2236 (let* ((body (match-string 6))
2237 (nothing (message "body:%s" body
))
2238 (preview (or (and (string-match
2239 "^[ \t]*\\([^\n\r]*\\)" body
)
2240 (match-string 1 body
)) body
)))
2241 (if (> (length preview
) 35)
2242 (concat (substring preview
0 32) "...")
2245 (setq lang
(match-string 4)
2246 opts
(match-string 5)
2247 code
(match-string 6)
2248 indent
(length (match-string 2))
2249 caption
(get-text-property 0 'org-caption
(match-string 0))))
2251 opts
(match-string 9)
2252 code
(match-string 10)
2253 indent
(length (match-string 8))
2254 caption
(get-text-property 0 'org-caption
(match-string 0))))
2256 (setq trans
(org-export-format-source-code-or-example
2257 backend lang code opts indent caption
))
2258 (replace-match trans t t
))))
2260 (defvar htmlp
) ;; dynamically scoped
2261 (defvar latexp
) ;; dynamically scoped
2262 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2263 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2264 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2265 (defvar org-export-latex-listings-w-names
) ;; defined in org-latex.el
2266 (defvar org-export-latex-minted-langs
) ;; defined in org-latex.el
2267 (defun org-export-format-source-code-or-example
2268 (backend lang code
&optional opts indent caption
)
2269 "Format CODE from language LANG and return it formatted for export.
2270 If LANG is nil, do not add any fontification.
2271 OPTS contains formatting options, like `-n' for triggering numbering lines,
2272 and `+n' for continuing previous numbering.
2273 Code formatting according to language currently only works for HTML.
2274 Numbering lines works for all three major backends (html, latex, and ascii).
2275 INDENT was the original indentation of the block."
2277 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2278 (setq opts
(or opts
"")
2279 num
(string-match "[-+]n\\>" opts
)
2280 cont
(string-match "\\+n\\>" opts
)
2281 rpllbl
(string-match "-r\\>" opts
)
2282 keepp
(string-match "-k\\>" opts
)
2283 textareap
(string-match "-t\\>" opts
)
2284 preserve-indentp
(or org-src-preserve-indentation
2285 (string-match "-i\\>" opts
))
2286 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2287 (string-to-number (match-string 1 opts
))
2289 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2290 (string-to-number (match-string 1 opts
))
2291 (org-count-lines code
))
2292 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2293 (match-string 1 opts
)))
2294 (when (and textareap
(eq backend
'html
))
2295 ;; we cannot use numbering or highlighting.
2296 (setq num nil cont nil lang nil
))
2297 (if keepp
(setq rpllbl
'keep
))
2298 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2299 (when (string-match "^," rtn
)
2300 (setq rtn
(with-temp-buffer
2302 ;; Free up the protected lines
2303 (goto-char (point-min))
2304 (while (re-search-forward "^," nil t
)
2305 (if (or (equal lang
"org")
2307 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2311 ;; Now backend-specific coding
2314 ((eq backend
'docbook
)
2315 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2316 (concat "\n#+BEGIN_DOCBOOK\n"
2317 (org-add-props (concat "<programlisting><![CDATA["
2319 "]]></programlisting>\n")
2320 '(org-protected t org-example t
))
2323 ;; We are exporting to HTML
2325 (if (featurep 'xemacs
)
2327 (require 'htmlize nil t
))
2328 (when (not (fboundp 'htmlize-region-for-paste
))
2329 ;; we do not have htmlize.el, or an old version of it
2332 "htmlize.el 1.34 or later is needed for source code formatting")))
2335 (let* ((lang-m (when lang
2336 (or (cdr (assoc lang org-src-lang-modes
))
2338 (mode (and lang-m
(intern
2340 (if (symbolp lang-m
)
2341 (symbol-name lang-m
)
2344 (org-inhibit-startup t
)
2345 (org-startup-folded nil
))
2349 (if (functionp mode
)
2352 (font-lock-fontify-buffer)
2354 (set-buffer-modified-p nil
)
2355 (org-export-htmlize-region-for-paste
2356 (point-min) (point-max))))
2357 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2362 "<div class=\"org-src-container\">"
2364 "<label class=\"org-src-name\">%s</label>"
2368 (format "<pre class=\"src src-%s\">\n" lang
)
2370 (if caption
"</div>" "")))))
2373 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2375 rtn
"</textarea>\n</p>\n"))
2378 (goto-char (point-min))
2379 (while (re-search-forward "[<>&]" nil t
)
2380 (replace-match (cdr (assq (char-before)
2381 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2383 (setq rtn
(buffer-string)))
2384 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2386 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2388 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2389 (setq rtn
(replace-match "\\1" t nil rtn
)))
2390 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t org-example t
)) "\n#+END_HTML\n\n"))
2391 ((eq backend
'latex
)
2392 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2393 (concat "#+BEGIN_LaTeX\n"
2396 ((and org-export-latex-listings
2397 (not (eq org-export-latex-listings
'minted
)))
2401 ((lang-sym (intern lang
))
2406 org-export-latex-listings-langs
))
2408 (format "\\lstset{language=%s}\n" lstlang
))
2411 org-export-latex-listings-w-names
)
2412 (format "\n%s $\\equiv$ \n"
2413 (replace-regexp-in-string
2414 "_" "\\\\_" caption
)))
2415 "\\begin{lstlisting}\n"
2416 rtn
"\\end{lstlisting}\n"))
2417 ((eq org-export-latex-listings
'minted
)
2420 ((lang-sym (intern lang
))
2425 org-export-latex-minted-langs
))
2429 org-export-latex-listings-w-names
)
2430 (format "\n%s $\\equiv$ \n"
2431 (replace-regexp-in-string
2432 "_" "\\\\_" caption
)))
2433 (format "\\begin{minted}{%s}\n" minted-lang
)
2434 rtn
"\\end{minted}\n"))))
2435 (t (concat (car org-export-latex-verbatim-wrap
)
2436 rtn
(cdr org-export-latex-verbatim-wrap
))))
2437 '(org-protected t org-example t
))
2439 ((eq backend
'ascii
)
2440 ;; This is not HTML or LaTeX, so just make it an example.
2441 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2442 (concat caption
"\n"
2447 (lambda (l) (concat " " l
))
2448 (org-split-string rtn
"\n")
2451 '(org-protected t org-example t
))
2453 (org-add-props rtn nil
'original-indentation indent
))))
2455 (defun org-export-number-lines (text backend
2456 &optional skip1 skip2 number cont
2457 replace-labels label-format
)
2458 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2459 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2462 (goto-char (point-max))
2463 (skip-chars-backward " \t\n\r")
2464 (delete-region (point) (point-max))
2465 (beginning-of-line (- 1 skip2
))
2466 (let* ((last (org-current-line))
2467 (n org-export-last-code-line-counter-value
)
2468 (nmax (+ n
(- last skip1
)))
2469 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2472 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2474 ((eq backend
'ascii
) fmt
)
2475 ((eq backend
'latex
) fmt
)
2476 ((eq backend
'docbook
) fmt
)
2478 (label-format (or label-format org-coderef-label-format
))
2479 (label-pre (if (string-match "%s" label-format
)
2480 (substring label-format
0 (match-beginning 0))
2482 (label-post (if (string-match "%s" label-format
)
2483 (substring label-format
(match-end 0))
2487 ".*?\\S-.*?\\([ \t]*\\("
2488 (regexp-quote label-pre
)
2489 "\\([-a-zA-Z0-9_ ]+\\)"
2490 (regexp-quote label-post
)
2494 (org-goto-line (1+ skip1
))
2495 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2497 (insert (format fm
(incf n
)))
2499 (when (looking-at lbl-re
)
2500 (setq ref
(match-string 3))
2501 (cond ((numberp replace-labels
)
2502 ;; remove labels; use numbers for references when lines
2503 ;; are numbered, use labels otherwise
2504 (delete-region (match-beginning 1) (match-end 1))
2505 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2506 ((eq replace-labels
'keep
)
2507 ;; don't remove labels; use numbers for references when
2508 ;; lines are numbered, use labels otherwise
2509 (goto-char (match-beginning 2))
2510 (delete-region (match-beginning 2) (match-end 2))
2511 (insert "(" ref
")")
2512 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2513 org-export-code-refs
))
2515 ;; don't remove labels and don't use numbers for
2517 (goto-char (match-beginning 2))
2518 (delete-region (match-beginning 2) (match-end 2))
2519 (insert "(" ref
")")
2520 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2521 (when (eq backend
'html
)
2523 (beginning-of-line 1)
2524 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2527 (insert "</span>")))))
2528 (setq org-export-last-code-line-counter-value n
)
2529 (goto-char (point-max))
2533 (defun org-search-todo-below (line lines level
)
2534 "Search the subtree below LINE for any TODO entries."
2535 (let ((rest (cdr (memq line lines
)))
2536 (re org-todo-line-regexp
)
2539 (while (setq line
(pop rest
))
2540 (if (string-match re line
)
2542 (setq lv
(- (match-end 1) (match-beginning 1))
2543 todo
(and (match-beginning 2)
2544 (not (member (match-string 2 line
)
2545 org-done-keywords
))))
2547 (if (<= lv level
) (throw 'exit nil
))
2548 (if todo
(throw 'exit t
))))))))
2551 (defun org-export-visible (type arg
)
2552 "Create a copy of the visible part of the current buffer, and export it.
2553 The copy is created in a temporary buffer and removed after use.
2554 TYPE is the final key (as a string) that also selects the export command in
2555 the \\<org-mode-map>\\[org-export] export dispatcher.
2556 As a special case, if the you type SPC at the prompt, the temporary
2557 org-mode file will not be removed but presented to you so that you can
2558 continue to use it. The prefix arg ARG is passed through to the exporting
2562 (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")
2563 (read-char-exclusive))
2564 current-prefix-arg
))
2565 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L
)))
2566 (error "Invalid export key"))
2567 (let* ((binding (cdr (assoc type
2569 (?a . org-export-as-ascii
)
2570 (?A . org-export-as-ascii-to-buffer
)
2571 (?n . org-export-as-latin1
)
2572 (?N . org-export-as-latin1-to-buffer
)
2573 (?u . org-export-as-utf8
)
2574 (?U . org-export-as-utf8-to-buffer
)
2575 (?\C-a . org-export-as-ascii
)
2576 (?b . org-export-as-html-and-open
)
2577 (?\C-b . org-export-as-html-and-open
)
2578 (?h . org-export-as-html
)
2579 (?H . org-export-as-html-to-buffer
)
2580 (?R . org-export-region-as-html
)
2581 (?D . org-export-as-docbook
)
2583 (?l . org-export-as-latex
)
2584 (?p . org-export-as-pdf
)
2585 (?d . org-export-as-pdf-and-open
)
2586 (?L . org-export-as-latex-to-buffer
)
2588 (?x . org-export-as-xoxo
)))))
2589 (keepp (equal type ?\
))
2590 (file buffer-file-name
)
2591 (buffer (get-buffer-create "*Org Export Visible*"))
2593 ;; Need to hack the drawers here.
2595 (goto-char (point-min))
2596 (while (re-search-forward org-drawer-regexp nil t
)
2597 (goto-char (match-beginning 1))
2598 (or (org-invisible-p) (org-flag-drawer nil
))))
2599 (with-current-buffer buffer
(erase-buffer))
2601 (setq s
(goto-char (point-min)))
2602 (while (not (= (point) (point-max)))
2603 (goto-char (org-find-invisible))
2604 (append-to-buffer buffer s
(point))
2605 (setq s
(goto-char (org-find-visible))))
2606 (org-cycle-hide-drawers 'all
)
2607 (goto-char (point-min))
2609 ;; Copy all comment lines to the end, to make sure #+ settings are
2610 ;; still available for the second export step. Kind of a hack, but
2611 ;; does do the trick.
2612 (if (looking-at "#[^\r\n]*")
2613 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2614 (when (re-search-forward "^\\*+[ \t]+" nil t
)
2615 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t
)
2616 (append-to-buffer buffer
(1+ (match-beginning 0))
2617 (min (point-max) (1+ (match-end 0)))))))
2619 (let ((buffer-file-name file
)
2620 (org-inhibit-startup t
))
2623 (unless keepp
(funcall binding arg
))))
2625 (kill-buffer buffer
)
2626 (switch-to-buffer-other-window buffer
)
2627 (goto-char (point-min)))))
2629 (defun org-find-visible ()
2631 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2632 (get-char-property s
'invisible
)))
2634 (defun org-find-invisible ()
2636 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2637 (not (get-char-property s
'invisible
))))
2640 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2642 (defun org-export-string (string fmt
&optional dir
)
2643 "Export STRING to FMT using existing export facilities.
2644 During export STRING is saved to a temporary file whose location
2645 could vary. Optional argument DIR can be used to force the
2646 directory in which the temporary file is created during export
2647 which can be useful for resolving relative paths. Dir defaults
2648 to the value of `temporary-file-directory'."
2649 (let ((temporary-file-directory (or dir temporary-file-directory
))
2650 (tmp-file (make-temp-file "org-")))
2654 (write-file tmp-file
)
2655 (org-load-modules-maybe)
2656 (unless org-local-vars
2657 (setq org-local-vars
(org-get-local-variables)))
2658 (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
2659 (list 'let org-local-vars
2660 (list (intern (concat "org-export-as-" fmt
))
2661 nil nil nil
''string t
))))
2662 (delete-file tmp-file
))))
2665 (defun org-export-as-org (arg &optional hidden ext-plist
2666 to-buffer body-only pub-dir
)
2667 "Make a copy with not-exporting stuff removed.
2668 The purpose of this function is to provide a way to export the source
2669 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2670 stuff removed. This command will remove the following:
2672 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2673 - comment blocks and trees starting with the COMMENT keyword
2674 - only trees that are consistent with `org-export-select-tags'
2675 and `org-export-exclude-tags'.
2677 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2678 all the others will be ignored (but are present so that the general
2679 mechanism to call publishing functions will work).
2681 EXT-PLIST is a property list with external parameters overriding
2682 org-mode's default settings, but still inferior to file-local
2683 settings. When PUB-DIR is set, use this as the publishing
2686 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2688 (org-infile-export-plist)))
2689 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2690 (filename (concat (file-name-as-directory
2692 (org-export-directory :org opt-plist
)))
2693 (file-name-sans-extension
2694 (file-name-nondirectory bfname
))
2696 (filename (and filename
2697 (if (equal (file-truename filename
)
2698 (file-truename bfname
))
2699 (concat (file-name-sans-extension filename
)
2701 (file-name-extension filename
))
2703 (backup-inhibited t
)
2704 (buffer (find-file-noselect filename
))
2705 (region (buffer-string))
2708 (switch-to-buffer buffer
)
2711 (let ((org-inhibit-startup t
)) (org-mode))
2712 (org-install-letbind)
2714 ;; Get rid of archived trees
2715 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2717 ;; Remove comment environment and comment subtrees
2718 (org-export-remove-comment-blocks-and-subtrees)
2720 ;; Get rid of excluded trees
2721 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2722 (plist-get opt-plist
:exclude-tags
))
2724 (when (or (plist-get opt-plist
:plain-source
)
2725 (not (or (plist-get opt-plist
:plain-source
)
2726 (plist-get opt-plist
:htmlized-source
))))
2727 ;; Either nothing special is requested (default call)
2728 ;; or the plain source is explicitly requested
2731 (when (plist-get opt-plist
:htmlized-source
)
2732 ;; Make the htmlized version
2735 (font-lock-fontify-buffer)
2736 (let* ((htmlize-output-type 'css
)
2737 (newbuf (htmlize-buffer)))
2738 (with-current-buffer newbuf
2739 (when org-export-htmlized-org-css-url
2740 (goto-char (point-min))
2741 (and (re-search-forward
2742 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2746 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2747 org-export-htmlized-org-css-url
)
2749 (write-file (concat filename
".html")))
2750 (kill-buffer newbuf
)))
2751 (set-buffer-modified-p nil
)
2752 (if (equal to-buffer
'string
)
2753 (progn (setq str-ret
(buffer-string))
2754 (kill-buffer (current-buffer))
2756 (kill-buffer (current-buffer))))))
2758 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2759 (defun org-get-current-options ()
2760 "Return a string with current options as keyword options.
2761 Does include HTML export options as well as TODO and CATEGORY stuff."
2762 (require 'org-archive
)
2771 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2772 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2774 #+EXPORT_SELECT_TAGS: %s
2775 #+EXPORT_EXCLUDE_TAGS: %s
2782 #+PRIORITIES: %c %c %c
2784 #+STARTUP: %s %s %s %s %s
2790 (buffer-name) (user-full-name) user-mail-address
2791 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2792 org-export-default-language
2793 org-export-headline-levels
2794 org-export-with-section-numbers
2796 org-export-preserve-breaks
2797 org-export-html-expand
2798 org-export-with-fixed-width
2799 org-export-with-tables
2800 org-export-with-sub-superscripts
2801 org-export-with-special-strings
2802 org-export-with-footnotes
2803 org-export-with-emphasize
2804 org-export-with-timestamps
2805 org-export-with-TeX-macros
2806 org-export-with-LaTeX-fragments
2807 org-export-skip-text-before-1st-heading
2808 org-export-with-drawers
2809 org-export-with-todo-keywords
2810 org-export-with-priority
2811 org-export-with-tags
2812 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2813 (mapconcat 'identity org-export-select-tags
" ")
2814 (mapconcat 'identity org-export-exclude-tags
" ")
2815 org-export-html-link-up
2816 org-export-html-link-home
2818 (file-name-sans-extension
2819 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2821 "TODO FEEDBACK VERIFY DONE"
2822 "Me Jason Marie DONE"
2823 org-highest-priority org-lowest-priority org-default-priority
2824 (mapconcat 'identity org-drawers
" ")
2825 (cdr (assoc org-startup-folded
2826 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2827 (if org-odd-levels-only
"odd" "oddeven")
2828 (if org-hide-leading-stars
"hidestars" "showstars")
2829 (if org-startup-align-all-tables
"align" "noalign")
2830 (cond ((eq org-log-done t
) "logdone")
2831 ((equal org-log-done
'note
) "lognotedone")
2832 ((not org-log-done
) "nologdone"))
2833 (or (mapconcat (lambda (x)
2835 ((equal :startgroup
(car x
)) "{")
2836 ((equal :endgroup
(car x
)) "}")
2837 ((equal :newline
(car x
)) "")
2838 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2840 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2841 (mapconcat 'identity org-file-tags
" ")
2842 org-archive-location
2843 "org file:~/org/%s.org"
2847 (defun org-insert-export-options-template ()
2848 "Insert into the buffer a template with information for exporting."
2850 (if (not (bolp)) (newline))
2851 (let ((s (org-get-current-options)))
2852 (and (string-match "#\\+CATEGORY" s
)
2853 (setq s
(substring s
0 (match-beginning 0))))
2856 (defvar org-table-colgroup-info nil
)
2858 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2859 "Check if the table has a marking column.
2860 If yes remove the column and the special lines."
2861 (setq org-table-colgroup-info nil
)
2864 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2867 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2868 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2871 ;; No special marking column
2873 (setq org-table-clean-did-remove-column nil
)
2878 ((org-table-colgroup-line-p x
)
2879 ;; This line contains colgroup info, extract it
2880 ;; and then discard the line
2881 (setq org-table-colgroup-info
2883 (cond ((member x
'("<" "<")) :start
)
2884 ((member x
'(">" ">")) :end
)
2885 ((member x
'("<>" "<>")) :startend
)
2887 (org-split-string x
"[ \t]*|[ \t]*")))
2889 ((org-table-cookie-line-p x
)
2890 ;; This line contains formatting cookies, discard it
2894 ;; there is a special marking column
2895 (setq org-table-clean-did-remove-column t
)
2900 ((org-table-colgroup-line-p x
)
2901 ;; This line contains colgroup info, extract it
2902 ;; and then discard the line
2903 (setq org-table-colgroup-info
2905 (cond ((member x
'("<" "<")) :start
)
2906 ((member x
'(">" ">")) :end
)
2907 ((member x
'("<>" "<>")) :startend
)
2909 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2911 ((org-table-cookie-line-p x
)
2912 ;; This line contains formatting cookies, discard it
2914 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2917 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2918 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2919 ;; remove the first column
2920 (replace-match "\\1|" t nil x
))))
2923 (defun org-export-cleanup-toc-line (s)
2924 "Remove tags and timestamps from lines going into the toc."
2925 (when (memq org-export-with-tags
'(not-in-toc nil
))
2926 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s
)
2927 (setq s
(replace-match "" t t s
))))
2928 (when org-export-remove-timestamps-from-toc
2929 (while (string-match org-maybe-keyword-time-regexp s
)
2930 (setq s
(replace-match "" t t s
))))
2931 (while (string-match org-bracket-link-regexp s
)
2932 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2934 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
2935 (setq s
(replace-match "" t t s
)))
2939 (defun org-get-text-property-any (pos prop
&optional object
)
2940 (or (get-text-property pos prop object
)
2941 (and (setq pos
(next-single-property-change pos prop object
))
2942 (get-text-property pos prop object
))))
2944 (defun org-export-get-coderef-format (path desc
)
2946 (if (and desc
(string-match
2947 (regexp-quote (concat "(" path
")"))
2949 (replace-match "%s" t t desc
)
2952 (defun org-export-push-to-kill-ring (format)
2953 "Push buffer content to kill ring.
2954 The depends on the variable `org-export-copy-to-kill'."
2955 (when org-export-copy-to-kill-ring
2956 (org-kill-new (buffer-string))
2957 (when (fboundp 'x-set-selection
)
2958 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
2959 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
2960 (message "%s export done, pushed to kill ring and clipboard" format
)))
2965 ;;; org-exp.el ends here