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