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
))
42 (defgroup org-export nil
43 "Options for exporting org-listings."
47 (defgroup org-export-general nil
48 "General options for exporting Org-mode files."
49 :tag
"Org Export General"
53 (defvar org-export-publishing-directory nil
)
55 (defcustom org-export-run-in-background nil
56 "Non-nil means export and publishing commands will run in background.
57 This works by starting up a separate Emacs process visiting the same file
58 and doing the export from there.
59 Not all export commands are affected by this - only the ones which
60 actually write to a file, and that do not depend on the buffer state.
62 If this option is nil, you can still get background export by calling
63 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
65 If this option is t, the double prefix can be used to exceptionally
66 force an export command into the current process."
67 :group
'org-export-general
71 (defcustom org-export-select-tags
'("export")
72 "Tags that select a tree for export.
73 If any such tag is found in a buffer, all trees that do not carry one
74 of these tags will be deleted before export.
75 Inside trees that are selected like this, you can still deselect a
76 subtree by tagging it with one of the `org-export-exclude-tags'."
77 :group
'org-export-general
78 :type
'(repeat (string :tag
"Tag")))
80 (defcustom org-export-exclude-tags
'("noexport")
81 "Tags that exclude a tree from export.
82 All trees carrying any of these tags will be excluded from export.
83 This is without condition, so even subtrees inside that carry one of the
84 `org-export-select-tags' will be removed."
85 :group
'org-export-general
86 :type
'(repeat (string :tag
"Tag")))
88 ;; FIXME: rename, this is a general variable
89 (defcustom org-export-html-expand t
90 "Non-nil means, for HTML export, treat @<...> as HTML tag.
91 When nil, these tags will be exported as plain text and therefore
92 not be interpreted by a browser.
94 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
95 :group
'org-export-html
96 :group
'org-export-general
99 (defcustom org-export-with-special-strings t
100 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
101 When this option is turned on, these strings will be exported as:
104 -----+----------+--------
110 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
111 :group
'org-export-translation
114 (defcustom org-export-html-link-up
""
115 "Where should the \"UP\" link of exported HTML pages lead?"
116 :group
'org-export-html
117 :group
'org-export-general
118 :type
'(string :tag
"File or URL"))
120 (defcustom org-export-html-link-home
""
121 "Where should the \"HOME\" link of exported HTML pages lead?"
122 :group
'org-export-html
123 :group
'org-export-general
124 :type
'(string :tag
"File or URL"))
126 (defcustom org-export-language-setup
127 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
128 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
129 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
130 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
131 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
132 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
133 ("es" "Autor" "Fecha" "Índice" "Pies de página")
134 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
135 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
136 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
137 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
138 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
139 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
140 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
141 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
142 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
143 ("pl" "Autor" "Data" "Spis treści" "Przypis")
144 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
145 "Terms used in export text, translated to different languages.
146 Use the variable `org-export-default-language' to set the language,
147 or use the +OPTION lines for a per-file setting."
148 :group
'org-export-general
151 (string :tag
"HTML language tag")
152 (string :tag
"Author")
154 (string :tag
"Table of Contents")
155 (string :tag
"Footnotes"))))
157 (defcustom org-export-default-language
"en"
158 "The default language of HTML export, as a string.
159 This should have an association in `org-export-language-setup'."
160 :group
'org-export-general
163 (defvar org-export-page-description
""
164 "The page description, for the XHTML meta tag.
165 This is best set with the #+DESCRIPTION line in a file, it does not make
166 sense to set this globally.")
168 (defvar org-export-page-keywords
""
169 "The page description, for the XHTML meta tag.
170 This is best set with the #+KEYWORDS line in a file, it does not make
171 sense to set this globally.")
173 (defcustom org-export-skip-text-before-1st-heading nil
174 "Non-nil means, skip all text before the first headline when exporting.
175 When nil, that text is exported as well."
176 :group
'org-export-general
179 (defcustom org-export-headline-levels
3
180 "The last level which is still exported as a headline.
181 Inferior levels will produce itemize lists when exported.
182 Note that a numeric prefix argument to an exporter function overrides
185 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
186 :group
'org-export-general
189 (defcustom org-export-with-section-numbers t
190 "Non-nil means, add section numbers to headlines when exporting.
192 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
193 :group
'org-export-general
196 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
197 "Format of section numbers for export.
198 The variable has two components.
199 1. A list of lists, each indicating a counter type and a separator.
200 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
201 It causes causes numeric, alphabetic, or roman counters, respectively.
202 The separator is only used if another counter for a subsection is being
204 If there are more numbered section levels than entries in this lists,
205 then the last entry will be reused.
206 2. A terminator string that will be added after the entire
208 :group
'org-export-general
212 (string :tag
"Counter Type")
213 (string :tag
"Separator ")))
214 (string :tag
"Terminator")))
216 (defcustom org-export-with-toc t
217 "Non-nil means, create a table of contents in exported files.
218 The TOC contains headlines with levels up to`org-export-headline-levels'.
219 When an integer, include levels up to N in the toc, this may then be
220 different from `org-export-headline-levels', but it will not be allowed
221 to be larger than the number of headline levels.
222 When nil, no table of contents is made.
224 Headlines which contain any TODO items will be marked with \"(*)\" in
225 ASCII export, and with red color in HTML output, if the option
226 `org-export-mark-todo-in-toc' is set.
228 In HTML output, the TOC will be clickable.
230 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
232 :group
'org-export-general
234 (const :tag
"No Table of Contents" nil
)
235 (const :tag
"Full Table of Contents" t
)
236 (integer :tag
"TOC to level")))
238 (defcustom org-export-mark-todo-in-toc nil
239 "Non-nil means, mark TOC lines that contain any open TODO items."
240 :group
'org-export-general
243 (defcustom org-export-with-todo-keywords t
244 "Non-nil means, include TODO keywords in export.
245 When nil, remove all these keywords from the export."
246 :group
'org-export-general
249 (defcustom org-export-with-priority nil
250 "Non-nil means, include priority cookies in export.
251 When nil, remove priority cookies for export."
252 :group
'org-export-general
255 (defcustom org-export-preserve-breaks nil
256 "Non-nil means, preserve all line breaks when exporting.
257 Normally, in HTML output paragraphs will be reformatted. In ASCII
258 export, line breaks will always be preserved, regardless of this variable.
260 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
261 :group
'org-export-general
264 (defcustom org-export-with-archived-trees
'headline
265 "Whether subtrees with the ARCHIVE tag should be exported.
266 This can have three different values
267 nil Do not export, pretend this tree is not present
268 t Do export the entire tree
269 headline Only export the headline, but skip the tree below it."
270 :group
'org-export-general
273 (const :tag
"not at all" nil
)
274 (const :tag
"headline only" 'headline
)
275 (const :tag
"entirely" t
)))
277 (defcustom org-export-author-info t
278 "Non-nil means, insert author name and email into the exported file.
280 This option can also be set with the +OPTIONS line,
281 e.g. \"author-info:nil\"."
282 :group
'org-export-general
285 (defcustom org-export-creator-info t
286 "Non-nil means, the postamble should contain a creator sentence.
287 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
288 :group
'org-export-general
291 (defcustom org-export-time-stamp-file t
292 "Non-nil means, insert a time stamp into the exported file.
293 The time stamp shows when the file was created.
295 This option can also be set with the +OPTIONS line,
296 e.g. \"timestamp:nil\"."
297 :group
'org-export-general
300 (defcustom org-export-with-timestamps t
301 "If nil, do not export time stamps and associated keywords."
302 :group
'org-export-general
305 (defcustom org-export-remove-timestamps-from-toc t
306 "If nil, remove timestamps from the table of contents entries."
307 :group
'org-export-general
310 (defcustom org-export-with-tags
'not-in-toc
311 "If nil, do not export tags, just remove them from headlines.
312 If this is the symbol `not-in-toc', tags will be removed from table of
313 contents entries, but still be shown in the headlines of the document.
315 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
316 :group
'org-export-general
318 (const :tag
"Off" nil
)
319 (const :tag
"Not in TOC" not-in-toc
)
320 (const :tag
"On" t
)))
322 (defcustom org-export-with-drawers nil
323 "Non-nil means, export with drawers like the property drawer.
324 When t, all drawers are exported. This may also be a list of
325 drawer names to export."
326 :group
'org-export-general
328 (const :tag
"All drawers" t
)
329 (const :tag
"None" nil
)
330 (repeat :tag
"Selected drawers"
331 (string :tag
"Drawer name"))))
333 (defvar org-export-preprocess-hook nil
334 "Hook for preprocessing an export buffer.
335 Pretty much the first thing when exporting is running this hook.")
337 (defvar org-export-preprocess-after-include-files-hook nil
338 "Hook for preprocessing an export buffer.
339 This is run after the contents of included files have been inserted.")
341 (defvar org-export-preprocess-after-tree-selection-hook nil
342 "Hook for preprocessing an export buffer.
343 This is run after selection of trees to be exported has happened.
344 This selection includes tags-based selection, as well as removal
345 of commented and archived trees.")
347 (defvar org-export-preprocess-before-backend-specifics-hook nil
348 "Hook run before backend-specific functions are called during preprocessing.")
350 (defvar org-export-preprocess-final-hook nil
351 "Hook for preprocessing an export buffer.
352 This is run as the last thing in the preprocessing buffer, just before
353 returning the buffer string to the backend.")
355 (defgroup org-export-translation nil
356 "Options for translating special ascii sequences for the export backends."
357 :tag
"Org Export Translation"
360 (defcustom org-export-with-emphasize t
361 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
362 If the export target supports emphasizing text, the word will be
363 typeset in bold, italic, or underlined, respectively. Works only for
364 single words, but you can say: I *really* *mean* *this*.
365 Not all export backends support this.
367 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
368 :group
'org-export-translation
371 (defcustom org-export-with-footnotes t
372 "If nil, export [1] as a footnote marker.
373 Lines starting with [1] will be formatted as footnotes.
375 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
376 :group
'org-export-translation
379 (defcustom org-export-with-sub-superscripts t
380 "Non-nil means, interpret \"_\" and \"^\" for export.
381 When this option is turned on, you can use TeX-like syntax for sub- and
382 superscripts. Several characters after \"_\" or \"^\" will be
383 considered as a single item - so grouping with {} is normally not
384 needed. For example, the following things will be parsed as single
385 sub- or superscripts.
387 10^24 or 10^tau several digits will be considered 1 item.
388 10^-12 or 10^-tau a leading sign with digits or a word
389 x^2-y^3 will be read as x^2 - y^3, because items are
390 terminated by almost any nonword/nondigit char.
391 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
393 Still, ambiguity is possible - so when in doubt use {} to enclose the
394 sub/superscript. If you set this variable to the symbol `{}',
395 the braces are *required* in order to trigger interpretations as
396 sub/superscript. This can be helpful in documents that need \"_\"
397 frequently in plain text.
399 Not all export backends support this, but HTML does.
401 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
402 :group
'org-export-translation
404 (const :tag
"Always interpret" t
)
405 (const :tag
"Only with braces" {})
406 (const :tag
"Never interpret" nil
)))
408 (defcustom org-export-with-TeX-macros t
409 "Non-nil means, interpret simple TeX-like macros when exporting.
410 For example, HTML export converts \\alpha to α and \\AA to Å.
411 Not only real TeX macros will work here, but the standard HTML entities
412 for math can be used as macro names as well. For a list of supported
413 names in HTML export, see the constant `org-html-entities'.
414 Not all export backends support this.
416 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
417 :group
'org-export-translation
418 :group
'org-export-latex
421 (defcustom org-export-with-LaTeX-fragments nil
422 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
423 When set, the exporter will find LaTeX environments if the \\begin line is
424 the first non-white thing on a line. It will also find the math delimiters
425 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
428 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
429 :group
'org-export-translation
430 :group
'org-export-latex
433 (defcustom org-export-with-fixed-width t
434 "Non-nil means, lines starting with \":\" will be in fixed width font.
435 This can be used to have pre-formatted text, fragments of code etc. For
437 : ;; Some Lisp examples
440 will be looking just like this in also HTML. See also the QUOTE keyword.
441 Not all export backends support this.
443 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
444 :group
'org-export-translation
447 (defcustom org-match-sexp-depth
3
448 "Number of stacked braces for sub/superscript matching.
449 This has to be set before loading org.el to be effective."
450 :group
'org-export-translation
453 (defgroup org-export-tables nil
454 "Options for exporting tables in Org-mode."
455 :tag
"Org Export Tables"
458 (defcustom org-export-with-tables t
459 "If non-nil, lines starting with \"|\" define a table.
462 | Name | Address | Birthday |
463 |-------------+----------+-----------|
464 | Arthur Dent | England | 29.2.2100 |
466 Not all export backends support this.
468 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
469 :group
'org-export-tables
472 (defcustom org-export-highlight-first-table-line t
473 "Non-nil means, highlight the first table line.
474 In HTML export, this means use <th> instead of <td>.
475 In tables created with table.el, this applies to the first table line.
476 In Org-mode tables, all lines before the first horizontal separator
477 line will be formatted with <th> tags."
478 :group
'org-export-tables
481 (defcustom org-export-table-remove-special-lines t
482 "Remove special lines and marking characters in calculating tables.
483 This removes the special marking character column from tables that are set
484 up for spreadsheet calculations. It also removes the entire lines
485 marked with `!', `_', or `^'. The lines with `$' are kept, because
486 the values of constants may be useful to have."
487 :group
'org-export-tables
490 (defcustom org-export-prefer-native-exporter-for-tables nil
491 "Non-nil means, always export tables created with table.el natively.
492 Natively means, use the HTML code generator in table.el.
493 When nil, Org-mode's own HTML generator is used when possible (i.e. if
494 the table does not use row- or column-spanning). This has the
495 advantage, that the automatic HTML conversions for math symbols and
496 sub/superscripts can be applied. Org-mode's HTML generator is also
498 :group
'org-export-tables
502 (defgroup org-export-xml nil
503 "Options specific for XML export of Org-mode files."
504 :tag
"Org Export XML"
509 ;;; Variables, constants, and parameter plists
511 (defconst org-level-max
20)
513 (defvar org-current-export-file nil
) ; dynamically scoped parameter
514 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
515 (defvar org-export-opt-plist nil
516 "Contains the current option plist.")
517 (defvar org-last-level nil
) ; dynamically scoped variable
518 (defvar org-min-level nil
) ; dynamically scoped variable
519 (defvar org-levels-open nil
) ; dynamically scoped parameter
521 (defconst org-export-plist-vars
522 '((:link-up nil org-export-html-link-up
)
523 (:link-home nil org-export-html-link-home
)
524 (:language nil org-export-default-language
)
525 (:keywords nil org-export-page-keywords
)
526 (:description nil org-export-page-description
)
527 (:customtime nil org-display-custom-times
)
528 (:headline-levels
"H" org-export-headline-levels
)
529 (:section-numbers
"num" org-export-with-section-numbers
)
530 (:section-number-format nil org-export-section-number-format
)
531 (:table-of-contents
"toc" org-export-with-toc
)
532 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
533 (:archived-trees nil org-export-with-archived-trees
)
534 (:emphasize
"*" org-export-with-emphasize
)
535 (:sub-superscript
"^" org-export-with-sub-superscripts
)
536 (:special-strings
"-" org-export-with-special-strings
)
537 (:footnotes
"f" org-export-with-footnotes
)
538 (:drawers
"d" org-export-with-drawers
)
539 (:tags
"tags" org-export-with-tags
)
540 (:todo-keywords
"todo" org-export-with-todo-keywords
)
541 (:priority
"pri" org-export-with-priority
)
542 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
543 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
544 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
545 (:fixed-width
":" org-export-with-fixed-width
)
546 (:timestamps
"<" org-export-with-timestamps
)
547 (:author-info
"author" org-export-author-info
)
548 (:creator-info
"creator" org-export-creator-info
)
549 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
550 (:tables
"|" org-export-with-tables
)
551 (:table-auto-headline nil org-export-highlight-first-table-line
)
552 (:style-include-default nil org-export-html-style-include-default
)
553 (:style-include-scripts nil org-export-html-style-include-scripts
)
554 (:style nil org-export-html-style
)
555 (:style-extra nil org-export-html-style-extra
)
556 (:agenda-style nil org-agenda-export-html-style
)
557 (:convert-org-links nil org-export-html-link-org-files-as-html
)
558 (:inline-images nil org-export-html-inline-images
)
559 (:html-extension nil org-export-html-extension
)
560 (:html-table-tag nil org-export-html-table-tag
)
561 (:expand-quoted-html
"@" org-export-html-expand
)
562 (:timestamp nil org-export-html-with-timestamp
)
563 (:publishing-directory nil org-export-publishing-directory
)
564 (:preamble nil org-export-html-preamble
)
565 (:postamble nil org-export-html-postamble
)
566 (:auto-preamble nil org-export-html-auto-preamble
)
567 (:auto-postamble nil org-export-html-auto-postamble
)
568 (:author nil user-full-name
)
569 (:email nil user-mail-address
)
570 (:select-tags nil org-export-select-tags
)
571 (:exclude-tags nil org-export-exclude-tags
))
572 "List of properties that represent export/publishing variables.
573 Each element is a list of 3 items:
574 1. The property that is used internally, and also for org-publish-project-alist
575 2. The string that can be used in the OPTION lines to set this option,
576 or nil if this option cannot be changed in this way
577 3. The customization variable that sets the default for this option."
580 (defun org-default-export-plist ()
581 "Return the property list with default settings for the export variables."
582 (let ((l org-export-plist-vars
) rtn e s v
)
583 (while (setq e
(pop l
))
585 v
(if (boundp s
) (symbol-value s
) nil
)
586 rtn
(cons (car e
) (cons v rtn
))))
589 (defvar org-export-inbuffer-options-extra nil
590 "List of additional in-buffer options that should be detected.
591 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
592 etc. Extensions can add to this list to get their options detected, and they
593 can then add a function to `org-export-options-filters' to process these
595 Each element in this list must be a list, with the in-buffer keyword as car,
596 and a property (a symbol) as the next element. All occurrences of the
597 keyword will be found, the values concatenated with a space character
598 in between, and the result stored in the export options property list.")
600 (defvar org-export-options-filters nil
601 "Functions to be called to finalize the export/publishing options.
602 All these options are stored in a property list, and each of the functions
603 in this hook gets a chance to modify this property list. Each function
604 must accept the property list as an argument, and must return the (possibly
607 ;; FIXME: should we fold case here?
608 (defun org-infile-export-plist ()
609 "Return the property list with file-local settings for export."
613 (goto-char (point-min))
614 (let ((re (org-make-options-regexp
616 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
617 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
618 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
619 "KEYWORDS" "DESCRIPTION")
620 (mapcar 'car org-export-inbuffer-options-extra
))))
621 p key val text options a pr style
623 ext-setup-or-nil setup-contents
(start 0))
624 (while (or (and ext-setup-or-nil
625 (string-match re ext-setup-or-nil start
)
626 (setq start
(match-end 0)))
627 (and (setq ext-setup-or-nil nil start
0)
628 (re-search-forward re nil t
)))
629 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
630 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
632 ((setq a
(assoc key org-export-inbuffer-options-extra
))
634 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
635 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
636 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
637 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
638 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
639 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
640 ((string-equal key
"DESCRIPTION")
641 (setq p
(plist-put p
:description val
)))
642 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
643 ((string-equal key
"STYLE")
644 (setq style
(concat style
"\n" val
)))
645 ((string-equal key
"LATEX_HEADER")
646 (setq latex-header
(concat latex-header
"\n" val
)))
647 ((string-equal key
"TEXT")
648 (setq text
(if text
(concat text
"\n" val
) val
)))
649 ((string-equal key
"OPTIONS")
650 (setq options
(concat val
" " options
)))
651 ((string-equal key
"LINK_UP")
652 (setq p
(plist-put p
:link-up val
)))
653 ((string-equal key
"LINK_HOME")
654 (setq p
(plist-put p
:link-home val
)))
655 ((string-equal key
"EXPORT_SELECT_TAGS")
656 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
657 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
658 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
659 ((equal key
"SETUPFILE")
660 (setq setup-contents
(org-file-contents
662 (org-remove-double-quotes
665 (if (not ext-setup-or-nil
)
666 (setq ext-setup-or-nil setup-contents start
0)
667 (setq ext-setup-or-nil
668 (concat (substring ext-setup-or-nil
0 start
)
669 "\n" setup-contents
"\n"
670 (substring ext-setup-or-nil start
)))))))
671 (setq p
(plist-put p
:text text
))
672 (when style
(setq p
(plist-put p
:style-extra style
)))
674 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
676 (setq p
(org-export-add-options-to-plist p options
)))
677 ;; Add macro definitions
678 (goto-char (point-min))
679 (while (re-search-forward
680 "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
682 (setq p
(plist-put p
(intern (concat ":macro-"
683 (downcase (match-string 1))))
687 (defun org-export-add-options-to-plist (p options
)
688 "Parse an OPTIONS line and set values in the property list P."
691 (let ((op org-export-plist-vars
))
692 (while (setq o
(pop op
))
694 (string-match (concat (regexp-quote (nth 1 o
))
695 ":\\([^ \t\n\r;,.]*\\)")
697 (setq p
(plist-put p
(car o
)
698 (car (read-from-string
699 (match-string 1 options
))))))))))
702 (defun org-export-add-subtree-options (p pos
)
703 "Add options in subtree at position POS to property list P."
706 (when (org-at-heading-p)
708 ;; This is actually read in `org-export-get-title-from-subtree'
709 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
710 ;; (setq p (plist-put p :title a)))
711 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
712 (setq p
(plist-put p
:text a
)))
713 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
714 (setq p
(plist-put p
:author a
)))
715 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
716 (setq p
(plist-put p
:date a
)))
717 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
718 (setq p
(org-export-add-options-to-plist p a
)))))
721 (defun org-export-directory (type plist
)
722 (let* ((val (plist-get plist
:publishing-directory
))
724 (or (cdr (assoc type val
)) ".")
728 (defun org-export-process-option-filters (plist)
729 (let ((functions org-export-options-filters
) f
)
730 (while (setq f
(pop functions
))
731 (setq plist
(funcall f plist
))))
735 (defun org-export (&optional arg
)
736 "Export dispatcher for Org-mode.
737 When `org-export-run-in-background' is non-nil, try to run the command
738 in the background. This will be done only for commands that write
739 to a file. For details see the docstring of `org-export-run-in-background'.
741 The prefix argument ARG will be passed to the exporter. However, if
742 ARG is a double universal prefix `C-u C-u', that means to inverse the
743 value of `org-export-run-in-background'."
745 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
746 (help "[t] insert the export option template
747 \[v] limit export to visible part of outline tree
751 \[h] export as HTML [H] to temporary buffer [R] export region
752 \[b] export as HTML and open in browser
754 \[l] export as LaTeX [L] to temporary buffer
755 \[p] export as LaTeX and process to PDF
756 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
758 \[D] export as DocBook
759 \[V] export as DocBook, process to PDF, and open the resulting PDF document
763 \[i] export current file as iCalendar file
764 \[I] export all agenda files as iCalendar files
765 \[c] export agenda files into combined iCalendar file
767 \[F] publish current file [P] publish current project
768 \[X] publish a project... [A] publish all projects")
770 '((?t org-insert-export-options-template nil
)
771 (?v org-export-visible nil
)
772 (?a org-export-as-ascii t
)
773 (?h org-export-as-html t
)
774 (?b org-export-as-html-and-open t
)
775 (?H org-export-as-html-to-buffer nil
)
776 (?R org-export-region-as-html nil
)
777 (?x org-export-as-xoxo t
)
778 (?D org-export-as-docbook t
)
779 (?V org-export-as-docbook-pdf-and-open t
)
780 (?l org-export-as-latex t
)
781 (?p org-export-as-pdf t
)
782 (?d org-export-as-pdf-and-open t
)
783 (?L org-export-as-latex-to-buffer nil
)
784 (?i org-export-icalendar-this-file t
)
785 (?I org-export-icalendar-all-agenda-files t
)
786 (?c org-export-icalendar-combine-agenda-files t
)
787 (?F org-publish-current-file t
)
788 (?P org-publish-current-project t
)
790 (?A org-publish-all t
)))
793 (save-window-excursion
794 (delete-other-windows)
795 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
797 (org-fit-window-to-buffer (get-buffer-window
798 "*Org Export/Publishing Help*"))
799 (message "Select command: ")
800 (setq r1
(read-char-exclusive))))
801 (setq r2
(if (< r1
27) (+ r1
96) r1
))
802 (unless (setq ass
(assq r2 cmds
))
803 (error "No command associated with key %c" r1
))
804 (if (and bg
(nth 2 ass
)
805 (not (buffer-base-buffer))
806 (not (org-region-active-p)))
807 ;; execute in background
808 (let ((p (start-process
809 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
811 (expand-file-name invocation-name invocation-directory
)
814 "--eval" "(require 'org-exp)"
815 "--eval" "(setq org-wait .2)"
817 "-f" (symbol-name (nth 1 ass
)))))
818 (set-process-sentinel p
'org-export-process-sentinel
)
819 (message "Background process \"%s\": started" p
))
820 ;; background processing not requested, or not possible
821 (call-interactively (nth 1 ass
)))))
823 (defun org-export-process-sentinel (process status
)
824 (if (string-match "\n+\\'" status
)
825 (setq status
(substring status
0 -
1)))
826 (message "Background process \"%s\": %s" process status
))
828 (defconst org-html-entities
869 ("Aring") ("AA".
"Å")
958 ("varepsilon".
"ε")
971 ("sigmaf") ("varsigma".
"ς")
979 ("thetasym") ("vartheta".
"ϑ")
982 ("bull") ("bullet".
"•")
983 ("hellip") ("dots".
"…")
993 ("larr") ("leftarrow".
"←") ("gets".
"←")
994 ("uarr") ("uparrow".
"↑")
995 ("rarr") ("to".
"→") ("rightarrow".
"→")
996 ("darr")("downarrow".
"↓")
997 ("harr") ("leftrightarrow".
"↔")
998 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
999 ("lArr") ("Leftarrow".
"⇐")
1000 ("uArr") ("Uparrow".
"⇑")
1001 ("rArr") ("Rightarrow".
"⇒")
1002 ("dArr") ("Downarrow".
"⇓")
1003 ("hArr") ("Leftrightarrow".
"⇔")
1005 ("part") ("partial".
"∂")
1006 ("exist") ("exists".
"∃")
1007 ("empty") ("emptyset".
"∅")
1009 ("isin") ("in".
"∈")
1015 ("lowast") ("ast".
"∗")
1017 ("prop") ("proptp".
"∝")
1018 ("infin") ("infty".
"∞")
1019 ("ang") ("angle".
"∠")
1020 ("and") ("wedge".
"∧")
1021 ("or") ("vee".
"∨")
1027 ("cong") ("simeq".
"≅")
1028 ("asymp")("approx".
"≈")
1029 ("ne") ("neq".
"≠")
1033 ("sub") ("subset".
"⊂")
1034 ("sup") ("supset".
"⊃")
1041 ("sdot") ("cdot".
"⋅")
1048 ("loz") ("Diamond".
"◊")
1049 ("spades") ("spadesuit".
"♠")
1050 ("clubs") ("clubsuit".
"♣")
1051 ("hearts") ("diamondsuit".
"♥")
1052 ("diams") ("diamondsuit".
"♦")
1053 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1120 "Entities for TeX->HTML translation.
1121 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1122 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1123 In that case, \"\\ent\" will be translated to \"&other;\".
1124 The list contains HTML entities for Latin-1, Greek and other symbols.
1125 It is supplemented by a number of commonly used TeX macros with appropriate
1126 translations. There is currently no way for users to extend this.")
1128 ;;; General functions for all backends
1130 (defvar org-export-target-aliases nil
1131 "Alist of targets with invisible aliases.")
1132 (defvar org-export-preferred-target-alist nil
1133 "Alist of section id's with preferred aliases.")
1134 (defvar org-export-code-refs nil
1135 "Alist of code references and line numbers")
1137 (defun org-export-preprocess-string (string &rest parameters
)
1138 "Cleanup STRING so that that the true exported has a more consistent source.
1139 This function takes STRING, which should be a buffer-string of an org-file
1140 to export. It then creates a temporary buffer where it does its job.
1141 The result is then again returned as a string, and the exporter works
1142 on this string to produce the exported version."
1144 (let* ((htmlp (plist-get parameters
:for-html
))
1145 (asciip (plist-get parameters
:for-ascii
))
1146 (latexp (plist-get parameters
:for-LaTeX
))
1147 (docbookp (plist-get parameters
:for-docbook
))
1148 (backend (cond (htmlp 'html
)
1151 (docbookp 'docbook
)))
1152 (archived-trees (plist-get parameters
:archived-trees
))
1153 (inhibit-read-only t
)
1154 (drawers org-drawers
)
1155 (outline-regexp "\\*+ ")
1158 (setq org-export-target-aliases nil
)
1159 (setq org-export-preferred-target-alist nil
)
1160 (setq org-export-code-refs nil
)
1162 (with-current-buffer (get-buffer-create " org-mode-tmp")
1165 (setq case-fold-search t
)
1167 ;; Remove license-to-kill stuff
1168 ;; The caller marks some stuff for killing, stuff that has been
1169 ;; used to create the page title, for example.
1170 (org-export-kill-licensed-text)
1172 (let ((org-inhibit-startup t
)) (org-mode))
1173 (setq case-fold-search t
)
1176 (run-hooks 'org-export-preprocess-hook
)
1178 ;; Process the macros
1179 (org-export-preprocess-apply-macros)
1180 (run-hooks 'org-export-preprocess-after-macros-hook
)
1182 (untabify (point-min) (point-max))
1184 ;; Handle include files, and call a hook
1185 (org-export-handle-include-files)
1186 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1188 ;; Get rid of archived trees
1189 (org-export-remove-archived-trees archived-trees
)
1191 ;; Remove comment environment and comment subtrees
1192 (org-export-remove-comment-blocks-and-subtrees)
1194 ;; Get rid of excluded trees, and call a hook
1195 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1196 (plist-get parameters
:exclude-tags
))
1197 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1199 ;; Handle source code snippets
1200 (org-export-replace-src-segments-and-examples backend
)
1202 ;; Protect short examples marked by a leading colon
1203 (org-export-protect-colon-examples)
1205 ;; Normalize footnotes
1206 (when (plist-get parameters
:footnotes
)
1207 (org-footnote-normalize nil t
))
1209 ;; Find all headings and compute the targets for them
1210 (setq target-alist
(org-export-define-heading-targets target-alist
))
1212 ;; Get rid of drawers
1213 (org-export-remove-or-extract-drawers drawers
1214 (plist-get parameters
:drawers
))
1216 ;; Get the correct stuff before the first headline
1217 (when (plist-get parameters
:skip-before-1st-heading
)
1218 (goto-char (point-min))
1219 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1220 (delete-region (point-min) (match-beginning 0))
1221 (goto-char (point-min))
1223 (when (plist-get parameters
:add-text
)
1224 (goto-char (point-min))
1225 (insert (plist-get parameters
:add-text
) "\n"))
1227 ;; Remove todo-keywords before exporting, if the user has requested so
1228 (org-export-remove-headline-metadata parameters
)
1230 ;; Find targets in comments and move them out of comments,
1231 ;; but mark them as targets that should be invisible
1232 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1234 ;; Select and protect backend specific stuff, throw away stuff
1235 ;; that is specific for other backends
1236 (org-export-select-backend-specific-text backend
)
1238 ;; Protect quoted subtrees
1239 (org-export-protect-quoted-subtrees)
1241 ;; Remove clock lines
1242 (org-export-remove-clock-lines)
1244 ;; Protect verbatim elements
1245 (org-export-protect-verbatim)
1247 ;; Blockquotes, verse, and center
1248 (org-export-mark-blockquote-verse-center)
1250 ;; Remove timestamps, if the user has requested so
1251 (unless (plist-get parameters
:timestamps
)
1252 (org-export-remove-timestamps))
1254 ;; Attach captions to the correct object
1255 (setq target-alist
(org-export-attach-captions-and-attributes
1256 backend target-alist
))
1258 ;; Find matches for radio targets and turn them into internal links
1259 (org-export-mark-radio-links)
1261 ;; Find all links that contain a newline and put them into a single line
1262 (org-export-concatenate-multiline-links)
1264 ;; Normalize links: Convert angle and plain links into bracket links
1265 ;; and expand link abbreviations
1266 (org-export-normalize-links)
1268 ;; Find all internal links. If they have a fuzzy match (i.e. not
1269 ;; a *dedicated* target match, let the link point to the
1270 ;; corresponding section.
1271 (org-export-target-internal-links target-alist
)
1273 ;; Find multiline emphasis and put them into single line
1274 (when (plist-get parameters
:emph-multiline
)
1275 (org-export-concatenate-multiline-emphasis))
1277 ;; Remove special table lines
1278 (when org-export-table-remove-special-lines
1279 (org-export-remove-special-table-lines))
1282 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1284 ;; LaTeX-specific preprocessing
1286 (require 'org-latex nil
)
1287 (org-export-latex-preprocess parameters
))
1289 ;; ASCII-specific preprocessing
1291 (org-export-ascii-preprocess parameters
))
1293 ;; HTML-specific preprocessing
1295 (org-export-html-preprocess parameters
))
1297 ;; DocBook-specific preprocessing
1299 (require 'org-docbook nil
)
1300 (org-export-docbook-preprocess parameters
))
1302 ;; Remove or replace comments
1303 (org-export-handle-comments (plist-get parameters
:comments
))
1305 ;; Run the final hook
1306 (run-hooks 'org-export-preprocess-final-hook
)
1308 (setq rtn
(buffer-string)))
1309 (kill-buffer " org-mode-tmp")
1312 (defun org-export-kill-licensed-text ()
1313 "Remove all text that is marked with a :org-license-to-kill property."
1315 (while (setq p
(text-property-any (point-min) (point-max)
1316 :org-license-to-kill t
))
1318 p
(or (next-single-property-change p
:org-license-to-kill
)
1321 (defun org-export-define-heading-targets (target-alist)
1322 "Find all headings and define the targets for them.
1323 The new targets are added to TARGET-ALIST, which is also returned."
1324 (goto-char (point-min))
1325 (org-init-section-numbers)
1326 (let ((re (concat "^" org-outline-regexp
1327 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1328 level target last-section-target a id
)
1329 (while (re-search-forward re nil t
)
1332 (setq id
(org-match-string-no-properties 2))
1333 (push (cons id target
) target-alist
)
1334 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1336 (push (list last-section-target
)
1337 org-export-target-aliases
)
1338 (car org-export-target-aliases
))))
1339 (push (caar target-alist
) (cdr a
))
1340 (when (equal (match-string 1) "CUSTOM_ID")
1341 (if (not (assoc last-section-target
1342 org-export-preferred-target-alist
))
1343 (push (cons last-section-target id
)
1344 org-export-preferred-target-alist
))))
1345 (setq level
(org-reduced-level
1346 (save-excursion (goto-char (point-at-bol))
1347 (org-outline-level))))
1348 (setq target
(org-solidify-link-text
1349 (format "sec-%s" (org-section-number level
))))
1350 (setq last-section-target target
)
1351 (push (cons target target
) target-alist
)
1352 (add-text-properties
1353 (point-at-bol) (point-at-eol)
1354 (list 'target target
)))))
1357 (defun org-export-handle-invisible-targets (target-alist)
1358 "Find targets in comments and move them out of comments.
1359 Mark them as invisible targets."
1361 (goto-char (point-min))
1362 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1363 ;; Check if the line before or after is a headline with a target
1364 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1365 (get-text-property (point-at-bol 2) 'target
)))
1367 ;; use the existing target in a neighboring line
1368 (setq tmp
(match-string 2))
1370 (and (looking-at "\n") (delete-char 1))
1371 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1373 (setq a
(or (assoc target org-export-target-aliases
)
1375 (push (list target
) org-export-target-aliases
)
1376 (car org-export-target-aliases
))))
1378 ;; Make an invisible target
1379 (replace-match "\\1(INVISIBLE)"))))
1382 (defun org-export-target-internal-links (target-alist)
1383 "Find all internal links and assign targets to them.
1384 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1385 let the link point to the corresponding section.
1386 This function also handles the id links, if they have a match in
1388 (goto-char (point-min))
1389 (while (re-search-forward org-bracket-link-regexp nil t
)
1391 (let* ((md (match-data))
1392 (desc (match-end 2))
1393 (link (org-link-unescape (match-string 1)))
1394 (slink (org-solidify-link-text link
))
1395 found props pos cref
1398 ((= (string-to-char link
) ?
#)
1399 ;; user wants exactly this link
1401 ((cdr (assoc slink target-alist
))
1402 (or (cdr (assoc (assoc slink target-alist
)
1403 org-export-preferred-target-alist
))
1404 (cdr (assoc slink target-alist
))))
1405 ((and (string-match "^id:" link
)
1406 (cdr (assoc (substring link
3) target-alist
))))
1407 ((string-match "^(\\(.*\\))$" link
)
1408 (setq cref
(match-string 1 link
))
1409 (concat "coderef:" cref
))
1410 ((string-match org-link-types-re link
) nil
)
1411 ((or (file-name-absolute-p link
)
1412 (string-match "^\\." link
))
1416 (setq found
(condition-case nil
(org-link-search link
)
1419 (or (org-on-heading-p)
1420 (not (eq found
'dedicated
))))
1421 (or (get-text-property (point) 'target
)
1424 (1- (or (previous-single-property-change
1425 (point) 'target
) 0)))
1429 (goto-char (match-beginning 1))
1430 (setq props
(text-properties-at (point)))
1431 (delete-region (match-beginning 1) (match-end 1))
1434 (unless desc
(insert "][" link
))
1435 (add-text-properties pos
(point) props
))))))
1437 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1438 "Remove drawers, or extract the content.
1439 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1440 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1441 whose content to keep."
1442 (unless (eq t exp-drawers
)
1443 (goto-char (point-min))
1444 (let ((re (concat "^[ \t]*:\\("
1447 (org-delete-all exp-drawers
1448 (copy-sequence all-drawers
))
1452 (while (re-search-forward re nil t
)
1454 (setq beg
(match-beginning 0)
1456 (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
1459 ;; terminated in this entry
1461 (delete-region beg
(match-end 1))
1463 (goto-char eol
))))))))
1465 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1466 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1467 Both arguments are lists of tags.
1468 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1470 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1472 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1473 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1476 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1480 (goto-char (point-min))
1481 (when (and select-tags
1483 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1484 ;; At least one tree is marked for export, this means
1485 ;; all the unmarked stuff needs to go.
1486 ;; Dig out the trees that should be exported
1487 (goto-char (point-min))
1488 (outline-next-heading)
1490 (put-text-property beg
(point-max) :org-delete t
)
1491 (while (re-search-forward re-sel nil t
)
1492 (when (org-on-heading-p)
1493 (org-back-to-heading)
1494 (remove-text-properties
1495 (max (1- (point)) (point-min))
1496 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1498 (while (and (org-up-heading-safe)
1499 (get-text-property (point) :org-delete
))
1500 (remove-text-properties (max (1- (point)) (point-min))
1501 (point-at-eol) '(:org-delete t
)))
1503 ;; Remove the trees explicitly marked for noexport
1505 (goto-char (point-min))
1506 (while (re-search-forward re-excl nil t
)
1507 (when (org-at-heading-p)
1508 (org-back-to-heading t
)
1510 (org-end-of-subtree t
)
1511 (delete-region beg
(point)))))
1512 ;; Remove everything that is now still marked for deletion
1513 (goto-char (point-min))
1514 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1515 (setq end
(or (next-single-property-change beg
:org-delete
)
1517 (delete-region beg end
))))
1519 (defun org-export-remove-archived-trees (export-archived-trees)
1520 "Remove archived trees.
1521 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1522 When it is t, the entire archived tree will be exported.
1523 When it is nil the entire tree including the headline will be removed
1525 (let ((re-archive (concat ":" org-archive-tag
":"))
1527 (when (not (eq export-archived-trees t
))
1528 (goto-char (point-min))
1529 (while (re-search-forward re-archive nil t
)
1530 (if (not (org-on-heading-p t
))
1531 (org-end-of-subtree t
)
1532 (beginning-of-line 1)
1533 (setq a
(if export-archived-trees
1534 (1+ (point-at-eol)) (point))
1535 b
(org-end-of-subtree t
))
1536 (if (> b a
) (delete-region a b
)))))))
1538 (defun org-export-remove-headline-metadata (opts)
1539 "Remove meta data from the headline, according to user options."
1540 (let ((re org-complex-heading-regexp
)
1541 (todo (plist-get opts
:todo-keywords
))
1542 (tags (plist-get opts
:tags
))
1543 (pri (plist-get opts
:priority
))
1546 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1547 (when (or (not todo
) (not tags
) (not pri
))
1548 (goto-char (point-min))
1549 (while (re-search-forward re nil t
)
1551 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1553 (replace-match rpl t t
))))))
1555 (defun org-export-remove-timestamps ()
1556 "Remove timestamps and keywords for export."
1557 (goto-char (point-min))
1558 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1561 (unless (save-match-data (org-at-table-p))
1563 (beginning-of-line 1)
1564 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1565 (replace-match ""))))))
1567 (defun org-export-remove-clock-lines ()
1568 "Remove clock lines for export."
1569 (goto-char (point-min))
1570 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1571 (while (re-search-forward re nil t
)
1573 (replace-match "")))))
1575 (defun org-export-protect-quoted-subtrees ()
1576 "Mark quoted subtrees with the protection property."
1577 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1578 (goto-char (point-min))
1579 (while (re-search-forward re-quote nil t
)
1580 (goto-char (match-beginning 0))
1582 (add-text-properties (point) (org-end-of-subtree t
)
1583 '(org-protected t
)))))
1585 (defun org-export-protect-verbatim ()
1586 "Mark verbatim snippets with the protection property."
1587 (goto-char (point-min))
1588 (while (re-search-forward org-verbatim-re nil t
)
1589 (add-text-properties (match-beginning 4) (match-end 4)
1591 (goto-char (1+ (match-end 4)))))
1593 (defun org-export-protect-colon-examples ()
1594 "Protect lines starting with a colon."
1595 (goto-char (point-min))
1596 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1597 (while (re-search-forward re nil t
)
1598 (beginning-of-line 1)
1600 (while (looking-at re
)
1602 (or (eobp) (forward-char 1)))
1603 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1604 '(org-protected t
)))))
1606 (defun org-export-select-backend-specific-text (backend)
1608 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1609 (html "HTML" "BEGIN_HTML" "END_HTML")
1610 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1611 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1612 (case-fold-search t
)
1616 (setq fmt
(pop formatters
))
1617 (when (eq (car fmt
) backend
)
1618 ;; This is selected code, put it into the file for real
1619 (goto-char (point-min))
1620 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1621 ":[ \t]*\\(.*\\)") nil t
)
1622 (replace-match "\\1" t
)
1623 (add-text-properties
1624 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1625 '(org-protected t
))))
1626 (goto-char (point-min))
1627 (while (re-search-forward
1629 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1630 (cadddr fmt
) "\\>.*\n?") nil t
)
1631 (if (eq (car fmt
) backend
)
1633 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1635 ;; No, this is for a different backend, kill it
1636 (delete-region (match-beginning 0) (match-end 0)))))))
1638 (defun org-export-mark-blockquote-verse-center ()
1639 "Mark block quote and verse environments with special cookies.
1640 These special cookies will later be interpreted by the backend."
1642 (goto-char (point-min))
1643 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1645 (replace-match (if (equal (downcase (match-string 1)) "end")
1646 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1649 (goto-char (point-min))
1650 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1651 (replace-match (if (equal (downcase (match-string 1)) "end")
1652 "ORG-VERSE-END" "ORG-VERSE-START")
1655 (goto-char (point-min))
1656 (while (re-search-forward "^#\\+\\(begin\\|end\\)_center\\>.*" nil t
)
1657 (replace-match (if (equal (downcase (match-string 1)) "end")
1658 "ORG-CENTER-END" "ORG-CENTER-START")
1661 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1662 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1663 If the next thing following is a table, add the text properties to the first
1664 table line. If it is a link, add it to the line containing the link."
1665 (goto-char (point-min))
1666 (remove-text-properties (point-min) (point-max)
1667 '(org-caption nil org-attributes nil
))
1668 (let ((case-fold-search t
)
1669 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1671 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1673 "^#\\+label:[ \t]+\\(.*\\)"
1677 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1679 (while (re-search-forward re nil t
)
1682 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1684 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1686 (setq label
(org-trim (match-string 3))))
1688 (add-text-properties (point-at-bol) (point-at-eol)
1689 (list 'org-caption cap
1690 'org-attributes attr
1692 (if label
(push (cons label label
) target-alist
))
1693 (setq cap nil attr nil label nil
)))))
1696 (defun org-export-remove-comment-blocks-and-subtrees ()
1697 "Remove the comment environment, and also commented subtrees."
1698 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1699 (case-fold-search nil
))
1700 ;; Remove comment environment
1701 (goto-char (point-min))
1702 (while (re-search-forward
1703 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1704 (replace-match "" t t
))
1705 ;; Remove subtrees that are commented
1706 (goto-char (point-min))
1707 (while (re-search-forward re-commented nil t
)
1708 (goto-char (match-beginning 0))
1709 (delete-region (point) (org-end-of-subtree t
)))))
1711 (defun org-export-handle-comments (commentsp)
1712 "Remove comments, or convert to backend-specific format.
1713 COMMENTSP can be a format string for publishing comments.
1714 When it is nil, all comments will be removed."
1715 (let ((re "^#\\(.*\n?\\)")
1717 (goto-char (point-min))
1718 (while (or (looking-at re
)
1719 (re-search-forward re nil t
))
1720 (setq pos
(match-beginning 0))
1722 (progn (add-text-properties
1723 (match-beginning 0) (match-end 0) '(org-protected t
))
1724 (replace-match (format commentsp
(match-string 1)) t t
))
1725 (goto-char (1+ pos
))
1728 (goto-char (max (point-min) (1- pos
))))))))
1730 (defun org-export-mark-radio-links ()
1731 "Find all matches for radio targets and turn them into internal links."
1732 (let ((re-radio (and org-target-link-regexp
1733 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1734 (goto-char (point-min))
1736 (while (re-search-forward re-radio nil t
)
1738 (replace-match "\\1[[\\2]]"))))))
1740 (defun org-export-remove-special-table-lines ()
1741 "Remove tables lines that are used for internal purposes."
1742 (goto-char (point-min))
1743 (while (re-search-forward "^[ \t]*|" nil t
)
1744 (beginning-of-line 1)
1745 (if (or (looking-at "[ \t]*| *[!_^] *|")
1746 (and (looking-at ".*?| *<[0-9]+> *|")
1747 (not (looking-at ".*?| *[^ <|]"))))
1748 (delete-region (max (point-min) (1- (point-at-bol)))
1752 (defun org-export-normalize-links ()
1753 "Convert all links to bracket links, and expand link abbreviations."
1754 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1755 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1756 (goto-char (point-min))
1757 (while (re-search-forward re-plain-link nil t
)
1758 (goto-char (1- (match-end 0)))
1759 (org-if-unprotected-at (1+ (match-beginning 0))
1760 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1761 ":" (match-string 3) "]]")))
1762 ;; added 'org-link face to links
1763 (put-text-property 0 (length s
) 'face
'org-link s
)
1764 (replace-match s t t
))))
1765 (goto-char (point-min))
1766 (while (re-search-forward re-angle-link nil t
)
1767 (goto-char (1- (match-end 0)))
1769 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1770 ":" (match-string 3) "]]")))
1771 (put-text-property 0 (length s
) 'face
'org-link s
)
1772 (replace-match s t t
))))
1773 (goto-char (point-min))
1774 (while (re-search-forward org-bracket-link-regexp nil t
)
1775 (goto-char (1- (match-end 0)))
1777 (let* ((xx (save-match-data
1779 (org-link-expand-abbrev (match-string 1)))))
1781 "[[" (org-add-props (copy-sequence xx
)
1782 nil
'org-protected t
)
1786 (concat "[" (org-add-props
1791 (put-text-property 0 (length s
) 'face
'org-link s
)
1792 (replace-match s t t
))))))
1794 (defun org-export-concatenate-multiline-links ()
1795 "Find multi-line links and put it all into a single line.
1796 This is to make sure that the line-processing export backends
1797 can work correctly."
1798 (goto-char (point-min))
1799 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1801 (replace-match "\\1 \\3")
1802 (goto-char (match-beginning 0)))))
1804 (defun org-export-concatenate-multiline-emphasis ()
1805 "Find multi-line emphasis and put it all into a single line.
1806 This is to make sure that the line-processing export backends
1807 can work correctly."
1808 (goto-char (point-min))
1809 (while (re-search-forward org-emph-re nil t
)
1810 (if (and (not (= (char-after (match-beginning 3))
1811 (char-after (match-beginning 4))))
1812 (save-excursion (goto-char (match-beginning 0))
1813 (save-match-data (not (org-at-table-p)))))
1815 (subst-char-in-region (match-beginning 0) (match-end 0)
1817 (goto-char (1- (match-end 0))))
1818 (goto-char (1+ (match-beginning 0))))))
1820 (defun org-export-grab-title-from-buffer ()
1821 "Get a title for the current document, from looking at the buffer."
1822 (let ((inhibit-read-only t
))
1824 (goto-char (point-min))
1825 (let ((end (if (looking-at org-outline-regexp
)
1827 (save-excursion (outline-next-heading) (point)))))
1828 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1829 ;; Mark the line so that it will not be exported as normal text.
1831 (add-text-properties (match-beginning 0) (match-end 0)
1832 (list :org-license-to-kill t
)))
1833 ;; Return the title string
1834 (org-trim (match-string 0)))))))
1836 (defun org-export-get-title-from-subtree ()
1837 "Return subtree title and exclude it from export."
1838 (let (title (rbeg (region-beginning)) (rend (region-end)))
1841 (when (and (org-at-heading-p)
1842 (>= (org-end-of-subtree t t
) rend
))
1843 ;; This is a subtree, we take the title from the first heading
1845 (looking-at org-todo-line-regexp
)
1846 (setq title
(match-string 3))
1848 (add-text-properties (point) (1+ (point-at-eol))
1849 (list :org-license-to-kill t
)))
1850 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1853 (defun org-solidify-link-text (s &optional alist
)
1854 "Take link text and make a safe target out of it."
1859 (org-split-string s
"[ \t\r\n]+") "=="))
1860 (a (assoc rtn alist
)))
1863 (defun org-get-min-level (lines &optional offset
)
1864 "Get the minimum level in LINES."
1865 (let ((re "^\\(\\*+\\) ") l
)
1867 (while (setq l
(pop lines
))
1868 (if (string-match re l
)
1869 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1873 ;; Variable holding the vector with section numbers
1874 (defvar org-section-numbers
(make-vector org-level-max
0))
1876 (defun org-init-section-numbers ()
1877 "Initialize the vector for the section numbers."
1879 (numbers (nreverse (org-split-string "" "\\.")))
1880 (depth (1- (length org-section-numbers
)))
1881 (i depth
) number-string
)
1884 (aset org-section-numbers i
0)
1885 (setq number-string
(or (car numbers
) "0"))
1886 (if (string-match "\\`[A-Z]\\'" number-string
)
1887 (aset org-section-numbers i
1888 (- (string-to-char number-string
) ?A -
1))
1889 (aset org-section-numbers i
(string-to-number number-string
)))
1893 (defun org-section-number (&optional level
)
1894 "Return a string with the current section number.
1895 When LEVEL is non-nil, increase section numbers on that level."
1896 (let* ((depth (1- (length org-section-numbers
)))
1898 (fmts (car org-export-section-number-format
))
1899 (term (cdr org-export-section-number-format
))
1904 (aset org-section-numbers
1905 level
(1+ (aref org-section-numbers level
))))
1906 (setq idx
(1+ level
))
1907 (while (<= idx depth
)
1909 (aset org-section-numbers idx
0))
1910 (setq idx
(1+ idx
))))
1912 (while (<= idx depth
)
1913 (when (> (aref org-section-numbers idx
) 0)
1914 (setq fmt
(or (pop fmts
) fmt
)
1916 n
(aref org-section-numbers idx
)
1918 (concat string sep
(org-number-to-counter n ctype
))
1919 (concat string
".0"))
1921 (setq idx
(1+ idx
)))
1923 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1924 (setq string
(replace-match "" t nil string
)))
1925 (if (string-match "\\(\\.0\\)+\\'" string
)
1926 (setq string
(replace-match "" t nil string
))))
1927 (concat string term
)))
1929 (defun org-number-to-counter (n type
)
1930 "Concert number N to a string counter, according to TYPE.
1931 TYPE must be a string, any of:
1935 I upper case roman numeral
1936 i lower case roman numeral"
1938 ((equal type
"1") (number-to-string n
))
1939 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1940 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1941 ((equal type
"I") (org-number-to-roman n
))
1942 ((equal type
"i") (downcase (org-number-to-roman n
)))
1943 (t (error "Invalid counter type `%s'" type
))))
1945 (defun org-number-to-roman (n)
1946 "Convert integer N into a roman numeral."
1947 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1948 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1949 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1953 (number-to-string n
)
1955 (if (>= n
(caar roman
))
1956 (setq n
(- n
(caar roman
))
1957 res
(concat res
(cdar roman
)))
1963 (defun org-export-preprocess-apply-macros ()
1964 "Replace macro references."
1965 (goto-char (point-min))
1967 (while (re-search-forward "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)}}}" nil t
)
1968 (setq key
(downcase (match-string 1)))
1969 (when (setq val
(or (plist-get org-export-opt-plist
1970 (intern (concat ":macro-" key
)))
1971 (plist-get org-export-opt-plist
1972 (intern (concat ":" key
)))))
1974 (replace-match val t t
))))))
1976 (defun org-export-apply-macros-in-string (s)
1977 "Apply the macros in string S."
1981 (org-export-preprocess-apply-macros)
1986 (defun org-export-handle-include-files ()
1987 "Include the contents of include files, with proper formatting."
1988 (let ((case-fold-search t
)
1989 params file markup lang start end prefix prefix1 switches
)
1990 (goto-char (point-min))
1991 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1992 (setq params
(read (concat "(" (match-string 1) ")"))
1993 prefix
(org-get-and-remove-property 'params
:prefix
)
1994 prefix1
(org-get-and-remove-property 'params
:prefix1
)
1995 file
(org-symname-or-string (pop params
))
1996 markup
(org-symname-or-string (pop params
))
1997 lang
(and (member markup
'("src" "SRC"))
1998 (org-symname-or-string (pop params
)))
1999 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2000 (delete-region (match-beginning 0) (match-end 0))
2002 (not (file-exists-p file
))
2003 (not (file-readable-p file
)))
2004 (insert (format "CANNOT INCLUDE FILE %s" file
))
2006 (if (equal (downcase markup
) "src")
2007 (setq start
(format "#+begin_src %s %s\n"
2008 (or lang
"fundamental")
2011 (setq start
(format "#+begin_%s %s\n" markup switches
)
2012 end
(format "#+end_%s" markup
))))
2013 (insert (or start
""))
2014 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2015 (or (bolp) (newline))
2016 (insert (or end
""))))))
2018 (defun org-get-file-contents (file &optional prefix prefix1
)
2019 "Get the contents of FILE and return them as a string.
2020 If PREFIX is a string, prepend it to each line. If PREFIX1
2021 is a string, prepend it to the first line instead of PREFIX."
2023 (insert-file-contents file
)
2024 (when (or prefix prefix1
)
2025 (goto-char (point-min))
2027 (insert (or prefix1 prefix
))
2029 (beginning-of-line 2)))
2032 (defun org-get-and-remove-property (listvar prop
)
2033 "Check if the value of LISTVAR contains PROP as a property.
2034 If yes, return the value of that property (i.e. the element following
2035 in the list) and remove property and value from the list in LISTVAR."
2036 (let ((list (symbol-value listvar
)) m v
)
2037 (when (setq m
(member prop list
))
2039 (if (equal (car list
) prop
)
2040 (set listvar
(cddr list
))
2041 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2043 (set listvar list
)))
2046 (defun org-symname-or-string (s)
2048 (if s
(symbol-name s
) s
)
2051 ;;; Fontification and line numbers for code examples
2053 (defvar org-export-last-code-line-counter-value
0)
2055 (defun org-export-replace-src-segments-and-examples (backend)
2056 "Replace source code segments with special code for export."
2057 (setq org-export-last-code-line-counter-value
0)
2058 (let ((case-fold-search t
)
2059 lang code trans opts
)
2060 (goto-char (point-min))
2061 (while (re-search-forward
2062 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2066 (setq lang
(match-string 2)
2067 opts
(match-string 3)
2068 code
(match-string 4))
2070 opts
(match-string 6)
2071 code
(match-string 7)))
2073 (setq trans
(org-export-format-source-code-or-example
2074 backend lang code opts
))
2075 (replace-match trans t t
))))
2077 (defvar htmlp
) ;; dynamically scoped
2078 (defvar latexp
) ;; dynamically scoped
2080 (defun org-export-format-source-code-or-example (backend
2081 lang code
&optional opts
)
2082 "Format CODE from language LANG and return it formatted for export.
2083 If LANG is nil, do not add any fontification.
2084 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2085 and `+n' for continuing previous numering.
2086 Code formatting according to language currently only works for HTML.
2087 Numbering lines works for all three major backends (html, latex, and ascii)."
2089 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2090 (setq opts
(or opts
"")
2091 num
(string-match "[-+]n\\>" opts
)
2092 cont
(string-match "\\+n\\>" opts
)
2093 rpllbl
(string-match "-r\\>" opts
)
2094 keepp
(string-match "-k\\>" opts
)
2095 textareap
(string-match "-t\\>" opts
)
2096 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2097 (string-to-number (match-string 1 opts
))
2099 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2100 (string-to-number (match-string 1 opts
))
2101 (org-count-lines code
))
2102 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2103 (match-string 1 opts
)))
2104 (when (and textareap
(eq backend
'html
))
2105 ;; we cannot use numbering or highlighting.
2106 (setq num nil cont nil lang nil
))
2107 (if keepp
(setq rpllbl
'keep
))
2109 (when (equal lang
"org")
2110 (setq rtn
(with-temp-buffer
2112 ;; Free up the protected lines
2113 (goto-char (point-min))
2114 (while (re-search-forward "^," nil t
)
2118 ;; Now backend-specific coding
2120 ((eq backend
'docbook
)
2121 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2122 (concat "\n#+BEGIN_DOCBOOK\n"
2123 (org-add-props (concat "<programlisting><![CDATA["
2125 "]]>\n</programlisting>\n")
2129 ;; We are exporting to HTML
2131 (require 'htmlize nil t
)
2132 (when (not (fboundp 'htmlize-region-for-paste
))
2133 ;; we do not have htmlize.el, or an old version of it
2136 "htmlize.el 1.34 or later is needed for source code formatting")))
2139 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2140 (org-inhibit-startup t
)
2141 (org-startup-folded nil
))
2145 (if (functionp mode
)
2148 (font-lock-fontify-buffer)
2149 (set-buffer-modified-p nil
)
2150 (org-export-htmlize-region-for-paste
2151 (point-min) (point-max))))
2152 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2153 (setq rtn
(replace-match
2154 (format "<pre class=\"src src-%s\">\n" lang
)
2158 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2160 rtn
"</textarea>\n</p>\n"))
2163 (goto-char (point-min))
2164 (while (re-search-forward "[<>&]" nil t
)
2165 (replace-match (cdr (assq (char-before)
2166 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2168 (setq rtn
(buffer-string)))
2169 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2171 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2173 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2174 ((eq backend
'latex
)
2175 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2176 (concat "\n#+BEGIN_LaTeX\n"
2177 (org-add-props (concat "\\begin{verbatim}\n" rtn
"\n\\end{verbatim}\n")
2180 ((eq backend
'ascii
)
2181 ;; This is not HTML or LaTeX, so just make it an example.
2182 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2183 (concat "#+BEGIN_ASCII\n"
2187 (lambda (l) (concat " " l
))
2188 (org-split-string rtn
"\n")
2192 "#+END_ASCII\n"))))))
2194 (defun org-export-number-lines (text backend
2195 &optional skip1 skip2 number cont
2196 replace-labels label-format
)
2197 (if (and (not number
) (not (eq replace-labels
'keep
)))
2198 (setq replace-labels nil
)) ;; must use names if no numbers
2199 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2200 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2203 (goto-char (point-max))
2204 (skip-chars-backward " \t\n\r")
2205 (delete-region (point) (point-max))
2206 (beginning-of-line (- 1 skip2
))
2207 (let* ((last (org-current-line))
2208 (n org-export-last-code-line-counter-value
)
2209 (nmax (+ n
(- last skip1
)))
2210 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2213 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2215 ((eq backend
'ascii
) fmt
)
2216 ((eq backend
'latex
) fmt
)
2217 ((eq backend
'docbook
) fmt
)
2219 (label-format (or label-format org-coderef-label-format
))
2220 (label-pre (if (string-match "%s" label-format
)
2221 (substring label-format
0 (match-beginning 0))
2223 (label-post (if (string-match "%s" label-format
)
2224 (substring label-format
(match-end 0))
2228 ".*?\\S-.*?\\([ \t]*\\("
2229 (regexp-quote label-pre
)
2230 "\\([-a-zA-Z0-9_]+\\)"
2231 (regexp-quote label-post
)
2235 (goto-line (1+ skip1
))
2236 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2238 (insert (format fm
(incf n
)))
2240 (when (and (not (eq replace-labels
'keep
))
2241 (looking-at lbl-re
))
2242 (setq ref
(match-string 3))
2245 (delete-region (match-beginning 1) (match-end 1))
2246 (push (cons ref n
) org-export-code-refs
))
2247 (goto-char (match-beginning 2))
2248 (delete-region (match-beginning 2) (match-end 2))
2249 (insert "(" ref
")")
2250 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2251 (when (eq backend
'html
)
2253 (beginning-of-line 1)
2254 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2257 (insert "</span>")))))
2258 (setq org-export-last-code-line-counter-value n
)
2259 (goto-char (point-max))
2263 (defun org-search-todo-below (line lines level
)
2264 "Search the subtree below LINE for any TODO entries."
2265 (let ((rest (cdr (memq line lines
)))
2266 (re org-todo-line-regexp
)
2269 (while (setq line
(pop rest
))
2270 (if (string-match re line
)
2272 (setq lv
(- (match-end 1) (match-beginning 1))
2273 todo
(and (match-beginning 2)
2274 (not (member (match-string 2 line
)
2275 org-done-keywords
))))
2277 (if (<= lv level
) (throw 'exit nil
))
2278 (if todo
(throw 'exit t
))))))))
2281 (defun org-export-visible (type arg
)
2282 "Create a copy of the visible part of the current buffer, and export it.
2283 The copy is created in a temporary buffer and removed after use.
2284 TYPE is the final key (as a string) that also select the export command in
2285 the `C-c C-e' export dispatcher.
2286 As a special case, if the you type SPC at the prompt, the temporary
2287 org-mode file will not be removed but presented to you so that you can
2288 continue to use it. The prefix arg ARG is passed through to the exporting
2292 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2293 (read-char-exclusive))
2294 current-prefix-arg
))
2295 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\
)))
2296 (error "Invalid export key"))
2297 (let* ((binding (cdr (assoc type
2298 '((?a . org-export-as-ascii
)
2299 (?\C-a . org-export-as-ascii
)
2300 (?b . org-export-as-html-and-open
)
2301 (?\C-b . org-export-as-html-and-open
)
2302 (?h . org-export-as-html
)
2303 (?H . org-export-as-html-to-buffer
)
2304 (?R . org-export-region-as-html
)
2305 (?D . org-export-as-docbook
)
2306 (?x . org-export-as-xoxo
)))))
2307 (keepp (equal type ?\
))
2308 (file buffer-file-name
)
2309 (buffer (get-buffer-create "*Org Export Visible*"))
2311 ;; Need to hack the drawers here.
2313 (goto-char (point-min))
2314 (while (re-search-forward org-drawer-regexp nil t
)
2315 (goto-char (match-beginning 1))
2316 (or (org-invisible-p) (org-flag-drawer nil
))))
2317 (with-current-buffer buffer
(erase-buffer))
2319 (setq s
(goto-char (point-min)))
2320 (while (not (= (point) (point-max)))
2321 (goto-char (org-find-invisible))
2322 (append-to-buffer buffer s
(point))
2323 (setq s
(goto-char (org-find-visible))))
2324 (org-cycle-hide-drawers 'all
)
2325 (goto-char (point-min))
2327 ;; Copy all comment lines to the end, to make sure #+ settings are
2328 ;; still available for the second export step. Kind of a hack, but
2329 ;; does do the trick.
2330 (if (looking-at "#[^\r\n]*")
2331 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2332 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2333 (append-to-buffer buffer
(1+ (match-beginning 0))
2334 (min (point-max) (1+ (match-end 0))))))
2336 (let ((buffer-file-name file
)
2337 (org-inhibit-startup t
))
2340 (unless keepp
(funcall binding arg
))))
2342 (kill-buffer buffer
)
2343 (switch-to-buffer-other-window buffer
)
2344 (goto-char (point-min)))))
2346 (defun org-find-visible ()
2348 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2349 (get-char-property s
'invisible
)))
2351 (defun org-find-invisible ()
2353 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2354 (not (get-char-property s
'invisible
))))
2357 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2358 (defun org-get-current-options ()
2359 "Return a string with current options as keyword options.
2360 Does include HTML export options as well as TODO and CATEGORY stuff."
2361 (require 'org-archive
)
2370 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2371 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2373 #+EXPORT_SELECT_TAGS: %s
2374 #+EXPORT_EXCLUDE_TAGS: %s
2380 #+PRIORITIES: %c %c %c
2382 #+STARTUP: %s %s %s %s %s
2388 (buffer-name) (user-full-name) user-mail-address
2389 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2390 org-export-default-language
2391 org-export-headline-levels
2392 org-export-with-section-numbers
2394 org-export-preserve-breaks
2395 org-export-html-expand
2396 org-export-with-fixed-width
2397 org-export-with-tables
2398 org-export-with-sub-superscripts
2399 org-export-with-special-strings
2400 org-export-with-footnotes
2401 org-export-with-emphasize
2402 org-export-with-timestamps
2403 org-export-with-TeX-macros
2404 org-export-with-LaTeX-fragments
2405 org-export-skip-text-before-1st-heading
2406 org-export-with-drawers
2407 org-export-with-todo-keywords
2408 org-export-with-priority
2409 org-export-with-tags
2410 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2411 (mapconcat 'identity org-export-select-tags
" ")
2412 (mapconcat 'identity org-export-exclude-tags
" ")
2413 org-export-html-link-up
2414 org-export-html-link-home
2416 (file-name-sans-extension
2417 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2419 "TODO FEEDBACK VERIFY DONE"
2420 "Me Jason Marie DONE"
2421 org-highest-priority org-lowest-priority org-default-priority
2422 (mapconcat 'identity org-drawers
" ")
2423 (cdr (assoc org-startup-folded
2424 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2425 (if org-odd-levels-only
"odd" "oddeven")
2426 (if org-hide-leading-stars
"hidestars" "showstars")
2427 (if org-startup-align-all-tables
"align" "noalign")
2428 (cond ((eq org-log-done t
) "logdone")
2429 ((equal org-log-done
'note
) "lognotedone")
2430 ((not org-log-done
) "nologdone"))
2431 (or (mapconcat (lambda (x)
2433 ((equal '(:startgroup
) x
) "{")
2434 ((equal '(:endgroup
) x
) "}")
2435 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2437 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2438 (mapconcat 'identity org-file-tags
" ")
2439 org-archive-location
2440 "org file:~/org/%s.org"
2444 (defun org-insert-export-options-template ()
2445 "Insert into the buffer a template with information for exporting."
2447 (if (not (bolp)) (newline))
2448 (let ((s (org-get-current-options)))
2449 (and (string-match "#\\+CATEGORY" s
)
2450 (setq s
(substring s
0 (match-beginning 0))))
2453 (defvar org-table-colgroup-info nil
)
2455 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2456 "Check if the table has a marking column.
2457 If yes remove the column and the special lines."
2458 (setq org-table-colgroup-info nil
)
2461 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2464 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2465 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2469 (setq org-table-clean-did-remove-column nil
)
2474 ((string-match "^[ \t]*| */ *|" x
)
2475 (setq org-table-colgroup-info
2477 (cond ((member x
'("<" "<")) :start
)
2478 ((member x
'(">" ">")) :end
)
2479 ((member x
'("<>" "<>")) :startend
)
2481 (org-split-string x
"[ \t]*|[ \t]*")))
2485 (setq org-table-clean-did-remove-column t
)
2490 ((string-match "^[ \t]*| */ *|" x
)
2491 (setq org-table-colgroup-info
2493 (cond ((member x
'("<" "<")) :start
)
2494 ((member x
'(">" ">")) :end
)
2495 ((member x
'("<>" "<>")) :startend
)
2497 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2499 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2500 nil
) ; ignore this line
2501 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2502 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2503 ;; remove the first column
2504 (replace-match "\\1|" t nil x
))))
2507 (defun org-export-cleanup-toc-line (s)
2508 "Remove tags and timestamps from lines going into the toc."
2509 (when (memq org-export-with-tags
'(not-in-toc nil
))
2510 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2511 (setq s
(replace-match "" t t s
))))
2512 (when org-export-remove-timestamps-from-toc
2513 (while (string-match org-maybe-keyword-time-regexp s
)
2514 (setq s
(replace-match "" t t s
))))
2515 (while (string-match org-bracket-link-regexp s
)
2516 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2520 (defun org-create-multibrace-regexp (left right n
)
2521 "Create a regular expression which will match a balanced sexp.
2522 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2523 as single character strings.
2524 The regexp returned will match the entire expression including the
2525 delimiters. It will also define a single group which contains the
2526 match except for the outermost delimiters. The maximum depth of
2527 stacked delimiters is N. Escaping delimiters is not possible."
2528 (let* ((nothing (concat "[^" left right
"]*?"))
2531 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
2534 re
(concat re or next
)
2535 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
2536 (concat left
"\\(" re
"\\)" right
)))
2538 (defvar org-match-substring-regexp
2540 "\\([^\\]\\)\\([_^]\\)\\("
2541 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2543 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
2545 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2546 "The regular expression matching a sub- or superscript.")
2548 (defvar org-match-substring-with-braces-regexp
2550 "\\([^\\]\\)\\([_^]\\)\\("
2551 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2553 "The regular expression matching a sub- or superscript, forcing braces.")
2556 (defun org-get-text-property-any (pos prop
&optional object
)
2557 (or (get-text-property pos prop object
)
2558 (and (setq pos
(next-single-property-change pos prop object
))
2559 (get-text-property pos prop object
))))
2561 (defun org-export-get-coderef-format (path desc
)
2563 (if (and desc
(string-match
2564 (regexp-quote (concat "(" path
")"))
2566 (replace-match "%s" t t desc
)
2571 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2573 ;;; org-exp.el ends here