1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (require 'org-exp-blocks
)
41 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
42 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
43 (declare-function org-export-html-preprocess
"org-html" (parameters))
44 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
45 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
46 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
47 (declare-function htmlize-buffer
"ext:htmlize" (&optional buffer
))
48 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
49 (declare-function org-table-cookie-line-p
"org-table" (line))
50 (declare-function org-table-colgroup-line-p
"org-table" (line))
51 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
52 (defgroup org-export nil
53 "Options for exporting org-listings."
57 (defgroup org-export-general nil
58 "General options for exporting Org-mode files."
59 :tag
"Org Export General"
62 (defcustom org-export-allow-BIND
'confirm
63 "Non-nil means allow #+BIND to define local variable values for export.
64 This is a potential security risk, which is why the user must confirm the
66 :group
'org-export-general
68 (const :tag
"Never" nil
)
69 (const :tag
"Always" t
)
70 (const :tag
"Make the user confirm for each file" confirm
)))
73 (defvar org-export-publishing-directory nil
)
75 (defcustom org-export-show-temporary-export-buffer t
76 "Non-nil means show buffer after exporting to temp buffer.
77 When Org exports to a file, the buffer visiting that file is ever
78 shown, but remains buried. However, when exporting to a temporary
79 buffer, that buffer is popped up in a second window. When this variable
80 is nil, the buffer remains buried also in these cases."
81 :group
'org-export-general
84 (defcustom org-export-copy-to-kill-ring t
85 "Non-nil means exported stuff will also be pushed onto the kill ring."
86 :group
'org-export-general
89 (defcustom org-export-kill-product-buffer-when-displayed nil
90 "Non-nil means kill the product buffer if it is displayed immediately.
91 This applied to the commands `org-export-html-and-open' and
92 `org-export-as-pdf-and-open'."
93 :group
'org-export-general
96 (defcustom org-export-run-in-background nil
97 "Non-nil means export and publishing commands will run in background.
98 This works by starting up a separate Emacs process visiting the same file
99 and doing the export from there.
100 Not all export commands are affected by this - only the ones which
101 actually write to a file, and that do not depend on the buffer state.
103 If this option is nil, you can still get background export by calling
104 `org-export' with a double prefix arg: \
105 \\[universal-argument] \\[universal-argument] \\[org-export].
107 If this option is t, the double prefix can be used to exceptionally
108 force an export command into the current process."
109 :group
'org-export-general
112 (defcustom org-export-initial-scope
'buffer
113 "The initial scope when exporting with `org-export'.
114 This variable can be either set to 'buffer or 'subtree."
115 :group
'org-export-general
117 (const :tag
"Export current buffer" 'buffer
)
118 (const :tag
"Export current subtree" 'subtree
)))
120 (defcustom org-export-select-tags
'("export")
121 "Tags that select a tree for export.
122 If any such tag is found in a buffer, all trees that do not carry one
123 of these tags will be deleted before export.
124 Inside trees that are selected like this, you can still deselect a
125 subtree by tagging it with one of the `org-export-exclude-tags'."
126 :group
'org-export-general
127 :type
'(repeat (string :tag
"Tag")))
129 (defcustom org-export-exclude-tags
'("noexport")
130 "Tags that exclude a tree from export.
131 All trees carrying any of these tags will be excluded from export.
132 This is without condition, so even subtrees inside that carry one of the
133 `org-export-select-tags' will be removed."
134 :group
'org-export-general
135 :type
'(repeat (string :tag
"Tag")))
137 ;; FIXME: rename, this is a general variable
138 (defcustom org-export-html-expand t
139 "Non-nil means for HTML export, treat @<...> as HTML tag.
140 When nil, these tags will be exported as plain text and therefore
141 not be interpreted by a browser.
143 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
144 :group
'org-export-html
145 :group
'org-export-general
148 (defcustom org-export-with-special-strings t
149 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
150 When this option is turned on, these strings will be exported as:
153 -----+----------+--------
159 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
160 :group
'org-export-translation
163 (defcustom org-export-html-link-up
""
164 "Where should the \"UP\" link of exported HTML pages lead?"
165 :group
'org-export-html
166 :group
'org-export-general
167 :type
'(string :tag
"File or URL"))
169 (defcustom org-export-html-link-home
""
170 "Where should the \"HOME\" link of exported HTML pages lead?"
171 :group
'org-export-html
172 :group
'org-export-general
173 :type
'(string :tag
"File or URL"))
175 (defcustom org-export-language-setup
176 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
177 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
178 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
179 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
180 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
181 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
182 ("es" "Autor" "Fecha" "Índice" "Pies de página")
183 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
184 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
185 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
186 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
187 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
188 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
189 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
190 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
191 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
192 ("pl" "Autor" "Data" "Spis treści" "Przypis")
193 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
194 "Terms used in export text, translated to different languages.
195 Use the variable `org-export-default-language' to set the language,
196 or use the +OPTION lines for a per-file setting."
197 :group
'org-export-general
200 (string :tag
"HTML language tag")
201 (string :tag
"Author")
203 (string :tag
"Table of Contents")
204 (string :tag
"Footnotes"))))
206 (defcustom org-export-default-language
"en"
207 "The default language for export and clocktable translations, as a string.
208 This should have an association in `org-export-language-setup'
209 and in `org-clock-clocktable-language-setup'."
210 :group
'org-export-general
213 (defvar org-export-page-description
""
214 "The page description, for the XHTML meta tag.
215 This is best set with the #+DESCRIPTION line in a file, it does not make
216 sense to set this globally.")
218 (defvar org-export-page-keywords
""
219 "The page description, for the XHTML meta tag.
220 This is best set with the #+KEYWORDS line in a file, it does not make
221 sense to set this globally.")
223 (defcustom org-export-skip-text-before-1st-heading nil
224 "Non-nil means skip all text before the first headline when exporting.
225 When nil, that text is exported as well."
226 :group
'org-export-general
229 (defcustom org-export-headline-levels
3
230 "The last level which is still exported as a headline.
231 Inferior levels will produce itemize lists when exported.
232 Note that a numeric prefix argument to an exporter function overrides
235 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
236 :group
'org-export-general
239 (defcustom org-export-with-section-numbers t
240 "Non-nil means add section numbers to headlines when exporting.
242 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
243 :group
'org-export-general
246 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
247 "Format of section numbers for export.
248 The variable has two components.
249 1. A list of lists, each indicating a counter type and a separator.
250 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
251 It causes causes numeric, alphabetic, or roman counters, respectively.
252 The separator is only used if another counter for a subsection is being
254 If there are more numbered section levels than entries in this lists,
255 then the last entry will be reused.
256 2. A terminator string that will be added after the entire
258 :group
'org-export-general
262 (string :tag
"Counter Type")
263 (string :tag
"Separator ")))
264 (string :tag
"Terminator")))
266 (defcustom org-export-with-toc t
267 "Non-nil means create a table of contents in exported files.
268 The TOC contains headlines with levels up to`org-export-headline-levels'.
269 When an integer, include levels up to N in the toc, this may then be
270 different from `org-export-headline-levels', but it will not be allowed
271 to be larger than the number of headline levels.
272 When nil, no table of contents is made.
274 Headlines which contain any TODO items will be marked with \"(*)\" in
275 ASCII export, and with red color in HTML output, if the option
276 `org-export-mark-todo-in-toc' is set.
278 In HTML output, the TOC will be clickable.
280 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
282 :group
'org-export-general
284 (const :tag
"No Table of Contents" nil
)
285 (const :tag
"Full Table of Contents" t
)
286 (integer :tag
"TOC to level")))
288 (defcustom org-export-mark-todo-in-toc nil
289 "Non-nil means mark TOC lines that contain any open TODO items."
290 :group
'org-export-general
293 (defcustom org-export-with-todo-keywords t
294 "Non-nil means include TODO keywords in export.
295 When nil, remove all these keywords from the export."
296 :group
'org-export-general
299 (defcustom org-export-with-priority nil
300 "Non-nil means include priority cookies in export.
301 When nil, remove priority cookies for export."
302 :group
'org-export-general
305 (defcustom org-export-preserve-breaks nil
306 "Non-nil means preserve all line breaks when exporting.
307 Normally, in HTML output paragraphs will be reformatted. In ASCII
308 export, line breaks will always be preserved, regardless of this variable.
310 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
311 :group
'org-export-general
314 (defcustom org-export-with-archived-trees
'headline
315 "Whether subtrees with the ARCHIVE tag should be exported.
316 This can have three different values
317 nil Do not export, pretend this tree is not present
318 t Do export the entire tree
319 headline Only export the headline, but skip the tree below it."
320 :group
'org-export-general
323 (const :tag
"not at all" nil
)
324 (const :tag
"headline only" 'headline
)
325 (const :tag
"entirely" t
)))
327 (defcustom org-export-author-info t
328 "Non-nil means insert author name and email into the exported file.
330 This option can also be set with the +OPTIONS line,
331 e.g. \"author:nil\"."
332 :group
'org-export-general
335 (defcustom org-export-email-info nil
336 "Non-nil means insert author name and email into the exported file.
338 This option can also be set with the +OPTIONS line,
340 :group
'org-export-general
343 (defcustom org-export-creator-info t
344 "Non-nil means the postamble should contain a creator sentence.
345 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
346 :group
'org-export-general
349 (defcustom org-export-time-stamp-file t
350 "Non-nil means insert a time stamp into the exported file.
351 The time stamp shows when the file was created.
353 This option can also be set with the +OPTIONS line,
354 e.g. \"timestamp:nil\"."
355 :group
'org-export-general
358 (defcustom org-export-with-timestamps t
359 "If nil, do not export time stamps and associated keywords."
360 :group
'org-export-general
363 (defcustom org-export-remove-timestamps-from-toc t
364 "If t, remove timestamps from the table of contents entries."
365 :group
'org-export-general
368 (defcustom org-export-with-tags
'not-in-toc
369 "If nil, do not export tags, just remove them from headlines.
370 If this is the symbol `not-in-toc', tags will be removed from table of
371 contents entries, but still be shown in the headlines of the document.
373 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
374 :group
'org-export-general
376 (const :tag
"Off" nil
)
377 (const :tag
"Not in TOC" not-in-toc
)
378 (const :tag
"On" t
)))
380 (defcustom org-export-with-drawers nil
381 "Non-nil means export with drawers like the property drawer.
382 When t, all drawers are exported. This may also be a list of
383 drawer names to export."
384 :group
'org-export-general
386 (const :tag
"All drawers" t
)
387 (const :tag
"None" nil
)
388 (repeat :tag
"Selected drawers"
389 (string :tag
"Drawer name"))))
391 (defvar org-export-first-hook nil
392 "Hook called as the first thing in each exporter.
393 Point will be still in the original buffer.
394 Good for general initialization")
396 (defvar org-export-preprocess-hook nil
397 "Hook for preprocessing an export buffer.
398 Pretty much the first thing when exporting is running this hook.
399 Point will be in a temporary buffer that contains a copy of
400 the original buffer, or of the section that is being exported.
401 All the other hooks in the org-export-preprocess... category
402 also work in that temporary buffer, already modified by various
403 stages of the processing.")
405 (defvar org-export-preprocess-after-include-files-hook nil
406 "Hook for preprocessing an export buffer.
407 This is run after the contents of included files have been inserted.")
409 (defvar org-export-preprocess-after-tree-selection-hook nil
410 "Hook for preprocessing an export buffer.
411 This is run after selection of trees to be exported has happened.
412 This selection includes tags-based selection, as well as removal
413 of commented and archived trees.")
415 (defvar org-export-preprocess-after-headline-targets-hook nil
416 "Hook for preprocessing export buffer.
417 This is run just after the headline targets have been defined and
418 the target-alist has been set up.")
420 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
421 "Hook for preprocessing an export buffer.
422 This is run just before backend-specific blocks get selected.")
424 (defvar org-export-preprocess-after-blockquote-hook nil
425 "Hook for preprocessing an export buffer.
426 This is run after blockquote/quote/verse/center have been marked
429 (defvar org-export-preprocess-after-radio-targets-hook nil
430 "Hook for preprocessing an export buffer.
431 This is run after radio target processing.")
433 (defvar org-export-preprocess-before-normalizing-links-hook nil
434 "Hook for preprocessing an export buffer.
435 This hook is run before links are normalized.")
437 (defvar org-export-preprocess-before-backend-specifics-hook nil
438 "Hook run before backend-specific functions are called during preprocessing.")
440 (defvar org-export-preprocess-final-hook nil
441 "Hook for preprocessing an export buffer.
442 This is run as the last thing in the preprocessing buffer, just before
443 returning the buffer string to the backend.")
445 (defgroup org-export-translation nil
446 "Options for translating special ascii sequences for the export backends."
447 :tag
"Org Export Translation"
450 (defcustom org-export-with-emphasize t
451 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
452 If the export target supports emphasizing text, the word will be
453 typeset in bold, italic, or underlined, respectively. Works only for
454 single words, but you can say: I *really* *mean* *this*.
455 Not all export backends support this.
457 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
458 :group
'org-export-translation
461 (defcustom org-export-with-footnotes t
462 "If nil, export [1] as a footnote marker.
463 Lines starting with [1] will be formatted as footnotes.
465 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
466 :group
'org-export-translation
469 (defcustom org-export-with-TeX-macros t
470 "Non-nil means interpret simple TeX-like macros when exporting.
471 For example, HTML export converts \\alpha to α and \\AA to Å.
472 Not only real TeX macros will work here, but the standard HTML entities
473 for math can be used as macro names as well. For a list of supported
474 names in HTML export, see the constant `org-entities' and the user option
476 Not all export backends support this.
478 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
479 :group
'org-export-translation
480 :group
'org-export-latex
483 (defcustom org-export-with-LaTeX-fragments t
484 "Non-nil means process LaTeX math fragments for HTML display.
485 When set, the exporter will find and process LaTeX environments if the
486 \\begin line is the first non-white thing on a line. It will also find
487 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
488 $$a=b$$ and \\=\\[ a=b \\] for display math.
490 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
494 nil Don't do anything.
495 verbatim Keep everything in verbatim
496 dvipng Process the LaTeX fragments to images.
497 This will also include processing of non-math environments.
498 t Do MathJax preprocessing if there is at least on math snippet,
499 and arrange for MathJax.js to be loaded.
501 The default is nil, because this option needs the `dvipng' program which
502 is not available on all systems."
503 :group
'org-export-translation
504 :group
'org-export-latex
506 (const :tag
"Do not process math in any way" nil
)
507 (const :tag
"Obsolete, use dvipng setting" t
)
508 (const :tag
"Use dvipng to make images" dvipng
)
509 (const :tag
"Use MathJax to display math" mathjax
)
510 (const :tag
"Leave math verbatim" verbatim
)))
512 (defcustom org-export-with-fixed-width t
513 "Non-nil means lines starting with \":\" will be in fixed width font.
514 This can be used to have pre-formatted text, fragments of code etc. For
516 : ;; Some Lisp examples
519 will be looking just like this in also HTML. See also the QUOTE keyword.
520 Not all export backends support this.
522 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
523 :group
'org-export-translation
526 (defgroup org-export-tables nil
527 "Options for exporting tables in Org-mode."
528 :tag
"Org Export Tables"
531 (defcustom org-export-with-tables t
532 "If non-nil, lines starting with \"|\" define a table.
535 | Name | Address | Birthday |
536 |-------------+----------+-----------|
537 | Arthur Dent | England | 29.2.2100 |
539 Not all export backends support this.
541 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
542 :group
'org-export-tables
545 (defcustom org-export-highlight-first-table-line t
546 "Non-nil means highlight the first table line.
547 In HTML export, this means use <th> instead of <td>.
548 In tables created with table.el, this applies to the first table line.
549 In Org-mode tables, all lines before the first horizontal separator
550 line will be formatted with <th> tags."
551 :group
'org-export-tables
554 (defcustom org-export-table-remove-special-lines t
555 "Remove special lines and marking characters in calculating tables.
556 This removes the special marking character column from tables that are set
557 up for spreadsheet calculations. It also removes the entire lines
558 marked with `!', `_', or `^'. The lines with `$' are kept, because
559 the values of constants may be useful to have."
560 :group
'org-export-tables
563 (defcustom org-export-prefer-native-exporter-for-tables nil
564 "Non-nil means always export tables created with table.el natively.
565 Natively means use the HTML code generator in table.el.
566 When nil, Org-mode's own HTML generator is used when possible (i.e. if
567 the table does not use row- or column-spanning). This has the
568 advantage, that the automatic HTML conversions for math symbols and
569 sub/superscripts can be applied. Org-mode's HTML generator is also
570 much faster. The LaTeX exporter always use the native exporter for
572 :group
'org-export-tables
576 (defgroup org-export-xml nil
577 "Options specific for XML export of Org-mode files."
578 :tag
"Org Export XML"
583 ;;; Variables, constants, and parameter plists
585 (defconst org-level-max
20)
587 (defvar org-export-current-backend nil
588 "During export, this will be bound to a symbol such as 'html,
589 'latex, 'docbook, 'ascii, etc, indicating which of the export
590 backends is in use. Otherwise it has the value nil. Users
591 should not attempt to change the value of this variable
592 directly, but it can be used in code to test whether export is
593 in progress, and if so, what the backend is.")
595 (defvar org-current-export-file nil
) ; dynamically scoped parameter
596 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
597 (defvar org-export-opt-plist nil
598 "Contains the current option plist.")
599 (defvar org-last-level nil
) ; dynamically scoped variable
600 (defvar org-min-level nil
) ; dynamically scoped variable
601 (defvar org-levels-open nil
) ; dynamically scoped parameter
603 (defconst org-export-plist-vars
604 '((:link-up nil org-export-html-link-up
)
605 (:link-home nil org-export-html-link-home
)
606 (:language nil org-export-default-language
)
607 (:keywords nil org-export-page-keywords
)
608 (:description nil org-export-page-description
)
609 (:customtime nil org-display-custom-times
)
610 (:headline-levels
"H" org-export-headline-levels
)
611 (:section-numbers
"num" org-export-with-section-numbers
)
612 (:section-number-format nil org-export-section-number-format
)
613 (:table-of-contents
"toc" org-export-with-toc
)
614 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
615 (:archived-trees nil org-export-with-archived-trees
)
616 (:emphasize
"*" org-export-with-emphasize
)
617 (:sub-superscript
"^" org-export-with-sub-superscripts
)
618 (:special-strings
"-" org-export-with-special-strings
)
619 (:footnotes
"f" org-export-with-footnotes
)
620 (:drawers
"d" org-export-with-drawers
)
621 (:tags
"tags" org-export-with-tags
)
622 (:todo-keywords
"todo" org-export-with-todo-keywords
)
623 (:priority
"pri" org-export-with-priority
)
624 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
625 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
626 (:latex-listings nil org-export-latex-listings
)
627 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
628 (:fixed-width
":" org-export-with-fixed-width
)
629 (:timestamps
"<" org-export-with-timestamps
)
630 (:author-info
"author" org-export-author-info
)
631 (:email-info
"email" org-export-email-info
)
632 (:creator-info
"creator" org-export-creator-info
)
633 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
634 (:tables
"|" org-export-with-tables
)
635 (:table-auto-headline nil org-export-highlight-first-table-line
)
636 (:style-include-default nil org-export-html-style-include-default
)
637 (:style-include-scripts nil org-export-html-style-include-scripts
)
638 (:style nil org-export-html-style
)
639 (:style-extra nil org-export-html-style-extra
)
640 (:agenda-style nil org-agenda-export-html-style
)
641 (:convert-org-links nil org-export-html-link-org-files-as-html
)
642 (:inline-images nil org-export-html-inline-images
)
643 (:html-extension nil org-export-html-extension
)
644 (:xml-declaration nil org-export-html-xml-declaration
)
645 (:html-table-tag nil org-export-html-table-tag
)
646 (:expand-quoted-html
"@" org-export-html-expand
)
647 (:timestamp nil org-export-html-with-timestamp
)
648 (:publishing-directory nil org-export-publishing-directory
)
649 (:html-preamble nil org-export-html-preamble
)
650 (:html-postamble nil org-export-html-postamble
)
651 (:author nil user-full-name
)
652 (:email nil user-mail-address
)
653 (:select-tags nil org-export-select-tags
)
654 (:exclude-tags nil org-export-exclude-tags
)
656 (:latex-image-options nil org-export-latex-image-default-option
))
657 "List of properties that represent export/publishing variables.
658 Each element is a list of 3 items:
659 1. The property that is used internally, and also for org-publish-project-alist
660 2. The string that can be used in the OPTION lines to set this option,
661 or nil if this option cannot be changed in this way
662 3. The customization variable that sets the default for this option."
665 (defun org-default-export-plist ()
666 "Return the property list with default settings for the export variables."
667 (let* ((infile (org-infile-export-plist))
668 (letbind (plist-get infile
:let-bind
))
669 (l org-export-plist-vars
) rtn e s v
)
670 (while (setq e
(pop l
))
673 ((assq s letbind
) (nth 1 (assq s letbind
)))
674 ((boundp s
) (symbol-value s
))
676 rtn
(cons (car e
) (cons v rtn
))))
679 (defvar org-export-inbuffer-options-extra nil
680 "List of additional in-buffer options that should be detected.
681 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
682 etc. Extensions can add to this list to get their options detected, and they
683 can then add a function to `org-export-options-filters' to process these
685 Each element in this list must be a list, with the in-buffer keyword as car,
686 and a property (a symbol) as the next element. All occurrences of the
687 keyword will be found, the values concatenated with a space character
688 in between, and the result stored in the export options property list.")
690 (defvar org-export-options-filters nil
691 "Functions to be called to finalize the export/publishing options.
692 All these options are stored in a property list, and each of the functions
693 in this hook gets a chance to modify this property list. Each function
694 must accept the property list as an argument, and must return the (possibly
697 ;; FIXME: should we fold case here?
698 (defun org-infile-export-plist ()
699 "Return the property list with file-local settings for export."
703 (goto-char (point-min))
704 (let ((re (org-make-options-regexp
706 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
708 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
709 "LATEX_HEADER" "LATEX_CLASS"
710 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
711 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
712 (mapcar 'car org-export-inbuffer-options-extra
))))
714 p key val text options mathjax a pr style
715 latex-header latex-class macros letbind
716 ext-setup-or-nil setup-contents
(start 0))
717 (while (or (and ext-setup-or-nil
718 (string-match re ext-setup-or-nil start
)
719 (setq start
(match-end 0)))
720 (and (setq ext-setup-or-nil nil start
0)
721 (re-search-forward re nil t
)))
722 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
723 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
725 ((setq a
(assoc key org-export-inbuffer-options-extra
))
727 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
728 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
729 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
730 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
731 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
732 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
733 ((string-equal key
"DESCRIPTION")
734 (setq p
(plist-put p
:description val
)))
735 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
736 ((string-equal key
"STYLE")
737 (setq style
(concat style
"\n" val
)))
738 ((string-equal key
"LATEX_HEADER")
739 (setq latex-header
(concat latex-header
"\n" val
)))
740 ((string-equal key
"LATEX_CLASS")
741 (setq latex-class val
))
742 ((string-equal key
"TEXT")
743 (setq text
(if text
(concat text
"\n" val
) val
)))
744 ((string-equal key
"OPTIONS")
745 (setq options
(concat val
" " options
)))
746 ((string-equal key
"MATHJAX")
747 (setq mathjax
(concat val
" " mathjax
)))
748 ((string-equal key
"BIND")
749 (push (read (concat "(" val
")")) letbind
))
750 ((string-equal key
"XSLT")
751 (setq p
(plist-put p
:xslt val
)))
752 ((string-equal key
"LINK_UP")
753 (setq p
(plist-put p
:link-up val
)))
754 ((string-equal key
"LINK_HOME")
755 (setq p
(plist-put p
:link-home val
)))
756 ((string-equal key
"EXPORT_SELECT_TAGS")
757 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
758 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
759 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
760 ((string-equal key
"MACRO")
762 ((equal key
"SETUPFILE")
763 (setq setup-contents
(org-file-contents
765 (org-remove-double-quotes
768 (if (not ext-setup-or-nil
)
769 (setq ext-setup-or-nil setup-contents start
0)
770 (setq ext-setup-or-nil
771 (concat (substring ext-setup-or-nil
0 start
)
772 "\n" setup-contents
"\n"
773 (substring ext-setup-or-nil start
)))))))
774 (setq p
(plist-put p
:text text
))
775 (when (and letbind
(org-export-confirm-letbind))
776 (setq p
(plist-put p
:let-bind letbind
)))
777 (when style
(setq p
(plist-put p
:style-extra style
)))
779 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
781 (setq p
(plist-put p
:latex-class latex-class
)))
783 (setq p
(org-export-add-options-to-plist p options
)))
785 (setq p
(plist-put p
:mathjax mathjax
)))
786 ;; Add macro definitions
787 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
788 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
789 (setq p
(plist-put p
:macro-property
"(eval (org-entry-get nil \"$1\" 'selective))"))
791 p
:macro-modification-time
792 (and (buffer-file-name)
793 (file-exists-p (buffer-file-name))
795 "(eval (format-time-string \"$1\" '"
796 (prin1-to-string (nth 5 (file-attributes
797 (buffer-file-name))))
799 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
800 (file-name-nondirectory
801 (buffer-file-name)))))
802 (while (setq val
(pop macros
))
803 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
806 (concat ":macro-" (downcase (match-string 1 val
))))
807 (org-export-interpolate-newlines (match-string 2 val
))))))
810 (defun org-export-interpolate-newlines (s)
811 (while (string-match "\\\\n" s
)
812 (setq s
(replace-match "\n" t t s
)))
815 (defvar org-export-allow-BIND-local nil
)
816 (defun org-export-confirm-letbind ()
817 "Can we use #+BIND values during export?
818 By default this will ask for confirmation by the user, to divert possible
821 ((not org-export-allow-BIND
) nil
)
822 ((eq org-export-allow-BIND t
) t
)
823 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
824 org-export-allow-BIND-local
)
825 (t (org-set-local 'org-export-allow-BIND-local
826 (yes-or-no-p "Allow BIND values in this buffer? ")))))
828 (defun org-install-letbind ()
829 "Install the values from #+BIND lines as local variables."
830 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
832 (while (setq pair
(pop letbind
))
833 (org-set-local (car pair
) (nth 1 pair
)))))
835 (defun org-export-add-options-to-plist (p options
)
836 "Parse an OPTIONS line and set values in the property list P."
839 (let ((op org-export-plist-vars
))
840 (while (setq o
(pop op
))
842 (string-match (concat "\\<" (regexp-quote (nth 1 o
))
843 ":\\([^ \t\n\r;,.]*\\)")
845 (setq p
(plist-put p
(car o
)
846 (car (read-from-string
847 (match-string 1 options
))))))))))
850 (defun org-export-add-subtree-options (p pos
)
851 "Add options in subtree at position POS to property list P."
854 (when (org-at-heading-p)
856 ;; This is actually read in `org-export-get-title-from-subtree'
857 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
858 ;; (setq p (plist-put p :title a)))
859 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
860 (setq p
(plist-put p
:text a
)))
861 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
862 (setq p
(plist-put p
:author a
)))
863 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
864 (setq p
(plist-put p
:date a
)))
865 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
866 (setq p
(org-export-add-options-to-plist p a
)))))
869 (defun org-export-directory (type plist
)
870 (let* ((val (plist-get plist
:publishing-directory
))
872 (or (cdr (assoc type val
)) ".")
876 (defun org-export-process-option-filters (plist)
877 (let ((functions org-export-options-filters
) f
)
878 (while (setq f
(pop functions
))
879 (setq plist
(funcall f plist
))))
883 (defun org-export (&optional arg
)
884 "Export dispatcher for Org-mode.
885 When `org-export-run-in-background' is non-nil, try to run the command
886 in the background. This will be done only for commands that write
887 to a file. For details see the docstring of `org-export-run-in-background'.
889 The prefix argument ARG will be passed to the exporter. However, if
890 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
891 that means to inverse the
892 value of `org-export-run-in-background'.
894 If `org-export-initial-scope' is set to 'subtree, try to export
895 the current subtree, otherwise try to export the whole buffer.
896 Pressing `1' will switch between these two options."
898 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
899 (subtree-p (or (org-region-active-p)
900 (eq org-export-initial-scope
'subtree
)))
901 (help "[t] insert the export option template
902 \[v] limit export to visible part of outline tree
903 \[1] switch buffer/subtree export
904 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
906 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
908 \[h] export as HTML [H] to temporary buffer [R] export region
909 \[b] export as HTML and open in browser
911 \[l] export as LaTeX [L] to temporary buffer
912 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
914 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
916 \[j] export as TaskJuggler [J] ... and open
918 \[m] export as Freemind mind map
920 \[g] export using Wes Hardaker's generic exporter
922 \[i] export current file as iCalendar file
923 \[I] export all agenda files as iCalendar files [c] ...as one combined file
925 \[F] publish current file [P] publish current project
926 \[X] publish a project... [E] publish every projects")
928 '((?t org-insert-export-options-template nil
)
929 (?v org-export-visible nil
)
930 (?a org-export-as-ascii t
)
931 (?A org-export-as-ascii-to-buffer t
)
932 (?n org-export-as-latin1 t
)
933 (?N org-export-as-latin1-to-buffer t
)
934 (?u org-export-as-utf8 t
)
935 (?U org-export-as-utf8-to-buffer t
)
936 (?h org-export-as-html t
)
937 (?b org-export-as-html-and-open t
)
938 (?H org-export-as-html-to-buffer nil
)
939 (?R org-export-region-as-html nil
)
940 (?x org-export-as-xoxo t
)
941 (?g org-export-generic t
)
942 (?D org-export-as-docbook t
)
943 (?V org-export-as-docbook-pdf-and-open t
)
944 (?j org-export-as-taskjuggler t
)
945 (?J org-export-as-taskjuggler-and-open t
)
946 (?m org-export-as-freemind t
)
947 (?l org-export-as-latex t
)
948 (?p org-export-as-pdf t
)
949 (?d org-export-as-pdf-and-open t
)
950 (?L org-export-as-latex-to-buffer nil
)
951 (?i org-export-icalendar-this-file t
)
952 (?I org-export-icalendar-all-agenda-files t
)
953 (?c org-export-icalendar-combine-agenda-files t
)
954 (?F org-publish-current-file t
)
955 (?P org-publish-current-project t
)
957 (?E org-publish-all t
)))
959 (cpos (point)) (cbuf (current-buffer)) bpos
)
961 (save-window-excursion
963 (message "Export subtree: ")
964 (message "Export buffer: "))
965 (delete-other-windows)
966 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
968 (org-fit-window-to-buffer (get-buffer-window
969 "*Org Export/Publishing Help*"))
970 (while (eq (setq r1
(read-char-exclusive)) ?
1)
973 (message "Export buffer: "))
976 (message "Export subtree: "))))
978 (let ((case-fold-search t
))
979 (if (re-search-backward
980 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
983 (org-back-to-heading t
)
986 (message "Select command (for subtree): ")
987 (setq r1
(read-char-exclusive)))
988 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
991 (and bpos
(goto-char bpos
))
992 (setq r2
(if (< r1
27) (+ r1
96) r1
))
993 (unless (setq ass
(assq r2 cmds
))
994 (error "No command associated with key %c" r1
))
995 (if (and bg
(nth 2 ass
)
996 (not (buffer-base-buffer))
997 (not (org-region-active-p)))
998 ;; execute in background
999 (let ((p (start-process
1000 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1002 (expand-file-name invocation-name invocation-directory
)
1005 "--eval" "(require 'org-exp)"
1006 "--eval" "(setq org-wait .2)"
1008 "-f" (symbol-name (nth 1 ass
)))))
1009 (set-process-sentinel p
'org-export-process-sentinel
)
1010 (message "Background process \"%s\": started" p
))
1011 ;; background processing not requested, or not possible
1012 (if subtree-p
(progn (org-mark-subtree) (activate-mark)))
1013 (call-interactively (nth 1 ass
))
1014 (when (and bpos
(get-buffer-window cbuf
))
1015 (let ((cw (selected-window)))
1016 (select-window (get-buffer-window cbuf
))
1019 (select-window cw
))))))
1021 (defun org-export-process-sentinel (process status
)
1022 (if (string-match "\n+\\'" status
)
1023 (setq status
(substring status
0 -
1)))
1024 (message "Background process \"%s\": %s" process status
))
1026 ;;; General functions for all backends
1028 (defvar org-export-target-aliases nil
1029 "Alist of targets with invisible aliases.")
1030 (defvar org-export-preferred-target-alist nil
1031 "Alist of section id's with preferred aliases.")
1032 (defvar org-export-id-target-alist nil
1033 "Alist of section id's with preferred aliases.")
1034 (defvar org-export-code-refs nil
1035 "Alist of code references and line numbers.")
1037 (defun org-export-preprocess-string (string &rest parameters
)
1038 "Cleanup STRING so that that the true exported has a more consistent source.
1039 This function takes STRING, which should be a buffer-string of an org-file
1040 to export. It then creates a temporary buffer where it does its job.
1041 The result is then again returned as a string, and the exporter works
1042 on this string to produce the exported version."
1044 (let* ((org-export-current-backend (plist-get parameters
:for-backend
))
1045 (archived-trees (plist-get parameters
:archived-trees
))
1046 (inhibit-read-only t
)
1047 (drawers org-drawers
)
1048 (outline-regexp "\\*+ ")
1049 (source-buffer (current-buffer))
1052 (setq org-export-target-aliases nil
1053 org-export-preferred-target-alist nil
1054 org-export-id-target-alist nil
1055 org-export-code-refs nil
)
1057 (with-current-buffer (get-buffer-create " org-mode-tmp")
1060 (setq case-fold-search t
)
1062 (let ((inhibit-read-only t
))
1063 (remove-text-properties (point-min) (point-max)
1066 ;; Remove license-to-kill stuff
1067 ;; The caller marks some stuff for killing, stuff that has been
1068 ;; used to create the page title, for example.
1069 (org-export-kill-licensed-text)
1071 (let ((org-inhibit-startup t
)) (org-mode))
1072 (setq case-fold-search t
)
1073 (org-clone-local-variables source-buffer
"^\\(org-\\|orgtbl-\\)")
1074 (org-install-letbind)
1077 (run-hooks 'org-export-preprocess-hook
)
1079 ;; Process the macros
1080 (org-export-preprocess-apply-macros)
1081 (run-hooks 'org-export-preprocess-after-macros-hook
)
1083 (untabify (point-min) (point-max))
1085 ;; Handle include files, and call a hook
1086 (org-export-handle-include-files-recurse)
1087 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1089 ;; Get rid of archived trees
1090 (org-export-remove-archived-trees archived-trees
)
1092 ;; Remove comment environment and comment subtrees
1093 (org-export-remove-comment-blocks-and-subtrees)
1095 ;; Get rid of excluded trees, and call a hook
1096 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1097 (plist-get parameters
:exclude-tags
))
1098 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1100 ;; Change lists ending. Other parts of export may insert blank
1101 ;; lines and lists' structure could be altered.
1102 (org-export-mark-list-end)
1104 ;; Export code blocks
1105 (org-export-blocks-preprocess)
1107 ;; Mark lists with properties
1108 (org-export-mark-list-properties)
1110 ;; Handle source code snippets
1111 (org-export-replace-src-segments-and-examples)
1113 ;; Protect short examples marked by a leading colon
1114 (org-export-protect-colon-examples)
1117 (org-export-convert-protected-spaces)
1119 ;; Normalize footnotes
1120 (when (plist-get parameters
:footnotes
)
1121 (org-footnote-normalize nil t
))
1123 ;; Find all headings and compute the targets for them
1124 (setq target-alist
(org-export-define-heading-targets target-alist
))
1126 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1128 ;; Find HTML special classes for headlines
1129 (org-export-remember-html-container-classes)
1131 ;; Get rid of drawers
1132 (org-export-remove-or-extract-drawers
1133 drawers
(plist-get parameters
:drawers
))
1135 ;; Get the correct stuff before the first headline
1136 (when (plist-get parameters
:skip-before-1st-heading
)
1137 (goto-char (point-min))
1138 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1139 (delete-region (point-min) (match-beginning 0))
1140 (goto-char (point-min))
1142 (when (plist-get parameters
:add-text
)
1143 (goto-char (point-min))
1144 (insert (plist-get parameters
:add-text
) "\n"))
1146 ;; Remove todo-keywords before exporting, if the user has requested so
1147 (org-export-remove-headline-metadata parameters
)
1149 ;; Find targets in comments and move them out of comments,
1150 ;; but mark them as targets that should be invisible
1151 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1153 ;; Select and protect backend specific stuff, throw away stuff
1154 ;; that is specific for other backends
1155 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1156 (org-export-select-backend-specific-text)
1158 ;; Protect quoted subtrees
1159 (org-export-protect-quoted-subtrees)
1161 ;; Remove clock lines
1162 (org-export-remove-clock-lines)
1164 ;; Protect verbatim elements
1165 (org-export-protect-verbatim)
1167 ;; Blockquotes, verse, and center
1168 (org-export-mark-blockquote-verse-center)
1169 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1171 ;; Remove timestamps, if the user has requested so
1172 (unless (plist-get parameters
:timestamps
)
1173 (org-export-remove-timestamps))
1175 ;; Attach captions to the correct object
1176 (setq target-alist
(org-export-attach-captions-and-attributes target-alist
))
1178 ;; Find matches for radio targets and turn them into internal links
1179 (org-export-mark-radio-links)
1180 (run-hooks 'org-export-preprocess-after-radio-targets-hook
)
1182 ;; Find all links that contain a newline and put them into a single line
1183 (org-export-concatenate-multiline-links)
1185 ;; Normalize links: Convert angle and plain links into bracket links
1186 ;; and expand link abbreviations
1187 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1188 (org-export-normalize-links)
1190 ;; Find all internal links. If they have a fuzzy match (i.e. not
1191 ;; a *dedicated* target match, let the link point to the
1192 ;; corresponding section.
1193 (org-export-target-internal-links target-alist
)
1195 ;; Find multiline emphasis and put them into single line
1196 (when (plist-get parameters
:emph-multiline
)
1197 (org-export-concatenate-multiline-emphasis))
1199 ;; Remove special table lines, and store alignment information
1200 (org-store-forced-table-alignment)
1201 (when org-export-table-remove-special-lines
1202 (org-export-remove-special-table-lines))
1205 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1207 ;; Backend-specific preprocessing
1208 (let* ((backend-name (symbol-name org-export-current-backend
))
1209 (f (intern (format "org-export-%s-preprocess" backend-name
))))
1210 (require (intern (concat "org-" backend-name
)) nil
)
1211 (funcall f parameters
))
1213 ;; Remove or replace comments
1214 (org-export-handle-comments (plist-get parameters
:comments
))
1216 ;; Remove #+TBLFM and #+TBLNAME lines
1217 (org-export-handle-table-metalines)
1219 ;; Run the final hook
1220 (run-hooks 'org-export-preprocess-final-hook
)
1222 (setq rtn
(buffer-string)))
1223 (kill-buffer " org-mode-tmp")
1226 (defun org-export-kill-licensed-text ()
1227 "Remove all text that is marked with a :org-license-to-kill property."
1229 (while (setq p
(text-property-any (point-min) (point-max)
1230 :org-license-to-kill t
))
1232 p
(or (next-single-property-change p
:org-license-to-kill
)
1235 (defvar org-export-define-heading-targets-headline-hook nil
1236 "Hook that is run when a headline was matched during target search.
1237 This is part of the preprocessing for export.")
1239 (defun org-export-define-heading-targets (target-alist)
1240 "Find all headings and define the targets for them.
1241 The new targets are added to TARGET-ALIST, which is also returned.
1242 Also find all ID and CUSTOM_ID properties and store them."
1243 (goto-char (point-min))
1244 (org-init-section-numbers)
1245 (let ((re (concat "^" org-outline-regexp
1247 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1248 level target last-section-target a id
)
1249 (while (re-search-forward re nil t
)
1250 (org-if-unprotected-at (match-beginning 0)
1253 (setq id
(org-match-string-no-properties 2))
1254 (push (cons id target
) target-alist
)
1255 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1257 (push (list last-section-target
)
1258 org-export-target-aliases
)
1259 (car org-export-target-aliases
))))
1260 (push (caar target-alist
) (cdr a
))
1261 (when (equal (match-string 1) "CUSTOM_ID")
1262 (if (not (assoc last-section-target
1263 org-export-preferred-target-alist
))
1264 (push (cons last-section-target id
)
1265 org-export-preferred-target-alist
)))
1266 (when (equal (match-string 1) "ID")
1267 (if (not (assoc last-section-target
1268 org-export-id-target-alist
))
1269 (push (cons last-section-target
(concat "ID-" id
))
1270 org-export-id-target-alist
))))
1271 (setq level
(org-reduced-level
1272 (save-excursion (goto-char (point-at-bol))
1273 (org-outline-level))))
1274 (setq target
(org-solidify-link-text
1275 (format "sec-%s" (replace-regexp-in-string
1277 (org-section-number level
)))))
1278 (setq last-section-target target
)
1279 (push (cons target target
) target-alist
)
1280 (add-text-properties
1281 (point-at-bol) (point-at-eol)
1282 (list 'target target
))
1283 (run-hooks 'org-export-define-heading-targets-headline-hook
)))))
1286 (defun org-export-handle-invisible-targets (target-alist)
1287 "Find targets in comments and move them out of comments.
1288 Mark them as invisible targets."
1290 (goto-char (point-min))
1291 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1292 ;; Check if the line before or after is a headline with a target
1293 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1294 (get-text-property (point-at-bol 2) 'target
)))
1296 ;; use the existing target in a neighboring line
1297 (setq tmp
(match-string 2))
1299 (and (looking-at "\n") (delete-char 1))
1300 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1302 (setq a
(or (assoc target org-export-target-aliases
)
1304 (push (list target
) org-export-target-aliases
)
1305 (car org-export-target-aliases
))))
1307 ;; Make an invisible target
1308 (replace-match "\\1(INVISIBLE)"))))
1311 (defun org-export-target-internal-links (target-alist)
1312 "Find all internal links and assign targets to them.
1313 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1314 let the link point to the corresponding section.
1315 This function also handles the id links, if they have a match in
1317 (goto-char (point-min))
1318 (while (re-search-forward org-bracket-link-regexp nil t
)
1319 (org-if-unprotected-at (1+ (match-beginning 0))
1320 (let* ((org-link-search-must-match-exact-headline t
)
1322 (desc (match-end 2))
1323 (link (org-link-unescape (match-string 1)))
1324 (slink (org-solidify-link-text link
))
1325 found props pos cref
1328 ((= (string-to-char link
) ?
#)
1329 ;; user wants exactly this link
1331 ((cdr (assoc slink target-alist
))
1332 (or (cdr (assoc (assoc slink target-alist
)
1333 org-export-preferred-target-alist
))
1334 (cdr (assoc slink target-alist
))))
1335 ((and (string-match "^id:" link
)
1336 (cdr (assoc (substring link
3) target-alist
))))
1337 ((string-match "^(\\(.*\\))$" link
)
1338 (setq cref
(match-string 1 link
))
1339 (concat "coderef:" cref
))
1340 ((string-match org-link-types-re link
) nil
)
1341 ((or (file-name-absolute-p link
)
1342 (string-match "^\\." link
))
1345 (let ((org-link-search-inhibit-query t
))
1347 (setq found
(condition-case nil
(org-link-search link
)
1350 (or (org-on-heading-p)
1351 (not (eq found
'dedicated
))))
1352 (or (get-text-property (point) 'target
)
1355 (1- (or (previous-single-property-change
1356 (point) 'target
) 0)))
1360 (goto-char (match-beginning 1))
1361 (setq props
(text-properties-at (point)))
1362 (delete-region (match-beginning 1) (match-end 1))
1365 (unless desc
(insert "][" link
))
1366 (add-text-properties pos
(point) props
))))))
1368 (defun org-export-remember-html-container-classes ()
1369 "Store the HTML_CONTAINER_CLASS properties in a text property."
1370 (goto-char (point-min))
1372 (while (re-search-forward
1373 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t
)
1374 (setq class
(match-string 1))
1376 (org-back-to-heading t
)
1377 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1379 (defvar org-export-format-drawer-function nil
1380 "Function to be called to format the contents of a drawer.
1381 The function must accept three parameters:
1382 NAME the drawer name, like \"PROPERTIES\"
1383 CONTENT the content of the drawer.
1384 You can check the export backend through `org-export-current-backend'.
1385 The function should return the text to be inserted into the buffer.
1386 If this is nil, `org-export-format-drawer' is used as a default.")
1388 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1389 "Remove drawers, or extract and format the content.
1390 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1391 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1392 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1393 EXP-DRAWERS will be removed."
1394 (goto-char (point-min))
1395 (let ((re (concat "^[ \t]*:\\("
1396 (mapconcat 'identity all-drawers
"\\|")
1398 name beg beg-content eol content
)
1399 (while (re-search-forward re nil t
)
1401 (setq name
(match-string 1))
1402 (setq beg
(match-beginning 0)
1403 beg-content
(1+ (point-at-eol))
1405 (if (not (and (re-search-forward
1406 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1409 (goto-char (match-beginning 0))
1410 (and (looking-at ".*\n?") (replace-match ""))
1411 (setq content
(buffer-substring beg-content
(point)))
1412 (delete-region beg
(point))
1413 (when (or (eq exp-drawers t
)
1414 (member name exp-drawers
))
1415 (setq content
(funcall (or org-export-format-drawer-function
1416 'org-export-format-drawer
)
1418 (insert content
)))))))
1420 (defun org-export-format-drawer (name content
)
1421 "Format the content of a drawer as a colon example."
1422 (if (string-match "[ \t]+\\'" content
)
1423 (setq content
(substring content
(match-beginning 0))))
1424 (while (string-match "\\`[ \t]*\n" content
)
1425 (setq content
(substring content
(match-end 0))))
1426 (setq content
(org-remove-indentation content
))
1427 (setq content
(concat ": " (mapconcat 'identity
1428 (org-split-string content
"\n")
1431 (setq content
(concat " : " (upcase name
) "\n" content
))
1432 (org-add-props content nil
'org-protected t
))
1434 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1435 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1436 Both arguments are lists of tags.
1437 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1439 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1441 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1442 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1445 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1449 (goto-char (point-min))
1450 (when (and select-tags
1452 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1453 ;; At least one tree is marked for export, this means
1454 ;; all the unmarked stuff needs to go.
1455 ;; Dig out the trees that should be exported
1456 (goto-char (point-min))
1457 (outline-next-heading)
1459 (put-text-property beg
(point-max) :org-delete t
)
1460 (while (re-search-forward re-sel nil t
)
1461 (when (org-on-heading-p)
1462 (org-back-to-heading)
1463 (remove-text-properties
1464 (max (1- (point)) (point-min))
1465 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1467 (while (and (org-up-heading-safe)
1468 (get-text-property (point) :org-delete
))
1469 (remove-text-properties (max (1- (point)) (point-min))
1470 (point-at-eol) '(:org-delete t
)))
1472 ;; Remove the trees explicitly marked for noexport
1474 (goto-char (point-min))
1475 (while (re-search-forward re-excl nil t
)
1476 (when (org-at-heading-p)
1477 (org-back-to-heading t
)
1479 (org-end-of-subtree t t
)
1480 (delete-region beg
(point))
1481 (when (featurep 'org-inlinetask
)
1482 (org-inlinetask-remove-END-maybe)))))
1483 ;; Remove everything that is now still marked for deletion
1484 (goto-char (point-min))
1485 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1486 (setq end
(or (next-single-property-change beg
:org-delete
)
1488 (delete-region beg end
))))
1490 (defun org-export-remove-archived-trees (export-archived-trees)
1491 "Remove archived trees.
1492 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1493 When it is t, the entire archived tree will be exported.
1494 When it is nil the entire tree including the headline will be removed
1496 (let ((re-archive (concat ":" org-archive-tag
":"))
1498 (when (not (eq export-archived-trees t
))
1499 (goto-char (point-min))
1500 (while (re-search-forward re-archive nil t
)
1501 (if (not (org-on-heading-p t
))
1502 (goto-char (point-at-eol))
1503 (beginning-of-line 1)
1504 (setq a
(if export-archived-trees
1505 (1+ (point-at-eol)) (point))
1506 b
(org-end-of-subtree t
))
1507 (if (> b a
) (delete-region a b
)))))))
1509 (defun org-export-remove-headline-metadata (opts)
1510 "Remove meta data from the headline, according to user options."
1511 (let ((re org-complex-heading-regexp
)
1512 (todo (plist-get opts
:todo-keywords
))
1513 (tags (plist-get opts
:tags
))
1514 (pri (plist-get opts
:priority
))
1516 (case-fold-search nil
)
1518 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1519 (when (or (not todo
) (not tags
) (not pri
))
1520 (goto-char (point-min))
1521 (while (re-search-forward re nil t
)
1523 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1525 (replace-match rpl t t
))))))
1527 (defun org-export-remove-timestamps ()
1528 "Remove timestamps and keywords for export."
1529 (goto-char (point-min))
1530 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1533 (unless (save-match-data (org-at-table-p))
1535 (beginning-of-line 1)
1536 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1537 (replace-match ""))))))
1539 (defun org-export-remove-clock-lines ()
1540 "Remove clock lines for export."
1541 (goto-char (point-min))
1542 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1543 (while (re-search-forward re nil t
)
1545 (replace-match "")))))
1547 (defun org-export-protect-quoted-subtrees ()
1548 "Mark quoted subtrees with the protection property."
1549 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1550 (goto-char (point-min))
1551 (while (re-search-forward re-quote nil t
)
1552 (goto-char (match-beginning 0))
1554 (add-text-properties (point) (org-end-of-subtree t
)
1555 '(org-protected t
)))))
1557 (defun org-export-convert-protected-spaces ()
1558 "Convert strings like \\____ to protected spaces in all backends."
1559 (goto-char (point-min))
1560 (while (re-search-forward "\\\\__+" nil t
)
1561 (org-if-unprotected-1
1565 ((eq org-export-current-backend
'latex
)
1566 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1567 ((eq org-export-current-backend
'html
)
1568 (org-add-props (match-string 0) nil
1569 'org-whitespace
(- (match-end 0) (match-beginning 0))))
1570 ;; ((eq org-export-current-backend 'docbook))
1571 ((eq org-export-current-backend
'ascii
)
1572 (org-add-props (match-string 0) '(org-whitespace t
)))
1573 (t (make-string (- (match-end 0) (match-beginning 0)) ?\
)))
1577 (defun org-export-protect-verbatim ()
1578 "Mark verbatim snippets with the protection property."
1579 (goto-char (point-min))
1580 (while (re-search-forward org-verbatim-re nil t
)
1582 (add-text-properties (match-beginning 4) (match-end 4)
1583 '(org-protected t org-verbatim-emph t
))
1584 (goto-char (1+ (match-end 4))))))
1586 (defun org-export-protect-colon-examples ()
1587 "Protect lines starting with a colon."
1588 (goto-char (point-min))
1589 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1590 (while (re-search-forward re nil t
)
1591 (beginning-of-line 1)
1593 (while (looking-at re
)
1595 (or (eobp) (forward-char 1)))
1596 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1597 '(org-protected t
)))))
1599 (defun org-export-select-backend-specific-text ()
1601 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1602 (html "HTML" "BEGIN_HTML" "END_HTML")
1603 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1604 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1605 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1606 (case-fold-search t
)
1607 fmt beg beg-content end end-content ind
)
1610 (setq fmt
(pop formatters
))
1611 ;; Handle #+backend: stuff
1612 (goto-char (point-min))
1613 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1614 ":[ \t]*\\(.*\\)") nil t
)
1615 (if (not (eq (car fmt
) org-export-current-backend
))
1616 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1617 (replace-match "\\1\\2" t
)
1618 (add-text-properties
1619 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1620 `(org-protected t original-indentation
,ind
))))
1621 ;; Delete #+attr_Backend: stuff of another backend. Those
1622 ;; matching the current backend will be taken care of by
1623 ;; `org-export-attach-captions-and-attributes'
1624 (goto-char (point-min))
1625 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt
)
1626 ":[ \t]*\\(.*\\)") nil t
)
1627 (setq ind
(org-get-indentation))
1628 (when (not (eq (car fmt
) org-export-current-backend
))
1629 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1630 ;; Handle #+begin_backend and #+end_backend stuff
1631 (goto-char (point-min))
1632 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt
) "\\>.*\n?")
1634 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1635 (setq ind
(save-excursion (goto-char beg
) (org-get-indentation)))
1636 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt
) "\\>.*\n?")
1638 (setq end
(match-end 0) end-content
(match-beginning 0))
1639 (if (eq (car fmt
) org-export-current-backend
)
1642 (add-text-properties
1643 beg-content end-content
1644 `(org-protected t original-indentation
,ind
))
1645 (delete-region (match-beginning 0) (match-end 0))
1648 (delete-region (point) (1+ (point-at-eol)))))
1649 ;; No, this is for a different backend, kill it
1650 (delete-region beg end
)))))))
1652 (defun org-export-mark-blockquote-verse-center ()
1653 "Mark block quote and verse environments with special cookies.
1654 These special cookies will later be interpreted by the backend."
1656 (let (type t1 ind beg end beg1 end1 content
)
1657 (goto-char (point-min))
1658 (while (re-search-forward
1659 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1661 (setq ind
(length (match-string 1))
1662 type
(downcase (match-string 3))
1663 t1
(if (equal type
"quote") "blockquote" type
))
1664 (setq beg
(match-beginning 0)
1665 beg1
(1+ (match-end 0)))
1666 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1667 (setq end1
(1- (match-beginning 0))
1668 end
(+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1669 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1670 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1672 "ORG-" (upcase t1
) "-END\n"))
1673 (delete-region beg end
)
1674 (insert (org-add-props content nil
'original-indentation ind
))))))
1676 (defun org-export-mark-list-end ()
1677 "Mark all list endings with a special string."
1678 (unless (eq org-export-current-backend
'ascii
)
1681 ;; For each type allowing list export, find every list, remove
1682 ;; ending regexp if needed, and insert org-list-end.
1683 (goto-char (point-min))
1684 (while (re-search-forward (org-item-beginning-re) nil t
)
1685 (when (eq (nth 2 (org-list-context)) e
)
1686 (let* ((struct (org-list-struct))
1687 (bottom (org-list-get-bottom-point struct
))
1688 (top (point-at-bol))
1689 (top-ind (org-list-get-ind top struct
)))
1691 (when (and (not (eq org-list-ending-method
'indent
))
1692 (looking-at org-list-end-re
))
1694 (unless (bolp) (insert "\n"))
1695 ;; As org-list-end is inserted at column 0, it would end
1696 ;; by indentation any list. It can be problematic when
1697 ;; there are lists within lists: the inner list end would
1698 ;; also become the outer list end. To avoid this, text
1699 ;; property `original-indentation' is added, as
1700 ;; `org-list-struct' pays attention to it when reading a
1702 (insert (org-add-props
1703 "ORG-LIST-END-MARKER\n"
1704 (list 'original-indentation top-ind
)))))))
1705 (cons nil org-list-export-context
))))
1707 (defun org-export-mark-list-properties ()
1708 "Mark list with special properties.
1709 These special properties will later be interpreted by the backend."
1712 ;; Mark a list with 3 properties: `list-item' which is
1713 ;; position at beginning of line, `list-struct' which is
1714 ;; list structure, and `list-prevs' which is the alist of
1715 ;; item and its predecessor. Leave point at list ending.
1717 (let* ((struct (org-list-struct))
1718 (top (org-list-get-top-point struct
))
1719 (bottom (org-list-get-bottom-point struct
))
1720 (prevs (org-list-prevs-alist struct
))
1722 ;; Get every item and ending position, without dups and
1723 ;; without bottom point of list.
1727 (unless (memq pos poi
)
1729 (unless (or (= end bottom
) (memq end poi
))
1732 (setq poi
(sort poi
'<))
1733 ;; For every point of interest, mark the whole line with
1734 ;; its position in list.
1738 (add-text-properties (point-at-bol) (point-at-eol)
1739 (list 'list-item
(point-at-bol)
1741 'list-prevs prevs
)))
1743 ;; Take care of bottom point. As babel may have inserted
1744 ;; a new list in buffer, list ending isn't always
1745 ;; marked. Now mark every list ending and add properties
1746 ;; useful to line processing exporters.
1748 (when (or (looking-at "^ORG-LIST-END-MARKER\n")
1749 (and (not (eq org-list-ending-method
'indent
))
1750 (looking-at org-list-end-re
)))
1752 (unless (bolp) (insert "\n"))
1754 (org-add-props "ORG-LIST-END-MARKER\n" (list 'list-item bottom
1756 'list-prevs prevs
)))
1757 ;; Following property is used by LaTeX exporter.
1758 (add-text-properties top
(point) (list 'list-context ctxt
)))))))
1759 ;; Mark lists except for backends not interpreting them.
1760 (unless (eq org-export-current-backend
'ascii
)
1761 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
1764 (goto-char (point-min))
1765 (while (re-search-forward (org-item-beginning-re) nil t
)
1766 (when (eq (nth 2 (org-list-context)) e
) (funcall mark-list e
))))
1767 (cons nil org-list-export-context
))))))
1769 (defun org-export-attach-captions-and-attributes (target-alist)
1770 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1771 If the next thing following is a table, add the text properties to the first
1772 table line. If it is a link, add it to the line containing the link."
1773 (goto-char (point-min))
1774 (remove-text-properties (point-min) (point-max)
1775 '(org-caption nil org-attributes nil
))
1776 (let ((case-fold-search t
)
1777 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1779 "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend
) ":[ \t]+\\(.*\\)"
1781 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1783 "^[ \t]*\\(|[^-]\\)"
1785 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1786 cap shortn attr label end
)
1787 (while (re-search-forward re nil t
)
1789 ;; there is a caption
1792 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1))))
1793 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap
)
1794 (setq shortn
(match-string 1 cap
)
1795 cap
(match-string 2 cap
)))
1796 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1797 ;; there is an attribute
1800 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2))))
1801 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1805 (setq label
(org-trim (match-string 3)))
1806 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1808 (setq end
(if (match-end 4)
1809 (let ((ee (org-table-end)))
1810 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1812 (add-text-properties (point-at-bol) end
1813 (list 'org-caption cap
1814 'org-caption-shortn shortn
1815 'org-attributes attr
1817 (if label
(push (cons label label
) target-alist
))
1819 (setq cap nil attr nil label nil
)))))
1822 (defun org-export-remove-comment-blocks-and-subtrees ()
1823 "Remove the comment environment, and also commented subtrees."
1824 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1826 ;; Remove comment environment
1827 (goto-char (point-min))
1828 (setq case-fold-search t
)
1829 (while (re-search-forward
1830 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t
)
1831 (replace-match "" t t
))
1832 ;; Remove subtrees that are commented
1833 (goto-char (point-min))
1834 (setq case-fold-search nil
)
1835 (while (re-search-forward re-commented nil t
)
1836 (goto-char (match-beginning 0))
1837 (delete-region (point) (org-end-of-subtree t
)))))
1839 (defun org-export-handle-comments (commentsp)
1840 "Remove comments, or convert to backend-specific format.
1841 COMMENTSP can be a format string for publishing comments.
1842 When it is nil, all comments will be removed."
1843 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1845 (goto-char (point-min))
1846 (while (or (looking-at re
)
1847 (re-search-forward re nil t
))
1848 (setq pos
(match-beginning 0))
1849 (if (get-text-property pos
'org-protected
)
1850 (goto-char (1+ pos
))
1852 (not (equal (char-before (match-end 1)) ?
+)))
1853 (progn (add-text-properties
1854 (match-beginning 0) (match-end 0) '(org-protected t
))
1855 (replace-match (format commentsp
(match-string 2)) t t
))
1856 (goto-char (1+ pos
))
1858 (goto-char (max (point-min) (1- pos
))))))))
1860 (defun org-export-handle-table-metalines ()
1861 "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
1862 (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
1864 (goto-char (point-min))
1865 (while (or (looking-at re
)
1866 (re-search-forward re nil t
))
1867 (setq pos
(match-beginning 0))
1868 (if (get-text-property (match-beginning 1) 'org-protected
)
1869 (goto-char (1+ pos
))
1870 (goto-char (1+ pos
))
1872 (goto-char (max (point-min) (1- pos
)))))))
1874 (defun org-export-mark-radio-links ()
1875 "Find all matches for radio targets and turn them into internal links."
1876 (let ((re-radio (and org-target-link-regexp
1877 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1878 (goto-char (point-min))
1880 (while (re-search-forward re-radio nil t
)
1883 (or (org-in-regexp org-bracket-link-regexp
)
1884 (org-in-regexp org-plain-link-re
)
1885 (org-in-regexp "<<[^<>]+>>")))
1887 (replace-match "\\1[[\\2]]")))))))
1889 (defun org-store-forced-table-alignment ()
1890 "Find table lines which force alignment, store the results in properties."
1891 (let (line cnt aligns
)
1892 (goto-char (point-min))
1893 (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t
)
1894 ;; OK, this looks like a table line with an alignment cookie
1896 (setq line
(buffer-substring (point-at-bol) (point-at-eol)))
1897 (when (and (org-at-table-p)
1898 (org-table-cookie-line-p line
))
1899 (setq cnt
0 aligns nil
)
1903 (if (string-match "\\`<\\([lrc]\\)" x
)
1904 (push (cons cnt
(downcase (match-string 1 x
))) aligns
)))
1905 (org-split-string line
"[ \t]*|[ \t]*"))
1906 (add-text-properties (org-table-begin) (org-table-end)
1907 (list 'org-forced-aligns aligns
))))
1908 (goto-char (point-at-eol)))))
1910 (defun org-export-remove-special-table-lines ()
1911 "Remove tables lines that are used for internal purposes.
1912 Also, store forcedalignment information found in such lines."
1913 (goto-char (point-min))
1914 (while (re-search-forward "^[ \t]*|" nil t
)
1915 (org-if-unprotected-at (1- (point))
1916 (beginning-of-line 1)
1917 (if (or (looking-at "[ \t]*| *[!_^] *|")
1923 (or (= (length f
) 0)
1925 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f
)))
1926 (org-split-string ;; FIXME, can't we do without splitting???
1927 (buffer-substring (point-at-bol) (point-at-eol))
1928 "[ \t]*|[ \t]*")))))
1929 (delete-region (max (point-min) (1- (point-at-bol)))
1933 (defun org-export-protect-sub-super (s)
1935 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
1936 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
1939 (defun org-export-normalize-links ()
1940 "Convert all links to bracket links, and expand link abbreviations."
1941 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1942 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1944 (goto-char (point-min))
1945 (while (re-search-forward re-plain-link nil t
)
1946 (unless (org-string-match-p
1947 "\\[\\[\\S-+:\\S-*?\\<"
1948 (buffer-substring (point-at-bol) (match-beginning 0)))
1949 (goto-char (1- (match-end 0)))
1950 (org-if-unprotected-at (1+ (match-beginning 0))
1951 (let* ((s (concat (match-string 1)
1952 "[[" (match-string 2) ":" (match-string 3)
1953 "][" (match-string 2) ":" (org-export-protect-sub-super
1956 ;; added 'org-link face to links
1957 (put-text-property 0 (length s
) 'face
'org-link s
)
1958 (replace-match s t t
)))))
1959 (goto-char (point-min))
1960 (while (re-search-forward re-angle-link nil t
)
1961 (goto-char (1- (match-end 0)))
1963 (let* ((s (concat (match-string 1)
1964 "[[" (match-string 2) ":" (match-string 3)
1965 "][" (match-string 2) ":" (org-export-protect-sub-super
1968 (put-text-property 0 (length s
) 'face
'org-link s
)
1969 (replace-match s t t
))))
1970 (goto-char (point-min))
1971 (while (re-search-forward org-bracket-link-regexp nil t
)
1972 (goto-char (1- (match-end 0)))
1973 (setq nodesc
(not (match-end 3)))
1975 (let* ((xx (save-match-data
1977 (org-link-expand-abbrev (match-string 1)))))
1979 "[[" (org-add-props (copy-sequence xx
)
1980 nil
'org-protected t
'org-no-description nodesc
)
1984 (concat "[" (copy-sequence xx
)
1987 (put-text-property 0 (length s
) 'face
'org-link s
)
1988 (replace-match s t t
))))))
1990 (defun org-export-concatenate-multiline-links ()
1991 "Find multi-line links and put it all into a single line.
1992 This is to make sure that the line-processing export backends
1993 can work correctly."
1994 (goto-char (point-min))
1995 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1996 (org-if-unprotected-at (match-beginning 1)
1997 (replace-match "\\1 \\3")
1998 (goto-char (match-beginning 0)))))
2000 (defun org-export-concatenate-multiline-emphasis ()
2001 "Find multi-line emphasis and put it all into a single line.
2002 This is to make sure that the line-processing export backends
2003 can work correctly."
2004 (goto-char (point-min))
2005 (while (re-search-forward org-emph-re nil t
)
2006 (if (and (not (= (char-after (match-beginning 3))
2007 (char-after (match-beginning 4))))
2008 (save-excursion (goto-char (match-beginning 0))
2010 (and (not (org-at-table-p))
2011 (not (org-at-heading-p))))))
2013 (subst-char-in-region (match-beginning 0) (match-end 0)
2015 (goto-char (1- (match-end 0))))
2016 (goto-char (1+ (match-beginning 0))))))
2018 (defun org-export-grab-title-from-buffer ()
2019 "Get a title for the current document, from looking at the buffer."
2020 (let ((inhibit-read-only t
))
2022 (goto-char (point-min))
2023 (let ((end (if (looking-at org-outline-regexp
)
2025 (save-excursion (outline-next-heading) (point)))))
2026 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2027 ;; Mark the line so that it will not be exported as normal text.
2029 (add-text-properties (match-beginning 0) (match-end 0)
2030 (list :org-license-to-kill t
)))
2031 ;; Return the title string
2032 (org-trim (match-string 0)))))))
2034 (defun org-export-get-title-from-subtree ()
2035 "Return subtree title and exclude it from export."
2036 (let ((rbeg (region-beginning)) (rend (region-end))
2037 (inhibit-read-only t
) title
)
2040 (when (and (org-at-heading-p)
2041 (>= (org-end-of-subtree t t
) rend
))
2042 ;; This is a subtree, we take the title from the first heading
2044 (looking-at org-todo-line-regexp
)
2045 (setq title
(match-string 3))
2047 (add-text-properties (point) (1+ (point-at-eol))
2048 (list :org-license-to-kill t
)))
2049 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2052 (defun org-solidify-link-text (s &optional alist
)
2053 "Take link text and make a safe target out of it."
2058 (org-split-string s
"[^a-zA-Z0-9_\\.-]+") "--"))
2059 (a (assoc rtn alist
)))
2062 (defun org-get-min-level (lines &optional offset
)
2063 "Get the minimum level in LINES."
2064 (let ((re "^\\(\\*+\\) ") l
)
2066 (while (setq l
(pop lines
))
2067 (if (string-match re l
)
2068 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2072 ;; Variable holding the vector with section numbers
2073 (defvar org-section-numbers
(make-vector org-level-max
0))
2075 (defun org-init-section-numbers ()
2076 "Initialize the vector for the section numbers."
2078 (numbers (nreverse (org-split-string "" "\\.")))
2079 (depth (1- (length org-section-numbers
)))
2080 (i depth
) number-string
)
2083 (aset org-section-numbers i
0)
2084 (setq number-string
(or (car numbers
) "0"))
2085 (if (string-match "\\`[A-Z]\\'" number-string
)
2086 (aset org-section-numbers i
2087 (- (string-to-char number-string
) ?A -
1))
2088 (aset org-section-numbers i
(string-to-number number-string
)))
2092 (defun org-section-number (&optional level
)
2093 "Return a string with the current section number.
2094 When LEVEL is non-nil, increase section numbers on that level."
2095 (let* ((depth (1- (length org-section-numbers
)))
2097 (fmts (car org-export-section-number-format
))
2098 (term (cdr org-export-section-number-format
))
2103 (aset org-section-numbers
2104 level
(1+ (aref org-section-numbers level
))))
2105 (setq idx
(1+ level
))
2106 (while (<= idx depth
)
2108 (aset org-section-numbers idx
0))
2109 (setq idx
(1+ idx
))))
2111 (while (<= idx depth
)
2112 (when (> (aref org-section-numbers idx
) 0)
2113 (setq fmt
(or (pop fmts
) fmt
)
2115 n
(aref org-section-numbers idx
)
2117 (concat string sep
(org-number-to-counter n ctype
))
2118 (concat string
".0"))
2120 (setq idx
(1+ idx
)))
2122 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2123 (setq string
(replace-match "" t nil string
)))
2124 (if (string-match "\\(\\.0\\)+\\'" string
)
2125 (setq string
(replace-match "" t nil string
))))
2126 (concat string term
)))
2128 (defun org-number-to-counter (n type
)
2129 "Concert number N to a string counter, according to TYPE.
2130 TYPE must be a string, any of:
2134 I upper case roman numeral
2135 i lower case roman numeral"
2137 ((equal type
"1") (number-to-string n
))
2138 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2139 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2140 ((equal type
"I") (org-number-to-roman n
))
2141 ((equal type
"i") (downcase (org-number-to-roman n
)))
2142 (t (error "Invalid counter type `%s'" type
))))
2144 (defun org-number-to-roman (n)
2145 "Convert integer N into a roman numeral."
2146 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2147 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2148 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2152 (number-to-string n
)
2154 (if (>= n
(caar roman
))
2155 (setq n
(- n
(caar roman
))
2156 res
(concat res
(cdar roman
)))
2162 (defun org-export-preprocess-apply-macros ()
2163 "Replace macro references."
2164 (goto-char (point-min))
2165 (let (sy val key args args2 s n
)
2166 (while (re-search-forward
2167 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2169 (unless (save-match-data
2171 (goto-char (point-at-bol))
2172 (looking-at "[ \t]*#\\+macro")))
2173 (setq key
(downcase (match-string 1))
2174 args
(match-string 3))
2175 (when (setq val
(or (plist-get org-export-opt-plist
2176 (intern (concat ":macro-" key
)))
2177 (plist-get org-export-opt-plist
2178 (intern (concat ":" key
)))))
2181 (setq args
(org-split-string args
",") args2 nil
)
2183 (while (string-match "\\\\\\'" (car args
))
2184 ;; repair bad splits
2185 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2188 (push (pop args
) args2
))
2189 (setq args
(mapcar 'org-trim
(nreverse args2
)))
2191 (while (string-match "\\$\\([0-9]+\\)" val s
)
2192 (setq s
(1+ (match-beginning 0))
2193 n
(string-to-number (match-string 1 val
)))
2194 (and (>= (length args
) n
)
2195 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2196 (when (string-match "\\`(eval\\>" val
)
2197 (setq val
(eval (read val
))))
2198 (if (and val
(not (stringp val
)))
2199 (setq val
(format "%s" val
))))
2201 (prog1 (replace-match val t t
)
2202 (goto-char (match-beginning 0)))))))))
2204 (defun org-export-apply-macros-in-string (s)
2205 "Apply the macros in string S."
2209 (org-export-preprocess-apply-macros)
2214 (defun org-export-handle-include-files ()
2215 "Include the contents of include files, with proper formatting."
2216 (let ((case-fold-search t
)
2217 params file markup lang start end prefix prefix1 switches all minlevel lines
)
2218 (goto-char (point-min))
2219 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2220 (setq params
(read (concat "(" (match-string 1) ")"))
2221 prefix
(org-get-and-remove-property 'params
:prefix
)
2222 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2223 minlevel
(org-get-and-remove-property 'params
:minlevel
)
2224 lines
(org-get-and-remove-property 'params
:lines
)
2225 file
(org-symname-or-string (pop params
))
2226 markup
(org-symname-or-string (pop params
))
2227 lang
(and (member markup
'("src" "SRC"))
2228 (org-symname-or-string (pop params
)))
2229 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" ")
2231 (delete-region (match-beginning 0) (match-end 0))
2233 (not (file-exists-p file
))
2234 (not (file-readable-p file
)))
2235 (insert (format "CANNOT INCLUDE FILE %s" file
))
2236 (setq all
(cons file all
))
2238 (if (equal (downcase markup
) "src")
2239 (setq start
(format "#+begin_src %s %s\n"
2240 (or lang
"fundamental")
2243 (setq start
(format "#+begin_%s %s\n" markup switches
)
2244 end
(format "#+end_%s" markup
))))
2245 (insert (or start
""))
2246 (insert (org-get-file-contents (expand-file-name file
)
2247 prefix prefix1 markup minlevel lines
))
2248 (or (bolp) (newline))
2249 (insert (or end
""))))
2252 (defun org-export-handle-include-files-recurse ()
2253 "Recursively include files aborting on circular inclusion."
2254 (let ((now (list org-current-export-file
)) all
)
2256 (setq all
(append now all
))
2257 (setq now
(org-export-handle-include-files))
2260 (mapcar (lambda (el) (when (member el all
) el
)) now
))))
2262 (error "Recursive #+INCLUDE: %S" intersection
))))))
2264 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel lines
)
2265 "Get the contents of FILE and return them as a string.
2266 If PREFIX is a string, prepend it to each line. If PREFIX1
2267 is a string, prepend it to the first line instead of PREFIX.
2268 If MARKUP, don't protect org-like lines, the exporter will
2269 take care of the block they are in. If LINES is a string
2270 specifying a range of lines, include only those lines ."
2271 (if (stringp markup
) (setq markup
(downcase markup
)))
2273 (insert-file-contents file
)
2275 (let* ((lines (split-string lines
"-"))
2276 (lbeg (string-to-number (car lines
)))
2277 (lend (string-to-number (cadr lines
)))
2278 (beg (if (zerop lbeg
) (point-min)
2279 (goto-char (point-min))
2280 (forward-line (1- lbeg
))
2282 (end (if (zerop lend
) (point-max)
2283 (goto-char (point-min))
2284 (forward-line (1- lend
))
2286 (narrow-to-region beg end
)))
2287 (when (or prefix prefix1
)
2288 (goto-char (point-min))
2290 (insert (or prefix1 prefix
))
2292 (beginning-of-line 2)))
2294 (when (member markup
'("src" "example"))
2295 (goto-char (point-min))
2296 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2297 (goto-char (match-beginning 0))
2301 (dotimes (lvl minlevel
)
2302 (org-map-region 'org-demote
(point-min) (point-max))))
2305 (defun org-get-and-remove-property (listvar prop
)
2306 "Check if the value of LISTVAR contains PROP as a property.
2307 If yes, return the value of that property (i.e. the element following
2308 in the list) and remove property and value from the list in LISTVAR."
2309 (let ((list (symbol-value listvar
)) m v
)
2310 (when (setq m
(member prop list
))
2312 (if (equal (car list
) prop
)
2313 (set listvar
(cddr list
))
2314 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2316 (set listvar list
)))
2319 (defun org-symname-or-string (s)
2321 (if s
(symbol-name s
) s
)
2324 ;;; Fontification and line numbers for code examples
2326 (defvar org-export-last-code-line-counter-value
0)
2328 (defun org-export-replace-src-segments-and-examples ()
2329 "Replace source code segments with special code for export."
2330 (setq org-export-last-code-line-counter-value
0)
2331 (let ((case-fold-search t
)
2332 lang code trans opts indent caption
)
2333 (goto-char (point-min))
2334 (while (re-search-forward
2335 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2338 (if (not (match-string 4))
2339 (error "Source block missing language specification: %s"
2340 (let* ((body (match-string 6))
2341 (nothing (message "body:%s" body
))
2342 (preview (or (and (string-match
2343 "^[ \t]*\\([^\n\r]*\\)" body
)
2344 (match-string 1 body
)) body
)))
2345 (if (> (length preview
) 35)
2346 (concat (substring preview
0 32) "...")
2349 (setq lang
(match-string 4)
2350 opts
(match-string 5)
2351 code
(match-string 6)
2352 indent
(length (match-string 2))
2353 caption
(get-text-property 0 'org-caption
(match-string 0))))
2355 opts
(match-string 9)
2356 code
(match-string 10)
2357 indent
(length (match-string 8))
2358 caption
(get-text-property 0 'org-caption
(match-string 0))))
2360 (setq trans
(org-export-format-source-code-or-example
2361 lang code opts indent caption
))
2362 (replace-match trans t t
))))
2364 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2365 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2366 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2367 (defvar org-export-latex-listings-w-names
) ;; defined in org-latex.el
2368 (defvar org-export-latex-minted-langs
) ;; defined in org-latex.el
2369 (defvar org-export-latex-custom-lang-environments
) ;; defined in org-latex.el
2370 (defvar org-export-latex-listings-options
) ;; defined in org-latex.el
2371 (defvar org-export-latex-minted-options
) ;; defined in org-latex.el
2373 (defun org-export-format-source-code-or-example
2374 (lang code
&optional opts indent caption
)
2375 "Format CODE from language LANG and return it formatted for export.
2376 If LANG is nil, do not add any fontification.
2377 OPTS contains formatting options, like `-n' for triggering numbering lines,
2378 and `+n' for continuing previous numbering.
2379 Code formatting according to language currently only works for HTML.
2380 Numbering lines works for all three major backends (html, latex, and ascii).
2381 INDENT was the original indentation of the block."
2383 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2384 (setq opts
(or opts
"")
2385 num
(string-match "[-+]n\\>" opts
)
2386 cont
(string-match "\\+n\\>" opts
)
2387 rpllbl
(string-match "-r\\>" opts
)
2388 keepp
(string-match "-k\\>" opts
)
2389 textareap
(string-match "-t\\>" opts
)
2390 preserve-indentp
(or org-src-preserve-indentation
2391 (string-match "-i\\>" opts
))
2392 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2393 (string-to-number (match-string 1 opts
))
2395 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2396 (string-to-number (match-string 1 opts
))
2397 (org-count-lines code
))
2398 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2399 (match-string 1 opts
)))
2400 (when (and textareap
(eq org-export-current-backend
'html
))
2401 ;; we cannot use numbering or highlighting.
2402 (setq num nil cont nil lang nil
))
2403 (if keepp
(setq rpllbl
'keep
))
2404 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2405 (when (string-match "^," rtn
)
2406 (setq rtn
(with-temp-buffer
2408 ;; Free up the protected lines
2409 (goto-char (point-min))
2410 (while (re-search-forward "^," nil t
)
2411 (if (or (equal lang
"org")
2413 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2417 ;; Now backend-specific coding
2420 ((eq org-export-current-backend
'docbook
)
2421 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2422 (concat "\n#+BEGIN_DOCBOOK\n"
2423 (org-add-props (concat "<programlisting><![CDATA["
2425 "]]></programlisting>\n")
2426 '(org-protected t org-example t
))
2428 ((eq org-export-current-backend
'html
)
2429 ;; We are exporting to HTML
2431 (if (featurep 'xemacs
)
2433 (require 'htmlize nil t
))
2434 (when (not (fboundp 'htmlize-region-for-paste
))
2435 ;; we do not have htmlize.el, or an old version of it
2438 "htmlize.el 1.34 or later is needed for source code formatting")))
2441 (let* ((lang-m (when lang
2442 (or (cdr (assoc lang org-src-lang-modes
))
2444 (mode (and lang-m
(intern
2446 (if (symbolp lang-m
)
2447 (symbol-name lang-m
)
2450 (org-inhibit-startup t
)
2451 (org-startup-folded nil
))
2455 (if (functionp mode
)
2458 (font-lock-fontify-buffer)
2460 (set-buffer-modified-p nil
)
2461 (org-export-htmlize-region-for-paste
2462 (point-min) (point-max))))
2463 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2468 "<div class=\"org-src-container\">"
2470 "<label class=\"org-src-name\">%s</label>"
2474 (format "<pre class=\"src src-%s\">\n" lang
)
2476 (if caption
"</div>" "")))))
2479 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2481 rtn
"</textarea>\n</p>\n"))
2484 (goto-char (point-min))
2485 (while (re-search-forward "[<>&]" nil t
)
2486 (replace-match (cdr (assq (char-before)
2487 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2489 (setq rtn
(buffer-string)))
2490 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2492 (setq rtn
(org-export-number-lines rtn
1 1 num cont rpllbl fmt
)))
2493 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2494 (setq rtn
(replace-match "\\1" t nil rtn
)))
2495 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t org-example t
)) "\n#+END_HTML\n\n"))
2496 ((eq org-export-current-backend
'latex
)
2497 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2502 ((and lang org-export-latex-listings
)
2503 (flet ((make-option-string
2505 (concat (first pair
)
2506 (if (> (length (second pair
)) 0)
2507 (concat "=" (second pair
))))))
2508 (let* ((lang-sym (intern lang
))
2509 (minted-p (eq org-export-latex-listings
'minted
))
2510 (listings-p (not minted-p
))
2516 (minted-p org-export-latex-minted-langs
)
2517 (listings-p org-export-latex-listings-langs
))))
2523 org-export-latex-custom-lang-environments
))))
2525 (when (and listings-p
(not custom-environment
))
2529 #'make-option-string
2530 (append org-export-latex-listings-options
2531 `(("language" ,backend-lang
))) ",")))
2532 (when (and caption org-export-latex-listings-w-names
)
2535 (replace-regexp-in-string "_" "\\\\_" caption
)))
2538 (format "\\begin{%s}\n%s\\end{%s}\n"
2539 custom-environment rtn custom-environment
))
2541 (format "\\begin{%s}\n%s\\end{%s}\n"
2542 "lstlisting" rtn
"lstlisting"))
2545 "\\begin{minted}[%s]{%s}\n%s\\end{minted}\n"
2546 (mapconcat #'make-option-string
2547 org-export-latex-minted-options
",")
2548 backend-lang rtn
)))))))
2549 (t (concat (car org-export-latex-verbatim-wrap
)
2550 rtn
(cdr org-export-latex-verbatim-wrap
))))
2551 '(org-protected t org-example t
))
2553 ((eq org-export-current-backend
'ascii
)
2554 ;; This is not HTML or LaTeX, so just make it an example.
2555 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2556 (concat caption
"\n"
2561 (lambda (l) (concat " " l
))
2562 (org-split-string rtn
"\n")
2565 '(org-protected t org-example t
))
2567 (org-add-props rtn nil
'original-indentation indent
))))
2569 (defun org-export-number-lines (text &optional skip1 skip2 number cont
2570 replace-labels label-format
)
2571 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2572 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2575 (goto-char (point-max))
2576 (skip-chars-backward " \t\n\r")
2577 (delete-region (point) (point-max))
2578 (beginning-of-line (- 1 skip2
))
2579 (let* ((last (org-current-line))
2580 (n org-export-last-code-line-counter-value
)
2581 (nmax (+ n
(- last skip1
)))
2582 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2585 ((eq org-export-current-backend
'html
) (format "<span class=\"linenr\">%s</span>"
2587 ((eq org-export-current-backend
'ascii
) fmt
)
2588 ((eq org-export-current-backend
'latex
) fmt
)
2589 ((eq org-export-current-backend
'docbook
) fmt
)
2591 (label-format (or label-format org-coderef-label-format
))
2592 (label-pre (if (string-match "%s" label-format
)
2593 (substring label-format
0 (match-beginning 0))
2595 (label-post (if (string-match "%s" label-format
)
2596 (substring label-format
(match-end 0))
2600 ".*?\\S-.*?\\([ \t]*\\("
2601 (regexp-quote label-pre
)
2602 "\\([-a-zA-Z0-9_ ]+\\)"
2603 (regexp-quote label-post
)
2607 (org-goto-line (1+ skip1
))
2608 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2610 (insert (format fm
(incf n
)))
2612 (when (looking-at lbl-re
)
2613 (setq ref
(match-string 3))
2614 (cond ((numberp replace-labels
)
2615 ;; remove labels; use numbers for references when lines
2616 ;; are numbered, use labels otherwise
2617 (delete-region (match-beginning 1) (match-end 1))
2618 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2619 ((eq replace-labels
'keep
)
2620 ;; don't remove labels; use numbers for references when
2621 ;; lines are numbered, use labels otherwise
2622 (goto-char (match-beginning 2))
2623 (delete-region (match-beginning 2) (match-end 2))
2624 (insert "(" ref
")")
2625 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2626 org-export-code-refs
))
2628 ;; don't remove labels and don't use numbers for
2630 (goto-char (match-beginning 2))
2631 (delete-region (match-beginning 2) (match-end 2))
2632 (insert "(" ref
")")
2633 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2634 (when (eq org-export-current-backend
'html
)
2636 (beginning-of-line 1)
2637 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2640 (insert "</span>")))))
2641 (setq org-export-last-code-line-counter-value n
)
2642 (goto-char (point-max))
2646 (defun org-search-todo-below (line lines level
)
2647 "Search the subtree below LINE for any TODO entries."
2648 (let ((rest (cdr (memq line lines
)))
2649 (re org-todo-line-regexp
)
2652 (while (setq line
(pop rest
))
2653 (if (string-match re line
)
2655 (setq lv
(- (match-end 1) (match-beginning 1))
2656 todo
(and (match-beginning 2)
2657 (not (member (match-string 2 line
)
2658 org-done-keywords
))))
2660 (if (<= lv level
) (throw 'exit nil
))
2661 (if todo
(throw 'exit t
))))))))
2664 (defun org-export-visible (type arg
)
2665 "Create a copy of the visible part of the current buffer, and export it.
2666 The copy is created in a temporary buffer and removed after use.
2667 TYPE is the final key (as a string) that also selects the export command in
2668 the \\<org-mode-map>\\[org-export] export dispatcher.
2669 As a special case, if the you type SPC at the prompt, the temporary
2670 org-mode file will not be removed but presented to you so that you can
2671 continue to use it. The prefix arg ARG is passed through to the exporting
2675 (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")
2676 (read-char-exclusive))
2677 current-prefix-arg
))
2678 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L
)))
2679 (error "Invalid export key"))
2680 (let* ((binding (cdr (assoc type
2682 (?a . org-export-as-ascii
)
2683 (?A . org-export-as-ascii-to-buffer
)
2684 (?n . org-export-as-latin1
)
2685 (?N . org-export-as-latin1-to-buffer
)
2686 (?u . org-export-as-utf8
)
2687 (?U . org-export-as-utf8-to-buffer
)
2688 (?\C-a . org-export-as-ascii
)
2689 (?b . org-export-as-html-and-open
)
2690 (?\C-b . org-export-as-html-and-open
)
2691 (?h . org-export-as-html
)
2692 (?H . org-export-as-html-to-buffer
)
2693 (?R . org-export-region-as-html
)
2694 (?D . org-export-as-docbook
)
2696 (?l . org-export-as-latex
)
2697 (?p . org-export-as-pdf
)
2698 (?d . org-export-as-pdf-and-open
)
2699 (?L . org-export-as-latex-to-buffer
)
2701 (?x . org-export-as-xoxo
)))))
2702 (keepp (equal type ?\
))
2703 (file buffer-file-name
)
2704 (buffer (get-buffer-create "*Org Export Visible*"))
2706 ;; Need to hack the drawers here.
2708 (goto-char (point-min))
2709 (while (re-search-forward org-drawer-regexp nil t
)
2710 (goto-char (match-beginning 1))
2711 (or (outline-invisible-p) (org-flag-drawer nil
))))
2712 (with-current-buffer buffer
(erase-buffer))
2714 (setq s
(goto-char (point-min)))
2715 (while (not (= (point) (point-max)))
2716 (goto-char (org-find-invisible))
2717 (append-to-buffer buffer s
(point))
2718 (setq s
(goto-char (org-find-visible))))
2719 (org-cycle-hide-drawers 'all
)
2720 (goto-char (point-min))
2722 ;; Copy all comment lines to the end, to make sure #+ settings are
2723 ;; still available for the second export step. Kind of a hack, but
2724 ;; does do the trick.
2725 (if (looking-at "#[^\r\n]*")
2726 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2727 (when (re-search-forward "^\\*+[ \t]+" nil t
)
2728 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t
)
2729 (append-to-buffer buffer
(1+ (match-beginning 0))
2730 (min (point-max) (1+ (match-end 0)))))))
2732 (let ((buffer-file-name file
)
2733 (org-inhibit-startup t
))
2736 (unless keepp
(funcall binding arg
))))
2738 (kill-buffer buffer
)
2739 (switch-to-buffer-other-window buffer
)
2740 (goto-char (point-min)))))
2742 (defun org-find-visible ()
2744 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2745 (get-char-property s
'invisible
)))
2747 (defun org-find-invisible ()
2749 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2750 (not (get-char-property s
'invisible
))))
2753 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2755 (defun org-export-string (string fmt
&optional dir
)
2756 "Export STRING to FMT using existing export facilities.
2757 During export STRING is saved to a temporary file whose location
2758 could vary. Optional argument DIR can be used to force the
2759 directory in which the temporary file is created during export
2760 which can be useful for resolving relative paths. Dir defaults
2761 to the value of `temporary-file-directory'."
2762 (let ((temporary-file-directory (or dir temporary-file-directory
))
2763 (tmp-file (make-temp-file "org-")))
2767 (write-file tmp-file
)
2768 (org-load-modules-maybe)
2769 (unless org-local-vars
2770 (setq org-local-vars
(org-get-local-variables)))
2771 (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
2772 (list 'let org-local-vars
2773 (list (intern (format "org-export-as-%s" fmt
))
2774 nil nil nil
''string t
))))
2775 (delete-file tmp-file
))))
2778 (defun org-export-as-org (arg &optional hidden ext-plist
2779 to-buffer body-only pub-dir
)
2780 "Make a copy with not-exporting stuff removed.
2781 The purpose of this function is to provide a way to export the source
2782 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2783 stuff removed. This command will remove the following:
2785 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2786 - comment blocks and trees starting with the COMMENT keyword
2787 - only trees that are consistent with `org-export-select-tags'
2788 and `org-export-exclude-tags'.
2790 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2791 all the others will be ignored (but are present so that the general
2792 mechanism to call publishing functions will work).
2794 EXT-PLIST is a property list with external parameters overriding
2795 org-mode's default settings, but still inferior to file-local
2796 settings. When PUB-DIR is set, use this as the publishing
2799 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2801 (org-infile-export-plist)))
2802 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2803 (filename (concat (file-name-as-directory
2805 (org-export-directory :org opt-plist
)))
2806 (file-name-sans-extension
2807 (file-name-nondirectory bfname
))
2809 (filename (and filename
2810 (if (equal (file-truename filename
)
2811 (file-truename bfname
))
2812 (concat (file-name-sans-extension filename
)
2814 (file-name-extension filename
))
2816 (backup-inhibited t
)
2817 (buffer (find-file-noselect filename
))
2818 (region (buffer-string))
2821 (switch-to-buffer buffer
)
2824 (let ((org-inhibit-startup t
)) (org-mode))
2825 (org-install-letbind)
2827 ;; Get rid of archived trees
2828 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2830 ;; Remove comment environment and comment subtrees
2831 (org-export-remove-comment-blocks-and-subtrees)
2833 ;; Get rid of excluded trees
2834 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2835 (plist-get opt-plist
:exclude-tags
))
2837 (when (or (plist-get opt-plist
:plain-source
)
2838 (not (or (plist-get opt-plist
:plain-source
)
2839 (plist-get opt-plist
:htmlized-source
))))
2840 ;; Either nothing special is requested (default call)
2841 ;; or the plain source is explicitly requested
2844 (when (plist-get opt-plist
:htmlized-source
)
2845 ;; Make the htmlized version
2848 (font-lock-fontify-buffer)
2849 (let* ((htmlize-output-type 'css
)
2850 (newbuf (htmlize-buffer)))
2851 (with-current-buffer newbuf
2852 (when org-export-htmlized-org-css-url
2853 (goto-char (point-min))
2854 (and (re-search-forward
2855 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2859 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2860 org-export-htmlized-org-css-url
)
2862 (write-file (concat filename
".html")))
2863 (kill-buffer newbuf
)))
2864 (set-buffer-modified-p nil
)
2865 (if (equal to-buffer
'string
)
2866 (progn (setq str-ret
(buffer-string))
2867 (kill-buffer (current-buffer))
2869 (kill-buffer (current-buffer))))))
2871 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2872 (defun org-get-current-options ()
2873 "Return a string with current options as keyword options.
2874 Does include HTML export options as well as TODO and CATEGORY stuff."
2875 (require 'org-archive
)
2884 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2885 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2887 #+EXPORT_SELECT_TAGS: %s
2888 #+EXPORT_EXCLUDE_TAGS: %s
2895 #+PRIORITIES: %c %c %c
2897 #+STARTUP: %s %s %s %s %s
2903 (buffer-name) (user-full-name) user-mail-address
2904 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2905 org-export-default-language
2906 org-export-headline-levels
2907 org-export-with-section-numbers
2909 org-export-preserve-breaks
2910 org-export-html-expand
2911 org-export-with-fixed-width
2912 org-export-with-tables
2913 org-export-with-sub-superscripts
2914 org-export-with-special-strings
2915 org-export-with-footnotes
2916 org-export-with-emphasize
2917 org-export-with-timestamps
2918 org-export-with-TeX-macros
2919 org-export-with-LaTeX-fragments
2920 org-export-skip-text-before-1st-heading
2921 org-export-with-drawers
2922 org-export-with-todo-keywords
2923 org-export-with-priority
2924 org-export-with-tags
2925 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2926 (mapconcat 'identity org-export-select-tags
" ")
2927 (mapconcat 'identity org-export-exclude-tags
" ")
2928 org-export-html-link-up
2929 org-export-html-link-home
2931 (file-name-sans-extension
2932 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2934 "TODO FEEDBACK VERIFY DONE"
2935 "Me Jason Marie DONE"
2936 org-highest-priority org-lowest-priority org-default-priority
2937 (mapconcat 'identity org-drawers
" ")
2938 (cdr (assoc org-startup-folded
2939 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2940 (if org-odd-levels-only
"odd" "oddeven")
2941 (if org-hide-leading-stars
"hidestars" "showstars")
2942 (if org-startup-align-all-tables
"align" "noalign")
2943 (cond ((eq org-log-done t
) "logdone")
2944 ((equal org-log-done
'note
) "lognotedone")
2945 ((not org-log-done
) "nologdone"))
2946 (or (mapconcat (lambda (x)
2948 ((equal :startgroup
(car x
)) "{")
2949 ((equal :endgroup
(car x
)) "}")
2950 ((equal :newline
(car x
)) "")
2951 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2953 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2954 (mapconcat 'identity org-file-tags
" ")
2955 org-archive-location
2956 "org file:~/org/%s.org"
2960 (defun org-insert-export-options-template ()
2961 "Insert into the buffer a template with information for exporting."
2963 (if (not (bolp)) (newline))
2964 (let ((s (org-get-current-options)))
2965 (and (string-match "#\\+CATEGORY" s
)
2966 (setq s
(substring s
0 (match-beginning 0))))
2969 (defvar org-table-colgroup-info nil
)
2971 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2972 "Check if the table has a marking column.
2973 If yes remove the column and the special lines."
2974 (setq org-table-colgroup-info nil
)
2977 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2980 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2981 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2984 ;; No special marking column
2986 (setq org-table-clean-did-remove-column nil
)
2991 ((org-table-colgroup-line-p x
)
2992 ;; This line contains colgroup info, extract it
2993 ;; and then discard the line
2994 (setq org-table-colgroup-info
2996 (cond ((member x
'("<" "<")) :start
)
2997 ((member x
'(">" ">")) :end
)
2998 ((member x
'("<>" "<>")) :startend
)
3000 (org-split-string x
"[ \t]*|[ \t]*")))
3002 ((org-table-cookie-line-p x
)
3003 ;; This line contains formatting cookies, discard it
3007 ;; there is a special marking column
3008 (setq org-table-clean-did-remove-column t
)
3013 ((org-table-colgroup-line-p x
)
3014 ;; This line contains colgroup info, extract it
3015 ;; and then discard the line
3016 (setq org-table-colgroup-info
3018 (cond ((member x
'("<" "<")) :start
)
3019 ((member x
'(">" ">")) :end
)
3020 ((member x
'("<>" "<>")) :startend
)
3022 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3024 ((org-table-cookie-line-p x
)
3025 ;; This line contains formatting cookies, discard it
3027 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3030 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3031 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3032 ;; remove the first column
3033 (replace-match "\\1|" t nil x
))))
3036 (defun org-export-cleanup-toc-line (s)
3037 "Remove tags and timestamps from lines going into the toc."
3038 (when (memq org-export-with-tags
'(not-in-toc nil
))
3039 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s
)
3040 (setq s
(replace-match "" t t s
))))
3041 (when org-export-remove-timestamps-from-toc
3042 (while (string-match org-maybe-keyword-time-regexp s
)
3043 (setq s
(replace-match "" t t s
))))
3044 (while (string-match org-bracket-link-regexp s
)
3045 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3047 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
3048 (setq s
(replace-match "" t t s
)))
3052 (defun org-get-text-property-any (pos prop
&optional object
)
3053 (or (get-text-property pos prop object
)
3054 (and (setq pos
(next-single-property-change pos prop object
))
3055 (get-text-property pos prop object
))))
3057 (defun org-export-get-coderef-format (path desc
)
3059 (if (and desc
(string-match
3060 (regexp-quote (concat "(" path
")"))
3062 (replace-match "%s" t t desc
)
3065 (defun org-export-push-to-kill-ring (format)
3066 "Push buffer content to kill ring.
3067 The depends on the variable `org-export-copy-to-kill'."
3068 (when org-export-copy-to-kill-ring
3069 (org-kill-new (buffer-string))
3070 (when (fboundp 'x-set-selection
)
3071 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
3072 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
3073 (message "%s export done, pushed to kill ring and clipboard" format
)))
3077 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3079 ;;; org-exp.el ends here