1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31 (require 'org-exp-blocks
)
35 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
36 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
37 (declare-function org-export-html-preprocess
"org-html" (parameters))
38 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
39 (declare-function org-agenda-skip
"org-agenda" ())
40 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
41 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
42 (declare-function htmlize-buffer
"htmlize" (&optional buffer
))
43 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
44 (defgroup org-export nil
45 "Options for exporting org-listings."
49 (defgroup org-export-general nil
50 "General options for exporting Org-mode files."
51 :tag
"Org Export General"
55 (defvar org-export-publishing-directory nil
)
57 (defcustom org-export-show-temporary-export-buffer t
58 "Non-nil means, show buffer after exporting to temp buffer.
59 When Org exports to a file, the buffer visiting that file is ever
60 shown, but remains buried. However, when exporting to a temporary
61 buffer, that buffer is popped up in a second window. When this variable
62 is nil, the buffer remains buried also in these cases."
63 :group
'org-export-general
66 (defcustom org-export-copy-to-kill-ring t
67 "Non-nil means, exported stuff will also be pushed onto the kill ring."
68 :group
'org-export-general
71 (defcustom org-export-run-in-background nil
72 "Non-nil means export and publishing commands will run in background.
73 This works by starting up a separate Emacs process visiting the same file
74 and doing the export from there.
75 Not all export commands are affected by this - only the ones which
76 actually write to a file, and that do not depend on the buffer state.
78 If this option is nil, you can still get background export by calling
79 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
81 If this option is t, the double prefix can be used to exceptionally
82 force an export command into the current process."
83 :group
'org-export-general
86 (defcustom org-export-select-tags
'("export")
87 "Tags that select a tree for export.
88 If any such tag is found in a buffer, all trees that do not carry one
89 of these tags will be deleted before export.
90 Inside trees that are selected like this, you can still deselect a
91 subtree by tagging it with one of the `org-export-exclude-tags'."
92 :group
'org-export-general
93 :type
'(repeat (string :tag
"Tag")))
95 (defcustom org-export-exclude-tags
'("noexport")
96 "Tags that exclude a tree from export.
97 All trees carrying any of these tags will be excluded from export.
98 This is without condition, so even subtrees inside that carry one of the
99 `org-export-select-tags' will be removed."
100 :group
'org-export-general
101 :type
'(repeat (string :tag
"Tag")))
103 ;; FIXME: rename, this is a general variable
104 (defcustom org-export-html-expand t
105 "Non-nil means, for HTML export, treat @<...> as HTML tag.
106 When nil, these tags will be exported as plain text and therefore
107 not be interpreted by a browser.
109 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
110 :group
'org-export-html
111 :group
'org-export-general
114 (defcustom org-export-with-special-strings t
115 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
116 When this option is turned on, these strings will be exported as:
119 -----+----------+--------
125 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
126 :group
'org-export-translation
129 (defcustom org-export-html-link-up
""
130 "Where should the \"UP\" link of exported HTML pages lead?"
131 :group
'org-export-html
132 :group
'org-export-general
133 :type
'(string :tag
"File or URL"))
135 (defcustom org-export-html-link-home
""
136 "Where should the \"HOME\" link of exported HTML pages lead?"
137 :group
'org-export-html
138 :group
'org-export-general
139 :type
'(string :tag
"File or URL"))
141 (defcustom org-export-language-setup
142 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
143 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
144 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
145 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
146 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
147 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
148 ("es" "Autor" "Fecha" "Índice" "Pies de página")
149 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
150 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
151 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
152 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
153 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
154 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
155 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
156 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
157 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
158 ("pl" "Autor" "Data" "Spis treści" "Przypis")
159 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
160 "Terms used in export text, translated to different languages.
161 Use the variable `org-export-default-language' to set the language,
162 or use the +OPTION lines for a per-file setting."
163 :group
'org-export-general
166 (string :tag
"HTML language tag")
167 (string :tag
"Author")
169 (string :tag
"Table of Contents")
170 (string :tag
"Footnotes"))))
172 (defcustom org-export-default-language
"en"
173 "The default language of HTML export, as a string.
174 This should have an association in `org-export-language-setup'."
175 :group
'org-export-general
178 (defvar org-export-page-description
""
179 "The page description, for the XHTML meta tag.
180 This is best set with the #+DESCRIPTION line in a file, it does not make
181 sense to set this globally.")
183 (defvar org-export-page-keywords
""
184 "The page description, for the XHTML meta tag.
185 This is best set with the #+KEYWORDS line in a file, it does not make
186 sense to set this globally.")
188 (defcustom org-export-skip-text-before-1st-heading nil
189 "Non-nil means, skip all text before the first headline when exporting.
190 When nil, that text is exported as well."
191 :group
'org-export-general
194 (defcustom org-export-headline-levels
3
195 "The last level which is still exported as a headline.
196 Inferior levels will produce itemize lists when exported.
197 Note that a numeric prefix argument to an exporter function overrides
200 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
201 :group
'org-export-general
204 (defcustom org-export-with-section-numbers t
205 "Non-nil means, add section numbers to headlines when exporting.
207 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
208 :group
'org-export-general
211 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
212 "Format of section numbers for export.
213 The variable has two components.
214 1. A list of lists, each indicating a counter type and a separator.
215 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
216 It causes causes numeric, alphabetic, or roman counters, respectively.
217 The separator is only used if another counter for a subsection is being
219 If there are more numbered section levels than entries in this lists,
220 then the last entry will be reused.
221 2. A terminator string that will be added after the entire
223 :group
'org-export-general
227 (string :tag
"Counter Type")
228 (string :tag
"Separator ")))
229 (string :tag
"Terminator")))
231 (defcustom org-export-with-toc t
232 "Non-nil means, create a table of contents in exported files.
233 The TOC contains headlines with levels up to`org-export-headline-levels'.
234 When an integer, include levels up to N in the toc, this may then be
235 different from `org-export-headline-levels', but it will not be allowed
236 to be larger than the number of headline levels.
237 When nil, no table of contents is made.
239 Headlines which contain any TODO items will be marked with \"(*)\" in
240 ASCII export, and with red color in HTML output, if the option
241 `org-export-mark-todo-in-toc' is set.
243 In HTML output, the TOC will be clickable.
245 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
247 :group
'org-export-general
249 (const :tag
"No Table of Contents" nil
)
250 (const :tag
"Full Table of Contents" t
)
251 (integer :tag
"TOC to level")))
253 (defcustom org-export-mark-todo-in-toc nil
254 "Non-nil means, mark TOC lines that contain any open TODO items."
255 :group
'org-export-general
258 (defcustom org-export-with-todo-keywords t
259 "Non-nil means, include TODO keywords in export.
260 When nil, remove all these keywords from the export."
261 :group
'org-export-general
264 (defcustom org-export-with-priority nil
265 "Non-nil means, include priority cookies in export.
266 When nil, remove priority cookies for export."
267 :group
'org-export-general
270 (defcustom org-export-preserve-breaks nil
271 "Non-nil means, preserve all line breaks when exporting.
272 Normally, in HTML output paragraphs will be reformatted. In ASCII
273 export, line breaks will always be preserved, regardless of this variable.
275 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
276 :group
'org-export-general
279 (defcustom org-export-with-archived-trees
'headline
280 "Whether subtrees with the ARCHIVE tag should be exported.
281 This can have three different values
282 nil Do not export, pretend this tree is not present
283 t Do export the entire tree
284 headline Only export the headline, but skip the tree below it."
285 :group
'org-export-general
288 (const :tag
"not at all" nil
)
289 (const :tag
"headline only" 'headline
)
290 (const :tag
"entirely" t
)))
292 (defcustom org-export-author-info t
293 "Non-nil means, insert author name and email into the exported file.
295 This option can also be set with the +OPTIONS line,
296 e.g. \"author-info:nil\"."
297 :group
'org-export-general
300 (defcustom org-export-creator-info t
301 "Non-nil means, the postamble should contain a creator sentence.
302 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
303 :group
'org-export-general
306 (defcustom org-export-time-stamp-file t
307 "Non-nil means, insert a time stamp into the exported file.
308 The time stamp shows when the file was created.
310 This option can also be set with the +OPTIONS line,
311 e.g. \"timestamp:nil\"."
312 :group
'org-export-general
315 (defcustom org-export-with-timestamps t
316 "If nil, do not export time stamps and associated keywords."
317 :group
'org-export-general
320 (defcustom org-export-remove-timestamps-from-toc t
321 "If nil, remove timestamps from the table of contents entries."
322 :group
'org-export-general
325 (defcustom org-export-with-tags
'not-in-toc
326 "If nil, do not export tags, just remove them from headlines.
327 If this is the symbol `not-in-toc', tags will be removed from table of
328 contents entries, but still be shown in the headlines of the document.
330 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
331 :group
'org-export-general
333 (const :tag
"Off" nil
)
334 (const :tag
"Not in TOC" not-in-toc
)
335 (const :tag
"On" t
)))
337 (defcustom org-export-with-drawers nil
338 "Non-nil means, export with drawers like the property drawer.
339 When t, all drawers are exported. This may also be a list of
340 drawer names to export."
341 :group
'org-export-general
343 (const :tag
"All drawers" t
)
344 (const :tag
"None" nil
)
345 (repeat :tag
"Selected drawers"
346 (string :tag
"Drawer name"))))
348 (defvar org-export-preprocess-hook nil
349 "Hook for preprocessing an export buffer.
350 Pretty much the first thing when exporting is running this hook.")
352 (defvar org-export-preprocess-after-include-files-hook nil
353 "Hook for preprocessing an export buffer.
354 This is run after the contents of included files have been inserted.")
356 (defvar org-export-preprocess-after-tree-selection-hook nil
357 "Hook for preprocessing an export buffer.
358 This is run after selection of trees to be exported has happened.
359 This selection includes tags-based selection, as well as removal
360 of commented and archived trees.")
362 (defvar org-export-preprocess-after-blockquote-hook nil
363 "Hook for preprocessing an export buffer.
364 This is run after blockquote/quote/verse/center have been marked
367 (defvar org-export-preprocess-before-backend-specifics-hook nil
368 "Hook run before backend-specific functions are called during preprocessing.")
370 (defvar org-export-preprocess-final-hook nil
371 "Hook for preprocessing an export buffer.
372 This is run as the last thing in the preprocessing buffer, just before
373 returning the buffer string to the backend.")
375 (defgroup org-export-translation nil
376 "Options for translating special ascii sequences for the export backends."
377 :tag
"Org Export Translation"
380 (defcustom org-export-with-emphasize t
381 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
382 If the export target supports emphasizing text, the word will be
383 typeset in bold, italic, or underlined, respectively. Works only for
384 single words, but you can say: I *really* *mean* *this*.
385 Not all export backends support this.
387 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
388 :group
'org-export-translation
391 (defcustom org-export-with-footnotes t
392 "If nil, export [1] as a footnote marker.
393 Lines starting with [1] will be formatted as footnotes.
395 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
396 :group
'org-export-translation
399 (defcustom org-export-with-sub-superscripts t
400 "Non-nil means, interpret \"_\" and \"^\" for export.
401 When this option is turned on, you can use TeX-like syntax for sub- and
402 superscripts. Several characters after \"_\" or \"^\" will be
403 considered as a single item - so grouping with {} is normally not
404 needed. For example, the following things will be parsed as single
405 sub- or superscripts.
407 10^24 or 10^tau several digits will be considered 1 item.
408 10^-12 or 10^-tau a leading sign with digits or a word
409 x^2-y^3 will be read as x^2 - y^3, because items are
410 terminated by almost any nonword/nondigit char.
411 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
413 Still, ambiguity is possible - so when in doubt use {} to enclose the
414 sub/superscript. If you set this variable to the symbol `{}',
415 the braces are *required* in order to trigger interpretations as
416 sub/superscript. This can be helpful in documents that need \"_\"
417 frequently in plain text.
419 Not all export backends support this, but HTML does.
421 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
422 :group
'org-export-translation
424 (const :tag
"Always interpret" t
)
425 (const :tag
"Only with braces" {})
426 (const :tag
"Never interpret" nil
)))
428 (defcustom org-export-with-TeX-macros t
429 "Non-nil means, interpret simple TeX-like macros when exporting.
430 For example, HTML export converts \\alpha to α and \\AA to Å.
431 Not only real TeX macros will work here, but the standard HTML entities
432 for math can be used as macro names as well. For a list of supported
433 names in HTML export, see the constant `org-html-entities'.
434 Not all export backends support this.
436 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
437 :group
'org-export-translation
438 :group
'org-export-latex
441 (defcustom org-export-with-LaTeX-fragments nil
442 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
443 When set, the exporter will find LaTeX environments if the \\begin line is
444 the first non-white thing on a line. It will also find the math delimiters
445 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
448 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
450 The default is nil, because this option needs the `dvipng' program which
451 is not available on all systems."
452 :group
'org-export-translation
453 :group
'org-export-latex
456 (defcustom org-export-with-fixed-width t
457 "Non-nil means, lines starting with \":\" will be in fixed width font.
458 This can be used to have pre-formatted text, fragments of code etc. For
460 : ;; Some Lisp examples
463 will be looking just like this in also HTML. See also the QUOTE keyword.
464 Not all export backends support this.
466 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
467 :group
'org-export-translation
470 (defcustom org-match-sexp-depth
3
471 "Number of stacked braces for sub/superscript matching.
472 This has to be set before loading org.el to be effective."
473 :group
'org-export-translation
476 (defgroup org-export-tables nil
477 "Options for exporting tables in Org-mode."
478 :tag
"Org Export Tables"
481 (defcustom org-export-with-tables t
482 "If non-nil, lines starting with \"|\" define a table.
485 | Name | Address | Birthday |
486 |-------------+----------+-----------|
487 | Arthur Dent | England | 29.2.2100 |
489 Not all export backends support this.
491 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
492 :group
'org-export-tables
495 (defcustom org-export-highlight-first-table-line t
496 "Non-nil means, highlight the first table line.
497 In HTML export, this means use <th> instead of <td>.
498 In tables created with table.el, this applies to the first table line.
499 In Org-mode tables, all lines before the first horizontal separator
500 line will be formatted with <th> tags."
501 :group
'org-export-tables
504 (defcustom org-export-table-remove-special-lines t
505 "Remove special lines and marking characters in calculating tables.
506 This removes the special marking character column from tables that are set
507 up for spreadsheet calculations. It also removes the entire lines
508 marked with `!', `_', or `^'. The lines with `$' are kept, because
509 the values of constants may be useful to have."
510 :group
'org-export-tables
513 (defcustom org-export-prefer-native-exporter-for-tables nil
514 "Non-nil means, always export tables created with table.el natively.
515 Natively means, use the HTML code generator in table.el.
516 When nil, Org-mode's own HTML generator is used when possible (i.e. if
517 the table does not use row- or column-spanning). This has the
518 advantage, that the automatic HTML conversions for math symbols and
519 sub/superscripts can be applied. Org-mode's HTML generator is also
521 :group
'org-export-tables
525 (defgroup org-export-xml nil
526 "Options specific for XML export of Org-mode files."
527 :tag
"Org Export XML"
532 ;;; Variables, constants, and parameter plists
534 (defconst org-level-max
20)
536 (defvar org-current-export-file nil
) ; dynamically scoped parameter
537 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
538 (defvar org-export-opt-plist nil
539 "Contains the current option plist.")
540 (defvar org-last-level nil
) ; dynamically scoped variable
541 (defvar org-min-level nil
) ; dynamically scoped variable
542 (defvar org-levels-open nil
) ; dynamically scoped parameter
544 (defconst org-export-plist-vars
545 '((:link-up nil org-export-html-link-up
)
546 (:link-home nil org-export-html-link-home
)
547 (:language nil org-export-default-language
)
548 (:keywords nil org-export-page-keywords
)
549 (:description nil org-export-page-description
)
550 (:customtime nil org-display-custom-times
)
551 (:headline-levels
"H" org-export-headline-levels
)
552 (:section-numbers
"num" org-export-with-section-numbers
)
553 (:section-number-format nil org-export-section-number-format
)
554 (:table-of-contents
"toc" org-export-with-toc
)
555 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
556 (:archived-trees nil org-export-with-archived-trees
)
557 (:emphasize
"*" org-export-with-emphasize
)
558 (:sub-superscript
"^" org-export-with-sub-superscripts
)
559 (:special-strings
"-" org-export-with-special-strings
)
560 (:footnotes
"f" org-export-with-footnotes
)
561 (:drawers
"d" org-export-with-drawers
)
562 (:tags
"tags" org-export-with-tags
)
563 (:todo-keywords
"todo" org-export-with-todo-keywords
)
564 (:priority
"pri" org-export-with-priority
)
565 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
566 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
567 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
568 (:fixed-width
":" org-export-with-fixed-width
)
569 (:timestamps
"<" org-export-with-timestamps
)
570 (:author-info
"author" org-export-author-info
)
571 (:creator-info
"creator" org-export-creator-info
)
572 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
573 (:tables
"|" org-export-with-tables
)
574 (:table-auto-headline nil org-export-highlight-first-table-line
)
575 (:style-include-default nil org-export-html-style-include-default
)
576 (:style-include-scripts nil org-export-html-style-include-scripts
)
577 (:style nil org-export-html-style
)
578 (:style-extra nil org-export-html-style-extra
)
579 (:agenda-style nil org-agenda-export-html-style
)
580 (:convert-org-links nil org-export-html-link-org-files-as-html
)
581 (:inline-images nil org-export-html-inline-images
)
582 (:html-extension nil org-export-html-extension
)
583 (:xml-declaration nil org-export-html-xml-declaration
)
584 (:html-table-tag nil org-export-html-table-tag
)
585 (:expand-quoted-html
"@" org-export-html-expand
)
586 (:timestamp nil org-export-html-with-timestamp
)
587 (:publishing-directory nil org-export-publishing-directory
)
588 (:preamble nil org-export-html-preamble
)
589 (:postamble nil org-export-html-postamble
)
590 (:auto-preamble nil org-export-html-auto-preamble
)
591 (:auto-postamble nil org-export-html-auto-postamble
)
592 (:author nil user-full-name
)
593 (:email nil user-mail-address
)
594 (:select-tags nil org-export-select-tags
)
595 (:exclude-tags nil org-export-exclude-tags
)
597 (:latex-image-options nil org-export-latex-image-default-option
))
598 "List of properties that represent export/publishing variables.
599 Each element is a list of 3 items:
600 1. The property that is used internally, and also for org-publish-project-alist
601 2. The string that can be used in the OPTION lines to set this option,
602 or nil if this option cannot be changed in this way
603 3. The customization variable that sets the default for this option."
606 (defun org-default-export-plist ()
607 "Return the property list with default settings for the export variables."
608 (let ((l org-export-plist-vars
) rtn e s v
)
609 (while (setq e
(pop l
))
611 v
(if (boundp s
) (symbol-value s
) nil
)
612 rtn
(cons (car e
) (cons v rtn
))))
615 (defvar org-export-inbuffer-options-extra nil
616 "List of additional in-buffer options that should be detected.
617 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
618 etc. Extensions can add to this list to get their options detected, and they
619 can then add a function to `org-export-options-filters' to process these
621 Each element in this list must be a list, with the in-buffer keyword as car,
622 and a property (a symbol) as the next element. All occurrences of the
623 keyword will be found, the values concatenated with a space character
624 in between, and the result stored in the export options property list.")
626 (defvar org-export-options-filters nil
627 "Functions to be called to finalize the export/publishing options.
628 All these options are stored in a property list, and each of the functions
629 in this hook gets a chance to modify this property list. Each function
630 must accept the property list as an argument, and must return the (possibly
633 ;; FIXME: should we fold case here?
634 (defun org-infile-export-plist ()
635 "Return the property list with file-local settings for export."
639 (goto-char (point-min))
640 (let ((re (org-make-options-regexp
642 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
643 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
644 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
645 "KEYWORDS" "DESCRIPTION" "MACRO")
646 (mapcar 'car org-export-inbuffer-options-extra
))))
647 p key val text options a pr style
649 ext-setup-or-nil setup-contents
(start 0))
650 (while (or (and ext-setup-or-nil
651 (string-match re ext-setup-or-nil start
)
652 (setq start
(match-end 0)))
653 (and (setq ext-setup-or-nil nil start
0)
654 (re-search-forward re nil t
)))
655 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
656 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
658 ((setq a
(assoc key org-export-inbuffer-options-extra
))
660 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
661 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
662 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
663 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
664 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
665 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
666 ((string-equal key
"DESCRIPTION")
667 (setq p
(plist-put p
:description val
)))
668 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
669 ((string-equal key
"STYLE")
670 (setq style
(concat style
"\n" val
)))
671 ((string-equal key
"LATEX_HEADER")
672 (setq latex-header
(concat latex-header
"\n" val
)))
673 ((string-equal key
"TEXT")
674 (setq text
(if text
(concat text
"\n" val
) val
)))
675 ((string-equal key
"OPTIONS")
676 (setq options
(concat val
" " options
)))
677 ((string-equal key
"LINK_UP")
678 (setq p
(plist-put p
:link-up val
)))
679 ((string-equal key
"LINK_HOME")
680 (setq p
(plist-put p
:link-home val
)))
681 ((string-equal key
"EXPORT_SELECT_TAGS")
682 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
683 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
684 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
685 ((string-equal key
"MACRO")
687 ((equal key
"SETUPFILE")
688 (setq setup-contents
(org-file-contents
690 (org-remove-double-quotes
693 (if (not ext-setup-or-nil
)
694 (setq ext-setup-or-nil setup-contents start
0)
695 (setq ext-setup-or-nil
696 (concat (substring ext-setup-or-nil
0 start
)
697 "\n" setup-contents
"\n"
698 (substring ext-setup-or-nil start
)))))))
699 (setq p
(plist-put p
:text text
))
700 (when style
(setq p
(plist-put p
:style-extra style
)))
702 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
704 (setq p
(org-export-add-options-to-plist p options
)))
705 ;; Add macro definitions
706 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
707 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
709 p
:macro-modification-time
710 (and (buffer-file-name)
711 (file-exists-p (buffer-file-name))
713 "(eval (format-time-string \"$1\" '"
714 (prin1-to-string (nth 5 (file-attributes
715 (buffer-file-name))))
717 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
718 (file-name-nondirectory
719 (buffer-file-name)))))
720 (while (setq val
(pop macros
))
721 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
724 (concat ":macro-" (downcase (match-string 1 val
))))
725 (match-string 2 val
)))))
728 (defun org-export-add-options-to-plist (p options
)
729 "Parse an OPTIONS line and set values in the property list P."
732 (let ((op org-export-plist-vars
))
733 (while (setq o
(pop op
))
735 (string-match (concat (regexp-quote (nth 1 o
))
736 ":\\([^ \t\n\r;,.]*\\)")
738 (setq p
(plist-put p
(car o
)
739 (car (read-from-string
740 (match-string 1 options
))))))))))
743 (defun org-export-add-subtree-options (p pos
)
744 "Add options in subtree at position POS to property list P."
747 (when (org-at-heading-p)
749 ;; This is actually read in `org-export-get-title-from-subtree'
750 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
751 ;; (setq p (plist-put p :title a)))
752 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
753 (setq p
(plist-put p
:text a
)))
754 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
755 (setq p
(plist-put p
:author a
)))
756 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
757 (setq p
(plist-put p
:date a
)))
758 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
759 (setq p
(org-export-add-options-to-plist p a
)))))
762 (defun org-export-directory (type plist
)
763 (let* ((val (plist-get plist
:publishing-directory
))
765 (or (cdr (assoc type val
)) ".")
769 (defun org-export-process-option-filters (plist)
770 (let ((functions org-export-options-filters
) f
)
771 (while (setq f
(pop functions
))
772 (setq plist
(funcall f plist
))))
776 (defun org-export (&optional arg
)
777 "Export dispatcher for Org-mode.
778 When `org-export-run-in-background' is non-nil, try to run the command
779 in the background. This will be done only for commands that write
780 to a file. For details see the docstring of `org-export-run-in-background'.
782 The prefix argument ARG will be passed to the exporter. However, if
783 ARG is a double universal prefix `C-u C-u', that means to inverse the
784 value of `org-export-run-in-background'."
786 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
787 (help "[t] insert the export option template
788 \[v] limit export to visible part of outline tree
790 \[a] export as ASCII [A] to temporary buffer
792 \[h] export as HTML [H] to temporary buffer [R] export region
793 \[b] export as HTML and open in browser
795 \[l] export as LaTeX [L] to temporary buffer
796 \[p] export as LaTeX and process to PDF
797 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
799 \[D] export as DocBook
800 \[V] export as DocBook, process to PDF, and open the resulting PDF document
803 \[g] export using Wes Hardaker's generic exporter
805 \[i] export current file as iCalendar file
806 \[I] export all agenda files as iCalendar files
807 \[c] export agenda files into combined iCalendar file
809 \[F] publish current file [P] publish current project
810 \[X] publish a project... [E] publish every projects")
812 '((?t org-insert-export-options-template nil
)
813 (?v org-export-visible nil
)
814 (?a org-export-as-ascii t
)
815 (?A org-export-as-ascii-to-buffer t
)
816 (?h org-export-as-html t
)
817 (?b org-export-as-html-and-open t
)
818 (?H org-export-as-html-to-buffer nil
)
819 (?R org-export-region-as-html nil
)
820 (?x org-export-as-xoxo t
)
821 (?g org-export-generic t
)
822 (?D org-export-as-docbook t
)
823 (?V org-export-as-docbook-pdf-and-open t
)
824 (?l org-export-as-latex t
)
825 (?p org-export-as-pdf t
)
826 (?d org-export-as-pdf-and-open t
)
827 (?L org-export-as-latex-to-buffer nil
)
828 (?i org-export-icalendar-this-file t
)
829 (?I org-export-icalendar-all-agenda-files t
)
830 (?c org-export-icalendar-combine-agenda-files t
)
831 (?F org-publish-current-file t
)
832 (?P org-publish-current-project t
)
834 (?E org-publish-all t
)))
837 (save-window-excursion
838 (delete-other-windows)
839 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
841 (org-fit-window-to-buffer (get-buffer-window
842 "*Org Export/Publishing Help*"))
843 (message "Select command: ")
844 (setq r1
(read-char-exclusive))))
845 (setq r2
(if (< r1
27) (+ r1
96) r1
))
846 (unless (setq ass
(assq r2 cmds
))
847 (error "No command associated with key %c" r1
))
848 (if (and bg
(nth 2 ass
)
849 (not (buffer-base-buffer))
850 (not (org-region-active-p)))
851 ;; execute in background
852 (let ((p (start-process
853 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
855 (expand-file-name invocation-name invocation-directory
)
858 "--eval" "(require 'org-exp)"
859 "--eval" "(setq org-wait .2)"
861 "-f" (symbol-name (nth 1 ass
)))))
862 (set-process-sentinel p
'org-export-process-sentinel
)
863 (message "Background process \"%s\": started" p
))
864 ;; background processing not requested, or not possible
865 (call-interactively (nth 1 ass
)))))
867 (defun org-export-process-sentinel (process status
)
868 (if (string-match "\n+\\'" status
)
869 (setq status
(substring status
0 -
1)))
870 (message "Background process \"%s\": %s" process status
))
872 (defconst org-html-entities
914 ("Aring") ("AA".
"Å")
1003 ("varepsilon".
"ε")
1016 ("sigmaf") ("varsigma".
"ς")
1024 ("thetasym") ("vartheta".
"ϑ")
1027 ("bull") ("bullet".
"•")
1028 ("hellip") ("dots".
"…")
1038 ("larr") ("leftarrow".
"←") ("gets".
"←")
1039 ("uarr") ("uparrow".
"↑")
1040 ("rarr") ("to".
"→") ("rightarrow".
"→")
1041 ("darr")("downarrow".
"↓")
1042 ("harr") ("leftrightarrow".
"↔")
1043 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1044 ("lArr") ("Leftarrow".
"⇐")
1045 ("uArr") ("Uparrow".
"⇑")
1046 ("rArr") ("Rightarrow".
"⇒")
1047 ("dArr") ("Downarrow".
"⇓")
1048 ("hArr") ("Leftrightarrow".
"⇔")
1050 ("part") ("partial".
"∂")
1051 ("exist") ("exists".
"∃")
1052 ("empty") ("emptyset".
"∅")
1054 ("isin") ("in".
"∈")
1060 ("lowast") ("ast".
"∗")
1062 ("prop") ("proptp".
"∝")
1063 ("infin") ("infty".
"∞")
1064 ("ang") ("angle".
"∠")
1065 ("and") ("wedge".
"∧")
1066 ("or") ("vee".
"∨")
1072 ("cong") ("simeq".
"≅")
1073 ("asymp")("approx".
"≈")
1074 ("ne") ("neq".
"≠")
1078 ("sub") ("subset".
"⊂")
1079 ("sup") ("supset".
"⊃")
1086 ("sdot") ("cdot".
"⋅")
1093 ("loz") ("Diamond".
"◊")
1094 ("spades") ("spadesuit".
"♠")
1095 ("clubs") ("clubsuit".
"♣")
1096 ("hearts") ("diamondsuit".
"♥")
1097 ("diams") ("diamondsuit".
"♦")
1098 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1165 "Entities for TeX->HTML translation.
1166 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1167 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1168 In that case, \"\\ent\" will be translated to \"&other;\".
1169 The list contains HTML entities for Latin-1, Greek and other symbols.
1170 It is supplemented by a number of commonly used TeX macros with appropriate
1171 translations. There is currently no way for users to extend this.")
1173 ;;; General functions for all backends
1175 (defvar org-export-target-aliases nil
1176 "Alist of targets with invisible aliases.")
1177 (defvar org-export-preferred-target-alist nil
1178 "Alist of section id's with preferred aliases.")
1179 (defvar org-export-code-refs nil
1180 "Alist of code references and line numbers")
1182 (defun org-export-preprocess-string (string &rest parameters
)
1183 "Cleanup STRING so that that the true exported has a more consistent source.
1184 This function takes STRING, which should be a buffer-string of an org-file
1185 to export. It then creates a temporary buffer where it does its job.
1186 The result is then again returned as a string, and the exporter works
1187 on this string to produce the exported version."
1189 (let* ((htmlp (plist-get parameters
:for-html
))
1190 (asciip (plist-get parameters
:for-ascii
))
1191 (latexp (plist-get parameters
:for-LaTeX
))
1192 (docbookp (plist-get parameters
:for-docbook
))
1193 (backend (cond (htmlp 'html
)
1196 (docbookp 'docbook
)))
1197 (archived-trees (plist-get parameters
:archived-trees
))
1198 (inhibit-read-only t
)
1199 (drawers org-drawers
)
1200 (outline-regexp "\\*+ ")
1203 (setq org-export-target-aliases nil
)
1204 (setq org-export-preferred-target-alist nil
)
1205 (setq org-export-code-refs nil
)
1207 (with-current-buffer (get-buffer-create " org-mode-tmp")
1210 (setq case-fold-search t
)
1212 ;; Remove license-to-kill stuff
1213 ;; The caller marks some stuff for killing, stuff that has been
1214 ;; used to create the page title, for example.
1215 (org-export-kill-licensed-text)
1217 (let ((org-inhibit-startup t
)) (org-mode))
1218 (setq case-fold-search t
)
1221 (run-hooks 'org-export-preprocess-hook
)
1223 ;; Process the macros
1224 (org-export-preprocess-apply-macros)
1225 (run-hooks 'org-export-preprocess-after-macros-hook
)
1227 (untabify (point-min) (point-max))
1229 ;; Handle include files, and call a hook
1230 (org-export-handle-include-files)
1231 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1233 ;; Get rid of archived trees
1234 (org-export-remove-archived-trees archived-trees
)
1236 ;; Remove comment environment and comment subtrees
1237 (org-export-remove-comment-blocks-and-subtrees)
1239 ;; Get rid of excluded trees, and call a hook
1240 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1241 (plist-get parameters
:exclude-tags
))
1242 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1244 ;; Handle source code snippets
1245 (org-export-replace-src-segments-and-examples backend
)
1247 ;; Protect short examples marked by a leading colon
1248 (org-export-protect-colon-examples)
1250 ;; Normalize footnotes
1251 (when (plist-get parameters
:footnotes
)
1252 (org-footnote-normalize nil t
))
1254 ;; Find all headings and compute the targets for them
1255 (setq target-alist
(org-export-define-heading-targets target-alist
))
1257 ;; Get rid of drawers
1258 (org-export-remove-or-extract-drawers drawers
1259 (plist-get parameters
:drawers
))
1261 ;; Get the correct stuff before the first headline
1262 (when (plist-get parameters
:skip-before-1st-heading
)
1263 (goto-char (point-min))
1264 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1265 (delete-region (point-min) (match-beginning 0))
1266 (goto-char (point-min))
1268 (when (plist-get parameters
:add-text
)
1269 (goto-char (point-min))
1270 (insert (plist-get parameters
:add-text
) "\n"))
1272 ;; Remove todo-keywords before exporting, if the user has requested so
1273 (org-export-remove-headline-metadata parameters
)
1275 ;; Find targets in comments and move them out of comments,
1276 ;; but mark them as targets that should be invisible
1277 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1279 ;; Select and protect backend specific stuff, throw away stuff
1280 ;; that is specific for other backends
1281 (org-export-select-backend-specific-text backend
)
1283 ;; Protect quoted subtrees
1284 (org-export-protect-quoted-subtrees)
1286 ;; Remove clock lines
1287 (org-export-remove-clock-lines)
1289 ;; Protect verbatim elements
1290 (org-export-protect-verbatim)
1292 ;; Blockquotes, verse, and center
1293 (org-export-mark-blockquote-verse-center)
1294 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1296 ;; Remove timestamps, if the user has requested so
1297 (unless (plist-get parameters
:timestamps
)
1298 (org-export-remove-timestamps))
1300 ;; Attach captions to the correct object
1301 (setq target-alist
(org-export-attach-captions-and-attributes
1302 backend target-alist
))
1304 ;; Find matches for radio targets and turn them into internal links
1305 (org-export-mark-radio-links)
1307 ;; Find all links that contain a newline and put them into a single line
1308 (org-export-concatenate-multiline-links)
1310 ;; Normalize links: Convert angle and plain links into bracket links
1311 ;; and expand link abbreviations
1312 (org-export-normalize-links)
1314 ;; Find all internal links. If they have a fuzzy match (i.e. not
1315 ;; a *dedicated* target match, let the link point to the
1316 ;; corresponding section.
1317 (org-export-target-internal-links target-alist
)
1319 ;; Find multiline emphasis and put them into single line
1320 (when (plist-get parameters
:emph-multiline
)
1321 (org-export-concatenate-multiline-emphasis))
1323 ;; Remove special table lines
1324 (when org-export-table-remove-special-lines
1325 (org-export-remove-special-table-lines))
1328 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1330 ;; LaTeX-specific preprocessing
1332 (require 'org-latex nil
)
1333 (org-export-latex-preprocess parameters
))
1335 ;; ASCII-specific preprocessing
1337 (org-export-ascii-preprocess parameters
))
1339 ;; HTML-specific preprocessing
1341 (org-export-html-preprocess parameters
))
1343 ;; DocBook-specific preprocessing
1345 (require 'org-docbook nil
)
1346 (org-export-docbook-preprocess parameters
))
1348 ;; Remove or replace comments
1349 (org-export-handle-comments (plist-get parameters
:comments
))
1351 ;; Run the final hook
1352 (run-hooks 'org-export-preprocess-final-hook
)
1354 (setq rtn
(buffer-string)))
1355 (kill-buffer " org-mode-tmp")
1358 (defun org-export-kill-licensed-text ()
1359 "Remove all text that is marked with a :org-license-to-kill property."
1361 (while (setq p
(text-property-any (point-min) (point-max)
1362 :org-license-to-kill t
))
1364 p
(or (next-single-property-change p
:org-license-to-kill
)
1367 (defun org-export-define-heading-targets (target-alist)
1368 "Find all headings and define the targets for them.
1369 The new targets are added to TARGET-ALIST, which is also returned."
1370 (goto-char (point-min))
1371 (org-init-section-numbers)
1372 (let ((re (concat "^" org-outline-regexp
1373 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1374 level target last-section-target a id
)
1375 (while (re-search-forward re nil t
)
1378 (setq id
(org-match-string-no-properties 2))
1379 (push (cons id target
) target-alist
)
1380 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1382 (push (list last-section-target
)
1383 org-export-target-aliases
)
1384 (car org-export-target-aliases
))))
1385 (push (caar target-alist
) (cdr a
))
1386 (when (equal (match-string 1) "CUSTOM_ID")
1387 (if (not (assoc last-section-target
1388 org-export-preferred-target-alist
))
1389 (push (cons last-section-target id
)
1390 org-export-preferred-target-alist
))))
1391 (setq level
(org-reduced-level
1392 (save-excursion (goto-char (point-at-bol))
1393 (org-outline-level))))
1394 (setq target
(org-solidify-link-text
1395 (format "sec-%s" (org-section-number level
))))
1396 (setq last-section-target target
)
1397 (push (cons target target
) target-alist
)
1398 (add-text-properties
1399 (point-at-bol) (point-at-eol)
1400 (list 'target target
)))))
1403 (defun org-export-handle-invisible-targets (target-alist)
1404 "Find targets in comments and move them out of comments.
1405 Mark them as invisible targets."
1407 (goto-char (point-min))
1408 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1409 ;; Check if the line before or after is a headline with a target
1410 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1411 (get-text-property (point-at-bol 2) 'target
)))
1413 ;; use the existing target in a neighboring line
1414 (setq tmp
(match-string 2))
1416 (and (looking-at "\n") (delete-char 1))
1417 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1419 (setq a
(or (assoc target org-export-target-aliases
)
1421 (push (list target
) org-export-target-aliases
)
1422 (car org-export-target-aliases
))))
1424 ;; Make an invisible target
1425 (replace-match "\\1(INVISIBLE)"))))
1428 (defun org-export-target-internal-links (target-alist)
1429 "Find all internal links and assign targets to them.
1430 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1431 let the link point to the corresponding section.
1432 This function also handles the id links, if they have a match in
1434 (goto-char (point-min))
1435 (while (re-search-forward org-bracket-link-regexp nil t
)
1437 (let* ((md (match-data))
1438 (desc (match-end 2))
1439 (link (org-link-unescape (match-string 1)))
1440 (slink (org-solidify-link-text link
))
1441 found props pos cref
1444 ((= (string-to-char link
) ?
#)
1445 ;; user wants exactly this link
1447 ((cdr (assoc slink target-alist
))
1448 (or (cdr (assoc (assoc slink target-alist
)
1449 org-export-preferred-target-alist
))
1450 (cdr (assoc slink target-alist
))))
1451 ((and (string-match "^id:" link
)
1452 (cdr (assoc (substring link
3) target-alist
))))
1453 ((string-match "^(\\(.*\\))$" link
)
1454 (setq cref
(match-string 1 link
))
1455 (concat "coderef:" cref
))
1456 ((string-match org-link-types-re link
) nil
)
1457 ((or (file-name-absolute-p link
)
1458 (string-match "^\\." link
))
1462 (setq found
(condition-case nil
(org-link-search link
)
1465 (or (org-on-heading-p)
1466 (not (eq found
'dedicated
))))
1467 (or (get-text-property (point) 'target
)
1470 (1- (or (previous-single-property-change
1471 (point) 'target
) 0)))
1475 (goto-char (match-beginning 1))
1476 (setq props
(text-properties-at (point)))
1477 (delete-region (match-beginning 1) (match-end 1))
1480 (unless desc
(insert "][" link
))
1481 (add-text-properties pos
(point) props
))))))
1483 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1484 "Remove drawers, or extract the content.
1485 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1486 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1487 whose content to keep."
1488 (unless (eq t exp-drawers
)
1489 (goto-char (point-min))
1490 (let ((re (concat "^[ \t]*:\\("
1493 (org-delete-all exp-drawers
1494 (copy-sequence all-drawers
))
1498 (while (re-search-forward re nil t
)
1500 (setq beg
(match-beginning 0)
1502 (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
1505 ;; terminated in this entry
1507 (delete-region beg
(match-end 1))
1509 (goto-char eol
))))))))
1511 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1512 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1513 Both arguments are lists of tags.
1514 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1516 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1518 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1519 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1522 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1526 (goto-char (point-min))
1527 (when (and select-tags
1529 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1530 ;; At least one tree is marked for export, this means
1531 ;; all the unmarked stuff needs to go.
1532 ;; Dig out the trees that should be exported
1533 (goto-char (point-min))
1534 (outline-next-heading)
1536 (put-text-property beg
(point-max) :org-delete t
)
1537 (while (re-search-forward re-sel nil t
)
1538 (when (org-on-heading-p)
1539 (org-back-to-heading)
1540 (remove-text-properties
1541 (max (1- (point)) (point-min))
1542 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1544 (while (and (org-up-heading-safe)
1545 (get-text-property (point) :org-delete
))
1546 (remove-text-properties (max (1- (point)) (point-min))
1547 (point-at-eol) '(:org-delete t
)))
1549 ;; Remove the trees explicitly marked for noexport
1551 (goto-char (point-min))
1552 (while (re-search-forward re-excl nil t
)
1553 (when (org-at-heading-p)
1554 (org-back-to-heading t
)
1556 (org-end-of-subtree t
)
1557 (delete-region beg
(point)))))
1558 ;; Remove everything that is now still marked for deletion
1559 (goto-char (point-min))
1560 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1561 (setq end
(or (next-single-property-change beg
:org-delete
)
1563 (delete-region beg end
))))
1565 (defun org-export-remove-archived-trees (export-archived-trees)
1566 "Remove archived trees.
1567 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1568 When it is t, the entire archived tree will be exported.
1569 When it is nil the entire tree including the headline will be removed
1571 (let ((re-archive (concat ":" org-archive-tag
":"))
1573 (when (not (eq export-archived-trees t
))
1574 (goto-char (point-min))
1575 (while (re-search-forward re-archive nil t
)
1576 (if (not (org-on-heading-p t
))
1577 (org-end-of-subtree t
)
1578 (beginning-of-line 1)
1579 (setq a
(if export-archived-trees
1580 (1+ (point-at-eol)) (point))
1581 b
(org-end-of-subtree t
))
1582 (if (> b a
) (delete-region a b
)))))))
1584 (defun org-export-remove-headline-metadata (opts)
1585 "Remove meta data from the headline, according to user options."
1586 (let ((re org-complex-heading-regexp
)
1587 (todo (plist-get opts
:todo-keywords
))
1588 (tags (plist-get opts
:tags
))
1589 (pri (plist-get opts
:priority
))
1592 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1593 (when (or (not todo
) (not tags
) (not pri
))
1594 (goto-char (point-min))
1595 (while (re-search-forward re nil t
)
1597 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1599 (replace-match rpl t t
))))))
1601 (defun org-export-remove-timestamps ()
1602 "Remove timestamps and keywords for export."
1603 (goto-char (point-min))
1604 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1607 (unless (save-match-data (org-at-table-p))
1609 (beginning-of-line 1)
1610 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1611 (replace-match ""))))))
1613 (defun org-export-remove-clock-lines ()
1614 "Remove clock lines for export."
1615 (goto-char (point-min))
1616 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1617 (while (re-search-forward re nil t
)
1619 (replace-match "")))))
1621 (defun org-export-protect-quoted-subtrees ()
1622 "Mark quoted subtrees with the protection property."
1623 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1624 (goto-char (point-min))
1625 (while (re-search-forward re-quote nil t
)
1626 (goto-char (match-beginning 0))
1628 (add-text-properties (point) (org-end-of-subtree t
)
1629 '(org-protected t
)))))
1631 (defun org-export-protect-verbatim ()
1632 "Mark verbatim snippets with the protection property."
1633 (goto-char (point-min))
1634 (while (re-search-forward org-verbatim-re nil t
)
1635 (add-text-properties (match-beginning 4) (match-end 4)
1637 (goto-char (1+ (match-end 4)))))
1639 (defun org-export-protect-colon-examples ()
1640 "Protect lines starting with a colon."
1641 (goto-char (point-min))
1642 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1643 (while (re-search-forward re nil t
)
1644 (beginning-of-line 1)
1646 (while (looking-at re
)
1648 (or (eobp) (forward-char 1)))
1649 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1650 '(org-protected t
)))))
1652 (defun org-export-select-backend-specific-text (backend)
1654 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1655 (html "HTML" "BEGIN_HTML" "END_HTML")
1656 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1657 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1658 (case-fold-search t
)
1662 (setq fmt
(pop formatters
))
1663 (when (eq (car fmt
) backend
)
1664 ;; This is selected code, put it into the file for real
1665 (goto-char (point-min))
1666 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1667 ":[ \t]*\\(.*\\)") nil t
)
1668 (replace-match "\\1\\2" t
)
1669 (add-text-properties
1670 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1671 '(org-protected t
))))
1672 (goto-char (point-min))
1673 (while (re-search-forward
1674 (concat "^[ \t]*#\\+" (caddr fmt
)
1675 "\\>.*\\(\\(\n.*\\)*?\n\\)[ \t]*#\\+" (cadddr fmt
)
1677 (if (eq (car fmt
) backend
)
1679 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1681 ;; No, this is for a different backend, kill it
1682 (delete-region (match-beginning 0) (match-end 0)))))))
1684 (defun org-export-mark-blockquote-verse-center ()
1685 "Mark block quote and verse environments with special cookies.
1686 These special cookies will later be interpreted by the backend."
1688 (let (type t1 ind beg end beg1 end1 content
)
1689 (goto-char (point-min))
1690 (while (re-search-forward
1691 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1693 (setq ind
(length (match-string 1))
1694 type
(downcase (match-string 3))
1695 t1
(if (equal type
"quote") "blockquote" type
))
1696 (setq beg
(match-beginning 0)
1697 beg1
(1+ (match-end 0)))
1698 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1699 (setq end
(1+ (point-at-eol))
1700 end1
(1- (match-beginning 0)))
1701 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1702 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1704 "ORG-" (upcase t1
) "-END\n"))
1705 (delete-region beg end
)
1706 (insert (org-add-props content nil
'original-indentation ind
))))))
1708 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1709 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1710 If the next thing following is a table, add the text properties to the first
1711 table line. If it is a link, add it to the line containing the link."
1712 (goto-char (point-min))
1713 (remove-text-properties (point-min) (point-max)
1714 '(org-caption nil org-attributes nil
))
1715 (let ((case-fold-search t
)
1716 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1718 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1720 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1724 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1726 (while (re-search-forward re nil t
)
1729 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1731 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1733 (setq label
(org-trim (match-string 3))))
1735 (add-text-properties (point-at-bol) (point-at-eol)
1736 (list 'org-caption cap
1737 'org-attributes attr
1739 (if label
(push (cons label label
) target-alist
))
1740 (setq cap nil attr nil label nil
)))))
1743 (defun org-export-remove-comment-blocks-and-subtrees ()
1744 "Remove the comment environment, and also commented subtrees."
1745 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1746 (case-fold-search nil
))
1747 ;; Remove comment environment
1748 (goto-char (point-min))
1749 (while (re-search-forward
1750 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1751 (replace-match "" t t
))
1752 ;; Remove subtrees that are commented
1753 (goto-char (point-min))
1754 (while (re-search-forward re-commented nil t
)
1755 (goto-char (match-beginning 0))
1756 (delete-region (point) (org-end-of-subtree t
)))))
1758 (defun org-export-handle-comments (commentsp)
1759 "Remove comments, or convert to backend-specific format.
1760 COMMENTSP can be a format string for publishing comments.
1761 When it is nil, all comments will be removed."
1762 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1764 (goto-char (point-min))
1765 (while (or (looking-at re
)
1766 (re-search-forward re nil t
))
1767 (setq pos
(match-beginning 0))
1769 (not (equal (char-before (match-end 1)) ?
+)))
1770 (progn (add-text-properties
1771 (match-beginning 0) (match-end 0) '(org-protected t
))
1772 (replace-match (format commentsp
(match-string 2)) t t
))
1773 (goto-char (1+ pos
))
1776 (goto-char (max (point-min) (1- pos
))))))))
1778 (defun org-export-mark-radio-links ()
1779 "Find all matches for radio targets and turn them into internal links."
1780 (let ((re-radio (and org-target-link-regexp
1781 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1782 (goto-char (point-min))
1784 (while (re-search-forward re-radio nil t
)
1786 (replace-match "\\1[[\\2]]"))))))
1788 (defun org-export-remove-special-table-lines ()
1789 "Remove tables lines that are used for internal purposes."
1790 (goto-char (point-min))
1791 (while (re-search-forward "^[ \t]*|" nil t
)
1792 (beginning-of-line 1)
1793 (if (or (looking-at "[ \t]*| *[!_^] *|")
1794 (and (looking-at ".*?| *<[0-9]+> *|")
1795 (not (looking-at ".*?| *[^ <|]"))))
1796 (delete-region (max (point-min) (1- (point-at-bol)))
1800 (defun org-export-normalize-links ()
1801 "Convert all links to bracket links, and expand link abbreviations."
1802 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1803 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1804 (goto-char (point-min))
1805 (while (re-search-forward re-plain-link nil t
)
1806 (goto-char (1- (match-end 0)))
1807 (org-if-unprotected-at (1+ (match-beginning 0))
1808 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1809 ":" (match-string 3) "]]")))
1810 ;; added 'org-link face to links
1811 (put-text-property 0 (length s
) 'face
'org-link s
)
1812 (replace-match s t t
))))
1813 (goto-char (point-min))
1814 (while (re-search-forward re-angle-link nil t
)
1815 (goto-char (1- (match-end 0)))
1817 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1818 ":" (match-string 3) "]]")))
1819 (put-text-property 0 (length s
) 'face
'org-link s
)
1820 (replace-match s t t
))))
1821 (goto-char (point-min))
1822 (while (re-search-forward org-bracket-link-regexp nil t
)
1823 (goto-char (1- (match-end 0)))
1825 (let* ((xx (save-match-data
1827 (org-link-expand-abbrev (match-string 1)))))
1829 "[[" (org-add-props (copy-sequence xx
)
1830 nil
'org-protected t
)
1834 (concat "[" (copy-sequence xx
)
1837 (put-text-property 0 (length s
) 'face
'org-link s
)
1838 (replace-match s t t
))))))
1840 (defun org-export-concatenate-multiline-links ()
1841 "Find multi-line links and put it all into a single line.
1842 This is to make sure that the line-processing export backends
1843 can work correctly."
1844 (goto-char (point-min))
1845 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1847 (replace-match "\\1 \\3")
1848 (goto-char (match-beginning 0)))))
1850 (defun org-export-concatenate-multiline-emphasis ()
1851 "Find multi-line emphasis and put it all into a single line.
1852 This is to make sure that the line-processing export backends
1853 can work correctly."
1854 (goto-char (point-min))
1855 (while (re-search-forward org-emph-re nil t
)
1856 (if (and (not (= (char-after (match-beginning 3))
1857 (char-after (match-beginning 4))))
1858 (save-excursion (goto-char (match-beginning 0))
1859 (save-match-data (not (org-at-table-p)))))
1861 (subst-char-in-region (match-beginning 0) (match-end 0)
1863 (goto-char (1- (match-end 0))))
1864 (goto-char (1+ (match-beginning 0))))))
1866 (defun org-export-grab-title-from-buffer ()
1867 "Get a title for the current document, from looking at the buffer."
1868 (let ((inhibit-read-only t
))
1870 (goto-char (point-min))
1871 (let ((end (if (looking-at org-outline-regexp
)
1873 (save-excursion (outline-next-heading) (point)))))
1874 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1875 ;; Mark the line so that it will not be exported as normal text.
1877 (add-text-properties (match-beginning 0) (match-end 0)
1878 (list :org-license-to-kill t
)))
1879 ;; Return the title string
1880 (org-trim (match-string 0)))))))
1882 (defun org-export-get-title-from-subtree ()
1883 "Return subtree title and exclude it from export."
1884 (let (title (rbeg (region-beginning)) (rend (region-end)))
1887 (when (and (org-at-heading-p)
1888 (>= (org-end-of-subtree t t
) rend
))
1889 ;; This is a subtree, we take the title from the first heading
1891 (looking-at org-todo-line-regexp
)
1892 (setq title
(match-string 3))
1894 (add-text-properties (point) (1+ (point-at-eol))
1895 (list :org-license-to-kill t
)))
1896 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1899 (defun org-solidify-link-text (s &optional alist
)
1900 "Take link text and make a safe target out of it."
1905 (org-split-string s
"[ \t\r\n]+") "=="))
1906 (a (assoc rtn alist
)))
1909 (defun org-get-min-level (lines &optional offset
)
1910 "Get the minimum level in LINES."
1911 (let ((re "^\\(\\*+\\) ") l
)
1913 (while (setq l
(pop lines
))
1914 (if (string-match re l
)
1915 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1919 ;; Variable holding the vector with section numbers
1920 (defvar org-section-numbers
(make-vector org-level-max
0))
1922 (defun org-init-section-numbers ()
1923 "Initialize the vector for the section numbers."
1925 (numbers (nreverse (org-split-string "" "\\.")))
1926 (depth (1- (length org-section-numbers
)))
1927 (i depth
) number-string
)
1930 (aset org-section-numbers i
0)
1931 (setq number-string
(or (car numbers
) "0"))
1932 (if (string-match "\\`[A-Z]\\'" number-string
)
1933 (aset org-section-numbers i
1934 (- (string-to-char number-string
) ?A -
1))
1935 (aset org-section-numbers i
(string-to-number number-string
)))
1939 (defun org-section-number (&optional level
)
1940 "Return a string with the current section number.
1941 When LEVEL is non-nil, increase section numbers on that level."
1942 (let* ((depth (1- (length org-section-numbers
)))
1944 (fmts (car org-export-section-number-format
))
1945 (term (cdr org-export-section-number-format
))
1950 (aset org-section-numbers
1951 level
(1+ (aref org-section-numbers level
))))
1952 (setq idx
(1+ level
))
1953 (while (<= idx depth
)
1955 (aset org-section-numbers idx
0))
1956 (setq idx
(1+ idx
))))
1958 (while (<= idx depth
)
1959 (when (> (aref org-section-numbers idx
) 0)
1960 (setq fmt
(or (pop fmts
) fmt
)
1962 n
(aref org-section-numbers idx
)
1964 (concat string sep
(org-number-to-counter n ctype
))
1965 (concat string
".0"))
1967 (setq idx
(1+ idx
)))
1969 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1970 (setq string
(replace-match "" t nil string
)))
1971 (if (string-match "\\(\\.0\\)+\\'" string
)
1972 (setq string
(replace-match "" t nil string
))))
1973 (concat string term
)))
1975 (defun org-number-to-counter (n type
)
1976 "Concert number N to a string counter, according to TYPE.
1977 TYPE must be a string, any of:
1981 I upper case roman numeral
1982 i lower case roman numeral"
1984 ((equal type
"1") (number-to-string n
))
1985 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1986 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1987 ((equal type
"I") (org-number-to-roman n
))
1988 ((equal type
"i") (downcase (org-number-to-roman n
)))
1989 (t (error "Invalid counter type `%s'" type
))))
1991 (defun org-number-to-roman (n)
1992 "Convert integer N into a roman numeral."
1993 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1994 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1995 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1999 (number-to-string n
)
2001 (if (>= n
(caar roman
))
2002 (setq n
(- n
(caar roman
))
2003 res
(concat res
(cdar roman
)))
2009 (defun org-export-preprocess-apply-macros ()
2010 "Replace macro references."
2011 (goto-char (point-min))
2012 (let (sy val key args args2 s n
)
2013 (while (re-search-forward
2014 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\(.*?\\))\\)?}}}"
2016 (setq key
(downcase (match-string 1))
2017 args
(match-string 3))
2018 (when (setq val
(or (plist-get org-export-opt-plist
2019 (intern (concat ":macro-" key
)))
2020 (plist-get org-export-opt-plist
2021 (intern (concat ":" key
)))))
2024 (setq args
(org-split-string args
";") args2 nil
)
2026 (while (string-match "\\\\\\'" (car args
))
2027 ;; repair bad splits
2028 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2031 (push (pop args
) args2
))
2032 (setq args
(nreverse args2
))
2034 (while (string-match "\\$\\([0-9]+\\)" val s
)
2035 (setq s
(1+ (match-beginning 0))
2036 n
(string-to-number (match-string 1 val
)))
2037 (and (>= (length args
) n
)
2038 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2039 (when (string-match "\\`(eval\\>" val
)
2040 (setq val
(eval (read val
))))
2041 (if (and val
(not (stringp val
)))
2042 (setq val
(format "%s" val
))))
2044 (replace-match val t t
))))))
2046 (defun org-export-apply-macros-in-string (s)
2047 "Apply the macros in string S."
2051 (org-export-preprocess-apply-macros)
2056 (defun org-export-handle-include-files ()
2057 "Include the contents of include files, with proper formatting."
2058 (let ((case-fold-search t
)
2059 params file markup lang start end prefix prefix1 switches
)
2060 (goto-char (point-min))
2061 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2062 (setq params
(read (concat "(" (match-string 1) ")"))
2063 prefix
(org-get-and-remove-property 'params
:prefix
)
2064 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2065 file
(org-symname-or-string (pop params
))
2066 markup
(org-symname-or-string (pop params
))
2067 lang
(and (member markup
'("src" "SRC"))
2068 (org-symname-or-string (pop params
)))
2069 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2070 (delete-region (match-beginning 0) (match-end 0))
2072 (not (file-exists-p file
))
2073 (not (file-readable-p file
)))
2074 (insert (format "CANNOT INCLUDE FILE %s" file
))
2076 (if (equal (downcase markup
) "src")
2077 (setq start
(format "#+begin_src %s %s\n"
2078 (or lang
"fundamental")
2081 (setq start
(format "#+begin_%s %s\n" markup switches
)
2082 end
(format "#+end_%s" markup
))))
2083 (insert (or start
""))
2084 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2085 (or (bolp) (newline))
2086 (insert (or end
""))))))
2088 (defun org-get-file-contents (file &optional prefix prefix1
)
2089 "Get the contents of FILE and return them as a string.
2090 If PREFIX is a string, prepend it to each line. If PREFIX1
2091 is a string, prepend it to the first line instead of PREFIX."
2093 (insert-file-contents file
)
2094 (when (or prefix prefix1
)
2095 (goto-char (point-min))
2097 (insert (or prefix1 prefix
))
2099 (beginning-of-line 2)))
2102 (defun org-get-and-remove-property (listvar prop
)
2103 "Check if the value of LISTVAR contains PROP as a property.
2104 If yes, return the value of that property (i.e. the element following
2105 in the list) and remove property and value from the list in LISTVAR."
2106 (let ((list (symbol-value listvar
)) m v
)
2107 (when (setq m
(member prop list
))
2109 (if (equal (car list
) prop
)
2110 (set listvar
(cddr list
))
2111 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2113 (set listvar list
)))
2116 (defun org-symname-or-string (s)
2118 (if s
(symbol-name s
) s
)
2121 ;;; Fontification and line numbers for code examples
2123 (defvar org-export-last-code-line-counter-value
0)
2125 (defun org-export-replace-src-segments-and-examples (backend)
2126 "Replace source code segments with special code for export."
2127 (setq org-export-last-code-line-counter-value
0)
2128 (let ((case-fold-search t
)
2129 lang code trans opts indent
)
2130 (goto-char (point-min))
2131 (while (re-search-forward
2132 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
2136 (setq lang
(match-string 3)
2137 opts
(match-string 4)
2138 code
(match-string 5)
2139 indent
(length (match-string 2)))
2141 opts
(match-string 8)
2142 code
(match-string 9)
2143 indent
(length (match-string 7))))
2145 (setq trans
(org-export-format-source-code-or-example
2146 backend lang code opts indent
))
2147 (replace-match trans t t
))))
2149 (defvar htmlp
) ;; dynamically scoped
2150 (defvar latexp
) ;; dynamically scoped
2151 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2153 (defun org-export-format-source-code-or-example
2154 (backend lang code
&optional opts indent
)
2155 "Format CODE from language LANG and return it formatted for export.
2156 If LANG is nil, do not add any fontification.
2157 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2158 and `+n' for continuing previous numering.
2159 Code formatting according to language currently only works for HTML.
2160 Numbering lines works for all three major backends (html, latex, and ascii).
2161 INDENT was the original indentation of the block."
2163 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2164 (setq opts
(or opts
"")
2165 num
(string-match "[-+]n\\>" opts
)
2166 cont
(string-match "\\+n\\>" opts
)
2167 rpllbl
(string-match "-r\\>" opts
)
2168 keepp
(string-match "-k\\>" opts
)
2169 textareap
(string-match "-t\\>" opts
)
2170 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2171 (string-to-number (match-string 1 opts
))
2173 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2174 (string-to-number (match-string 1 opts
))
2175 (org-count-lines code
))
2176 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2177 (match-string 1 opts
)))
2178 (when (and textareap
(eq backend
'html
))
2179 ;; we cannot use numbering or highlighting.
2180 (setq num nil cont nil lang nil
))
2181 (if keepp
(setq rpllbl
'keep
))
2182 (setq rtn
(org-remove-indentation code
))
2183 (when (string-match "^," rtn
)
2184 (setq rtn
(with-temp-buffer
2186 ;; Free up the protected lines
2187 (goto-char (point-min))
2188 (while (re-search-forward "^," nil t
)
2189 (if (or (equal lang
"org")
2191 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2195 ;; Now backend-specific coding
2198 ((eq backend
'docbook
)
2199 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2200 (concat "\n#+BEGIN_DOCBOOK\n"
2201 (org-add-props (concat "<programlisting><![CDATA["
2203 "]]>\n</programlisting>\n")
2207 ;; We are exporting to HTML
2209 (require 'htmlize nil t
)
2210 (when (not (fboundp 'htmlize-region-for-paste
))
2211 ;; we do not have htmlize.el, or an old version of it
2214 "htmlize.el 1.34 or later is needed for source code formatting")))
2217 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2218 (org-inhibit-startup t
)
2219 (org-startup-folded nil
))
2223 (if (functionp mode
)
2226 (font-lock-fontify-buffer)
2228 (set-buffer-modified-p nil
)
2229 (org-export-htmlize-region-for-paste
2230 (point-min) (point-max))))
2231 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2232 (setq rtn
(replace-match
2233 (format "<pre class=\"src src-%s\">" lang
)
2237 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2239 rtn
"</textarea>\n</p>\n"))
2242 (goto-char (point-min))
2243 (while (re-search-forward "[<>&]" nil t
)
2244 (replace-match (cdr (assq (char-before)
2245 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2247 (setq rtn
(buffer-string)))
2248 (setq rtn
(concat "<pre class=\"example\">" rtn
"</pre>\n"))))
2250 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2252 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2253 ((eq backend
'latex
)
2254 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2255 (concat "\n#+BEGIN_LaTeX\n"
2256 (org-add-props (concat (car org-export-latex-verbatim-wrap
)
2257 rtn
(cdr org-export-latex-verbatim-wrap
))
2260 ((eq backend
'ascii
)
2261 ;; This is not HTML or LaTeX, so just make it an example.
2262 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2263 (concat "#+BEGIN_ASCII\n"
2267 (lambda (l) (concat " " l
))
2268 (org-split-string rtn
"\n")
2273 (org-add-props rtn nil
'original-indentation indent
))))
2275 (defun org-export-number-lines (text backend
2276 &optional skip1 skip2 number cont
2277 replace-labels label-format
)
2278 (if (and (not number
) (not (eq replace-labels
'keep
)))
2279 (setq replace-labels nil
)) ;; must use names if no numbers
2280 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2281 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2284 (goto-char (point-max))
2285 (skip-chars-backward " \t\n\r")
2286 (delete-region (point) (point-max))
2287 (beginning-of-line (- 1 skip2
))
2288 (let* ((last (org-current-line))
2289 (n org-export-last-code-line-counter-value
)
2290 (nmax (+ n
(- last skip1
)))
2291 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2294 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2296 ((eq backend
'ascii
) fmt
)
2297 ((eq backend
'latex
) fmt
)
2298 ((eq backend
'docbook
) fmt
)
2300 (label-format (or label-format org-coderef-label-format
))
2301 (label-pre (if (string-match "%s" label-format
)
2302 (substring label-format
0 (match-beginning 0))
2304 (label-post (if (string-match "%s" label-format
)
2305 (substring label-format
(match-end 0))
2309 ".*?\\S-.*?\\([ \t]*\\("
2310 (regexp-quote label-pre
)
2311 "\\([-a-zA-Z0-9_]+\\)"
2312 (regexp-quote label-post
)
2316 (goto-line (1+ skip1
))
2317 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2319 (insert (format fm
(incf n
)))
2321 (when (and (not (eq replace-labels
'keep
))
2322 (looking-at lbl-re
))
2323 (setq ref
(match-string 3))
2326 (delete-region (match-beginning 1) (match-end 1))
2327 (push (cons ref n
) org-export-code-refs
))
2328 (goto-char (match-beginning 2))
2329 (delete-region (match-beginning 2) (match-end 2))
2330 (insert "(" ref
")")
2331 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2332 (when (eq backend
'html
)
2334 (beginning-of-line 1)
2335 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2338 (insert "</span>")))))
2339 (setq org-export-last-code-line-counter-value n
)
2340 (goto-char (point-max))
2344 (defun org-search-todo-below (line lines level
)
2345 "Search the subtree below LINE for any TODO entries."
2346 (let ((rest (cdr (memq line lines
)))
2347 (re org-todo-line-regexp
)
2350 (while (setq line
(pop rest
))
2351 (if (string-match re line
)
2353 (setq lv
(- (match-end 1) (match-beginning 1))
2354 todo
(and (match-beginning 2)
2355 (not (member (match-string 2 line
)
2356 org-done-keywords
))))
2358 (if (<= lv level
) (throw 'exit nil
))
2359 (if todo
(throw 'exit t
))))))))
2362 (defun org-export-visible (type arg
)
2363 "Create a copy of the visible part of the current buffer, and export it.
2364 The copy is created in a temporary buffer and removed after use.
2365 TYPE is the final key (as a string) that also select the export command in
2366 the `C-c C-e' export dispatcher.
2367 As a special case, if the you type SPC at the prompt, the temporary
2368 org-mode file will not be removed but presented to you so that you can
2369 continue to use it. The prefix arg ARG is passed through to the exporting
2373 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2374 (read-char-exclusive))
2375 current-prefix-arg
))
2376 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\
)))
2377 (error "Invalid export key"))
2378 (let* ((binding (cdr (assoc type
2379 '((?a . org-export-as-ascii
)
2380 (?A . org-export-as-ascii-to-buffer
)
2381 (?\C-a . org-export-as-ascii
)
2382 (?b . org-export-as-html-and-open
)
2383 (?\C-b . org-export-as-html-and-open
)
2384 (?h . org-export-as-html
)
2385 (?H . org-export-as-html-to-buffer
)
2386 (?R . org-export-region-as-html
)
2387 (?D . org-export-as-docbook
)
2388 (?x . org-export-as-xoxo
)))))
2389 (keepp (equal type ?\
))
2390 (file buffer-file-name
)
2391 (buffer (get-buffer-create "*Org Export Visible*"))
2393 ;; Need to hack the drawers here.
2395 (goto-char (point-min))
2396 (while (re-search-forward org-drawer-regexp nil t
)
2397 (goto-char (match-beginning 1))
2398 (or (org-invisible-p) (org-flag-drawer nil
))))
2399 (with-current-buffer buffer
(erase-buffer))
2401 (setq s
(goto-char (point-min)))
2402 (while (not (= (point) (point-max)))
2403 (goto-char (org-find-invisible))
2404 (append-to-buffer buffer s
(point))
2405 (setq s
(goto-char (org-find-visible))))
2406 (org-cycle-hide-drawers 'all
)
2407 (goto-char (point-min))
2409 ;; Copy all comment lines to the end, to make sure #+ settings are
2410 ;; still available for the second export step. Kind of a hack, but
2411 ;; does do the trick.
2412 (if (looking-at "#[^\r\n]*")
2413 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2414 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2415 (append-to-buffer buffer
(1+ (match-beginning 0))
2416 (min (point-max) (1+ (match-end 0))))))
2418 (let ((buffer-file-name file
)
2419 (org-inhibit-startup t
))
2422 (unless keepp
(funcall binding arg
))))
2424 (kill-buffer buffer
)
2425 (switch-to-buffer-other-window buffer
)
2426 (goto-char (point-min)))))
2428 (defun org-find-visible ()
2430 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2431 (get-char-property s
'invisible
)))
2433 (defun org-find-invisible ()
2435 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2436 (not (get-char-property s
'invisible
))))
2439 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2442 (defun org-export-as-org (arg &optional hidden ext-plist
2443 to-buffer body-only pub-dir
)
2444 "Make a copy wiht not-exporting stuff removed.
2445 The purpose of this function is to provide a way to export the source
2446 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2447 stuff removed. This command will remove the following:
2449 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2450 - comment blocks and trees starting with the COMMENT keyword
2451 - only trees that are consistent with `org-export-select-tags'
2452 and `org-export-exclude-tags'.
2454 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2455 all the others will be ignored (but are present so that the general
2456 mechanism to call publishing functions will work).
2458 EXT-PLIST is a property list with external parameters overriding
2459 org-mode's default settings, but still inferior to file-local
2460 settings. When PUB-DIR is set, use this as the publishing
2463 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2465 (org-infile-export-plist)))
2466 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2467 (filename (concat (file-name-as-directory
2469 (org-export-directory :org opt-plist
)))
2470 (file-name-sans-extension
2471 (file-name-nondirectory bfname
))
2473 (filename (and filename
2474 (if (equal (file-truename filename
)
2475 (file-truename bfname
))
2476 (concat filename
"-source")
2478 (backup-inhibited t
)
2479 (buffer (find-file-noselect filename
))
2480 (region (buffer-string)))
2482 (switch-to-buffer buffer
)
2485 (let ((org-inhibit-startup t
)) (org-mode))
2487 ;; Get rid of archived trees
2488 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2490 ;; Remove comment environment and comment subtrees
2491 (org-export-remove-comment-blocks-and-subtrees)
2493 ;; Get rid of excluded trees
2494 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2495 (plist-get opt-plist
:exclude-tags
))
2497 (when (or (plist-get opt-plist
:plain-source
)
2498 (not (or (plist-get opt-plist
:plain-source
)
2499 (plist-get opt-plist
:htmlized-source
))))
2500 ;; Either nothing special is requested (default call)
2501 ;; or the plain source is explicitly requested
2504 (when (plist-get opt-plist
:htmlized-source
)
2505 ;; Make the htmlized version
2508 (font-lock-fontify-buffer)
2509 (let* ((htmlize-output-type 'css
)
2510 (newbuf (htmlize-buffer)))
2511 (with-current-buffer newbuf
2512 (when org-export-htmlized-org-css-url
2513 (goto-char (point-min))
2514 (and (re-search-forward
2515 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2519 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2520 org-export-htmlized-org-css-url
)
2522 (write-file (concat filename
".html")))
2523 (kill-buffer newbuf
)))
2524 (set-buffer-modified-p nil
)
2525 (kill-buffer (current-buffer)))))
2527 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2528 (defun org-get-current-options ()
2529 "Return a string with current options as keyword options.
2530 Does include HTML export options as well as TODO and CATEGORY stuff."
2531 (require 'org-archive
)
2540 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2541 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2543 #+EXPORT_SELECT_TAGS: %s
2544 #+EXPORT_EXCLUDE_TAGS: %s
2550 #+PRIORITIES: %c %c %c
2552 #+STARTUP: %s %s %s %s %s
2558 (buffer-name) (user-full-name) user-mail-address
2559 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2560 org-export-default-language
2561 org-export-headline-levels
2562 org-export-with-section-numbers
2564 org-export-preserve-breaks
2565 org-export-html-expand
2566 org-export-with-fixed-width
2567 org-export-with-tables
2568 org-export-with-sub-superscripts
2569 org-export-with-special-strings
2570 org-export-with-footnotes
2571 org-export-with-emphasize
2572 org-export-with-timestamps
2573 org-export-with-TeX-macros
2574 org-export-with-LaTeX-fragments
2575 org-export-skip-text-before-1st-heading
2576 org-export-with-drawers
2577 org-export-with-todo-keywords
2578 org-export-with-priority
2579 org-export-with-tags
2580 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2581 (mapconcat 'identity org-export-select-tags
" ")
2582 (mapconcat 'identity org-export-exclude-tags
" ")
2583 org-export-html-link-up
2584 org-export-html-link-home
2586 (file-name-sans-extension
2587 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2589 "TODO FEEDBACK VERIFY DONE"
2590 "Me Jason Marie DONE"
2591 org-highest-priority org-lowest-priority org-default-priority
2592 (mapconcat 'identity org-drawers
" ")
2593 (cdr (assoc org-startup-folded
2594 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2595 (if org-odd-levels-only
"odd" "oddeven")
2596 (if org-hide-leading-stars
"hidestars" "showstars")
2597 (if org-startup-align-all-tables
"align" "noalign")
2598 (cond ((eq org-log-done t
) "logdone")
2599 ((equal org-log-done
'note
) "lognotedone")
2600 ((not org-log-done
) "nologdone"))
2601 (or (mapconcat (lambda (x)
2603 ((equal '(:startgroup
) x
) "{")
2604 ((equal '(:endgroup
) x
) "}")
2605 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2607 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2608 (mapconcat 'identity org-file-tags
" ")
2609 org-archive-location
2610 "org file:~/org/%s.org"
2614 (defun org-insert-export-options-template ()
2615 "Insert into the buffer a template with information for exporting."
2617 (if (not (bolp)) (newline))
2618 (let ((s (org-get-current-options)))
2619 (and (string-match "#\\+CATEGORY" s
)
2620 (setq s
(substring s
0 (match-beginning 0))))
2623 (defvar org-table-colgroup-info nil
)
2625 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2626 "Check if the table has a marking column.
2627 If yes remove the column and the special lines."
2628 (setq org-table-colgroup-info nil
)
2631 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2634 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2635 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2639 (setq org-table-clean-did-remove-column nil
)
2644 ((string-match "^[ \t]*| */ *|" x
)
2645 (setq org-table-colgroup-info
2647 (cond ((member x
'("<" "<")) :start
)
2648 ((member x
'(">" ">")) :end
)
2649 ((member x
'("<>" "<>")) :startend
)
2651 (org-split-string x
"[ \t]*|[ \t]*")))
2655 (setq org-table-clean-did-remove-column t
)
2660 ((string-match "^[ \t]*| */ *|" x
)
2661 (setq org-table-colgroup-info
2663 (cond ((member x
'("<" "<")) :start
)
2664 ((member x
'(">" ">")) :end
)
2665 ((member x
'("<>" "<>")) :startend
)
2667 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2669 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2670 nil
) ; ignore this line
2671 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2672 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2673 ;; remove the first column
2674 (replace-match "\\1|" t nil x
))))
2677 (defun org-export-cleanup-toc-line (s)
2678 "Remove tags and timestamps from lines going into the toc."
2679 (when (memq org-export-with-tags
'(not-in-toc nil
))
2680 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2681 (setq s
(replace-match "" t t s
))))
2682 (when org-export-remove-timestamps-from-toc
2683 (while (string-match org-maybe-keyword-time-regexp s
)
2684 (setq s
(replace-match "" t t s
))))
2685 (while (string-match org-bracket-link-regexp s
)
2686 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2690 (defun org-create-multibrace-regexp (left right n
)
2691 "Create a regular expression which will match a balanced sexp.
2692 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2693 as single character strings.
2694 The regexp returned will match the entire expression including the
2695 delimiters. It will also define a single group which contains the
2696 match except for the outermost delimiters. The maximum depth of
2697 stacked delimiters is N. Escaping delimiters is not possible."
2698 (let* ((nothing (concat "[^" left right
"]*?"))
2701 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
2704 re
(concat re or next
)
2705 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
2706 (concat left
"\\(" re
"\\)" right
)))
2708 (defvar org-match-substring-regexp
2710 "\\([^\\]\\)\\([_^]\\)\\("
2711 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2713 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
2715 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2716 "The regular expression matching a sub- or superscript.")
2718 (defvar org-match-substring-with-braces-regexp
2720 "\\([^\\]\\)\\([_^]\\)\\("
2721 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2723 "The regular expression matching a sub- or superscript, forcing braces.")
2726 (defun org-get-text-property-any (pos prop
&optional object
)
2727 (or (get-text-property pos prop object
)
2728 (and (setq pos
(next-single-property-change pos prop object
))
2729 (get-text-property pos prop object
))))
2731 (defun org-export-get-coderef-format (path desc
)
2733 (if (and desc
(string-match
2734 (regexp-quote (concat "(" path
")"))
2736 (replace-match "%s" t t desc
)
2739 (defun org-export-push-to-kill-ring (format)
2740 "Push buffer content to kill ring.
2741 The depends on the variable `org-export-copy-to-kill'."
2742 (when org-export-copy-to-kill-ring
2743 (kill-new (buffer-string))
2744 (when (fboundp 'x-set-selection
)
2745 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
2746 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
2747 (message "%s export done, pushed to kill ring and clipboard" format
)))
2751 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2753 ;;; org-exp.el ends here