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
))
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")
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 ((equal key
"SETUPFILE")
686 (setq setup-contents
(org-file-contents
688 (org-remove-double-quotes
691 (if (not ext-setup-or-nil
)
692 (setq ext-setup-or-nil setup-contents start
0)
693 (setq ext-setup-or-nil
694 (concat (substring ext-setup-or-nil
0 start
)
695 "\n" setup-contents
"\n"
696 (substring ext-setup-or-nil start
)))))))
697 (setq p
(plist-put p
:text text
))
698 (when style
(setq p
(plist-put p
:style-extra style
)))
700 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
702 (setq p
(org-export-add-options-to-plist p options
)))
703 ;; Add macro definitions
704 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
705 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
707 p
:macro-modification-time
708 (and (buffer-file-name)
709 (file-exists-p (buffer-file-name))
711 "(eval (format-time-string \"$1\" '"
712 (prin1-to-string (nth 5 (file-attributes
713 (buffer-file-name))))
715 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
716 (file-name-nondirectory
717 (buffer-file-name)))))
718 (goto-char (point-min))
719 (while (re-search-forward
720 "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
722 (setq p
(plist-put p
(intern (concat ":macro-"
723 (downcase (match-string 1))))
727 (defun org-export-add-options-to-plist (p options
)
728 "Parse an OPTIONS line and set values in the property list P."
731 (let ((op org-export-plist-vars
))
732 (while (setq o
(pop op
))
734 (string-match (concat (regexp-quote (nth 1 o
))
735 ":\\([^ \t\n\r;,.]*\\)")
737 (setq p
(plist-put p
(car o
)
738 (car (read-from-string
739 (match-string 1 options
))))))))))
742 (defun org-export-add-subtree-options (p pos
)
743 "Add options in subtree at position POS to property list P."
746 (when (org-at-heading-p)
748 ;; This is actually read in `org-export-get-title-from-subtree'
749 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
750 ;; (setq p (plist-put p :title a)))
751 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
752 (setq p
(plist-put p
:text a
)))
753 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
754 (setq p
(plist-put p
:author a
)))
755 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
756 (setq p
(plist-put p
:date a
)))
757 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
758 (setq p
(org-export-add-options-to-plist p a
)))))
761 (defun org-export-directory (type plist
)
762 (let* ((val (plist-get plist
:publishing-directory
))
764 (or (cdr (assoc type val
)) ".")
768 (defun org-export-process-option-filters (plist)
769 (let ((functions org-export-options-filters
) f
)
770 (while (setq f
(pop functions
))
771 (setq plist
(funcall f plist
))))
775 (defun org-export (&optional arg
)
776 "Export dispatcher for Org-mode.
777 When `org-export-run-in-background' is non-nil, try to run the command
778 in the background. This will be done only for commands that write
779 to a file. For details see the docstring of `org-export-run-in-background'.
781 The prefix argument ARG will be passed to the exporter. However, if
782 ARG is a double universal prefix `C-u C-u', that means to inverse the
783 value of `org-export-run-in-background'."
785 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
786 (help "[t] insert the export option template
787 \[v] limit export to visible part of outline tree
789 \[a] export as ASCII [A] to temporary buffer
791 \[h] export as HTML [H] to temporary buffer [R] export region
792 \[b] export as HTML and open in browser
794 \[l] export as LaTeX [L] to temporary buffer
795 \[p] export as LaTeX and process to PDF
796 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
798 \[D] export as DocBook
799 \[V] export as DocBook, process to PDF, and open the resulting PDF document
803 \[i] export current file as iCalendar file
804 \[I] export all agenda files as iCalendar files
805 \[c] export agenda files into combined iCalendar file
807 \[F] publish current file [P] publish current project
808 \[X] publish a project... [E] publish every projects")
810 '((?t org-insert-export-options-template nil
)
811 (?v org-export-visible nil
)
812 (?a org-export-as-ascii t
)
813 (?A org-export-as-ascii-to-buffer t
)
814 (?h org-export-as-html t
)
815 (?b org-export-as-html-and-open t
)
816 (?H org-export-as-html-to-buffer nil
)
817 (?R org-export-region-as-html nil
)
818 (?x org-export-as-xoxo t
)
819 (?D org-export-as-docbook t
)
820 (?V org-export-as-docbook-pdf-and-open t
)
821 (?l org-export-as-latex t
)
822 (?p org-export-as-pdf t
)
823 (?d org-export-as-pdf-and-open t
)
824 (?L org-export-as-latex-to-buffer nil
)
825 (?i org-export-icalendar-this-file t
)
826 (?I org-export-icalendar-all-agenda-files t
)
827 (?c org-export-icalendar-combine-agenda-files t
)
828 (?F org-publish-current-file t
)
829 (?P org-publish-current-project t
)
831 (?E org-publish-all t
)))
834 (save-window-excursion
835 (delete-other-windows)
836 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
838 (org-fit-window-to-buffer (get-buffer-window
839 "*Org Export/Publishing Help*"))
840 (message "Select command: ")
841 (setq r1
(read-char-exclusive))))
842 (setq r2
(if (< r1
27) (+ r1
96) r1
))
843 (unless (setq ass
(assq r2 cmds
))
844 (error "No command associated with key %c" r1
))
845 (if (and bg
(nth 2 ass
)
846 (not (buffer-base-buffer))
847 (not (org-region-active-p)))
848 ;; execute in background
849 (let ((p (start-process
850 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
852 (expand-file-name invocation-name invocation-directory
)
855 "--eval" "(require 'org-exp)"
856 "--eval" "(setq org-wait .2)"
858 "-f" (symbol-name (nth 1 ass
)))))
859 (set-process-sentinel p
'org-export-process-sentinel
)
860 (message "Background process \"%s\": started" p
))
861 ;; background processing not requested, or not possible
862 (call-interactively (nth 1 ass
)))))
864 (defun org-export-process-sentinel (process status
)
865 (if (string-match "\n+\\'" status
)
866 (setq status
(substring status
0 -
1)))
867 (message "Background process \"%s\": %s" process status
))
869 (defconst org-html-entities
911 ("Aring") ("AA".
"Å")
1000 ("varepsilon".
"ε")
1013 ("sigmaf") ("varsigma".
"ς")
1021 ("thetasym") ("vartheta".
"ϑ")
1024 ("bull") ("bullet".
"•")
1025 ("hellip") ("dots".
"…")
1035 ("larr") ("leftarrow".
"←") ("gets".
"←")
1036 ("uarr") ("uparrow".
"↑")
1037 ("rarr") ("to".
"→") ("rightarrow".
"→")
1038 ("darr")("downarrow".
"↓")
1039 ("harr") ("leftrightarrow".
"↔")
1040 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1041 ("lArr") ("Leftarrow".
"⇐")
1042 ("uArr") ("Uparrow".
"⇑")
1043 ("rArr") ("Rightarrow".
"⇒")
1044 ("dArr") ("Downarrow".
"⇓")
1045 ("hArr") ("Leftrightarrow".
"⇔")
1047 ("part") ("partial".
"∂")
1048 ("exist") ("exists".
"∃")
1049 ("empty") ("emptyset".
"∅")
1051 ("isin") ("in".
"∈")
1057 ("lowast") ("ast".
"∗")
1059 ("prop") ("proptp".
"∝")
1060 ("infin") ("infty".
"∞")
1061 ("ang") ("angle".
"∠")
1062 ("and") ("wedge".
"∧")
1063 ("or") ("vee".
"∨")
1069 ("cong") ("simeq".
"≅")
1070 ("asymp")("approx".
"≈")
1071 ("ne") ("neq".
"≠")
1075 ("sub") ("subset".
"⊂")
1076 ("sup") ("supset".
"⊃")
1083 ("sdot") ("cdot".
"⋅")
1090 ("loz") ("Diamond".
"◊")
1091 ("spades") ("spadesuit".
"♠")
1092 ("clubs") ("clubsuit".
"♣")
1093 ("hearts") ("diamondsuit".
"♥")
1094 ("diams") ("diamondsuit".
"♦")
1095 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1162 "Entities for TeX->HTML translation.
1163 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1164 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1165 In that case, \"\\ent\" will be translated to \"&other;\".
1166 The list contains HTML entities for Latin-1, Greek and other symbols.
1167 It is supplemented by a number of commonly used TeX macros with appropriate
1168 translations. There is currently no way for users to extend this.")
1170 ;;; General functions for all backends
1172 (defvar org-export-target-aliases nil
1173 "Alist of targets with invisible aliases.")
1174 (defvar org-export-preferred-target-alist nil
1175 "Alist of section id's with preferred aliases.")
1176 (defvar org-export-code-refs nil
1177 "Alist of code references and line numbers")
1179 (defun org-export-preprocess-string (string &rest parameters
)
1180 "Cleanup STRING so that that the true exported has a more consistent source.
1181 This function takes STRING, which should be a buffer-string of an org-file
1182 to export. It then creates a temporary buffer where it does its job.
1183 The result is then again returned as a string, and the exporter works
1184 on this string to produce the exported version."
1186 (let* ((htmlp (plist-get parameters
:for-html
))
1187 (asciip (plist-get parameters
:for-ascii
))
1188 (latexp (plist-get parameters
:for-LaTeX
))
1189 (docbookp (plist-get parameters
:for-docbook
))
1190 (backend (cond (htmlp 'html
)
1193 (docbookp 'docbook
)))
1194 (archived-trees (plist-get parameters
:archived-trees
))
1195 (inhibit-read-only t
)
1196 (drawers org-drawers
)
1197 (outline-regexp "\\*+ ")
1200 (setq org-export-target-aliases nil
)
1201 (setq org-export-preferred-target-alist nil
)
1202 (setq org-export-code-refs nil
)
1204 (with-current-buffer (get-buffer-create " org-mode-tmp")
1207 (setq case-fold-search t
)
1209 ;; Remove license-to-kill stuff
1210 ;; The caller marks some stuff for killing, stuff that has been
1211 ;; used to create the page title, for example.
1212 (org-export-kill-licensed-text)
1214 (let ((org-inhibit-startup t
)) (org-mode))
1215 (setq case-fold-search t
)
1218 (run-hooks 'org-export-preprocess-hook
)
1220 ;; Process the macros
1221 (org-export-preprocess-apply-macros)
1222 (run-hooks 'org-export-preprocess-after-macros-hook
)
1224 (untabify (point-min) (point-max))
1226 ;; Handle include files, and call a hook
1227 (org-export-handle-include-files)
1228 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1230 ;; Get rid of archived trees
1231 (org-export-remove-archived-trees archived-trees
)
1233 ;; Remove comment environment and comment subtrees
1234 (org-export-remove-comment-blocks-and-subtrees)
1236 ;; Get rid of excluded trees, and call a hook
1237 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1238 (plist-get parameters
:exclude-tags
))
1239 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1241 ;; Handle source code snippets
1242 (org-export-replace-src-segments-and-examples backend
)
1244 ;; Protect short examples marked by a leading colon
1245 (org-export-protect-colon-examples)
1247 ;; Normalize footnotes
1248 (when (plist-get parameters
:footnotes
)
1249 (org-footnote-normalize nil t
))
1251 ;; Find all headings and compute the targets for them
1252 (setq target-alist
(org-export-define-heading-targets target-alist
))
1254 ;; Get rid of drawers
1255 (org-export-remove-or-extract-drawers drawers
1256 (plist-get parameters
:drawers
))
1258 ;; Get the correct stuff before the first headline
1259 (when (plist-get parameters
:skip-before-1st-heading
)
1260 (goto-char (point-min))
1261 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1262 (delete-region (point-min) (match-beginning 0))
1263 (goto-char (point-min))
1265 (when (plist-get parameters
:add-text
)
1266 (goto-char (point-min))
1267 (insert (plist-get parameters
:add-text
) "\n"))
1269 ;; Remove todo-keywords before exporting, if the user has requested so
1270 (org-export-remove-headline-metadata parameters
)
1272 ;; Find targets in comments and move them out of comments,
1273 ;; but mark them as targets that should be invisible
1274 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1276 ;; Select and protect backend specific stuff, throw away stuff
1277 ;; that is specific for other backends
1278 (org-export-select-backend-specific-text backend
)
1280 ;; Protect quoted subtrees
1281 (org-export-protect-quoted-subtrees)
1283 ;; Remove clock lines
1284 (org-export-remove-clock-lines)
1286 ;; Protect verbatim elements
1287 (org-export-protect-verbatim)
1289 ;; Blockquotes, verse, and center
1290 (org-export-mark-blockquote-verse-center)
1291 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1293 ;; Remove timestamps, if the user has requested so
1294 (unless (plist-get parameters
:timestamps
)
1295 (org-export-remove-timestamps))
1297 ;; Attach captions to the correct object
1298 (setq target-alist
(org-export-attach-captions-and-attributes
1299 backend target-alist
))
1301 ;; Find matches for radio targets and turn them into internal links
1302 (org-export-mark-radio-links)
1304 ;; Find all links that contain a newline and put them into a single line
1305 (org-export-concatenate-multiline-links)
1307 ;; Normalize links: Convert angle and plain links into bracket links
1308 ;; and expand link abbreviations
1309 (org-export-normalize-links)
1311 ;; Find all internal links. If they have a fuzzy match (i.e. not
1312 ;; a *dedicated* target match, let the link point to the
1313 ;; corresponding section.
1314 (org-export-target-internal-links target-alist
)
1316 ;; Find multiline emphasis and put them into single line
1317 (when (plist-get parameters
:emph-multiline
)
1318 (org-export-concatenate-multiline-emphasis))
1320 ;; Remove special table lines
1321 (when org-export-table-remove-special-lines
1322 (org-export-remove-special-table-lines))
1325 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1327 ;; LaTeX-specific preprocessing
1329 (require 'org-latex nil
)
1330 (org-export-latex-preprocess parameters
))
1332 ;; ASCII-specific preprocessing
1334 (org-export-ascii-preprocess parameters
))
1336 ;; HTML-specific preprocessing
1338 (org-export-html-preprocess parameters
))
1340 ;; DocBook-specific preprocessing
1342 (require 'org-docbook nil
)
1343 (org-export-docbook-preprocess parameters
))
1345 ;; Remove or replace comments
1346 (org-export-handle-comments (plist-get parameters
:comments
))
1348 ;; Run the final hook
1349 (run-hooks 'org-export-preprocess-final-hook
)
1351 (setq rtn
(buffer-string)))
1352 (kill-buffer " org-mode-tmp")
1355 (defun org-export-kill-licensed-text ()
1356 "Remove all text that is marked with a :org-license-to-kill property."
1358 (while (setq p
(text-property-any (point-min) (point-max)
1359 :org-license-to-kill t
))
1361 p
(or (next-single-property-change p
:org-license-to-kill
)
1364 (defun org-export-define-heading-targets (target-alist)
1365 "Find all headings and define the targets for them.
1366 The new targets are added to TARGET-ALIST, which is also returned."
1367 (goto-char (point-min))
1368 (org-init-section-numbers)
1369 (let ((re (concat "^" org-outline-regexp
1370 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1371 level target last-section-target a id
)
1372 (while (re-search-forward re nil t
)
1375 (setq id
(org-match-string-no-properties 2))
1376 (push (cons id target
) target-alist
)
1377 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1379 (push (list last-section-target
)
1380 org-export-target-aliases
)
1381 (car org-export-target-aliases
))))
1382 (push (caar target-alist
) (cdr a
))
1383 (when (equal (match-string 1) "CUSTOM_ID")
1384 (if (not (assoc last-section-target
1385 org-export-preferred-target-alist
))
1386 (push (cons last-section-target id
)
1387 org-export-preferred-target-alist
))))
1388 (setq level
(org-reduced-level
1389 (save-excursion (goto-char (point-at-bol))
1390 (org-outline-level))))
1391 (setq target
(org-solidify-link-text
1392 (format "sec-%s" (org-section-number level
))))
1393 (setq last-section-target target
)
1394 (push (cons target target
) target-alist
)
1395 (add-text-properties
1396 (point-at-bol) (point-at-eol)
1397 (list 'target target
)))))
1400 (defun org-export-handle-invisible-targets (target-alist)
1401 "Find targets in comments and move them out of comments.
1402 Mark them as invisible targets."
1404 (goto-char (point-min))
1405 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1406 ;; Check if the line before or after is a headline with a target
1407 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1408 (get-text-property (point-at-bol 2) 'target
)))
1410 ;; use the existing target in a neighboring line
1411 (setq tmp
(match-string 2))
1413 (and (looking-at "\n") (delete-char 1))
1414 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1416 (setq a
(or (assoc target org-export-target-aliases
)
1418 (push (list target
) org-export-target-aliases
)
1419 (car org-export-target-aliases
))))
1421 ;; Make an invisible target
1422 (replace-match "\\1(INVISIBLE)"))))
1425 (defun org-export-target-internal-links (target-alist)
1426 "Find all internal links and assign targets to them.
1427 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1428 let the link point to the corresponding section.
1429 This function also handles the id links, if they have a match in
1431 (goto-char (point-min))
1432 (while (re-search-forward org-bracket-link-regexp nil t
)
1434 (let* ((md (match-data))
1435 (desc (match-end 2))
1436 (link (org-link-unescape (match-string 1)))
1437 (slink (org-solidify-link-text link
))
1438 found props pos cref
1441 ((= (string-to-char link
) ?
#)
1442 ;; user wants exactly this link
1444 ((cdr (assoc slink target-alist
))
1445 (or (cdr (assoc (assoc slink target-alist
)
1446 org-export-preferred-target-alist
))
1447 (cdr (assoc slink target-alist
))))
1448 ((and (string-match "^id:" link
)
1449 (cdr (assoc (substring link
3) target-alist
))))
1450 ((string-match "^(\\(.*\\))$" link
)
1451 (setq cref
(match-string 1 link
))
1452 (concat "coderef:" cref
))
1453 ((string-match org-link-types-re link
) nil
)
1454 ((or (file-name-absolute-p link
)
1455 (string-match "^\\." link
))
1459 (setq found
(condition-case nil
(org-link-search link
)
1462 (or (org-on-heading-p)
1463 (not (eq found
'dedicated
))))
1464 (or (get-text-property (point) 'target
)
1467 (1- (or (previous-single-property-change
1468 (point) 'target
) 0)))
1472 (goto-char (match-beginning 1))
1473 (setq props
(text-properties-at (point)))
1474 (delete-region (match-beginning 1) (match-end 1))
1477 (unless desc
(insert "][" link
))
1478 (add-text-properties pos
(point) props
))))))
1480 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1481 "Remove drawers, or extract the content.
1482 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1483 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1484 whose content to keep."
1485 (unless (eq t exp-drawers
)
1486 (goto-char (point-min))
1487 (let ((re (concat "^[ \t]*:\\("
1490 (org-delete-all exp-drawers
1491 (copy-sequence all-drawers
))
1495 (while (re-search-forward re nil t
)
1497 (setq beg
(match-beginning 0)
1499 (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
1502 ;; terminated in this entry
1504 (delete-region beg
(match-end 1))
1506 (goto-char eol
))))))))
1508 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1509 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1510 Both arguments are lists of tags.
1511 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1513 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1515 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1516 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1519 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1523 (goto-char (point-min))
1524 (when (and select-tags
1526 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1527 ;; At least one tree is marked for export, this means
1528 ;; all the unmarked stuff needs to go.
1529 ;; Dig out the trees that should be exported
1530 (goto-char (point-min))
1531 (outline-next-heading)
1533 (put-text-property beg
(point-max) :org-delete t
)
1534 (while (re-search-forward re-sel nil t
)
1535 (when (org-on-heading-p)
1536 (org-back-to-heading)
1537 (remove-text-properties
1538 (max (1- (point)) (point-min))
1539 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1541 (while (and (org-up-heading-safe)
1542 (get-text-property (point) :org-delete
))
1543 (remove-text-properties (max (1- (point)) (point-min))
1544 (point-at-eol) '(:org-delete t
)))
1546 ;; Remove the trees explicitly marked for noexport
1548 (goto-char (point-min))
1549 (while (re-search-forward re-excl nil t
)
1550 (when (org-at-heading-p)
1551 (org-back-to-heading t
)
1553 (org-end-of-subtree t
)
1554 (delete-region beg
(point)))))
1555 ;; Remove everything that is now still marked for deletion
1556 (goto-char (point-min))
1557 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1558 (setq end
(or (next-single-property-change beg
:org-delete
)
1560 (delete-region beg end
))))
1562 (defun org-export-remove-archived-trees (export-archived-trees)
1563 "Remove archived trees.
1564 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1565 When it is t, the entire archived tree will be exported.
1566 When it is nil the entire tree including the headline will be removed
1568 (let ((re-archive (concat ":" org-archive-tag
":"))
1570 (when (not (eq export-archived-trees t
))
1571 (goto-char (point-min))
1572 (while (re-search-forward re-archive nil t
)
1573 (if (not (org-on-heading-p t
))
1574 (org-end-of-subtree t
)
1575 (beginning-of-line 1)
1576 (setq a
(if export-archived-trees
1577 (1+ (point-at-eol)) (point))
1578 b
(org-end-of-subtree t
))
1579 (if (> b a
) (delete-region a b
)))))))
1581 (defun org-export-remove-headline-metadata (opts)
1582 "Remove meta data from the headline, according to user options."
1583 (let ((re org-complex-heading-regexp
)
1584 (todo (plist-get opts
:todo-keywords
))
1585 (tags (plist-get opts
:tags
))
1586 (pri (plist-get opts
:priority
))
1589 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1590 (when (or (not todo
) (not tags
) (not pri
))
1591 (goto-char (point-min))
1592 (while (re-search-forward re nil t
)
1594 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1596 (replace-match rpl t t
))))))
1598 (defun org-export-remove-timestamps ()
1599 "Remove timestamps and keywords for export."
1600 (goto-char (point-min))
1601 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1604 (unless (save-match-data (org-at-table-p))
1606 (beginning-of-line 1)
1607 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1608 (replace-match ""))))))
1610 (defun org-export-remove-clock-lines ()
1611 "Remove clock lines for export."
1612 (goto-char (point-min))
1613 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1614 (while (re-search-forward re nil t
)
1616 (replace-match "")))))
1618 (defun org-export-protect-quoted-subtrees ()
1619 "Mark quoted subtrees with the protection property."
1620 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1621 (goto-char (point-min))
1622 (while (re-search-forward re-quote nil t
)
1623 (goto-char (match-beginning 0))
1625 (add-text-properties (point) (org-end-of-subtree t
)
1626 '(org-protected t
)))))
1628 (defun org-export-protect-verbatim ()
1629 "Mark verbatim snippets with the protection property."
1630 (goto-char (point-min))
1631 (while (re-search-forward org-verbatim-re nil t
)
1632 (add-text-properties (match-beginning 4) (match-end 4)
1634 (goto-char (1+ (match-end 4)))))
1636 (defun org-export-protect-colon-examples ()
1637 "Protect lines starting with a colon."
1638 (goto-char (point-min))
1639 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1640 (while (re-search-forward re nil t
)
1641 (beginning-of-line 1)
1643 (while (looking-at re
)
1645 (or (eobp) (forward-char 1)))
1646 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1647 '(org-protected t
)))))
1649 (defun org-export-select-backend-specific-text (backend)
1651 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1652 (html "HTML" "BEGIN_HTML" "END_HTML")
1653 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1654 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1655 (case-fold-search t
)
1659 (setq fmt
(pop formatters
))
1660 (when (eq (car fmt
) backend
)
1661 ;; This is selected code, put it into the file for real
1662 (goto-char (point-min))
1663 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1664 ":[ \t]*\\(.*\\)") nil t
)
1665 (replace-match "\\1\\2" t
)
1666 (add-text-properties
1667 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1668 '(org-protected t
))))
1669 (goto-char (point-min))
1670 (while (re-search-forward
1671 (concat "^[ \t]*#\\+" (caddr fmt
)
1672 "\\>.*\\(\\(\n.*\\)*?\n\\)[ \t]*#\\+" (cadddr fmt
)
1674 (if (eq (car fmt
) backend
)
1676 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1678 ;; No, this is for a different backend, kill it
1679 (delete-region (match-beginning 0) (match-end 0)))))))
1681 (defun org-export-mark-blockquote-verse-center ()
1682 "Mark block quote and verse environments with special cookies.
1683 These special cookies will later be interpreted by the backend."
1685 (let (type t1 ind beg end beg1 end1 content
)
1686 (goto-char (point-min))
1687 (while (re-search-forward
1688 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1690 (setq ind
(length (match-string 1))
1691 type
(downcase (match-string 3))
1692 t1
(if (equal type
"quote") "blockquote" type
))
1693 (setq beg
(match-beginning 0)
1694 beg1
(1+ (match-end 0)))
1695 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1696 (setq end
(1+ (point-at-eol))
1697 end1
(1- (match-beginning 0)))
1698 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1699 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1701 "ORG-" (upcase t1
) "-END\n"))
1702 (delete-region beg end
)
1703 (insert (org-add-props content nil
'original-indentation ind
))))))
1705 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1706 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1707 If the next thing following is a table, add the text properties to the first
1708 table line. If it is a link, add it to the line containing the link."
1709 (goto-char (point-min))
1710 (remove-text-properties (point-min) (point-max)
1711 '(org-caption nil org-attributes nil
))
1712 (let ((case-fold-search t
)
1713 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1715 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1717 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1721 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1723 (while (re-search-forward re nil t
)
1726 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1728 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1730 (setq label
(org-trim (match-string 3))))
1732 (add-text-properties (point-at-bol) (point-at-eol)
1733 (list 'org-caption cap
1734 'org-attributes attr
1736 (if label
(push (cons label label
) target-alist
))
1737 (setq cap nil attr nil label nil
)))))
1740 (defun org-export-remove-comment-blocks-and-subtrees ()
1741 "Remove the comment environment, and also commented subtrees."
1742 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1743 (case-fold-search nil
))
1744 ;; Remove comment environment
1745 (goto-char (point-min))
1746 (while (re-search-forward
1747 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1748 (replace-match "" t t
))
1749 ;; Remove subtrees that are commented
1750 (goto-char (point-min))
1751 (while (re-search-forward re-commented nil t
)
1752 (goto-char (match-beginning 0))
1753 (delete-region (point) (org-end-of-subtree t
)))))
1755 (defun org-export-handle-comments (commentsp)
1756 "Remove comments, or convert to backend-specific format.
1757 COMMENTSP can be a format string for publishing comments.
1758 When it is nil, all comments will be removed."
1759 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1761 (goto-char (point-min))
1762 (while (or (looking-at re
)
1763 (re-search-forward re nil t
))
1764 (setq pos
(match-beginning 0))
1766 (not (equal (char-before (match-end 1)) ?
+)))
1767 (progn (add-text-properties
1768 (match-beginning 0) (match-end 0) '(org-protected t
))
1769 (replace-match (format commentsp
(match-string 2)) t t
))
1770 (goto-char (1+ pos
))
1773 (goto-char (max (point-min) (1- pos
))))))))
1775 (defun org-export-mark-radio-links ()
1776 "Find all matches for radio targets and turn them into internal links."
1777 (let ((re-radio (and org-target-link-regexp
1778 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1779 (goto-char (point-min))
1781 (while (re-search-forward re-radio nil t
)
1783 (replace-match "\\1[[\\2]]"))))))
1785 (defun org-export-remove-special-table-lines ()
1786 "Remove tables lines that are used for internal purposes."
1787 (goto-char (point-min))
1788 (while (re-search-forward "^[ \t]*|" nil t
)
1789 (beginning-of-line 1)
1790 (if (or (looking-at "[ \t]*| *[!_^] *|")
1791 (and (looking-at ".*?| *<[0-9]+> *|")
1792 (not (looking-at ".*?| *[^ <|]"))))
1793 (delete-region (max (point-min) (1- (point-at-bol)))
1797 (defun org-export-normalize-links ()
1798 "Convert all links to bracket links, and expand link abbreviations."
1799 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1800 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1801 (goto-char (point-min))
1802 (while (re-search-forward re-plain-link nil t
)
1803 (goto-char (1- (match-end 0)))
1804 (org-if-unprotected-at (1+ (match-beginning 0))
1805 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1806 ":" (match-string 3) "]]")))
1807 ;; added 'org-link face to links
1808 (put-text-property 0 (length s
) 'face
'org-link s
)
1809 (replace-match s t t
))))
1810 (goto-char (point-min))
1811 (while (re-search-forward re-angle-link nil t
)
1812 (goto-char (1- (match-end 0)))
1814 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1815 ":" (match-string 3) "]]")))
1816 (put-text-property 0 (length s
) 'face
'org-link s
)
1817 (replace-match s t t
))))
1818 (goto-char (point-min))
1819 (while (re-search-forward org-bracket-link-regexp nil t
)
1820 (goto-char (1- (match-end 0)))
1822 (let* ((xx (save-match-data
1824 (org-link-expand-abbrev (match-string 1)))))
1826 "[[" (org-add-props (copy-sequence xx
)
1827 nil
'org-protected t
)
1831 (concat "[" (copy-sequence xx
)
1834 (put-text-property 0 (length s
) 'face
'org-link s
)
1835 (replace-match s t t
))))))
1837 (defun org-export-concatenate-multiline-links ()
1838 "Find multi-line links and put it all into a single line.
1839 This is to make sure that the line-processing export backends
1840 can work correctly."
1841 (goto-char (point-min))
1842 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1844 (replace-match "\\1 \\3")
1845 (goto-char (match-beginning 0)))))
1847 (defun org-export-concatenate-multiline-emphasis ()
1848 "Find multi-line emphasis and put it all into a single line.
1849 This is to make sure that the line-processing export backends
1850 can work correctly."
1851 (goto-char (point-min))
1852 (while (re-search-forward org-emph-re nil t
)
1853 (if (and (not (= (char-after (match-beginning 3))
1854 (char-after (match-beginning 4))))
1855 (save-excursion (goto-char (match-beginning 0))
1856 (save-match-data (not (org-at-table-p)))))
1858 (subst-char-in-region (match-beginning 0) (match-end 0)
1860 (goto-char (1- (match-end 0))))
1861 (goto-char (1+ (match-beginning 0))))))
1863 (defun org-export-grab-title-from-buffer ()
1864 "Get a title for the current document, from looking at the buffer."
1865 (let ((inhibit-read-only t
))
1867 (goto-char (point-min))
1868 (let ((end (if (looking-at org-outline-regexp
)
1870 (save-excursion (outline-next-heading) (point)))))
1871 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1872 ;; Mark the line so that it will not be exported as normal text.
1874 (add-text-properties (match-beginning 0) (match-end 0)
1875 (list :org-license-to-kill t
)))
1876 ;; Return the title string
1877 (org-trim (match-string 0)))))))
1879 (defun org-export-get-title-from-subtree ()
1880 "Return subtree title and exclude it from export."
1881 (let (title (rbeg (region-beginning)) (rend (region-end)))
1884 (when (and (org-at-heading-p)
1885 (>= (org-end-of-subtree t t
) rend
))
1886 ;; This is a subtree, we take the title from the first heading
1888 (looking-at org-todo-line-regexp
)
1889 (setq title
(match-string 3))
1891 (add-text-properties (point) (1+ (point-at-eol))
1892 (list :org-license-to-kill t
)))
1893 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1896 (defun org-solidify-link-text (s &optional alist
)
1897 "Take link text and make a safe target out of it."
1902 (org-split-string s
"[ \t\r\n]+") "=="))
1903 (a (assoc rtn alist
)))
1906 (defun org-get-min-level (lines &optional offset
)
1907 "Get the minimum level in LINES."
1908 (let ((re "^\\(\\*+\\) ") l
)
1910 (while (setq l
(pop lines
))
1911 (if (string-match re l
)
1912 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1916 ;; Variable holding the vector with section numbers
1917 (defvar org-section-numbers
(make-vector org-level-max
0))
1919 (defun org-init-section-numbers ()
1920 "Initialize the vector for the section numbers."
1922 (numbers (nreverse (org-split-string "" "\\.")))
1923 (depth (1- (length org-section-numbers
)))
1924 (i depth
) number-string
)
1927 (aset org-section-numbers i
0)
1928 (setq number-string
(or (car numbers
) "0"))
1929 (if (string-match "\\`[A-Z]\\'" number-string
)
1930 (aset org-section-numbers i
1931 (- (string-to-char number-string
) ?A -
1))
1932 (aset org-section-numbers i
(string-to-number number-string
)))
1936 (defun org-section-number (&optional level
)
1937 "Return a string with the current section number.
1938 When LEVEL is non-nil, increase section numbers on that level."
1939 (let* ((depth (1- (length org-section-numbers
)))
1941 (fmts (car org-export-section-number-format
))
1942 (term (cdr org-export-section-number-format
))
1947 (aset org-section-numbers
1948 level
(1+ (aref org-section-numbers level
))))
1949 (setq idx
(1+ level
))
1950 (while (<= idx depth
)
1952 (aset org-section-numbers idx
0))
1953 (setq idx
(1+ idx
))))
1955 (while (<= idx depth
)
1956 (when (> (aref org-section-numbers idx
) 0)
1957 (setq fmt
(or (pop fmts
) fmt
)
1959 n
(aref org-section-numbers idx
)
1961 (concat string sep
(org-number-to-counter n ctype
))
1962 (concat string
".0"))
1964 (setq idx
(1+ idx
)))
1966 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1967 (setq string
(replace-match "" t nil string
)))
1968 (if (string-match "\\(\\.0\\)+\\'" string
)
1969 (setq string
(replace-match "" t nil string
))))
1970 (concat string term
)))
1972 (defun org-number-to-counter (n type
)
1973 "Concert number N to a string counter, according to TYPE.
1974 TYPE must be a string, any of:
1978 I upper case roman numeral
1979 i lower case roman numeral"
1981 ((equal type
"1") (number-to-string n
))
1982 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1983 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1984 ((equal type
"I") (org-number-to-roman n
))
1985 ((equal type
"i") (downcase (org-number-to-roman n
)))
1986 (t (error "Invalid counter type `%s'" type
))))
1988 (defun org-number-to-roman (n)
1989 "Convert integer N into a roman numeral."
1990 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1991 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1992 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1996 (number-to-string n
)
1998 (if (>= n
(caar roman
))
1999 (setq n
(- n
(caar roman
))
2000 res
(concat res
(cdar roman
)))
2006 (defun org-export-preprocess-apply-macros ()
2007 "Replace macro references."
2008 (goto-char (point-min))
2009 (let (sy val key args args2 s n
)
2010 (while (re-search-forward
2011 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\(.*?\\))\\)?}}}"
2013 (setq key
(downcase (match-string 1))
2014 args
(match-string 3))
2015 (when (setq val
(or (plist-get org-export-opt-plist
2016 (intern (concat ":macro-" key
)))
2017 (plist-get org-export-opt-plist
2018 (intern (concat ":" key
)))))
2021 (setq args
(org-split-string args
";") args2 nil
)
2023 (while (string-match "\\\\\\'" (car args
))
2024 ;; repair bad splits
2025 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2028 (push (pop args
) args2
))
2029 (setq args
(nreverse args2
))
2031 (while (string-match "\\$\\([0-9]+\\)" val s
)
2032 (setq s
(1+ (match-beginning 0))
2033 n
(string-to-number (match-string 1 val
)))
2034 (and (>= (length args
) n
)
2035 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2036 (when (string-match "\\`(eval\\>" val
)
2037 (setq val
(eval (read val
))))
2038 (if (and val
(not (stringp val
)))
2039 (setq val
(format "%s" val
))))
2041 (replace-match val t t
))))))
2043 (defun org-export-apply-macros-in-string (s)
2044 "Apply the macros in string S."
2048 (org-export-preprocess-apply-macros)
2053 (defun org-export-handle-include-files ()
2054 "Include the contents of include files, with proper formatting."
2055 (let ((case-fold-search t
)
2056 params file markup lang start end prefix prefix1 switches
)
2057 (goto-char (point-min))
2058 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2059 (setq params
(read (concat "(" (match-string 1) ")"))
2060 prefix
(org-get-and-remove-property 'params
:prefix
)
2061 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2062 file
(org-symname-or-string (pop params
))
2063 markup
(org-symname-or-string (pop params
))
2064 lang
(and (member markup
'("src" "SRC"))
2065 (org-symname-or-string (pop params
)))
2066 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2067 (delete-region (match-beginning 0) (match-end 0))
2069 (not (file-exists-p file
))
2070 (not (file-readable-p file
)))
2071 (insert (format "CANNOT INCLUDE FILE %s" file
))
2073 (if (equal (downcase markup
) "src")
2074 (setq start
(format "#+begin_src %s %s\n"
2075 (or lang
"fundamental")
2078 (setq start
(format "#+begin_%s %s\n" markup switches
)
2079 end
(format "#+end_%s" markup
))))
2080 (insert (or start
""))
2081 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2082 (or (bolp) (newline))
2083 (insert (or end
""))))))
2085 (defun org-get-file-contents (file &optional prefix prefix1
)
2086 "Get the contents of FILE and return them as a string.
2087 If PREFIX is a string, prepend it to each line. If PREFIX1
2088 is a string, prepend it to the first line instead of PREFIX."
2090 (insert-file-contents file
)
2091 (when (or prefix prefix1
)
2092 (goto-char (point-min))
2094 (insert (or prefix1 prefix
))
2096 (beginning-of-line 2)))
2099 (defun org-get-and-remove-property (listvar prop
)
2100 "Check if the value of LISTVAR contains PROP as a property.
2101 If yes, return the value of that property (i.e. the element following
2102 in the list) and remove property and value from the list in LISTVAR."
2103 (let ((list (symbol-value listvar
)) m v
)
2104 (when (setq m
(member prop list
))
2106 (if (equal (car list
) prop
)
2107 (set listvar
(cddr list
))
2108 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2110 (set listvar list
)))
2113 (defun org-symname-or-string (s)
2115 (if s
(symbol-name s
) s
)
2118 ;;; Fontification and line numbers for code examples
2120 (defvar org-export-last-code-line-counter-value
0)
2122 (defun org-export-replace-src-segments-and-examples (backend)
2123 "Replace source code segments with special code for export."
2124 (setq org-export-last-code-line-counter-value
0)
2125 (let ((case-fold-search t
)
2126 lang code trans opts indent
)
2127 (goto-char (point-min))
2128 (while (re-search-forward
2129 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
2133 (setq lang
(match-string 3)
2134 opts
(match-string 4)
2135 code
(match-string 5)
2136 indent
(length (match-string 2)))
2138 opts
(match-string 8)
2139 code
(match-string 9)
2140 indent
(length (match-string 7))))
2142 (setq trans
(org-export-format-source-code-or-example
2143 backend lang code opts indent
))
2144 (replace-match trans t t
))))
2146 (defvar htmlp
) ;; dynamically scoped
2147 (defvar latexp
) ;; dynamically scoped
2149 (defun org-export-format-source-code-or-example
2150 (backend lang code
&optional opts indent
)
2151 "Format CODE from language LANG and return it formatted for export.
2152 If LANG is nil, do not add any fontification.
2153 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2154 and `+n' for continuing previous numering.
2155 Code formatting according to language currently only works for HTML.
2156 Numbering lines works for all three major backends (html, latex, and ascii).
2157 INDENT was the original indentation of the block."
2159 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2160 (setq opts
(or opts
"")
2161 num
(string-match "[-+]n\\>" opts
)
2162 cont
(string-match "\\+n\\>" opts
)
2163 rpllbl
(string-match "-r\\>" opts
)
2164 keepp
(string-match "-k\\>" opts
)
2165 textareap
(string-match "-t\\>" opts
)
2166 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2167 (string-to-number (match-string 1 opts
))
2169 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2170 (string-to-number (match-string 1 opts
))
2171 (org-count-lines code
))
2172 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2173 (match-string 1 opts
)))
2174 (when (and textareap
(eq backend
'html
))
2175 ;; we cannot use numbering or highlighting.
2176 (setq num nil cont nil lang nil
))
2177 (if keepp
(setq rpllbl
'keep
))
2178 (setq rtn
(org-remove-indentation code
))
2179 (when (string-match "^," rtn
)
2180 (setq rtn
(with-temp-buffer
2182 ;; Free up the protected lines
2183 (goto-char (point-min))
2184 (while (re-search-forward "^," nil t
)
2185 (if (or (equal lang
"org")
2187 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2191 ;; Now backend-specific coding
2194 ((eq backend
'docbook
)
2195 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2196 (concat "\n#+BEGIN_DOCBOOK\n"
2197 (org-add-props (concat "<programlisting><![CDATA["
2199 "]]>\n</programlisting>\n")
2203 ;; We are exporting to HTML
2205 (require 'htmlize nil t
)
2206 (when (not (fboundp 'htmlize-region-for-paste
))
2207 ;; we do not have htmlize.el, or an old version of it
2210 "htmlize.el 1.34 or later is needed for source code formatting")))
2213 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2214 (org-inhibit-startup t
)
2215 (org-startup-folded nil
))
2219 (if (functionp mode
)
2222 (font-lock-fontify-buffer)
2224 (set-buffer-modified-p nil
)
2225 (org-export-htmlize-region-for-paste
2226 (point-min) (point-max))))
2227 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2228 (setq rtn
(replace-match
2229 (format "<pre class=\"src src-%s\">\n" lang
)
2233 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2235 rtn
"</textarea>\n</p>\n"))
2238 (goto-char (point-min))
2239 (while (re-search-forward "[<>&]" nil t
)
2240 (replace-match (cdr (assq (char-before)
2241 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2243 (setq rtn
(buffer-string)))
2244 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2246 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2248 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2249 ((eq backend
'latex
)
2250 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2251 (concat "\n#+BEGIN_LaTeX\n"
2252 (org-add-props (concat "\\begin{verbatim}\n" rtn
"\n\\end{verbatim}\n")
2255 ((eq backend
'ascii
)
2256 ;; This is not HTML or LaTeX, so just make it an example.
2257 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2258 (concat "#+BEGIN_ASCII\n"
2262 (lambda (l) (concat " " l
))
2263 (org-split-string rtn
"\n")
2268 (org-add-props rtn nil
'original-indentation indent
))))
2270 (defun org-export-number-lines (text backend
2271 &optional skip1 skip2 number cont
2272 replace-labels label-format
)
2273 (if (and (not number
) (not (eq replace-labels
'keep
)))
2274 (setq replace-labels nil
)) ;; must use names if no numbers
2275 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2276 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2279 (goto-char (point-max))
2280 (skip-chars-backward " \t\n\r")
2281 (delete-region (point) (point-max))
2282 (beginning-of-line (- 1 skip2
))
2283 (let* ((last (org-current-line))
2284 (n org-export-last-code-line-counter-value
)
2285 (nmax (+ n
(- last skip1
)))
2286 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2289 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2291 ((eq backend
'ascii
) fmt
)
2292 ((eq backend
'latex
) fmt
)
2293 ((eq backend
'docbook
) fmt
)
2295 (label-format (or label-format org-coderef-label-format
))
2296 (label-pre (if (string-match "%s" label-format
)
2297 (substring label-format
0 (match-beginning 0))
2299 (label-post (if (string-match "%s" label-format
)
2300 (substring label-format
(match-end 0))
2304 ".*?\\S-.*?\\([ \t]*\\("
2305 (regexp-quote label-pre
)
2306 "\\([-a-zA-Z0-9_]+\\)"
2307 (regexp-quote label-post
)
2311 (goto-line (1+ skip1
))
2312 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2314 (insert (format fm
(incf n
)))
2316 (when (and (not (eq replace-labels
'keep
))
2317 (looking-at lbl-re
))
2318 (setq ref
(match-string 3))
2321 (delete-region (match-beginning 1) (match-end 1))
2322 (push (cons ref n
) org-export-code-refs
))
2323 (goto-char (match-beginning 2))
2324 (delete-region (match-beginning 2) (match-end 2))
2325 (insert "(" ref
")")
2326 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2327 (when (eq backend
'html
)
2329 (beginning-of-line 1)
2330 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2333 (insert "</span>")))))
2334 (setq org-export-last-code-line-counter-value n
)
2335 (goto-char (point-max))
2339 (defun org-search-todo-below (line lines level
)
2340 "Search the subtree below LINE for any TODO entries."
2341 (let ((rest (cdr (memq line lines
)))
2342 (re org-todo-line-regexp
)
2345 (while (setq line
(pop rest
))
2346 (if (string-match re line
)
2348 (setq lv
(- (match-end 1) (match-beginning 1))
2349 todo
(and (match-beginning 2)
2350 (not (member (match-string 2 line
)
2351 org-done-keywords
))))
2353 (if (<= lv level
) (throw 'exit nil
))
2354 (if todo
(throw 'exit t
))))))))
2357 (defun org-export-visible (type arg
)
2358 "Create a copy of the visible part of the current buffer, and export it.
2359 The copy is created in a temporary buffer and removed after use.
2360 TYPE is the final key (as a string) that also select the export command in
2361 the `C-c C-e' export dispatcher.
2362 As a special case, if the you type SPC at the prompt, the temporary
2363 org-mode file will not be removed but presented to you so that you can
2364 continue to use it. The prefix arg ARG is passed through to the exporting
2368 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2369 (read-char-exclusive))
2370 current-prefix-arg
))
2371 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\
)))
2372 (error "Invalid export key"))
2373 (let* ((binding (cdr (assoc type
2374 '((?a . org-export-as-ascii
)
2375 (?A . org-export-as-ascii-to-buffer
)
2376 (?\C-a . org-export-as-ascii
)
2377 (?b . org-export-as-html-and-open
)
2378 (?\C-b . org-export-as-html-and-open
)
2379 (?h . org-export-as-html
)
2380 (?H . org-export-as-html-to-buffer
)
2381 (?R . org-export-region-as-html
)
2382 (?D . org-export-as-docbook
)
2383 (?x . org-export-as-xoxo
)))))
2384 (keepp (equal type ?\
))
2385 (file buffer-file-name
)
2386 (buffer (get-buffer-create "*Org Export Visible*"))
2388 ;; Need to hack the drawers here.
2390 (goto-char (point-min))
2391 (while (re-search-forward org-drawer-regexp nil t
)
2392 (goto-char (match-beginning 1))
2393 (or (org-invisible-p) (org-flag-drawer nil
))))
2394 (with-current-buffer buffer
(erase-buffer))
2396 (setq s
(goto-char (point-min)))
2397 (while (not (= (point) (point-max)))
2398 (goto-char (org-find-invisible))
2399 (append-to-buffer buffer s
(point))
2400 (setq s
(goto-char (org-find-visible))))
2401 (org-cycle-hide-drawers 'all
)
2402 (goto-char (point-min))
2404 ;; Copy all comment lines to the end, to make sure #+ settings are
2405 ;; still available for the second export step. Kind of a hack, but
2406 ;; does do the trick.
2407 (if (looking-at "#[^\r\n]*")
2408 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2409 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2410 (append-to-buffer buffer
(1+ (match-beginning 0))
2411 (min (point-max) (1+ (match-end 0))))))
2413 (let ((buffer-file-name file
)
2414 (org-inhibit-startup t
))
2417 (unless keepp
(funcall binding arg
))))
2419 (kill-buffer buffer
)
2420 (switch-to-buffer-other-window buffer
)
2421 (goto-char (point-min)))))
2423 (defun org-find-visible ()
2425 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2426 (get-char-property s
'invisible
)))
2428 (defun org-find-invisible ()
2430 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2431 (not (get-char-property s
'invisible
))))
2434 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2437 (defun org-export-as-org (arg &optional hidden ext-plist
2438 to-buffer body-only pub-dir
)
2439 "Make a copy wiht not-exporting stuff removed.
2440 The purpose of this function is to provide a way to export the source
2441 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2442 stuff removed. This command will remove the following:
2444 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2445 - comment blocks and trees starting with the COMMENT keyword
2446 - only trees that are consistent with `org-export-select-tags'
2447 and `org-export-exclude-tags'.
2449 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2450 all the others will be ignored (but are present so that the general
2451 mechanism to call publishing functions will work).
2453 EXT-PLIST is a property list with external parameters overriding
2454 org-mode's default settings, but still inferior to file-local
2455 settings. When PUB-DIR is set, use this as the publishing
2458 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2460 (org-infile-export-plist)))
2461 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2462 (filename (concat (file-name-as-directory
2464 (org-export-directory :org opt-plist
)))
2465 (file-name-sans-extension
2466 (file-name-nondirectory bfname
))
2468 (filename (and filename
2469 (if (equal (file-truename filename
)
2470 (file-truename bfname
))
2471 (concat filename
"-source")
2473 (backup-inhibited t
)
2474 (buffer (find-file-noselect filename
))
2475 (region (buffer-string)))
2477 (switch-to-buffer buffer
)
2480 (let ((org-inhibit-startup t
)) (org-mode))
2482 ;; Get rid of archived trees
2483 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2485 ;; Remove comment environment and comment subtrees
2486 (org-export-remove-comment-blocks-and-subtrees)
2488 ;; Get rid of excluded trees
2489 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2490 (plist-get opt-plist
:exclude-tags
))
2492 (when (or (plist-get opt-plist
:plain-source
)
2493 (not (or (plist-get opt-plist
:plain-source
)
2494 (plist-get opt-plist
:htmlized-source
))))
2495 ;; Either nothing special is requested (default call)
2496 ;; or the plain source is explicitly requested
2499 (when (plist-get opt-plist
:htmlized-source
)
2500 ;; Make the htmlized version
2503 (font-lock-fontify-buffer)
2504 (let* ((htmlize-output-type 'css
)
2505 (newbuf (htmlize-buffer)))
2506 (with-current-buffer newbuf
2507 (when org-export-htmlized-org-css-url
2508 (goto-char (point-min))
2509 (and (re-search-forward
2510 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2514 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2515 org-export-htmlized-org-css-url
)
2517 (write-file (concat filename
".html")))
2518 (kill-buffer newbuf
)))
2519 (set-buffer-modified-p nil
)
2520 (kill-buffer (current-buffer)))))
2522 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2523 (defun org-get-current-options ()
2524 "Return a string with current options as keyword options.
2525 Does include HTML export options as well as TODO and CATEGORY stuff."
2526 (require 'org-archive
)
2535 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2536 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2538 #+EXPORT_SELECT_TAGS: %s
2539 #+EXPORT_EXCLUDE_TAGS: %s
2545 #+PRIORITIES: %c %c %c
2547 #+STARTUP: %s %s %s %s %s
2553 (buffer-name) (user-full-name) user-mail-address
2554 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2555 org-export-default-language
2556 org-export-headline-levels
2557 org-export-with-section-numbers
2559 org-export-preserve-breaks
2560 org-export-html-expand
2561 org-export-with-fixed-width
2562 org-export-with-tables
2563 org-export-with-sub-superscripts
2564 org-export-with-special-strings
2565 org-export-with-footnotes
2566 org-export-with-emphasize
2567 org-export-with-timestamps
2568 org-export-with-TeX-macros
2569 org-export-with-LaTeX-fragments
2570 org-export-skip-text-before-1st-heading
2571 org-export-with-drawers
2572 org-export-with-todo-keywords
2573 org-export-with-priority
2574 org-export-with-tags
2575 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2576 (mapconcat 'identity org-export-select-tags
" ")
2577 (mapconcat 'identity org-export-exclude-tags
" ")
2578 org-export-html-link-up
2579 org-export-html-link-home
2581 (file-name-sans-extension
2582 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2584 "TODO FEEDBACK VERIFY DONE"
2585 "Me Jason Marie DONE"
2586 org-highest-priority org-lowest-priority org-default-priority
2587 (mapconcat 'identity org-drawers
" ")
2588 (cdr (assoc org-startup-folded
2589 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2590 (if org-odd-levels-only
"odd" "oddeven")
2591 (if org-hide-leading-stars
"hidestars" "showstars")
2592 (if org-startup-align-all-tables
"align" "noalign")
2593 (cond ((eq org-log-done t
) "logdone")
2594 ((equal org-log-done
'note
) "lognotedone")
2595 ((not org-log-done
) "nologdone"))
2596 (or (mapconcat (lambda (x)
2598 ((equal '(:startgroup
) x
) "{")
2599 ((equal '(:endgroup
) x
) "}")
2600 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2602 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2603 (mapconcat 'identity org-file-tags
" ")
2604 org-archive-location
2605 "org file:~/org/%s.org"
2609 (defun org-insert-export-options-template ()
2610 "Insert into the buffer a template with information for exporting."
2612 (if (not (bolp)) (newline))
2613 (let ((s (org-get-current-options)))
2614 (and (string-match "#\\+CATEGORY" s
)
2615 (setq s
(substring s
0 (match-beginning 0))))
2618 (defvar org-table-colgroup-info nil
)
2620 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2621 "Check if the table has a marking column.
2622 If yes remove the column and the special lines."
2623 (setq org-table-colgroup-info nil
)
2626 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2629 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2630 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2634 (setq org-table-clean-did-remove-column nil
)
2639 ((string-match "^[ \t]*| */ *|" x
)
2640 (setq org-table-colgroup-info
2642 (cond ((member x
'("<" "<")) :start
)
2643 ((member x
'(">" ">")) :end
)
2644 ((member x
'("<>" "<>")) :startend
)
2646 (org-split-string x
"[ \t]*|[ \t]*")))
2650 (setq org-table-clean-did-remove-column t
)
2655 ((string-match "^[ \t]*| */ *|" x
)
2656 (setq org-table-colgroup-info
2658 (cond ((member x
'("<" "<")) :start
)
2659 ((member x
'(">" ">")) :end
)
2660 ((member x
'("<>" "<>")) :startend
)
2662 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2664 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2665 nil
) ; ignore this line
2666 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2667 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2668 ;; remove the first column
2669 (replace-match "\\1|" t nil x
))))
2672 (defun org-export-cleanup-toc-line (s)
2673 "Remove tags and timestamps from lines going into the toc."
2674 (when (memq org-export-with-tags
'(not-in-toc nil
))
2675 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2676 (setq s
(replace-match "" t t s
))))
2677 (when org-export-remove-timestamps-from-toc
2678 (while (string-match org-maybe-keyword-time-regexp s
)
2679 (setq s
(replace-match "" t t s
))))
2680 (while (string-match org-bracket-link-regexp s
)
2681 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2685 (defun org-create-multibrace-regexp (left right n
)
2686 "Create a regular expression which will match a balanced sexp.
2687 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2688 as single character strings.
2689 The regexp returned will match the entire expression including the
2690 delimiters. It will also define a single group which contains the
2691 match except for the outermost delimiters. The maximum depth of
2692 stacked delimiters is N. Escaping delimiters is not possible."
2693 (let* ((nothing (concat "[^" left right
"]*?"))
2696 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
2699 re
(concat re or next
)
2700 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
2701 (concat left
"\\(" re
"\\)" right
)))
2703 (defvar org-match-substring-regexp
2705 "\\([^\\]\\)\\([_^]\\)\\("
2706 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2708 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
2710 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2711 "The regular expression matching a sub- or superscript.")
2713 (defvar org-match-substring-with-braces-regexp
2715 "\\([^\\]\\)\\([_^]\\)\\("
2716 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2718 "The regular expression matching a sub- or superscript, forcing braces.")
2721 (defun org-get-text-property-any (pos prop
&optional object
)
2722 (or (get-text-property pos prop object
)
2723 (and (setq pos
(next-single-property-change pos prop object
))
2724 (get-text-property pos prop object
))))
2726 (defun org-export-get-coderef-format (path desc
)
2728 (if (and desc
(string-match
2729 (regexp-quote (concat "(" path
")"))
2731 (replace-match "%s" t t desc
)
2734 (defun org-export-push-to-kill-ring (format)
2735 "Push buffer content to kill ring.
2736 The depends on the variable `org-export-copy-to-kill'."
2737 (when org-export-copy-to-kill-ring
2738 (kill-new (buffer-string))
2739 (when (fboundp 'x-set-selection
)
2740 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
2741 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
2742 (message "%s export done, pushed to kill ring and clipboard" format
)))
2746 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2748 ;;; org-exp.el ends here