1 ;;; org-exp.el --- Export internals for Org-mode
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
39 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
40 (declare-function org-export-html-preprocess
"org-html" (parameters))
41 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
42 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
43 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
44 (declare-function htmlize-buffer
"ext:htmlize" (&optional buffer
))
45 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
46 (declare-function org-table-cookie-line-p
"org-table" (line))
47 (declare-function org-table-colgroup-line-p
"org-table" (line))
48 (declare-function org-pop-to-buffer-same-window
"org-compat"
49 (&optional buffer-or-name norecord label
))
50 (declare-function org-unescape-code-in-region
"org-src" (beg end
))
52 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
54 (autoload 'org-export-as-odt
"org-odt"
55 "Export the outline to a OpenDocument Text file." t
)
56 (autoload 'org-export-as-odt-and-open
"org-odt"
57 "Export the outline to a OpenDocument Text file and open it." t
)
59 (defgroup org-export nil
60 "Options for exporting org-listings."
64 (defgroup org-export-general nil
65 "General options for exporting Org-mode files."
66 :tag
"Org Export General"
69 (defcustom org-export-allow-BIND
'confirm
70 "Non-nil means allow #+BIND to define local variable values for export.
71 This is a potential security risk, which is why the user must confirm the
73 :group
'org-export-general
75 (const :tag
"Never" nil
)
76 (const :tag
"Always" t
)
77 (const :tag
"Make the user confirm for each file" confirm
)))
80 (defvar org-export-publishing-directory nil
)
82 (defcustom org-export-show-temporary-export-buffer t
83 "Non-nil means show buffer after exporting to temp buffer.
84 When Org exports to a file, the buffer visiting that file is ever
85 shown, but remains buried. However, when exporting to a temporary
86 buffer, that buffer is popped up in a second window. When this variable
87 is nil, the buffer remains buried also in these cases."
88 :group
'org-export-general
91 (defcustom org-export-copy-to-kill-ring
'if-interactive
92 "Should we push exported content to the kill ring?"
93 :group
'org-export-general
96 (const :tag
"Always" t
)
97 (const :tag
"When export is done interactively" if-interactive
)
98 (const :tag
"Never" nil
)))
100 (defcustom org-export-kill-product-buffer-when-displayed nil
101 "Non-nil means kill the product buffer if it is displayed immediately.
102 This applied to the commands `org-export-as-html-and-open' and
103 `org-export-as-pdf-and-open'."
104 :group
'org-export-general
108 (defcustom org-export-run-in-background nil
109 "Non-nil means export and publishing commands will run in background.
110 This works by starting up a separate Emacs process visiting the same file
111 and doing the export from there.
112 Not all export commands are affected by this - only the ones which
113 actually write to a file, and that do not depend on the buffer state.
115 If this option is nil, you can still get background export by calling
116 `org-export' with a double prefix arg: \
117 \\[universal-argument] \\[universal-argument] \\[org-export].
119 If this option is t, the double prefix can be used to exceptionally
120 force an export command into the current process."
121 :group
'org-export-general
124 (defcustom org-export-initial-scope
'buffer
125 "The initial scope when exporting with `org-export'.
126 This variable can be either set to 'buffer or 'subtree."
127 :group
'org-export-general
130 (const :tag
"Export current buffer" 'buffer
)
131 (const :tag
"Export current subtree" 'subtree
)))
133 (defcustom org-export-select-tags
'("export")
134 "Tags that select a tree for export.
135 If any such tag is found in a buffer, all trees that do not carry one
136 of these tags will be deleted before export.
137 Inside trees that are selected like this, you can still deselect a
138 subtree by tagging it with one of the `org-export-exclude-tags'."
139 :group
'org-export-general
140 :type
'(repeat (string :tag
"Tag")))
142 (defcustom org-export-exclude-tags
'("noexport")
143 "Tags that exclude a tree from export.
144 All trees carrying any of these tags will be excluded from export.
145 This is without condition, so even subtrees inside that carry one of the
146 `org-export-select-tags' will be removed."
147 :group
'org-export-general
148 :type
'(repeat (string :tag
"Tag")))
150 ;; FIXME: rename, this is a general variable
151 (defcustom org-export-html-expand t
152 "Non-nil means for HTML export, treat @<...> as HTML tag.
153 When nil, these tags will be exported as plain text and therefore
154 not be interpreted by a browser.
156 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
157 :group
'org-export-html
158 :group
'org-export-general
161 (defcustom org-export-with-special-strings t
162 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
163 When this option is turned on, these strings will be exported as:
166 -----+----------+--------
172 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
173 :group
'org-export-translation
176 (defcustom org-export-html-link-up
""
177 "Where should the \"UP\" link of exported HTML pages lead?"
178 :group
'org-export-html
179 :group
'org-export-general
180 :type
'(string :tag
"File or URL"))
182 (defcustom org-export-html-link-home
""
183 "Where should the \"HOME\" link of exported HTML pages lead?"
184 :group
'org-export-html
185 :group
'org-export-general
186 :type
'(string :tag
"File or URL"))
188 (defcustom org-export-language-setup
189 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
190 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
191 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
192 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
193 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
194 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
195 ("es" "Autor" "Fecha" "Índice" "Pies de página")
196 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
197 ("fr" "Auteur" "Date" "Sommaire" "Notes de bas de page")
198 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
199 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
200 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
201 ;; Use numeric character entities for proper rendering of non-UTF8 documents
202 ;; ("ja" "著者" "日付" "目次" "脚注")
203 ("ja" "著者" "日付" "目次" "脚注")
204 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
205 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
206 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
207 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
208 ("pl" "Autor" "Data" "Spis treści" "Przypis")
209 ;; Use numeric character entities for proper rendering of non-UTF8 documents
210 ;; ("ru" "Автор" "Дата" "Содержание" "Сноски")
211 ("ru" "Автор" "Дата" "Содержание" "Сноски")
212 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter")
213 ;; Use numeric character entities for proper rendering of non-UTF8 documents
214 ;; ("uk" "Автор" "Дата" "Зміст" "Примітки")
215 ("uk" "Автор" "Дата" "Зміст" "Примітки")
216 ;; Use numeric character entities for proper rendering of non-UTF8 documents
217 ;; ("zh-CN" "作者" "日期" "目录" "脚注")
218 ("zh-CN" "作者" "日期" "目录" "脚注")
219 ;; Use numeric character entities for proper rendering of non-UTF8 documents
220 ;; ("zh-TW" "作者" "日期" "目錄" "腳註")
221 ("zh-TW" "作者" "日期" "目錄" "腳註"))
222 "Terms used in export text, translated to different languages.
223 Use the variable `org-export-default-language' to set the language,
224 or use the +OPTION lines for a per-file setting."
225 :group
'org-export-general
228 (string :tag
"HTML language tag")
229 (string :tag
"Author")
231 (string :tag
"Table of Contents")
232 (string :tag
"Footnotes"))))
234 (defcustom org-export-default-language
"en"
235 "The default language for export and clocktable translations, as a string.
236 This should have an association in `org-export-language-setup'
237 and in `org-clock-clocktable-language-setup'."
238 :group
'org-export-general
241 (defcustom org-export-date-timestamp-format
"%Y-%m-%d"
242 "Time string format for Org timestamps in the #+DATE option."
243 :group
'org-export-general
247 (defvar org-export-page-description
""
248 "The page description, for the XHTML meta tag.
249 This is best set with the #+DESCRIPTION line in a file, it does not make
250 sense to set this globally.")
252 (defvar org-export-page-keywords
""
253 "The page description, for the XHTML meta tag.
254 This is best set with the #+KEYWORDS line in a file, it does not make
255 sense to set this globally.")
257 (defcustom org-export-skip-text-before-1st-heading nil
258 "Non-nil means skip all text before the first headline when exporting.
259 When nil, that text is exported as well."
260 :group
'org-export-general
263 (defcustom org-export-headline-levels
3
264 "The last level which is still exported as a headline.
265 Inferior levels will produce itemize lists when exported.
266 Note that a numeric prefix argument to an exporter function overrides
269 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
270 :group
'org-export-general
273 (defcustom org-export-with-section-numbers t
274 "Non-nil means add section numbers to headlines when exporting.
276 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
277 :group
'org-export-general
280 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
281 "Format of section numbers for export.
282 The variable has two components.
283 1. A list of lists, each indicating a counter type and a separator.
284 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
285 It causes causes numeric, alphabetic, or roman counters, respectively.
286 The separator is only used if another counter for a subsection is being
288 If there are more numbered section levels than entries in this lists,
289 then the last entry will be reused.
290 2. A terminator string that will be added after the entire
292 :group
'org-export-general
296 (string :tag
"Counter Type")
297 (string :tag
"Separator ")))
298 (string :tag
"Terminator")))
300 (defcustom org-export-with-toc t
301 "Non-nil means create a table of contents in exported files.
302 The TOC contains headlines with levels up to`org-export-headline-levels'.
303 When an integer, include levels up to N in the toc, this may then be
304 different from `org-export-headline-levels', but it will not be allowed
305 to be larger than the number of headline levels.
306 When nil, no table of contents is made.
308 Headlines which contain any TODO items will be marked with \"(*)\" in
309 ASCII export, and with red color in HTML output, if the option
310 `org-export-mark-todo-in-toc' is set.
312 In HTML output, the TOC will be clickable.
314 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
316 :group
'org-export-general
318 (const :tag
"No Table of Contents" nil
)
319 (const :tag
"Full Table of Contents" t
)
320 (integer :tag
"TOC to level")))
322 (defcustom org-export-mark-todo-in-toc nil
323 "Non-nil means mark TOC lines that contain any open TODO items."
324 :group
'org-export-general
327 (defcustom org-export-with-todo-keywords t
328 "Non-nil means include TODO keywords in export.
329 When nil, remove all these keywords from the export."
330 :group
'org-export-general
333 (defcustom org-export-with-tasks t
334 "Non-nil means include TODO items for export.
335 This may have the following values:
336 t include tasks independent of state.
337 todo include only tasks that are not yet done.
338 done include only tasks that are already done.
339 nil remove all tasks before export
340 list of TODO kwds keep only tasks with these keywords"
341 :group
'org-export-general
344 (const :tag
"All tasks" t
)
345 (const :tag
"No tasks" nil
)
346 (const :tag
"Not-done tasks" todo
)
347 (const :tag
"Only done tasks" done
)
348 (repeat :tag
"Specific TODO keywords"
349 (string :tag
"Keyword"))))
351 (defcustom org-export-with-priority nil
352 "Non-nil means include priority cookies in export.
353 When nil, remove priority cookies for export."
354 :group
'org-export-general
357 (defcustom org-export-preserve-breaks nil
358 "Non-nil means preserve all line breaks when exporting.
359 Normally, in HTML output paragraphs will be reformatted. In ASCII
360 export, line breaks will always be preserved, regardless of this variable.
362 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
363 :group
'org-export-general
366 (defcustom org-export-with-archived-trees
'headline
367 "Whether subtrees with the ARCHIVE tag should be exported.
368 This can have three different values
369 nil Do not export, pretend this tree is not present
370 t Do export the entire tree
371 headline Only export the headline, but skip the tree below it."
372 :group
'org-export-general
375 (const :tag
"not at all" nil
)
376 (const :tag
"headline only" 'headline
)
377 (const :tag
"entirely" t
)))
379 (defcustom org-export-author-info t
380 "Non-nil means insert author name and email into the exported file.
382 This option can also be set with the +OPTIONS line,
383 e.g. \"author:nil\"."
384 :group
'org-export-general
387 (defcustom org-export-email-info nil
388 "Non-nil means insert author name and email into the exported file.
390 This option can also be set with the +OPTIONS line,
392 :group
'org-export-general
396 (defcustom org-export-creator-info t
397 "Non-nil means the postamble should contain a creator sentence.
398 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
399 :group
'org-export-general
402 (defcustom org-export-time-stamp-file t
403 "Non-nil means insert a time stamp into the exported file.
404 The time stamp shows when the file was created.
406 This option can also be set with the +OPTIONS line,
407 e.g. \"timestamp:nil\"."
408 :group
'org-export-general
411 (defcustom org-export-with-timestamps t
412 "If nil, do not export time stamps and associated keywords."
413 :group
'org-export-general
416 (defcustom org-export-remove-timestamps-from-toc t
417 "If t, remove timestamps from the table of contents entries."
418 :group
'org-export-general
421 (defcustom org-export-with-tags
'not-in-toc
422 "If nil, do not export tags, just remove them from headlines.
423 If this is the symbol `not-in-toc', tags will be removed from table of
424 contents entries, but still be shown in the headlines of the document.
426 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
427 :group
'org-export-general
429 (const :tag
"Off" nil
)
430 (const :tag
"Not in TOC" not-in-toc
)
431 (const :tag
"On" t
)))
433 (defcustom org-export-with-drawers nil
434 "Non-nil means export with drawers like the property drawer.
435 When t, all drawers are exported. This may also be a list of
436 drawer names to export."
437 :group
'org-export-general
439 (const :tag
"All drawers" t
)
440 (const :tag
"None" nil
)
441 (repeat :tag
"Selected drawers"
442 (string :tag
"Drawer name"))))
444 (defvar org-export-first-hook nil
445 "Hook called as the first thing in each exporter.
446 Point will be still in the original buffer.
447 Good for general initialization")
449 (defvar org-export-preprocess-hook nil
450 "Hook for preprocessing an export buffer.
451 Pretty much the first thing when exporting is running this hook.
452 Point will be in a temporary buffer that contains a copy of
453 the original buffer, or of the section that is being exported.
454 All the other hooks in the org-export-preprocess... category
455 also work in that temporary buffer, already modified by various
456 stages of the processing.")
458 (defvar org-export-preprocess-after-include-files-hook nil
459 "Hook for preprocessing an export buffer.
460 This is run after the contents of included files have been inserted.")
462 (defvar org-export-preprocess-after-tree-selection-hook nil
463 "Hook for preprocessing an export buffer.
464 This is run after selection of trees to be exported has happened.
465 This selection includes tags-based selection, as well as removal
466 of commented and archived trees.")
468 (defvar org-export-preprocess-after-headline-targets-hook nil
469 "Hook for preprocessing export buffer.
470 This is run just after the headline targets have been defined and
471 the target-alist has been set up.")
473 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
474 "Hook for preprocessing an export buffer.
475 This is run just before backend-specific blocks get selected.")
477 (defvar org-export-preprocess-after-blockquote-hook nil
478 "Hook for preprocessing an export buffer.
479 This is run after blockquote/quote/verse/center have been marked
482 (defvar org-export-preprocess-after-radio-targets-hook nil
483 "Hook for preprocessing an export buffer.
484 This is run after radio target processing.")
486 (defvar org-export-preprocess-before-normalizing-links-hook nil
487 "Hook for preprocessing an export buffer.
488 This hook is run before links are normalized.")
490 (defvar org-export-preprocess-before-backend-specifics-hook nil
491 "Hook run before backend-specific functions are called during preprocessing.")
493 (defvar org-export-preprocess-final-hook nil
494 "Hook for preprocessing an export buffer.
495 This is run as the last thing in the preprocessing buffer, just before
496 returning the buffer string to the backend.")
498 (defgroup org-export-translation nil
499 "Options for translating special ascii sequences for the export backends."
500 :tag
"Org Export Translation"
503 (defcustom org-export-with-emphasize t
504 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
505 If the export target supports emphasizing text, the word will be
506 typeset in bold, italic, or underlined, respectively. Works only for
507 single words, but you can say: I *really* *mean* *this*.
508 Not all export backends support this.
510 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
511 :group
'org-export-translation
514 (defcustom org-export-with-footnotes t
515 "If nil, export [1] as a footnote marker.
516 Lines starting with [1] will be formatted as footnotes.
518 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
519 :group
'org-export-translation
522 (defcustom org-export-with-TeX-macros t
523 "Non-nil means interpret simple TeX-like macros when exporting.
524 For example, HTML export converts \\alpha to α and \\AA to Å.
525 Not only real TeX macros will work here, but the standard HTML entities
526 for math can be used as macro names as well. For a list of supported
527 names in HTML export, see the constant `org-entities' and the user option
529 Not all export backends support this.
531 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
532 :group
'org-export-translation
533 :group
'org-export-latex
536 (defcustom org-export-with-LaTeX-fragments t
537 "Non-nil means process LaTeX math fragments for HTML display.
538 When set, the exporter will find and process LaTeX environments if the
539 \\begin line is the first non-white thing on a line. It will also find
540 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
541 $$a=b$$ and \\=\\[ a=b \\] for display math.
543 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
547 nil Don't do anything.
548 verbatim Keep everything in verbatim
549 dvipng Process the LaTeX fragments to images.
550 This will also include processing of non-math environments.
551 imagemagick Convert the LaTeX fragments to pdf files and use imagemagick
552 to convert pdf files to png files.
553 t Do MathJax preprocessing if there is at least on math snippet,
554 and arrange for MathJax.js to be loaded.
556 The default is nil, because this option needs the `dvipng' program which
557 is not available on all systems."
558 :group
'org-export-translation
559 :group
'org-export-latex
561 (const :tag
"Do not process math in any way" nil
)
562 (const :tag
"Obsolete, use dvipng setting" t
)
563 (const :tag
"Use dvipng to make images" dvipng
)
564 (const :tag
"Use imagemagick to make images" imagemagick
)
565 (const :tag
"Use MathJax to display math" mathjax
)
566 (const :tag
"Leave math verbatim" verbatim
)))
568 (defcustom org-export-with-fixed-width t
569 "Non-nil means lines starting with \":\" will be in fixed width font.
570 This can be used to have pre-formatted text, fragments of code etc. For
572 : ;; Some Lisp examples
575 will be looking just like this in also HTML. See also the QUOTE keyword.
576 Not all export backends support this.
578 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
579 :group
'org-export-translation
582 (defgroup org-export-tables nil
583 "Options for exporting tables in Org-mode."
584 :tag
"Org Export Tables"
587 (defcustom org-export-with-tables t
588 "If non-nil, lines starting with \"|\" define a table.
591 | Name | Address | Birthday |
592 |-------------+----------+-----------|
593 | Arthur Dent | England | 29.2.2100 |
595 Not all export backends support this.
597 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
598 :group
'org-export-tables
601 (defcustom org-export-highlight-first-table-line t
602 "Non-nil means highlight the first table line.
603 In HTML export, this means use <th> instead of <td>.
604 In tables created with table.el, this applies to the first table line.
605 In Org-mode tables, all lines before the first horizontal separator
606 line will be formatted with <th> tags."
607 :group
'org-export-tables
610 (defcustom org-export-table-remove-special-lines t
611 "Remove special lines and marking characters in calculating tables.
612 This removes the special marking character column from tables that are set
613 up for spreadsheet calculations. It also removes the entire lines
614 marked with `!', `_', or `^'. The lines with `$' are kept, because
615 the values of constants may be useful to have."
616 :group
'org-export-tables
619 (defcustom org-export-table-remove-empty-lines t
620 "Remove empty lines when exporting tables.
621 This is the global equivalent of the :remove-nil-lines option
622 when locally sending a table with #+ORGTBL."
623 :group
'org-export-tables
627 (defcustom org-export-prefer-native-exporter-for-tables nil
628 "Non-nil means always export tables created with table.el natively.
629 Natively means use the HTML code generator in table.el.
630 When nil, Org-mode's own HTML generator is used when possible (i.e. if
631 the table does not use row- or column-spanning). This has the
632 advantage, that the automatic HTML conversions for math symbols and
633 sub/superscripts can be applied. Org-mode's HTML generator is also
634 much faster. The LaTeX exporter always use the native exporter for
636 :group
'org-export-tables
641 ;;; Variables, constants, and parameter plists
643 (defconst org-level-max
20)
645 (defvar org-export-current-backend nil
646 "During export, this will be bound to a symbol such as 'html,
647 'latex, 'docbook, 'ascii, etc, indicating which of the export
648 backends is in use. Otherwise it has the value nil. Users
649 should not attempt to change the value of this variable
650 directly, but it can be used in code to test whether export is
651 in progress, and if so, what the backend is.")
653 (defvar org-current-export-file nil
) ; dynamically scoped parameter
654 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
655 (defvar org-export-opt-plist nil
656 "Contains the current option plist.")
657 (defvar org-last-level nil
) ; dynamically scoped variable
658 (defvar org-min-level nil
) ; dynamically scoped variable
659 (defvar org-levels-open nil
) ; dynamically scoped parameter
660 (defvar org-export-footnotes-data nil
661 "Alist of labels used in buffers, along with their definition.")
662 (defvar org-export-footnotes-seen nil
663 "Alist of labels encountered so far by the exporter, along with their definition.")
666 (defconst org-export-plist-vars
667 '((:link-up nil org-export-html-link-up
)
668 (:link-home nil org-export-html-link-home
)
669 (:language nil org-export-default-language
)
670 (:keywords nil org-export-page-keywords
)
671 (:description nil org-export-page-description
)
672 (:customtime nil org-display-custom-times
)
673 (:headline-levels
"H" org-export-headline-levels
)
674 (:section-numbers
"num" org-export-with-section-numbers
)
675 (:section-number-format nil org-export-section-number-format
)
676 (:table-of-contents
"toc" org-export-with-toc
)
677 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
678 (:archived-trees nil org-export-with-archived-trees
)
679 (:emphasize
"*" org-export-with-emphasize
)
680 (:sub-superscript
"^" org-export-with-sub-superscripts
)
681 (:special-strings
"-" org-export-with-special-strings
)
682 (:footnotes
"f" org-export-with-footnotes
)
683 (:drawers
"d" org-export-with-drawers
)
684 (:tags
"tags" org-export-with-tags
)
685 (:todo-keywords
"todo" org-export-with-todo-keywords
)
686 (:tasks
"tasks" org-export-with-tasks
)
687 (:priority
"pri" org-export-with-priority
)
688 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
689 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
690 (:latex-listings nil org-export-latex-listings
)
691 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
692 (:fixed-width
":" org-export-with-fixed-width
)
693 (:timestamps
"<" org-export-with-timestamps
)
694 (:author nil user-full-name
)
695 (:email nil user-mail-address
)
696 (:author-info
"author" org-export-author-info
)
697 (:email-info
"email" org-export-email-info
)
698 (:creator-info
"creator" org-export-creator-info
)
699 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
700 (:tables
"|" org-export-with-tables
)
701 (:table-auto-headline nil org-export-highlight-first-table-line
)
702 (:style-include-default nil org-export-html-style-include-default
)
703 (:style-include-scripts nil org-export-html-style-include-scripts
)
704 (:style nil org-export-html-style
)
705 (:style-extra nil org-export-html-style-extra
)
706 (:agenda-style nil org-agenda-export-html-style
)
707 (:convert-org-links nil org-export-html-link-org-files-as-html
)
708 (:inline-images nil org-export-html-inline-images
)
709 (:html-extension nil org-export-html-extension
)
710 (:html-preamble nil org-export-html-preamble
)
711 (:html-postamble nil org-export-html-postamble
)
712 (:xml-declaration nil org-export-html-xml-declaration
)
713 (:html-table-tag nil org-export-html-table-tag
)
714 (:expand-quoted-html
"@" org-export-html-expand
)
715 (:timestamp nil org-export-html-with-timestamp
)
716 (:publishing-directory nil org-export-publishing-directory
)
717 (:select-tags nil org-export-select-tags
)
718 (:exclude-tags nil org-export-exclude-tags
)
720 (:latex-image-options nil org-export-latex-image-default-option
))
721 "List of properties that represent export/publishing variables.
722 Each element is a list of 3 items:
723 1. The property that is used internally, and also for org-publish-project-alist
724 2. The string that can be used in the OPTION lines to set this option,
725 or nil if this option cannot be changed in this way
726 3. The customization variable that sets the default for this option."
729 (defun org-default-export-plist ()
730 "Return the property list with default settings for the export variables."
731 (let* ((infile (org-infile-export-plist))
732 (letbind (plist-get infile
:let-bind
))
733 (l org-export-plist-vars
) rtn e s v
)
734 (while (setq e
(pop l
))
737 ((assq s letbind
) (nth 1 (assq s letbind
)))
738 ((boundp s
) (symbol-value s
)))
739 rtn
(cons (car e
) (cons v rtn
))))
742 (defvar org-export-inbuffer-options-extra nil
743 "List of additional in-buffer options that should be detected.
744 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
745 etc. Extensions can add to this list to get their options detected, and they
746 can then add a function to `org-export-options-filters' to process these
748 Each element in this list must be a list, with the in-buffer keyword as car,
749 and a property (a symbol) as the next element. All occurrences of the
750 keyword will be found, the values concatenated with a space character
751 in between, and the result stored in the export options property list.")
753 (defvar org-export-options-filters nil
754 "Functions to be called to finalize the export/publishing options.
755 All these options are stored in a property list, and each of the functions
756 in this hook gets a chance to modify this property list. Each function
757 must accept the property list as an argument, and must return the (possibly
760 ;; FIXME: should we fold case here?
762 (defun org-infile-export-plist ()
763 "Return the property list with file-local settings for export."
767 (goto-char (point-min))
768 (let ((re (org-make-options-regexp
770 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
772 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
773 "LATEX_HEADER" "LATEX_CLASS" "LATEX_CLASS_OPTIONS"
774 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
775 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
776 (mapcar 'car org-export-inbuffer-options-extra
))))
778 p key val text options mathjax a pr style
779 latex-header latex-class latex-class-options macros letbind
780 ext-setup-or-nil setup-file setup-dir setup-contents
(start 0))
781 (while (or (and ext-setup-or-nil
782 (string-match re ext-setup-or-nil start
)
783 (setq start
(match-end 0)))
784 (and (setq ext-setup-or-nil nil start
0)
785 (re-search-forward re nil t
)))
786 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
787 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
789 ((setq a
(assoc key org-export-inbuffer-options-extra
))
791 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
792 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
793 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
794 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
795 ((string-equal key
"DATE")
796 ;; If date is an Org timestamp, convert it to a time
797 ;; string using `org-export-date-timestamp-format'
798 (when (string-match org-ts-regexp3 val
)
799 (setq val
(format-time-string
800 org-export-date-timestamp-format
801 (apply 'encode-time
(org-parse-time-string
802 (match-string 0 val
))))))
803 (setq p
(plist-put p
:date val
)))
804 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
805 ((string-equal key
"DESCRIPTION")
806 (setq p
(plist-put p
:description val
)))
807 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
808 ((string-equal key
"STYLE")
809 (setq style
(concat style
"\n" val
)))
810 ((string-equal key
"LATEX_HEADER")
811 (setq latex-header
(concat latex-header
"\n" val
)))
812 ((string-equal key
"LATEX_CLASS")
813 (setq latex-class val
))
814 ((string-equal key
"LATEX_CLASS_OPTIONS")
815 (setq latex-class-options val
))
816 ((string-equal key
"TEXT")
817 (setq text
(if text
(concat text
"\n" val
) val
)))
818 ((string-equal key
"OPTIONS")
819 (setq options
(concat val
" " options
)))
820 ((string-equal key
"MATHJAX")
821 (setq mathjax
(concat val
" " mathjax
)))
822 ((string-equal key
"BIND")
823 (push (read (concat "(" val
")")) letbind
))
824 ((string-equal key
"XSLT")
825 (setq p
(plist-put p
:xslt val
)))
826 ((string-equal key
"LINK_UP")
827 (setq p
(plist-put p
:link-up val
)))
828 ((string-equal key
"LINK_HOME")
829 (setq p
(plist-put p
:link-home val
)))
830 ((string-equal key
"EXPORT_SELECT_TAGS")
831 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
832 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
833 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
834 ((string-equal key
"MACRO")
836 ((equal key
"SETUPFILE")
837 (setq setup-file
(org-remove-double-quotes (org-trim val
))
838 ;; take care of recursive inclusion of setupfiles
839 setup-file
(if (or (file-name-absolute-p val
) (not setup-dir
))
840 (expand-file-name setup-file
)
841 (let ((default-directory setup-dir
))
842 (expand-file-name setup-file
))))
843 (setq setup-dir
(file-name-directory setup-file
))
844 (setq setup-contents
(org-file-contents setup-file
'noerror
))
845 (if (not ext-setup-or-nil
)
846 (setq ext-setup-or-nil setup-contents start
0)
847 (setq ext-setup-or-nil
848 (concat (substring ext-setup-or-nil
0 start
)
849 "\n" setup-contents
"\n"
850 (substring ext-setup-or-nil start
)))))))
851 (setq p
(plist-put p
:text text
))
852 (when (and letbind
(org-export-confirm-letbind))
853 (setq p
(plist-put p
:let-bind letbind
)))
854 (when style
(setq p
(plist-put p
:style-extra style
)))
856 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
858 (setq p
(plist-put p
:latex-class latex-class
)))
859 (when latex-class-options
860 (setq p
(plist-put p
:latex-class-options latex-class-options
)))
862 (setq p
(org-export-add-options-to-plist p options
)))
864 (setq p
(plist-put p
:mathjax mathjax
)))
865 ;; Add macro definitions
866 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
867 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
868 (setq p
(plist-put p
:macro-property
"(eval (org-entry-get nil \"$1\" 'selective))"))
870 p
:macro-modification-time
871 (and (buffer-file-name)
872 (file-exists-p (buffer-file-name))
874 "(eval (format-time-string \"$1\" '"
875 (prin1-to-string (nth 5 (file-attributes
876 (buffer-file-name))))
878 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
879 (file-name-nondirectory
880 (buffer-file-name)))))
881 (while (setq val
(pop macros
))
882 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
885 (concat ":macro-" (downcase (match-string 1 val
))))
886 (org-export-interpolate-newlines (match-string 2 val
))))))
889 (defun org-export-interpolate-newlines (s)
890 (while (string-match "\\\\n" s
)
891 (setq s
(replace-match "\n" t t s
)))
894 (defvar org-export-allow-BIND-local nil
)
895 (defun org-export-confirm-letbind ()
896 "Can we use #+BIND values during export?
897 By default this will ask for confirmation by the user, to divert possible
900 ((not org-export-allow-BIND
) nil
)
901 ((eq org-export-allow-BIND t
) t
)
902 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
903 org-export-allow-BIND-local
)
904 (t (org-set-local 'org-export-allow-BIND-local
905 (yes-or-no-p "Allow BIND values in this buffer? ")))))
907 (defun org-install-letbind ()
908 "Install the values from #+BIND lines as local variables."
909 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
911 (while (setq pair
(pop letbind
))
912 (org-set-local (car pair
) (nth 1 pair
)))))
914 (defun org-export-add-options-to-plist (p options
)
915 "Parse an OPTIONS line and set values in the property list P."
918 (let ((op org-export-plist-vars
))
919 (while (setq o
(pop op
))
921 (string-match (concat "\\(\\`\\|[ \t]\\)"
922 (regexp-quote (nth 1 o
))
923 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
925 (setq p
(plist-put p
(car o
)
926 (car (read-from-string
927 (match-string 2 options
))))))))))
930 (defun org-export-add-subtree-options (p pos
)
931 "Add options in subtree at position POS to property list P."
934 (when (org-at-heading-p)
936 ;; This is actually read in `org-export-get-title-from-subtree'
937 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
938 ;; (setq p (plist-put p :title a)))
939 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
940 (setq p
(plist-put p
:text a
)))
941 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
942 (setq p
(plist-put p
:author a
)))
943 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
944 (setq p
(plist-put p
:date a
)))
945 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
946 (setq p
(org-export-add-options-to-plist p a
)))))
949 (defun org-export-directory (type plist
)
950 (let* ((val (plist-get plist
:publishing-directory
))
952 (or (cdr (assoc type val
)) ".")
956 (defun org-export-process-option-filters (plist)
957 (let ((functions org-export-options-filters
) f
)
958 (while (setq f
(pop functions
))
959 (setq plist
(funcall f plist
))))
963 (defun org-export (&optional arg
)
964 "Export dispatcher for Org-mode.
965 When `org-export-run-in-background' is non-nil, try to run the command
966 in the background. This will be done only for commands that write
967 to a file. For details see the docstring of `org-export-run-in-background'.
969 The prefix argument ARG will be passed to the exporter. However, if
970 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
971 that means to inverse the
972 value of `org-export-run-in-background'.
974 If `org-export-initial-scope' is set to 'subtree, try to export
975 the current subtree, otherwise try to export the whole buffer.
976 Pressing `1' will switch between these two options."
978 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
979 (subtree-p (or (org-region-active-p)
980 (eq org-export-initial-scope
'subtree
)))
981 (regb (and (org-region-active-p) (region-beginning)))
982 (rege (and (org-region-active-p) (region-end)))
983 (help "[t] insert the export option template
984 \[v] limit export to visible part of outline tree
985 \[1] switch buffer/subtree export
986 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
988 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
990 \[h] export as HTML [H] to temporary buffer [R] export region
991 \[b] export as HTML and open in browser
993 \[l] export as LaTeX [L] to temporary buffer
994 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
996 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
998 \[o] export as OpenDocument Text [O] ... and open
1000 \[j] export as TaskJuggler [J] ... and open
1002 \[m] export as Freemind mind map
1004 \[g] export using Wes Hardaker's generic exporter
1006 \[i] export current file as iCalendar file
1007 \[I] export all agenda files as iCalendar files [c] ...as one combined file
1009 \[F] publish current file [P] publish current project
1010 \[X] publish a project... [E] publish every projects")
1012 '((?t org-insert-export-options-template nil
)
1013 (?v org-export-visible nil
)
1014 (?a org-export-as-ascii t
)
1015 (?A org-export-as-ascii-to-buffer t
)
1016 (?n org-export-as-latin1 t
)
1017 (?N org-export-as-latin1-to-buffer t
)
1018 (?u org-export-as-utf8 t
)
1019 (?U org-export-as-utf8-to-buffer t
)
1020 (?h org-export-as-html t
)
1021 (?b org-export-as-html-and-open t
)
1022 (?H org-export-as-html-to-buffer nil
)
1023 (?R org-export-region-as-html nil
)
1024 (?x org-export-as-xoxo t
)
1025 (?g org-export-generic t
)
1026 (?D org-export-as-docbook t
)
1027 (?V org-export-as-docbook-pdf-and-open t
)
1028 (?o org-export-as-odt t
)
1029 (?O org-export-as-odt-and-open t
)
1030 (?j org-export-as-taskjuggler t
)
1031 (?J org-export-as-taskjuggler-and-open t
)
1032 (?m org-export-as-freemind t
)
1033 (?l org-export-as-latex t
)
1034 (?p org-export-as-pdf t
)
1035 (?d org-export-as-pdf-and-open t
)
1036 (?L org-export-as-latex-to-buffer nil
)
1037 (?i org-export-icalendar-this-file t
)
1038 (?I org-export-icalendar-all-agenda-files t
)
1039 (?c org-export-icalendar-combine-agenda-files t
)
1040 (?F org-publish-current-file t
)
1041 (?P org-publish-current-project t
)
1043 (?E org-publish-all t
)))
1045 (cpos (point)) (cbuf (current-buffer)) bpos
)
1047 (save-window-excursion
1049 (message "Export subtree: ")
1050 (message "Export buffer: "))
1051 (delete-other-windows)
1052 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1054 (org-fit-window-to-buffer (get-buffer-window
1055 "*Org Export/Publishing Help*"))
1056 (while (eq (setq r1
(read-char-exclusive)) ?
1)
1058 (setq subtree-p nil
)
1059 (message "Export buffer: "))
1065 (setq regb
(and (org-region-active-p) (region-beginning)))
1066 (setq rege
(and (org-region-active-p) (region-end)))
1067 (message "Export subtree: "))))
1069 (let ((case-fold-search t
)
1070 (end (save-excursion (while (org-up-heading-safe)) (point))))
1071 (outline-next-heading)
1072 (if (re-search-backward
1073 "^[ \t]+\\(:latex_class:\\|:export_title:\\|:export_file_name:\\)[ \t]+\\S-"
1076 (org-back-to-heading t
)
1079 (message "Select command (for subtree): ")
1080 (setq r1
(read-char-exclusive)))
1081 (error "No enclosing node with LaTeX_CLASS or EXPORT_TITLE or EXPORT_FILE_NAME")
1083 (if (fboundp 'redisplay
) (redisplay)) ;; XEmacs does not have/need (redisplay)
1084 (and bpos
(goto-char bpos
))
1085 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1086 (unless (setq ass
(assq r2 cmds
))
1087 (error "No command associated with key %c" r1
))
1088 (if (and bg
(nth 2 ass
)
1089 (not (buffer-base-buffer))
1090 (not (org-region-active-p)))
1091 ;; execute in background
1092 (let ((p (start-process
1093 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1095 (expand-file-name invocation-name invocation-directory
)
1098 "--eval" "(require 'org-exp)"
1099 "--eval" "(setq org-wait .2)"
1101 "-f" (symbol-name (nth 1 ass
)))))
1102 (set-process-sentinel p
'org-export-process-sentinel
)
1103 (message "Background process \"%s\": started" p
))
1104 ;; set the mark correctly when exporting a subtree
1105 (if subtree-p
(let (deactivate-mark) (push-mark rege t t
) (goto-char regb
)))
1107 (call-interactively (nth 1 ass
))
1108 (when (and bpos
(get-buffer-window cbuf
))
1109 (let ((cw (selected-window)))
1110 (select-window (get-buffer-window cbuf
))
1113 (select-window cw
))))))
1115 (defun org-export-process-sentinel (process status
)
1116 (if (string-match "\n+\\'" status
)
1117 (setq status
(substring status
0 -
1)))
1118 (message "Background process \"%s\": %s" process status
))
1120 ;;; General functions for all backends
1122 (defvar org-export-target-aliases nil
1123 "Alist of targets with invisible aliases.")
1124 (defvar org-export-preferred-target-alist nil
1125 "Alist of section id's with preferred aliases.")
1126 (defvar org-export-id-target-alist nil
1127 "Alist of section id's with preferred aliases.")
1128 (defvar org-export-code-refs nil
1129 "Alist of code references and line numbers.")
1131 (defun org-export-preprocess-string (string &rest parameters
)
1132 "Cleanup STRING so that the true exported has a more consistent source.
1133 This function takes STRING, which should be a buffer-string of an org-file
1134 to export. It then creates a temporary buffer where it does its job.
1135 The result is then again returned as a string, and the exporter works
1136 on this string to produce the exported version."
1138 (let* ((org-export-current-backend (or (plist-get parameters
:for-backend
)
1139 org-export-current-backend
))
1140 (archived-trees (plist-get parameters
:archived-trees
))
1141 (inhibit-read-only t
)
1142 (drawers org-drawers
)
1143 (source-buffer (current-buffer))
1146 (setq org-export-target-aliases nil
1147 org-export-preferred-target-alist nil
1148 org-export-id-target-alist nil
1149 org-export-code-refs nil
)
1154 (setq case-fold-search t
)
1156 (let ((inhibit-read-only t
))
1157 (remove-text-properties (point-min) (point-max)
1160 ;; Remove license-to-kill stuff
1161 ;; The caller marks some stuff for killing, stuff that has been
1162 ;; used to create the page title, for example.
1163 (org-export-kill-licensed-text)
1165 (let ((org-inhibit-startup t
)) (org-mode))
1166 (setq case-fold-search t
)
1167 (org-clone-local-variables source-buffer
"^\\(org-\\|orgtbl-\\)")
1168 (org-install-letbind)
1171 (run-hooks 'org-export-preprocess-hook
)
1173 (untabify (point-min) (point-max))
1175 ;; Handle include files, and call a hook
1176 (org-export-handle-include-files-recurse)
1177 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1179 ;; Get rid of archived trees
1180 (org-export-remove-archived-trees archived-trees
)
1182 ;; Remove comment environment and comment subtrees
1183 (org-export-remove-comment-blocks-and-subtrees)
1185 ;; Get rid of excluded trees, and call a hook
1186 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1187 (plist-get parameters
:exclude-tags
))
1188 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1190 ;; Get rid of tasks, depending on configuration
1191 (org-export-remove-tasks (plist-get parameters
:tasks
))
1193 ;; Prepare footnotes for export. During that process, footnotes
1194 ;; actually included in the exported part of the buffer go
1195 ;; though some transformations:
1197 ;; 1. They have their label normalized (like "[N]");
1199 ;; 2. They get moved at the same place in the buffer (usually at
1200 ;; its end, but backends may define another place via
1201 ;; `org-footnote-insert-pos-for-preprocessor');
1203 ;; 3. The are stored in `org-export-footnotes-seen', while
1204 ;; `org-export-preprocess-string' is applied to their
1207 ;; Line-wise exporters ignore `org-export-footnotes-seen', as
1208 ;; they interpret footnotes at the moment they see them in the
1209 ;; buffer. Context-wise exporters grab all the info needed in
1210 ;; that variable and delete moved definitions (as described in
1212 (when (plist-get parameters
:footnotes
)
1213 (org-footnote-normalize nil parameters
))
1215 ;; Change lists ending. Other parts of export may insert blank
1216 ;; lines and lists' structure could be altered.
1217 (org-export-mark-list-end)
1219 ;; Process the macros
1220 (org-export-preprocess-apply-macros)
1221 (run-hooks 'org-export-preprocess-after-macros-hook
)
1223 ;; Export code blocks
1224 (org-export-blocks-preprocess)
1226 ;; Mark lists with properties
1227 (org-export-mark-list-properties)
1229 ;; Handle source code snippets
1230 (org-export-replace-src-segments-and-examples)
1232 ;; Protect short examples marked by a leading colon
1233 (org-export-protect-colon-examples)
1236 (org-export-convert-protected-spaces)
1238 ;; Find all headings and compute the targets for them
1239 (setq target-alist
(org-export-define-heading-targets target-alist
))
1241 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1243 ;; Find HTML special classes for headlines
1244 (org-export-remember-html-container-classes)
1246 ;; Get rid of drawers
1247 (org-export-remove-or-extract-drawers
1248 drawers
(plist-get parameters
:drawers
))
1250 ;; Get the correct stuff before the first headline
1251 (when (plist-get parameters
:skip-before-1st-heading
)
1252 (goto-char (point-min))
1253 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1254 (delete-region (point-min) (match-beginning 0))
1255 (goto-char (point-min))
1257 (when (plist-get parameters
:add-text
)
1258 (goto-char (point-min))
1259 (insert (plist-get parameters
:add-text
) "\n"))
1261 ;; Remove todo-keywords before exporting, if the user has requested so
1262 (org-export-remove-headline-metadata parameters
)
1264 ;; Find targets in comments and move them out of comments,
1265 ;; but mark them as targets that should be invisible
1266 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1268 ;; Select and protect backend specific stuff, throw away stuff
1269 ;; that is specific for other backends
1270 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1271 (org-export-select-backend-specific-text)
1273 ;; Protect quoted subtrees
1274 (org-export-protect-quoted-subtrees)
1276 ;; Remove clock lines
1277 (org-export-remove-clock-lines)
1279 ;; Protect verbatim elements
1280 (org-export-protect-verbatim)
1282 ;; Blockquotes, verse, and center
1283 (org-export-mark-blockquote-verse-center)
1284 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1286 ;; Remove timestamps, if the user has requested so
1287 (unless (plist-get parameters
:timestamps
)
1288 (org-export-remove-timestamps))
1290 ;; Attach captions to the correct object
1291 (setq target-alist
(org-export-attach-captions-and-attributes target-alist
))
1293 ;; Find matches for radio targets and turn them into internal links
1294 (org-export-mark-radio-links)
1295 (run-hooks 'org-export-preprocess-after-radio-targets-hook
)
1297 ;; Find all links that contain a newline and put them into a single line
1298 (org-export-concatenate-multiline-links)
1300 ;; Normalize links: Convert angle and plain links into bracket links
1301 ;; and expand link abbreviations
1302 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1303 (org-export-normalize-links)
1305 ;; Find all internal links. If they have a fuzzy match (i.e. not
1306 ;; a *dedicated* target match, let the link point to the
1307 ;; corresponding section.
1308 (org-export-target-internal-links target-alist
)
1310 ;; Find multiline emphasis and put them into single line
1311 (when (plist-get parameters
:emph-multiline
)
1312 (org-export-concatenate-multiline-emphasis))
1314 ;; Remove special table lines, and store alignment information
1315 (org-store-forced-table-alignment)
1316 (when org-export-table-remove-special-lines
1317 (org-export-remove-special-table-lines))
1320 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1322 ;; Backend-specific preprocessing
1323 (let* ((backend-name (symbol-name org-export-current-backend
))
1324 (f (intern (format "org-export-%s-preprocess" backend-name
))))
1325 (require (intern (concat "org-" backend-name
)) nil
)
1326 (funcall f parameters
))
1328 ;; Remove or replace comments
1329 (org-export-handle-comments (plist-get parameters
:comments
))
1331 ;; Remove #+TBLFM #+TBLNAME #+NAME #+RESULTS lines
1332 (org-export-handle-metalines)
1334 ;; Run the final hook
1335 (run-hooks 'org-export-preprocess-final-hook
)
1337 (setq rtn
(buffer-string)))
1340 (defun org-export-kill-licensed-text ()
1341 "Remove all text that is marked with a :org-license-to-kill property."
1343 (while (setq p
(text-property-any (point-min) (point-max)
1344 :org-license-to-kill t
))
1346 p
(or (next-single-property-change p
:org-license-to-kill
)
1349 (defvar org-export-define-heading-targets-headline-hook nil
1350 "Hook that is run when a headline was matched during target search.
1351 This is part of the preprocessing for export.")
1353 (defun org-export-define-heading-targets (target-alist)
1354 "Find all headings and define the targets for them.
1355 The new targets are added to TARGET-ALIST, which is also returned.
1356 Also find all ID and CUSTOM_ID properties and store them."
1357 (goto-char (point-min))
1358 (org-init-section-numbers)
1359 (let ((re (concat "^" org-outline-regexp
1361 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1362 level target last-section-target a id
)
1363 (while (re-search-forward re nil t
)
1364 (org-if-unprotected-at (match-beginning 0)
1367 (setq id
(org-match-string-no-properties 2))
1368 (push (cons id target
) target-alist
)
1369 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1371 (push (list last-section-target
)
1372 org-export-target-aliases
)
1373 (car org-export-target-aliases
))))
1374 (push (caar target-alist
) (cdr a
))
1375 (when (equal (match-string 1) "CUSTOM_ID")
1376 (if (not (assoc last-section-target
1377 org-export-preferred-target-alist
))
1378 (push (cons last-section-target id
)
1379 org-export-preferred-target-alist
)))
1380 (when (equal (match-string 1) "ID")
1381 (if (not (assoc last-section-target
1382 org-export-id-target-alist
))
1383 (push (cons last-section-target
(concat "ID-" id
))
1384 org-export-id-target-alist
))))
1385 (setq level
(org-reduced-level
1386 (save-excursion (goto-char (point-at-bol))
1387 (org-outline-level))))
1388 (setq target
(org-solidify-link-text
1389 (format "sec-%s" (replace-regexp-in-string
1391 (org-section-number level
)))))
1392 (setq last-section-target target
)
1393 (push (cons target target
) target-alist
)
1394 (add-text-properties
1395 (point-at-bol) (point-at-eol)
1396 (list 'target target
))
1397 (run-hooks 'org-export-define-heading-targets-headline-hook
)))))
1400 (defun org-export-handle-invisible-targets (target-alist)
1401 "Find targets in comments and move them out of comments.
1402 Mark them as invisible targets."
1404 (goto-char (point-min))
1405 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1406 ;; Check if the line before or after is a headline with a target
1407 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1408 (get-text-property (point-at-bol 2) 'target
)))
1410 ;; use the existing target in a neighboring line
1411 (setq tmp
(match-string 2))
1413 (and (looking-at "\n") (delete-char 1))
1414 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1416 (setq a
(or (assoc target org-export-target-aliases
)
1418 (push (list target
) org-export-target-aliases
)
1419 (car org-export-target-aliases
))))
1421 ;; Make an invisible target
1422 (replace-match "\\1(INVISIBLE)"))))
1425 (defun org-export-target-internal-links (target-alist)
1426 "Find all internal links and assign targets to them.
1427 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1428 let the link point to the corresponding section.
1429 This function also handles the id links, if they have a match in
1431 (goto-char (point-min))
1432 (while (re-search-forward org-bracket-link-regexp nil t
)
1433 (org-if-unprotected-at (1+ (match-beginning 0))
1434 (let* ((org-link-search-must-match-exact-headline t
)
1436 (desc (match-end 2))
1437 (link (org-link-unescape (match-string 1)))
1438 (slink (org-solidify-link-text link
))
1439 found props pos cref
1442 ((= (string-to-char link
) ?
#)
1443 ;; user wants exactly this link
1445 ((cdr (assoc slink target-alist
))
1446 (or (cdr (assoc (assoc slink target-alist
)
1447 org-export-preferred-target-alist
))
1448 (cdr (assoc slink target-alist
))))
1449 ((and (string-match "^id:" link
)
1450 (cdr (assoc (substring link
3) target-alist
))))
1451 ((string-match "^(\\(.*\\))$" link
)
1452 (setq cref
(match-string 1 link
))
1453 (concat "coderef:" cref
))
1454 ((string-match org-link-types-re link
) nil
)
1455 ((or (file-name-absolute-p link
)
1456 (string-match "^\\." link
))
1459 (let ((org-link-search-inhibit-query t
))
1461 (setq found
(condition-case nil
(org-link-search link
)
1464 (or (org-at-heading-p)
1465 (not (eq found
'dedicated
))))
1466 (or (get-text-property (point) 'target
)
1469 (1- (or (previous-single-property-change
1470 (point) 'target
) 0)))
1474 (goto-char (match-beginning 1))
1475 (setq props
(text-properties-at (point)))
1476 (delete-region (match-beginning 1) (match-end 1))
1479 (unless desc
(insert "][" link
))
1480 (add-text-properties pos
(point) props
))))))
1482 (defun org-export-remember-html-container-classes ()
1483 "Store the HTML_CONTAINER_CLASS properties in a text property."
1484 (goto-char (point-min))
1486 (while (re-search-forward
1487 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t
)
1488 (setq class
(match-string 1))
1490 (when (re-search-backward "^\\*" (point-min) t
)
1491 (org-back-to-heading t
)
1492 (put-text-property (point-at-bol) (point-at-eol)
1493 'html-container-class class
))))))
1495 (defvar org-export-format-drawer-function nil
1496 "Function to be called to format the contents of a drawer.
1497 The function must accept two parameters:
1498 NAME the drawer name, like \"PROPERTIES\"
1499 CONTENT the content of the drawer.
1500 You can check the export backend through `org-export-current-backend'.
1501 The function should return the text to be inserted into the buffer.
1502 If this is nil, `org-export-format-drawer' is used as a default.")
1504 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1505 "Remove drawers, or extract and format the content.
1506 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1507 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1508 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1509 EXP-DRAWERS will be removed."
1510 (goto-char (point-min))
1511 (let ((re (concat "^[ \t]*:\\("
1512 (mapconcat 'identity all-drawers
"\\|")
1514 name beg beg-content eol content
)
1515 (while (re-search-forward re nil t
)
1517 (setq name
(match-string 1))
1518 (setq beg
(match-beginning 0)
1519 beg-content
(1+ (point-at-eol))
1521 (if (not (and (re-search-forward
1522 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1525 (goto-char (match-beginning 0))
1526 (and (looking-at ".*\n?") (replace-match ""))
1527 (setq content
(buffer-substring beg-content
(point)))
1528 (delete-region beg
(point))
1529 (when (or (eq exp-drawers t
)
1530 (member name exp-drawers
))
1531 (setq content
(funcall (or org-export-format-drawer-function
1532 'org-export-format-drawer
)
1534 (insert content
)))))))
1536 (defun org-export-format-drawer (name content
)
1537 "Format the content of a drawer as a colon example."
1538 (if (string-match "[ \t]+\\'" content
)
1539 (setq content
(substring content
(match-beginning 0))))
1540 (while (string-match "\\`[ \t]*\n" content
)
1541 (setq content
(substring content
(match-end 0))))
1542 (setq content
(org-remove-indentation content
))
1543 (setq content
(concat ": " (mapconcat 'identity
1544 (org-split-string content
"\n")
1547 (setq content
(concat " : " (upcase name
) "\n" content
))
1548 (org-add-props content nil
'org-protected t
))
1550 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1551 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1552 Both arguments are lists of tags.
1553 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1555 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1557 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1558 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1561 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1565 (goto-char (point-min))
1566 (when (and select-tags
1568 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1569 ;; At least one tree is marked for export, this means
1570 ;; all the unmarked stuff needs to go.
1571 ;; Dig out the trees that should be exported
1572 (goto-char (point-min))
1573 (outline-next-heading)
1575 (put-text-property beg
(point-max) :org-delete t
)
1576 (while (re-search-forward re-sel nil t
)
1577 (when (org-at-heading-p)
1578 (org-back-to-heading)
1579 (remove-text-properties
1580 (max (1- (point)) (point-min))
1581 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1583 (while (and (org-up-heading-safe)
1584 (get-text-property (point) :org-delete
))
1585 (remove-text-properties (max (1- (point)) (point-min))
1586 (point-at-eol) '(:org-delete t
)))
1588 ;; Remove the trees explicitly marked for noexport
1590 (goto-char (point-min))
1591 (while (re-search-forward re-excl nil t
)
1592 (when (org-at-heading-p)
1593 (org-back-to-heading t
)
1595 (org-end-of-subtree t t
)
1596 (delete-region beg
(point))
1597 (when (featurep 'org-inlinetask
)
1598 (org-inlinetask-remove-END-maybe)))))
1599 ;; Remove everything that is now still marked for deletion
1600 (goto-char (point-min))
1601 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1602 (setq end
(or (next-single-property-change beg
:org-delete
)
1604 (delete-region beg end
))))
1606 (defun org-export-remove-tasks (keep)
1607 "Remove tasks depending on configuration.
1608 When KEEP is nil, remove all tasks.
1609 When KEEP is `todo', remove the tasks that are DONE.
1610 When KEEP is `done', remove the tasks that are not yet done.
1611 When it is a list of strings, keep only tasks with these TODO keywords."
1612 (when (or (listp keep
) (memq keep
'(todo done nil
)))
1613 (let ((re (concat "^\\*+[ \t]+\\("
1616 (cond ((not keep
) org-todo-keywords-1
)
1617 ((eq keep
'todo
) org-done-keywords
)
1618 ((eq keep
'done
) org-not-done-keywords
)
1620 (org-delete-all keep
(copy-sequence
1621 org-todo-keywords-1
))))
1623 "\\)\\($\\|[ \t]\\)"))
1624 (case-fold-search nil
)
1626 (goto-char (point-min))
1627 (while (re-search-forward re nil t
)
1629 (setq beg
(match-beginning 0))
1630 (org-end-of-subtree t t
)
1631 (if (looking-at "^\\*+[ \t]+END[ \t]*$")
1632 ;; Kill the END line of the inline task
1633 (goto-char (min (point-max) (1+ (match-end 0)))))
1634 (delete-region beg
(point)))))))
1636 (defun org-export-remove-archived-trees (export-archived-trees)
1637 "Remove archived trees.
1638 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1639 When it is t, the entire archived tree will be exported.
1640 When it is nil the entire tree including the headline will be removed
1642 (let ((re-archive (concat ":" org-archive-tag
":"))
1644 (when (not (eq export-archived-trees t
))
1645 (goto-char (point-min))
1646 (while (re-search-forward re-archive nil t
)
1647 (if (not (org-at-heading-p t
))
1648 (goto-char (point-at-eol))
1649 (beginning-of-line 1)
1650 (setq a
(if export-archived-trees
1651 (1+ (point-at-eol)) (point))
1652 b
(org-end-of-subtree t
))
1653 (if (> b a
) (delete-region a b
)))))))
1655 (defun org-export-remove-headline-metadata (opts)
1656 "Remove meta data from the headline, according to user options."
1657 (let ((re org-complex-heading-regexp
)
1658 (todo (plist-get opts
:todo-keywords
))
1659 (tags (plist-get opts
:tags
))
1660 (pri (plist-get opts
:priority
))
1662 (case-fold-search nil
)
1664 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1665 (when (or (not todo
) (not tags
) (not pri
))
1666 (goto-char (point-min))
1667 (while (re-search-forward re nil t
)
1669 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1671 (replace-match rpl t t
))))))
1673 (defun org-export-remove-timestamps ()
1674 "Remove timestamps and keywords for export."
1675 (goto-char (point-min))
1676 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1679 (unless (save-match-data (org-at-table-p))
1681 (beginning-of-line 1)
1682 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1683 (replace-match ""))))))
1685 (defun org-export-remove-clock-lines ()
1686 "Remove clock lines for export."
1687 (goto-char (point-min))
1688 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1689 (while (re-search-forward re nil t
)
1691 (replace-match "")))))
1693 (defvar org-heading-keyword-regexp-format
) ; defined in org.el
1694 (defun org-export-protect-quoted-subtrees ()
1695 "Mark quoted subtrees with the protection property."
1696 (let ((org-re-quote (format org-heading-keyword-regexp-format
1698 (goto-char (point-min))
1699 (while (re-search-forward org-re-quote nil t
)
1700 (goto-char (match-beginning 0))
1702 (add-text-properties (point) (org-end-of-subtree t
)
1703 '(org-protected t
)))))
1705 (defun org-export-convert-protected-spaces ()
1706 "Convert strings like \\____ to protected spaces in all backends."
1707 (goto-char (point-min))
1708 (while (re-search-forward "\\\\__+" nil t
)
1709 (org-if-unprotected-1
1713 ((eq org-export-current-backend
'latex
)
1714 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1715 ((eq org-export-current-backend
'html
)
1716 (org-add-props (match-string 0) nil
1717 'org-whitespace
(- (match-end 0) (match-beginning 0))))
1718 ;; ((eq org-export-current-backend 'docbook))
1719 ((eq org-export-current-backend
'ascii
)
1720 (org-add-props (match-string 0) '(org-whitespace t
)))
1721 (t (make-string (- (match-end 0) (match-beginning 0)) ?\
)))
1725 (defun org-export-protect-verbatim ()
1726 "Mark verbatim snippets with the protection property."
1727 (goto-char (point-min))
1728 (while (re-search-forward org-verbatim-re nil t
)
1730 (add-text-properties (match-beginning 4) (match-end 4)
1731 '(org-protected t org-verbatim-emph t
))
1732 (goto-char (1+ (match-end 4))))))
1734 (defun org-export-protect-colon-examples ()
1735 "Protect lines starting with a colon."
1736 (goto-char (point-min))
1737 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1738 (while (re-search-forward re nil t
)
1739 (beginning-of-line 1)
1741 (while (looking-at re
)
1743 (or (eobp) (forward-char 1)))
1744 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1745 '(org-protected t
)))))
1747 (defvar org-export-backends
1748 '(docbook html beamer ascii latex
)
1749 "List of Org supported export backends.")
1751 (defun org-export-select-backend-specific-text ()
1752 (let ((formatters org-export-backends
)
1753 (case-fold-search t
)
1754 backend backend-name beg beg-content end end-content ind
)
1757 (setq backend
(pop formatters
)
1758 backend-name
(symbol-name backend
))
1760 ;; Handle #+BACKEND: stuff
1761 (goto-char (point-min))
1762 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" backend-name
1763 ":[ \t]*\\(.*\\)") nil t
)
1764 (if (not (eq backend org-export-current-backend
))
1765 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1766 (let ((ind (get-text-property (point-at-bol) 'original-indentation
)))
1767 (replace-match "\\1\\2" t
)
1768 (add-text-properties
1769 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1770 `(org-protected t original-indentation
,ind org-native-text t
)))))
1771 ;; Delete #+ATTR_BACKEND: stuff of another backend. Those
1772 ;; matching the current backend will be taken care of by
1773 ;; `org-export-attach-captions-and-attributes'
1774 (goto-char (point-min))
1775 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+ATTR_" backend-name
1776 ":[ \t]*\\(.*\\)") nil t
)
1777 (setq ind
(org-get-indentation))
1778 (when (not (eq backend org-export-current-backend
))
1779 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1780 ;; Handle #+BEGIN_BACKEND and #+END_BACKEND stuff
1781 (goto-char (point-min))
1782 (while (re-search-forward (concat "^[ \t]*#\\+BEGIN_" backend-name
"\\>.*\n?")
1784 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1785 (setq ind
(or (get-text-property beg
'original-indentation
)
1786 (save-excursion (goto-char beg
) (org-get-indentation))))
1787 (when (re-search-forward (concat "^[ \t]*#\\+END_" backend-name
"\\>.*\n?")
1789 (setq end
(match-end 0) end-content
(match-beginning 0))
1790 (if (eq backend org-export-current-backend
)
1793 (add-text-properties
1794 beg-content end-content
1795 `(org-protected t original-indentation
,ind org-native-text t
))
1796 ;; strip protective commas
1797 (org-unescape-code-in-region beg-content end-content
)
1798 (delete-region (match-beginning 0) (match-end 0))
1801 (delete-region (point) (1+ (point-at-eol)))))
1802 ;; No, this is for a different backend, kill it
1803 (delete-region beg end
)))))))
1805 (defun org-export-mark-blockquote-verse-center ()
1806 "Mark block quote and verse environments with special cookies.
1807 These special cookies will later be interpreted by the backend."
1809 (let (type t1 ind beg end beg1 end1 content
)
1810 (goto-char (point-min))
1811 (while (re-search-forward
1812 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1814 (setq ind
(length (match-string 1))
1815 type
(downcase (match-string 3))
1816 t1
(if (equal type
"quote") "blockquote" type
))
1817 (setq beg
(match-beginning 0)
1818 beg1
(1+ (match-end 0)))
1819 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1820 (setq end1
(1- (match-beginning 0))
1821 end
(+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1822 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1823 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1825 "ORG-" (upcase t1
) "-END\n"))
1826 (delete-region beg end
)
1827 (insert (org-add-props content nil
'original-indentation ind
))))))
1829 (defun org-export-mark-list-end ()
1830 "Mark all list endings with a special string."
1831 (unless (eq org-export-current-backend
'ascii
)
1834 ;; For each type allowing list export, find every list, remove
1835 ;; ending regexp if needed, and insert org-list-end.
1836 (goto-char (point-min))
1837 (while (re-search-forward (org-item-beginning-re) nil t
)
1838 (when (eq (nth 2 (org-list-context)) e
)
1839 (let* ((struct (org-list-struct))
1840 (bottom (org-list-get-bottom-point struct
))
1841 (top (point-at-bol))
1842 (top-ind (org-list-get-ind top struct
)))
1844 (when (and (not (looking-at "[ \t]*$"))
1845 (looking-at org-list-end-re
))
1847 (unless (bolp) (insert "\n"))
1848 ;; As org-list-end is inserted at column 0, it would end
1849 ;; by indentation any list. It can be problematic when
1850 ;; there are lists within lists: the inner list end would
1851 ;; also become the outer list end. To avoid this, text
1852 ;; property `original-indentation' is added, as
1853 ;; `org-list-struct' pays attention to it when reading a
1855 (insert (org-add-props
1856 "ORG-LIST-END-MARKER\n"
1857 (list 'original-indentation top-ind
)))))))
1858 (cons nil org-list-export-context
))))
1860 (defun org-export-mark-list-properties ()
1861 "Mark list with special properties.
1862 These special properties will later be interpreted by the backend."
1865 ;; Mark a list with 3 properties: `list-item' which is
1866 ;; position at beginning of line, `list-struct' which is
1867 ;; list structure, and `list-prevs' which is the alist of
1868 ;; item and its predecessor. Leave point at list ending.
1870 (let* ((struct (org-list-struct))
1871 (top (org-list-get-top-point struct
))
1872 (bottom (org-list-get-bottom-point struct
))
1873 (prevs (org-list-prevs-alist struct
))
1875 ;; Get every item and ending position, without dups and
1876 ;; without bottom point of list.
1880 (unless (memq pos poi
)
1882 (unless (or (= end bottom
) (memq end poi
))
1885 (setq poi
(sort poi
'<))
1886 ;; For every point of interest, mark the whole line with
1887 ;; its position in list.
1891 (add-text-properties (point-at-bol) (point-at-eol)
1892 (list 'list-item
(point-at-bol)
1894 'list-prevs prevs
)))
1896 ;; Take care of bottom point. As babel may have inserted
1897 ;; a new list in buffer, list ending isn't always
1898 ;; marked. Now mark every list ending and add properties
1899 ;; useful to line processing exporters.
1901 (when (or (looking-at "^ORG-LIST-END-MARKER\n")
1902 (and (not (looking-at "[ \t]*$"))
1903 (looking-at org-list-end-re
)))
1905 (unless (bolp) (insert "\n"))
1907 (org-add-props "ORG-LIST-END-MARKER\n" (list 'list-item bottom
1909 'list-prevs prevs
)))
1910 ;; Following property is used by LaTeX exporter.
1911 (add-text-properties top
(point) (list 'list-context ctxt
)))))))
1912 ;; Mark lists except for backends not interpreting them.
1913 (unless (eq org-export-current-backend
'ascii
)
1914 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
1917 (goto-char (point-min))
1918 (while (re-search-forward (org-item-beginning-re) nil t
)
1919 (let ((context (nth 2 (org-list-context))))
1921 (funcall mark-list e
)
1922 (put-text-property (point-at-bol) (point-at-eol)
1923 'list-context context
)))))
1924 (cons nil org-list-export-context
))))))
1926 (defun org-export-attach-captions-and-attributes (target-alist)
1927 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1928 If the next thing following is a table, add the text properties to the first
1929 table line. If it is a link, add it to the line containing the link."
1930 (goto-char (point-min))
1931 (remove-text-properties (point-min) (point-max)
1932 '(org-caption nil org-attributes nil
))
1933 (let ((case-fold-search t
)
1934 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1936 "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend
) ":[ \t]+\\(.*\\)"
1938 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1940 "^[ \t]*\\(|[^-]\\)"
1942 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1943 cap shortn attr label end
)
1944 (while (re-search-forward re nil t
)
1946 ;; there is a caption
1949 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1))))
1950 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap
)
1951 (setq shortn
(match-string 1 cap
)
1952 cap
(match-string 2 cap
)))
1953 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1954 ;; there is an attribute
1957 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2))))
1958 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1962 (setq label
(org-trim (match-string 3)))
1963 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1965 (setq end
(if (match-end 4)
1966 (let ((ee (org-table-end)))
1967 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1969 (add-text-properties (point-at-bol) end
1970 (list 'org-caption cap
1971 'org-caption-shortn shortn
1972 'org-attributes attr
1974 (if label
(push (cons label label
) target-alist
))
1976 (setq cap nil shortn nil attr nil label nil
)))))
1979 (defun org-export-remove-comment-blocks-and-subtrees ()
1980 "Remove the comment environment, and also commented subtrees."
1981 (let ((re-commented (format org-heading-keyword-regexp-format
1982 org-comment-string
))
1984 ;; Remove comment environment
1985 (goto-char (point-min))
1986 (setq case-fold-search t
)
1987 (while (re-search-forward
1988 "^#\\+begin_comment[ \t]*\n[^\000]*?\n#\\+end_comment\\>.*" nil t
)
1989 (replace-match "" t t
))
1990 ;; Remove subtrees that are commented
1991 (goto-char (point-min))
1992 (setq case-fold-search nil
)
1993 (while (re-search-forward re-commented nil t
)
1994 (goto-char (match-beginning 0))
1995 (delete-region (point) (org-end-of-subtree t
)))))
1997 (defun org-export-handle-comments (org-commentsp)
1998 "Remove comments, or convert to backend-specific format.
1999 ORG-COMMENTSP can be a format string for publishing comments.
2000 When it is nil, all comments will be removed."
2001 (let ((re "^[ \t]*#\\( \\|$\\)"))
2002 (goto-char (point-min))
2003 (while (re-search-forward re nil t
)
2004 (let ((pos (match-beginning 0))
2005 (end (progn (forward-line) (point))))
2006 (if (get-text-property pos
'org-protected
)
2008 (if (not org-commentsp
) (delete-region pos end
)
2009 (add-text-properties pos end
'(org-protected t
))
2012 (format org-commentsp
(buffer-substring (match-end 0) end
))
2013 nil
'org-protected t
)
2015 ;; Hack attack: previous implementation also removed keywords at
2016 ;; column 0. Brainlessly do it again.
2017 (goto-char (point-min))
2018 (while (re-search-forward "^#\\+" nil t
)
2019 (unless (get-text-property (point-at-bol) 'org-protected
)
2020 (delete-region (point-at-bol) (progn (forward-line) (point)))))))
2022 (defun org-export-handle-metalines ()
2023 "Remove tables and source blocks metalines.
2024 This function should only be called after all block processing
2026 (let ((re "^[ \t]*#\\+\\(tbl\\(?:name\\|fm\\)\\|results\\(?:\\[[a-z0-9]+\\]\\)?\\|name\\):\\(.*\n?\\)")
2027 (case-fold-search t
)
2029 (goto-char (point-min))
2030 (while (or (looking-at re
)
2031 (re-search-forward re nil t
))
2032 (setq pos
(match-beginning 0))
2033 (if (get-text-property (match-beginning 1) 'org-protected
)
2034 (goto-char (1+ pos
))
2035 (goto-char (1+ pos
))
2037 (goto-char (max (point-min) (1- pos
)))))))
2039 (defun org-export-mark-radio-links ()
2040 "Find all matches for radio targets and turn them into internal links."
2041 (let ((re-radio (and org-target-link-regexp
2042 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
2043 (goto-char (point-min))
2045 (while (re-search-forward re-radio nil t
)
2048 (or (org-in-regexp org-bracket-link-regexp
)
2049 (org-in-regexp org-plain-link-re
)
2050 (org-in-regexp "<<[^<>]+>>")))
2052 (replace-match "\\1[[\\2]]")))))))
2054 (defun org-store-forced-table-alignment ()
2055 "Find table lines which force alignment, store the results in properties."
2056 (let (line cnt cookies
)
2057 (goto-char (point-min))
2058 (while (re-search-forward "|[ \t]*<\\([lrc]?[0-9]+\\|[lrc]\\)>[ \t]*|"
2060 ;; OK, this looks like a table line with an alignment cookie
2062 (setq line
(buffer-substring (point-at-bol) (point-at-eol)))
2063 (when (and (org-at-table-p)
2064 (org-table-cookie-line-p line
))
2065 (setq cnt
0 cookies nil
)
2069 (when (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'" x
)
2070 (let ((align (and (match-end 1)
2071 (downcase (match-string 1 x
))))
2072 (width (and (match-end 2)
2073 (string-to-number (match-string 2 x
)))))
2074 (push (cons cnt
(list align width
)) cookies
))))
2075 (org-split-string line
"[ \t]*|[ \t]*"))
2076 (add-text-properties (org-table-begin) (org-table-end)
2077 (list 'org-col-cookies cookies
))))
2078 (goto-char (point-at-eol)))))
2080 (defun org-export-remove-special-table-lines ()
2081 "Remove tables lines that are used for internal purposes.
2082 Also, store forced alignment information found in such lines."
2083 (goto-char (point-min))
2084 (while (re-search-forward "^[ \t]*|" nil t
)
2085 (org-if-unprotected-at (1- (point))
2086 (beginning-of-line 1)
2087 (if (or (looking-at "[ \t]*| *[!_^] *|")
2093 (or (and org-export-table-remove-empty-lines
(= (length f
) 0))
2095 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f
)))
2096 (org-split-string ;; FIXME, can't we do without splitting???
2097 (buffer-substring (point-at-bol) (point-at-eol))
2098 "[ \t]*|[ \t]*")))))
2099 (delete-region (max (point-min) (1- (point-at-bol)))
2103 (defun org-export-protect-sub-super (s)
2105 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
2106 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
2109 (defun org-export-normalize-links ()
2110 "Convert all links to bracket links, and expand link abbreviations."
2111 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2112 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
2114 (goto-char (point-min))
2115 (while (re-search-forward org-bracket-link-regexp nil t
)
2116 (put-text-property (match-beginning 0) (match-end 0) 'org-normalized-link t
))
2117 (goto-char (point-min))
2118 (while (re-search-forward re-plain-link nil t
)
2119 (unless (get-text-property (match-beginning 0) 'org-normalized-link
)
2120 (goto-char (1- (match-end 0)))
2121 (org-if-unprotected-at (1+ (match-beginning 0))
2122 (let* ((s (concat (match-string 1)
2123 "[[" (match-string 2) ":" (match-string 3)
2124 "][" (match-string 2) ":" (org-export-protect-sub-super
2127 ;; added 'org-link face to links
2128 (put-text-property 0 (length s
) 'face
'org-link s
)
2129 (replace-match s t t
)))))
2130 (goto-char (point-min))
2131 (while (re-search-forward re-angle-link nil t
)
2132 (goto-char (1- (match-end 0)))
2134 (let* ((s (concat (match-string 1)
2135 "[[" (match-string 2) ":" (match-string 3)
2136 "][" (match-string 2) ":" (org-export-protect-sub-super
2139 (put-text-property 0 (length s
) 'face
'org-link s
)
2140 (replace-match s t t
))))
2141 (goto-char (point-min))
2142 (while (re-search-forward org-bracket-link-regexp nil t
)
2143 (goto-char (1- (match-end 0)))
2144 (setq nodesc
(not (match-end 3)))
2146 (let* ((xx (save-match-data
2148 (org-link-expand-abbrev (match-string 1)))))
2150 "[[" (org-add-props (copy-sequence xx
)
2151 nil
'org-protected t
'org-no-description nodesc
)
2155 (concat "[" (copy-sequence xx
)
2158 (put-text-property 0 (length s
) 'face
'org-link s
)
2159 (replace-match s t t
))))))
2161 (defun org-export-concatenate-multiline-links ()
2162 "Find multi-line links and put it all into a single line.
2163 This is to make sure that the line-processing export backends
2164 can work correctly."
2165 (goto-char (point-min))
2166 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2167 (org-if-unprotected-at (match-beginning 1)
2168 (replace-match "\\1 \\3")
2169 (goto-char (match-beginning 0)))))
2171 (defun org-export-concatenate-multiline-emphasis ()
2172 "Find multi-line emphasis and put it all into a single line.
2173 This is to make sure that the line-processing export backends
2174 can work correctly."
2175 (goto-char (point-min))
2176 (while (re-search-forward org-emph-re nil t
)
2177 (if (and (not (= (char-after (match-beginning 3))
2178 (char-after (match-beginning 4))))
2179 (save-excursion (goto-char (match-beginning 0))
2181 (and (not (org-at-table-p))
2182 (not (org-at-heading-p))))))
2184 (subst-char-in-region (match-beginning 0) (match-end 0)
2186 (goto-char (1- (match-end 0))))
2187 (goto-char (1+ (match-beginning 0))))))
2189 (defun org-export-grab-title-from-buffer ()
2190 "Get a title for the current document, from looking at the buffer."
2191 (let ((inhibit-read-only t
))
2193 (goto-char (point-min))
2194 (let ((end (if (looking-at org-outline-regexp
)
2196 (save-excursion (outline-next-heading) (point)))))
2197 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2198 ;; Mark the line so that it will not be exported as normal text.
2199 (unless (org-in-block-p org-list-forbidden-blocks
)
2201 (add-text-properties (match-beginning 0) (match-end 0)
2202 (list :org-license-to-kill t
))))
2203 ;; Return the title string
2204 (org-trim (match-string 0)))))))
2206 (defun org-export-get-title-from-subtree ()
2207 "Return subtree title and exclude it from export."
2208 (let ((rbeg (region-beginning)) (rend (region-end))
2209 (inhibit-read-only t
)
2210 (tags (plist-get (org-infile-export-plist) :tags
))
2214 (when (and (org-at-heading-p)
2215 (>= (org-end-of-subtree t t
) rend
))
2216 (when (plist-member org-export-opt-plist
:tags
)
2217 (setq tags
(or (plist-get org-export-opt-plist
:tags
) tags
)))
2218 ;; This is a subtree, we take the title from the first heading
2220 (looking-at org-todo-line-tags-regexp
)
2221 (setq title
(if (and (eq tags t
) (match-string 4))
2222 (format "%s\t%s" (match-string 3) (match-string 4))
2225 (add-text-properties (point) (1+ (point-at-eol))
2226 (list :org-license-to-kill t
)))
2227 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2230 (defun org-solidify-link-text (s &optional alist
)
2231 "Take link text and make a safe target out of it."
2236 (org-split-string s
"[^a-zA-Z0-9_\\.-]+") "-"))
2237 (a (assoc rtn alist
)))
2240 (defun org-get-min-level (lines &optional offset
)
2241 "Get the minimum level in LINES."
2242 (let ((re "^\\(\\*+\\) ") l
)
2244 (while (setq l
(pop lines
))
2245 (if (string-match re l
)
2246 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2250 ;; Variable holding the vector with section numbers
2251 (defvar org-section-numbers
(make-vector org-level-max
0))
2253 (defun org-init-section-numbers ()
2254 "Initialize the vector for the section numbers."
2256 (numbers (nreverse (org-split-string "" "\\.")))
2257 (depth (1- (length org-section-numbers
)))
2258 (i depth
) number-string
)
2261 (aset org-section-numbers i
0)
2262 (setq number-string
(or (car numbers
) "0"))
2263 (if (string-match "\\`[A-Z]\\'" number-string
)
2264 (aset org-section-numbers i
2265 (- (string-to-char number-string
) ?A -
1))
2266 (aset org-section-numbers i
(string-to-number number-string
)))
2270 (defun org-section-number (&optional level
)
2271 "Return a string with the current section number.
2272 When LEVEL is non-nil, increase section numbers on that level."
2273 (let* ((depth (1- (length org-section-numbers
)))
2275 (fmts (car org-export-section-number-format
))
2276 (term (cdr org-export-section-number-format
))
2281 (aset org-section-numbers
2282 level
(1+ (aref org-section-numbers level
))))
2283 (setq idx
(1+ level
))
2284 (while (<= idx depth
)
2286 (aset org-section-numbers idx
0))
2287 (setq idx
(1+ idx
))))
2289 (while (<= idx depth
)
2290 (when (> (aref org-section-numbers idx
) 0)
2291 (setq fmt
(or (pop fmts
) fmt
)
2293 n
(aref org-section-numbers idx
)
2295 (concat string sep
(org-number-to-counter n ctype
))
2296 (concat string
".0"))
2298 (setq idx
(1+ idx
)))
2300 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2301 (setq string
(replace-match "" t nil string
)))
2302 (if (string-match "\\(\\.0\\)+\\'" string
)
2303 (setq string
(replace-match "" t nil string
))))
2304 (concat string term
)))
2306 (defun org-number-to-counter (n type
)
2307 "Concert number N to a string counter, according to TYPE.
2308 TYPE must be a string, any of:
2312 I upper case roman numeral
2313 i lower case roman numeral"
2315 ((equal type
"1") (number-to-string n
))
2316 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2317 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2318 ((equal type
"I") (org-number-to-roman n
))
2319 ((equal type
"i") (downcase (org-number-to-roman n
)))
2320 (t (error "Invalid counter type `%s'" type
))))
2322 (defun org-number-to-roman (n)
2323 "Convert integer N into a roman numeral."
2324 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2325 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2326 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2330 (number-to-string n
)
2332 (if (>= n
(caar roman
))
2333 (setq n
(- n
(caar roman
))
2334 res
(concat res
(cdar roman
)))
2340 (defun org-export-preprocess-apply-macros ()
2341 "Replace macro references."
2342 (goto-char (point-min))
2343 (let (sy val key args args2 ind-str s n
)
2344 (while (re-search-forward
2345 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2347 (unless (save-match-data (save-excursion
2348 (goto-char (point-at-bol))
2349 (looking-at "[ \t]*#\\+macro")))
2350 ;; Get macro name (KEY), arguments (ARGS), and indentation of
2351 ;; current line (IND-STR) as strings.
2352 (setq key
(downcase (match-string 1))
2353 args
(match-string 3)
2354 ind-str
(save-match-data (save-excursion
2356 (looking-at "^\\([ \t]*\\).*")
2358 ;; When macro is defined, retrieve replacement text in VAL,
2359 ;; and proceed with expansion.
2360 (when (setq val
(or (plist-get org-export-opt-plist
2361 (intern (concat ":macro-" key
)))
2362 (plist-get org-export-opt-plist
2363 (intern (concat ":" key
)))))
2365 ;; If arguments are provided, first retrieve them properly
2366 ;; (in ARGS, as a list), then replace them in VAL.
2368 (setq args
(org-split-string args
",") args2 nil
)
2370 (while (string-match "\\\\\\'" (car args
))
2371 ;; Repair bad splits.
2372 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2375 (push (pop args
) args2
))
2376 (setq args
(mapcar 'org-trim
(nreverse args2
)))
2378 (while (string-match "\\$\\([0-9]+\\)" val s
)
2379 (setq s
(1+ (match-beginning 0))
2380 n
(string-to-number (match-string 1 val
)))
2381 (and (>= (length args
) n
)
2382 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2383 ;; VAL starts with "(eval": it is a sexp, `eval' it.
2384 (when (string-match "\\`(eval\\>" val
)
2385 (setq val
(eval (read val
))))
2386 ;; Ensure VAL is a string (or nil) and that each new line
2387 ;; is indented as the first one.
2389 (mapconcat 'identity
2391 (if (stringp val
) val
(format "%s" val
))
2393 (concat "\n" ind-str
)))))
2394 ;; Eventually do the replacement, if VAL isn't nil. Move
2395 ;; point at beginning of macro for recursive expansions.
2397 (replace-match val t t
)
2398 (goto-char (match-beginning 0))))))))
2400 (defun org-export-apply-macros-in-string (s)
2401 "Apply the macros in string S."
2405 (org-export-preprocess-apply-macros)
2410 (defun org-export-handle-include-files ()
2411 "Include the contents of include files, with proper formatting."
2412 (let ((case-fold-search t
)
2413 params file markup lang start end prefix prefix1 switches all minlevel currentlevel addlevel lines
)
2414 (goto-char (point-min))
2415 (while (re-search-forward "^#\\+include:[ \t]+\\(.*\\)" nil t
)
2416 (setq params
(read (concat "(" (match-string 1) ")"))
2417 prefix
(org-get-and-remove-property 'params
:prefix
)
2418 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2419 minlevel
(org-get-and-remove-property 'params
:minlevel
)
2420 addlevel
(org-get-and-remove-property 'params
:addlevel
)
2421 lines
(org-get-and-remove-property 'params
:lines
)
2422 file
(org-symname-or-string (pop params
))
2423 markup
(org-symname-or-string (pop params
))
2424 lang
(and (member markup
'("src" "SRC"))
2425 (org-symname-or-string (pop params
)))
2426 switches
(mapconcat #'(lambda (x) (format "%s" x
)) params
" ")
2428 (delete-region (match-beginning 0) (match-end 0))
2429 (setq currentlevel
(or (org-current-level) 0))
2431 (not (file-exists-p file
))
2432 (not (file-readable-p file
)))
2433 (insert (format "CANNOT INCLUDE FILE %s" file
))
2434 (setq all
(cons file all
))
2436 (if (equal (downcase markup
) "src")
2437 (setq start
(format "#+begin_src %s %s\n"
2438 (or lang
"fundamental")
2441 (setq start
(format "#+begin_%s %s\n" markup switches
)
2442 end
(format "#+end_%s" markup
))))
2443 (insert (or start
""))
2444 (insert (org-get-file-contents (expand-file-name file
)
2445 prefix prefix1 markup currentlevel minlevel addlevel lines
))
2446 (or (bolp) (newline))
2447 (insert (or end
""))))
2450 (defun org-export-handle-include-files-recurse ()
2451 "Recursively include files aborting on circular inclusion."
2452 (let ((now (list org-current-export-file
)) all
)
2454 (setq all
(append now all
))
2455 (setq now
(org-export-handle-include-files))
2458 (mapcar (lambda (el) (when (member el all
) el
)) now
))))
2460 (error "Recursive #+INCLUDE: %S" intersection
))))))
2462 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel parentlevel addlevel lines
)
2463 "Get the contents of FILE and return them as a string.
2464 If PREFIX is a string, prepend it to each line. If PREFIX1
2465 is a string, prepend it to the first line instead of PREFIX.
2466 If MARKUP, don't protect org-like lines, the exporter will
2467 take care of the block they are in. If ADDLEVEL is a number,
2468 demote included file to current heading level+ADDLEVEL.
2469 If LINES is a string specifying a range of lines,
2470 include only those lines."
2471 (if (stringp markup
) (setq markup
(downcase markup
)))
2473 (insert-file-contents file
)
2475 (let* ((lines (split-string lines
"-"))
2476 (lbeg (string-to-number (car lines
)))
2477 (lend (string-to-number (cadr lines
)))
2478 (beg (if (zerop lbeg
) (point-min)
2479 (goto-char (point-min))
2480 (forward-line (1- lbeg
))
2482 (end (if (zerop lend
) (point-max)
2483 (goto-char (point-min))
2484 (forward-line (1- lend
))
2486 (narrow-to-region beg end
)))
2487 (when (or prefix prefix1
)
2488 (goto-char (point-min))
2490 (insert (or prefix1 prefix
))
2492 (beginning-of-line 2)))
2494 (when (member markup
'("src" "example"))
2495 (goto-char (point-min))
2496 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2497 (goto-char (match-beginning 0))
2501 (dotimes (lvl minlevel
)
2502 (org-map-region 'org-demote
(point-min) (point-max))))
2504 (let ((inclevel (or (if (org-before-first-heading-p)
2505 (1- (and (outline-next-heading)
2506 (org-current-level)))
2507 (1- (org-current-level)))
2509 (dotimes (level (- (+ parentlevel addlevel
) inclevel
))
2510 (org-map-region 'org-demote
(point-min) (point-max)))))
2513 (defun org-get-and-remove-property (listvar prop
)
2514 "Check if the value of LISTVAR contains PROP as a property.
2515 If yes, return the value of that property (i.e. the element following
2516 in the list) and remove property and value from the list in LISTVAR."
2517 (let ((list (symbol-value listvar
)) m v
)
2518 (when (setq m
(member prop list
))
2520 (if (equal (car list
) prop
)
2521 (set listvar
(cddr list
))
2522 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2524 (set listvar list
)))
2527 (defun org-symname-or-string (s)
2529 (if s
(symbol-name s
) s
)
2532 ;;; Fontification and line numbers for code examples
2534 (defvar org-export-last-code-line-counter-value
0)
2536 (defun org-export-replace-src-segments-and-examples ()
2537 "Replace source code segments with special code for export."
2538 (setq org-export-last-code-line-counter-value
0)
2539 (let ((case-fold-search t
)
2540 lang code trans opts indent caption
)
2541 (goto-char (point-min))
2542 (while (re-search-forward
2543 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2546 (if (not (match-string 4))
2547 (error "Source block missing language specification: %s"
2548 (let* ((body (match-string 6))
2549 (nothing (message "body:%s" body
))
2550 (preview (or (and (string-match
2551 "^[ \t]*\\([^\n\r]*\\)" body
)
2552 (match-string 1 body
)) body
)))
2553 (if (> (length preview
) 35)
2554 (concat (substring preview
0 32) "...")
2557 (setq lang
(match-string 4)
2558 opts
(match-string 5)
2559 code
(match-string 6)
2560 indent
(length (match-string 2))
2561 caption
(get-text-property 0 'org-caption
(match-string 0))))
2563 opts
(match-string 9)
2564 code
(match-string 10)
2565 indent
(length (match-string 8))
2566 caption
(get-text-property 0 'org-caption
(match-string 0))))
2568 (setq trans
(org-export-format-source-code-or-example
2569 lang code opts indent caption
))
2570 (replace-match trans t t
))))
2572 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2573 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2574 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2575 (defvar org-export-latex-listings-w-names
) ;; defined in org-latex.el
2576 (defvar org-export-latex-minted-langs
) ;; defined in org-latex.el
2577 (defvar org-export-latex-custom-lang-environments
) ;; defined in org-latex.el
2578 (defvar org-export-latex-listings-options
) ;; defined in org-latex.el
2579 (defvar org-export-latex-minted-options
) ;; defined in org-latex.el
2581 (defun org-remove-formatting-on-newlines-in-region (beg end
)
2582 "Remove formatting on newline characters."
2586 (while (progn (end-of-line) (< (point) end
))
2587 (put-text-property (point) (1+ (point)) 'face nil
)
2590 (defun org-export-format-source-code-or-example
2591 (lang code
&optional opts indent caption
)
2592 "Format CODE from language LANG and return it formatted for export.
2593 The CODE is marked up in `org-export-current-backend' format.
2595 Check if a function by name
2596 \"org-<backend>-format-source-code-or-example\" is bound. If yes,
2597 use it as the custom formatter. Otherwise, use the default
2598 formatter. Default formatters are provided for docbook, html,
2599 latex and ascii backends. For example, use
2600 `org-html-format-source-code-or-example' to provide a custom
2601 formatter for export to \"html\".
2603 If LANG is nil, do not add any fontification.
2604 OPTS contains formatting options, like `-n' for triggering numbering lines,
2605 and `+n' for continuing previous numbering.
2606 Code formatting according to language currently only works for HTML.
2607 Numbering lines works for all three major backends (html, latex, and ascii).
2608 INDENT was the original indentation of the block."
2610 (let* ((backend-name (symbol-name org-export-current-backend
))
2612 (intern (format "org-%s-format-source-code-or-example"
2614 (backend-feature (intern (concat "org-" backend-name
)))
2616 (and (require (intern (concat "org-" backend-name
)) nil
)
2617 (fboundp backend-formatter
) backend-formatter
))
2618 num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2619 (setq opts
(or opts
"")
2620 num
(string-match "[-+]n\\>" opts
)
2621 cont
(string-match "\\+n\\>" opts
)
2622 rpllbl
(string-match "-r\\>" opts
)
2623 keepp
(string-match "-k\\>" opts
)
2624 textareap
(string-match "-t\\>" opts
)
2625 preserve-indentp
(or org-src-preserve-indentation
2626 (string-match "-i\\>" opts
))
2627 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2628 (string-to-number (match-string 1 opts
))
2630 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2631 (string-to-number (match-string 1 opts
))
2632 (org-count-lines code
))
2633 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2634 (match-string 1 opts
)))
2635 (when (and textareap
(eq org-export-current-backend
'html
))
2636 ;; we cannot use numbering or highlighting.
2637 (setq num nil cont nil lang nil
))
2638 (if keepp
(setq rpllbl
'keep
))
2639 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2640 (when (string-match "^," rtn
)
2641 (setq rtn
(with-temp-buffer
2643 ;; Free up the protected lines
2644 (goto-char (point-min))
2645 (while (re-search-forward "^," nil t
)
2646 (if (or (equal lang
"org")
2648 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2652 ;; Now backend-specific coding
2656 (funcall backend-formatter rtn lang caption textareap cols rows num
2658 ((eq org-export-current-backend
'docbook
)
2659 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2660 (concat "<programlisting><![CDATA["
2662 "]]></programlisting>\n"))
2663 ((eq org-export-current-backend
'html
)
2664 ;; We are exporting to HTML
2666 (if (featurep 'xemacs
)
2668 (require 'htmlize nil t
))
2669 (when (not (fboundp 'htmlize-region-for-paste
))
2670 ;; we do not have htmlize.el, or an old version of it
2673 "htmlize.el 1.34 or later is needed for source code formatting")))
2676 (let* ((lang-m (when lang
2677 (or (cdr (assoc lang org-src-lang-modes
))
2679 (mode (and lang-m
(intern
2681 (if (symbolp lang-m
)
2682 (symbol-name lang-m
)
2685 (org-inhibit-startup t
)
2686 (org-startup-folded nil
))
2690 (if (functionp mode
)
2693 (font-lock-fontify-buffer)
2694 ;; markup each line separately
2695 (org-remove-formatting-on-newlines-in-region (point-min) (point-max))
2697 (set-buffer-modified-p nil
)
2698 (org-export-htmlize-region-for-paste
2699 (point-min) (point-max))))
2700 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2705 "<div class=\"org-src-container\">"
2707 "<label class=\"org-src-name\">%s</label>"
2711 (format "<pre class=\"src src-%s\">\n" lang
)
2713 (if caption
"</div>" "")))))
2716 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2718 rtn
"</textarea>\n</p>\n"))
2721 (goto-char (point-min))
2722 (while (re-search-forward "[<>&]" nil t
)
2723 (replace-match (cdr (assq (char-before)
2724 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2726 (setq rtn
(buffer-string)))
2727 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2729 (setq rtn
(org-export-number-lines rtn
1 1 num cont rpllbl fmt
)))
2730 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2731 (setq rtn
(replace-match "\\1" t nil rtn
)))
2733 ((eq org-export-current-backend
'latex
)
2734 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2736 ((and lang org-export-latex-listings
)
2737 (let* ((make-option-string
2739 (concat (first pair
)
2740 (if (> (length (second pair
)) 0)
2741 (concat "=" (second pair
))))))
2742 (lang-sym (intern lang
))
2743 (minted-p (eq org-export-latex-listings
'minted
))
2744 (listings-p (not minted-p
))
2750 (minted-p org-export-latex-minted-langs
)
2751 (listings-p org-export-latex-listings-langs
))))
2757 org-export-latex-custom-lang-environments
))))
2759 (when (and listings-p
(not custom-environment
))
2764 (append org-export-latex-listings-options
2765 `(("language" ,backend-lang
))) ",")))
2766 (when (and caption org-export-latex-listings-w-names
)
2769 (replace-regexp-in-string "_" "\\\\_" caption
)))
2772 (format "\\begin{%s}\n%s\\end{%s}\n"
2773 custom-environment rtn custom-environment
))
2775 (format "\\begin{%s}\n%s\\end{%s}"
2776 "lstlisting" rtn
"lstlisting"))
2779 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2780 (mapconcat make-option-string
2781 org-export-latex-minted-options
",")
2782 backend-lang rtn
))))))
2783 (t (concat (car org-export-latex-verbatim-wrap
)
2784 rtn
(cdr org-export-latex-verbatim-wrap
)))))
2785 ((eq org-export-current-backend
'ascii
)
2786 ;; This is not HTML or LaTeX, so just make it an example.
2787 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2788 (concat caption
"\n"
2791 (lambda (l) (concat " " l
))
2792 (org-split-string rtn
"\n")
2796 (error "Don't know how to markup source or example block in %s"
2797 (upcase backend-name
)))))
2800 "\n#+BEGIN_" backend-name
"\n"
2802 '(org-protected t org-example t org-native-text t
))
2803 "\n#+END_" backend-name
"\n"))
2804 (org-add-props rtn nil
'original-indentation indent
))))
2806 (defun org-export-number-lines (text &optional skip1 skip2 number cont
2807 replace-labels label-format preprocess
)
2808 "Apply line numbers to literal examples and handle code references.
2809 Handle user-specified options under info node `(org)Literal
2810 examples' and return the modified source block.
2812 TEXT contains the source or example block.
2814 SKIP1 and SKIP2 are the number of lines that are to be skipped at
2815 the beginning and end of TEXT. Use these to skip over
2816 backend-specific lines pre-pended or appended to the original
2819 NUMBER is non-nil if the literal example specifies \"+n\" or
2820 \"-n\" switch. If NUMBER is non-nil add line numbers.
2822 CONT is non-nil if the literal example specifies \"+n\" switch.
2823 If CONT is nil, start numbering this block from 1. Otherwise
2824 continue numbering from the last numbered block.
2826 REPLACE-LABELS is dual-purpose.
2827 1. It controls the retention of labels in the exported block.
2828 2. It specifies in what manner the links (or references) to a
2829 labeled line be formatted.
2831 REPLACE-LABELS is the symbol `keep' if the literal example
2832 specifies \"-k\" option, is numeric if the literal example
2833 specifies \"-r\" option and is nil otherwise.
2835 Handle REPLACE-LABELS as below:
2836 - If nil, retain labels in the exported block and use
2837 user-provided labels for referencing the labeled lines.
2838 - If it is a number, remove labels in the exported block and use
2839 one of line numbers or labels for referencing labeled lines based
2841 - If it is a keep, retain labels in the exported block and use
2842 one of line numbers or labels for referencing labeled lines
2843 based on NUMBER option.
2845 LABEL-FORMAT is the value of \"-l\" switch associated with
2846 literal example. See `org-coderef-label-format'.
2848 PREPROCESS is intended for backend-agnostic handling of source
2849 block numbering. When non-nil do the following:
2850 - do not number the lines
2851 - always strip the labels from exported block
2852 - do not make the labeled line a target of an incoming link.
2853 Instead mark the labeled line with `org-coderef' property and
2854 store the label in it."
2855 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2856 (if (and number
(not cont
)) (setq org-export-last-code-line-counter-value
0))
2859 (goto-char (point-max))
2860 (skip-chars-backward " \t\n\r")
2861 (delete-region (point) (point-max))
2862 (beginning-of-line (- 1 skip2
))
2863 (let* ((last (org-current-line))
2864 (n org-export-last-code-line-counter-value
)
2865 (nmax (+ n
(- last skip1
)))
2866 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2869 ((eq org-export-current-backend
'html
) (format "<span class=\"linenr\">%s</span>"
2871 ((eq org-export-current-backend
'ascii
) fmt
)
2872 ((eq org-export-current-backend
'latex
) fmt
)
2873 ((eq org-export-current-backend
'docbook
) fmt
)
2875 (label-format (or label-format org-coderef-label-format
))
2876 (label-pre (if (string-match "%s" label-format
)
2877 (substring label-format
0 (match-beginning 0))
2879 (label-post (if (string-match "%s" label-format
)
2880 (substring label-format
(match-end 0))
2884 ".*?\\S-.*?\\([ \t]*\\("
2885 (regexp-quote label-pre
)
2886 "\\([-a-zA-Z0-9_ ]+\\)"
2887 (regexp-quote label-post
)
2891 (org-goto-line (1+ skip1
))
2892 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2893 (when number
(incf n
))
2894 (if (or preprocess
(not number
))
2896 (insert (format fm n
)))
2897 (when (looking-at lbl-re
)
2898 (setq ref
(match-string 3))
2899 (cond ((numberp replace-labels
)
2900 ;; remove labels; use numbers for references when lines
2901 ;; are numbered, use labels otherwise
2902 (delete-region (match-beginning 1) (match-end 1))
2903 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2904 ((eq replace-labels
'keep
)
2905 ;; don't remove labels; use numbers for references when
2906 ;; lines are numbered, use labels otherwise
2907 (goto-char (match-beginning 2))
2908 (delete-region (match-beginning 2) (match-end 2))
2910 (insert "(" ref
")"))
2911 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2912 org-export-code-refs
))
2914 ;; don't remove labels and don't use numbers for
2916 (goto-char (match-beginning 2))
2917 (delete-region (match-beginning 2) (match-end 2))
2919 (insert "(" ref
")"))
2920 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2921 (when (and (eq org-export-current-backend
'html
) (not preprocess
))
2923 (beginning-of-line 1)
2924 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2927 (insert "</span>")))
2929 (add-text-properties
2930 (point-at-bol) (point-at-eol) (list 'org-coderef ref
)))))
2931 (setq org-export-last-code-line-counter-value n
)
2932 (goto-char (point-max))
2936 (defun org-search-todo-below (line lines level
)
2937 "Search the subtree below LINE for any TODO entries."
2938 (let ((rest (cdr (memq line lines
)))
2939 (re org-todo-line-regexp
)
2942 (while (setq line
(pop rest
))
2943 (if (string-match re line
)
2945 (setq lv
(- (match-end 1) (match-beginning 1))
2946 todo
(and (match-beginning 2)
2947 (not (member (match-string 2 line
)
2948 org-done-keywords
))))
2950 (if (<= lv level
) (throw 'exit nil
))
2951 (if todo
(throw 'exit t
))))))))
2954 (defun org-export-visible (type arg
)
2955 "Create a copy of the visible part of the current buffer, and export it.
2956 The copy is created in a temporary buffer and removed after use.
2957 TYPE is the final key (as a string) that also selects the export command in
2958 the \\<org-mode-map>\\[org-export] export dispatcher.
2959 As a special case, if the you type SPC at the prompt, the temporary
2960 org-mode file will not be removed but presented to you so that you can
2961 continue to use it. The prefix arg ARG is passed through to the exporting
2965 (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")
2966 (read-char-exclusive))
2967 current-prefix-arg
))
2968 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L ?H ?R
)))
2969 (error "Invalid export key"))
2970 (let* ((binding (cdr (assoc type
2972 (?a . org-export-as-ascii
)
2973 (?A . org-export-as-ascii-to-buffer
)
2974 (?n . org-export-as-latin1
)
2975 (?N . org-export-as-latin1-to-buffer
)
2976 (?u . org-export-as-utf8
)
2977 (?U . org-export-as-utf8-to-buffer
)
2978 (?\C-a . org-export-as-ascii
)
2979 (?b . org-export-as-html-and-open
)
2980 (?\C-b . org-export-as-html-and-open
)
2981 (?h . org-export-as-html
)
2982 (?H . org-export-as-html-to-buffer
)
2983 (?R . org-export-region-as-html
)
2984 (?D . org-export-as-docbook
)
2986 (?l . org-export-as-latex
)
2987 (?p . org-export-as-pdf
)
2988 (?d . org-export-as-pdf-and-open
)
2989 (?L . org-export-as-latex-to-buffer
)
2991 (?x . org-export-as-xoxo
)))))
2992 (keepp (equal type ?\
))
2993 (file buffer-file-name
)
2994 (buffer (get-buffer-create "*Org Export Visible*"))
2996 ;; Need to hack the drawers here.
2998 (goto-char (point-min))
2999 (while (re-search-forward org-drawer-regexp nil t
)
3000 (goto-char (match-beginning 1))
3001 (or (outline-invisible-p) (org-flag-drawer nil
))))
3002 (with-current-buffer buffer
(erase-buffer))
3004 (setq s
(goto-char (point-min)))
3005 (while (not (= (point) (point-max)))
3006 (goto-char (org-find-invisible))
3007 (append-to-buffer buffer s
(point))
3008 (setq s
(goto-char (org-find-visible))))
3009 (org-cycle-hide-drawers 'all
)
3010 (goto-char (point-min))
3012 ;; Copy all comment lines to the end, to make sure #+ settings are
3013 ;; still available for the second export step. Kind of a hack, but
3014 ;; does do the trick.
3015 (if (looking-at "#[^\r\n]*")
3016 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
3017 (when (re-search-forward "^\\*+[ \t]+" nil t
)
3018 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t
)
3019 (append-to-buffer buffer
(1+ (match-beginning 0))
3020 (min (point-max) (1+ (match-end 0)))))))
3022 (let ((buffer-file-name file
)
3023 (org-inhibit-startup t
))
3026 (unless keepp
(funcall binding arg
))))
3028 (kill-buffer buffer
)
3029 (switch-to-buffer-other-window buffer
)
3030 (goto-char (point-min)))))
3032 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
3034 (defun org-export-string (string fmt
&optional dir
)
3035 "Export STRING to FMT using existing export facilities.
3036 During export STRING is saved to a temporary file whose location
3037 could vary. Optional argument DIR can be used to force the
3038 directory in which the temporary file is created during export
3039 which can be useful for resolving relative paths. Dir defaults
3040 to the value of `temporary-file-directory'."
3041 (let ((temporary-file-directory (or dir temporary-file-directory
))
3042 (tmp-file (make-temp-file "org-")))
3046 (write-file tmp-file
)
3047 (org-load-modules-maybe)
3048 (unless org-local-vars
3049 (setq org-local-vars
(org-get-local-variables)))
3050 (eval ;; convert to fmt -- mimicking `org-run-like-in-org-mode'
3051 (list 'let org-local-vars
3052 (list (intern (format "org-export-as-%s" fmt
))
3053 nil nil nil
''string t dir
))))
3054 (delete-file tmp-file
))))
3057 (defun org-export-as-org (arg &optional hidden ext-plist
3058 to-buffer body-only pub-dir
)
3059 "Make a copy with not-exporting stuff removed.
3060 The purpose of this function is to provide a way to export the source
3061 Org file of a webpage in Org format, but with sensitive and/or irrelevant
3062 stuff removed. This command will remove the following:
3064 - archived trees (if the variable `org-export-with-archived-trees' is nil)
3065 - comment blocks and trees starting with the COMMENT keyword
3066 - only trees that are consistent with `org-export-select-tags'
3067 and `org-export-exclude-tags'.
3069 The only arguments that will be used are EXT-PLIST and PUB-DIR,
3070 all the others will be ignored (but are present so that the general
3071 mechanism to call publishing functions will work).
3073 EXT-PLIST is a property list with external parameters overriding
3074 org-mode's default settings, but still inferior to file-local
3075 settings. When PUB-DIR is set, use this as the publishing
3078 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
3080 (org-infile-export-plist)))
3081 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3082 (filename (concat (file-name-as-directory
3084 (org-export-directory :org opt-plist
)))
3085 (file-name-sans-extension
3086 (file-name-nondirectory bfname
))
3088 (filename (and filename
3089 (if (equal (file-truename filename
)
3090 (file-truename bfname
))
3091 (concat (file-name-sans-extension filename
)
3093 (file-name-extension filename
))
3095 (backup-inhibited t
)
3096 (buffer (find-file-noselect filename
))
3097 (region (buffer-string))
3100 (org-pop-to-buffer-same-window buffer
)
3103 (let ((org-inhibit-startup t
)) (org-mode))
3104 (org-install-letbind)
3106 ;; Get rid of archived trees
3107 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
3109 ;; Remove comment environment and comment subtrees
3110 (org-export-remove-comment-blocks-and-subtrees)
3112 ;; Get rid of excluded trees
3113 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
3114 (plist-get opt-plist
:exclude-tags
))
3116 (when (or (plist-get opt-plist
:plain-source
)
3117 (not (or (plist-get opt-plist
:plain-source
)
3118 (plist-get opt-plist
:htmlized-source
))))
3119 ;; Either nothing special is requested (default call)
3120 ;; or the plain source is explicitly requested
3123 (when (plist-get opt-plist
:htmlized-source
)
3124 ;; Make the htmlized version
3127 (font-lock-fontify-buffer)
3128 (let* ((htmlize-output-type 'css
)
3129 (newbuf (htmlize-buffer)))
3130 (with-current-buffer newbuf
3131 (when org-export-htmlized-org-css-url
3132 (goto-char (point-min))
3133 (and (re-search-forward
3134 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
3138 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
3139 org-export-htmlized-org-css-url
)
3141 (write-file (concat filename
".html")))
3142 (kill-buffer newbuf
)))
3143 (set-buffer-modified-p nil
)
3144 (if (equal to-buffer
'string
)
3145 (progn (setq str-ret
(buffer-string))
3146 (kill-buffer (current-buffer))
3148 (kill-buffer (current-buffer))))))
3150 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
3151 (defun org-get-current-options ()
3152 "Return a string with current options as keyword options.
3153 Does include HTML export options as well as TODO and CATEGORY stuff."
3154 (require 'org-archive
)
3163 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
3164 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
3166 #+EXPORT_SELECT_TAGS: %s
3167 #+EXPORT_EXCLUDE_TAGS: %s
3174 #+PRIORITIES: %c %c %c
3176 #+STARTUP: %s %s %s %s %s
3182 (buffer-name) (user-full-name) user-mail-address
3183 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
3184 org-export-default-language
3185 org-export-headline-levels
3186 org-export-with-section-numbers
3188 org-export-preserve-breaks
3189 org-export-html-expand
3190 org-export-with-fixed-width
3191 org-export-with-tables
3192 org-export-with-sub-superscripts
3193 org-export-with-special-strings
3194 org-export-with-footnotes
3195 org-export-with-emphasize
3196 org-export-with-timestamps
3197 org-export-with-TeX-macros
3198 org-export-with-LaTeX-fragments
3199 org-export-skip-text-before-1st-heading
3200 org-export-with-drawers
3201 org-export-with-todo-keywords
3202 org-export-with-priority
3203 org-export-with-tags
3204 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
3205 (mapconcat 'identity org-export-select-tags
" ")
3206 (mapconcat 'identity org-export-exclude-tags
" ")
3207 org-export-html-link-up
3208 org-export-html-link-home
3210 (file-name-sans-extension
3211 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3213 "TODO FEEDBACK VERIFY DONE"
3214 "Me Jason Marie DONE"
3215 org-highest-priority org-lowest-priority org-default-priority
3216 (mapconcat 'identity org-drawers
" ")
3217 (cdr (assoc org-startup-folded
3218 '((nil .
"showall") (t .
"overview") (content .
"content"))))
3219 (if org-odd-levels-only
"odd" "oddeven")
3220 (if org-hide-leading-stars
"hidestars" "showstars")
3221 (if org-startup-align-all-tables
"align" "noalign")
3222 (cond ((eq org-log-done t
) "logdone")
3223 ((equal org-log-done
'note
) "lognotedone")
3224 ((not org-log-done
) "nologdone"))
3225 (or (mapconcat (lambda (x)
3227 ((equal :startgroup
(car x
)) "{")
3228 ((equal :endgroup
(car x
)) "}")
3229 ((equal :newline
(car x
)) "")
3230 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
3232 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
3233 (mapconcat 'identity org-file-tags
" ")
3234 org-archive-location
3235 "org file:~/org/%s.org"))
3237 (defun org-insert-export-options-template ()
3238 "Insert into the buffer a template with information for exporting."
3240 (if (not (bolp)) (newline))
3241 (let ((s (org-get-current-options)))
3242 (and (string-match "#\\+CATEGORY" s
)
3243 (setq s
(substring s
0 (match-beginning 0))))
3246 (defvar org-table-colgroup-info nil
)
3248 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
3249 "Check if the table has a marking column.
3250 If yes remove the column and the special lines."
3251 (setq org-table-colgroup-info nil
)
3254 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3257 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
3258 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
3261 ;; No special marking column
3263 (setq org-table-clean-did-remove-column nil
)
3268 ((org-table-colgroup-line-p x
)
3269 ;; This line contains colgroup info, extract it
3270 ;; and then discard the line
3271 (setq org-table-colgroup-info
3273 (cond ((member x
'("<" "<")) :start
)
3274 ((member x
'(">" ">")) :end
)
3275 ((member x
'("<>" "<>")) :startend
)))
3276 (org-split-string x
"[ \t]*|[ \t]*")))
3278 ((org-table-cookie-line-p x
)
3279 ;; This line contains formatting cookies, discard it
3283 ;; there is a special marking column
3284 (setq org-table-clean-did-remove-column t
)
3289 ((org-table-colgroup-line-p x
)
3290 ;; This line contains colgroup info, extract it
3291 ;; and then discard the line
3292 (setq org-table-colgroup-info
3294 (cond ((member x
'("<" "<")) :start
)
3295 ((member x
'(">" ">")) :end
)
3296 ((member x
'("<>" "<>")) :startend
)))
3297 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3299 ((org-table-cookie-line-p x
)
3300 ;; This line contains formatting cookies, discard it
3302 ((string-match "^[ \t]*| *\\([!_^/$]\\|\\\\\\$\\) *|" x
)
3305 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3306 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3307 ;; remove the first column
3308 (replace-match "\\1|" t nil x
))))
3311 (defun org-export-cleanup-toc-line (s)
3312 "Remove tags and timestamps from lines going into the toc."
3314 "" ; Return a string when argument is nil
3315 (when (memq org-export-with-tags
'(not-in-toc nil
))
3316 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s
)
3317 (setq s
(replace-match "" t t s
))))
3318 (when org-export-remove-timestamps-from-toc
3319 (while (string-match org-maybe-keyword-time-regexp s
)
3320 (setq s
(replace-match "" t t s
))))
3321 (while (string-match org-bracket-link-regexp s
)
3322 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3324 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
3325 (setq s
(replace-match "" t t s
)))
3329 (defun org-get-text-property-any (pos prop
&optional object
)
3330 (or (get-text-property pos prop object
)
3331 (and (setq pos
(next-single-property-change pos prop object
))
3332 (get-text-property pos prop object
))))
3334 (defun org-export-get-coderef-format (path desc
)
3336 (if (and desc
(string-match
3337 (regexp-quote (concat "(" path
")"))
3339 (replace-match "%s" t t desc
)
3342 (defun org-export-push-to-kill-ring (format)
3343 "Push buffer content to kill ring.
3344 The depends on the variable `org-export-copy-to-kill-ring'."
3345 (when (or (and (eq org-export-copy-to-kill-ring
'if-interactive
)
3346 (not (or executing-kbd-macro noninteractive
)))
3347 (eq org-export-copy-to-kill-ring t
))
3348 (org-kill-new (buffer-string))
3349 (when (fboundp 'x-set-selection
)
3350 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
3351 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
3352 (message "%s export done, pushed to kill ring and clipboard" format
)))
3357 ;; generated-autoload-file: "org-loaddefs.el"
3360 ;;; org-exp.el ends here