1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (require 'org-exp-blocks
)
41 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
42 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
43 (declare-function org-export-html-preprocess
"org-html" (parameters))
44 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
45 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
46 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
47 (declare-function htmlize-buffer
"ext:htmlize" (&optional buffer
))
48 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
49 (declare-function org-table-cookie-line-p
"org-table" (line))
50 (declare-function org-table-colgroup-line-p
"org-table" (line))
51 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
52 (defgroup org-export nil
53 "Options for exporting org-listings."
57 (defgroup org-export-general nil
58 "General options for exporting Org-mode files."
59 :tag
"Org Export General"
62 (defcustom org-export-allow-BIND
'confirm
63 "Non-nil means allow #+BIND to define local variable values for export.
64 This is a potential security risk, which is why the user must confirm the
66 :group
'org-export-general
68 (const :tag
"Never" nil
)
69 (const :tag
"Always" t
)
70 (const :tag
"Make the user confirm for each file" confirm
)))
73 (defvar org-export-publishing-directory nil
)
75 (defcustom org-export-show-temporary-export-buffer t
76 "Non-nil means show buffer after exporting to temp buffer.
77 When Org exports to a file, the buffer visiting that file is ever
78 shown, but remains buried. However, when exporting to a temporary
79 buffer, that buffer is popped up in a second window. When this variable
80 is nil, the buffer remains buried also in these cases."
81 :group
'org-export-general
84 (defcustom org-export-copy-to-kill-ring t
85 "Non-nil means exported stuff will also be pushed onto the kill ring."
86 :group
'org-export-general
89 (defcustom org-export-kill-product-buffer-when-displayed nil
90 "Non-nil means kill the product buffer if it is displayed immediately.
91 This applied to the commands `org-export-html-and-open' and
92 `org-export-as-pdf-and-open'."
93 :group
'org-export-general
96 (defcustom org-export-run-in-background nil
97 "Non-nil means export and publishing commands will run in background.
98 This works by starting up a separate Emacs process visiting the same file
99 and doing the export from there.
100 Not all export commands are affected by this - only the ones which
101 actually write to a file, and that do not depend on the buffer state.
103 If this option is nil, you can still get background export by calling
104 `org-export' with a double prefix arg: \
105 \\[universal-argument] \\[universal-argument] \\[org-export].
107 If this option is t, the double prefix can be used to exceptionally
108 force an export command into the current process."
109 :group
'org-export-general
112 (defcustom org-export-initial-scope
'buffer
113 "The initial scope when exporting with `org-export'.
114 This variable can be either set to 'buffer or 'subtree."
115 :group
'org-export-general
117 (const :tag
"Export current buffer" 'buffer
)
118 (const :tag
"Export current subtree" 'subtree
)))
120 (defcustom org-export-select-tags
'("export")
121 "Tags that select a tree for export.
122 If any such tag is found in a buffer, all trees that do not carry one
123 of these tags will be deleted before export.
124 Inside trees that are selected like this, you can still deselect a
125 subtree by tagging it with one of the `org-export-exclude-tags'."
126 :group
'org-export-general
127 :type
'(repeat (string :tag
"Tag")))
129 (defcustom org-export-exclude-tags
'("noexport")
130 "Tags that exclude a tree from export.
131 All trees carrying any of these tags will be excluded from export.
132 This is without condition, so even subtrees inside that carry one of the
133 `org-export-select-tags' will be removed."
134 :group
'org-export-general
135 :type
'(repeat (string :tag
"Tag")))
137 ;; FIXME: rename, this is a general variable
138 (defcustom org-export-html-expand t
139 "Non-nil means for HTML export, treat @<...> as HTML tag.
140 When nil, these tags will be exported as plain text and therefore
141 not be interpreted by a browser.
143 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
144 :group
'org-export-html
145 :group
'org-export-general
148 (defcustom org-export-with-special-strings t
149 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
150 When this option is turned on, these strings will be exported as:
153 -----+----------+--------
159 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
160 :group
'org-export-translation
163 (defcustom org-export-html-link-up
""
164 "Where should the \"UP\" link of exported HTML pages lead?"
165 :group
'org-export-html
166 :group
'org-export-general
167 :type
'(string :tag
"File or URL"))
169 (defcustom org-export-html-link-home
""
170 "Where should the \"HOME\" link of exported HTML pages lead?"
171 :group
'org-export-html
172 :group
'org-export-general
173 :type
'(string :tag
"File or URL"))
175 (defcustom org-export-language-setup
176 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
177 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
178 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
179 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
180 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
181 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
182 ("es" "Autor" "Fecha" "Índice" "Pies de página")
183 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
184 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
185 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
186 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
187 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
188 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
189 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
190 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
191 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
192 ("pl" "Autor" "Data" "Spis treści" "Przypis")
193 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
194 "Terms used in export text, translated to different languages.
195 Use the variable `org-export-default-language' to set the language,
196 or use the +OPTION lines for a per-file setting."
197 :group
'org-export-general
200 (string :tag
"HTML language tag")
201 (string :tag
"Author")
203 (string :tag
"Table of Contents")
204 (string :tag
"Footnotes"))))
206 (defcustom org-export-default-language
"en"
207 "The default language for export and clocktable translations, as a string.
208 This should have an association in `org-export-language-setup'
209 and in `org-clock-clocktable-language-setup'."
210 :group
'org-export-general
213 (defvar org-export-page-description
""
214 "The page description, for the XHTML meta tag.
215 This is best set with the #+DESCRIPTION line in a file, it does not make
216 sense to set this globally.")
218 (defvar org-export-page-keywords
""
219 "The page description, for the XHTML meta tag.
220 This is best set with the #+KEYWORDS line in a file, it does not make
221 sense to set this globally.")
223 (defcustom org-export-skip-text-before-1st-heading nil
224 "Non-nil means skip all text before the first headline when exporting.
225 When nil, that text is exported as well."
226 :group
'org-export-general
229 (defcustom org-export-headline-levels
3
230 "The last level which is still exported as a headline.
231 Inferior levels will produce itemize lists when exported.
232 Note that a numeric prefix argument to an exporter function overrides
235 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
236 :group
'org-export-general
239 (defcustom org-export-with-section-numbers t
240 "Non-nil means add section numbers to headlines when exporting.
242 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
243 :group
'org-export-general
246 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
247 "Format of section numbers for export.
248 The variable has two components.
249 1. A list of lists, each indicating a counter type and a separator.
250 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
251 It causes causes numeric, alphabetic, or roman counters, respectively.
252 The separator is only used if another counter for a subsection is being
254 If there are more numbered section levels than entries in this lists,
255 then the last entry will be reused.
256 2. A terminator string that will be added after the entire
258 :group
'org-export-general
262 (string :tag
"Counter Type")
263 (string :tag
"Separator ")))
264 (string :tag
"Terminator")))
266 (defcustom org-export-with-toc t
267 "Non-nil means create a table of contents in exported files.
268 The TOC contains headlines with levels up to`org-export-headline-levels'.
269 When an integer, include levels up to N in the toc, this may then be
270 different from `org-export-headline-levels', but it will not be allowed
271 to be larger than the number of headline levels.
272 When nil, no table of contents is made.
274 Headlines which contain any TODO items will be marked with \"(*)\" in
275 ASCII export, and with red color in HTML output, if the option
276 `org-export-mark-todo-in-toc' is set.
278 In HTML output, the TOC will be clickable.
280 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
282 :group
'org-export-general
284 (const :tag
"No Table of Contents" nil
)
285 (const :tag
"Full Table of Contents" t
)
286 (integer :tag
"TOC to level")))
288 (defcustom org-export-mark-todo-in-toc nil
289 "Non-nil means mark TOC lines that contain any open TODO items."
290 :group
'org-export-general
293 (defcustom org-export-with-todo-keywords t
294 "Non-nil means include TODO keywords in export.
295 When nil, remove all these keywords from the export."
296 :group
'org-export-general
299 (defcustom org-export-with-priority nil
300 "Non-nil means include priority cookies in export.
301 When nil, remove priority cookies for export."
302 :group
'org-export-general
305 (defcustom org-export-preserve-breaks nil
306 "Non-nil means preserve all line breaks when exporting.
307 Normally, in HTML output paragraphs will be reformatted. In ASCII
308 export, line breaks will always be preserved, regardless of this variable.
310 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
311 :group
'org-export-general
314 (defcustom org-export-with-archived-trees
'headline
315 "Whether subtrees with the ARCHIVE tag should be exported.
316 This can have three different values
317 nil Do not export, pretend this tree is not present
318 t Do export the entire tree
319 headline Only export the headline, but skip the tree below it."
320 :group
'org-export-general
323 (const :tag
"not at all" nil
)
324 (const :tag
"headline only" 'headline
)
325 (const :tag
"entirely" t
)))
327 (defcustom org-export-author-info t
328 "Non-nil means insert author name and email into the exported file.
330 This option can also be set with the +OPTIONS line,
331 e.g. \"author:nil\"."
332 :group
'org-export-general
335 (defcustom org-export-email-info nil
336 "Non-nil means insert author name and email into the exported file.
338 This option can also be set with the +OPTIONS line,
340 :group
'org-export-general
343 (defcustom org-export-creator-info t
344 "Non-nil means the postamble should contain a creator sentence.
345 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
346 :group
'org-export-general
349 (defcustom org-export-time-stamp-file t
350 "Non-nil means insert a time stamp into the exported file.
351 The time stamp shows when the file was created.
353 This option can also be set with the +OPTIONS line,
354 e.g. \"timestamp:nil\"."
355 :group
'org-export-general
358 (defcustom org-export-with-timestamps t
359 "If nil, do not export time stamps and associated keywords."
360 :group
'org-export-general
363 (defcustom org-export-remove-timestamps-from-toc t
364 "If t, remove timestamps from the table of contents entries."
365 :group
'org-export-general
368 (defcustom org-export-with-tags
'not-in-toc
369 "If nil, do not export tags, just remove them from headlines.
370 If this is the symbol `not-in-toc', tags will be removed from table of
371 contents entries, but still be shown in the headlines of the document.
373 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
374 :group
'org-export-general
376 (const :tag
"Off" nil
)
377 (const :tag
"Not in TOC" not-in-toc
)
378 (const :tag
"On" t
)))
380 (defcustom org-export-with-drawers nil
381 "Non-nil means export with drawers like the property drawer.
382 When t, all drawers are exported. This may also be a list of
383 drawer names to export."
384 :group
'org-export-general
386 (const :tag
"All drawers" t
)
387 (const :tag
"None" nil
)
388 (repeat :tag
"Selected drawers"
389 (string :tag
"Drawer name"))))
391 (defvar org-export-first-hook nil
392 "Hook called as the first thing in each exporter.
393 Point will be still in the original buffer.
394 Good for general initialization")
396 (defvar org-export-preprocess-hook nil
397 "Hook for preprocessing an export buffer.
398 Pretty much the first thing when exporting is running this hook.
399 Point will be in a temporary buffer that contains a copy of
400 the original buffer, or of the section that is being exported.
401 All the other hooks in the org-export-preprocess... category
402 also work in that temporary buffer, already modified by various
403 stages of the processing.")
405 (defvar org-export-preprocess-after-include-files-hook nil
406 "Hook for preprocessing an export buffer.
407 This is run after the contents of included files have been inserted.")
409 (defvar org-export-preprocess-after-tree-selection-hook nil
410 "Hook for preprocessing an export buffer.
411 This is run after selection of trees to be exported has happened.
412 This selection includes tags-based selection, as well as removal
413 of commented and archived trees.")
415 (defvar org-export-preprocess-after-headline-targets-hook nil
416 "Hook for preprocessing export buffer.
417 This is run just after the headline targets have been defined and
418 the target-alist has been set up.")
420 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
421 "Hook for preprocessing an export buffer.
422 This is run just before backend-specific blocks get selected.")
424 (defvar org-export-preprocess-after-blockquote-hook nil
425 "Hook for preprocessing an export buffer.
426 This is run after blockquote/quote/verse/center have been marked
429 (defvar org-export-preprocess-after-radio-targets-hook nil
430 "Hook for preprocessing an export buffer.
431 This is run after radio target processing.")
433 (defvar org-export-preprocess-before-normalizing-links-hook nil
434 "Hook for preprocessing an export buffer.
435 This hook is run before links are normalized.")
437 (defvar org-export-preprocess-before-backend-specifics-hook nil
438 "Hook run before backend-specific functions are called during preprocessing.")
440 (defvar org-export-preprocess-final-hook nil
441 "Hook for preprocessing an export buffer.
442 This is run as the last thing in the preprocessing buffer, just before
443 returning the buffer string to the backend.")
445 (defgroup org-export-translation nil
446 "Options for translating special ascii sequences for the export backends."
447 :tag
"Org Export Translation"
450 (defcustom org-export-with-emphasize t
451 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
452 If the export target supports emphasizing text, the word will be
453 typeset in bold, italic, or underlined, respectively. Works only for
454 single words, but you can say: I *really* *mean* *this*.
455 Not all export backends support this.
457 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
458 :group
'org-export-translation
461 (defcustom org-export-with-footnotes t
462 "If nil, export [1] as a footnote marker.
463 Lines starting with [1] will be formatted as footnotes.
465 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
466 :group
'org-export-translation
469 (defcustom org-export-with-TeX-macros t
470 "Non-nil means interpret simple TeX-like macros when exporting.
471 For example, HTML export converts \\alpha to α and \\AA to Å.
472 Not only real TeX macros will work here, but the standard HTML entities
473 for math can be used as macro names as well. For a list of supported
474 names in HTML export, see the constant `org-entities' and the user option
476 Not all export backends support this.
478 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
479 :group
'org-export-translation
480 :group
'org-export-latex
483 (defcustom org-export-with-LaTeX-fragments t
484 "Non-nil means process LaTeX math fragments for HTML display.
485 When set, the exporter will find and process LaTeX environments if the
486 \\begin line is the first non-white thing on a line. It will also find
487 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
488 $$a=b$$ and \\=\\[ a=b \\] for display math.
490 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
494 nil Don't do anything.
495 verbatim Keep everything in verbatim
496 dvipng Process the LaTeX fragments to images.
497 This will also include processing of non-math environments.
498 t Do MathJax preprocessing if there is at least on math snippet,
499 and arrange for MathJax.js to be loaded.
501 The default is nil, because this option needs the `dvipng' program which
502 is not available on all systems."
503 :group
'org-export-translation
504 :group
'org-export-latex
506 (const :tag
"Do not process math in any way" nil
)
507 (const :tag
"Obsolete, use dvipng setting" t
)
508 (const :tag
"Use dvipng to make images" dvipng
)
509 (const :tag
"Use MathJax to display math" mathjax
)
510 (const :tag
"Leave math verbatim" verbatim
)))
512 (defcustom org-export-with-fixed-width t
513 "Non-nil means lines starting with \":\" will be in fixed width font.
514 This can be used to have pre-formatted text, fragments of code etc. For
516 : ;; Some Lisp examples
519 will be looking just like this in also HTML. See also the QUOTE keyword.
520 Not all export backends support this.
522 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
523 :group
'org-export-translation
526 (defgroup org-export-tables nil
527 "Options for exporting tables in Org-mode."
528 :tag
"Org Export Tables"
531 (defcustom org-export-with-tables t
532 "If non-nil, lines starting with \"|\" define a table.
535 | Name | Address | Birthday |
536 |-------------+----------+-----------|
537 | Arthur Dent | England | 29.2.2100 |
539 Not all export backends support this.
541 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
542 :group
'org-export-tables
545 (defcustom org-export-highlight-first-table-line t
546 "Non-nil means highlight the first table line.
547 In HTML export, this means use <th> instead of <td>.
548 In tables created with table.el, this applies to the first table line.
549 In Org-mode tables, all lines before the first horizontal separator
550 line will be formatted with <th> tags."
551 :group
'org-export-tables
554 (defcustom org-export-table-remove-special-lines t
555 "Remove special lines and marking characters in calculating tables.
556 This removes the special marking character column from tables that are set
557 up for spreadsheet calculations. It also removes the entire lines
558 marked with `!', `_', or `^'. The lines with `$' are kept, because
559 the values of constants may be useful to have."
560 :group
'org-export-tables
563 (defcustom org-export-prefer-native-exporter-for-tables nil
564 "Non-nil means always export tables created with table.el natively.
565 Natively means use the HTML code generator in table.el.
566 When nil, Org-mode's own HTML generator is used when possible (i.e. if
567 the table does not use row- or column-spanning). This has the
568 advantage, that the automatic HTML conversions for math symbols and
569 sub/superscripts can be applied. Org-mode's HTML generator is also
570 much faster. The LaTeX exporter always use the native exporter for
572 :group
'org-export-tables
576 (defgroup org-export-xml nil
577 "Options specific for XML export of Org-mode files."
578 :tag
"Org Export XML"
583 ;;; Variables, constants, and parameter plists
585 (defconst org-level-max
20)
587 (defvar org-current-export-file nil
) ; dynamically scoped parameter
588 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
589 (defvar org-export-opt-plist nil
590 "Contains the current option plist.")
591 (defvar org-last-level nil
) ; dynamically scoped variable
592 (defvar org-min-level nil
) ; dynamically scoped variable
593 (defvar org-levels-open nil
) ; dynamically scoped parameter
595 (defconst org-export-plist-vars
596 '((:link-up nil org-export-html-link-up
)
597 (:link-home nil org-export-html-link-home
)
598 (:language nil org-export-default-language
)
599 (:keywords nil org-export-page-keywords
)
600 (:description nil org-export-page-description
)
601 (:customtime nil org-display-custom-times
)
602 (:headline-levels
"H" org-export-headline-levels
)
603 (:section-numbers
"num" org-export-with-section-numbers
)
604 (:section-number-format nil org-export-section-number-format
)
605 (:table-of-contents
"toc" org-export-with-toc
)
606 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
607 (:archived-trees nil org-export-with-archived-trees
)
608 (:emphasize
"*" org-export-with-emphasize
)
609 (:sub-superscript
"^" org-export-with-sub-superscripts
)
610 (:special-strings
"-" org-export-with-special-strings
)
611 (:footnotes
"f" org-export-with-footnotes
)
612 (:drawers
"d" org-export-with-drawers
)
613 (:tags
"tags" org-export-with-tags
)
614 (:todo-keywords
"todo" org-export-with-todo-keywords
)
615 (:priority
"pri" org-export-with-priority
)
616 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
617 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
618 (:latex-listings nil org-export-latex-listings
)
619 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
620 (:fixed-width
":" org-export-with-fixed-width
)
621 (:timestamps
"<" org-export-with-timestamps
)
622 (:author-info
"author" org-export-author-info
)
623 (:email-info
"email" org-export-email-info
)
624 (:creator-info
"creator" org-export-creator-info
)
625 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
626 (:tables
"|" org-export-with-tables
)
627 (:table-auto-headline nil org-export-highlight-first-table-line
)
628 (:style-include-default nil org-export-html-style-include-default
)
629 (:style-include-scripts nil org-export-html-style-include-scripts
)
630 (:style nil org-export-html-style
)
631 (:style-extra nil org-export-html-style-extra
)
632 (:agenda-style nil org-agenda-export-html-style
)
633 (:convert-org-links nil org-export-html-link-org-files-as-html
)
634 (:inline-images nil org-export-html-inline-images
)
635 (:html-extension nil org-export-html-extension
)
636 (:xml-declaration nil org-export-html-xml-declaration
)
637 (:html-table-tag nil org-export-html-table-tag
)
638 (:expand-quoted-html
"@" org-export-html-expand
)
639 (:timestamp nil org-export-html-with-timestamp
)
640 (:publishing-directory nil org-export-publishing-directory
)
641 (:html-preamble nil org-export-html-preamble
)
642 (:html-postamble nil org-export-html-postamble
)
643 (:author nil user-full-name
)
644 (:email nil user-mail-address
)
645 (:select-tags nil org-export-select-tags
)
646 (:exclude-tags nil org-export-exclude-tags
)
648 (:latex-image-options nil org-export-latex-image-default-option
))
649 "List of properties that represent export/publishing variables.
650 Each element is a list of 3 items:
651 1. The property that is used internally, and also for org-publish-project-alist
652 2. The string that can be used in the OPTION lines to set this option,
653 or nil if this option cannot be changed in this way
654 3. The customization variable that sets the default for this option."
657 (defun org-default-export-plist ()
658 "Return the property list with default settings for the export variables."
659 (let* ((infile (org-infile-export-plist))
660 (letbind (plist-get infile
:let-bind
))
661 (l org-export-plist-vars
) rtn e s v
)
662 (while (setq e
(pop l
))
665 ((assq s letbind
) (nth 1 (assq s letbind
)))
666 ((boundp s
) (symbol-value s
))
668 rtn
(cons (car e
) (cons v rtn
))))
671 (defvar org-export-inbuffer-options-extra nil
672 "List of additional in-buffer options that should be detected.
673 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
674 etc. Extensions can add to this list to get their options detected, and they
675 can then add a function to `org-export-options-filters' to process these
677 Each element in this list must be a list, with the in-buffer keyword as car,
678 and a property (a symbol) as the next element. All occurrences of the
679 keyword will be found, the values concatenated with a space character
680 in between, and the result stored in the export options property list.")
682 (defvar org-export-options-filters nil
683 "Functions to be called to finalize the export/publishing options.
684 All these options are stored in a property list, and each of the functions
685 in this hook gets a chance to modify this property list. Each function
686 must accept the property list as an argument, and must return the (possibly
689 ;; FIXME: should we fold case here?
690 (defun org-infile-export-plist ()
691 "Return the property list with file-local settings for export."
695 (goto-char (point-min))
696 (let ((re (org-make-options-regexp
698 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
700 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
701 "LATEX_HEADER" "LATEX_CLASS"
702 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
703 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
704 (mapcar 'car org-export-inbuffer-options-extra
))))
706 p key val text options mathjax a pr style
707 latex-header latex-class macros letbind
708 ext-setup-or-nil setup-contents
(start 0))
709 (while (or (and ext-setup-or-nil
710 (string-match re ext-setup-or-nil start
)
711 (setq start
(match-end 0)))
712 (and (setq ext-setup-or-nil nil start
0)
713 (re-search-forward re nil t
)))
714 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
715 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
717 ((setq a
(assoc key org-export-inbuffer-options-extra
))
719 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
720 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
721 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
722 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
723 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
724 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
725 ((string-equal key
"DESCRIPTION")
726 (setq p
(plist-put p
:description val
)))
727 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
728 ((string-equal key
"STYLE")
729 (setq style
(concat style
"\n" val
)))
730 ((string-equal key
"LATEX_HEADER")
731 (setq latex-header
(concat latex-header
"\n" val
)))
732 ((string-equal key
"LATEX_CLASS")
733 (setq latex-class val
))
734 ((string-equal key
"TEXT")
735 (setq text
(if text
(concat text
"\n" val
) val
)))
736 ((string-equal key
"OPTIONS")
737 (setq options
(concat val
" " options
)))
738 ((string-equal key
"MATHJAX")
739 (setq mathjax
(concat val
" " mathjax
)))
740 ((string-equal key
"BIND")
741 (push (read (concat "(" val
")")) letbind
))
742 ((string-equal key
"XSLT")
743 (setq p
(plist-put p
:xslt val
)))
744 ((string-equal key
"LINK_UP")
745 (setq p
(plist-put p
:link-up val
)))
746 ((string-equal key
"LINK_HOME")
747 (setq p
(plist-put p
:link-home val
)))
748 ((string-equal key
"EXPORT_SELECT_TAGS")
749 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
750 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
751 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
752 ((string-equal key
"MACRO")
754 ((equal key
"SETUPFILE")
755 (setq setup-contents
(org-file-contents
757 (org-remove-double-quotes
760 (if (not ext-setup-or-nil
)
761 (setq ext-setup-or-nil setup-contents start
0)
762 (setq ext-setup-or-nil
763 (concat (substring ext-setup-or-nil
0 start
)
764 "\n" setup-contents
"\n"
765 (substring ext-setup-or-nil start
)))))))
766 (setq p
(plist-put p
:text text
))
767 (when (and letbind
(org-export-confirm-letbind))
768 (setq p
(plist-put p
:let-bind letbind
)))
769 (when style
(setq p
(plist-put p
:style-extra style
)))
771 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
773 (setq p
(plist-put p
:latex-class latex-class
)))
775 (setq p
(org-export-add-options-to-plist p options
)))
777 (setq p
(plist-put p
:mathjax mathjax
)))
778 ;; Add macro definitions
779 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
780 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
781 (setq p
(plist-put p
:macro-property
"(eval (org-entry-get nil \"$1\" 'selective))"))
783 p
:macro-modification-time
784 (and (buffer-file-name)
785 (file-exists-p (buffer-file-name))
787 "(eval (format-time-string \"$1\" '"
788 (prin1-to-string (nth 5 (file-attributes
789 (buffer-file-name))))
791 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
792 (file-name-nondirectory
793 (buffer-file-name)))))
794 (while (setq val
(pop macros
))
795 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
798 (concat ":macro-" (downcase (match-string 1 val
))))
799 (org-export-interpolate-newlines (match-string 2 val
))))))
802 (defun org-export-interpolate-newlines (s)
803 (while (string-match "\\\\n" s
)
804 (setq s
(replace-match "\n" t t s
)))
807 (defvar org-export-allow-BIND-local nil
)
808 (defun org-export-confirm-letbind ()
809 "Can we use #+BIND values during export?
810 By default this will ask fro confirmation by the user, to divert possible
813 ((not org-export-allow-BIND
) nil
)
814 ((eq org-export-allow-BIND t
) t
)
815 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
816 org-export-allow-BIND-local
)
817 (t (org-set-local 'org-export-allow-BIND-local
818 (yes-or-no-p "Allow BIND values in this buffer? ")))))
820 (defun org-install-letbind ()
821 "Install the values from #+BIND lines as local variables."
822 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
824 (while (setq pair
(pop letbind
))
825 (org-set-local (car pair
) (nth 1 pair
)))))
827 (defun org-export-add-options-to-plist (p options
)
828 "Parse an OPTIONS line and set values in the property list P."
831 (let ((op org-export-plist-vars
))
832 (while (setq o
(pop op
))
834 (string-match (concat "\\<" (regexp-quote (nth 1 o
))
835 ":\\([^ \t\n\r;,.]*\\)")
837 (setq p
(plist-put p
(car o
)
838 (car (read-from-string
839 (match-string 1 options
))))))))))
842 (defun org-export-add-subtree-options (p pos
)
843 "Add options in subtree at position POS to property list P."
846 (when (org-at-heading-p)
848 ;; This is actually read in `org-export-get-title-from-subtree'
849 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
850 ;; (setq p (plist-put p :title a)))
851 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
852 (setq p
(plist-put p
:text a
)))
853 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
854 (setq p
(plist-put p
:author a
)))
855 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
856 (setq p
(plist-put p
:date a
)))
857 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
858 (setq p
(org-export-add-options-to-plist p a
)))))
861 (defun org-export-directory (type plist
)
862 (let* ((val (plist-get plist
:publishing-directory
))
864 (or (cdr (assoc type val
)) ".")
868 (defun org-export-process-option-filters (plist)
869 (let ((functions org-export-options-filters
) f
)
870 (while (setq f
(pop functions
))
871 (setq plist
(funcall f plist
))))
875 (defun org-export (&optional arg
)
876 "Export dispatcher for Org-mode.
877 When `org-export-run-in-background' is non-nil, try to run the command
878 in the background. This will be done only for commands that write
879 to a file. For details see the docstring of `org-export-run-in-background'.
881 The prefix argument ARG will be passed to the exporter. However, if
882 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
883 that means to inverse the
884 value of `org-export-run-in-background'.
886 If `org-export-initial-scope' is set to 'subtree, try to export
887 the current subtree, otherwise try to export the whole buffer.
888 Pressing `1' will switch between these two options."
890 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
891 (subtree-p (or (org-region-active-p)
892 (eq org-export-initial-scope
'subtree
)))
893 (help "[t] insert the export option template
894 \[v] limit export to visible part of outline tree
895 \[1] switch buffer/subtree export
896 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
898 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
900 \[h] export as HTML [H] to temporary buffer [R] export region
901 \[b] export as HTML and open in browser
903 \[l] export as LaTeX [L] to temporary buffer
904 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
906 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
908 \[j] export as TaskJuggler [J] ... and open
910 \[m] export as Freemind mind map
912 \[g] export using Wes Hardaker's generic exporter
914 \[i] export current file as iCalendar file
915 \[I] export all agenda files as iCalendar files [c] ...as one combined file
917 \[F] publish current file [P] publish current project
918 \[X] publish a project... [E] publish every projects")
920 '((?t org-insert-export-options-template nil
)
921 (?v org-export-visible nil
)
922 (?a org-export-as-ascii t
)
923 (?A org-export-as-ascii-to-buffer t
)
924 (?n org-export-as-latin1 t
)
925 (?N org-export-as-latin1-to-buffer t
)
926 (?u org-export-as-utf8 t
)
927 (?U org-export-as-utf8-to-buffer t
)
928 (?h org-export-as-html t
)
929 (?b org-export-as-html-and-open t
)
930 (?H org-export-as-html-to-buffer nil
)
931 (?R org-export-region-as-html nil
)
932 (?x org-export-as-xoxo t
)
933 (?g org-export-generic t
)
934 (?D org-export-as-docbook t
)
935 (?V org-export-as-docbook-pdf-and-open t
)
936 (?j org-export-as-taskjuggler t
)
937 (?J org-export-as-taskjuggler-and-open t
)
938 (?m org-export-as-freemind t
)
939 (?l org-export-as-latex t
)
940 (?p org-export-as-pdf t
)
941 (?d org-export-as-pdf-and-open t
)
942 (?L org-export-as-latex-to-buffer nil
)
943 (?i org-export-icalendar-this-file t
)
944 (?I org-export-icalendar-all-agenda-files t
)
945 (?c org-export-icalendar-combine-agenda-files t
)
946 (?F org-publish-current-file t
)
947 (?P org-publish-current-project t
)
949 (?E org-publish-all t
)))
951 (cpos (point)) (cbuf (current-buffer)) bpos
)
953 (save-window-excursion
955 (message "Export subtree: ")
956 (message "Export buffer: "))
957 (delete-other-windows)
958 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
960 (org-fit-window-to-buffer (get-buffer-window
961 "*Org Export/Publishing Help*"))
962 (while (eq (setq r1
(read-char-exclusive)) ?
1)
965 (message "Export buffer: "))
968 (message "Export subtree: "))))
970 (let ((case-fold-search t
))
971 (if (re-search-backward
972 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
975 (org-back-to-heading t
)
978 (message "Select command (for subtree): ")
979 (setq r1
(read-char-exclusive)))
980 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
983 (and bpos
(goto-char bpos
))
984 (setq r2
(if (< r1
27) (+ r1
96) r1
))
985 (unless (setq ass
(assq r2 cmds
))
986 (error "No command associated with key %c" r1
))
987 (if (and bg
(nth 2 ass
)
988 (not (buffer-base-buffer))
989 (not (org-region-active-p)))
990 ;; execute in background
991 (let ((p (start-process
992 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
994 (expand-file-name invocation-name invocation-directory
)
997 "--eval" "(require 'org-exp)"
998 "--eval" "(setq org-wait .2)"
1000 "-f" (symbol-name (nth 1 ass
)))))
1001 (set-process-sentinel p
'org-export-process-sentinel
)
1002 (message "Background process \"%s\": started" p
))
1003 ;; background processing not requested, or not possible
1004 (if subtree-p
(progn (org-mark-subtree) (activate-mark)))
1005 (call-interactively (nth 1 ass
))
1006 (when (and bpos
(get-buffer-window cbuf
))
1007 (let ((cw (selected-window)))
1008 (select-window (get-buffer-window cbuf
))
1011 (select-window cw
))))))
1013 (defun org-export-process-sentinel (process status
)
1014 (if (string-match "\n+\\'" status
)
1015 (setq status
(substring status
0 -
1)))
1016 (message "Background process \"%s\": %s" process status
))
1018 ;;; General functions for all backends
1020 (defvar org-export-target-aliases nil
1021 "Alist of targets with invisible aliases.")
1022 (defvar org-export-preferred-target-alist nil
1023 "Alist of section id's with preferred aliases.")
1024 (defvar org-export-id-target-alist nil
1025 "Alist of section id's with preferred aliases.")
1026 (defvar org-export-code-refs nil
1027 "Alist of code references and line numbers.")
1029 (defun org-export-preprocess-string (string &rest parameters
)
1030 "Cleanup STRING so that that the true exported has a more consistent source.
1031 This function takes STRING, which should be a buffer-string of an org-file
1032 to export. It then creates a temporary buffer where it does its job.
1033 The result is then again returned as a string, and the exporter works
1034 on this string to produce the exported version."
1036 (let* ((docbookp (eq (plist-get parameters
:for-backend
) 'docbook
))
1037 (backend (plist-get parameters
:for-backend
))
1038 (archived-trees (plist-get parameters
:archived-trees
))
1039 (inhibit-read-only t
)
1040 (drawers org-drawers
)
1041 (outline-regexp "\\*+ ")
1042 (source-buffer (current-buffer))
1045 (setq org-export-target-aliases nil
1046 org-export-preferred-target-alist nil
1047 org-export-id-target-alist nil
1048 org-export-code-refs nil
)
1050 (with-current-buffer (get-buffer-create " org-mode-tmp")
1053 (setq case-fold-search t
)
1055 (let ((inhibit-read-only t
))
1056 (remove-text-properties (point-min) (point-max)
1059 ;; Remove license-to-kill stuff
1060 ;; The caller marks some stuff for killing, stuff that has been
1061 ;; used to create the page title, for example.
1062 (org-export-kill-licensed-text)
1064 (let ((org-inhibit-startup t
)) (org-mode))
1065 (setq case-fold-search t
)
1066 (org-clone-local-variables source-buffer
"^\\(org-\\|orgtbl-\\)")
1067 (org-install-letbind)
1070 (run-hooks 'org-export-preprocess-hook
)
1072 ;; Process the macros
1073 (org-export-preprocess-apply-macros)
1074 (run-hooks 'org-export-preprocess-after-macros-hook
)
1076 (untabify (point-min) (point-max))
1078 ;; Handle include files, and call a hook
1079 (org-export-handle-include-files-recurse)
1080 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1082 ;; Get rid of archived trees
1083 (org-export-remove-archived-trees archived-trees
)
1085 ;; Remove comment environment and comment subtrees
1086 (org-export-remove-comment-blocks-and-subtrees)
1088 ;; Get rid of excluded trees, and call a hook
1089 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1090 (plist-get parameters
:exclude-tags
))
1091 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1093 ;; Mark end of lists
1094 (org-export-mark-list-ending backend
)
1096 ;; Export code blocks
1097 (org-export-blocks-preprocess)
1099 ;; Handle source code snippets
1100 (org-export-replace-src-segments-and-examples backend
)
1102 ;; Protect short examples marked by a leading colon
1103 (org-export-protect-colon-examples)
1106 (org-export-convert-protected-spaces backend
)
1108 ;; Normalize footnotes
1109 (when (plist-get parameters
:footnotes
)
1110 (org-footnote-normalize nil t
))
1112 ;; Find all headings and compute the targets for them
1113 (setq target-alist
(org-export-define-heading-targets target-alist
))
1115 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1117 ;; Find HTML special classes for headlines
1118 (org-export-remember-html-container-classes)
1120 ;; Get rid of drawers
1121 (org-export-remove-or-extract-drawers
1122 drawers
(plist-get parameters
:drawers
) backend
)
1124 ;; Get the correct stuff before the first headline
1125 (when (plist-get parameters
:skip-before-1st-heading
)
1126 (goto-char (point-min))
1127 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1128 (delete-region (point-min) (match-beginning 0))
1129 (goto-char (point-min))
1131 (when (plist-get parameters
:add-text
)
1132 (goto-char (point-min))
1133 (insert (plist-get parameters
:add-text
) "\n"))
1135 ;; Remove todo-keywords before exporting, if the user has requested so
1136 (org-export-remove-headline-metadata parameters
)
1138 ;; Find targets in comments and move them out of comments,
1139 ;; but mark them as targets that should be invisible
1140 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1142 ;; Select and protect backend specific stuff, throw away stuff
1143 ;; that is specific for other backends
1144 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1145 (org-export-select-backend-specific-text backend
)
1147 ;; Protect quoted subtrees
1148 (org-export-protect-quoted-subtrees)
1150 ;; Remove clock lines
1151 (org-export-remove-clock-lines)
1153 ;; Protect verbatim elements
1154 (org-export-protect-verbatim)
1156 ;; Blockquotes, verse, and center
1157 (org-export-mark-blockquote-verse-center)
1158 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1160 ;; Remove timestamps, if the user has requested so
1161 (unless (plist-get parameters
:timestamps
)
1162 (org-export-remove-timestamps))
1164 ;; Attach captions to the correct object
1165 (setq target-alist
(org-export-attach-captions-and-attributes
1166 backend target-alist
))
1168 ;; Find matches for radio targets and turn them into internal links
1169 (org-export-mark-radio-links)
1170 (run-hooks 'org-export-preprocess-after-radio-targets-hook
)
1172 ;; Find all links that contain a newline and put them into a single line
1173 (org-export-concatenate-multiline-links)
1175 ;; Normalize links: Convert angle and plain links into bracket links
1176 ;; and expand link abbreviations
1177 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1178 (org-export-normalize-links)
1180 ;; Find all internal links. If they have a fuzzy match (i.e. not
1181 ;; a *dedicated* target match, let the link point to the
1182 ;; corresponding section.
1183 (org-export-target-internal-links target-alist
)
1185 ;; Find multiline emphasis and put them into single line
1186 (when (plist-get parameters
:emph-multiline
)
1187 (org-export-concatenate-multiline-emphasis))
1189 ;; Remove special table lines, and store alignment information
1190 (org-store-forced-table-alignment)
1191 (when org-export-table-remove-special-lines
1192 (org-export-remove-special-table-lines))
1195 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1197 ;; LaTeX-specific preprocessing
1198 (when (eq backend
'latex
)
1199 (require 'org-latex nil
)
1200 (org-export-latex-preprocess parameters
))
1202 ;; ASCII-specific preprocessing
1203 (when (eq backend
'ascii
)
1204 (org-export-ascii-preprocess parameters
))
1206 ;; HTML-specific preprocessing
1207 (when (eq backend
'html
)
1208 (org-export-html-preprocess parameters
))
1210 ;; DocBook-specific preprocessing
1211 (when (eq backend
'docbook
)
1212 (require 'org-docbook nil
)
1213 (org-export-docbook-preprocess parameters
))
1215 ;; Remove or replace comments
1216 (org-export-handle-comments (plist-get parameters
:comments
))
1218 ;; Remove #+TBLFM and #+TBLNAME lines
1219 (org-export-handle-table-metalines)
1221 ;; Run the final hook
1222 (run-hooks 'org-export-preprocess-final-hook
)
1224 (setq rtn
(buffer-string)))
1225 (kill-buffer " org-mode-tmp")
1228 (defun org-export-kill-licensed-text ()
1229 "Remove all text that is marked with a :org-license-to-kill property."
1231 (while (setq p
(text-property-any (point-min) (point-max)
1232 :org-license-to-kill t
))
1234 p
(or (next-single-property-change p
:org-license-to-kill
)
1237 (defvar org-export-define-heading-targets-headline-hook nil
1238 "Hook that is run when a headline was matched during target search.
1239 This is part of the preprocessing for export.")
1241 (defun org-export-define-heading-targets (target-alist)
1242 "Find all headings and define the targets for them.
1243 The new targets are added to TARGET-ALIST, which is also returned.
1244 Also find all ID and CUSTOM_ID properties and store them."
1245 (goto-char (point-min))
1246 (org-init-section-numbers)
1247 (let ((re (concat "^" org-outline-regexp
1249 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1250 level target last-section-target a id
)
1251 (while (re-search-forward re nil t
)
1252 (org-if-unprotected-at (match-beginning 0)
1255 (setq id
(org-match-string-no-properties 2))
1256 (push (cons id target
) target-alist
)
1257 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1259 (push (list last-section-target
)
1260 org-export-target-aliases
)
1261 (car org-export-target-aliases
))))
1262 (push (caar target-alist
) (cdr a
))
1263 (when (equal (match-string 1) "CUSTOM_ID")
1264 (if (not (assoc last-section-target
1265 org-export-preferred-target-alist
))
1266 (push (cons last-section-target id
)
1267 org-export-preferred-target-alist
)))
1268 (when (equal (match-string 1) "ID")
1269 (if (not (assoc last-section-target
1270 org-export-id-target-alist
))
1271 (push (cons last-section-target
(concat "ID-" id
))
1272 org-export-id-target-alist
))))
1273 (setq level
(org-reduced-level
1274 (save-excursion (goto-char (point-at-bol))
1275 (org-outline-level))))
1276 (setq target
(org-solidify-link-text
1277 (format "sec-%s" (replace-regexp-in-string
1279 (org-section-number level
)))))
1280 (setq last-section-target target
)
1281 (push (cons target target
) target-alist
)
1282 (add-text-properties
1283 (point-at-bol) (point-at-eol)
1284 (list 'target target
))
1285 (run-hooks 'org-export-define-heading-targets-headline-hook
)))))
1288 (defun org-export-handle-invisible-targets (target-alist)
1289 "Find targets in comments and move them out of comments.
1290 Mark them as invisible targets."
1292 (goto-char (point-min))
1293 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1294 ;; Check if the line before or after is a headline with a target
1295 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1296 (get-text-property (point-at-bol 2) 'target
)))
1298 ;; use the existing target in a neighboring line
1299 (setq tmp
(match-string 2))
1301 (and (looking-at "\n") (delete-char 1))
1302 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1304 (setq a
(or (assoc target org-export-target-aliases
)
1306 (push (list target
) org-export-target-aliases
)
1307 (car org-export-target-aliases
))))
1309 ;; Make an invisible target
1310 (replace-match "\\1(INVISIBLE)"))))
1313 (defun org-export-target-internal-links (target-alist)
1314 "Find all internal links and assign targets to them.
1315 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1316 let the link point to the corresponding section.
1317 This function also handles the id links, if they have a match in
1319 (goto-char (point-min))
1320 (while (re-search-forward org-bracket-link-regexp nil t
)
1321 (org-if-unprotected-at (1+ (match-beginning 0))
1322 (let* ((org-link-search-must-match-exact-headline t
)
1324 (desc (match-end 2))
1325 (link (org-link-unescape (match-string 1)))
1326 (slink (org-solidify-link-text link
))
1327 found props pos cref
1330 ((= (string-to-char link
) ?
#)
1331 ;; user wants exactly this link
1333 ((cdr (assoc slink target-alist
))
1334 (or (cdr (assoc (assoc slink target-alist
)
1335 org-export-preferred-target-alist
))
1336 (cdr (assoc slink target-alist
))))
1337 ((and (string-match "^id:" link
)
1338 (cdr (assoc (substring link
3) target-alist
))))
1339 ((string-match "^(\\(.*\\))$" link
)
1340 (setq cref
(match-string 1 link
))
1341 (concat "coderef:" cref
))
1342 ((string-match org-link-types-re link
) nil
)
1343 ((or (file-name-absolute-p link
)
1344 (string-match "^\\." link
))
1347 (let ((org-link-search-inhibit-query t
))
1349 (setq found
(condition-case nil
(org-link-search link
)
1352 (or (org-on-heading-p)
1353 (not (eq found
'dedicated
))))
1354 (or (get-text-property (point) 'target
)
1357 (1- (or (previous-single-property-change
1358 (point) 'target
) 0)))
1362 (goto-char (match-beginning 1))
1363 (setq props
(text-properties-at (point)))
1364 (delete-region (match-beginning 1) (match-end 1))
1367 (unless desc
(insert "][" link
))
1368 (add-text-properties pos
(point) props
))))))
1370 (defun org-export-remember-html-container-classes ()
1371 "Store the HTML_CONTAINER_CLASS properties in a text property."
1372 (goto-char (point-min))
1374 (while (re-search-forward
1375 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t
)
1376 (setq class
(match-string 1))
1378 (org-back-to-heading t
)
1379 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1381 (defvar org-export-format-drawer-function nil
1382 "Function to be called to format the contents of a drawer.
1383 The function must accept three parameters:
1384 NAME the drawer name, like \"PROPERTIES\"
1385 CONTENT the content of the drawer.
1386 BACKEND one of the symbols html, docbook, latex, ascii, xoxo
1387 The function should return the text to be inserted into the buffer.
1388 If this is nil, `org-export-format-drawer' is used as a default.")
1390 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend
)
1391 "Remove drawers, or extract and format the content.
1392 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1393 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1394 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1395 EXP-DRAWERS will be removed.
1396 BACKEND is the current export backend."
1397 (goto-char (point-min))
1398 (let ((re (concat "^[ \t]*:\\("
1399 (mapconcat 'identity all-drawers
"\\|")
1401 name beg beg-content eol content
)
1402 (while (re-search-forward re nil t
)
1404 (setq name
(match-string 1))
1405 (setq beg
(match-beginning 0)
1406 beg-content
(1+ (point-at-eol))
1408 (if (not (and (re-search-forward
1409 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1412 (goto-char (match-beginning 0))
1413 (and (looking-at ".*\n?") (replace-match ""))
1414 (setq content
(buffer-substring beg-content
(point)))
1415 (delete-region beg
(point))
1416 (when (or (eq exp-drawers t
)
1417 (member name exp-drawers
))
1418 (setq content
(funcall (or org-export-format-drawer-function
1419 'org-export-format-drawer
)
1420 name content backend
))
1421 (insert content
)))))))
1423 (defun org-export-format-drawer (name content backend
)
1424 "Format the content of a drawer as a colon example."
1425 (if (string-match "[ \t]+\\'" content
)
1426 (setq content
(substring content
(match-beginning 0))))
1427 (while (string-match "\\`[ \t]*\n" content
)
1428 (setq content
(substring content
(match-end 0))))
1429 (setq content
(org-remove-indentation content
))
1430 (setq content
(concat ": " (mapconcat 'identity
1431 (org-split-string content
"\n")
1434 (setq content
(concat " : " (upcase name
) "\n" content
))
1435 (org-add-props content nil
'org-protected t
))
1437 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1438 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1439 Both arguments are lists of tags.
1440 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1442 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1444 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1445 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1448 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1452 (goto-char (point-min))
1453 (when (and select-tags
1455 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1456 ;; At least one tree is marked for export, this means
1457 ;; all the unmarked stuff needs to go.
1458 ;; Dig out the trees that should be exported
1459 (goto-char (point-min))
1460 (outline-next-heading)
1462 (put-text-property beg
(point-max) :org-delete t
)
1463 (while (re-search-forward re-sel nil t
)
1464 (when (org-on-heading-p)
1465 (org-back-to-heading)
1466 (remove-text-properties
1467 (max (1- (point)) (point-min))
1468 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1470 (while (and (org-up-heading-safe)
1471 (get-text-property (point) :org-delete
))
1472 (remove-text-properties (max (1- (point)) (point-min))
1473 (point-at-eol) '(:org-delete t
)))
1475 ;; Remove the trees explicitly marked for noexport
1477 (goto-char (point-min))
1478 (while (re-search-forward re-excl nil t
)
1479 (when (org-at-heading-p)
1480 (org-back-to-heading t
)
1482 (org-end-of-subtree t t
)
1483 (delete-region beg
(point))
1484 (when (featurep 'org-inlinetask
)
1485 (org-inlinetask-remove-END-maybe)))))
1486 ;; Remove everything that is now still marked for deletion
1487 (goto-char (point-min))
1488 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1489 (setq end
(or (next-single-property-change beg
:org-delete
)
1491 (delete-region beg end
))))
1493 (defun org-export-remove-archived-trees (export-archived-trees)
1494 "Remove archived trees.
1495 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1496 When it is t, the entire archived tree will be exported.
1497 When it is nil the entire tree including the headline will be removed
1499 (let ((re-archive (concat ":" org-archive-tag
":"))
1501 (when (not (eq export-archived-trees t
))
1502 (goto-char (point-min))
1503 (while (re-search-forward re-archive nil t
)
1504 (if (not (org-on-heading-p t
))
1505 (goto-char (point-at-eol))
1506 (beginning-of-line 1)
1507 (setq a
(if export-archived-trees
1508 (1+ (point-at-eol)) (point))
1509 b
(org-end-of-subtree t
))
1510 (if (> b a
) (delete-region a b
)))))))
1512 (defun org-export-remove-headline-metadata (opts)
1513 "Remove meta data from the headline, according to user options."
1514 (let ((re org-complex-heading-regexp
)
1515 (todo (plist-get opts
:todo-keywords
))
1516 (tags (plist-get opts
:tags
))
1517 (pri (plist-get opts
:priority
))
1520 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1521 (when (or (not todo
) (not tags
) (not pri
))
1522 (goto-char (point-min))
1523 (while (re-search-forward re nil t
)
1525 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1527 (replace-match rpl t t
))))))
1529 (defun org-export-remove-timestamps ()
1530 "Remove timestamps and keywords for export."
1531 (goto-char (point-min))
1532 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1535 (unless (save-match-data (org-at-table-p))
1537 (beginning-of-line 1)
1538 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1539 (replace-match ""))))))
1541 (defun org-export-remove-clock-lines ()
1542 "Remove clock lines for export."
1543 (goto-char (point-min))
1544 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1545 (while (re-search-forward re nil t
)
1547 (replace-match "")))))
1549 (defun org-export-protect-quoted-subtrees ()
1550 "Mark quoted subtrees with the protection property."
1551 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1552 (goto-char (point-min))
1553 (while (re-search-forward re-quote nil t
)
1554 (goto-char (match-beginning 0))
1556 (add-text-properties (point) (org-end-of-subtree t
)
1557 '(org-protected t
)))))
1559 (defun org-export-convert-protected-spaces (backend)
1560 "Convert strings like \\____ to protected spaces in all backends."
1561 (goto-char (point-min))
1562 (while (re-search-forward "\\\\__+" nil t
)
1563 (org-if-unprotected-1
1567 ((eq backend
'latex
)
1568 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1570 (org-add-props (match-string 0) nil
1571 'org-whitespace
(- (match-end 0) (match-beginning 0))))
1572 ;; ((eq backend 'docbook))
1573 ((eq backend
'ascii
)
1574 (org-add-props (match-string 0) '(org-whitespace t
)))
1575 (t (make-string (- (match-end 0) (match-beginning 0)) ?\
)))
1579 (defun org-export-protect-verbatim ()
1580 "Mark verbatim snippets with the protection property."
1581 (goto-char (point-min))
1582 (while (re-search-forward org-verbatim-re nil t
)
1584 (add-text-properties (match-beginning 4) (match-end 4)
1585 '(org-protected t org-verbatim-emph t
))
1586 (goto-char (1+ (match-end 4))))))
1588 (defun org-export-protect-colon-examples ()
1589 "Protect lines starting with a colon."
1590 (goto-char (point-min))
1591 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1592 (while (re-search-forward re nil t
)
1593 (beginning-of-line 1)
1595 (while (looking-at re
)
1597 (or (eobp) (forward-char 1)))
1598 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1599 '(org-protected t
)))))
1601 (defun org-export-select-backend-specific-text (backend)
1603 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1604 (html "HTML" "BEGIN_HTML" "END_HTML")
1605 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1606 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1607 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1608 (case-fold-search t
)
1609 fmt beg beg-content end end-content
)
1612 (setq fmt
(pop formatters
))
1613 ;; Handle #+Backend: stuff
1614 (goto-char (point-min))
1615 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1616 ":[ \t]*\\(.*\\)") nil t
)
1617 (if (not (eq (car fmt
) backend
))
1618 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1619 (replace-match "\\1\\2" t
)
1620 (add-text-properties
1621 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1622 '(org-protected t
))))
1623 ;; Delete #+attr_Backend: stuff of another backend. Those
1624 ;; matching the current backend will be taken care of by
1625 ;; `org-export-attach-captions-and-attributes'
1626 (goto-char (point-min))
1627 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt
)
1628 ":[ \t]*\\(.*\\)") nil t
)
1629 (when (not (eq (car fmt
) backend
))
1630 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1631 ;; Handle #+begin_Backend and #+end_Backend stuff
1632 (goto-char (point-min))
1633 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt
) "\\>.*\n?")
1635 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1636 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt
) "\\>.*\n?")
1638 (setq end
(match-end 0) end-content
(match-beginning 0))
1639 (if (eq (car fmt
) backend
)
1642 (add-text-properties beg-content end-content
'(org-protected t
))
1643 (delete-region (match-beginning 0) (match-end 0))
1646 (delete-region (point) (1+ (point-at-eol)))))
1647 ;; No, this is for a different backend, kill it
1648 (delete-region beg end
)))))))
1650 (defun org-export-mark-blockquote-verse-center ()
1651 "Mark block quote and verse environments with special cookies.
1652 These special cookies will later be interpreted by the backend."
1654 (let (type t1 ind beg end beg1 end1 content
)
1655 (goto-char (point-min))
1656 (while (re-search-forward
1657 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1659 (setq ind
(length (match-string 1))
1660 type
(downcase (match-string 3))
1661 t1
(if (equal type
"quote") "blockquote" type
))
1662 (setq beg
(match-beginning 0)
1663 beg1
(1+ (match-end 0)))
1664 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1665 (setq end1
(1- (match-beginning 0))
1666 end
(+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1667 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1668 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1670 "ORG-" (upcase t1
) "-END\n"))
1671 (delete-region beg end
)
1672 (insert (org-add-props content nil
'original-indentation ind
))))))
1674 (defun org-export-mark-list-ending (backend)
1675 "Mark list endings with special cookies.
1676 These special cookies will later be interpreted by the backend.
1677 `org-list-end-re' is replaced by a blank line in the process."
1678 (let ((process-buffer
1679 (lambda (end-list-marker)
1680 (goto-char (point-min))
1681 (while (org-search-forward-unenclosed org-item-beginning-re nil t
)
1682 (goto-char (org-list-bottom-point))
1683 (when (and (not (eq org-list-ending-method
'indent
))
1684 (looking-at (org-list-end-re)))
1685 (replace-match "\n"))
1686 (unless (bolp) (insert "\n"))
1687 (unless (looking-at end-list-marker
)
1688 (insert end-list-marker
))
1689 (unless (eolp) (insert "\n"))))))
1690 ;; We need to divide backends into 3 categories.
1692 ;; 1. Backends using `org-list-parse-list' do not need markers.
1693 ((memq backend
'(latex))
1695 ;; 2. Line-processing backends need to be told where lists end.
1696 ((memq backend
'(html docbook
))
1697 (funcall process-buffer
"ORG-LIST-END\n"))
1698 ;; 3. Others backends do not need to know this: clean list enders.
1700 (funcall process-buffer
"")))))
1702 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1703 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1704 If the next thing following is a table, add the text properties to the first
1705 table line. If it is a link, add it to the line containing the link."
1706 (goto-char (point-min))
1707 (remove-text-properties (point-min) (point-max)
1708 '(org-caption nil org-attributes nil
))
1709 (let ((case-fold-search t
)
1710 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1712 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1714 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1716 "^[ \t]*\\(|[^-]\\)"
1718 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1719 cap shortn attr label end
)
1720 (while (re-search-forward re nil t
)
1722 ;; there is a caption
1725 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1))))
1726 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap
)
1727 (setq shortn
(match-string 1 cap
)
1728 cap
(match-string 2 cap
)))
1729 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1730 ;; there is an attribute
1733 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2))))
1734 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1738 (setq label
(org-trim (match-string 3)))
1739 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1741 (setq end
(if (match-end 4)
1742 (let ((ee (org-table-end)))
1743 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1745 (add-text-properties (point-at-bol) end
1746 (list 'org-caption cap
1747 'org-caption-shortn shortn
1748 'org-attributes attr
1750 (if label
(push (cons label label
) target-alist
))
1752 (setq cap nil attr nil label nil
)))))
1755 (defun org-export-remove-comment-blocks-and-subtrees ()
1756 "Remove the comment environment, and also commented subtrees."
1757 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1759 ;; Remove comment environment
1760 (goto-char (point-min))
1761 (setq case-fold-search t
)
1762 (while (re-search-forward
1763 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t
)
1764 (replace-match "" t t
))
1765 ;; Remove subtrees that are commented
1766 (goto-char (point-min))
1767 (setq case-fold-search nil
)
1768 (while (re-search-forward re-commented nil t
)
1769 (goto-char (match-beginning 0))
1770 (delete-region (point) (org-end-of-subtree t
)))))
1772 (defun org-export-handle-comments (commentsp)
1773 "Remove comments, or convert to backend-specific format.
1774 COMMENTSP can be a format string for publishing comments.
1775 When it is nil, all comments will be removed."
1776 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1778 (goto-char (point-min))
1779 (while (or (looking-at re
)
1780 (re-search-forward re nil t
))
1781 (setq pos
(match-beginning 0))
1782 (if (get-text-property pos
'org-protected
)
1783 (goto-char (1+ pos
))
1785 (not (equal (char-before (match-end 1)) ?
+)))
1786 (progn (add-text-properties
1787 (match-beginning 0) (match-end 0) '(org-protected t
))
1788 (replace-match (format commentsp
(match-string 2)) t t
))
1789 (goto-char (1+ pos
))
1791 (goto-char (max (point-min) (1- pos
))))))))
1793 (defun org-export-handle-table-metalines ()
1794 "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
1795 (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
1797 (goto-char (point-min))
1798 (while (or (looking-at re
)
1799 (re-search-forward re nil t
))
1800 (setq pos
(match-beginning 0))
1801 (if (get-text-property (match-beginning 1) 'org-protected
)
1802 (goto-char (1+ pos
))
1803 (goto-char (1+ pos
))
1805 (goto-char (max (point-min) (1- pos
)))))))
1807 (defun org-export-mark-radio-links ()
1808 "Find all matches for radio targets and turn them into internal links."
1809 (let ((re-radio (and org-target-link-regexp
1810 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1811 (goto-char (point-min))
1813 (while (re-search-forward re-radio nil t
)
1816 (or (org-in-regexp org-bracket-link-regexp
)
1817 (org-in-regexp org-plain-link-re
)
1818 (org-in-regexp "<<[^<>]+>>")))
1820 (replace-match "\\1[[\\2]]")))))))
1822 (defun org-store-forced-table-alignment ()
1823 "Find table lines which force alignment, store the results in properties."
1824 (let (line cnt aligns
)
1825 (goto-char (point-min))
1826 (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t
)
1827 ;; OK, this looks like a table line with an alignment cookie
1829 (setq line
(buffer-substring (point-at-bol) (point-at-eol)))
1830 (when (and (org-at-table-p)
1831 (org-table-cookie-line-p line
))
1832 (setq cnt
0 aligns nil
)
1836 (if (string-match "\\`<\\([lrc]\\)" x
)
1837 (push (cons cnt
(downcase (match-string 1 x
))) aligns
)))
1838 (org-split-string line
"[ \t]*|[ \t]*"))
1839 (add-text-properties (org-table-begin) (org-table-end)
1840 (list 'org-forced-aligns aligns
))))
1841 (goto-char (point-at-eol)))))
1843 (defun org-export-remove-special-table-lines ()
1844 "Remove tables lines that are used for internal purposes.
1845 Also, store forcedalignment information found in such lines."
1846 (goto-char (point-min))
1847 (while (re-search-forward "^[ \t]*|" nil t
)
1848 (org-if-unprotected-at (1- (point))
1849 (beginning-of-line 1)
1850 (if (or (looking-at "[ \t]*| *[!_^] *|")
1856 (or (= (length f
) 0)
1858 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f
)))
1859 (org-split-string ;; FIXME, can't we do without splitting???
1860 (buffer-substring (point-at-bol) (point-at-eol))
1861 "[ \t]*|[ \t]*")))))
1862 (delete-region (max (point-min) (1- (point-at-bol)))
1866 (defun org-export-protect-sub-super (s)
1868 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
1869 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
1872 (defun org-export-normalize-links ()
1873 "Convert all links to bracket links, and expand link abbreviations."
1874 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1875 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1877 (goto-char (point-min))
1878 (while (re-search-forward re-plain-link nil t
)
1879 (unless (org-string-match-p
1880 "\\[\\[\\S-+:\\S-*?\\<"
1881 (buffer-substring (point-at-bol) (match-beginning 0)))
1882 (goto-char (1- (match-end 0)))
1883 (org-if-unprotected-at (1+ (match-beginning 0))
1884 (let* ((s (concat (match-string 1)
1885 "[[" (match-string 2) ":" (match-string 3)
1886 "][" (match-string 2) ":" (org-export-protect-sub-super
1889 ;; added 'org-link face to links
1890 (put-text-property 0 (length s
) 'face
'org-link s
)
1891 (replace-match s t t
)))))
1892 (goto-char (point-min))
1893 (while (re-search-forward re-angle-link nil t
)
1894 (goto-char (1- (match-end 0)))
1896 (let* ((s (concat (match-string 1)
1897 "[[" (match-string 2) ":" (match-string 3)
1898 "][" (match-string 2) ":" (org-export-protect-sub-super
1901 (put-text-property 0 (length s
) 'face
'org-link s
)
1902 (replace-match s t t
))))
1903 (goto-char (point-min))
1904 (while (re-search-forward org-bracket-link-regexp nil t
)
1905 (goto-char (1- (match-end 0)))
1906 (setq nodesc
(not (match-end 3)))
1908 (let* ((xx (save-match-data
1910 (org-link-expand-abbrev (match-string 1)))))
1912 "[[" (org-add-props (copy-sequence xx
)
1913 nil
'org-protected t
'org-no-description nodesc
)
1917 (concat "[" (copy-sequence xx
)
1920 (put-text-property 0 (length s
) 'face
'org-link s
)
1921 (replace-match s t t
))))))
1923 (defun org-export-concatenate-multiline-links ()
1924 "Find multi-line links and put it all into a single line.
1925 This is to make sure that the line-processing export backends
1926 can work correctly."
1927 (goto-char (point-min))
1928 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1929 (org-if-unprotected-at (match-beginning 1)
1930 (replace-match "\\1 \\3")
1931 (goto-char (match-beginning 0)))))
1933 (defun org-export-concatenate-multiline-emphasis ()
1934 "Find multi-line emphasis and put it all into a single line.
1935 This is to make sure that the line-processing export backends
1936 can work correctly."
1937 (goto-char (point-min))
1938 (while (re-search-forward org-emph-re nil t
)
1939 (if (and (not (= (char-after (match-beginning 3))
1940 (char-after (match-beginning 4))))
1941 (save-excursion (goto-char (match-beginning 0))
1943 (and (not (org-at-table-p))
1944 (not (org-at-heading-p))))))
1946 (subst-char-in-region (match-beginning 0) (match-end 0)
1948 (goto-char (1- (match-end 0))))
1949 (goto-char (1+ (match-beginning 0))))))
1951 (defun org-export-grab-title-from-buffer ()
1952 "Get a title for the current document, from looking at the buffer."
1953 (let ((inhibit-read-only t
))
1955 (goto-char (point-min))
1956 (let ((end (if (looking-at org-outline-regexp
)
1958 (save-excursion (outline-next-heading) (point)))))
1959 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1960 ;; Mark the line so that it will not be exported as normal text.
1962 (add-text-properties (match-beginning 0) (match-end 0)
1963 (list :org-license-to-kill t
)))
1964 ;; Return the title string
1965 (org-trim (match-string 0)))))))
1967 (defun org-export-get-title-from-subtree ()
1968 "Return subtree title and exclude it from export."
1969 (let ((rbeg (region-beginning)) (rend (region-end))
1970 (inhibit-read-only t
) title
)
1973 (when (and (org-at-heading-p)
1974 (>= (org-end-of-subtree t t
) rend
))
1975 ;; This is a subtree, we take the title from the first heading
1977 (looking-at org-todo-line-regexp
)
1978 (setq title
(match-string 3))
1980 (add-text-properties (point) (1+ (point-at-eol))
1981 (list :org-license-to-kill t
)))
1982 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1985 (defun org-solidify-link-text (s &optional alist
)
1986 "Take link text and make a safe target out of it."
1991 (org-split-string s
"[^a-zA-Z0-9_\\.-]+") "--"))
1992 (a (assoc rtn alist
)))
1995 (defun org-get-min-level (lines &optional offset
)
1996 "Get the minimum level in LINES."
1997 (let ((re "^\\(\\*+\\) ") l
)
1999 (while (setq l
(pop lines
))
2000 (if (string-match re l
)
2001 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2005 ;; Variable holding the vector with section numbers
2006 (defvar org-section-numbers
(make-vector org-level-max
0))
2008 (defun org-init-section-numbers ()
2009 "Initialize the vector for the section numbers."
2011 (numbers (nreverse (org-split-string "" "\\.")))
2012 (depth (1- (length org-section-numbers
)))
2013 (i depth
) number-string
)
2016 (aset org-section-numbers i
0)
2017 (setq number-string
(or (car numbers
) "0"))
2018 (if (string-match "\\`[A-Z]\\'" number-string
)
2019 (aset org-section-numbers i
2020 (- (string-to-char number-string
) ?A -
1))
2021 (aset org-section-numbers i
(string-to-number number-string
)))
2025 (defun org-section-number (&optional level
)
2026 "Return a string with the current section number.
2027 When LEVEL is non-nil, increase section numbers on that level."
2028 (let* ((depth (1- (length org-section-numbers
)))
2030 (fmts (car org-export-section-number-format
))
2031 (term (cdr org-export-section-number-format
))
2036 (aset org-section-numbers
2037 level
(1+ (aref org-section-numbers level
))))
2038 (setq idx
(1+ level
))
2039 (while (<= idx depth
)
2041 (aset org-section-numbers idx
0))
2042 (setq idx
(1+ idx
))))
2044 (while (<= idx depth
)
2045 (when (> (aref org-section-numbers idx
) 0)
2046 (setq fmt
(or (pop fmts
) fmt
)
2048 n
(aref org-section-numbers idx
)
2050 (concat string sep
(org-number-to-counter n ctype
))
2051 (concat string
".0"))
2053 (setq idx
(1+ idx
)))
2055 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2056 (setq string
(replace-match "" t nil string
)))
2057 (if (string-match "\\(\\.0\\)+\\'" string
)
2058 (setq string
(replace-match "" t nil string
))))
2059 (concat string term
)))
2061 (defun org-number-to-counter (n type
)
2062 "Concert number N to a string counter, according to TYPE.
2063 TYPE must be a string, any of:
2067 I upper case roman numeral
2068 i lower case roman numeral"
2070 ((equal type
"1") (number-to-string n
))
2071 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2072 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2073 ((equal type
"I") (org-number-to-roman n
))
2074 ((equal type
"i") (downcase (org-number-to-roman n
)))
2075 (t (error "Invalid counter type `%s'" type
))))
2077 (defun org-number-to-roman (n)
2078 "Convert integer N into a roman numeral."
2079 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2080 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2081 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2085 (number-to-string n
)
2087 (if (>= n
(caar roman
))
2088 (setq n
(- n
(caar roman
))
2089 res
(concat res
(cdar roman
)))
2095 (defun org-export-preprocess-apply-macros ()
2096 "Replace macro references."
2097 (goto-char (point-min))
2098 (let (sy val key args args2 s n
)
2099 (while (re-search-forward
2100 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2102 (unless (save-match-data
2104 (goto-char (point-at-bol))
2105 (looking-at "[ \t]*#\\+macro")))
2106 (setq key
(downcase (match-string 1))
2107 args
(match-string 3))
2108 (when (setq val
(or (plist-get org-export-opt-plist
2109 (intern (concat ":macro-" key
)))
2110 (plist-get org-export-opt-plist
2111 (intern (concat ":" key
)))))
2114 (setq args
(org-split-string args
",") args2 nil
)
2116 (while (string-match "\\\\\\'" (car args
))
2117 ;; repair bad splits
2118 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2121 (push (pop args
) args2
))
2122 (setq args
(mapcar 'org-trim
(nreverse args2
)))
2124 (while (string-match "\\$\\([0-9]+\\)" val s
)
2125 (setq s
(1+ (match-beginning 0))
2126 n
(string-to-number (match-string 1 val
)))
2127 (and (>= (length args
) n
)
2128 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2129 (when (string-match "\\`(eval\\>" val
)
2130 (setq val
(eval (read val
))))
2131 (if (and val
(not (stringp val
)))
2132 (setq val
(format "%s" val
))))
2134 (prog1 (replace-match val t t
)
2135 (goto-char (match-beginning 0)))))))))
2137 (defun org-export-apply-macros-in-string (s)
2138 "Apply the macros in string S."
2142 (org-export-preprocess-apply-macros)
2147 (defun org-export-handle-include-files ()
2148 "Include the contents of include files, with proper formatting."
2149 (let ((case-fold-search t
)
2150 params file markup lang start end prefix prefix1 switches all minlevel lines
)
2151 (goto-char (point-min))
2152 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2153 (setq params
(read (concat "(" (match-string 1) ")"))
2154 prefix
(org-get-and-remove-property 'params
:prefix
)
2155 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2156 minlevel
(org-get-and-remove-property 'params
:minlevel
)
2157 lines
(org-get-and-remove-property 'params
:lines
)
2158 file
(org-symname-or-string (pop params
))
2159 markup
(org-symname-or-string (pop params
))
2160 lang
(and (member markup
'("src" "SRC"))
2161 (org-symname-or-string (pop params
)))
2162 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" ")
2164 (delete-region (match-beginning 0) (match-end 0))
2166 (not (file-exists-p file
))
2167 (not (file-readable-p file
)))
2168 (insert (format "CANNOT INCLUDE FILE %s" file
))
2169 (setq all
(cons file all
))
2171 (if (equal (downcase markup
) "src")
2172 (setq start
(format "#+begin_src %s %s\n"
2173 (or lang
"fundamental")
2176 (setq start
(format "#+begin_%s %s\n" markup switches
)
2177 end
(format "#+end_%s" markup
))))
2178 (insert (or start
""))
2179 (insert (org-get-file-contents (expand-file-name file
)
2180 prefix prefix1 markup minlevel lines
))
2181 (or (bolp) (newline))
2182 (insert (or end
""))))
2185 (defun org-export-handle-include-files-recurse ()
2186 "Recursively include files aborting on circular inclusion."
2187 (let ((now (list org-current-export-file
)) all
)
2189 (setq all
(append now all
))
2190 (setq now
(org-export-handle-include-files))
2193 (mapcar (lambda (el) (when (member el all
) el
)) now
))))
2195 (error "Recursive #+INCLUDE: %S" intersection
))))))
2197 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel lines
)
2198 "Get the contents of FILE and return them as a string.
2199 If PREFIX is a string, prepend it to each line. If PREFIX1
2200 is a string, prepend it to the first line instead of PREFIX.
2201 If MARKUP, don't protect org-like lines, the exporter will
2202 take care of the block they are in. If LINES is a string
2203 specifying a range of lines, include only those lines ."
2204 (if (stringp markup
) (setq markup
(downcase markup
)))
2206 (insert-file-contents file
)
2208 (let* ((lines (split-string lines
"-"))
2209 (lbeg (string-to-number (car lines
)))
2210 (lend (string-to-number (cadr lines
)))
2211 (beg (if (zerop lbeg
) (point-min)
2212 (goto-char (point-min))
2213 (forward-line (1- lbeg
))
2215 (end (if (zerop lend
) (point-max)
2216 (goto-char (point-min))
2217 (forward-line (1- lend
))
2219 (narrow-to-region beg end
)))
2220 (when (or prefix prefix1
)
2221 (goto-char (point-min))
2223 (insert (or prefix1 prefix
))
2225 (beginning-of-line 2)))
2227 (when (member markup
'("src" "example"))
2228 (goto-char (point-min))
2229 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2230 (goto-char (match-beginning 0))
2234 (dotimes (lvl minlevel
)
2235 (org-map-region 'org-demote
(point-min) (point-max))))
2238 (defun org-get-and-remove-property (listvar prop
)
2239 "Check if the value of LISTVAR contains PROP as a property.
2240 If yes, return the value of that property (i.e. the element following
2241 in the list) and remove property and value from the list in LISTVAR."
2242 (let ((list (symbol-value listvar
)) m v
)
2243 (when (setq m
(member prop list
))
2245 (if (equal (car list
) prop
)
2246 (set listvar
(cddr list
))
2247 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2249 (set listvar list
)))
2252 (defun org-symname-or-string (s)
2254 (if s
(symbol-name s
) s
)
2257 ;;; Fontification and line numbers for code examples
2259 (defvar org-export-last-code-line-counter-value
0)
2261 (defun org-export-replace-src-segments-and-examples (backend)
2262 "Replace source code segments with special code for export."
2263 (setq org-export-last-code-line-counter-value
0)
2264 (let ((case-fold-search t
)
2265 lang code trans opts indent caption
)
2266 (goto-char (point-min))
2267 (while (re-search-forward
2268 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2271 (if (not (match-string 4))
2272 (error "Source block missing language specification: %s"
2273 (let* ((body (match-string 6))
2274 (nothing (message "body:%s" body
))
2275 (preview (or (and (string-match
2276 "^[ \t]*\\([^\n\r]*\\)" body
)
2277 (match-string 1 body
)) body
)))
2278 (if (> (length preview
) 35)
2279 (concat (substring preview
0 32) "...")
2282 (setq lang
(match-string 4)
2283 opts
(match-string 5)
2284 code
(match-string 6)
2285 indent
(length (match-string 2))
2286 caption
(get-text-property 0 'org-caption
(match-string 0))))
2288 opts
(match-string 9)
2289 code
(match-string 10)
2290 indent
(length (match-string 8))
2291 caption
(get-text-property 0 'org-caption
(match-string 0))))
2293 (setq trans
(org-export-format-source-code-or-example
2294 backend lang code opts indent caption
))
2295 (replace-match trans t t
))))
2297 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2298 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2299 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2300 (defvar org-export-latex-listings-w-names
) ;; defined in org-latex.el
2301 (defvar org-export-latex-minted-langs
) ;; defined in org-latex.el
2302 (defvar org-export-latex-custom-lang-environments
) ;; defined in org-latex.el
2303 (defvar org-export-latex-listings-options
) ;; defined in org-latex.el
2304 (defvar org-export-latex-minted-options
) ;; defined in org-latex.el
2306 (defun org-export-format-source-code-or-example
2307 (backend lang code
&optional opts indent caption
)
2308 "Format CODE from language LANG and return it formatted for export.
2309 If LANG is nil, do not add any fontification.
2310 OPTS contains formatting options, like `-n' for triggering numbering lines,
2311 and `+n' for continuing previous numbering.
2312 Code formatting according to language currently only works for HTML.
2313 Numbering lines works for all three major backends (html, latex, and ascii).
2314 INDENT was the original indentation of the block."
2316 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2317 (setq opts
(or opts
"")
2318 num
(string-match "[-+]n\\>" opts
)
2319 cont
(string-match "\\+n\\>" opts
)
2320 rpllbl
(string-match "-r\\>" opts
)
2321 keepp
(string-match "-k\\>" opts
)
2322 textareap
(string-match "-t\\>" opts
)
2323 preserve-indentp
(or org-src-preserve-indentation
2324 (string-match "-i\\>" opts
))
2325 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2326 (string-to-number (match-string 1 opts
))
2328 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2329 (string-to-number (match-string 1 opts
))
2330 (org-count-lines code
))
2331 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2332 (match-string 1 opts
)))
2333 (when (and textareap
(eq backend
'html
))
2334 ;; we cannot use numbering or highlighting.
2335 (setq num nil cont nil lang nil
))
2336 (if keepp
(setq rpllbl
'keep
))
2337 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2338 (when (string-match "^," rtn
)
2339 (setq rtn
(with-temp-buffer
2341 ;; Free up the protected lines
2342 (goto-char (point-min))
2343 (while (re-search-forward "^," nil t
)
2344 (if (or (equal lang
"org")
2346 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2350 ;; Now backend-specific coding
2353 ((eq backend
'docbook
)
2354 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2355 (concat "\n#+BEGIN_DOCBOOK\n"
2356 (org-add-props (concat "<programlisting><![CDATA["
2358 "]]></programlisting>\n")
2359 '(org-protected t org-example t
))
2362 ;; We are exporting to HTML
2364 (if (featurep 'xemacs
)
2366 (require 'htmlize nil t
))
2367 (when (not (fboundp 'htmlize-region-for-paste
))
2368 ;; we do not have htmlize.el, or an old version of it
2371 "htmlize.el 1.34 or later is needed for source code formatting")))
2374 (let* ((lang-m (when lang
2375 (or (cdr (assoc lang org-src-lang-modes
))
2377 (mode (and lang-m
(intern
2379 (if (symbolp lang-m
)
2380 (symbol-name lang-m
)
2383 (org-inhibit-startup t
)
2384 (org-startup-folded nil
))
2388 (if (functionp mode
)
2391 (font-lock-fontify-buffer)
2393 (set-buffer-modified-p nil
)
2394 (org-export-htmlize-region-for-paste
2395 (point-min) (point-max))))
2396 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2401 "<div class=\"org-src-container\">"
2403 "<label class=\"org-src-name\">%s</label>"
2407 (format "<pre class=\"src src-%s\">\n" lang
)
2409 (if caption
"</div>" "")))))
2412 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2414 rtn
"</textarea>\n</p>\n"))
2417 (goto-char (point-min))
2418 (while (re-search-forward "[<>&]" nil t
)
2419 (replace-match (cdr (assq (char-before)
2420 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2422 (setq rtn
(buffer-string)))
2423 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2425 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2427 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2428 (setq rtn
(replace-match "\\1" t nil rtn
)))
2429 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t org-example t
)) "\n#+END_HTML\n\n"))
2430 ((eq backend
'latex
)
2431 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2436 ((and lang org-export-latex-listings
)
2437 (flet ((make-option-string
2439 (concat (first pair
)
2440 (if (> (length (second pair
)) 0)
2441 (concat "=" (second pair
))))))
2442 (let* ((lang-sym (intern lang
))
2443 (minted-p (eq org-export-latex-listings
'minted
))
2444 (listings-p (not minted-p
))
2450 (minted-p org-export-latex-minted-langs
)
2451 (listings-p org-export-latex-listings-langs
))))
2457 org-export-latex-custom-lang-environments
))))
2459 (when (and listings-p
(not custom-environment
))
2463 #'make-option-string
2464 (append org-export-latex-listings-options
2465 `(("language" ,backend-lang
))) ",")))
2466 (when (and caption org-export-latex-listings-w-names
)
2469 (replace-regexp-in-string "_" "\\\\_" caption
)))
2472 (format "\\begin{%s}\n%s\\end{%s}\n"
2473 custom-environment rtn custom-environment
))
2475 (format "\\begin{%s}\n%s\\end{%s}\n"
2476 "lstlisting" rtn
"lstlisting"))
2479 "\\begin{minted}[%s]{%s}\n%s\\end{minted}\n"
2480 (mapconcat #'make-option-string
2481 org-export-latex-minted-options
",")
2482 backend-lang rtn
)))))))
2483 (t (concat (car org-export-latex-verbatim-wrap
)
2484 rtn
(cdr org-export-latex-verbatim-wrap
))))
2485 '(org-protected t org-example t
))
2487 ((eq backend
'ascii
)
2488 ;; This is not HTML or LaTeX, so just make it an example.
2489 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2490 (concat caption
"\n"
2495 (lambda (l) (concat " " l
))
2496 (org-split-string rtn
"\n")
2499 '(org-protected t org-example t
))
2501 (org-add-props rtn nil
'original-indentation indent
))))
2503 (defun org-export-number-lines (text backend
2504 &optional skip1 skip2 number cont
2505 replace-labels label-format
)
2506 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2507 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2510 (goto-char (point-max))
2511 (skip-chars-backward " \t\n\r")
2512 (delete-region (point) (point-max))
2513 (beginning-of-line (- 1 skip2
))
2514 (let* ((last (org-current-line))
2515 (n org-export-last-code-line-counter-value
)
2516 (nmax (+ n
(- last skip1
)))
2517 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2520 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2522 ((eq backend
'ascii
) fmt
)
2523 ((eq backend
'latex
) fmt
)
2524 ((eq backend
'docbook
) fmt
)
2526 (label-format (or label-format org-coderef-label-format
))
2527 (label-pre (if (string-match "%s" label-format
)
2528 (substring label-format
0 (match-beginning 0))
2530 (label-post (if (string-match "%s" label-format
)
2531 (substring label-format
(match-end 0))
2535 ".*?\\S-.*?\\([ \t]*\\("
2536 (regexp-quote label-pre
)
2537 "\\([-a-zA-Z0-9_ ]+\\)"
2538 (regexp-quote label-post
)
2542 (org-goto-line (1+ skip1
))
2543 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2545 (insert (format fm
(incf n
)))
2547 (when (looking-at lbl-re
)
2548 (setq ref
(match-string 3))
2549 (cond ((numberp replace-labels
)
2550 ;; remove labels; use numbers for references when lines
2551 ;; are numbered, use labels otherwise
2552 (delete-region (match-beginning 1) (match-end 1))
2553 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2554 ((eq replace-labels
'keep
)
2555 ;; don't remove labels; use numbers for references when
2556 ;; lines are numbered, use labels otherwise
2557 (goto-char (match-beginning 2))
2558 (delete-region (match-beginning 2) (match-end 2))
2559 (insert "(" ref
")")
2560 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2561 org-export-code-refs
))
2563 ;; don't remove labels and don't use numbers for
2565 (goto-char (match-beginning 2))
2566 (delete-region (match-beginning 2) (match-end 2))
2567 (insert "(" ref
")")
2568 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2569 (when (eq backend
'html
)
2571 (beginning-of-line 1)
2572 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2575 (insert "</span>")))))
2576 (setq org-export-last-code-line-counter-value n
)
2577 (goto-char (point-max))
2581 (defun org-search-todo-below (line lines level
)
2582 "Search the subtree below LINE for any TODO entries."
2583 (let ((rest (cdr (memq line lines
)))
2584 (re org-todo-line-regexp
)
2587 (while (setq line
(pop rest
))
2588 (if (string-match re line
)
2590 (setq lv
(- (match-end 1) (match-beginning 1))
2591 todo
(and (match-beginning 2)
2592 (not (member (match-string 2 line
)
2593 org-done-keywords
))))
2595 (if (<= lv level
) (throw 'exit nil
))
2596 (if todo
(throw 'exit t
))))))))
2599 (defun org-export-visible (type arg
)
2600 "Create a copy of the visible part of the current buffer, and export it.
2601 The copy is created in a temporary buffer and removed after use.
2602 TYPE is the final key (as a string) that also selects the export command in
2603 the \\<org-mode-map>\\[org-export] export dispatcher.
2604 As a special case, if the you type SPC at the prompt, the temporary
2605 org-mode file will not be removed but presented to you so that you can
2606 continue to use it. The prefix arg ARG is passed through to the exporting
2610 (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")
2611 (read-char-exclusive))
2612 current-prefix-arg
))
2613 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L
)))
2614 (error "Invalid export key"))
2615 (let* ((binding (cdr (assoc type
2617 (?a . org-export-as-ascii
)
2618 (?A . org-export-as-ascii-to-buffer
)
2619 (?n . org-export-as-latin1
)
2620 (?N . org-export-as-latin1-to-buffer
)
2621 (?u . org-export-as-utf8
)
2622 (?U . org-export-as-utf8-to-buffer
)
2623 (?\C-a . org-export-as-ascii
)
2624 (?b . org-export-as-html-and-open
)
2625 (?\C-b . org-export-as-html-and-open
)
2626 (?h . org-export-as-html
)
2627 (?H . org-export-as-html-to-buffer
)
2628 (?R . org-export-region-as-html
)
2629 (?D . org-export-as-docbook
)
2631 (?l . org-export-as-latex
)
2632 (?p . org-export-as-pdf
)
2633 (?d . org-export-as-pdf-and-open
)
2634 (?L . org-export-as-latex-to-buffer
)
2636 (?x . org-export-as-xoxo
)))))
2637 (keepp (equal type ?\
))
2638 (file buffer-file-name
)
2639 (buffer (get-buffer-create "*Org Export Visible*"))
2641 ;; Need to hack the drawers here.
2643 (goto-char (point-min))
2644 (while (re-search-forward org-drawer-regexp nil t
)
2645 (goto-char (match-beginning 1))
2646 (or (outline-invisible-p) (org-flag-drawer nil
))))
2647 (with-current-buffer buffer
(erase-buffer))
2649 (setq s
(goto-char (point-min)))
2650 (while (not (= (point) (point-max)))
2651 (goto-char (org-find-invisible))
2652 (append-to-buffer buffer s
(point))
2653 (setq s
(goto-char (org-find-visible))))
2654 (org-cycle-hide-drawers 'all
)
2655 (goto-char (point-min))
2657 ;; Copy all comment lines to the end, to make sure #+ settings are
2658 ;; still available for the second export step. Kind of a hack, but
2659 ;; does do the trick.
2660 (if (looking-at "#[^\r\n]*")
2661 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2662 (when (re-search-forward "^\\*+[ \t]+" nil t
)
2663 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t
)
2664 (append-to-buffer buffer
(1+ (match-beginning 0))
2665 (min (point-max) (1+ (match-end 0)))))))
2667 (let ((buffer-file-name file
)
2668 (org-inhibit-startup t
))
2671 (unless keepp
(funcall binding arg
))))
2673 (kill-buffer buffer
)
2674 (switch-to-buffer-other-window buffer
)
2675 (goto-char (point-min)))))
2677 (defun org-find-visible ()
2679 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2680 (get-char-property s
'invisible
)))
2682 (defun org-find-invisible ()
2684 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2685 (not (get-char-property s
'invisible
))))
2688 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2690 (defun org-export-string (string fmt
&optional dir
)
2691 "Export STRING to FMT using existing export facilities.
2692 During export STRING is saved to a temporary file whose location
2693 could vary. Optional argument DIR can be used to force the
2694 directory in which the temporary file is created during export
2695 which can be useful for resolving relative paths. Dir defaults
2696 to the value of `temporary-file-directory'."
2697 (let ((temporary-file-directory (or dir temporary-file-directory
))
2698 (tmp-file (make-temp-file "org-")))
2702 (write-file tmp-file
)
2703 (org-load-modules-maybe)
2704 (unless org-local-vars
2705 (setq org-local-vars
(org-get-local-variables)))
2706 (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
2707 (list 'let org-local-vars
2708 (list (intern (format "org-export-as-%s" fmt
))
2709 nil nil nil
''string t
))))
2710 (delete-file tmp-file
))))
2713 (defun org-export-as-org (arg &optional hidden ext-plist
2714 to-buffer body-only pub-dir
)
2715 "Make a copy with not-exporting stuff removed.
2716 The purpose of this function is to provide a way to export the source
2717 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2718 stuff removed. This command will remove the following:
2720 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2721 - comment blocks and trees starting with the COMMENT keyword
2722 - only trees that are consistent with `org-export-select-tags'
2723 and `org-export-exclude-tags'.
2725 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2726 all the others will be ignored (but are present so that the general
2727 mechanism to call publishing functions will work).
2729 EXT-PLIST is a property list with external parameters overriding
2730 org-mode's default settings, but still inferior to file-local
2731 settings. When PUB-DIR is set, use this as the publishing
2734 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2736 (org-infile-export-plist)))
2737 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2738 (filename (concat (file-name-as-directory
2740 (org-export-directory :org opt-plist
)))
2741 (file-name-sans-extension
2742 (file-name-nondirectory bfname
))
2744 (filename (and filename
2745 (if (equal (file-truename filename
)
2746 (file-truename bfname
))
2747 (concat (file-name-sans-extension filename
)
2749 (file-name-extension filename
))
2751 (backup-inhibited t
)
2752 (buffer (find-file-noselect filename
))
2753 (region (buffer-string))
2756 (switch-to-buffer buffer
)
2759 (let ((org-inhibit-startup t
)) (org-mode))
2760 (org-install-letbind)
2762 ;; Get rid of archived trees
2763 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2765 ;; Remove comment environment and comment subtrees
2766 (org-export-remove-comment-blocks-and-subtrees)
2768 ;; Get rid of excluded trees
2769 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2770 (plist-get opt-plist
:exclude-tags
))
2772 (when (or (plist-get opt-plist
:plain-source
)
2773 (not (or (plist-get opt-plist
:plain-source
)
2774 (plist-get opt-plist
:htmlized-source
))))
2775 ;; Either nothing special is requested (default call)
2776 ;; or the plain source is explicitly requested
2779 (when (plist-get opt-plist
:htmlized-source
)
2780 ;; Make the htmlized version
2783 (font-lock-fontify-buffer)
2784 (let* ((htmlize-output-type 'css
)
2785 (newbuf (htmlize-buffer)))
2786 (with-current-buffer newbuf
2787 (when org-export-htmlized-org-css-url
2788 (goto-char (point-min))
2789 (and (re-search-forward
2790 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2794 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2795 org-export-htmlized-org-css-url
)
2797 (write-file (concat filename
".html")))
2798 (kill-buffer newbuf
)))
2799 (set-buffer-modified-p nil
)
2800 (if (equal to-buffer
'string
)
2801 (progn (setq str-ret
(buffer-string))
2802 (kill-buffer (current-buffer))
2804 (kill-buffer (current-buffer))))))
2806 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2807 (defun org-get-current-options ()
2808 "Return a string with current options as keyword options.
2809 Does include HTML export options as well as TODO and CATEGORY stuff."
2810 (require 'org-archive
)
2819 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2820 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2822 #+EXPORT_SELECT_TAGS: %s
2823 #+EXPORT_EXCLUDE_TAGS: %s
2830 #+PRIORITIES: %c %c %c
2832 #+STARTUP: %s %s %s %s %s
2838 (buffer-name) (user-full-name) user-mail-address
2839 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2840 org-export-default-language
2841 org-export-headline-levels
2842 org-export-with-section-numbers
2844 org-export-preserve-breaks
2845 org-export-html-expand
2846 org-export-with-fixed-width
2847 org-export-with-tables
2848 org-export-with-sub-superscripts
2849 org-export-with-special-strings
2850 org-export-with-footnotes
2851 org-export-with-emphasize
2852 org-export-with-timestamps
2853 org-export-with-TeX-macros
2854 org-export-with-LaTeX-fragments
2855 org-export-skip-text-before-1st-heading
2856 org-export-with-drawers
2857 org-export-with-todo-keywords
2858 org-export-with-priority
2859 org-export-with-tags
2860 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2861 (mapconcat 'identity org-export-select-tags
" ")
2862 (mapconcat 'identity org-export-exclude-tags
" ")
2863 org-export-html-link-up
2864 org-export-html-link-home
2866 (file-name-sans-extension
2867 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2869 "TODO FEEDBACK VERIFY DONE"
2870 "Me Jason Marie DONE"
2871 org-highest-priority org-lowest-priority org-default-priority
2872 (mapconcat 'identity org-drawers
" ")
2873 (cdr (assoc org-startup-folded
2874 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2875 (if org-odd-levels-only
"odd" "oddeven")
2876 (if org-hide-leading-stars
"hidestars" "showstars")
2877 (if org-startup-align-all-tables
"align" "noalign")
2878 (cond ((eq org-log-done t
) "logdone")
2879 ((equal org-log-done
'note
) "lognotedone")
2880 ((not org-log-done
) "nologdone"))
2881 (or (mapconcat (lambda (x)
2883 ((equal :startgroup
(car x
)) "{")
2884 ((equal :endgroup
(car x
)) "}")
2885 ((equal :newline
(car x
)) "")
2886 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2888 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2889 (mapconcat 'identity org-file-tags
" ")
2890 org-archive-location
2891 "org file:~/org/%s.org"
2895 (defun org-insert-export-options-template ()
2896 "Insert into the buffer a template with information for exporting."
2898 (if (not (bolp)) (newline))
2899 (let ((s (org-get-current-options)))
2900 (and (string-match "#\\+CATEGORY" s
)
2901 (setq s
(substring s
0 (match-beginning 0))))
2904 (defvar org-table-colgroup-info nil
)
2906 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2907 "Check if the table has a marking column.
2908 If yes remove the column and the special lines."
2909 (setq org-table-colgroup-info nil
)
2912 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2915 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2916 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2919 ;; No special marking column
2921 (setq org-table-clean-did-remove-column nil
)
2926 ((org-table-colgroup-line-p x
)
2927 ;; This line contains colgroup info, extract it
2928 ;; and then discard the line
2929 (setq org-table-colgroup-info
2931 (cond ((member x
'("<" "<")) :start
)
2932 ((member x
'(">" ">")) :end
)
2933 ((member x
'("<>" "<>")) :startend
)
2935 (org-split-string x
"[ \t]*|[ \t]*")))
2937 ((org-table-cookie-line-p x
)
2938 ;; This line contains formatting cookies, discard it
2942 ;; there is a special marking column
2943 (setq org-table-clean-did-remove-column t
)
2948 ((org-table-colgroup-line-p x
)
2949 ;; This line contains colgroup info, extract it
2950 ;; and then discard the line
2951 (setq org-table-colgroup-info
2953 (cond ((member x
'("<" "<")) :start
)
2954 ((member x
'(">" ">")) :end
)
2955 ((member x
'("<>" "<>")) :startend
)
2957 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2959 ((org-table-cookie-line-p x
)
2960 ;; This line contains formatting cookies, discard it
2962 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2965 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2966 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2967 ;; remove the first column
2968 (replace-match "\\1|" t nil x
))))
2971 (defun org-export-cleanup-toc-line (s)
2972 "Remove tags and timestamps from lines going into the toc."
2973 (when (memq org-export-with-tags
'(not-in-toc nil
))
2974 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s
)
2975 (setq s
(replace-match "" t t s
))))
2976 (when org-export-remove-timestamps-from-toc
2977 (while (string-match org-maybe-keyword-time-regexp s
)
2978 (setq s
(replace-match "" t t s
))))
2979 (while (string-match org-bracket-link-regexp s
)
2980 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2982 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
2983 (setq s
(replace-match "" t t s
)))
2987 (defun org-get-text-property-any (pos prop
&optional object
)
2988 (or (get-text-property pos prop object
)
2989 (and (setq pos
(next-single-property-change pos prop object
))
2990 (get-text-property pos prop object
))))
2992 (defun org-export-get-coderef-format (path desc
)
2994 (if (and desc
(string-match
2995 (regexp-quote (concat "(" path
")"))
2997 (replace-match "%s" t t desc
)
3000 (defun org-export-push-to-kill-ring (format)
3001 "Push buffer content to kill ring.
3002 The depends on the variable `org-export-copy-to-kill'."
3003 (when org-export-copy-to-kill-ring
3004 (org-kill-new (buffer-string))
3005 (when (fboundp 'x-set-selection
)
3006 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
3007 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
3008 (message "%s export done, pushed to kill ring and clipboard" format
)))
3012 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3014 ;;; org-exp.el ends here