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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 (require 'org-exp-blocks
)
37 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
38 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
39 (declare-function org-export-html-preprocess
"org-html" (parameters))
40 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
41 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
42 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
43 (declare-function htmlize-buffer
"ext:htmlize" (&optional buffer
))
44 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
45 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
46 (defgroup org-export nil
47 "Options for exporting org-listings."
51 (defgroup org-export-general nil
52 "General options for exporting Org-mode files."
53 :tag
"Org Export General"
56 (defcustom org-export-allow-BIND
'confirm
57 "Non-nil means allow #+BIND to define local variable values for export.
58 This is a potential security risk, which is why the user must confirm the
60 :group
'org-export-general
62 (const :tag
"Never" nil
)
63 (const :tag
"Always" t
)
64 (const :tag
"Make the user confirm for each file" confirm
)))
67 (defvar org-export-publishing-directory nil
)
69 (defcustom org-export-show-temporary-export-buffer t
70 "Non-nil means show buffer after exporting to temp buffer.
71 When Org exports to a file, the buffer visiting that file is ever
72 shown, but remains buried. However, when exporting to a temporary
73 buffer, that buffer is popped up in a second window. When this variable
74 is nil, the buffer remains buried also in these cases."
75 :group
'org-export-general
78 (defcustom org-export-copy-to-kill-ring t
79 "Non-nil means exported stuff will also be pushed onto the kill ring."
80 :group
'org-export-general
83 (defcustom org-export-run-in-background nil
84 "Non-nil means export and publishing commands will run in background.
85 This works by starting up a separate Emacs process visiting the same file
86 and doing the export from there.
87 Not all export commands are affected by this - only the ones which
88 actually write to a file, and that do not depend on the buffer state.
90 If this option is nil, you can still get background export by calling
91 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
93 If this option is t, the double prefix can be used to exceptionally
94 force an export command into the current process."
95 :group
'org-export-general
98 (defcustom org-export-select-tags
'("export")
99 "Tags that select a tree for export.
100 If any such tag is found in a buffer, all trees that do not carry one
101 of these tags will be deleted before export.
102 Inside trees that are selected like this, you can still deselect a
103 subtree by tagging it with one of the `org-export-exclude-tags'."
104 :group
'org-export-general
105 :type
'(repeat (string :tag
"Tag")))
107 (defcustom org-export-exclude-tags
'("noexport")
108 "Tags that exclude a tree from export.
109 All trees carrying any of these tags will be excluded from export.
110 This is without condition, so even subtrees inside that carry one of the
111 `org-export-select-tags' will be removed."
112 :group
'org-export-general
113 :type
'(repeat (string :tag
"Tag")))
115 ;; FIXME: rename, this is a general variable
116 (defcustom org-export-html-expand t
117 "Non-nil means for HTML export, treat @<...> as HTML tag.
118 When nil, these tags will be exported as plain text and therefore
119 not be interpreted by a browser.
121 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
122 :group
'org-export-html
123 :group
'org-export-general
126 (defcustom org-export-with-special-strings t
127 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
128 When this option is turned on, these strings will be exported as:
131 -----+----------+--------
137 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
138 :group
'org-export-translation
141 (defcustom org-export-html-link-up
""
142 "Where should the \"UP\" link of exported HTML pages lead?"
143 :group
'org-export-html
144 :group
'org-export-general
145 :type
'(string :tag
"File or URL"))
147 (defcustom org-export-html-link-home
""
148 "Where should the \"HOME\" link of exported HTML pages lead?"
149 :group
'org-export-html
150 :group
'org-export-general
151 :type
'(string :tag
"File or URL"))
153 (defcustom org-export-language-setup
154 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
155 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
156 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
157 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
158 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
159 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
160 ("es" "Autor" "Fecha" "Índice" "Pies de página")
161 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
162 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
163 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
164 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
165 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
166 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
167 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
168 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
169 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
170 ("pl" "Autor" "Data" "Spis treści" "Przypis")
171 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
172 "Terms used in export text, translated to different languages.
173 Use the variable `org-export-default-language' to set the language,
174 or use the +OPTION lines for a per-file setting."
175 :group
'org-export-general
178 (string :tag
"HTML language tag")
179 (string :tag
"Author")
181 (string :tag
"Table of Contents")
182 (string :tag
"Footnotes"))))
184 (defcustom org-export-default-language
"en"
185 "The default language of HTML export, as a string.
186 This should have an association in `org-export-language-setup'."
187 :group
'org-export-general
190 (defvar org-export-page-description
""
191 "The page description, for the XHTML meta tag.
192 This is best set with the #+DESCRIPTION line in a file, it does not make
193 sense to set this globally.")
195 (defvar org-export-page-keywords
""
196 "The page description, for the XHTML meta tag.
197 This is best set with the #+KEYWORDS line in a file, it does not make
198 sense to set this globally.")
200 (defcustom org-export-skip-text-before-1st-heading nil
201 "Non-nil means skip all text before the first headline when exporting.
202 When nil, that text is exported as well."
203 :group
'org-export-general
206 (defcustom org-export-headline-levels
3
207 "The last level which is still exported as a headline.
208 Inferior levels will produce itemize lists when exported.
209 Note that a numeric prefix argument to an exporter function overrides
212 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
213 :group
'org-export-general
216 (defcustom org-export-with-section-numbers t
217 "Non-nil means add section numbers to headlines when exporting.
219 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
220 :group
'org-export-general
223 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
224 "Format of section numbers for export.
225 The variable has two components.
226 1. A list of lists, each indicating a counter type and a separator.
227 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
228 It causes causes numeric, alphabetic, or roman counters, respectively.
229 The separator is only used if another counter for a subsection is being
231 If there are more numbered section levels than entries in this lists,
232 then the last entry will be reused.
233 2. A terminator string that will be added after the entire
235 :group
'org-export-general
239 (string :tag
"Counter Type")
240 (string :tag
"Separator ")))
241 (string :tag
"Terminator")))
243 (defcustom org-export-with-toc t
244 "Non-nil means create a table of contents in exported files.
245 The TOC contains headlines with levels up to`org-export-headline-levels'.
246 When an integer, include levels up to N in the toc, this may then be
247 different from `org-export-headline-levels', but it will not be allowed
248 to be larger than the number of headline levels.
249 When nil, no table of contents is made.
251 Headlines which contain any TODO items will be marked with \"(*)\" in
252 ASCII export, and with red color in HTML output, if the option
253 `org-export-mark-todo-in-toc' is set.
255 In HTML output, the TOC will be clickable.
257 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
259 :group
'org-export-general
261 (const :tag
"No Table of Contents" nil
)
262 (const :tag
"Full Table of Contents" t
)
263 (integer :tag
"TOC to level")))
265 (defcustom org-export-mark-todo-in-toc nil
266 "Non-nil means mark TOC lines that contain any open TODO items."
267 :group
'org-export-general
270 (defcustom org-export-with-todo-keywords t
271 "Non-nil means include TODO keywords in export.
272 When nil, remove all these keywords from the export."
273 :group
'org-export-general
276 (defcustom org-export-with-priority nil
277 "Non-nil means include priority cookies in export.
278 When nil, remove priority cookies for export."
279 :group
'org-export-general
282 (defcustom org-export-preserve-breaks nil
283 "Non-nil means preserve all line breaks when exporting.
284 Normally, in HTML output paragraphs will be reformatted. In ASCII
285 export, line breaks will always be preserved, regardless of this variable.
287 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
288 :group
'org-export-general
291 (defcustom org-export-with-archived-trees
'headline
292 "Whether subtrees with the ARCHIVE tag should be exported.
293 This can have three different values
294 nil Do not export, pretend this tree is not present
295 t Do export the entire tree
296 headline Only export the headline, but skip the tree below it."
297 :group
'org-export-general
300 (const :tag
"not at all" nil
)
301 (const :tag
"headline only" 'headline
)
302 (const :tag
"entirely" t
)))
304 (defcustom org-export-author-info t
305 "Non-nil means insert author name and email into the exported file.
307 This option can also be set with the +OPTIONS line,
308 e.g. \"author-info:nil\"."
309 :group
'org-export-general
312 (defcustom org-export-creator-info t
313 "Non-nil means the postamble should contain a creator sentence.
314 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
315 :group
'org-export-general
318 (defcustom org-export-time-stamp-file t
319 "Non-nil means insert a time stamp into the exported file.
320 The time stamp shows when the file was created.
322 This option can also be set with the +OPTIONS line,
323 e.g. \"timestamp:nil\"."
324 :group
'org-export-general
327 (defcustom org-export-with-timestamps t
328 "If nil, do not export time stamps and associated keywords."
329 :group
'org-export-general
332 (defcustom org-export-remove-timestamps-from-toc t
333 "If t, remove timestamps from the table of contents entries."
334 :group
'org-export-general
337 (defcustom org-export-with-tags
'not-in-toc
338 "If nil, do not export tags, just remove them from headlines.
339 If this is the symbol `not-in-toc', tags will be removed from table of
340 contents entries, but still be shown in the headlines of the document.
342 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
343 :group
'org-export-general
345 (const :tag
"Off" nil
)
346 (const :tag
"Not in TOC" not-in-toc
)
347 (const :tag
"On" t
)))
349 (defcustom org-export-with-drawers nil
350 "Non-nil means export with drawers like the property drawer.
351 When t, all drawers are exported. This may also be a list of
352 drawer names to export."
353 :group
'org-export-general
355 (const :tag
"All drawers" t
)
356 (const :tag
"None" nil
)
357 (repeat :tag
"Selected drawers"
358 (string :tag
"Drawer name"))))
360 (defvar org-export-first-hook nil
361 "Hook called as the first thing in each exporter.
362 Point will be still in the original buffer.
363 Good for general initialization")
365 (defvar org-export-preprocess-hook nil
366 "Hook for preprocessing an export buffer.
367 Pretty much the first thing when exporting is running this hook.
368 Point will be in a temporary buffer that contains a copy of
369 the original buffer, or of the section that is being export.
370 All the other hooks in the org-export-preprocess... category
371 also work in that temporary buffer, already modified by various
372 stages of the processing.")
374 (defvar org-export-preprocess-after-include-files-hook nil
375 "Hook for preprocessing an export buffer.
376 This is run after the contents of included files have been inserted.")
378 (defvar org-export-preprocess-after-tree-selection-hook nil
379 "Hook for preprocessing an export buffer.
380 This is run after selection of trees to be exported has happened.
381 This selection includes tags-based selection, as well as removal
382 of commented and archived trees.")
384 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
385 "Hook for preprocessing an export buffer.
386 This is run just before backend-specific blocks get selected.")
388 (defvar org-export-preprocess-after-blockquote-hook nil
389 "Hook for preprocessing an export buffer.
390 This is run after blockquote/quote/verse/center have been marked
393 (defvar org-export-preprocess-before-normalizing-links-hook nil
394 "Hook for preprocessing an export buffer.
395 This hook is run before links are normalized.")
397 (defvar org-export-preprocess-before-backend-specifics-hook nil
398 "Hook run before backend-specific functions are called during preprocessing.")
400 (defvar org-export-preprocess-final-hook nil
401 "Hook for preprocessing an export buffer.
402 This is run as the last thing in the preprocessing buffer, just before
403 returning the buffer string to the backend.")
405 (defgroup org-export-translation nil
406 "Options for translating special ascii sequences for the export backends."
407 :tag
"Org Export Translation"
410 (defcustom org-export-with-emphasize t
411 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
412 If the export target supports emphasizing text, the word will be
413 typeset in bold, italic, or underlined, respectively. Works only for
414 single words, but you can say: I *really* *mean* *this*.
415 Not all export backends support this.
417 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
418 :group
'org-export-translation
421 (defcustom org-export-with-footnotes t
422 "If nil, export [1] as a footnote marker.
423 Lines starting with [1] will be formatted as footnotes.
425 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
426 :group
'org-export-translation
429 (defcustom org-export-with-sub-superscripts t
430 "Non-nil means interpret \"_\" and \"^\" for export.
431 When this option is turned on, you can use TeX-like syntax for sub- and
432 superscripts. Several characters after \"_\" or \"^\" will be
433 considered as a single item - so grouping with {} is normally not
434 needed. For example, the following things will be parsed as single
435 sub- or superscripts.
437 10^24 or 10^tau several digits will be considered 1 item.
438 10^-12 or 10^-tau a leading sign with digits or a word
439 x^2-y^3 will be read as x^2 - y^3, because items are
440 terminated by almost any nonword/nondigit char.
441 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
443 Still, ambiguity is possible - so when in doubt use {} to enclose the
444 sub/superscript. If you set this variable to the symbol `{}',
445 the braces are *required* in order to trigger interpretations as
446 sub/superscript. This can be helpful in documents that need \"_\"
447 frequently in plain text.
449 Not all export backends support this, but HTML does.
451 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
452 :group
'org-export-translation
454 (const :tag
"Always interpret" t
)
455 (const :tag
"Only with braces" {})
456 (const :tag
"Never interpret" nil
)))
458 (defcustom org-export-with-TeX-macros t
459 "Non-nil means interpret simple TeX-like macros when exporting.
460 For example, HTML export converts \\alpha to α and \\AA to Å.
461 Not only real TeX macros will work here, but the standard HTML entities
462 for math can be used as macro names as well. For a list of supported
463 names in HTML export, see the constant `org-html-entities'.
464 Not all export backends support this.
466 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
467 :group
'org-export-translation
468 :group
'org-export-latex
471 (defcustom org-export-with-LaTeX-fragments nil
472 "Non-nil means convert LaTeX fragments to images when exporting to HTML.
473 When set, the exporter will find LaTeX environments if the \\begin line is
474 the first non-white thing on a line. It will also find the math delimiters
475 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
478 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
480 The default is nil, because this option needs the `dvipng' program which
481 is not available on all systems."
482 :group
'org-export-translation
483 :group
'org-export-latex
486 (defcustom org-export-with-fixed-width t
487 "Non-nil means lines starting with \":\" will be in fixed width font.
488 This can be used to have pre-formatted text, fragments of code etc. For
490 : ;; Some Lisp examples
493 will be looking just like this in also HTML. See also the QUOTE keyword.
494 Not all export backends support this.
496 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
497 :group
'org-export-translation
500 (defcustom org-match-sexp-depth
3
501 "Number of stacked braces for sub/superscript matching.
502 This has to be set before loading org.el to be effective."
503 :group
'org-export-translation
506 (defgroup org-export-tables nil
507 "Options for exporting tables in Org-mode."
508 :tag
"Org Export Tables"
511 (defcustom org-export-with-tables t
512 "If non-nil, lines starting with \"|\" define a table.
515 | Name | Address | Birthday |
516 |-------------+----------+-----------|
517 | Arthur Dent | England | 29.2.2100 |
519 Not all export backends support this.
521 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
522 :group
'org-export-tables
525 (defcustom org-export-highlight-first-table-line t
526 "Non-nil means highlight the first table line.
527 In HTML export, this means use <th> instead of <td>.
528 In tables created with table.el, this applies to the first table line.
529 In Org-mode tables, all lines before the first horizontal separator
530 line will be formatted with <th> tags."
531 :group
'org-export-tables
534 (defcustom org-export-table-remove-special-lines t
535 "Remove special lines and marking characters in calculating tables.
536 This removes the special marking character column from tables that are set
537 up for spreadsheet calculations. It also removes the entire lines
538 marked with `!', `_', or `^'. The lines with `$' are kept, because
539 the values of constants may be useful to have."
540 :group
'org-export-tables
543 (defcustom org-export-prefer-native-exporter-for-tables nil
544 "Non-nil means always export tables created with table.el natively.
545 Natively means use the HTML code generator in table.el.
546 When nil, Org-mode's own HTML generator is used when possible (i.e. if
547 the table does not use row- or column-spanning). This has the
548 advantage, that the automatic HTML conversions for math symbols and
549 sub/superscripts can be applied. Org-mode's HTML generator is also
551 :group
'org-export-tables
555 (defgroup org-export-xml nil
556 "Options specific for XML export of Org-mode files."
557 :tag
"Org Export XML"
562 ;;; Variables, constants, and parameter plists
564 (defconst org-level-max
20)
566 (defvar org-current-export-file nil
) ; dynamically scoped parameter
567 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
568 (defvar org-export-opt-plist nil
569 "Contains the current option plist.")
570 (defvar org-last-level nil
) ; dynamically scoped variable
571 (defvar org-min-level nil
) ; dynamically scoped variable
572 (defvar org-levels-open nil
) ; dynamically scoped parameter
574 (defconst org-export-plist-vars
575 '((:link-up nil org-export-html-link-up
)
576 (:link-home nil org-export-html-link-home
)
577 (:language nil org-export-default-language
)
578 (:keywords nil org-export-page-keywords
)
579 (:description nil org-export-page-description
)
580 (:customtime nil org-display-custom-times
)
581 (:headline-levels
"H" org-export-headline-levels
)
582 (:section-numbers
"num" org-export-with-section-numbers
)
583 (:section-number-format nil org-export-section-number-format
)
584 (:table-of-contents
"toc" org-export-with-toc
)
585 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
586 (:archived-trees nil org-export-with-archived-trees
)
587 (:emphasize
"*" org-export-with-emphasize
)
588 (:sub-superscript
"^" org-export-with-sub-superscripts
)
589 (:special-strings
"-" org-export-with-special-strings
)
590 (:footnotes
"f" org-export-with-footnotes
)
591 (:drawers
"d" org-export-with-drawers
)
592 (:tags
"tags" org-export-with-tags
)
593 (:todo-keywords
"todo" org-export-with-todo-keywords
)
594 (:priority
"pri" org-export-with-priority
)
595 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
596 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
597 (:latex-listings nil org-export-latex-listings
)
598 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
599 (:fixed-width
":" org-export-with-fixed-width
)
600 (:timestamps
"<" org-export-with-timestamps
)
601 (:author-info
"author" org-export-author-info
)
602 (:creator-info
"creator" org-export-creator-info
)
603 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
604 (:tables
"|" org-export-with-tables
)
605 (:table-auto-headline nil org-export-highlight-first-table-line
)
606 (:style-include-default nil org-export-html-style-include-default
)
607 (:style-include-scripts nil org-export-html-style-include-scripts
)
608 (:style nil org-export-html-style
)
609 (:style-extra nil org-export-html-style-extra
)
610 (:agenda-style nil org-agenda-export-html-style
)
611 (:convert-org-links nil org-export-html-link-org-files-as-html
)
612 (:inline-images nil org-export-html-inline-images
)
613 (:html-extension nil org-export-html-extension
)
614 (:xml-declaration nil org-export-html-xml-declaration
)
615 (:html-table-tag nil org-export-html-table-tag
)
616 (:expand-quoted-html
"@" org-export-html-expand
)
617 (:timestamp nil org-export-html-with-timestamp
)
618 (:publishing-directory nil org-export-publishing-directory
)
619 (:preamble nil org-export-html-preamble
)
620 (:postamble nil org-export-html-postamble
)
621 (:auto-preamble nil org-export-html-auto-preamble
)
622 (:auto-postamble nil org-export-html-auto-postamble
)
623 (:author nil user-full-name
)
624 (:email nil user-mail-address
)
625 (:select-tags nil org-export-select-tags
)
626 (:exclude-tags nil org-export-exclude-tags
)
628 (:latex-image-options nil org-export-latex-image-default-option
))
629 "List of properties that represent export/publishing variables.
630 Each element is a list of 3 items:
631 1. The property that is used internally, and also for org-publish-project-alist
632 2. The string that can be used in the OPTION lines to set this option,
633 or nil if this option cannot be changed in this way
634 3. The customization variable that sets the default for this option."
637 (defun org-default-export-plist ()
638 "Return the property list with default settings for the export variables."
639 (let* ((infile (org-infile-export-plist))
640 (letbind (plist-get infile
:let-bind
))
641 (l org-export-plist-vars
) rtn e s v
)
642 (while (setq e
(pop l
))
645 ((assq s letbind
) (nth 1 (assq s letbind
)))
646 ((boundp s
) (symbol-value s
))
648 rtn
(cons (car e
) (cons v rtn
))))
651 (defvar org-export-inbuffer-options-extra nil
652 "List of additional in-buffer options that should be detected.
653 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
654 etc. Extensions can add to this list to get their options detected, and they
655 can then add a function to `org-export-options-filters' to process these
657 Each element in this list must be a list, with the in-buffer keyword as car,
658 and a property (a symbol) as the next element. All occurrences of the
659 keyword will be found, the values concatenated with a space character
660 in between, and the result stored in the export options property list.")
662 (defvar org-export-options-filters nil
663 "Functions to be called to finalize the export/publishing options.
664 All these options are stored in a property list, and each of the functions
665 in this hook gets a chance to modify this property list. Each function
666 must accept the property list as an argument, and must return the (possibly
669 ;; FIXME: should we fold case here?
670 (defun org-infile-export-plist ()
671 "Return the property list with file-local settings for export."
675 (goto-char (point-min))
676 (let ((re (org-make-options-regexp
678 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
679 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
680 "LATEX_HEADER" "LATEX_CLASS"
681 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
682 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND")
683 (mapcar 'car org-export-inbuffer-options-extra
))))
684 p key val text options a pr style
685 latex-header latex-class macros letbind
686 ext-setup-or-nil setup-contents
(start 0))
687 (while (or (and ext-setup-or-nil
688 (string-match re ext-setup-or-nil start
)
689 (setq start
(match-end 0)))
690 (and (setq ext-setup-or-nil nil start
0)
691 (re-search-forward re nil t
)))
692 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
693 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
695 ((setq a
(assoc key org-export-inbuffer-options-extra
))
697 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
698 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
699 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
700 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
701 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
702 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
703 ((string-equal key
"DESCRIPTION")
704 (setq p
(plist-put p
:description val
)))
705 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
706 ((string-equal key
"STYLE")
707 (setq style
(concat style
"\n" val
)))
708 ((string-equal key
"LATEX_HEADER")
709 (setq latex-header
(concat latex-header
"\n" val
)))
710 ((string-equal key
"LATEX_CLASS")
711 (setq latex-class val
))
712 ((string-equal key
"TEXT")
713 (setq text
(if text
(concat text
"\n" val
) val
)))
714 ((string-equal key
"OPTIONS")
715 (setq options
(concat val
" " options
)))
716 ((string-equal key
"BIND")
717 (push (read (concat "(" val
")")) letbind
))
718 ((string-equal key
"LINK_UP")
719 (setq p
(plist-put p
:link-up val
)))
720 ((string-equal key
"LINK_HOME")
721 (setq p
(plist-put p
:link-home val
)))
722 ((string-equal key
"EXPORT_SELECT_TAGS")
723 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
724 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
725 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
726 ((string-equal key
"MACRO")
728 ((equal key
"SETUPFILE")
729 (setq setup-contents
(org-file-contents
731 (org-remove-double-quotes
734 (if (not ext-setup-or-nil
)
735 (setq ext-setup-or-nil setup-contents start
0)
736 (setq ext-setup-or-nil
737 (concat (substring ext-setup-or-nil
0 start
)
738 "\n" setup-contents
"\n"
739 (substring ext-setup-or-nil start
)))))))
740 (setq p
(plist-put p
:text text
))
741 (when (and letbind
(org-export-confirm-letbind))
742 (setq p
(plist-put p
:let-bind letbind
)))
743 (when style
(setq p
(plist-put p
:style-extra style
)))
745 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
747 (setq p
(plist-put p
:latex-class latex-class
)))
749 (setq p
(org-export-add-options-to-plist p options
)))
750 ;; Add macro definitions
751 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
752 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
754 p
:macro-modification-time
755 (and (buffer-file-name)
756 (file-exists-p (buffer-file-name))
758 "(eval (format-time-string \"$1\" '"
759 (prin1-to-string (nth 5 (file-attributes
760 (buffer-file-name))))
762 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
763 (file-name-nondirectory
764 (buffer-file-name)))))
765 (while (setq val
(pop macros
))
766 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
769 (concat ":macro-" (downcase (match-string 1 val
))))
770 (org-export-interpolate-newlines (match-string 2 val
))))))
773 (defun org-export-interpolate-newlines (s)
774 (while (string-match "\\\\n" s
)
775 (setq s
(replace-match "\n" t t s
)))
778 (defvar org-export-allow-BIND-local nil
)
779 (defun org-export-confirm-letbind ()
780 "Can we use #+BIND values during export?
781 By default this will ask fro confirmation by the user, to divert possible
784 ((not org-export-allow-BIND
) nil
)
785 ((eq org-export-allow-BIND t
) t
)
786 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
787 org-export-allow-BIND-local
)
788 (t (org-set-local 'org-export-allow-BIND-local
789 (yes-or-no-p "Allow BIND values in this buffer? ")))))
791 (defun org-install-letbind ()
792 "Install the values from #+BIND lines as local variables."
793 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
795 (while (setq pair
(pop letbind
))
796 (org-set-local (car pair
) (nth 1 pair
)))))
798 (defun org-export-add-options-to-plist (p options
)
799 "Parse an OPTIONS line and set values in the property list P."
802 (let ((op org-export-plist-vars
))
803 (while (setq o
(pop op
))
805 (string-match (concat (regexp-quote (nth 1 o
))
806 ":\\([^ \t\n\r;,.]*\\)")
808 (setq p
(plist-put p
(car o
)
809 (car (read-from-string
810 (match-string 1 options
))))))))))
813 (defun org-export-add-subtree-options (p pos
)
814 "Add options in subtree at position POS to property list P."
817 (when (org-at-heading-p)
819 ;; This is actually read in `org-export-get-title-from-subtree'
820 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
821 ;; (setq p (plist-put p :title a)))
822 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
823 (setq p
(plist-put p
:text a
)))
824 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
825 (setq p
(plist-put p
:author a
)))
826 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
827 (setq p
(plist-put p
:date a
)))
828 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
829 (setq p
(org-export-add-options-to-plist p a
)))))
832 (defun org-export-directory (type plist
)
833 (let* ((val (plist-get plist
:publishing-directory
))
835 (or (cdr (assoc type val
)) ".")
839 (defun org-export-process-option-filters (plist)
840 (let ((functions org-export-options-filters
) f
)
841 (while (setq f
(pop functions
))
842 (setq plist
(funcall f plist
))))
846 (defun org-export (&optional arg
)
847 "Export dispatcher for Org-mode.
848 When `org-export-run-in-background' is non-nil, try to run the command
849 in the background. This will be done only for commands that write
850 to a file. For details see the docstring of `org-export-run-in-background'.
852 The prefix argument ARG will be passed to the exporter. However, if
853 ARG is a double universal prefix `C-u C-u', that means to inverse the
854 value of `org-export-run-in-background'."
856 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
858 (help "[t] insert the export option template
859 \[v] limit export to visible part of outline tree
860 \[1] only export the current subtree
861 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
863 \[a] export as ASCII [A] to temporary buffer
865 \[h] export as HTML [H] to temporary buffer [R] export region
866 \[b] export as HTML and open in browser
868 \[l] export as LaTeX [L] to temporary buffer
869 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
871 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
873 \[m] export as Freemind mind map
875 \[g] export using Wes Hardaker's generic exporter
877 \[i] export current file as iCalendar file
878 \[I] export all agenda files as iCalendar files [c] ...as one combined file
880 \[F] publish current file [P] publish current project
881 \[X] publish a project... [E] publish every projects")
883 '((?t org-insert-export-options-template nil
)
884 (?v org-export-visible nil
)
885 (?a org-export-as-ascii t
)
886 (?A org-export-as-ascii-to-buffer t
)
887 (?h org-export-as-html t
)
888 (?b org-export-as-html-and-open t
)
889 (?H org-export-as-html-to-buffer nil
)
890 (?R org-export-region-as-html nil
)
891 (?x org-export-as-xoxo t
)
892 (?g org-export-generic t
)
893 (?D org-export-as-docbook t
)
894 (?V org-export-as-docbook-pdf-and-open t
)
895 (?m org-export-as-freemind t
)
896 (?l org-export-as-latex t
)
897 (?p org-export-as-pdf t
)
898 (?d org-export-as-pdf-and-open t
)
899 (?L org-export-as-latex-to-buffer nil
)
900 (?i org-export-icalendar-this-file t
)
901 (?I org-export-icalendar-all-agenda-files t
)
902 (?c org-export-icalendar-combine-agenda-files t
)
903 (?F org-publish-current-file t
)
904 (?P org-publish-current-project t
)
906 (?E org-publish-all t
)))
908 (cpos (point)) (cbuf (current-buffer)) bpos
)
910 (save-window-excursion
911 (delete-other-windows)
912 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
914 (org-fit-window-to-buffer (get-buffer-window
915 "*Org Export/Publishing Help*"))
916 (message "Select command: ")
917 (setq r1
(read-char-exclusive))
920 (message "Select command (for subtree): ")
921 (setq r1
(read-char-exclusive)))
923 (let ((case-fold-search t
))
924 (if (re-search-backward
925 "^[ \t]+\\(:latex_class:\\|:export_title:\\)[ \t]+\\S-"
928 (org-back-to-heading t
)
931 (message "Select command (for subtree): ")
932 (setq r1
(read-char-exclusive)))
933 (error "No enclosing node with LaTeX_CLASS or EXPORT_FILE_NAME")
935 (and bpos
(goto-char bpos
))
936 (setq r2
(if (< r1
27) (+ r1
96) r1
))
937 (unless (setq ass
(assq r2 cmds
))
938 (error "No command associated with key %c" r1
))
939 (if (and bg
(nth 2 ass
)
940 (not (buffer-base-buffer))
941 (not (org-region-active-p)))
942 ;; execute in background
943 (let ((p (start-process
944 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
946 (expand-file-name invocation-name invocation-directory
)
949 "--eval" "(require 'org-exp)"
950 "--eval" "(setq org-wait .2)"
952 "-f" (symbol-name (nth 1 ass
)))))
953 (set-process-sentinel p
'org-export-process-sentinel
)
954 (message "Background process \"%s\": started" p
))
955 ;; background processing not requested, or not possible
956 (if subtree-p
(progn (outline-mark-subtree) (activate-mark)))
957 (call-interactively (nth 1 ass
))
958 (when (and bpos
(get-buffer-window cbuf
))
959 (let ((cw (selected-window)))
960 (select-window (get-buffer-window cbuf
))
963 (select-window cw
))))))
965 (defun org-export-process-sentinel (process status
)
966 (if (string-match "\n+\\'" status
)
967 (setq status
(substring status
0 -
1)))
968 (message "Background process \"%s\": %s" process status
))
970 (defconst org-html-entities
1012 ("Aring") ("AA".
"Å")
1047 ("checkmark" .
"✓")
1102 ("varepsilon".
"ε")
1115 ("sigmaf") ("varsigma".
"ς")
1123 ("thetasym") ("vartheta".
"ϑ")
1126 ("bull") ("bullet".
"•")
1127 ("hellip") ("dots".
"…")
1137 ("larr") ("leftarrow".
"←") ("gets".
"←")
1138 ("uarr") ("uparrow".
"↑")
1139 ("rarr") ("to".
"→") ("rightarrow".
"→")
1140 ("darr")("downarrow".
"↓")
1141 ("harr") ("leftrightarrow".
"↔")
1142 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1143 ("lArr") ("Leftarrow".
"⇐")
1144 ("uArr") ("Uparrow".
"⇑")
1145 ("rArr") ("Rightarrow".
"⇒")
1146 ("dArr") ("Downarrow".
"⇓")
1147 ("hArr") ("Leftrightarrow".
"⇔")
1149 ("part") ("partial".
"∂")
1150 ("exist") ("exists".
"∃")
1151 ("empty") ("emptyset".
"∅")
1153 ("isin") ("in".
"∈")
1159 ("lowast") ("ast".
"∗")
1161 ("prop") ("proptp".
"∝")
1162 ("infin") ("infty".
"∞")
1163 ("ang") ("angle".
"∠")
1164 ("and") ("wedge".
"∧")
1165 ("or") ("vee".
"∨")
1171 ("cong") ("simeq".
"≅")
1172 ("asymp")("approx".
"≈")
1173 ("ne") ("neq".
"≠")
1177 ("sub") ("subset".
"⊂")
1178 ("sup") ("supset".
"⊃")
1185 ("sdot") ("cdot".
"⋅")
1192 ("loz") ("Diamond".
"◊")
1193 ("spades") ("spadesuit".
"♠")
1194 ("clubs") ("clubsuit".
"♣")
1196 ("diams") ("diamondsuit".
"♦")
1197 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1268 "Entities for TeX->HTML translation.
1269 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1270 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1271 In that case, \"\\ent\" will be translated to \"&other;\".
1272 The list contains HTML entities for Latin-1, Greek and other symbols.
1273 It is supplemented by a number of commonly used TeX macros with appropriate
1274 translations. There is currently no way for users to extend this.")
1276 ;;; General functions for all backends
1278 (defvar org-export-target-aliases nil
1279 "Alist of targets with invisible aliases.")
1280 (defvar org-export-preferred-target-alist nil
1281 "Alist of section id's with preferred aliases.")
1282 (defvar org-export-code-refs nil
1283 "Alist of code references and line numbers")
1285 (defun org-export-preprocess-string (string &rest parameters
)
1286 "Cleanup STRING so that that the true exported has a more consistent source.
1287 This function takes STRING, which should be a buffer-string of an org-file
1288 to export. It then creates a temporary buffer where it does its job.
1289 The result is then again returned as a string, and the exporter works
1290 on this string to produce the exported version."
1292 (let* ((htmlp (plist-get parameters
:for-html
))
1293 (asciip (plist-get parameters
:for-ascii
))
1294 (latexp (plist-get parameters
:for-LaTeX
))
1295 (docbookp (plist-get parameters
:for-docbook
))
1296 (backend (cond (htmlp 'html
)
1299 (docbookp 'docbook
)))
1300 (archived-trees (plist-get parameters
:archived-trees
))
1301 (inhibit-read-only t
)
1302 (drawers org-drawers
)
1303 (outline-regexp "\\*+ ")
1306 (setq org-export-target-aliases nil
)
1307 (setq org-export-preferred-target-alist nil
)
1308 (setq org-export-code-refs nil
)
1310 (with-current-buffer (get-buffer-create " org-mode-tmp")
1313 (setq case-fold-search t
)
1315 (let ((inhibit-read-only t
))
1316 (remove-text-properties (point-min) (point-max)
1319 ;; Remove license-to-kill stuff
1320 ;; The caller marks some stuff for killing, stuff that has been
1321 ;; used to create the page title, for example.
1322 (org-export-kill-licensed-text)
1324 (let ((org-inhibit-startup t
)) (org-mode))
1325 (setq case-fold-search t
)
1326 (org-install-letbind)
1329 (run-hooks 'org-export-preprocess-hook
)
1331 ;; Process the macros
1332 (org-export-preprocess-apply-macros)
1333 (run-hooks 'org-export-preprocess-after-macros-hook
)
1335 (untabify (point-min) (point-max))
1337 ;; Handle include files, and call a hook
1338 (org-export-handle-include-files)
1339 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1341 ;; Get rid of archived trees
1342 (org-export-remove-archived-trees archived-trees
)
1344 ;; Remove comment environment and comment subtrees
1345 (org-export-remove-comment-blocks-and-subtrees)
1347 ;; Get rid of excluded trees, and call a hook
1348 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1349 (plist-get parameters
:exclude-tags
))
1350 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1352 ;; Handle source code snippets
1353 (org-export-replace-src-segments-and-examples backend
)
1355 ;; Protect short examples marked by a leading colon
1356 (org-export-protect-colon-examples)
1358 ;; Normalize footnotes
1359 (when (plist-get parameters
:footnotes
)
1360 (org-footnote-normalize nil t
))
1362 ;; Find all headings and compute the targets for them
1363 (setq target-alist
(org-export-define-heading-targets target-alist
))
1365 ;; Find HTML special classes for headlines
1366 (org-export-remember-html-container-classes)
1368 ;; Get rid of drawers
1369 (org-export-remove-or-extract-drawers
1370 drawers
(plist-get parameters
:drawers
) backend
)
1372 ;; Get the correct stuff before the first headline
1373 (when (plist-get parameters
:skip-before-1st-heading
)
1374 (goto-char (point-min))
1375 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1376 (delete-region (point-min) (match-beginning 0))
1377 (goto-char (point-min))
1379 (when (plist-get parameters
:add-text
)
1380 (goto-char (point-min))
1381 (insert (plist-get parameters
:add-text
) "\n"))
1383 ;; Remove todo-keywords before exporting, if the user has requested so
1384 (org-export-remove-headline-metadata parameters
)
1386 ;; Find targets in comments and move them out of comments,
1387 ;; but mark them as targets that should be invisible
1388 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1390 ;; Select and protect backend specific stuff, throw away stuff
1391 ;; that is specific for other backends
1392 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1393 (org-export-select-backend-specific-text backend
)
1395 ;; Protect quoted subtrees
1396 (org-export-protect-quoted-subtrees)
1398 ;; Remove clock lines
1399 (org-export-remove-clock-lines)
1401 ;; Protect verbatim elements
1402 (org-export-protect-verbatim)
1404 ;; Blockquotes, verse, and center
1405 (org-export-mark-blockquote-verse-center)
1406 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1408 ;; Remove timestamps, if the user has requested so
1409 (unless (plist-get parameters
:timestamps
)
1410 (org-export-remove-timestamps))
1412 ;; Attach captions to the correct object
1413 (setq target-alist
(org-export-attach-captions-and-attributes
1414 backend target-alist
))
1416 ;; Find matches for radio targets and turn them into internal links
1417 (org-export-mark-radio-links)
1419 ;; Find all links that contain a newline and put them into a single line
1420 (org-export-concatenate-multiline-links)
1422 ;; Normalize links: Convert angle and plain links into bracket links
1423 ;; and expand link abbreviations
1424 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1425 (org-export-normalize-links)
1427 ;; Find all internal links. If they have a fuzzy match (i.e. not
1428 ;; a *dedicated* target match, let the link point to the
1429 ;; corresponding section.
1430 (org-export-target-internal-links target-alist
)
1432 ;; Find multiline emphasis and put them into single line
1433 (when (plist-get parameters
:emph-multiline
)
1434 (org-export-concatenate-multiline-emphasis))
1436 ;; Remove special table lines
1437 (when org-export-table-remove-special-lines
1438 (org-export-remove-special-table-lines))
1441 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1443 ;; LaTeX-specific preprocessing
1445 (require 'org-latex nil
)
1446 (org-export-latex-preprocess parameters
))
1448 ;; ASCII-specific preprocessing
1450 (org-export-ascii-preprocess parameters
))
1452 ;; HTML-specific preprocessing
1454 (org-export-html-preprocess parameters
))
1456 ;; DocBook-specific preprocessing
1458 (require 'org-docbook nil
)
1459 (org-export-docbook-preprocess parameters
))
1461 ;; Remove or replace comments
1462 (org-export-handle-comments (plist-get parameters
:comments
))
1464 ;; Run the final hook
1465 (run-hooks 'org-export-preprocess-final-hook
)
1467 (setq rtn
(buffer-string)))
1468 (kill-buffer " org-mode-tmp")
1471 (defun org-export-kill-licensed-text ()
1472 "Remove all text that is marked with a :org-license-to-kill property."
1474 (while (setq p
(text-property-any (point-min) (point-max)
1475 :org-license-to-kill t
))
1477 p
(or (next-single-property-change p
:org-license-to-kill
)
1480 (defun org-export-define-heading-targets (target-alist)
1481 "Find all headings and define the targets for them.
1482 The new targets are added to TARGET-ALIST, which is also returned."
1483 (goto-char (point-min))
1484 (org-init-section-numbers)
1485 (let ((re (concat "^" org-outline-regexp
1486 "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1487 level target last-section-target a id
)
1488 (while (re-search-forward re nil t
)
1491 (setq id
(org-match-string-no-properties 2))
1492 (push (cons id target
) target-alist
)
1493 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1495 (push (list last-section-target
)
1496 org-export-target-aliases
)
1497 (car org-export-target-aliases
))))
1498 (push (caar target-alist
) (cdr a
))
1499 (when (equal (match-string 1) "CUSTOM_ID")
1500 (if (not (assoc last-section-target
1501 org-export-preferred-target-alist
))
1502 (push (cons last-section-target id
)
1503 org-export-preferred-target-alist
))))
1504 (setq level
(org-reduced-level
1505 (save-excursion (goto-char (point-at-bol))
1506 (org-outline-level))))
1507 (setq target
(org-solidify-link-text
1508 (format "sec-%s" (org-section-number level
))))
1509 (setq last-section-target target
)
1510 (push (cons target target
) target-alist
)
1511 (add-text-properties
1512 (point-at-bol) (point-at-eol)
1513 (list 'target target
)))))
1516 (defun org-export-handle-invisible-targets (target-alist)
1517 "Find targets in comments and move them out of comments.
1518 Mark them as invisible targets."
1520 (goto-char (point-min))
1521 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1522 ;; Check if the line before or after is a headline with a target
1523 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1524 (get-text-property (point-at-bol 2) 'target
)))
1526 ;; use the existing target in a neighboring line
1527 (setq tmp
(match-string 2))
1529 (and (looking-at "\n") (delete-char 1))
1530 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1532 (setq a
(or (assoc target org-export-target-aliases
)
1534 (push (list target
) org-export-target-aliases
)
1535 (car org-export-target-aliases
))))
1537 ;; Make an invisible target
1538 (replace-match "\\1(INVISIBLE)"))))
1541 (defun org-export-target-internal-links (target-alist)
1542 "Find all internal links and assign targets to them.
1543 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1544 let the link point to the corresponding section.
1545 This function also handles the id links, if they have a match in
1547 (goto-char (point-min))
1548 (while (re-search-forward org-bracket-link-regexp nil t
)
1549 (org-if-unprotected-at (1+ (match-beginning 0))
1550 (let* ((md (match-data))
1551 (desc (match-end 2))
1552 (link (org-link-unescape (match-string 1)))
1553 (slink (org-solidify-link-text link
))
1554 found props pos cref
1557 ((= (string-to-char link
) ?
#)
1558 ;; user wants exactly this link
1560 ((cdr (assoc slink target-alist
))
1561 (or (cdr (assoc (assoc slink target-alist
)
1562 org-export-preferred-target-alist
))
1563 (cdr (assoc slink target-alist
))))
1564 ((and (string-match "^id:" link
)
1565 (cdr (assoc (substring link
3) target-alist
))))
1566 ((string-match "^(\\(.*\\))$" link
)
1567 (setq cref
(match-string 1 link
))
1568 (concat "coderef:" cref
))
1569 ((string-match org-link-types-re link
) nil
)
1570 ((or (file-name-absolute-p link
)
1571 (string-match "^\\." link
))
1575 (setq found
(condition-case nil
(org-link-search link
)
1578 (or (org-on-heading-p)
1579 (not (eq found
'dedicated
))))
1580 (or (get-text-property (point) 'target
)
1583 (1- (or (previous-single-property-change
1584 (point) 'target
) 0)))
1588 (goto-char (match-beginning 1))
1589 (setq props
(text-properties-at (point)))
1590 (delete-region (match-beginning 1) (match-end 1))
1593 (unless desc
(insert "][" link
))
1594 (add-text-properties pos
(point) props
))))))
1596 (defun org-export-remember-html-container-classes ()
1597 "Store the HTML_CONTAINER_CLASS properties in a text property."
1598 (goto-char (point-min))
1600 (while (re-search-forward
1601 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(\\S-+\\)" nil t
)
1602 (setq class
(match-string 1))
1604 (org-back-to-heading t
)
1605 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1607 (defvar org-export-format-drawer-function nil
1608 "Function to be called to format the contents of a drawer.
1609 The function must accept three parameters:
1610 BACKEND one of the symbols html, docbook, latex, ascii, xoxo
1611 NAME the drawer name, like \"PROPERTIES\"
1612 CONTENT the content of the drawer.
1613 The function should return the text to be inserted into the buffer.
1614 If this is nil, `org-export-format-drawer' is used as a default.")
1616 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend
)
1617 "Remove drawers, or extract and format the content.
1618 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1619 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1620 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1621 EXP-DRAWERS will be removed.
1622 BACKEND is the current export backend."
1623 (goto-char (point-min))
1624 (let ((re (concat "^[ \t]*:\\("
1625 (mapconcat 'identity all-drawers
"\\|")
1627 name beg beg-content eol content
)
1628 (while (re-search-forward re nil t
)
1630 (setq name
(match-string 1))
1631 (setq beg
(match-beginning 0)
1632 beg-content
(1+ (point-at-eol))
1634 (if (not (and (re-search-forward
1635 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1638 (goto-char (match-beginning 0))
1639 (and (looking-at ".*\n?") (replace-match ""))
1640 (setq content
(buffer-substring beg-content
(point)))
1641 (delete-region beg
(point))
1642 (when (or (eq exp-drawers t
)
1643 (member name exp-drawers
))
1644 (setq content
(funcall (or org-export-format-drawer-function
1645 'org-export-format-drawer
)
1646 name content backend
))
1647 (insert content
)))))))
1649 (defun org-export-format-drawer (name content backend
)
1650 "Format the content of a drawer as a colon example."
1651 (if (string-match "[ \t]+\\'" content
)
1652 (setq content
(substring content
(match-beginning 0))))
1653 (while (string-match "\\`[ \t]*\n" content
)
1654 (setq content
(substring content
(match-end 0))))
1655 (setq content
(org-remove-indentation content
))
1656 (setq content
(concat ": " (mapconcat 'identity
1657 (org-split-string content
"\n")
1660 (setq content
(concat " : " (upcase name
) "\n" content
))
1661 (org-add-props content nil
'org-protected t
))
1663 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1664 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1665 Both arguments are lists of tags.
1666 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1668 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1670 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1671 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1674 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1678 (goto-char (point-min))
1679 (when (and select-tags
1681 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1682 ;; At least one tree is marked for export, this means
1683 ;; all the unmarked stuff needs to go.
1684 ;; Dig out the trees that should be exported
1685 (goto-char (point-min))
1686 (outline-next-heading)
1688 (put-text-property beg
(point-max) :org-delete t
)
1689 (while (re-search-forward re-sel nil t
)
1690 (when (org-on-heading-p)
1691 (org-back-to-heading)
1692 (remove-text-properties
1693 (max (1- (point)) (point-min))
1694 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1696 (while (and (org-up-heading-safe)
1697 (get-text-property (point) :org-delete
))
1698 (remove-text-properties (max (1- (point)) (point-min))
1699 (point-at-eol) '(:org-delete t
)))
1701 ;; Remove the trees explicitly marked for noexport
1703 (goto-char (point-min))
1704 (while (re-search-forward re-excl nil t
)
1705 (when (org-at-heading-p)
1706 (org-back-to-heading t
)
1708 (org-end-of-subtree t t
)
1709 (delete-region beg
(point))
1710 (when (featurep 'org-inlinetask
)
1711 (org-inlinetask-remove-END-maybe)))))
1712 ;; Remove everything that is now still marked for deletion
1713 (goto-char (point-min))
1714 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1715 (setq end
(or (next-single-property-change beg
:org-delete
)
1717 (delete-region beg end
))))
1719 (defun org-export-remove-archived-trees (export-archived-trees)
1720 "Remove archived trees.
1721 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1722 When it is t, the entire archived tree will be exported.
1723 When it is nil the entire tree including the headline will be removed
1725 (let ((re-archive (concat ":" org-archive-tag
":"))
1727 (when (not (eq export-archived-trees t
))
1728 (goto-char (point-min))
1729 (while (re-search-forward re-archive nil t
)
1730 (if (not (org-on-heading-p t
))
1731 (org-end-of-subtree t
)
1732 (beginning-of-line 1)
1733 (setq a
(if export-archived-trees
1734 (1+ (point-at-eol)) (point))
1735 b
(org-end-of-subtree t
))
1736 (if (> b a
) (delete-region a b
)))))))
1738 (defun org-export-remove-headline-metadata (opts)
1739 "Remove meta data from the headline, according to user options."
1740 (let ((re org-complex-heading-regexp
)
1741 (todo (plist-get opts
:todo-keywords
))
1742 (tags (plist-get opts
:tags
))
1743 (pri (plist-get opts
:priority
))
1746 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1747 (when (or (not todo
) (not tags
) (not pri
))
1748 (goto-char (point-min))
1749 (while (re-search-forward re nil t
)
1751 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1753 (replace-match rpl t t
))))))
1755 (defun org-export-remove-timestamps ()
1756 "Remove timestamps and keywords for export."
1757 (goto-char (point-min))
1758 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1761 (unless (save-match-data (org-at-table-p))
1763 (beginning-of-line 1)
1764 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1765 (replace-match ""))))))
1767 (defun org-export-remove-clock-lines ()
1768 "Remove clock lines for export."
1769 (goto-char (point-min))
1770 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1771 (while (re-search-forward re nil t
)
1773 (replace-match "")))))
1775 (defun org-export-protect-quoted-subtrees ()
1776 "Mark quoted subtrees with the protection property."
1777 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1778 (goto-char (point-min))
1779 (while (re-search-forward re-quote nil t
)
1780 (goto-char (match-beginning 0))
1782 (add-text-properties (point) (org-end-of-subtree t
)
1783 '(org-protected t
)))))
1785 (defun org-export-protect-verbatim ()
1786 "Mark verbatim snippets with the protection property."
1787 (goto-char (point-min))
1788 (while (re-search-forward org-verbatim-re nil t
)
1790 (add-text-properties (match-beginning 4) (match-end 4)
1791 '(org-protected t org-verbatim-emph t
))
1792 (goto-char (1+ (match-end 4))))))
1794 (defun org-export-protect-colon-examples ()
1795 "Protect lines starting with a colon."
1796 (goto-char (point-min))
1797 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1798 (while (re-search-forward re nil t
)
1799 (beginning-of-line 1)
1801 (while (looking-at re
)
1803 (or (eobp) (forward-char 1)))
1804 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1805 '(org-protected t
)))))
1807 (defun org-export-select-backend-specific-text (backend)
1809 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1810 (html "HTML" "BEGIN_HTML" "END_HTML")
1811 (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
1812 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1813 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1814 (case-fold-search t
)
1815 fmt beg beg-content end end-content
)
1818 (setq fmt
(pop formatters
))
1819 (when (eq (car fmt
) backend
)
1820 ;; This is selected code, put it into the file for real
1821 (goto-char (point-min))
1822 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt
)
1823 ":[ \t]*\\(.*\\)") nil t
)
1824 (replace-match "\\1\\2" t
)
1825 (add-text-properties
1826 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1827 '(org-protected t
))))
1828 (goto-char (point-min))
1829 (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt
) "\\>.*\n?")
1831 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1832 (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt
) "\\>.*\n?")
1834 (setq end
(match-end 0) end-content
(match-beginning 0))
1835 (if (eq (car fmt
) backend
)
1838 (add-text-properties beg-content end-content
'(org-protected t
))
1839 (delete-region (match-beginning 0) (match-end 0))
1842 (delete-region (point) (1+ (point-at-eol)))))
1843 ;; No, this is for a different backend, kill it
1844 (delete-region beg end
)))))))
1846 (defun org-export-mark-blockquote-verse-center ()
1847 "Mark block quote and verse environments with special cookies.
1848 These special cookies will later be interpreted by the backend."
1850 (let (type t1 ind beg end beg1 end1 content
)
1851 (goto-char (point-min))
1852 (while (re-search-forward
1853 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1855 (setq ind
(length (match-string 1))
1856 type
(downcase (match-string 3))
1857 t1
(if (equal type
"quote") "blockquote" type
))
1858 (setq beg
(match-beginning 0)
1859 beg1
(1+ (match-end 0)))
1860 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1861 (setq end
(1+ (point-at-eol))
1862 end1
(1- (match-beginning 0)))
1863 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1864 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1866 "ORG-" (upcase t1
) "-END\n"))
1867 (delete-region beg end
)
1868 (insert (org-add-props content nil
'original-indentation ind
))))))
1870 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1871 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1872 If the next thing following is a table, add the text properties to the first
1873 table line. If it is a link, add it to the line containing the link."
1874 (goto-char (point-min))
1875 (remove-text-properties (point-min) (point-max)
1876 '(org-caption nil org-attributes nil
))
1877 (let ((case-fold-search t
)
1878 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1880 "^[ \t]*#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1882 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1886 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1888 (while (re-search-forward re nil t
)
1891 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1893 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1895 (setq label
(org-trim (match-string 3))))
1897 (add-text-properties (point-at-bol) (point-at-eol)
1898 (list 'org-caption cap
1899 'org-attributes attr
1901 (if label
(push (cons label label
) target-alist
))
1902 (setq cap nil attr nil label nil
)))))
1905 (defun org-export-remove-comment-blocks-and-subtrees ()
1906 "Remove the comment environment, and also commented subtrees."
1907 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1909 ;; Remove comment environment
1910 (goto-char (point-min))
1911 (setq case-fold-search t
)
1912 (while (re-search-forward
1913 "^#\\+begin_comment[ \t]*\n[^\000]*?^#\\+end_comment\\>.*" nil t
)
1914 (replace-match "" t t
))
1915 ;; Remove subtrees that are commented
1916 (goto-char (point-min))
1917 (setq case-fold-search nil
)
1918 (while (re-search-forward re-commented nil t
)
1919 (goto-char (match-beginning 0))
1920 (delete-region (point) (org-end-of-subtree t
)))))
1922 (defun org-export-handle-comments (commentsp)
1923 "Remove comments, or convert to backend-specific format.
1924 COMMENTSP can be a format string for publishing comments.
1925 When it is nil, all comments will be removed."
1926 (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
1928 (goto-char (point-min))
1929 (while (or (looking-at re
)
1930 (re-search-forward re nil t
))
1931 (setq pos
(match-beginning 0))
1933 (not (equal (char-before (match-end 1)) ?
+)))
1934 (progn (add-text-properties
1935 (match-beginning 0) (match-end 0) '(org-protected t
))
1936 (replace-match (format commentsp
(match-string 2)) t t
))
1937 (goto-char (1+ pos
))
1940 (goto-char (max (point-min) (1- pos
))))))))
1942 (defun org-export-mark-radio-links ()
1943 "Find all matches for radio targets and turn them into internal links."
1944 (let ((re-radio (and org-target-link-regexp
1945 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1946 (goto-char (point-min))
1948 (while (re-search-forward re-radio nil t
)
1951 (or (org-in-regexp org-bracket-link-regexp
)
1952 (org-in-regexp org-plain-link-re
)
1953 (org-in-regexp "<<[^<>]+>>")))
1955 (replace-match "\\1[[\\2]]")))))))
1957 (defun org-export-remove-special-table-lines ()
1958 "Remove tables lines that are used for internal purposes."
1959 (goto-char (point-min))
1960 (while (re-search-forward "^[ \t]*|" nil t
)
1961 (beginning-of-line 1)
1962 (if (or (looking-at "[ \t]*| *[!_^] *|")
1968 (or (= (length f
) 0)
1970 "\\`<\\([0-9]\\|[rl]\\|[rl][0-9]+\\)>\\'" f
)))
1971 (org-split-string ;; FIXME, can't we do this without splitting???
1972 (buffer-substring (point-at-bol) (point-at-eol))
1973 "[ \t]*|[ \t]*")))))
1974 (delete-region (max (point-min) (1- (point-at-bol)))
1978 (defun org-export-protect-sub-super (s)
1980 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
1981 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
1984 (defun org-export-normalize-links ()
1985 "Convert all links to bracket links, and expand link abbreviations."
1986 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1987 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1989 (goto-char (point-min))
1990 (while (re-search-forward re-plain-link nil t
)
1991 (goto-char (1- (match-end 0)))
1992 (org-if-unprotected-at (1+ (match-beginning 0))
1993 (let* ((s (concat (match-string 1)
1994 "[[" (match-string 2) ":" (match-string 3)
1995 "][" (match-string 2) ":" (org-export-protect-sub-super
1998 ;; added 'org-link face to links
1999 (put-text-property 0 (length s
) 'face
'org-link s
)
2000 (replace-match s t t
))))
2001 (goto-char (point-min))
2002 (while (re-search-forward re-angle-link nil t
)
2003 (goto-char (1- (match-end 0)))
2005 (let* ((s (concat (match-string 1)
2006 "[[" (match-string 2) ":" (match-string 3)
2007 "][" (match-string 2) ":" (org-export-protect-sub-super
2010 (put-text-property 0 (length s
) 'face
'org-link s
)
2011 (replace-match s t t
))))
2012 (goto-char (point-min))
2013 (while (re-search-forward org-bracket-link-regexp nil t
)
2014 (goto-char (1- (match-end 0)))
2015 (setq nodesc
(not (match-end 3)))
2017 (let* ((xx (save-match-data
2019 (org-link-expand-abbrev (match-string 1)))))
2021 "[[" (org-add-props (copy-sequence xx
)
2022 nil
'org-protected t
'org-no-description nodesc
)
2026 (concat "[" (copy-sequence xx
)
2029 (put-text-property 0 (length s
) 'face
'org-link s
)
2030 (replace-match s t t
))))))
2032 (defun org-export-concatenate-multiline-links ()
2033 "Find multi-line links and put it all into a single line.
2034 This is to make sure that the line-processing export backends
2035 can work correctly."
2036 (goto-char (point-min))
2037 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2038 (org-if-unprotected-at (match-beginning 1)
2039 (replace-match "\\1 \\3")
2040 (goto-char (match-beginning 0)))))
2042 (defun org-export-concatenate-multiline-emphasis ()
2043 "Find multi-line emphasis and put it all into a single line.
2044 This is to make sure that the line-processing export backends
2045 can work correctly."
2046 (goto-char (point-min))
2047 (while (re-search-forward org-emph-re nil t
)
2048 (if (and (not (= (char-after (match-beginning 3))
2049 (char-after (match-beginning 4))))
2050 (save-excursion (goto-char (match-beginning 0))
2051 (save-match-data (not (org-at-table-p)))))
2053 (subst-char-in-region (match-beginning 0) (match-end 0)
2055 (goto-char (1- (match-end 0))))
2056 (goto-char (1+ (match-beginning 0))))))
2058 (defun org-export-grab-title-from-buffer ()
2059 "Get a title for the current document, from looking at the buffer."
2060 (let ((inhibit-read-only t
))
2062 (goto-char (point-min))
2063 (let ((end (if (looking-at org-outline-regexp
)
2065 (save-excursion (outline-next-heading) (point)))))
2066 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2067 ;; Mark the line so that it will not be exported as normal text.
2069 (add-text-properties (match-beginning 0) (match-end 0)
2070 (list :org-license-to-kill t
)))
2071 ;; Return the title string
2072 (org-trim (match-string 0)))))))
2074 (defun org-export-get-title-from-subtree ()
2075 "Return subtree title and exclude it from export."
2076 (let (title (rbeg (region-beginning)) (rend (region-end)))
2079 (when (and (org-at-heading-p)
2080 (>= (org-end-of-subtree t t
) rend
))
2081 ;; This is a subtree, we take the title from the first heading
2083 (looking-at org-todo-line-regexp
)
2084 (setq title
(match-string 3))
2086 (add-text-properties (point) (1+ (point-at-eol))
2087 (list :org-license-to-kill t
)))
2088 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2091 (defun org-solidify-link-text (s &optional alist
)
2092 "Take link text and make a safe target out of it."
2097 (org-split-string s
"[ \t\r\n]+") "=="))
2098 (a (assoc rtn alist
)))
2101 (defun org-get-min-level (lines &optional offset
)
2102 "Get the minimum level in LINES."
2103 (let ((re "^\\(\\*+\\) ") l
)
2105 (while (setq l
(pop lines
))
2106 (if (string-match re l
)
2107 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2111 ;; Variable holding the vector with section numbers
2112 (defvar org-section-numbers
(make-vector org-level-max
0))
2114 (defun org-init-section-numbers ()
2115 "Initialize the vector for the section numbers."
2117 (numbers (nreverse (org-split-string "" "\\.")))
2118 (depth (1- (length org-section-numbers
)))
2119 (i depth
) number-string
)
2122 (aset org-section-numbers i
0)
2123 (setq number-string
(or (car numbers
) "0"))
2124 (if (string-match "\\`[A-Z]\\'" number-string
)
2125 (aset org-section-numbers i
2126 (- (string-to-char number-string
) ?A -
1))
2127 (aset org-section-numbers i
(string-to-number number-string
)))
2131 (defun org-section-number (&optional level
)
2132 "Return a string with the current section number.
2133 When LEVEL is non-nil, increase section numbers on that level."
2134 (let* ((depth (1- (length org-section-numbers
)))
2136 (fmts (car org-export-section-number-format
))
2137 (term (cdr org-export-section-number-format
))
2142 (aset org-section-numbers
2143 level
(1+ (aref org-section-numbers level
))))
2144 (setq idx
(1+ level
))
2145 (while (<= idx depth
)
2147 (aset org-section-numbers idx
0))
2148 (setq idx
(1+ idx
))))
2150 (while (<= idx depth
)
2151 (when (> (aref org-section-numbers idx
) 0)
2152 (setq fmt
(or (pop fmts
) fmt
)
2154 n
(aref org-section-numbers idx
)
2156 (concat string sep
(org-number-to-counter n ctype
))
2157 (concat string
".0"))
2159 (setq idx
(1+ idx
)))
2161 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2162 (setq string
(replace-match "" t nil string
)))
2163 (if (string-match "\\(\\.0\\)+\\'" string
)
2164 (setq string
(replace-match "" t nil string
))))
2165 (concat string term
)))
2167 (defun org-number-to-counter (n type
)
2168 "Concert number N to a string counter, according to TYPE.
2169 TYPE must be a string, any of:
2173 I upper case roman numeral
2174 i lower case roman numeral"
2176 ((equal type
"1") (number-to-string n
))
2177 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2178 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2179 ((equal type
"I") (org-number-to-roman n
))
2180 ((equal type
"i") (downcase (org-number-to-roman n
)))
2181 (t (error "Invalid counter type `%s'" type
))))
2183 (defun org-number-to-roman (n)
2184 "Convert integer N into a roman numeral."
2185 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2186 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2187 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2191 (number-to-string n
)
2193 (if (>= n
(caar roman
))
2194 (setq n
(- n
(caar roman
))
2195 res
(concat res
(cdar roman
)))
2201 (defun org-export-preprocess-apply-macros ()
2202 "Replace macro references."
2203 (goto-char (point-min))
2204 (let (sy val key args args2 s n
)
2205 (while (re-search-forward
2206 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2208 (unless (save-match-data
2210 (goto-char (point-at-bol))
2211 (looking-at "[ \t]*#\\+macro")))
2212 (setq key
(downcase (match-string 1))
2213 args
(match-string 3))
2214 (when (setq val
(or (plist-get org-export-opt-plist
2215 (intern (concat ":macro-" key
)))
2216 (plist-get org-export-opt-plist
2217 (intern (concat ":" key
)))))
2220 (setq args
(org-split-string args
",[ \t\n]*") args2 nil
)
2221 (setq args
(mapcar 'org-trim args
))
2223 (while (string-match "\\\\\\'" (car args
))
2224 ;; repair bad splits
2225 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2228 (push (pop args
) args2
))
2229 (setq args
(nreverse args2
))
2231 (while (string-match "\\$\\([0-9]+\\)" val s
)
2232 (setq s
(1+ (match-beginning 0))
2233 n
(string-to-number (match-string 1 val
)))
2234 (and (>= (length args
) n
)
2235 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2236 (when (string-match "\\`(eval\\>" val
)
2237 (setq val
(eval (read val
))))
2238 (if (and val
(not (stringp val
)))
2239 (setq val
(format "%s" val
))))
2241 (prog1 (replace-match val t t
)
2242 (goto-char (match-beginning 0)))))))))
2244 (defun org-export-apply-macros-in-string (s)
2245 "Apply the macros in string S."
2249 (org-export-preprocess-apply-macros)
2254 (defun org-export-handle-include-files ()
2255 "Include the contents of include files, with proper formatting."
2256 (let ((case-fold-search t
)
2257 params file markup lang start end prefix prefix1 switches
)
2258 (goto-char (point-min))
2259 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2260 (setq params
(read (concat "(" (match-string 1) ")"))
2261 prefix
(org-get-and-remove-property 'params
:prefix
)
2262 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2263 file
(org-symname-or-string (pop params
))
2264 markup
(org-symname-or-string (pop params
))
2265 lang
(and (member markup
'("src" "SRC"))
2266 (org-symname-or-string (pop params
)))
2267 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" ")
2269 (delete-region (match-beginning 0) (match-end 0))
2271 (not (file-exists-p file
))
2272 (not (file-readable-p file
)))
2273 (insert (format "CANNOT INCLUDE FILE %s" file
))
2275 (if (equal (downcase markup
) "src")
2276 (setq start
(format "#+begin_src %s %s\n"
2277 (or lang
"fundamental")
2280 (setq start
(format "#+begin_%s %s\n" markup switches
)
2281 end
(format "#+end_%s" markup
))))
2282 (insert (or start
""))
2283 (insert (org-get-file-contents (expand-file-name file
)
2284 prefix prefix1 markup
))
2285 (or (bolp) (newline))
2286 (insert (or end
""))))))
2288 (defun org-get-file-contents (file &optional prefix prefix1 markup
)
2289 "Get the contents of FILE and return them as a string.
2290 If PREFIX is a string, prepend it to each line. If PREFIX1
2291 is a string, prepend it to the first line instead of PREFIX.
2292 If MARKUP, don't protect org-like lines, the exporter will
2293 take care of the block they are in."
2294 (if (stringp markup
) (setq markup
(downcase markup
)))
2296 (insert-file-contents file
)
2297 (when (or prefix prefix1
)
2298 (goto-char (point-min))
2300 (insert (or prefix1 prefix
))
2302 (beginning-of-line 2)))
2304 (when (member markup
'("src" "example"))
2305 (goto-char (point-min))
2306 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2307 (goto-char (match-beginning 0))
2312 (defun org-get-and-remove-property (listvar prop
)
2313 "Check if the value of LISTVAR contains PROP as a property.
2314 If yes, return the value of that property (i.e. the element following
2315 in the list) and remove property and value from the list in LISTVAR."
2316 (let ((list (symbol-value listvar
)) m v
)
2317 (when (setq m
(member prop list
))
2319 (if (equal (car list
) prop
)
2320 (set listvar
(cddr list
))
2321 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2323 (set listvar list
)))
2326 (defun org-symname-or-string (s)
2328 (if s
(symbol-name s
) s
)
2331 ;;; Fontification and line numbers for code examples
2333 (defvar org-export-last-code-line-counter-value
0)
2335 (defun org-export-replace-src-segments-and-examples (backend)
2336 "Replace source code segments with special code for export."
2337 (setq org-export-last-code-line-counter-value
0)
2338 (let ((case-fold-search t
)
2339 lang code trans opts indent caption
)
2340 (goto-char (point-min))
2341 (while (re-search-forward
2342 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2346 (setq lang
(match-string 3)
2347 opts
(match-string 4)
2348 code
(match-string 5)
2349 indent
(length (match-string 2))
2350 caption
(get-text-property 0 'org-caption
(match-string 0)))
2352 opts
(match-string 8)
2353 code
(match-string 9)
2354 indent
(length (match-string 7))
2355 caption
(get-text-property 0 'org-caption
(match-string 0))))
2357 (setq trans
(org-export-format-source-code-or-example
2358 backend lang code opts indent caption
))
2359 (replace-match trans t t
))))
2361 (defvar htmlp
) ;; dynamically scoped
2362 (defvar latexp
) ;; dynamically scoped
2363 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2364 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2365 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2367 (defun org-export-format-source-code-or-example
2368 (backend lang code
&optional opts indent caption
)
2369 "Format CODE from language LANG and return it formatted for export.
2370 If LANG is nil, do not add any fontification.
2371 OPTS contains formatting options, like `-n' for triggering numbering lines,
2372 and `+n' for continuing previous numbering.
2373 Code formatting according to language currently only works for HTML.
2374 Numbering lines works for all three major backends (html, latex, and ascii).
2375 INDENT was the original indentation of the block."
2377 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2378 (setq opts
(or opts
"")
2379 num
(string-match "[-+]n\\>" opts
)
2380 cont
(string-match "\\+n\\>" opts
)
2381 rpllbl
(string-match "-r\\>" opts
)
2382 keepp
(string-match "-k\\>" opts
)
2383 textareap
(string-match "-t\\>" opts
)
2384 preserve-indentp
(or org-src-preserve-indentation
2385 (string-match "-i\\>" opts
))
2386 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2387 (string-to-number (match-string 1 opts
))
2389 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2390 (string-to-number (match-string 1 opts
))
2391 (org-count-lines code
))
2392 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2393 (match-string 1 opts
)))
2394 (when (and textareap
(eq backend
'html
))
2395 ;; we cannot use numbering or highlighting.
2396 (setq num nil cont nil lang nil
))
2397 (if keepp
(setq rpllbl
'keep
))
2398 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2399 (when (string-match "^," rtn
)
2400 (setq rtn
(with-temp-buffer
2402 ;; Free up the protected lines
2403 (goto-char (point-min))
2404 (while (re-search-forward "^," nil t
)
2405 (if (or (equal lang
"org")
2407 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2411 ;; Now backend-specific coding
2414 ((eq backend
'docbook
)
2415 (setq rtn
(org-export-number-lines rtn
'docbook
0 0 num cont rpllbl fmt
))
2416 (concat "\n#+BEGIN_DOCBOOK\n"
2417 (org-add-props (concat "<programlisting><![CDATA["
2419 "]]>\n</programlisting>\n")
2423 ;; We are exporting to HTML
2425 (require 'htmlize nil t
)
2426 (when (not (fboundp 'htmlize-region-for-paste
))
2427 ;; we do not have htmlize.el, or an old version of it
2430 "htmlize.el 1.34 or later is needed for source code formatting")))
2433 (let* ((lang-m (when lang
2434 (or (cdr (assoc lang org-src-lang-modes
))
2436 (mode (and lang-m
(intern
2438 (if (symbolp lang-m
)
2439 (symbol-name lang-m
)
2442 (org-inhibit-startup t
)
2443 (org-startup-folded nil
))
2447 (if (functionp mode
)
2450 (font-lock-fontify-buffer)
2452 (set-buffer-modified-p nil
)
2453 (org-export-htmlize-region-for-paste
2454 (point-min) (point-max))))
2455 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2460 "<div class=\"org-src-container\">"
2462 "<label class=\"org-src-name\">%s</label>"
2466 (format "<pre class=\"src src-%s\">\n" lang
)
2468 (if caption
"</div>" "")))))
2471 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2473 rtn
"</textarea>\n</p>\n"))
2476 (goto-char (point-min))
2477 (while (re-search-forward "[<>&]" nil t
)
2478 (replace-match (cdr (assq (char-before)
2479 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2481 (setq rtn
(buffer-string)))
2482 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2484 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2486 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2487 (setq rtn
(replace-match "\\1" t nil rtn
)))
2488 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2489 ((eq backend
'latex
)
2490 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2491 (concat "#+BEGIN_LaTeX\n"
2493 (if org-export-latex-listings
2497 ((lang-sym (intern lang
))
2502 org-export-latex-listings-langs
))
2504 (format "\\lstset{language=%s}\n" lstlang
))
2507 (format "\n%s $\\equiv$ \n" caption
))
2508 "\\begin{lstlisting}\n"
2509 rtn
"\\end{lstlisting}\n")
2510 (concat (car org-export-latex-verbatim-wrap
)
2511 rtn
(cdr org-export-latex-verbatim-wrap
)))
2514 ((eq backend
'ascii
)
2515 ;; This is not HTML or LaTeX, so just make it an example.
2516 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2517 (concat caption
"\n"
2522 (lambda (l) (concat " " l
))
2523 (org-split-string rtn
"\n")
2528 (org-add-props rtn nil
'original-indentation indent
))))
2530 (defun org-export-number-lines (text backend
2531 &optional skip1 skip2 number cont
2532 replace-labels label-format
)
2533 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2534 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2537 (goto-char (point-max))
2538 (skip-chars-backward " \t\n\r")
2539 (delete-region (point) (point-max))
2540 (beginning-of-line (- 1 skip2
))
2541 (let* ((last (org-current-line))
2542 (n org-export-last-code-line-counter-value
)
2543 (nmax (+ n
(- last skip1
)))
2544 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2547 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2549 ((eq backend
'ascii
) fmt
)
2550 ((eq backend
'latex
) fmt
)
2551 ((eq backend
'docbook
) fmt
)
2553 (label-format (or label-format org-coderef-label-format
))
2554 (label-pre (if (string-match "%s" label-format
)
2555 (substring label-format
0 (match-beginning 0))
2557 (label-post (if (string-match "%s" label-format
)
2558 (substring label-format
(match-end 0))
2562 ".*?\\S-.*?\\([ \t]*\\("
2563 (regexp-quote label-pre
)
2564 "\\([-a-zA-Z0-9_ ]+\\)"
2565 (regexp-quote label-post
)
2569 (org-goto-line (1+ skip1
))
2570 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2572 (insert (format fm
(incf n
)))
2574 (when (looking-at lbl-re
)
2575 (setq ref
(match-string 3))
2576 (cond ((numberp replace-labels
)
2577 ;; remove labels; use numbers for references when lines
2578 ;; are numbered, use labels otherwise
2579 (delete-region (match-beginning 1) (match-end 1))
2580 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2581 ((eq replace-labels
'keep
)
2582 ;; don't remove labels; use numbers for references when
2583 ;; lines are numbered, use labels otherwise
2584 (goto-char (match-beginning 2))
2585 (delete-region (match-beginning 2) (match-end 2))
2586 (insert "(" ref
")")
2587 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2588 org-export-code-refs
))
2590 ;; don't remove labels and don't use numbers for
2592 (goto-char (match-beginning 2))
2593 (delete-region (match-beginning 2) (match-end 2))
2594 (insert "(" ref
")")
2595 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2596 (when (eq backend
'html
)
2598 (beginning-of-line 1)
2599 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2602 (insert "</span>")))))
2603 (setq org-export-last-code-line-counter-value n
)
2604 (goto-char (point-max))
2608 (defun org-search-todo-below (line lines level
)
2609 "Search the subtree below LINE for any TODO entries."
2610 (let ((rest (cdr (memq line lines
)))
2611 (re org-todo-line-regexp
)
2614 (while (setq line
(pop rest
))
2615 (if (string-match re line
)
2617 (setq lv
(- (match-end 1) (match-beginning 1))
2618 todo
(and (match-beginning 2)
2619 (not (member (match-string 2 line
)
2620 org-done-keywords
))))
2622 (if (<= lv level
) (throw 'exit nil
))
2623 (if todo
(throw 'exit t
))))))))
2626 (defun org-export-visible (type arg
)
2627 "Create a copy of the visible part of the current buffer, and export it.
2628 The copy is created in a temporary buffer and removed after use.
2629 TYPE is the final key (as a string) that also select the export command in
2630 the `C-c C-e' export dispatcher.
2631 As a special case, if the you type SPC at the prompt, the temporary
2632 org-mode file will not be removed but presented to you so that you can
2633 continue to use it. The prefix arg ARG is passed through to the exporting
2637 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]buffer with HTML [D]ocBook [l]atex [p]df [d]view pdf [L]atex buffer [x]OXO [ ]keep buffer")
2638 (read-char-exclusive))
2639 current-prefix-arg
))
2640 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L
)))
2641 (error "Invalid export key"))
2642 (let* ((binding (cdr (assoc type
2643 '((?a . org-export-as-ascii
)
2644 (?A . org-export-as-ascii-to-buffer
)
2645 (?\C-a . org-export-as-ascii
)
2646 (?b . org-export-as-html-and-open
)
2647 (?\C-b . org-export-as-html-and-open
)
2648 (?h . org-export-as-html
)
2649 (?H . org-export-as-html-to-buffer
)
2650 (?R . org-export-region-as-html
)
2651 (?D . org-export-as-docbook
)
2653 (?l . org-export-as-latex
)
2654 (?p . org-export-as-pdf
)
2655 (?d . org-export-as-pdf-and-open
)
2656 (?L . org-export-as-latex-to-buffer
)
2658 (?x . org-export-as-xoxo
)))))
2659 (keepp (equal type ?\
))
2660 (file buffer-file-name
)
2661 (buffer (get-buffer-create "*Org Export Visible*"))
2663 ;; Need to hack the drawers here.
2665 (goto-char (point-min))
2666 (while (re-search-forward org-drawer-regexp nil t
)
2667 (goto-char (match-beginning 1))
2668 (or (org-invisible-p) (org-flag-drawer nil
))))
2669 (with-current-buffer buffer
(erase-buffer))
2671 (setq s
(goto-char (point-min)))
2672 (while (not (= (point) (point-max)))
2673 (goto-char (org-find-invisible))
2674 (append-to-buffer buffer s
(point))
2675 (setq s
(goto-char (org-find-visible))))
2676 (org-cycle-hide-drawers 'all
)
2677 (goto-char (point-min))
2679 ;; Copy all comment lines to the end, to make sure #+ settings are
2680 ;; still available for the second export step. Kind of a hack, but
2681 ;; does do the trick.
2682 (if (looking-at "#[^\r\n]*")
2683 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2684 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2685 (append-to-buffer buffer
(1+ (match-beginning 0))
2686 (min (point-max) (1+ (match-end 0))))))
2688 (let ((buffer-file-name file
)
2689 (org-inhibit-startup t
))
2692 (unless keepp
(funcall binding arg
))))
2694 (kill-buffer buffer
)
2695 (switch-to-buffer-other-window buffer
)
2696 (goto-char (point-min)))))
2698 (defun org-find-visible ()
2700 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2701 (get-char-property s
'invisible
)))
2703 (defun org-find-invisible ()
2705 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2706 (not (get-char-property s
'invisible
))))
2709 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
2712 (defun org-export-as-org (arg &optional hidden ext-plist
2713 to-buffer body-only pub-dir
)
2714 "Make a copy with not-exporting stuff removed.
2715 The purpose of this function is to provide a way to export the source
2716 Org file of a webpage in Org format, but with sensitive and/or irrelevant
2717 stuff removed. This command will remove the following:
2719 - archived trees (if the variable `org-export-with-archived-trees' is nil)
2720 - comment blocks and trees starting with the COMMENT keyword
2721 - only trees that are consistent with `org-export-select-tags'
2722 and `org-export-exclude-tags'.
2724 The only arguments that will be used are EXT-PLIST and PUB-DIR,
2725 all the others will be ignored (but are present so that the general
2726 mechanism to call publishing functions will work).
2728 EXT-PLIST is a property list with external parameters overriding
2729 org-mode's default settings, but still inferior to file-local
2730 settings. When PUB-DIR is set, use this as the publishing
2733 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2735 (org-infile-export-plist)))
2736 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2737 (filename (concat (file-name-as-directory
2739 (org-export-directory :org opt-plist
)))
2740 (file-name-sans-extension
2741 (file-name-nondirectory bfname
))
2743 (filename (and filename
2744 (if (equal (file-truename filename
)
2745 (file-truename bfname
))
2746 (concat (file-name-sans-extension filename
)
2748 (file-name-extension filename
))
2750 (backup-inhibited t
)
2751 (buffer (find-file-noselect filename
))
2752 (region (buffer-string)))
2754 (switch-to-buffer buffer
)
2757 (let ((org-inhibit-startup t
)) (org-mode))
2758 (org-install-letbind)
2760 ;; Get rid of archived trees
2761 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
2763 ;; Remove comment environment and comment subtrees
2764 (org-export-remove-comment-blocks-and-subtrees)
2766 ;; Get rid of excluded trees
2767 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
2768 (plist-get opt-plist
:exclude-tags
))
2770 (when (or (plist-get opt-plist
:plain-source
)
2771 (not (or (plist-get opt-plist
:plain-source
)
2772 (plist-get opt-plist
:htmlized-source
))))
2773 ;; Either nothing special is requested (default call)
2774 ;; or the plain source is explicitly requested
2777 (when (plist-get opt-plist
:htmlized-source
)
2778 ;; Make the htmlized version
2781 (font-lock-fontify-buffer)
2782 (let* ((htmlize-output-type 'css
)
2783 (newbuf (htmlize-buffer)))
2784 (with-current-buffer newbuf
2785 (when org-export-htmlized-org-css-url
2786 (goto-char (point-min))
2787 (and (re-search-forward
2788 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
2792 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
2793 org-export-htmlized-org-css-url
)
2795 (write-file (concat filename
".html")))
2796 (kill-buffer newbuf
)))
2797 (set-buffer-modified-p nil
)
2798 (kill-buffer (current-buffer)))))
2800 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2801 (defun org-get-current-options ()
2802 "Return a string with current options as keyword options.
2803 Does include HTML export options as well as TODO and CATEGORY stuff."
2804 (require 'org-archive
)
2813 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2814 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2816 #+EXPORT_SELECT_TAGS: %s
2817 #+EXPORT_EXCLUDE_TAGS: %s
2823 #+PRIORITIES: %c %c %c
2825 #+STARTUP: %s %s %s %s %s
2831 (buffer-name) (user-full-name) user-mail-address
2832 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2833 org-export-default-language
2834 org-export-headline-levels
2835 org-export-with-section-numbers
2837 org-export-preserve-breaks
2838 org-export-html-expand
2839 org-export-with-fixed-width
2840 org-export-with-tables
2841 org-export-with-sub-superscripts
2842 org-export-with-special-strings
2843 org-export-with-footnotes
2844 org-export-with-emphasize
2845 org-export-with-timestamps
2846 org-export-with-TeX-macros
2847 org-export-with-LaTeX-fragments
2848 org-export-skip-text-before-1st-heading
2849 org-export-with-drawers
2850 org-export-with-todo-keywords
2851 org-export-with-priority
2852 org-export-with-tags
2853 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2854 (mapconcat 'identity org-export-select-tags
" ")
2855 (mapconcat 'identity org-export-exclude-tags
" ")
2856 org-export-html-link-up
2857 org-export-html-link-home
2859 (file-name-sans-extension
2860 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2862 "TODO FEEDBACK VERIFY DONE"
2863 "Me Jason Marie DONE"
2864 org-highest-priority org-lowest-priority org-default-priority
2865 (mapconcat 'identity org-drawers
" ")
2866 (cdr (assoc org-startup-folded
2867 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2868 (if org-odd-levels-only
"odd" "oddeven")
2869 (if org-hide-leading-stars
"hidestars" "showstars")
2870 (if org-startup-align-all-tables
"align" "noalign")
2871 (cond ((eq org-log-done t
) "logdone")
2872 ((equal org-log-done
'note
) "lognotedone")
2873 ((not org-log-done
) "nologdone"))
2874 (or (mapconcat (lambda (x)
2876 ((equal :startgroup
(car x
)) "{")
2877 ((equal :endgroup
(car x
)) "}")
2878 ((equal :newline
(car x
)) "")
2879 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2881 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2882 (mapconcat 'identity org-file-tags
" ")
2883 org-archive-location
2884 "org file:~/org/%s.org"
2888 (defun org-insert-export-options-template ()
2889 "Insert into the buffer a template with information for exporting."
2891 (if (not (bolp)) (newline))
2892 (let ((s (org-get-current-options)))
2893 (and (string-match "#\\+CATEGORY" s
)
2894 (setq s
(substring s
0 (match-beginning 0))))
2897 (defvar org-table-colgroup-info nil
)
2899 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
2900 "Check if the table has a marking column.
2901 If yes remove the column and the special lines."
2902 (setq org-table-colgroup-info nil
)
2905 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2908 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
2909 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
2913 (setq org-table-clean-did-remove-column nil
)
2918 ((string-match "^[ \t]*| */ *|" x
)
2919 (setq org-table-colgroup-info
2921 (cond ((member x
'("<" "<")) :start
)
2922 ((member x
'(">" ">")) :end
)
2923 ((member x
'("<>" "<>")) :startend
)
2925 (org-split-string x
"[ \t]*|[ \t]*")))
2929 (setq org-table-clean-did-remove-column t
)
2934 ((string-match "^[ \t]*| */ *|" x
)
2935 (setq org-table-colgroup-info
2937 (cond ((member x
'("<" "<")) :start
)
2938 ((member x
'(">" ">")) :end
)
2939 ((member x
'("<>" "<>")) :startend
)
2941 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2943 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2944 nil
) ; ignore this line
2945 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2946 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2947 ;; remove the first column
2948 (replace-match "\\1|" t nil x
))))
2951 (defun org-export-cleanup-toc-line (s)
2952 "Remove tags and timestamps from lines going into the toc."
2953 (when (memq org-export-with-tags
'(not-in-toc nil
))
2954 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
2955 (setq s
(replace-match "" t t s
))))
2956 (when org-export-remove-timestamps-from-toc
2957 (while (string-match org-maybe-keyword-time-regexp s
)
2958 (setq s
(replace-match "" t t s
))))
2959 (while (string-match org-bracket-link-regexp s
)
2960 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
2962 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
2963 (setq s
(replace-match "" t t s
)))
2966 (defun org-create-multibrace-regexp (left right n
)
2967 "Create a regular expression which will match a balanced sexp.
2968 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
2969 as single character strings.
2970 The regexp returned will match the entire expression including the
2971 delimiters. It will also define a single group which contains the
2972 match except for the outermost delimiters. The maximum depth of
2973 stacked delimiters is N. Escaping delimiters is not possible."
2974 (let* ((nothing (concat "[^" left right
"]*?"))
2977 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
2980 re
(concat re or next
)
2981 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
2982 (concat left
"\\(" re
"\\)" right
)))
2984 (defvar org-match-substring-regexp
2986 "\\([^\\]\\)\\([_^]\\)\\("
2987 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2989 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
2991 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
2992 "The regular expression matching a sub- or superscript.")
2994 (defvar org-match-substring-with-braces-regexp
2996 "\\([^\\]\\)\\([_^]\\)\\("
2997 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
2999 "The regular expression matching a sub- or superscript, forcing braces.")
3002 (defun org-get-text-property-any (pos prop
&optional object
)
3003 (or (get-text-property pos prop object
)
3004 (and (setq pos
(next-single-property-change pos prop object
))
3005 (get-text-property pos prop object
))))
3007 (defun org-export-get-coderef-format (path desc
)
3009 (if (and desc
(string-match
3010 (regexp-quote (concat "(" path
")"))
3012 (replace-match "%s" t t desc
)
3015 (defun org-export-push-to-kill-ring (format)
3016 "Push buffer content to kill ring.
3017 The depends on the variable `org-export-copy-to-kill'."
3018 (when org-export-copy-to-kill-ring
3019 (org-kill-new (buffer-string))
3020 (when (fboundp 'x-set-selection
)
3021 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
3022 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
3023 (message "%s export done, pushed to kill ring and clipboard" format
)))
3027 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3029 ;;; org-exp.el ends here