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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
35 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
36 (declare-function org-export-html-preprocess
"org-html" (parameters))
37 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
38 (declare-function org-agenda-skip
"org-agenda" ())
39 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
40 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
41 (declare-function htmlize-buffer
"htmlize" (&optional buffer
))
43 (defgroup org-export nil
44 "Options for exporting org-listings."
48 (defgroup org-export-general nil
49 "General options for exporting Org-mode files."
50 :tag
"Org Export General"
54 (defvar org-export-publishing-directory nil
)
56 (defcustom org-export-show-temporary-export-buffer t
57 "Non-nil means, show buffer after exporting to temp buffer.
58 When Org exports to a file, the buffer visiting that file is ever
59 shown, but remains buried. However, when exporting to a temporary
60 buffer, that buffer is popped up in a second window. When this variable
61 is nil, the buffer remains buried also in these cases."
62 :group
'org-export-general
65 (defcustom org-export-copy-to-kill-ring t
66 "Non-nil means, exported stuff will also be pushed onto the kill ring."
67 :group
'org-export-general
70 (defcustom org-export-run-in-background nil
71 "Non-nil means export and publishing commands will run in background.
72 This works by starting up a separate Emacs process visiting the same file
73 and doing the export from there.
74 Not all export commands are affected by this - only the ones which
75 actually write to a file, and that do not depend on the buffer state.
77 If this option is nil, you can still get background export by calling
78 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
80 If this option is t, the double prefix can be used to exceptionally
81 force an export command into the current process."
82 :group
'org-export-general
85 (defcustom org-export-select-tags
'("export")
86 "Tags that select a tree for export.
87 If any such tag is found in a buffer, all trees that do not carry one
88 of these tags will be deleted before export.
89 Inside trees that are selected like this, you can still deselect a
90 subtree by tagging it with one of the `org-export-exclude-tags'."
91 :group
'org-export-general
92 :type
'(repeat (string :tag
"Tag")))
94 (defcustom org-export-exclude-tags
'("noexport")
95 "Tags that exclude a tree from export.
96 All trees carrying any of these tags will be excluded from export.
97 This is without condition, so even subtrees inside that carry one of the
98 `org-export-select-tags' will be removed."
99 :group
'org-export-general
100 :type
'(repeat (string :tag
"Tag")))
102 ;; FIXME: rename, this is a general variable
103 (defcustom org-export-html-expand t
104 "Non-nil means, for HTML export, treat @<...> as HTML tag.
105 When nil, these tags will be exported as plain text and therefore
106 not be interpreted by a browser.
108 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
109 :group
'org-export-html
110 :group
'org-export-general
113 (defcustom org-export-with-special-strings t
114 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
115 When this option is turned on, these strings will be exported as:
118 -----+----------+--------
124 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
125 :group
'org-export-translation
128 (defcustom org-export-html-link-up
""
129 "Where should the \"UP\" link of exported HTML pages lead?"
130 :group
'org-export-html
131 :group
'org-export-general
132 :type
'(string :tag
"File or URL"))
134 (defcustom org-export-html-link-home
""
135 "Where should the \"HOME\" link of exported HTML pages lead?"
136 :group
'org-export-html
137 :group
'org-export-general
138 :type
'(string :tag
"File or URL"))
140 (defcustom org-export-language-setup
141 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
142 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
143 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
144 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
145 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
146 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
147 ("es" "Autor" "Fecha" "Índice" "Pies de página")
148 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
149 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
150 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
151 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
152 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
153 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
154 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
155 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
156 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
157 ("pl" "Autor" "Data" "Spis treści" "Przypis")
158 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
159 "Terms used in export text, translated to different languages.
160 Use the variable `org-export-default-language' to set the language,
161 or use the +OPTION lines for a per-file setting."
162 :group
'org-export-general
165 (string :tag
"HTML language tag")
166 (string :tag
"Author")
168 (string :tag
"Table of Contents")
169 (string :tag
"Footnotes"))))
171 (defcustom org-export-default-language
"en"
172 "The default language of HTML export, as a string.
173 This should have an association in `org-export-language-setup'."
174 :group
'org-export-general
177 (defvar org-export-page-description
""
178 "The page description, for the XHTML meta tag.
179 This is best set with the #+DESCRIPTION line in a file, it does not make
180 sense to set this globally.")
182 (defvar org-export-page-keywords
""
183 "The page description, for the XHTML meta tag.
184 This is best set with the #+KEYWORDS line in a file, it does not make
185 sense to set this globally.")
187 (defcustom org-export-skip-text-before-1st-heading nil
188 "Non-nil means, skip all text before the first headline when exporting.
189 When nil, that text is exported as well."
190 :group
'org-export-general
193 (defcustom org-export-headline-levels
3
194 "The last level which is still exported as a headline.
195 Inferior levels will produce itemize lists when exported.
196 Note that a numeric prefix argument to an exporter function overrides
199 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
200 :group
'org-export-general
203 (defcustom org-export-with-section-numbers t
204 "Non-nil means, add section numbers to headlines when exporting.
206 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
207 :group
'org-export-general
210 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
211 "Format of section numbers for export.
212 The variable has two components.
213 1. A list of lists, each indicating a counter type and a separator.
214 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
215 It causes causes numeric, alphabetic, or roman counters, respectively.
216 The separator is only used if another counter for a subsection is being
218 If there are more numbered section levels than entries in this lists,
219 then the last entry will be reused.
220 2. A terminator string that will be added after the entire
222 :group
'org-export-general
226 (string :tag
"Counter Type")
227 (string :tag
"Separator ")))
228 (string :tag
"Terminator")))
230 (defcustom org-export-with-toc t
231 "Non-nil means, create a table of contents in exported files.
232 The TOC contains headlines with levels up to`org-export-headline-levels'.
233 When an integer, include levels up to N in the toc, this may then be
234 different from `org-export-headline-levels', but it will not be allowed
235 to be larger than the number of headline levels.
236 When nil, no table of contents is made.
238 Headlines which contain any TODO items will be marked with \"(*)\" in
239 ASCII export, and with red color in HTML output, if the option
240 `org-export-mark-todo-in-toc' is set.
242 In HTML output, the TOC will be clickable.
244 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
246 :group
'org-export-general
248 (const :tag
"No Table of Contents" nil
)
249 (const :tag
"Full Table of Contents" t
)
250 (integer :tag
"TOC to level")))
252 (defcustom org-export-mark-todo-in-toc nil
253 "Non-nil means, mark TOC lines that contain any open TODO items."
254 :group
'org-export-general
257 (defcustom org-export-with-todo-keywords t
258 "Non-nil means, include TODO keywords in export.
259 When nil, remove all these keywords from the export."
260 :group
'org-export-general
263 (defcustom org-export-with-priority nil
264 "Non-nil means, include priority cookies in export.
265 When nil, remove priority cookies for export."
266 :group
'org-export-general
269 (defcustom org-export-preserve-breaks nil
270 "Non-nil means, preserve all line breaks when exporting.
271 Normally, in HTML output paragraphs will be reformatted. In ASCII
272 export, line breaks will always be preserved, regardless of this variable.
274 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
275 :group
'org-export-general
278 (defcustom org-export-with-archived-trees
'headline
279 "Whether subtrees with the ARCHIVE tag should be exported.
280 This can have three different values
281 nil Do not export, pretend this tree is not present
282 t Do export the entire tree
283 headline Only export the headline, but skip the tree below it."
284 :group
'org-export-general
287 (const :tag
"not at all" nil
)
288 (const :tag
"headline only" 'headline
)
289 (const :tag
"entirely" t
)))
291 (defcustom org-export-author-info t
292 "Non-nil means, insert author name and email into the exported file.
294 This option can also be set with the +OPTIONS line,
295 e.g. \"author-info:nil\"."
296 :group
'org-export-general
299 (defcustom org-export-creator-info t
300 "Non-nil means, the postamble should contain a creator sentence.
301 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
302 :group
'org-export-general
305 (defcustom org-export-time-stamp-file t
306 "Non-nil means, insert a time stamp into the exported file.
307 The time stamp shows when the file was created.
309 This option can also be set with the +OPTIONS line,
310 e.g. \"timestamp:nil\"."
311 :group
'org-export-general
314 (defcustom org-export-with-timestamps t
315 "If nil, do not export time stamps and associated keywords."
316 :group
'org-export-general
319 (defcustom org-export-remove-timestamps-from-toc t
320 "If nil, remove timestamps from the table of contents entries."
321 :group
'org-export-general
324 (defcustom org-export-with-tags
'not-in-toc
325 "If nil, do not export tags, just remove them from headlines.
326 If this is the symbol `not-in-toc', tags will be removed from table of
327 contents entries, but still be shown in the headlines of the document.
329 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
330 :group
'org-export-general
332 (const :tag
"Off" nil
)
333 (const :tag
"Not in TOC" not-in-toc
)
334 (const :tag
"On" t
)))
336 (defcustom org-export-with-drawers nil
337 "Non-nil means, export with drawers like the property drawer.
338 When t, all drawers are exported. This may also be a list of
339 drawer names to export."
340 :group
'org-export-general
342 (const :tag
"All drawers" t
)
343 (const :tag
"None" nil
)
344 (repeat :tag
"Selected drawers"
345 (string :tag
"Drawer name"))))
347 (defvar org-export-preprocess-hook nil
348 "Hook for preprocessing an export buffer.
349 Pretty much the first thing when exporting is running this hook.")
351 (defvar org-export-preprocess-after-include-files-hook nil
352 "Hook for preprocessing an export buffer.
353 This is run after the contents of included files have been inserted.")
355 (defvar org-export-preprocess-after-tree-selection-hook nil
356 "Hook for preprocessing an export buffer.
357 This is run after selection of trees to be exported has happened.
358 This selection includes tags-based selection, as well as removal
359 of commented and archived trees.")
361 (defvar org-export-preprocess-after-blockquote-hook nil
362 "Hook for preprocessing an export buffer.
363 This is run after blockquote/quote/verse/center have been marked
366 (defvar org-export-preprocess-before-backend-specifics-hook nil
367 "Hook run before backend-specific functions are called during preprocessing.")
369 (defvar org-export-preprocess-final-hook nil
370 "Hook for preprocessing an export buffer.
371 This is run as the last thing in the preprocessing buffer, just before
372 returning the buffer string to the backend.")
374 (defgroup org-export-translation nil
375 "Options for translating special ascii sequences for the export backends."
376 :tag
"Org Export Translation"
379 (defcustom org-export-with-emphasize t
380 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
381 If the export target supports emphasizing text, the word will be
382 typeset in bold, italic, or underlined, respectively. Works only for
383 single words, but you can say: I *really* *mean* *this*.
384 Not all export backends support this.
386 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
387 :group
'org-export-translation
390 (defcustom org-export-with-footnotes t
391 "If nil, export [1] as a footnote marker.
392 Lines starting with [1] will be formatted as footnotes.
394 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
395 :group
'org-export-translation
398 (defcustom org-export-with-sub-superscripts t
399 "Non-nil means, interpret \"_\" and \"^\" for export.
400 When this option is turned on, you can use TeX-like syntax for sub- and
401 superscripts. Several characters after \"_\" or \"^\" will be
402 considered as a single item - so grouping with {} is normally not
403 needed. For example, the following things will be parsed as single
404 sub- or superscripts.
406 10^24 or 10^tau several digits will be considered 1 item.
407 10^-12 or 10^-tau a leading sign with digits or a word
408 x^2-y^3 will be read as x^2 - y^3, because items are
409 terminated by almost any nonword/nondigit char.
410 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
412 Still, ambiguity is possible - so when in doubt use {} to enclose the
413 sub/superscript. If you set this variable to the symbol `{}',
414 the braces are *required* in order to trigger interpretations as
415 sub/superscript. This can be helpful in documents that need \"_\"
416 frequently in plain text.
418 Not all export backends support this, but HTML does.
420 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
421 :group
'org-export-translation
423 (const :tag
"Always interpret" t
)
424 (const :tag
"Only with braces" {})
425 (const :tag
"Never interpret" nil
)))
427 (defcustom org-export-with-TeX-macros t
428 "Non-nil means, interpret simple TeX-like macros when exporting.
429 For example, HTML export converts \\alpha to α and \\AA to Å.
430 Not only real TeX macros will work here, but the standard HTML entities
431 for math can be used as macro names as well. For a list of supported
432 names in HTML export, see the constant `org-html-entities'.
433 Not all export backends support this.
435 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
436 :group
'org-export-translation
437 :group
'org-export-latex
440 (defcustom org-export-with-LaTeX-fragments nil
441 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
442 When set, the exporter will find LaTeX environments if the \\begin line is
443 the first non-white thing on a line. It will also find the math delimiters
444 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
447 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
449 The default is nil, because this option needs the `dvipng' program which
450 is not available on all systems."
451 :group
'org-export-translation
452 :group
'org-export-latex
455 (defcustom org-export-with-fixed-width t
456 "Non-nil means, lines starting with \":\" will be in fixed width font.
457 This can be used to have pre-formatted text, fragments of code etc. For
459 : ;; Some Lisp examples
462 will be looking just like this in also HTML. See also the QUOTE keyword.
463 Not all export backends support this.
465 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
466 :group
'org-export-translation
469 (defcustom org-match-sexp-depth
3
470 "Number of stacked braces for sub/superscript matching.
471 This has to be set before loading org.el to be effective."
472 :group
'org-export-translation
475 (defgroup org-export-tables nil
476 "Options for exporting tables in Org-mode."
477 :tag
"Org Export Tables"
480 (defcustom org-export-with-tables t
481 "If non-nil, lines starting with \"|\" define a table.
484 | Name | Address | Birthday |
485 |-------------+----------+-----------|
486 | Arthur Dent | England | 29.2.2100 |
488 Not all export backends support this.
490 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
491 :group
'org-export-tables
494 (defcustom org-export-highlight-first-table-line t
495 "Non-nil means, highlight the first table line.
496 In HTML export, this means use <th> instead of <td>.
497 In tables created with table.el, this applies to the first table line.
498 In Org-mode tables, all lines before the first horizontal separator
499 line will be formatted with <th> tags."
500 :group
'org-export-tables
503 (defcustom org-export-table-remove-special-lines t
504 "Remove special lines and marking characters in calculating tables.
505 This removes the special marking character column from tables that are set
506 up for spreadsheet calculations. It also removes the entire lines
507 marked with `!', `_', or `^'. The lines with `$' are kept, because
508 the values of constants may be useful to have."
509 :group
'org-export-tables
512 (defcustom org-export-prefer-native-exporter-for-tables nil
513 "Non-nil means, always export tables created with table.el natively.
514 Natively means, use the HTML code generator in table.el.
515 When nil, Org-mode's own HTML generator is used when possible (i.e. if
516 the table does not use row- or column-spanning). This has the
517 advantage, that the automatic HTML conversions for math symbols and
518 sub/superscripts can be applied. Org-mode's HTML generator is also
520 :group
'org-export-tables
524 (defgroup org-export-xml nil
525 "Options specific for XML export of Org-mode files."
526 :tag
"Org Export XML"
531 ;;; Variables, constants, and parameter plists
533 (defconst org-level-max
20)
535 (defvar org-current-export-file nil
) ; dynamically scoped parameter
536 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
537 (defvar org-export-opt-plist nil
538 "Contains the current option plist.")
539 (defvar org-last-level nil
) ; dynamically scoped variable
540 (defvar org-min-level nil
) ; dynamically scoped variable
541 (defvar org-levels-open nil
) ; dynamically scoped parameter
543 (defconst org-export-plist-vars
544 '((:link-up nil org-export-html-link-up
)
545 (:link-home nil org-export-html-link-home
)
546 (:language nil org-export-default-language
)
547 (:keywords nil org-export-page-keywords
)
548 (:description nil org-export-page-description
)
549 (:customtime nil org-display-custom-times
)
550 (:headline-levels
"H" org-export-headline-levels
)
551 (:section-numbers
"num" org-export-with-section-numbers
)
552 (:section-number-format nil org-export-section-number-format
)
553 (:table-of-contents
"toc" org-export-with-toc
)
554 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
555 (:archived-trees nil org-export-with-archived-trees
)
556 (:emphasize
"*" org-export-with-emphasize
)
557 (:sub-superscript
"^" org-export-with-sub-superscripts
)
558 (:special-strings
"-" org-export-with-special-strings
)
559 (:footnotes
"f" org-export-with-footnotes
)
560 (:drawers
"d" org-export-with-drawers
)
561 (:tags
"tags" org-export-with-tags
)
562 (:todo-keywords
"todo" org-export-with-todo-keywords
)
563 (:priority
"pri" org-export-with-priority
)
564 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
565 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
566 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
567 (:fixed-width
":" org-export-with-fixed-width
)
568 (:timestamps
"<" org-export-with-timestamps
)
569 (:author-info
"author" org-export-author-info
)
570 (:creator-info
"creator" org-export-creator-info
)
571 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
572 (:tables
"|" org-export-with-tables
)
573 (:table-auto-headline nil org-export-highlight-first-table-line
)
574 (:style-include-default nil org-export-html-style-include-default
)
575 (:style-include-scripts nil org-export-html-style-include-scripts
)
576 (:style nil org-export-html-style
)
577 (:style-extra nil org-export-html-style-extra
)
578 (:agenda-style nil org-agenda-export-html-style
)
579 (:convert-org-links nil org-export-html-link-org-files-as-html
)
580 (:inline-images nil org-export-html-inline-images
)
581 (:html-extension nil org-export-html-extension
)
582 (:xml-declaration nil org-export-html-xml-declaration
)
583 (:html-table-tag nil org-export-html-table-tag
)
584 (:expand-quoted-html
"@" org-export-html-expand
)
585 (:timestamp nil org-export-html-with-timestamp
)
586 (:publishing-directory nil org-export-publishing-directory
)
587 (:preamble nil org-export-html-preamble
)
588 (:postamble nil org-export-html-postamble
)
589 (:auto-preamble nil org-export-html-auto-preamble
)
590 (:auto-postamble nil org-export-html-auto-postamble
)
591 (:author nil user-full-name
)
592 (:email nil user-mail-address
)
593 (:select-tags nil org-export-select-tags
)
594 (:exclude-tags nil org-export-exclude-tags
)
596 (:latex-image-options nil org-export-latex-image-default-option
))
597 "List of properties that represent export/publishing variables.
598 Each element is a list of 3 items:
599 1. The property that is used internally, and also for org-publish-project-alist
600 2. The string that can be used in the OPTION lines to set this option,
601 or nil if this option cannot be changed in this way
602 3. The customization variable that sets the default for this option."
605 (defun org-default-export-plist ()
606 "Return the property list with default settings for the export variables."
607 (let ((l org-export-plist-vars
) rtn e s v
)
608 (while (setq e
(pop l
))
610 v
(if (boundp s
) (symbol-value s
) nil
)
611 rtn
(cons (car e
) (cons v rtn
))))
614 (defvar org-export-inbuffer-options-extra nil
615 "List of additional in-buffer options that should be detected.
616 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
617 etc. Extensions can add to this list to get their options detected, and they
618 can then add a function to `org-export-options-filters' to process these
620 Each element in this list must be a list, with the in-buffer keyword as car,
621 and a property (a symbol) as the next element. All occurrences of the
622 keyword will be found, the values concatenated with a space character
623 in between, and the result stored in the export options property list.")
625 (defvar org-export-options-filters nil
626 "Functions to be called to finalize the export/publishing options.
627 All these options are stored in a property list, and each of the functions
628 in this hook gets a chance to modify this property list. Each function
629 must accept the property list as an argument, and must return the (possibly
632 ;; FIXME: should we fold case here?
633 (defun org-infile-export-plist ()
634 "Return the property list with file-local settings for export."
638 (goto-char (point-min))
639 (let ((re (org-make-options-regexp
641 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
642 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
643 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
644 "KEYWORDS" "DESCRIPTION")
645 (mapcar 'car org-export-inbuffer-options-extra
))))
646 p key val text options a pr style
648 ext-setup-or-nil setup-contents
(start 0))
649 (while (or (and ext-setup-or-nil
650 (string-match re ext-setup-or-nil start
)
651 (setq start
(match-end 0)))
652 (and (setq ext-setup-or-nil nil start
0)
653 (re-search-forward re nil t
)))
654 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
655 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
657 ((setq a
(assoc key org-export-inbuffer-options-extra
))
659 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
660 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
661 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
662 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
663 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
664 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
665 ((string-equal key
"DESCRIPTION")
666 (setq p
(plist-put p
:description val
)))
667 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
668 ((string-equal key
"STYLE")
669 (setq style
(concat style
"\n" val
)))
670 ((string-equal key
"LATEX_HEADER")
671 (setq latex-header
(concat latex-header
"\n" val
)))
672 ((string-equal key
"TEXT")
673 (setq text
(if text
(concat text
"\n" val
) val
)))
674 ((string-equal key
"OPTIONS")
675 (setq options
(concat val
" " options
)))
676 ((string-equal key
"LINK_UP")
677 (setq p
(plist-put p
:link-up val
)))
678 ((string-equal key
"LINK_HOME")
679 (setq p
(plist-put p
:link-home val
)))
680 ((string-equal key
"EXPORT_SELECT_TAGS")
681 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
682 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
683 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
684 ((equal key
"SETUPFILE")
685 (setq setup-contents
(org-file-contents
687 (org-remove-double-quotes
690 (if (not ext-setup-or-nil
)
691 (setq ext-setup-or-nil setup-contents start
0)
692 (setq ext-setup-or-nil
693 (concat (substring ext-setup-or-nil
0 start
)
694 "\n" setup-contents
"\n"
695 (substring ext-setup-or-nil start
)))))))
696 (setq p
(plist-put p
:text text
))
697 (when style
(setq p
(plist-put p
:style-extra style
)))
699 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
701 (setq p
(org-export-add-options-to-plist p options
)))
702 ;; Add macro definitions
703 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
704 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
706 p
:macro-modification-time
707 (and (buffer-file-name)
708 (file-exists-p (buffer-file-name))
710 "(eval (format-time-string \"$1\" '"
711 (prin1-to-string (nth 5 (file-attributes
712 (buffer-file-name))))
714 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
715 (file-name-nondirectory
716 (buffer-file-name)))))
717 (goto-char (point-min))
718 (while (re-search-forward
719 "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
721 (setq p
(plist-put p
(intern (concat ":macro-"
722 (downcase (match-string 1))))
726 (defun org-export-add-options-to-plist (p options
)
727 "Parse an OPTIONS line and set values in the property list P."
730 (let ((op org-export-plist-vars
))
731 (while (setq o
(pop op
))
733 (string-match (concat (regexp-quote (nth 1 o
))
734 ":\\([^ \t\n\r;,.]*\\)")
736 (setq p
(plist-put p
(car o
)
737 (car (read-from-string
738 (match-string 1 options
))))))))))
741 (defun org-export-add-subtree-options (p pos
)
742 "Add options in subtree at position POS to property list P."
745 (when (org-at-heading-p)
747 ;; This is actually read in `org-export-get-title-from-subtree'
748 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
749 ;; (setq p (plist-put p :title a)))
750 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
751 (setq p
(plist-put p
:text a
)))
752 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
753 (setq p
(plist-put p
:author a
)))
754 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
755 (setq p
(plist-put p
:date a
)))
756 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
757 (setq p
(org-export-add-options-to-plist p a
)))))
760 (defun org-export-directory (type plist
)
761 (let* ((val (plist-get plist
:publishing-directory
))
763 (or (cdr (assoc type val
)) ".")
767 (defun org-export-process-option-filters (plist)
768 (let ((functions org-export-options-filters
) f
)
769 (while (setq f
(pop functions
))
770 (setq plist
(funcall f plist
))))
774 (defun org-export (&optional arg
)
775 "Export dispatcher for Org-mode.
776 When `org-export-run-in-background' is non-nil, try to run the command
777 in the background. This will be done only for commands that write
778 to a file. For details see the docstring of `org-export-run-in-background'.
780 The prefix argument ARG will be passed to the exporter. However, if
781 ARG is a double universal prefix `C-u C-u', that means to inverse the
782 value of `org-export-run-in-background'."
784 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
785 (help "[t] insert the export option template
786 \[v] limit export to visible part of outline tree
788 \[a] export as ASCII [A] to temporary buffer
790 \[h] export as HTML [H] to temporary buffer [R] export region
791 \[b] export as HTML and open in browser
793 \[l] export as LaTeX [L] to temporary buffer
794 \[p] export as LaTeX and process to PDF
795 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
797 \[D] export as DocBook
798 \[V] export as DocBook, process to PDF, and open the resulting PDF document
802 \[i] export current file as iCalendar file
803 \[I] export all agenda files as iCalendar files
804 \[c] export agenda files into combined iCalendar file
806 \[F] publish current file [P] publish current project
807 \[X] publish a project... [E] publish every projects")
809 '((?t org-insert-export-options-template nil
)
810 (?v org-export-visible nil
)
811 (?a org-export-as-ascii t
)
812 (?A org-export-as-ascii-to-buffer t
)
813 (?h org-export-as-html t
)
814 (?b org-export-as-html-and-open t
)
815 (?H org-export-as-html-to-buffer nil
)
816 (?R org-export-region-as-html nil
)
817 (?x org-export-as-xoxo t
)
818 (?D org-export-as-docbook t
)
819 (?V org-export-as-docbook-pdf-and-open t
)
820 (?l org-export-as-latex t
)
821 (?p org-export-as-pdf t
)
822 (?d org-export-as-pdf-and-open t
)
823 (?L org-export-as-latex-to-buffer nil
)
824 (?i org-export-icalendar-this-file t
)
825 (?I org-export-icalendar-all-agenda-files t
)
826 (?c org-export-icalendar-combine-agenda-files t
)
827 (?F org-publish-current-file t
)
828 (?P org-publish-current-project t
)
830 (?E org-publish-all t
)))
833 (save-window-excursion
834 (delete-other-windows)
835 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
837 (org-fit-window-to-buffer (get-buffer-window
838 "*Org Export/Publishing Help*"))
839 (message "Select command: ")
840 (setq r1
(read-char-exclusive))))
841 (setq r2
(if (< r1
27) (+ r1
96) r1
))
842 (unless (setq ass
(assq r2 cmds
))
843 (error "No command associated with key %c" r1
))
844 (if (and bg
(nth 2 ass
)
845 (not (buffer-base-buffer))
846 (not (org-region-active-p)))
847 ;; execute in background
848 (let ((p (start-process
849 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
851 (expand-file-name invocation-name invocation-directory
)
854 "--eval" "(require 'org-exp)"
855 "--eval" "(setq org-wait .2)"
857 "-f" (symbol-name (nth 1 ass
)))))
858 (set-process-sentinel p
'org-export-process-sentinel
)
859 (message "Background process \"%s\": started" p
))
860 ;; background processing not requested, or not possible
861 (call-interactively (nth 1 ass
)))))
863 (defun org-export-process-sentinel (process status
)
864 (if (string-match "\n+\\'" status
)
865 (setq status
(substring status
0 -
1)))
866 (message "Background process \"%s\": %s" process status
))
868 (defconst org-html-entities
910 ("Aring") ("AA".
"Å")
999 ("varepsilon".
"ε")
1012 ("sigmaf") ("varsigma".
"ς")
1020 ("thetasym") ("vartheta".
"ϑ")
1023 ("bull") ("bullet".
"•")
1024 ("hellip") ("dots".
"…")
1034 ("larr") ("leftarrow".
"←") ("gets".
"←")
1035 ("uarr") ("uparrow".
"↑")
1036 ("rarr") ("to".
"→") ("rightarrow".
"→")
1037 ("darr")("downarrow".
"↓")
1038 ("harr") ("leftrightarrow".
"↔")
1039 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1040 ("lArr") ("Leftarrow".
"⇐")
1041 ("uArr") ("Uparrow".
"⇑")
1042 ("rArr") ("Rightarrow".
"⇒")
1043 ("dArr") ("Downarrow".
"⇓")
1044 ("hArr") ("Leftrightarrow".
"⇔")
1046 ("part") ("partial".
"∂")
1047 ("exist") ("exists".
"∃")
1048 ("empty") ("emptyset".
"∅")
1050 ("isin") ("in".
"∈")
1056 ("lowast") ("ast".
"∗")
1058 ("prop") ("proptp".
"∝")
1059 ("infin") ("infty".
"∞")
1060 ("ang") ("angle".
"∠")
1061 ("and") ("wedge".
"∧")
1062 ("or") ("vee".
"∨")
1068 ("cong") ("simeq".
"≅")
1069 ("asymp")("approx".
"≈")
1070 ("ne") ("neq".
"≠")
1074 ("sub") ("subset".
"⊂")
1075 ("sup") ("supset".
"⊃")
1082 ("sdot") ("cdot".
"⋅")
1089 ("loz") ("Diamond".
"◊")
1090 ("spades") ("spadesuit".
"♠")
1091 ("clubs") ("clubsuit".
"♣")
1092 ("hearts") ("diamondsuit".
"♥")
1093 ("diams") ("diamondsuit".
"♦")
1094 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1161 "Entities for TeX->HTML translation.
1162 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1163 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1164 In that case, \"\\ent\" will be translated to \"&other;\".
1165 The list contains HTML entities for Latin-1, Greek and other symbols.
1166 It is supplemented by a number of commonly used TeX macros with appropriate
1167 translations. There is currently no way for users to extend this.")
1169 ;;; General functions for all backends
1171 (defvar org-export-target-aliases nil
1172 "Alist of targets with invisible aliases.")
1173 (defvar org-export-preferred-target-alist nil
1174 "Alist of section id's with preferred aliases.")
1175 (defvar org-export-code-refs nil
1176 "Alist of code references and line numbers")
1178 (defun org-export-preprocess-string (string &rest parameters
)
1179 "Cleanup STRING so that that the true exported has a more consistent source.
1180 This function takes STRING, which should be a buffer-string of an org-file
1181 to export. It then creates a temporary buffer where it does its job.
1182 The result is then again returned as a string, and the exporter works
1183 on this string to produce the exported version."
1185 (let* ((htmlp (plist-get parameters
:for-html
))
1186 (asciip (plist-get parameters
:for-ascii
))
1187 (latexp (plist-get parameters
:for-LaTeX
))
1188 (docbookp (plist-get parameters
:for-docbook
))
1189 (backend (cond (htmlp 'html
)
1192 (docbookp 'docbook
)))
1193 (archived-trees (plist-get parameters
:archived-trees
))
1194 (inhibit-read-only t
)
1195 (drawers org-drawers
)
1196 (outline-regexp "\\*+ ")
1199 (setq org-export-target-aliases nil
)
1200 (setq org-export-preferred-target-alist nil
)
1201 (setq org-export-code-refs nil
)
1203 (with-current-buffer (get-buffer-create " org-mode-tmp")
1206 (setq case-fold-search t
)
1208 ;; Remove license-to-kill stuff
1209 ;; The caller marks some stuff for killing, stuff that has been
1210 ;; used to create the page title, for example.
1211 (org-export-kill-licensed-text)
1213 (let ((org-inhibit-startup t
)) (org-mode))
1214 (setq case-fold-search t
)
1217 (run-hooks 'org-export-preprocess-hook
)
1219 ;; Process the macros
1220 (org-export-preprocess-apply-macros)
1221 (run-hooks 'org-export-preprocess-after-macros-hook
)
1223 (untabify (point-min) (point-max))
1225 ;; Handle include files, and call a hook
1226 (org-export-handle-include-files)
1227 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1229 ;; Get rid of archived trees
1230 (org-export-remove-archived-trees archived-trees
)
1232 ;; Remove comment environment and comment subtrees
1233 (org-export-remove-comment-blocks-and-subtrees)
1235 ;; Get rid of excluded trees, and call a hook
1236 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1237 (plist-get parameters
:exclude-tags
))
1238 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1240 ;; Handle source code snippets
1241 (org-export-replace-src-segments-and-examples backend
)
1243 ;; Protect short examples marked by a leading colon
1244 (org-export-protect-colon-examples)
1246 ;; Normalize footnotes
1247 (when (plist-get parameters
:footnotes
)
1248 (org-footnote-normalize nil t
))
1250 ;; Find all headings and compute the targets for them
1251 (setq target-alist
(org-export-define-heading-targets target-alist
))
1253 ;; Get rid of drawers
1254 (org-export-remove-or-extract-drawers drawers
1255 (plist-get parameters
:drawers
))
1257 ;; Get the correct stuff before the first headline
1258 (when (plist-get parameters
:skip-before-1st-heading
)
1259 (goto-char (point-min))
1260 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1261 (delete-region (point-min) (match-beginning 0))
1262 (goto-char (point-min))
1264 (when (plist-get parameters
:add-text
)
1265 (goto-char (point-min))
1266 (insert (plist-get parameters
:add-text
) "\n"))
1268 ;; Remove todo-keywords before exporting, if the user has requested so
1269 (org-export-remove-headline-metadata parameters
)
1271 ;; Find targets in comments and move them out of comments,
1272 ;; but mark them as targets that should be invisible
1273 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1275 ;; Select and protect backend specific stuff, throw away stuff
1276 ;; that is specific for other backends
1277 (org-export-select-backend-specific-text backend
)
1279 ;; Protect quoted subtrees
1280 (org-export-protect-quoted-subtrees)
1282 ;; Remove clock lines
1283 (org-export-remove-clock-lines)
1285 ;; Protect verbatim elements
1286 (org-export-protect-verbatim)
1288 ;; Blockquotes, verse, and center
1289 (org-export-mark-blockquote-verse-center)
1290 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1292 ;; Remove timestamps, if the user has requested so
1293 (unless (plist-get parameters
:timestamps
)
1294 (org-export-remove-timestamps))
1296 ;; Attach captions to the correct object
1297 (setq target-alist
(org-export-attach-captions-and-attributes
1298 backend target-alist
))
1300 ;; Find matches for radio targets and turn them into internal links
1301 (org-export-mark-radio-links)
1303 ;; Find all links that contain a newline and put them into a single line
1304 (org-export-concatenate-multiline-links)
1306 ;; Normalize links: Convert angle and plain links into bracket links
1307 ;; and expand link abbreviations
1308 (org-export-normalize-links)
1310 ;; Find all internal links. If they have a fuzzy match (i.e. not
1311 ;; a *dedicated* target match, let the link point to the
1312 ;; corresponding section.
1313 (org-export-target-internal-links target-alist
)
1315 ;; Find multiline emphasis and put them into single line
1316 (when (plist-get parameters
:emph-multiline
)
1317 (org-export-concatenate-multiline-emphasis))
1319 ;; Remove special table lines
1320 (when org-export-table-remove-special-lines
1321 (org-export-remove-special-table-lines))
1324 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1326 ;; LaTeX-specific preprocessing
1328 (require 'org-latex nil
)
1329 (org-export-latex-preprocess parameters
))
1331 ;; ASCII-specific preprocessing
1333 (org-export-ascii-preprocess parameters
))
1335 ;; HTML-specific preprocessing
1337 (org-export-html-preprocess parameters
))
1339 ;; DocBook-specific preprocessing
1341 (require 'org-docbook nil
)
1342 (org-export-docbook-preprocess parameters
))
1344 ;; Remove or replace comments
1345 (org-export-handle-comments (plist-get parameters
:comments
))
1347 ;; Run the final hook
1348 (run-hooks 'org-export-preprocess-final-hook
)
1350 (setq rtn
(buffer-string)))
1351 (kill-buffer " org-mode-tmp")
1354 (defun org-export-kill-licensed-text ()
1355 "Remove all text that is marked with a :org-license-to-kill property."
1357 (while (setq p
(text-property-any (point-min) (point-max)
1358 :org-license-to-kill t
))
1360 p
(or (next-single-property-change p
:org-license-to-kill
)
1363 (defun org-export-define-heading-targets (target-alist)
1364 "Find all headings and define the targets for them.
1365 The new targets are added to TARGET-ALIST, which is also returned."
1366 (goto-char (point-min))
1367 (org-init-section-numbers)
1368 (let ((re (concat "^" org-outline-regexp
1369 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1370 level target last-section-target a id
)
1371 (while (re-search-forward re nil t
)
1374 (setq id
(org-match-string-no-properties 2))
1375 (push (cons id target
) target-alist
)
1376 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1378 (push (list last-section-target
)
1379 org-export-target-aliases
)
1380 (car org-export-target-aliases
))))
1381 (push (caar target-alist
) (cdr a
))
1382 (when (equal (match-string 1) "CUSTOM_ID")
1383 (if (not (assoc last-section-target
1384 org-export-preferred-target-alist
))
1385 (push (cons last-section-target id
)
1386 org-export-preferred-target-alist
))))
1387 (setq level
(org-reduced-level
1388 (save-excursion (goto-char (point-at-bol))
1389 (org-outline-level))))
1390 (setq target
(org-solidify-link-text
1391 (format "sec-%s" (org-section-number level
))))
1392 (setq last-section-target target
)
1393 (push (cons target target
) target-alist
)
1394 (add-text-properties
1395 (point-at-bol) (point-at-eol)
1396 (list 'target target
)))))
1399 (defun org-export-handle-invisible-targets (target-alist)
1400 "Find targets in comments and move them out of comments.
1401 Mark them as invisible targets."
1403 (goto-char (point-min))
1404 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1405 ;; Check if the line before or after is a headline with a target
1406 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1407 (get-text-property (point-at-bol 2) 'target
)))
1409 ;; use the existing target in a neighboring line
1410 (setq tmp
(match-string 2))
1412 (and (looking-at "\n") (delete-char 1))
1413 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1415 (setq a
(or (assoc target org-export-target-aliases
)
1417 (push (list target
) org-export-target-aliases
)
1418 (car org-export-target-aliases
))))
1420 ;; Make an invisible target
1421 (replace-match "\\1(INVISIBLE)"))))
1424 (defun org-export-target-internal-links (target-alist)
1425 "Find all internal links and assign targets to them.
1426 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1427 let the link point to the corresponding section.
1428 This function also handles the id links, if they have a match in
1430 (goto-char (point-min))
1431 (while (re-search-forward org-bracket-link-regexp nil t
)
1433 (let* ((md (match-data))
1434 (desc (match-end 2))
1435 (link (org-link-unescape (match-string 1)))
1436 (slink (org-solidify-link-text link
))
1437 found props pos cref
1440 ((= (string-to-char link
) ?
#)
1441 ;; user wants exactly this link
1443 ((cdr (assoc slink target-alist
))
1444 (or (cdr (assoc (assoc slink target-alist
)
1445 org-export-preferred-target-alist
))
1446 (cdr (assoc slink target-alist
))))
1447 ((and (string-match "^id:" link
)
1448 (cdr (assoc (substring link
3) target-alist
))))
1449 ((string-match "^(\\(.*\\))$" link
)
1450 (setq cref
(match-string 1 link
))
1451 (concat "coderef:" cref
))
1452 ((string-match org-link-types-re link
) nil
)
1453 ((or (file-name-absolute-p link
)
1454 (string-match "^\\." link
))
1458 (setq found
(condition-case nil
(org-link-search link
)
1461 (or (org-on-heading-p)
1462 (not (eq found
'dedicated
))))
1463 (or (get-text-property (point) 'target
)
1466 (1- (or (previous-single-property-change
1467 (point) 'target
) 0)))
1471 (goto-char (match-beginning 1))
1472 (setq props
(text-properties-at (point)))
1473 (delete-region (match-beginning 1) (match-end 1))
1476 (unless desc
(insert "][" link
))
1477 (add-text-properties pos
(point) props
))))))
1479 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1480 "Remove drawers, or extract the content.
1481 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1482 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1483 whose content to keep."
1484 (unless (eq t exp-drawers
)
1485 (goto-char (point-min))
1486 (let ((re (concat "^[ \t]*:\\("
1489 (org-delete-all exp-drawers
1490 (copy-sequence all-drawers
))
1494 (while (re-search-forward re nil t
)
1496 (setq beg
(match-beginning 0)
1498 (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
1501 ;; terminated in this entry
1503 (delete-region beg
(match-end 1))
1505 (goto-char eol
))))))))
1507 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1508 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1509 Both arguments are lists of tags.
1510 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1512 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1514 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1515 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1518 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1522 (goto-char (point-min))
1523 (when (and select-tags
1525 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1526 ;; At least one tree is marked for export, this means
1527 ;; all the unmarked stuff needs to go.
1528 ;; Dig out the trees that should be exported
1529 (goto-char (point-min))
1530 (outline-next-heading)
1532 (put-text-property beg
(point-max) :org-delete t
)
1533 (while (re-search-forward re-sel nil t
)
1534 (when (org-on-heading-p)
1535 (org-back-to-heading)
1536 (remove-text-properties
1537 (max (1- (point)) (point-min))
1538 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1540 (while (and (org-up-heading-safe)
1541 (get-text-property (point) :org-delete
))
1542 (remove-text-properties (max (1- (point)) (point-min))
1543 (point-at-eol) '(:org-delete t
)))
1545 ;; Remove the trees explicitly marked for noexport
1547 (goto-char (point-min))
1548 (while (re-search-forward re-excl nil t
)
1549 (when (org-at-heading-p)
1550 (org-back-to-heading t
)
1552 (org-end-of-subtree t
)
1553 (delete-region beg
(point)))))
1554 ;; Remove everything that is now still marked for deletion
1555 (goto-char (point-min))
1556 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1557 (setq end
(or (next-single-property-change beg
:org-delete
)
1559 (delete-region beg end
))))
1561 (defun org-export-remove-archived-trees (export-archived-trees)
1562 "Remove archived trees.
1563 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1564 When it is t, the entire archived tree will be exported.
1565 When it is nil the entire tree including the headline will be removed
1567 (let ((re-archive (concat ":" org-archive-tag
":"))
1569 (when (not (eq export-archived-trees t
))
1570 (goto-char (point-min))
1571 (while (re-search-forward re-archive nil t
)
1572 (if (not (org-on-heading-p t
))
1573 (org-end-of-subtree t
)
1574 (beginning-of-line 1)
1575 (setq a
(if export-archived-trees
1576 (1+ (point-at-eol)) (point))
1577 b
(org-end-of-subtree t
))
1578 (if (> b a
) (delete-region a b
)))))))
1580 (defun org-export-remove-headline-metadata (opts)
1581 "Remove meta data from the headline, according to user options."
1582 (let ((re org-complex-heading-regexp
)
1583 (todo (plist-get opts
:todo-keywords
))
1584 (tags (plist-get opts
:tags
))
1585 (pri (plist-get opts
:priority
))
1588 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1589 (when (or (not todo
) (not tags
) (not pri
))
1590 (goto-char (point-min))
1591 (while (re-search-forward re nil t
)
1593 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1595 (replace-match rpl t t
))))))
1597 (defun org-export-remove-timestamps ()
1598 "Remove timestamps and keywords for export."
1599 (goto-char (point-min))
1600 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1603 (unless (save-match-data (org-at-table-p))
1605 (beginning-of-line 1)
1606 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1607 (replace-match ""))))))
1609 (defun org-export-remove-clock-lines ()
1610 "Remove clock lines for export."
1611 (goto-char (point-min))
1612 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1613 (while (re-search-forward re nil t
)
1615 (replace-match "")))))
1617 (defun org-export-protect-quoted-subtrees ()
1618 "Mark quoted subtrees with the protection property."
1619 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1620 (goto-char (point-min))
1621 (while (re-search-forward re-quote nil t
)
1622 (goto-char (match-beginning 0))
1624 (add-text-properties (point) (org-end-of-subtree t
)
1625 '(org-protected t
)))))
1627 (defun org-export-protect-verbatim ()
1628 "Mark verbatim snippets with the protection property."
1629 (goto-char (point-min))
1630 (while (re-search-forward org-verbatim-re nil t
)
1631 (add-text-properties (match-beginning 4) (match-end 4)
1633 (goto-char (1+ (match-end 4)))))
1635 (defun org-export-protect-colon-examples ()
1636 "Protect lines starting with a colon."
1637 (goto-char (point-min))
1638 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1639 (while (re-search-forward re nil t
)
1640 (beginning-of-line 1)
1642 (while (looking-at re
)
1644 (or (eobp) (forward-char 1)))
1645 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1646 '(org-protected t
)))))
1648 (defun org-export-select-backend-specific-text (backend)
1650 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1651 (html "HTML" "BEGIN_HTML" "END_HTML")
1652 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1653 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1654 (case-fold-search t
)
1658 (setq fmt
(pop formatters
))
1659 (when (eq (car fmt
) backend
)
1660 ;; This is selected code, put it into the file for real
1661 (goto-char (point-min))
1662 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1663 ":[ \t]*\\(.*\\)") nil t
)
1664 (replace-match "\\1\\2" t
)
1665 (add-text-properties
1666 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1667 '(org-protected t
))))
1668 (goto-char (point-min))
1669 (while (re-search-forward
1670 (concat "^[ \t]*#\\+" (caddr fmt
)
1671 "\\>.*\\(\\(\n.*\\)*?\n\\)[ \t]*#\\+" (cadddr fmt
)
1673 (if (eq (car fmt
) backend
)
1675 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1677 ;; No, this is for a different backend, kill it
1678 (delete-region (match-beginning 0) (match-end 0)))))))
1680 (defun org-export-mark-blockquote-verse-center ()
1681 "Mark block quote and verse environments with special cookies.
1682 These special cookies will later be interpreted by the backend."
1684 (let (type t1 ind beg end beg1 end1 content
)
1685 (goto-char (point-min))
1686 (while (re-search-forward
1687 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1689 (setq ind
(length (match-string 1))
1690 type
(downcase (match-string 3))
1691 t1
(if (equal type
"quote") "blockquote" type
))
1692 (setq beg
(match-beginning 0)
1693 beg1
(1+ (match-end 0)))
1694 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1695 (setq end
(1+ (point-at-eol))
1696 end1
(1- (match-beginning 0)))
1697 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1698 (setq content
(concat "ORG-" (upcase type
) "-START\n"
1700 "ORG-" (upcase type
) "-END\n"))
1701 (delete-region beg end
)
1702 (insert (org-add-props content nil
'original-indentation ind
))))))
1704 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1705 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1706 If the next thing following is a table, add the text properties to the first
1707 table line. If it is a link, add it to the line containing the link."
1708 (goto-char (point-min))
1709 (remove-text-properties (point-min) (point-max)
1710 '(org-caption nil org-attributes nil
))
1711 (let ((case-fold-search t
)
1712 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1714 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1716 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1720 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1722 (while (re-search-forward re nil t
)
1725 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1727 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1729 (setq label
(org-trim (match-string 3))))
1731 (add-text-properties (point-at-bol) (point-at-eol)
1732 (list 'org-caption cap
1733 'org-attributes attr
1735 (if label
(push (cons label label
) target-alist
))
1736 (setq cap nil attr nil label nil
)))))
1739 (defun org-export-remove-comment-blocks-and-subtrees ()
1740 "Remove the comment environment, and also commented subtrees."
1741 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1742 (case-fold-search nil
))
1743 ;; Remove comment environment
1744 (goto-char (point-min))
1745 (while (re-search-forward
1746 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1747 (replace-match "" t t
))
1748 ;; Remove subtrees that are commented
1749 (goto-char (point-min))
1750 (while (re-search-forward re-commented nil t
)
1751 (goto-char (match-beginning 0))
1752 (delete-region (point) (org-end-of-subtree t
)))))
1754 (defun org-export-handle-comments (commentsp)
1755 "Remove comments, or convert to backend-specific format.
1756 COMMENTSP can be a format string for publishing comments.
1757 When it is nil, all comments will be removed."
1758 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1760 (goto-char (point-min))
1761 (while (or (looking-at re
)
1762 (re-search-forward re nil t
))
1763 (setq pos
(match-beginning 0))
1765 (not (equal (char-before (match-end 1)) ?
+)))
1766 (progn (add-text-properties
1767 (match-beginning 0) (match-end 0) '(org-protected t
))
1768 (replace-match (format commentsp
(match-string 2)) t t
))
1769 (goto-char (1+ pos
))
1772 (goto-char (max (point-min) (1- pos
))))))))
1774 (defun org-export-mark-radio-links ()
1775 "Find all matches for radio targets and turn them into internal links."
1776 (let ((re-radio (and org-target-link-regexp
1777 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1778 (goto-char (point-min))
1780 (while (re-search-forward re-radio nil t
)
1782 (replace-match "\\1[[\\2]]"))))))
1784 (defun org-export-remove-special-table-lines ()
1785 "Remove tables lines that are used for internal purposes."
1786 (goto-char (point-min))
1787 (while (re-search-forward "^[ \t]*|" nil t
)
1788 (beginning-of-line 1)
1789 (if (or (looking-at "[ \t]*| *[!_^] *|")
1790 (and (looking-at ".*?| *<[0-9]+> *|")
1791 (not (looking-at ".*?| *[^ <|]"))))
1792 (delete-region (max (point-min) (1- (point-at-bol)))
1796 (defun org-export-normalize-links ()
1797 "Convert all links to bracket links, and expand link abbreviations."
1798 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1799 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1800 (goto-char (point-min))
1801 (while (re-search-forward re-plain-link nil t
)
1802 (goto-char (1- (match-end 0)))
1803 (org-if-unprotected-at (1+ (match-beginning 0))
1804 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1805 ":" (match-string 3) "]]")))
1806 ;; added 'org-link face to links
1807 (put-text-property 0 (length s
) 'face
'org-link s
)
1808 (replace-match s t t
))))
1809 (goto-char (point-min))
1810 (while (re-search-forward re-angle-link nil t
)
1811 (goto-char (1- (match-end 0)))
1813 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1814 ":" (match-string 3) "]]")))
1815 (put-text-property 0 (length s
) 'face
'org-link s
)
1816 (replace-match s t t
))))
1817 (goto-char (point-min))
1818 (while (re-search-forward org-bracket-link-regexp nil t
)
1819 (goto-char (1- (match-end 0)))
1821 (let* ((xx (save-match-data
1823 (org-link-expand-abbrev (match-string 1)))))
1825 "[[" (org-add-props (copy-sequence xx
)
1826 nil
'org-protected t
)
1830 (concat "[" (copy-sequence xx
)
1833 (put-text-property 0 (length s
) 'face
'org-link s
)
1834 (replace-match s t t
))))))
1836 (defun org-export-concatenate-multiline-links ()
1837 "Find multi-line links and put it all into a single line.
1838 This is to make sure that the line-processing export backends
1839 can work correctly."
1840 (goto-char (point-min))
1841 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1843 (replace-match "\\1 \\3")
1844 (goto-char (match-beginning 0)))))
1846 (defun org-export-concatenate-multiline-emphasis ()
1847 "Find multi-line emphasis and put it all into a single line.
1848 This is to make sure that the line-processing export backends
1849 can work correctly."
1850 (goto-char (point-min))
1851 (while (re-search-forward org-emph-re nil t
)
1852 (if (and (not (= (char-after (match-beginning 3))
1853 (char-after (match-beginning 4))))
1854 (save-excursion (goto-char (match-beginning 0))
1855 (save-match-data (not (org-at-table-p)))))
1857 (subst-char-in-region (match-beginning 0) (match-end 0)
1859 (goto-char (1- (match-end 0))))
1860 (goto-char (1+ (match-beginning 0))))))
1862 (defun org-export-grab-title-from-buffer ()
1863 "Get a title for the current document, from looking at the buffer."
1864 (let ((inhibit-read-only t
))
1866 (goto-char (point-min))
1867 (let ((end (if (looking-at org-outline-regexp
)
1869 (save-excursion (outline-next-heading) (point)))))
1870 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1871 ;; Mark the line so that it will not be exported as normal text.
1873 (add-text-properties (match-beginning 0) (match-end 0)
1874 (list :org-license-to-kill t
)))
1875 ;; Return the title string
1876 (org-trim (match-string 0)))))))
1878 (defun org-export-get-title-from-subtree ()
1879 "Return subtree title and exclude it from export."
1880 (let (title (rbeg (region-beginning)) (rend (region-end)))
1883 (when (and (org-at-heading-p)
1884 (>= (org-end-of-subtree t t
) rend
))
1885 ;; This is a subtree, we take the title from the first heading
1887 (looking-at org-todo-line-regexp
)
1888 (setq title
(match-string 3))
1890 (add-text-properties (point) (1+ (point-at-eol))
1891 (list :org-license-to-kill t
)))
1892 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1895 (defun org-solidify-link-text (s &optional alist
)
1896 "Take link text and make a safe target out of it."
1901 (org-split-string s
"[ \t\r\n]+") "=="))
1902 (a (assoc rtn alist
)))
1905 (defun org-get-min-level (lines &optional offset
)
1906 "Get the minimum level in LINES."
1907 (let ((re "^\\(\\*+\\) ") l
)
1909 (while (setq l
(pop lines
))
1910 (if (string-match re l
)
1911 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1915 ;; Variable holding the vector with section numbers
1916 (defvar org-section-numbers
(make-vector org-level-max
0))
1918 (defun org-init-section-numbers ()
1919 "Initialize the vector for the section numbers."
1921 (numbers (nreverse (org-split-string "" "\\.")))
1922 (depth (1- (length org-section-numbers
)))
1923 (i depth
) number-string
)
1926 (aset org-section-numbers i
0)
1927 (setq number-string
(or (car numbers
) "0"))
1928 (if (string-match "\\`[A-Z]\\'" number-string
)
1929 (aset org-section-numbers i
1930 (- (string-to-char number-string
) ?A -
1))
1931 (aset org-section-numbers i
(string-to-number number-string
)))
1935 (defun org-section-number (&optional level
)
1936 "Return a string with the current section number.
1937 When LEVEL is non-nil, increase section numbers on that level."
1938 (let* ((depth (1- (length org-section-numbers
)))
1940 (fmts (car org-export-section-number-format
))
1941 (term (cdr org-export-section-number-format
))
1946 (aset org-section-numbers
1947 level
(1+ (aref org-section-numbers level
))))
1948 (setq idx
(1+ level
))
1949 (while (<= idx depth
)
1951 (aset org-section-numbers idx
0))
1952 (setq idx
(1+ idx
))))
1954 (while (<= idx depth
)
1955 (when (> (aref org-section-numbers idx
) 0)
1956 (setq fmt
(or (pop fmts
) fmt
)
1958 n
(aref org-section-numbers idx
)
1960 (concat string sep
(org-number-to-counter n ctype
))
1961 (concat string
".0"))
1963 (setq idx
(1+ idx
)))
1965 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1966 (setq string
(replace-match "" t nil string
)))
1967 (if (string-match "\\(\\.0\\)+\\'" string
)
1968 (setq string
(replace-match "" t nil string
))))
1969 (concat string term
)))
1971 (defun org-number-to-counter (n type
)
1972 "Concert number N to a string counter, according to TYPE.
1973 TYPE must be a string, any of:
1977 I upper case roman numeral
1978 i lower case roman numeral"
1980 ((equal type
"1") (number-to-string n
))
1981 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1982 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1983 ((equal type
"I") (org-number-to-roman n
))
1984 ((equal type
"i") (downcase (org-number-to-roman n
)))
1985 (t (error "Invalid counter type `%s'" type
))))
1987 (defun org-number-to-roman (n)
1988 "Convert integer N into a roman numeral."
1989 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1990 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1991 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1995 (number-to-string n
)
1997 (if (>= n
(caar roman
))
1998 (setq n
(- n
(caar roman
))
1999 res
(concat res
(cdar roman
)))
2005 (defun org-export-preprocess-apply-macros ()
2006 "Replace macro references."
2007 (goto-char (point-min))
2008 (let (sy val key args args2 s n
)
2009 (while (re-search-forward
2010 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\(.*?\\))\\)?}}}"
2012 (setq key
(downcase (match-string 1))
2013 args
(match-string 3))
2014 (when (setq val
(or (plist-get org-export-opt-plist
2015 (intern (concat ":macro-" key
)))
2016 (plist-get org-export-opt-plist
2017 (intern (concat ":" key
)))))
2020 (setq args
(org-split-string args
";") args2 nil
)
2022 (while (string-match "\\\\\\'" (car args
))
2023 ;; repair bad splits
2024 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2027 (push (pop args
) args2
))
2028 (setq args
(nreverse args2
))
2030 (while (string-match "\\$\\([0-9]+\\)" val s
)
2031 (setq s
(1+ (match-beginning 0))
2032 n
(string-to-number (match-string 1 val
)))
2033 (and (>= (length args
) n
)
2034 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2035 (when (string-match "\\`(eval\\>" val
)
2036 (setq val
(eval (read val
))))
2037 (if (and val
(not (stringp val
)))
2038 (setq val
(format "%s" val
))))
2040 (replace-match val t t
))))))
2042 (defun org-export-apply-macros-in-string (s)
2043 "Apply the macros in string S."
2047 (org-export-preprocess-apply-macros)
2052 (defun org-export-handle-include-files ()
2053 "Include the contents of include files, with proper formatting."
2054 (let ((case-fold-search t
)
2055 params file markup lang start end prefix prefix1 switches
)
2056 (goto-char (point-min))
2057 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2058 (setq params
(read (concat "(" (match-string 1) ")"))
2059 prefix
(org-get-and-remove-property 'params
:prefix
)
2060 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2061 file
(org-symname-or-string (pop params
))
2062 markup
(org-symname-or-string (pop params
))
2063 lang
(and (member markup
'("src" "SRC"))
2064 (org-symname-or-string (pop params
)))
2065 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2066 (delete-region (match-beginning 0) (match-end 0))
2068 (not (file-exists-p file
))
2069 (not (file-readable-p file
)))
2070 (insert (format "CANNOT INCLUDE FILE %s" file
))
2072 (if (equal (downcase markup
) "src")
2073 (setq start
(format "#+begin_src %s %s\n"
2074 (or lang
"fundamental")
2077 (setq start
(format "#+begin_%s %s\n" markup switches
)
2078 end
(format "#+end_%s" markup
))))
2079 (insert (or start
""))
2080 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2081 (or (bolp) (newline))
2082 (insert (or end
""))))))
2084 (defun org-get-file-contents (file &optional prefix prefix1
)
2085 "Get the contents of FILE and return them as a string.
2086 If PREFIX is a string, prepend it to each line. If PREFIX1
2087 is a string, prepend it to the first line instead of PREFIX."
2089 (insert-file-contents file
)
2090 (when (or prefix prefix1
)
2091 (goto-char (point-min))
2093 (insert (or prefix1 prefix
))
2095 (beginning-of-line 2)))
2098 (defun org-get-and-remove-property (listvar prop
)
2099 "Check if the value of LISTVAR contains PROP as a property.
2100 If yes, return the value of that property (i.e. the element following
2101 in the list) and remove property and value from the list in LISTVAR."
2102 (let ((list (symbol-value listvar
)) m v
)
2103 (when (setq m
(member prop list
))
2105 (if (equal (car list
) prop
)
2106 (set listvar
(cddr list
))
2107 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2109 (set listvar list
)))
2112 (defun org-symname-or-string (s)
2114 (if s
(symbol-name s
) s
)
2117 ;;; Fontification and line numbers for code examples
2119 (defvar org-export-last-code-line-counter-value
0)
2121 (defun org-export-replace-src-segments-and-examples (backend)
2122 "Replace source code segments with special code for export."
2123 (setq org-export-last-code-line-counter-value
0)
2124 (let ((case-fold-search t
)
2125 lang code trans opts indent
)
2126 (goto-char (point-min))
2127 (while (re-search-forward
2128 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
2132 (setq lang
(match-string 3)
2133 opts
(match-string 4)
2134 code
(match-string 5)
2135 indent
(length (match-string 2)))
2137 opts
(match-string 8)
2138 code
(match-string 9)
2139 indent
(length (match-string 7))))
2141 (setq trans
(org-export-format-source-code-or-example
2142 backend lang code opts indent
))
2143 (replace-match trans t t
))))
2145 (defvar htmlp
) ;; dynamically scoped
2146 (defvar latexp
) ;; dynamically scoped
2148 (defun org-export-format-source-code-or-example
2149 (backend lang code
&optional opts indent
)
2150 "Format CODE from language LANG and return it formatted for export.
2151 If LANG is nil, do not add any fontification.
2152 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2153 and `+n' for continuing previous numering.
2154 Code formatting according to language currently only works for HTML.
2155 Numbering lines works for all three major backends (html, latex, and ascii).
2156 INDENT was the original indentation of the block."
2158 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2159 (setq opts
(or opts
"")
2160 num
(string-match "[-+]n\\>" opts
)
2161 cont
(string-match "\\+n\\>" opts
)
2162 rpllbl
(string-match "-r\\>" opts
)
2163 keepp
(string-match "-k\\>" opts
)
2164 textareap
(string-match "-t\\>" opts
)
2165 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2166 (string-to-number (match-string 1 opts
))
2168 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2169 (string-to-number (match-string 1 opts
))
2170 (org-count-lines code
))
2171 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2172 (match-string 1 opts
)))
2173 (when (and textareap
(eq backend
'html
))
2174 ;; we cannot use numbering or highlighting.
2175 (setq num nil cont nil lang nil
))
2176 (if keepp
(setq rpllbl
'keep
))
2177 (setq rtn
(org-remove-indentation code
))
2178 (when (string-match "^," rtn
)
2179 (setq rtn
(with-temp-buffer
2181 ;; Free up the protected lines
2182 (goto-char (point-min))
2183 (while (re-search-forward "^," nil t
)
2184 (if (or (equal lang
"org")
2186 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2190 ;; Now backend-specific coding
2193 ((eq backend
'docbook
)
2194 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2195 (concat "\n#+BEGIN_DOCBOOK\n"
2196 (org-add-props (concat "<programlisting><![CDATA["
2198 "]]>\n</programlisting>\n")
2202 ;; We are exporting to HTML
2204 (require 'htmlize nil t
)
2205 (when (not (fboundp 'htmlize-region-for-paste
))
2206 ;; we do not have htmlize.el, or an old version of it
2209 "htmlize.el 1.34 or later is needed for source code formatting")))
2212 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2213 (org-inhibit-startup t
)
2214 (org-startup-folded nil
))
2218 (if (functionp mode
)
2221 (font-lock-fontify-buffer)
2222 (set-buffer-modified-p nil
)
2223 (org-export-htmlize-region-for-paste
2224 (point-min) (point-max))))
2225 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2226 (setq rtn
(replace-match
2227 (format "<pre class=\"src src-%s\">\n" lang
)
2231 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2233 rtn
"</textarea>\n</p>\n"))
2236 (goto-char (point-min))
2237 (while (re-search-forward "[<>&]" nil t
)
2238 (replace-match (cdr (assq (char-before)
2239 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2241 (setq rtn
(buffer-string)))
2242 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2244 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2246 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2247 ((eq backend
'latex
)
2248 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2249 (concat "\n#+BEGIN_LaTeX\n"
2250 (org-add-props (concat "\\begin{verbatim}\n" rtn
"\n\\end{verbatim}\n")
2253 ((eq backend
'ascii
)
2254 ;; This is not HTML or LaTeX, so just make it an example.
2255 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2256 (concat "#+BEGIN_ASCII\n"
2260 (lambda (l) (concat " " l
))
2261 (org-split-string rtn
"\n")
2266 (org-add-props rtn nil
'original-indentation indent
))))
2268 (defun org-export-number-lines (text backend
2269 &optional skip1 skip2 number cont
2270 replace-labels label-format
)
2271 (if (and (not number
) (not (eq replace-labels
'keep
)))
2272 (setq replace-labels nil
)) ;; must use names if no numbers
2273 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2274 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2277 (goto-char (point-max))
2278 (skip-chars-backward " \t\n\r")
2279 (delete-region (point) (point-max))
2280 (beginning-of-line (- 1 skip2
))
2281 (let* ((last (org-current-line))
2282 (n org-export-last-code-line-counter-value
)
2283 (nmax (+ n
(- last skip1
)))
2284 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2287 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2289 ((eq backend
'ascii
) fmt
)
2290 ((eq backend
'latex
) fmt
)
2291 ((eq backend
'docbook
) fmt
)
2293 (label-format (or label-format org-coderef-label-format
))
2294 (label-pre (if (string-match "%s" label-format
)
2295 (substring label-format
0 (match-beginning 0))
2297 (label-post (if (string-match "%s" label-format
)
2298 (substring label-format
(match-end 0))
2302 ".*?\\S-.*?\\([ \t]*\\("
2303 (regexp-quote label-pre
)
2304 "\\([-a-zA-Z0-9_]+\\)"
2305 (regexp-quote label-post
)
2309 (goto-line (1+ skip1
))
2310 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2312 (insert (format fm
(incf n
)))
2314 (when (and (not (eq replace-labels
'keep
))
2315 (looking-at lbl-re
))
2316 (setq ref
(match-string 3))
2319 (delete-region (match-beginning 1) (match-end 1))
2320 (push (cons ref n
) org-export-code-refs
))
2321 (goto-char (match-beginning 2))
2322 (delete-region (match-beginning 2) (match-end 2))
2323 (insert "(" ref
")")
2324 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2325 (when (eq backend
'html
)
2327 (beginning-of-line 1)
2328 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2331 (insert "</span>")))))
2332 (setq org-export-last-code-line-counter-value n
)
2333 (goto-char (point-max))
2337 (defun org-search-todo-below (line lines level
)
2338 "Search the subtree below LINE for any TODO entries."
2339 (let ((rest (cdr (memq line lines
)))
2340 (re org-todo-line-regexp
)
2343 (while (setq line
(pop rest
))
2344 (if (string-match re line
)
2346 (setq lv
(- (match-end 1) (match-beginning 1))
2347 todo
(and (match-beginning 2)
2348 (not (member (match-string 2 line
)
2349 org-done-keywords
))))
2351 (if (<= lv level
) (throw 'exit nil
))
2352 (if todo
(throw 'exit t
))))))))
2355 (defun org-export-visible (type arg
)
2356 "Create a copy of the visible part of the current buffer, and export it.
2357 The copy is created in a temporary buffer and removed after use.
2358 TYPE is the final key (as a string) that also select the export command in
2359 the `C-c C-e' export dispatcher.
2360 As a special case, if the you type SPC at the prompt, the temporary
2361 org-mode file will not be removed but presented to you so that you can
2362 continue to use it. The prefix arg ARG is passed through to the exporting
2366 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2367 (read-char-exclusive))
2368 current-prefix-arg
))
2369 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\
)))
2370 (error "Invalid export key"))
2371 (let* ((binding (cdr (assoc type
2372 '((?a . org-export-as-ascii
)
2373 (?A . org-export-as-ascii-to-buffer
)
2374 (?\C-a . org-export-as-ascii
)
2375 (?b . org-export-as-html-and-open
)
2376 (?\C-b . org-export-as-html-and-open
)
2377 (?h . org-export-as-html
)
2378 (?H . org-export-as-html-to-buffer
)
2379 (?R . org-export-region-as-html
)
2380 (?D . org-export-as-docbook
)
2381 (?x . org-export-as-xoxo
)))))
2382 (keepp (equal type ?\
))
2383 (file buffer-file-name
)
2384 (buffer (get-buffer-create "*Org Export Visible*"))
2386 ;; Need to hack the drawers here.
2388 (goto-char (point-min))
2389 (while (re-search-forward org-drawer-regexp nil t
)
2390 (goto-char (match-beginning 1))
2391 (or (org-invisible-p) (org-flag-drawer nil
))))
2392 (with-current-buffer buffer
(erase-buffer))
2394 (setq s
(goto-char (point-min)))
2395 (while (not (= (point) (point-max)))
2396 (goto-char (org-find-invisible))
2397 (append-to-buffer buffer s
(point))
2398 (setq s
(goto-char (org-find-visible))))
2399 (org-cycle-hide-drawers 'all
)
2400 (goto-char (point-min))
2402 ;; Copy all comment lines to the end, to make sure #+ settings are
2403 ;; still available for the second export step. Kind of a hack, but
2404 ;; does do the trick.
2405 (if (looking-at "#[^\r\n]*")
2406 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2407 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2408 (append-to-buffer buffer
(1+ (match-beginning 0))
2409 (min (point-max) (1+ (match-end 0))))))
2411 (let ((buffer-file-name file
)
2412 (org-inhibit-startup t
))
2415 (unless keepp
(funcall binding arg
))))
2417 (kill-buffer buffer
)
2418 (switch-to-buffer-other-window buffer
)
2419 (goto-char (point-min)))))
2421 (defun org-find-visible ()
2423 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2424 (get-char-property s
'invisible
)))
2426 (defun org-find-invisible ()
2428 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2429 (not (get-char-property s
'invisible
))))
2432 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2435 (defun org-export-as-org (arg &optional hidden ext-plist
2436 to-buffer body-only pub-dir
)
2437 "Make a copy wiht not-exporting stuff removed.
2438 The purpose of this function is to provide a way to export the source
2439 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2440 stuff removed. This command will remove the following:
2442 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2443 - comment blocks and trees starting with the COMMENT keyword
2444 - only trees that are consistent with `org-export-select-tags'
2445 and `org-export-exclude-tags'.
2447 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2448 all the others will be ignored (but are present so that the general
2449 mechanism to call publishing functions will work).
2451 EXT-PLIST is a property list with external parameters overriding
2452 org-mode's default settings, but still inferior to file-local
2453 settings. When PUB-DIR is set, use this as the publishing
2456 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2458 (org-infile-export-plist)))
2459 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2460 (filename (concat (file-name-as-directory
2462 (org-export-directory :org opt-plist
)))
2463 (file-name-sans-extension
2464 (file-name-nondirectory bfname
))
2466 (filename (and filename
2467 (if (equal (file-truename filename
)
2468 (file-truename bfname
))
2469 (concat filename
"-source")
2471 (backup-inhibited t
)
2472 (buffer (find-file-noselect filename
))
2473 (region (buffer-string)))
2475 (switch-to-buffer buffer
)
2478 (let ((org-inhibit-startup t
)) (org-mode))
2480 ;; Get rid of archived trees
2481 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2483 ;; Remove comment environment and comment subtrees
2484 (org-export-remove-comment-blocks-and-subtrees)
2486 ;; Get rid of excluded trees
2487 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2488 (plist-get opt-plist
:exclude-tags
))
2490 (when (or (plist-get opt-plist
:plain-source
)
2491 (not (or (plist-get opt-plist
:plain-source
)
2492 (plist-get opt-plist
:htmlized-source
))))
2493 ;; Either nothing special is requested (default call)
2494 ;; or the plain source is explicitly requested
2497 (when (plist-get opt-plist
:htmlized-source
)
2498 ;; Make the htmlized version
2501 (font-lock-fontify-buffer)
2502 (let* ((htmlize-output-type 'css
)
2503 (newbuf (htmlize-buffer)))
2504 (with-current-buffer newbuf
2505 (when org-export-htmlized-org-css-url
2506 (goto-char (point-min))
2507 (and (re-search-forward
2508 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2512 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2513 org-export-htmlized-org-css-url
)
2515 (write-file (concat filename
".html")))
2516 (kill-buffer newbuf
)))
2517 (set-buffer-modified-p nil
)
2518 (kill-buffer (current-buffer)))))
2520 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2521 (defun org-get-current-options ()
2522 "Return a string with current options as keyword options.
2523 Does include HTML export options as well as TODO and CATEGORY stuff."
2524 (require 'org-archive
)
2533 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2534 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2536 #+EXPORT_SELECT_TAGS: %s
2537 #+EXPORT_EXCLUDE_TAGS: %s
2543 #+PRIORITIES: %c %c %c
2545 #+STARTUP: %s %s %s %s %s
2551 (buffer-name) (user-full-name) user-mail-address
2552 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2553 org-export-default-language
2554 org-export-headline-levels
2555 org-export-with-section-numbers
2557 org-export-preserve-breaks
2558 org-export-html-expand
2559 org-export-with-fixed-width
2560 org-export-with-tables
2561 org-export-with-sub-superscripts
2562 org-export-with-special-strings
2563 org-export-with-footnotes
2564 org-export-with-emphasize
2565 org-export-with-timestamps
2566 org-export-with-TeX-macros
2567 org-export-with-LaTeX-fragments
2568 org-export-skip-text-before-1st-heading
2569 org-export-with-drawers
2570 org-export-with-todo-keywords
2571 org-export-with-priority
2572 org-export-with-tags
2573 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2574 (mapconcat 'identity org-export-select-tags
" ")
2575 (mapconcat 'identity org-export-exclude-tags
" ")
2576 org-export-html-link-up
2577 org-export-html-link-home
2579 (file-name-sans-extension
2580 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2582 "TODO FEEDBACK VERIFY DONE"
2583 "Me Jason Marie DONE"
2584 org-highest-priority org-lowest-priority org-default-priority
2585 (mapconcat 'identity org-drawers
" ")
2586 (cdr (assoc org-startup-folded
2587 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2588 (if org-odd-levels-only
"odd" "oddeven")
2589 (if org-hide-leading-stars
"hidestars" "showstars")
2590 (if org-startup-align-all-tables
"align" "noalign")
2591 (cond ((eq org-log-done t
) "logdone")
2592 ((equal org-log-done
'note
) "lognotedone")
2593 ((not org-log-done
) "nologdone"))
2594 (or (mapconcat (lambda (x)
2596 ((equal '(:startgroup
) x
) "{")
2597 ((equal '(:endgroup
) x
) "}")
2598 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2600 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2601 (mapconcat 'identity org-file-tags
" ")
2602 org-archive-location
2603 "org file:~/org/%s.org"
2607 (defun org-insert-export-options-template ()
2608 "Insert into the buffer a template with information for exporting."
2610 (if (not (bolp)) (newline))
2611 (let ((s (org-get-current-options)))
2612 (and (string-match "#\\+CATEGORY" s
)
2613 (setq s
(substring s
0 (match-beginning 0))))
2616 (defvar org-table-colgroup-info nil
)
2618 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2619 "Check if the table has a marking column.
2620 If yes remove the column and the special lines."
2621 (setq org-table-colgroup-info nil
)
2624 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2627 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2628 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2632 (setq org-table-clean-did-remove-column nil
)
2637 ((string-match "^[ \t]*| */ *|" x
)
2638 (setq org-table-colgroup-info
2640 (cond ((member x
'("<" "<")) :start
)
2641 ((member x
'(">" ">")) :end
)
2642 ((member x
'("<>" "<>")) :startend
)
2644 (org-split-string x
"[ \t]*|[ \t]*")))
2648 (setq org-table-clean-did-remove-column t
)
2653 ((string-match "^[ \t]*| */ *|" x
)
2654 (setq org-table-colgroup-info
2656 (cond ((member x
'("<" "<")) :start
)
2657 ((member x
'(">" ">")) :end
)
2658 ((member x
'("<>" "<>")) :startend
)
2660 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2662 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2663 nil
) ; ignore this line
2664 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2665 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2666 ;; remove the first column
2667 (replace-match "\\1|" t nil x
))))
2670 (defun org-export-cleanup-toc-line (s)
2671 "Remove tags and timestamps from lines going into the toc."
2672 (when (memq org-export-with-tags
'(not-in-toc nil
))
2673 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2674 (setq s
(replace-match "" t t s
))))
2675 (when org-export-remove-timestamps-from-toc
2676 (while (string-match org-maybe-keyword-time-regexp s
)
2677 (setq s
(replace-match "" t t s
))))
2678 (while (string-match org-bracket-link-regexp s
)
2679 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2683 (defun org-create-multibrace-regexp (left right n
)
2684 "Create a regular expression which will match a balanced sexp.
2685 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2686 as single character strings.
2687 The regexp returned will match the entire expression including the
2688 delimiters. It will also define a single group which contains the
2689 match except for the outermost delimiters. The maximum depth of
2690 stacked delimiters is N. Escaping delimiters is not possible."
2691 (let* ((nothing (concat "[^" left right
"]*?"))
2694 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
2697 re
(concat re or next
)
2698 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
2699 (concat left
"\\(" re
"\\)" right
)))
2701 (defvar org-match-substring-regexp
2703 "\\([^\\]\\)\\([_^]\\)\\("
2704 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2706 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
2708 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2709 "The regular expression matching a sub- or superscript.")
2711 (defvar org-match-substring-with-braces-regexp
2713 "\\([^\\]\\)\\([_^]\\)\\("
2714 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2716 "The regular expression matching a sub- or superscript, forcing braces.")
2719 (defun org-get-text-property-any (pos prop
&optional object
)
2720 (or (get-text-property pos prop object
)
2721 (and (setq pos
(next-single-property-change pos prop object
))
2722 (get-text-property pos prop object
))))
2724 (defun org-export-get-coderef-format (path desc
)
2726 (if (and desc
(string-match
2727 (regexp-quote (concat "(" path
")"))
2729 (replace-match "%s" t t desc
)
2732 (defun org-export-push-to-kill-ring (format)
2733 "Push buffer content to kill ring.
2734 The depends on the variable `org-export-copy-to-kill'."
2735 (when org-export-copy-to-kill-ring
2736 (kill-new (buffer-string))
2737 (when (fboundp 'x-set-selection
)
2738 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
2739 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
2740 (message "%s export done, pushed to kill ring and clipboard" format
)))
2744 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2746 ;;; org-exp.el ends here