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-after-blockquote-hook nil
348 "Hook for preprocessing an export buffer.
349 This is run after blockquote/quote/verse/center have been marked
352 (defvar org-export-preprocess-before-backend-specifics-hook nil
353 "Hook run before backend-specific functions are called during preprocessing.")
355 (defvar org-export-preprocess-final-hook nil
356 "Hook for preprocessing an export buffer.
357 This is run as the last thing in the preprocessing buffer, just before
358 returning the buffer string to the backend.")
360 (defgroup org-export-translation nil
361 "Options for translating special ascii sequences for the export backends."
362 :tag
"Org Export Translation"
365 (defcustom org-export-with-emphasize t
366 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
367 If the export target supports emphasizing text, the word will be
368 typeset in bold, italic, or underlined, respectively. Works only for
369 single words, but you can say: I *really* *mean* *this*.
370 Not all export backends support this.
372 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
373 :group
'org-export-translation
376 (defcustom org-export-with-footnotes t
377 "If nil, export [1] as a footnote marker.
378 Lines starting with [1] will be formatted as footnotes.
380 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
381 :group
'org-export-translation
384 (defcustom org-export-with-sub-superscripts t
385 "Non-nil means, interpret \"_\" and \"^\" for export.
386 When this option is turned on, you can use TeX-like syntax for sub- and
387 superscripts. Several characters after \"_\" or \"^\" will be
388 considered as a single item - so grouping with {} is normally not
389 needed. For example, the following things will be parsed as single
390 sub- or superscripts.
392 10^24 or 10^tau several digits will be considered 1 item.
393 10^-12 or 10^-tau a leading sign with digits or a word
394 x^2-y^3 will be read as x^2 - y^3, because items are
395 terminated by almost any nonword/nondigit char.
396 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
398 Still, ambiguity is possible - so when in doubt use {} to enclose the
399 sub/superscript. If you set this variable to the symbol `{}',
400 the braces are *required* in order to trigger interpretations as
401 sub/superscript. This can be helpful in documents that need \"_\"
402 frequently in plain text.
404 Not all export backends support this, but HTML does.
406 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
407 :group
'org-export-translation
409 (const :tag
"Always interpret" t
)
410 (const :tag
"Only with braces" {})
411 (const :tag
"Never interpret" nil
)))
413 (defcustom org-export-with-TeX-macros t
414 "Non-nil means, interpret simple TeX-like macros when exporting.
415 For example, HTML export converts \\alpha to α and \\AA to Å.
416 Not only real TeX macros will work here, but the standard HTML entities
417 for math can be used as macro names as well. For a list of supported
418 names in HTML export, see the constant `org-html-entities'.
419 Not all export backends support this.
421 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
422 :group
'org-export-translation
423 :group
'org-export-latex
426 (defcustom org-export-with-LaTeX-fragments nil
427 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
428 When set, the exporter will find LaTeX environments if the \\begin line is
429 the first non-white thing on a line. It will also find the math delimiters
430 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
433 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
435 The default is nil, because this option needs the `dvipng' program which
436 is not available on all systems."
437 :group
'org-export-translation
438 :group
'org-export-latex
441 (defcustom org-export-with-fixed-width t
442 "Non-nil means, lines starting with \":\" will be in fixed width font.
443 This can be used to have pre-formatted text, fragments of code etc. For
445 : ;; Some Lisp examples
448 will be looking just like this in also HTML. See also the QUOTE keyword.
449 Not all export backends support this.
451 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
452 :group
'org-export-translation
455 (defcustom org-match-sexp-depth
3
456 "Number of stacked braces for sub/superscript matching.
457 This has to be set before loading org.el to be effective."
458 :group
'org-export-translation
461 (defgroup org-export-tables nil
462 "Options for exporting tables in Org-mode."
463 :tag
"Org Export Tables"
466 (defcustom org-export-with-tables t
467 "If non-nil, lines starting with \"|\" define a table.
470 | Name | Address | Birthday |
471 |-------------+----------+-----------|
472 | Arthur Dent | England | 29.2.2100 |
474 Not all export backends support this.
476 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
477 :group
'org-export-tables
480 (defcustom org-export-highlight-first-table-line t
481 "Non-nil means, highlight the first table line.
482 In HTML export, this means use <th> instead of <td>.
483 In tables created with table.el, this applies to the first table line.
484 In Org-mode tables, all lines before the first horizontal separator
485 line will be formatted with <th> tags."
486 :group
'org-export-tables
489 (defcustom org-export-table-remove-special-lines t
490 "Remove special lines and marking characters in calculating tables.
491 This removes the special marking character column from tables that are set
492 up for spreadsheet calculations. It also removes the entire lines
493 marked with `!', `_', or `^'. The lines with `$' are kept, because
494 the values of constants may be useful to have."
495 :group
'org-export-tables
498 (defcustom org-export-prefer-native-exporter-for-tables nil
499 "Non-nil means, always export tables created with table.el natively.
500 Natively means, use the HTML code generator in table.el.
501 When nil, Org-mode's own HTML generator is used when possible (i.e. if
502 the table does not use row- or column-spanning). This has the
503 advantage, that the automatic HTML conversions for math symbols and
504 sub/superscripts can be applied. Org-mode's HTML generator is also
506 :group
'org-export-tables
510 (defgroup org-export-xml nil
511 "Options specific for XML export of Org-mode files."
512 :tag
"Org Export XML"
517 ;;; Variables, constants, and parameter plists
519 (defconst org-level-max
20)
521 (defvar org-current-export-file nil
) ; dynamically scoped parameter
522 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
523 (defvar org-export-opt-plist nil
524 "Contains the current option plist.")
525 (defvar org-last-level nil
) ; dynamically scoped variable
526 (defvar org-min-level nil
) ; dynamically scoped variable
527 (defvar org-levels-open nil
) ; dynamically scoped parameter
529 (defconst org-export-plist-vars
530 '((:link-up nil org-export-html-link-up
)
531 (:link-home nil org-export-html-link-home
)
532 (:language nil org-export-default-language
)
533 (:keywords nil org-export-page-keywords
)
534 (:description nil org-export-page-description
)
535 (:customtime nil org-display-custom-times
)
536 (:headline-levels
"H" org-export-headline-levels
)
537 (:section-numbers
"num" org-export-with-section-numbers
)
538 (:section-number-format nil org-export-section-number-format
)
539 (:table-of-contents
"toc" org-export-with-toc
)
540 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
541 (:archived-trees nil org-export-with-archived-trees
)
542 (:emphasize
"*" org-export-with-emphasize
)
543 (:sub-superscript
"^" org-export-with-sub-superscripts
)
544 (:special-strings
"-" org-export-with-special-strings
)
545 (:footnotes
"f" org-export-with-footnotes
)
546 (:drawers
"d" org-export-with-drawers
)
547 (:tags
"tags" org-export-with-tags
)
548 (:todo-keywords
"todo" org-export-with-todo-keywords
)
549 (:priority
"pri" org-export-with-priority
)
550 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
551 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
552 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
553 (:fixed-width
":" org-export-with-fixed-width
)
554 (:timestamps
"<" org-export-with-timestamps
)
555 (:author-info
"author" org-export-author-info
)
556 (:creator-info
"creator" org-export-creator-info
)
557 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
558 (:tables
"|" org-export-with-tables
)
559 (:table-auto-headline nil org-export-highlight-first-table-line
)
560 (:style-include-default nil org-export-html-style-include-default
)
561 (:style-include-scripts nil org-export-html-style-include-scripts
)
562 (:style nil org-export-html-style
)
563 (:style-extra nil org-export-html-style-extra
)
564 (:agenda-style nil org-agenda-export-html-style
)
565 (:convert-org-links nil org-export-html-link-org-files-as-html
)
566 (:inline-images nil org-export-html-inline-images
)
567 (:html-extension nil org-export-html-extension
)
568 (:html-table-tag nil org-export-html-table-tag
)
569 (:expand-quoted-html
"@" org-export-html-expand
)
570 (:timestamp nil org-export-html-with-timestamp
)
571 (:publishing-directory nil org-export-publishing-directory
)
572 (:preamble nil org-export-html-preamble
)
573 (:postamble nil org-export-html-postamble
)
574 (:auto-preamble nil org-export-html-auto-preamble
)
575 (:auto-postamble nil org-export-html-auto-postamble
)
576 (:author nil user-full-name
)
577 (:email nil user-mail-address
)
578 (:select-tags nil org-export-select-tags
)
579 (:exclude-tags nil org-export-exclude-tags
))
580 "List of properties that represent export/publishing variables.
581 Each element is a list of 3 items:
582 1. The property that is used internally, and also for org-publish-project-alist
583 2. The string that can be used in the OPTION lines to set this option,
584 or nil if this option cannot be changed in this way
585 3. The customization variable that sets the default for this option."
588 (defun org-default-export-plist ()
589 "Return the property list with default settings for the export variables."
590 (let ((l org-export-plist-vars
) rtn e s v
)
591 (while (setq e
(pop l
))
593 v
(if (boundp s
) (symbol-value s
) nil
)
594 rtn
(cons (car e
) (cons v rtn
))))
597 (defvar org-export-inbuffer-options-extra nil
598 "List of additional in-buffer options that should be detected.
599 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
600 etc. Extensions can add to this list to get their options detected, and they
601 can then add a function to `org-export-options-filters' to process these
603 Each element in this list must be a list, with the in-buffer keyword as car,
604 and a property (a symbol) as the next element. All occurrences of the
605 keyword will be found, the values concatenated with a space character
606 in between, and the result stored in the export options property list.")
608 (defvar org-export-options-filters nil
609 "Functions to be called to finalize the export/publishing options.
610 All these options are stored in a property list, and each of the functions
611 in this hook gets a chance to modify this property list. Each function
612 must accept the property list as an argument, and must return the (possibly
615 ;; FIXME: should we fold case here?
616 (defun org-infile-export-plist ()
617 "Return the property list with file-local settings for export."
621 (goto-char (point-min))
622 (let ((re (org-make-options-regexp
624 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
625 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
626 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
627 "KEYWORDS" "DESCRIPTION")
628 (mapcar 'car org-export-inbuffer-options-extra
))))
629 p key val text options a pr style
631 ext-setup-or-nil setup-contents
(start 0))
632 (while (or (and ext-setup-or-nil
633 (string-match re ext-setup-or-nil start
)
634 (setq start
(match-end 0)))
635 (and (setq ext-setup-or-nil nil start
0)
636 (re-search-forward re nil t
)))
637 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
638 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
640 ((setq a
(assoc key org-export-inbuffer-options-extra
))
642 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
643 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
644 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
645 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
646 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
647 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
648 ((string-equal key
"DESCRIPTION")
649 (setq p
(plist-put p
:description val
)))
650 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
651 ((string-equal key
"STYLE")
652 (setq style
(concat style
"\n" val
)))
653 ((string-equal key
"LATEX_HEADER")
654 (setq latex-header
(concat latex-header
"\n" val
)))
655 ((string-equal key
"TEXT")
656 (setq text
(if text
(concat text
"\n" val
) val
)))
657 ((string-equal key
"OPTIONS")
658 (setq options
(concat val
" " options
)))
659 ((string-equal key
"LINK_UP")
660 (setq p
(plist-put p
:link-up val
)))
661 ((string-equal key
"LINK_HOME")
662 (setq p
(plist-put p
:link-home val
)))
663 ((string-equal key
"EXPORT_SELECT_TAGS")
664 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
665 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
666 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
667 ((equal key
"SETUPFILE")
668 (setq setup-contents
(org-file-contents
670 (org-remove-double-quotes
673 (if (not ext-setup-or-nil
)
674 (setq ext-setup-or-nil setup-contents start
0)
675 (setq ext-setup-or-nil
676 (concat (substring ext-setup-or-nil
0 start
)
677 "\n" setup-contents
"\n"
678 (substring ext-setup-or-nil start
)))))))
679 (setq p
(plist-put p
:text text
))
680 (when style
(setq p
(plist-put p
:style-extra style
)))
682 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
684 (setq p
(org-export-add-options-to-plist p options
)))
685 ;; Add macro definitions
686 (goto-char (point-min))
687 (while (re-search-forward
688 "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
690 (setq p
(plist-put p
(intern (concat ":macro-"
691 (downcase (match-string 1))))
695 (defun org-export-add-options-to-plist (p options
)
696 "Parse an OPTIONS line and set values in the property list P."
699 (let ((op org-export-plist-vars
))
700 (while (setq o
(pop op
))
702 (string-match (concat (regexp-quote (nth 1 o
))
703 ":\\([^ \t\n\r;,.]*\\)")
705 (setq p
(plist-put p
(car o
)
706 (car (read-from-string
707 (match-string 1 options
))))))))))
710 (defun org-export-add-subtree-options (p pos
)
711 "Add options in subtree at position POS to property list P."
714 (when (org-at-heading-p)
716 ;; This is actually read in `org-export-get-title-from-subtree'
717 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
718 ;; (setq p (plist-put p :title a)))
719 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
720 (setq p
(plist-put p
:text a
)))
721 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
722 (setq p
(plist-put p
:author a
)))
723 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
724 (setq p
(plist-put p
:date a
)))
725 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
726 (setq p
(org-export-add-options-to-plist p a
)))))
729 (defun org-export-directory (type plist
)
730 (let* ((val (plist-get plist
:publishing-directory
))
732 (or (cdr (assoc type val
)) ".")
736 (defun org-export-process-option-filters (plist)
737 (let ((functions org-export-options-filters
) f
)
738 (while (setq f
(pop functions
))
739 (setq plist
(funcall f plist
))))
743 (defun org-export (&optional arg
)
744 "Export dispatcher for Org-mode.
745 When `org-export-run-in-background' is non-nil, try to run the command
746 in the background. This will be done only for commands that write
747 to a file. For details see the docstring of `org-export-run-in-background'.
749 The prefix argument ARG will be passed to the exporter. However, if
750 ARG is a double universal prefix `C-u C-u', that means to inverse the
751 value of `org-export-run-in-background'."
753 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
754 (help "[t] insert the export option template
755 \[v] limit export to visible part of outline tree
759 \[h] export as HTML [H] to temporary buffer [R] export region
760 \[b] export as HTML and open in browser
762 \[l] export as LaTeX [L] to temporary buffer
763 \[p] export as LaTeX and process to PDF
764 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
766 \[D] export as DocBook
767 \[V] export as DocBook, process to PDF, and open the resulting PDF document
771 \[i] export current file as iCalendar file
772 \[I] export all agenda files as iCalendar files
773 \[c] export agenda files into combined iCalendar file
775 \[F] publish current file [P] publish current project
776 \[X] publish a project... [A] publish all projects")
778 '((?t org-insert-export-options-template nil
)
779 (?v org-export-visible nil
)
780 (?a org-export-as-ascii t
)
781 (?h org-export-as-html t
)
782 (?b org-export-as-html-and-open t
)
783 (?H org-export-as-html-to-buffer nil
)
784 (?R org-export-region-as-html nil
)
785 (?x org-export-as-xoxo t
)
786 (?D org-export-as-docbook t
)
787 (?V org-export-as-docbook-pdf-and-open t
)
788 (?l org-export-as-latex t
)
789 (?p org-export-as-pdf t
)
790 (?d org-export-as-pdf-and-open t
)
791 (?L org-export-as-latex-to-buffer nil
)
792 (?i org-export-icalendar-this-file t
)
793 (?I org-export-icalendar-all-agenda-files t
)
794 (?c org-export-icalendar-combine-agenda-files t
)
795 (?F org-publish-current-file t
)
796 (?P org-publish-current-project t
)
798 (?A org-publish-all t
)))
801 (save-window-excursion
802 (delete-other-windows)
803 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
805 (org-fit-window-to-buffer (get-buffer-window
806 "*Org Export/Publishing Help*"))
807 (message "Select command: ")
808 (setq r1
(read-char-exclusive))))
809 (setq r2
(if (< r1
27) (+ r1
96) r1
))
810 (unless (setq ass
(assq r2 cmds
))
811 (error "No command associated with key %c" r1
))
812 (if (and bg
(nth 2 ass
)
813 (not (buffer-base-buffer))
814 (not (org-region-active-p)))
815 ;; execute in background
816 (let ((p (start-process
817 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
819 (expand-file-name invocation-name invocation-directory
)
822 "--eval" "(require 'org-exp)"
823 "--eval" "(setq org-wait .2)"
825 "-f" (symbol-name (nth 1 ass
)))))
826 (set-process-sentinel p
'org-export-process-sentinel
)
827 (message "Background process \"%s\": started" p
))
828 ;; background processing not requested, or not possible
829 (call-interactively (nth 1 ass
)))))
831 (defun org-export-process-sentinel (process status
)
832 (if (string-match "\n+\\'" status
)
833 (setq status
(substring status
0 -
1)))
834 (message "Background process \"%s\": %s" process status
))
836 (defconst org-html-entities
878 ("Aring") ("AA".
"Å")
967 ("varepsilon".
"ε")
980 ("sigmaf") ("varsigma".
"ς")
988 ("thetasym") ("vartheta".
"ϑ")
991 ("bull") ("bullet".
"•")
992 ("hellip") ("dots".
"…")
1002 ("larr") ("leftarrow".
"←") ("gets".
"←")
1003 ("uarr") ("uparrow".
"↑")
1004 ("rarr") ("to".
"→") ("rightarrow".
"→")
1005 ("darr")("downarrow".
"↓")
1006 ("harr") ("leftrightarrow".
"↔")
1007 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1008 ("lArr") ("Leftarrow".
"⇐")
1009 ("uArr") ("Uparrow".
"⇑")
1010 ("rArr") ("Rightarrow".
"⇒")
1011 ("dArr") ("Downarrow".
"⇓")
1012 ("hArr") ("Leftrightarrow".
"⇔")
1014 ("part") ("partial".
"∂")
1015 ("exist") ("exists".
"∃")
1016 ("empty") ("emptyset".
"∅")
1018 ("isin") ("in".
"∈")
1024 ("lowast") ("ast".
"∗")
1026 ("prop") ("proptp".
"∝")
1027 ("infin") ("infty".
"∞")
1028 ("ang") ("angle".
"∠")
1029 ("and") ("wedge".
"∧")
1030 ("or") ("vee".
"∨")
1036 ("cong") ("simeq".
"≅")
1037 ("asymp")("approx".
"≈")
1038 ("ne") ("neq".
"≠")
1042 ("sub") ("subset".
"⊂")
1043 ("sup") ("supset".
"⊃")
1050 ("sdot") ("cdot".
"⋅")
1057 ("loz") ("Diamond".
"◊")
1058 ("spades") ("spadesuit".
"♠")
1059 ("clubs") ("clubsuit".
"♣")
1060 ("hearts") ("diamondsuit".
"♥")
1061 ("diams") ("diamondsuit".
"♦")
1062 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1129 "Entities for TeX->HTML translation.
1130 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1131 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1132 In that case, \"\\ent\" will be translated to \"&other;\".
1133 The list contains HTML entities for Latin-1, Greek and other symbols.
1134 It is supplemented by a number of commonly used TeX macros with appropriate
1135 translations. There is currently no way for users to extend this.")
1137 ;;; General functions for all backends
1139 (defvar org-export-target-aliases nil
1140 "Alist of targets with invisible aliases.")
1141 (defvar org-export-preferred-target-alist nil
1142 "Alist of section id's with preferred aliases.")
1143 (defvar org-export-code-refs nil
1144 "Alist of code references and line numbers")
1146 (defun org-export-preprocess-string (string &rest parameters
)
1147 "Cleanup STRING so that that the true exported has a more consistent source.
1148 This function takes STRING, which should be a buffer-string of an org-file
1149 to export. It then creates a temporary buffer where it does its job.
1150 The result is then again returned as a string, and the exporter works
1151 on this string to produce the exported version."
1153 (let* ((htmlp (plist-get parameters
:for-html
))
1154 (asciip (plist-get parameters
:for-ascii
))
1155 (latexp (plist-get parameters
:for-LaTeX
))
1156 (docbookp (plist-get parameters
:for-docbook
))
1157 (backend (cond (htmlp 'html
)
1160 (docbookp 'docbook
)))
1161 (archived-trees (plist-get parameters
:archived-trees
))
1162 (inhibit-read-only t
)
1163 (drawers org-drawers
)
1164 (outline-regexp "\\*+ ")
1167 (setq org-export-target-aliases nil
)
1168 (setq org-export-preferred-target-alist nil
)
1169 (setq org-export-code-refs nil
)
1171 (with-current-buffer (get-buffer-create " org-mode-tmp")
1174 (setq case-fold-search t
)
1176 ;; Remove license-to-kill stuff
1177 ;; The caller marks some stuff for killing, stuff that has been
1178 ;; used to create the page title, for example.
1179 (org-export-kill-licensed-text)
1181 (let ((org-inhibit-startup t
)) (org-mode))
1182 (setq case-fold-search t
)
1185 (run-hooks 'org-export-preprocess-hook
)
1187 ;; Process the macros
1188 (org-export-preprocess-apply-macros)
1189 (run-hooks 'org-export-preprocess-after-macros-hook
)
1191 (untabify (point-min) (point-max))
1193 ;; Handle include files, and call a hook
1194 (org-export-handle-include-files)
1195 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1197 ;; Get rid of archived trees
1198 (org-export-remove-archived-trees archived-trees
)
1200 ;; Remove comment environment and comment subtrees
1201 (org-export-remove-comment-blocks-and-subtrees)
1203 ;; Get rid of excluded trees, and call a hook
1204 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1205 (plist-get parameters
:exclude-tags
))
1206 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1208 ;; Handle source code snippets
1209 (org-export-replace-src-segments-and-examples backend
)
1211 ;; Protect short examples marked by a leading colon
1212 (org-export-protect-colon-examples)
1214 ;; Normalize footnotes
1215 (when (plist-get parameters
:footnotes
)
1216 (org-footnote-normalize nil t
))
1218 ;; Find all headings and compute the targets for them
1219 (setq target-alist
(org-export-define-heading-targets target-alist
))
1221 ;; Get rid of drawers
1222 (org-export-remove-or-extract-drawers drawers
1223 (plist-get parameters
:drawers
))
1225 ;; Get the correct stuff before the first headline
1226 (when (plist-get parameters
:skip-before-1st-heading
)
1227 (goto-char (point-min))
1228 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1229 (delete-region (point-min) (match-beginning 0))
1230 (goto-char (point-min))
1232 (when (plist-get parameters
:add-text
)
1233 (goto-char (point-min))
1234 (insert (plist-get parameters
:add-text
) "\n"))
1236 ;; Remove todo-keywords before exporting, if the user has requested so
1237 (org-export-remove-headline-metadata parameters
)
1239 ;; Find targets in comments and move them out of comments,
1240 ;; but mark them as targets that should be invisible
1241 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1243 ;; Select and protect backend specific stuff, throw away stuff
1244 ;; that is specific for other backends
1245 (org-export-select-backend-specific-text backend
)
1247 ;; Protect quoted subtrees
1248 (org-export-protect-quoted-subtrees)
1250 ;; Remove clock lines
1251 (org-export-remove-clock-lines)
1253 ;; Protect verbatim elements
1254 (org-export-protect-verbatim)
1256 ;; Blockquotes, verse, and center
1257 (org-export-mark-blockquote-verse-center)
1258 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1260 ;; Remove timestamps, if the user has requested so
1261 (unless (plist-get parameters
:timestamps
)
1262 (org-export-remove-timestamps))
1264 ;; Attach captions to the correct object
1265 (setq target-alist
(org-export-attach-captions-and-attributes
1266 backend target-alist
))
1268 ;; Find matches for radio targets and turn them into internal links
1269 (org-export-mark-radio-links)
1271 ;; Find all links that contain a newline and put them into a single line
1272 (org-export-concatenate-multiline-links)
1274 ;; Normalize links: Convert angle and plain links into bracket links
1275 ;; and expand link abbreviations
1276 (org-export-normalize-links)
1278 ;; Find all internal links. If they have a fuzzy match (i.e. not
1279 ;; a *dedicated* target match, let the link point to the
1280 ;; corresponding section.
1281 (org-export-target-internal-links target-alist
)
1283 ;; Find multiline emphasis and put them into single line
1284 (when (plist-get parameters
:emph-multiline
)
1285 (org-export-concatenate-multiline-emphasis))
1287 ;; Remove special table lines
1288 (when org-export-table-remove-special-lines
1289 (org-export-remove-special-table-lines))
1292 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1294 ;; LaTeX-specific preprocessing
1296 (require 'org-latex nil
)
1297 (org-export-latex-preprocess parameters
))
1299 ;; ASCII-specific preprocessing
1301 (org-export-ascii-preprocess parameters
))
1303 ;; HTML-specific preprocessing
1305 (org-export-html-preprocess parameters
))
1307 ;; DocBook-specific preprocessing
1309 (require 'org-docbook nil
)
1310 (org-export-docbook-preprocess parameters
))
1312 ;; Remove or replace comments
1313 (org-export-handle-comments (plist-get parameters
:comments
))
1315 ;; Run the final hook
1316 (run-hooks 'org-export-preprocess-final-hook
)
1318 (setq rtn
(buffer-string)))
1319 (kill-buffer " org-mode-tmp")
1322 (defun org-export-kill-licensed-text ()
1323 "Remove all text that is marked with a :org-license-to-kill property."
1325 (while (setq p
(text-property-any (point-min) (point-max)
1326 :org-license-to-kill t
))
1328 p
(or (next-single-property-change p
:org-license-to-kill
)
1331 (defun org-export-define-heading-targets (target-alist)
1332 "Find all headings and define the targets for them.
1333 The new targets are added to TARGET-ALIST, which is also returned."
1334 (goto-char (point-min))
1335 (org-init-section-numbers)
1336 (let ((re (concat "^" org-outline-regexp
1337 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1338 level target last-section-target a id
)
1339 (while (re-search-forward re nil t
)
1342 (setq id
(org-match-string-no-properties 2))
1343 (push (cons id target
) target-alist
)
1344 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1346 (push (list last-section-target
)
1347 org-export-target-aliases
)
1348 (car org-export-target-aliases
))))
1349 (push (caar target-alist
) (cdr a
))
1350 (when (equal (match-string 1) "CUSTOM_ID")
1351 (if (not (assoc last-section-target
1352 org-export-preferred-target-alist
))
1353 (push (cons last-section-target id
)
1354 org-export-preferred-target-alist
))))
1355 (setq level
(org-reduced-level
1356 (save-excursion (goto-char (point-at-bol))
1357 (org-outline-level))))
1358 (setq target
(org-solidify-link-text
1359 (format "sec-%s" (org-section-number level
))))
1360 (setq last-section-target target
)
1361 (push (cons target target
) target-alist
)
1362 (add-text-properties
1363 (point-at-bol) (point-at-eol)
1364 (list 'target target
)))))
1367 (defun org-export-handle-invisible-targets (target-alist)
1368 "Find targets in comments and move them out of comments.
1369 Mark them as invisible targets."
1371 (goto-char (point-min))
1372 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1373 ;; Check if the line before or after is a headline with a target
1374 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1375 (get-text-property (point-at-bol 2) 'target
)))
1377 ;; use the existing target in a neighboring line
1378 (setq tmp
(match-string 2))
1380 (and (looking-at "\n") (delete-char 1))
1381 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1383 (setq a
(or (assoc target org-export-target-aliases
)
1385 (push (list target
) org-export-target-aliases
)
1386 (car org-export-target-aliases
))))
1388 ;; Make an invisible target
1389 (replace-match "\\1(INVISIBLE)"))))
1392 (defun org-export-target-internal-links (target-alist)
1393 "Find all internal links and assign targets to them.
1394 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1395 let the link point to the corresponding section.
1396 This function also handles the id links, if they have a match in
1398 (goto-char (point-min))
1399 (while (re-search-forward org-bracket-link-regexp nil t
)
1401 (let* ((md (match-data))
1402 (desc (match-end 2))
1403 (link (org-link-unescape (match-string 1)))
1404 (slink (org-solidify-link-text link
))
1405 found props pos cref
1408 ((= (string-to-char link
) ?
#)
1409 ;; user wants exactly this link
1411 ((cdr (assoc slink target-alist
))
1412 (or (cdr (assoc (assoc slink target-alist
)
1413 org-export-preferred-target-alist
))
1414 (cdr (assoc slink target-alist
))))
1415 ((and (string-match "^id:" link
)
1416 (cdr (assoc (substring link
3) target-alist
))))
1417 ((string-match "^(\\(.*\\))$" link
)
1418 (setq cref
(match-string 1 link
))
1419 (concat "coderef:" cref
))
1420 ((string-match org-link-types-re link
) nil
)
1421 ((or (file-name-absolute-p link
)
1422 (string-match "^\\." link
))
1426 (setq found
(condition-case nil
(org-link-search link
)
1429 (or (org-on-heading-p)
1430 (not (eq found
'dedicated
))))
1431 (or (get-text-property (point) 'target
)
1434 (1- (or (previous-single-property-change
1435 (point) 'target
) 0)))
1439 (goto-char (match-beginning 1))
1440 (setq props
(text-properties-at (point)))
1441 (delete-region (match-beginning 1) (match-end 1))
1444 (unless desc
(insert "][" link
))
1445 (add-text-properties pos
(point) props
))))))
1447 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1448 "Remove drawers, or extract the content.
1449 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1450 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1451 whose content to keep."
1452 (unless (eq t exp-drawers
)
1453 (goto-char (point-min))
1454 (let ((re (concat "^[ \t]*:\\("
1457 (org-delete-all exp-drawers
1458 (copy-sequence all-drawers
))
1462 (while (re-search-forward re nil t
)
1464 (setq beg
(match-beginning 0)
1466 (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
1469 ;; terminated in this entry
1471 (delete-region beg
(match-end 1))
1473 (goto-char eol
))))))))
1475 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1476 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1477 Both arguments are lists of tags.
1478 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1480 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1482 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1483 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1486 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1490 (goto-char (point-min))
1491 (when (and select-tags
1493 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1494 ;; At least one tree is marked for export, this means
1495 ;; all the unmarked stuff needs to go.
1496 ;; Dig out the trees that should be exported
1497 (goto-char (point-min))
1498 (outline-next-heading)
1500 (put-text-property beg
(point-max) :org-delete t
)
1501 (while (re-search-forward re-sel nil t
)
1502 (when (org-on-heading-p)
1503 (org-back-to-heading)
1504 (remove-text-properties
1505 (max (1- (point)) (point-min))
1506 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1508 (while (and (org-up-heading-safe)
1509 (get-text-property (point) :org-delete
))
1510 (remove-text-properties (max (1- (point)) (point-min))
1511 (point-at-eol) '(:org-delete t
)))
1513 ;; Remove the trees explicitly marked for noexport
1515 (goto-char (point-min))
1516 (while (re-search-forward re-excl nil t
)
1517 (when (org-at-heading-p)
1518 (org-back-to-heading t
)
1520 (org-end-of-subtree t
)
1521 (delete-region beg
(point)))))
1522 ;; Remove everything that is now still marked for deletion
1523 (goto-char (point-min))
1524 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1525 (setq end
(or (next-single-property-change beg
:org-delete
)
1527 (delete-region beg end
))))
1529 (defun org-export-remove-archived-trees (export-archived-trees)
1530 "Remove archived trees.
1531 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1532 When it is t, the entire archived tree will be exported.
1533 When it is nil the entire tree including the headline will be removed
1535 (let ((re-archive (concat ":" org-archive-tag
":"))
1537 (when (not (eq export-archived-trees t
))
1538 (goto-char (point-min))
1539 (while (re-search-forward re-archive nil t
)
1540 (if (not (org-on-heading-p t
))
1541 (org-end-of-subtree t
)
1542 (beginning-of-line 1)
1543 (setq a
(if export-archived-trees
1544 (1+ (point-at-eol)) (point))
1545 b
(org-end-of-subtree t
))
1546 (if (> b a
) (delete-region a b
)))))))
1548 (defun org-export-remove-headline-metadata (opts)
1549 "Remove meta data from the headline, according to user options."
1550 (let ((re org-complex-heading-regexp
)
1551 (todo (plist-get opts
:todo-keywords
))
1552 (tags (plist-get opts
:tags
))
1553 (pri (plist-get opts
:priority
))
1556 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1557 (when (or (not todo
) (not tags
) (not pri
))
1558 (goto-char (point-min))
1559 (while (re-search-forward re nil t
)
1561 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1563 (replace-match rpl t t
))))))
1565 (defun org-export-remove-timestamps ()
1566 "Remove timestamps and keywords for export."
1567 (goto-char (point-min))
1568 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1571 (unless (save-match-data (org-at-table-p))
1573 (beginning-of-line 1)
1574 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1575 (replace-match ""))))))
1577 (defun org-export-remove-clock-lines ()
1578 "Remove clock lines for export."
1579 (goto-char (point-min))
1580 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1581 (while (re-search-forward re nil t
)
1583 (replace-match "")))))
1585 (defun org-export-protect-quoted-subtrees ()
1586 "Mark quoted subtrees with the protection property."
1587 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1588 (goto-char (point-min))
1589 (while (re-search-forward re-quote nil t
)
1590 (goto-char (match-beginning 0))
1592 (add-text-properties (point) (org-end-of-subtree t
)
1593 '(org-protected t
)))))
1595 (defun org-export-protect-verbatim ()
1596 "Mark verbatim snippets with the protection property."
1597 (goto-char (point-min))
1598 (while (re-search-forward org-verbatim-re nil t
)
1599 (add-text-properties (match-beginning 4) (match-end 4)
1601 (goto-char (1+ (match-end 4)))))
1603 (defun org-export-protect-colon-examples ()
1604 "Protect lines starting with a colon."
1605 (goto-char (point-min))
1606 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1607 (while (re-search-forward re nil t
)
1608 (beginning-of-line 1)
1610 (while (looking-at re
)
1612 (or (eobp) (forward-char 1)))
1613 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1614 '(org-protected t
)))))
1616 (defun org-export-select-backend-specific-text (backend)
1618 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1619 (html "HTML" "BEGIN_HTML" "END_HTML")
1620 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1621 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1622 (case-fold-search t
)
1626 (setq fmt
(pop formatters
))
1627 (when (eq (car fmt
) backend
)
1628 ;; This is selected code, put it into the file for real
1629 (goto-char (point-min))
1630 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1631 ":[ \t]*\\(.*\\)") nil t
)
1632 (replace-match "\\1" t
)
1633 (add-text-properties
1634 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1635 '(org-protected t
))))
1636 (goto-char (point-min))
1637 (while (re-search-forward
1639 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1640 (cadddr fmt
) "\\>.*\n?") nil t
)
1641 (if (eq (car fmt
) backend
)
1643 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1645 ;; No, this is for a different backend, kill it
1646 (delete-region (match-beginning 0) (match-end 0)))))))
1648 (defun org-export-mark-blockquote-verse-center ()
1649 "Mark block quote and verse environments with special cookies.
1650 These special cookies will later be interpreted by the backend."
1652 (goto-char (point-min))
1653 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1655 (replace-match (if (equal (downcase (match-string 1)) "end")
1656 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1659 (goto-char (point-min))
1660 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1661 (replace-match (if (equal (downcase (match-string 1)) "end")
1662 "ORG-VERSE-END" "ORG-VERSE-START")
1665 (goto-char (point-min))
1666 (while (re-search-forward "^#\\+\\(begin\\|end\\)_center\\>.*" nil t
)
1667 (replace-match (if (equal (downcase (match-string 1)) "end")
1668 "ORG-CENTER-END" "ORG-CENTER-START")
1671 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1672 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1673 If the next thing following is a table, add the text properties to the first
1674 table line. If it is a link, add it to the line containing the link."
1675 (goto-char (point-min))
1676 (remove-text-properties (point-min) (point-max)
1677 '(org-caption nil org-attributes nil
))
1678 (let ((case-fold-search t
)
1679 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1681 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1683 "^#\\+label:[ \t]+\\(.*\\)"
1687 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1689 (while (re-search-forward re nil t
)
1692 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1694 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1696 (setq label
(org-trim (match-string 3))))
1698 (add-text-properties (point-at-bol) (point-at-eol)
1699 (list 'org-caption cap
1700 'org-attributes attr
1702 (if label
(push (cons label label
) target-alist
))
1703 (setq cap nil attr nil label nil
)))))
1706 (defun org-export-remove-comment-blocks-and-subtrees ()
1707 "Remove the comment environment, and also commented subtrees."
1708 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1709 (case-fold-search nil
))
1710 ;; Remove comment environment
1711 (goto-char (point-min))
1712 (while (re-search-forward
1713 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1714 (replace-match "" t t
))
1715 ;; Remove subtrees that are commented
1716 (goto-char (point-min))
1717 (while (re-search-forward re-commented nil t
)
1718 (goto-char (match-beginning 0))
1719 (delete-region (point) (org-end-of-subtree t
)))))
1721 (defun org-export-handle-comments (commentsp)
1722 "Remove comments, or convert to backend-specific format.
1723 COMMENTSP can be a format string for publishing comments.
1724 When it is nil, all comments will be removed."
1725 (let ((re "^#\\(.*\n?\\)")
1727 (goto-char (point-min))
1728 (while (or (looking-at re
)
1729 (re-search-forward re nil t
))
1730 (setq pos
(match-beginning 0))
1732 (progn (add-text-properties
1733 (match-beginning 0) (match-end 0) '(org-protected t
))
1734 (replace-match (format commentsp
(match-string 1)) t t
))
1735 (goto-char (1+ pos
))
1738 (goto-char (max (point-min) (1- pos
))))))))
1740 (defun org-export-mark-radio-links ()
1741 "Find all matches for radio targets and turn them into internal links."
1742 (let ((re-radio (and org-target-link-regexp
1743 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1744 (goto-char (point-min))
1746 (while (re-search-forward re-radio nil t
)
1748 (replace-match "\\1[[\\2]]"))))))
1750 (defun org-export-remove-special-table-lines ()
1751 "Remove tables lines that are used for internal purposes."
1752 (goto-char (point-min))
1753 (while (re-search-forward "^[ \t]*|" nil t
)
1754 (beginning-of-line 1)
1755 (if (or (looking-at "[ \t]*| *[!_^] *|")
1756 (and (looking-at ".*?| *<[0-9]+> *|")
1757 (not (looking-at ".*?| *[^ <|]"))))
1758 (delete-region (max (point-min) (1- (point-at-bol)))
1762 (defun org-export-normalize-links ()
1763 "Convert all links to bracket links, and expand link abbreviations."
1764 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1765 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1766 (goto-char (point-min))
1767 (while (re-search-forward re-plain-link nil t
)
1768 (goto-char (1- (match-end 0)))
1769 (org-if-unprotected-at (1+ (match-beginning 0))
1770 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1771 ":" (match-string 3) "]]")))
1772 ;; added 'org-link face to links
1773 (put-text-property 0 (length s
) 'face
'org-link s
)
1774 (replace-match s t t
))))
1775 (goto-char (point-min))
1776 (while (re-search-forward re-angle-link nil t
)
1777 (goto-char (1- (match-end 0)))
1779 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1780 ":" (match-string 3) "]]")))
1781 (put-text-property 0 (length s
) 'face
'org-link s
)
1782 (replace-match s t t
))))
1783 (goto-char (point-min))
1784 (while (re-search-forward org-bracket-link-regexp nil t
)
1785 (goto-char (1- (match-end 0)))
1787 (let* ((xx (save-match-data
1789 (org-link-expand-abbrev (match-string 1)))))
1791 "[[" (org-add-props (copy-sequence xx
)
1792 nil
'org-protected t
)
1796 (concat "[" (org-add-props
1801 (put-text-property 0 (length s
) 'face
'org-link s
)
1802 (replace-match s t t
))))))
1804 (defun org-export-concatenate-multiline-links ()
1805 "Find multi-line links 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 "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1811 (replace-match "\\1 \\3")
1812 (goto-char (match-beginning 0)))))
1814 (defun org-export-concatenate-multiline-emphasis ()
1815 "Find multi-line emphasis and put it all into a single line.
1816 This is to make sure that the line-processing export backends
1817 can work correctly."
1818 (goto-char (point-min))
1819 (while (re-search-forward org-emph-re nil t
)
1820 (if (and (not (= (char-after (match-beginning 3))
1821 (char-after (match-beginning 4))))
1822 (save-excursion (goto-char (match-beginning 0))
1823 (save-match-data (not (org-at-table-p)))))
1825 (subst-char-in-region (match-beginning 0) (match-end 0)
1827 (goto-char (1- (match-end 0))))
1828 (goto-char (1+ (match-beginning 0))))))
1830 (defun org-export-grab-title-from-buffer ()
1831 "Get a title for the current document, from looking at the buffer."
1832 (let ((inhibit-read-only t
))
1834 (goto-char (point-min))
1835 (let ((end (if (looking-at org-outline-regexp
)
1837 (save-excursion (outline-next-heading) (point)))))
1838 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1839 ;; Mark the line so that it will not be exported as normal text.
1841 (add-text-properties (match-beginning 0) (match-end 0)
1842 (list :org-license-to-kill t
)))
1843 ;; Return the title string
1844 (org-trim (match-string 0)))))))
1846 (defun org-export-get-title-from-subtree ()
1847 "Return subtree title and exclude it from export."
1848 (let (title (rbeg (region-beginning)) (rend (region-end)))
1851 (when (and (org-at-heading-p)
1852 (>= (org-end-of-subtree t t
) rend
))
1853 ;; This is a subtree, we take the title from the first heading
1855 (looking-at org-todo-line-regexp
)
1856 (setq title
(match-string 3))
1858 (add-text-properties (point) (1+ (point-at-eol))
1859 (list :org-license-to-kill t
)))
1860 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1863 (defun org-solidify-link-text (s &optional alist
)
1864 "Take link text and make a safe target out of it."
1869 (org-split-string s
"[ \t\r\n]+") "=="))
1870 (a (assoc rtn alist
)))
1873 (defun org-get-min-level (lines &optional offset
)
1874 "Get the minimum level in LINES."
1875 (let ((re "^\\(\\*+\\) ") l
)
1877 (while (setq l
(pop lines
))
1878 (if (string-match re l
)
1879 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
1883 ;; Variable holding the vector with section numbers
1884 (defvar org-section-numbers
(make-vector org-level-max
0))
1886 (defun org-init-section-numbers ()
1887 "Initialize the vector for the section numbers."
1889 (numbers (nreverse (org-split-string "" "\\.")))
1890 (depth (1- (length org-section-numbers
)))
1891 (i depth
) number-string
)
1894 (aset org-section-numbers i
0)
1895 (setq number-string
(or (car numbers
) "0"))
1896 (if (string-match "\\`[A-Z]\\'" number-string
)
1897 (aset org-section-numbers i
1898 (- (string-to-char number-string
) ?A -
1))
1899 (aset org-section-numbers i
(string-to-number number-string
)))
1903 (defun org-section-number (&optional level
)
1904 "Return a string with the current section number.
1905 When LEVEL is non-nil, increase section numbers on that level."
1906 (let* ((depth (1- (length org-section-numbers
)))
1908 (fmts (car org-export-section-number-format
))
1909 (term (cdr org-export-section-number-format
))
1914 (aset org-section-numbers
1915 level
(1+ (aref org-section-numbers level
))))
1916 (setq idx
(1+ level
))
1917 (while (<= idx depth
)
1919 (aset org-section-numbers idx
0))
1920 (setq idx
(1+ idx
))))
1922 (while (<= idx depth
)
1923 (when (> (aref org-section-numbers idx
) 0)
1924 (setq fmt
(or (pop fmts
) fmt
)
1926 n
(aref org-section-numbers idx
)
1928 (concat string sep
(org-number-to-counter n ctype
))
1929 (concat string
".0"))
1931 (setq idx
(1+ idx
)))
1933 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1934 (setq string
(replace-match "" t nil string
)))
1935 (if (string-match "\\(\\.0\\)+\\'" string
)
1936 (setq string
(replace-match "" t nil string
))))
1937 (concat string term
)))
1939 (defun org-number-to-counter (n type
)
1940 "Concert number N to a string counter, according to TYPE.
1941 TYPE must be a string, any of:
1945 I upper case roman numeral
1946 i lower case roman numeral"
1948 ((equal type
"1") (number-to-string n
))
1949 ((equal type
"A") (char-to-string (+ ?A n -
1)))
1950 ((equal type
"a") (char-to-string (+ ?a n -
1)))
1951 ((equal type
"I") (org-number-to-roman n
))
1952 ((equal type
"i") (downcase (org-number-to-roman n
)))
1953 (t (error "Invalid counter type `%s'" type
))))
1955 (defun org-number-to-roman (n)
1956 "Convert integer N into a roman numeral."
1957 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
1958 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
1959 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
1963 (number-to-string n
)
1965 (if (>= n
(caar roman
))
1966 (setq n
(- n
(caar roman
))
1967 res
(concat res
(cdar roman
)))
1973 (defun org-export-preprocess-apply-macros ()
1974 "Replace macro references."
1975 (goto-char (point-min))
1977 (while (re-search-forward "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)}}}" nil t
)
1978 (setq key
(downcase (match-string 1)))
1979 (when (setq val
(or (plist-get org-export-opt-plist
1980 (intern (concat ":macro-" key
)))
1981 (plist-get org-export-opt-plist
1982 (intern (concat ":" key
)))))
1984 (replace-match val t t
))))))
1986 (defun org-export-apply-macros-in-string (s)
1987 "Apply the macros in string S."
1991 (org-export-preprocess-apply-macros)
1996 (defun org-export-handle-include-files ()
1997 "Include the contents of include files, with proper formatting."
1998 (let ((case-fold-search t
)
1999 params file markup lang start end prefix prefix1 switches
)
2000 (goto-char (point-min))
2001 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2002 (setq params
(read (concat "(" (match-string 1) ")"))
2003 prefix
(org-get-and-remove-property 'params
:prefix
)
2004 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2005 file
(org-symname-or-string (pop params
))
2006 markup
(org-symname-or-string (pop params
))
2007 lang
(and (member markup
'("src" "SRC"))
2008 (org-symname-or-string (pop params
)))
2009 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2010 (delete-region (match-beginning 0) (match-end 0))
2012 (not (file-exists-p file
))
2013 (not (file-readable-p file
)))
2014 (insert (format "CANNOT INCLUDE FILE %s" file
))
2016 (if (equal (downcase markup
) "src")
2017 (setq start
(format "#+begin_src %s %s\n"
2018 (or lang
"fundamental")
2021 (setq start
(format "#+begin_%s %s\n" markup switches
)
2022 end
(format "#+end_%s" markup
))))
2023 (insert (or start
""))
2024 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2025 (or (bolp) (newline))
2026 (insert (or end
""))))))
2028 (defun org-get-file-contents (file &optional prefix prefix1
)
2029 "Get the contents of FILE and return them as a string.
2030 If PREFIX is a string, prepend it to each line. If PREFIX1
2031 is a string, prepend it to the first line instead of PREFIX."
2033 (insert-file-contents file
)
2034 (when (or prefix prefix1
)
2035 (goto-char (point-min))
2037 (insert (or prefix1 prefix
))
2039 (beginning-of-line 2)))
2042 (defun org-get-and-remove-property (listvar prop
)
2043 "Check if the value of LISTVAR contains PROP as a property.
2044 If yes, return the value of that property (i.e. the element following
2045 in the list) and remove property and value from the list in LISTVAR."
2046 (let ((list (symbol-value listvar
)) m v
)
2047 (when (setq m
(member prop list
))
2049 (if (equal (car list
) prop
)
2050 (set listvar
(cddr list
))
2051 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2053 (set listvar list
)))
2056 (defun org-symname-or-string (s)
2058 (if s
(symbol-name s
) s
)
2061 ;;; Fontification and line numbers for code examples
2063 (defvar org-export-last-code-line-counter-value
0)
2065 (defun org-export-replace-src-segments-and-examples (backend)
2066 "Replace source code segments with special code for export."
2067 (setq org-export-last-code-line-counter-value
0)
2068 (let ((case-fold-search t
)
2069 lang code trans opts
)
2070 (goto-char (point-min))
2071 (while (re-search-forward
2072 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2076 (setq lang
(match-string 2)
2077 opts
(match-string 3)
2078 code
(match-string 4))
2080 opts
(match-string 6)
2081 code
(match-string 7)))
2083 (setq trans
(org-export-format-source-code-or-example
2084 backend lang code opts
))
2085 (replace-match trans t t
))))
2087 (defvar htmlp
) ;; dynamically scoped
2088 (defvar latexp
) ;; dynamically scoped
2090 (defun org-export-format-source-code-or-example (backend
2091 lang code
&optional opts
)
2092 "Format CODE from language LANG and return it formatted for export.
2093 If LANG is nil, do not add any fontification.
2094 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2095 and `+n' for continuing previous numering.
2096 Code formatting according to language currently only works for HTML.
2097 Numbering lines works for all three major backends (html, latex, and ascii)."
2099 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2100 (setq opts
(or opts
"")
2101 num
(string-match "[-+]n\\>" opts
)
2102 cont
(string-match "\\+n\\>" opts
)
2103 rpllbl
(string-match "-r\\>" opts
)
2104 keepp
(string-match "-k\\>" opts
)
2105 textareap
(string-match "-t\\>" opts
)
2106 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2107 (string-to-number (match-string 1 opts
))
2109 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2110 (string-to-number (match-string 1 opts
))
2111 (org-count-lines code
))
2112 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2113 (match-string 1 opts
)))
2114 (when (and textareap
(eq backend
'html
))
2115 ;; we cannot use numbering or highlighting.
2116 (setq num nil cont nil lang nil
))
2117 (if keepp
(setq rpllbl
'keep
))
2119 (when (equal lang
"org")
2120 (setq rtn
(with-temp-buffer
2122 ;; Free up the protected lines
2123 (goto-char (point-min))
2124 (while (re-search-forward "^," nil t
)
2128 ;; Now backend-specific coding
2130 ((eq backend
'docbook
)
2131 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2132 (concat "\n#+BEGIN_DOCBOOK\n"
2133 (org-add-props (concat "<programlisting><![CDATA["
2135 "]]>\n</programlisting>\n")
2139 ;; We are exporting to HTML
2141 (require 'htmlize nil t
)
2142 (when (not (fboundp 'htmlize-region-for-paste
))
2143 ;; we do not have htmlize.el, or an old version of it
2146 "htmlize.el 1.34 or later is needed for source code formatting")))
2149 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2150 (org-inhibit-startup t
)
2151 (org-startup-folded nil
))
2155 (if (functionp mode
)
2158 (font-lock-fontify-buffer)
2159 (set-buffer-modified-p nil
)
2160 (org-export-htmlize-region-for-paste
2161 (point-min) (point-max))))
2162 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2163 (setq rtn
(replace-match
2164 (format "<pre class=\"src src-%s\">\n" lang
)
2168 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2170 rtn
"</textarea>\n</p>\n"))
2173 (goto-char (point-min))
2174 (while (re-search-forward "[<>&]" nil t
)
2175 (replace-match (cdr (assq (char-before)
2176 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2178 (setq rtn
(buffer-string)))
2179 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2181 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2183 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2184 ((eq backend
'latex
)
2185 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2186 (concat "\n#+BEGIN_LaTeX\n"
2187 (org-add-props (concat "\\begin{verbatim}\n" rtn
"\n\\end{verbatim}\n")
2190 ((eq backend
'ascii
)
2191 ;; This is not HTML or LaTeX, so just make it an example.
2192 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2193 (concat "#+BEGIN_ASCII\n"
2197 (lambda (l) (concat " " l
))
2198 (org-split-string rtn
"\n")
2202 "#+END_ASCII\n"))))))
2204 (defun org-export-number-lines (text backend
2205 &optional skip1 skip2 number cont
2206 replace-labels label-format
)
2207 (if (and (not number
) (not (eq replace-labels
'keep
)))
2208 (setq replace-labels nil
)) ;; must use names if no numbers
2209 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2210 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2213 (goto-char (point-max))
2214 (skip-chars-backward " \t\n\r")
2215 (delete-region (point) (point-max))
2216 (beginning-of-line (- 1 skip2
))
2217 (let* ((last (org-current-line))
2218 (n org-export-last-code-line-counter-value
)
2219 (nmax (+ n
(- last skip1
)))
2220 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2223 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2225 ((eq backend
'ascii
) fmt
)
2226 ((eq backend
'latex
) fmt
)
2227 ((eq backend
'docbook
) fmt
)
2229 (label-format (or label-format org-coderef-label-format
))
2230 (label-pre (if (string-match "%s" label-format
)
2231 (substring label-format
0 (match-beginning 0))
2233 (label-post (if (string-match "%s" label-format
)
2234 (substring label-format
(match-end 0))
2238 ".*?\\S-.*?\\([ \t]*\\("
2239 (regexp-quote label-pre
)
2240 "\\([-a-zA-Z0-9_]+\\)"
2241 (regexp-quote label-post
)
2245 (goto-line (1+ skip1
))
2246 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2248 (insert (format fm
(incf n
)))
2250 (when (and (not (eq replace-labels
'keep
))
2251 (looking-at lbl-re
))
2252 (setq ref
(match-string 3))
2255 (delete-region (match-beginning 1) (match-end 1))
2256 (push (cons ref n
) org-export-code-refs
))
2257 (goto-char (match-beginning 2))
2258 (delete-region (match-beginning 2) (match-end 2))
2259 (insert "(" ref
")")
2260 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2261 (when (eq backend
'html
)
2263 (beginning-of-line 1)
2264 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2267 (insert "</span>")))))
2268 (setq org-export-last-code-line-counter-value n
)
2269 (goto-char (point-max))
2273 (defun org-search-todo-below (line lines level
)
2274 "Search the subtree below LINE for any TODO entries."
2275 (let ((rest (cdr (memq line lines
)))
2276 (re org-todo-line-regexp
)
2279 (while (setq line
(pop rest
))
2280 (if (string-match re line
)
2282 (setq lv
(- (match-end 1) (match-beginning 1))
2283 todo
(and (match-beginning 2)
2284 (not (member (match-string 2 line
)
2285 org-done-keywords
))))
2287 (if (<= lv level
) (throw 'exit nil
))
2288 (if todo
(throw 'exit t
))))))))
2291 (defun org-export-visible (type arg
)
2292 "Create a copy of the visible part of the current buffer, and export it.
2293 The copy is created in a temporary buffer and removed after use.
2294 TYPE is the final key (as a string) that also select the export command in
2295 the `C-c C-e' export dispatcher.
2296 As a special case, if the you type SPC at the prompt, the temporary
2297 org-mode file will not be removed but presented to you so that you can
2298 continue to use it. The prefix arg ARG is passed through to the exporting
2302 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2303 (read-char-exclusive))
2304 current-prefix-arg
))
2305 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\
)))
2306 (error "Invalid export key"))
2307 (let* ((binding (cdr (assoc type
2308 '((?a . org-export-as-ascii
)
2309 (?\C-a . org-export-as-ascii
)
2310 (?b . org-export-as-html-and-open
)
2311 (?\C-b . org-export-as-html-and-open
)
2312 (?h . org-export-as-html
)
2313 (?H . org-export-as-html-to-buffer
)
2314 (?R . org-export-region-as-html
)
2315 (?D . org-export-as-docbook
)
2316 (?x . org-export-as-xoxo
)))))
2317 (keepp (equal type ?\
))
2318 (file buffer-file-name
)
2319 (buffer (get-buffer-create "*Org Export Visible*"))
2321 ;; Need to hack the drawers here.
2323 (goto-char (point-min))
2324 (while (re-search-forward org-drawer-regexp nil t
)
2325 (goto-char (match-beginning 1))
2326 (or (org-invisible-p) (org-flag-drawer nil
))))
2327 (with-current-buffer buffer
(erase-buffer))
2329 (setq s
(goto-char (point-min)))
2330 (while (not (= (point) (point-max)))
2331 (goto-char (org-find-invisible))
2332 (append-to-buffer buffer s
(point))
2333 (setq s
(goto-char (org-find-visible))))
2334 (org-cycle-hide-drawers 'all
)
2335 (goto-char (point-min))
2337 ;; Copy all comment lines to the end, to make sure #+ settings are
2338 ;; still available for the second export step. Kind of a hack, but
2339 ;; does do the trick.
2340 (if (looking-at "#[^\r\n]*")
2341 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2342 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2343 (append-to-buffer buffer
(1+ (match-beginning 0))
2344 (min (point-max) (1+ (match-end 0))))))
2346 (let ((buffer-file-name file
)
2347 (org-inhibit-startup t
))
2350 (unless keepp
(funcall binding arg
))))
2352 (kill-buffer buffer
)
2353 (switch-to-buffer-other-window buffer
)
2354 (goto-char (point-min)))))
2356 (defun org-find-visible ()
2358 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2359 (get-char-property s
'invisible
)))
2361 (defun org-find-invisible ()
2363 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2364 (not (get-char-property s
'invisible
))))
2367 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2368 (defun org-get-current-options ()
2369 "Return a string with current options as keyword options.
2370 Does include HTML export options as well as TODO and CATEGORY stuff."
2371 (require 'org-archive
)
2380 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2381 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2383 #+EXPORT_SELECT_TAGS: %s
2384 #+EXPORT_EXCLUDE_TAGS: %s
2390 #+PRIORITIES: %c %c %c
2392 #+STARTUP: %s %s %s %s %s
2398 (buffer-name) (user-full-name) user-mail-address
2399 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2400 org-export-default-language
2401 org-export-headline-levels
2402 org-export-with-section-numbers
2404 org-export-preserve-breaks
2405 org-export-html-expand
2406 org-export-with-fixed-width
2407 org-export-with-tables
2408 org-export-with-sub-superscripts
2409 org-export-with-special-strings
2410 org-export-with-footnotes
2411 org-export-with-emphasize
2412 org-export-with-timestamps
2413 org-export-with-TeX-macros
2414 org-export-with-LaTeX-fragments
2415 org-export-skip-text-before-1st-heading
2416 org-export-with-drawers
2417 org-export-with-todo-keywords
2418 org-export-with-priority
2419 org-export-with-tags
2420 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2421 (mapconcat 'identity org-export-select-tags
" ")
2422 (mapconcat 'identity org-export-exclude-tags
" ")
2423 org-export-html-link-up
2424 org-export-html-link-home
2426 (file-name-sans-extension
2427 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2429 "TODO FEEDBACK VERIFY DONE"
2430 "Me Jason Marie DONE"
2431 org-highest-priority org-lowest-priority org-default-priority
2432 (mapconcat 'identity org-drawers
" ")
2433 (cdr (assoc org-startup-folded
2434 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2435 (if org-odd-levels-only
"odd" "oddeven")
2436 (if org-hide-leading-stars
"hidestars" "showstars")
2437 (if org-startup-align-all-tables
"align" "noalign")
2438 (cond ((eq org-log-done t
) "logdone")
2439 ((equal org-log-done
'note
) "lognotedone")
2440 ((not org-log-done
) "nologdone"))
2441 (or (mapconcat (lambda (x)
2443 ((equal '(:startgroup
) x
) "{")
2444 ((equal '(:endgroup
) x
) "}")
2445 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2447 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2448 (mapconcat 'identity org-file-tags
" ")
2449 org-archive-location
2450 "org file:~/org/%s.org"
2454 (defun org-insert-export-options-template ()
2455 "Insert into the buffer a template with information for exporting."
2457 (if (not (bolp)) (newline))
2458 (let ((s (org-get-current-options)))
2459 (and (string-match "#\\+CATEGORY" s
)
2460 (setq s
(substring s
0 (match-beginning 0))))
2463 (defvar org-table-colgroup-info nil
)
2465 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2466 "Check if the table has a marking column.
2467 If yes remove the column and the special lines."
2468 (setq org-table-colgroup-info nil
)
2471 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2474 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2475 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2479 (setq org-table-clean-did-remove-column nil
)
2484 ((string-match "^[ \t]*| */ *|" x
)
2485 (setq org-table-colgroup-info
2487 (cond ((member x
'("<" "<")) :start
)
2488 ((member x
'(">" ">")) :end
)
2489 ((member x
'("<>" "<>")) :startend
)
2491 (org-split-string x
"[ \t]*|[ \t]*")))
2495 (setq org-table-clean-did-remove-column t
)
2500 ((string-match "^[ \t]*| */ *|" x
)
2501 (setq org-table-colgroup-info
2503 (cond ((member x
'("<" "<")) :start
)
2504 ((member x
'(">" ">")) :end
)
2505 ((member x
'("<>" "<>")) :startend
)
2507 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2509 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2510 nil
) ; ignore this line
2511 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2512 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2513 ;; remove the first column
2514 (replace-match "\\1|" t nil x
))))
2517 (defun org-export-cleanup-toc-line (s)
2518 "Remove tags and timestamps from lines going into the toc."
2519 (when (memq org-export-with-tags
'(not-in-toc nil
))
2520 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2521 (setq s
(replace-match "" t t s
))))
2522 (when org-export-remove-timestamps-from-toc
2523 (while (string-match org-maybe-keyword-time-regexp s
)
2524 (setq s
(replace-match "" t t s
))))
2525 (while (string-match org-bracket-link-regexp s
)
2526 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2530 (defun org-create-multibrace-regexp (left right n
)
2531 "Create a regular expression which will match a balanced sexp.
2532 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2533 as single character strings.
2534 The regexp returned will match the entire expression including the
2535 delimiters. It will also define a single group which contains the
2536 match except for the outermost delimiters. The maximum depth of
2537 stacked delimiters is N. Escaping delimiters is not possible."
2538 (let* ((nothing (concat "[^" left right
"]*?"))
2541 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
2544 re
(concat re or next
)
2545 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
2546 (concat left
"\\(" re
"\\)" right
)))
2548 (defvar org-match-substring-regexp
2550 "\\([^\\]\\)\\([_^]\\)\\("
2551 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2553 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
2555 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2556 "The regular expression matching a sub- or superscript.")
2558 (defvar org-match-substring-with-braces-regexp
2560 "\\([^\\]\\)\\([_^]\\)\\("
2561 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2563 "The regular expression matching a sub- or superscript, forcing braces.")
2566 (defun org-get-text-property-any (pos prop
&optional object
)
2567 (or (get-text-property pos prop object
)
2568 (and (setq pos
(next-single-property-change pos prop object
))
2569 (get-text-property pos prop object
))))
2571 (defun org-export-get-coderef-format (path desc
)
2573 (if (and desc
(string-match
2574 (regexp-quote (concat "(" path
")"))
2576 (replace-match "%s" t t desc
)
2581 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
2583 ;;; org-exp.el ends here