1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 (require 'org-exp-blocks
)
39 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
40 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
41 (declare-function org-export-html-preprocess
"org-html" (parameters))
42 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
43 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
44 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
45 (declare-function htmlize-buffer
"ext:htmlize" (&optional buffer
))
46 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
47 (declare-function org-table-cookie-line-p
"org-table" (line))
48 (declare-function org-table-colgroup-line-p
"org-table" (line))
49 (declare-function org-pop-to-buffer-same-window
"org-compat"
50 (&optional buffer-or-name norecord label
))
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 t
92 "Non-nil means exported stuff will also be pushed onto the kill ring."
93 :group
'org-export-general
96 (defcustom org-export-kill-product-buffer-when-displayed nil
97 "Non-nil means kill the product buffer if it is displayed immediately.
98 This applied to the commands `org-export-as-html-and-open' and
99 `org-export-as-pdf-and-open'."
100 :group
'org-export-general
104 (defcustom org-export-run-in-background nil
105 "Non-nil means export and publishing commands will run in background.
106 This works by starting up a separate Emacs process visiting the same file
107 and doing the export from there.
108 Not all export commands are affected by this - only the ones which
109 actually write to a file, and that do not depend on the buffer state.
111 If this option is nil, you can still get background export by calling
112 `org-export' with a double prefix arg: \
113 \\[universal-argument] \\[universal-argument] \\[org-export].
115 If this option is t, the double prefix can be used to exceptionally
116 force an export command into the current process."
117 :group
'org-export-general
120 (defcustom org-export-initial-scope
'buffer
121 "The initial scope when exporting with `org-export'.
122 This variable can be either set to 'buffer or 'subtree."
123 :group
'org-export-general
126 (const :tag
"Export current buffer" 'buffer
)
127 (const :tag
"Export current subtree" 'subtree
)))
129 (defcustom org-export-select-tags
'("export")
130 "Tags that select a tree for export.
131 If any such tag is found in a buffer, all trees that do not carry one
132 of these tags will be deleted before export.
133 Inside trees that are selected like this, you can still deselect a
134 subtree by tagging it with one of the `org-export-exclude-tags'."
135 :group
'org-export-general
136 :type
'(repeat (string :tag
"Tag")))
138 (defcustom org-export-exclude-tags
'("noexport")
139 "Tags that exclude a tree from export.
140 All trees carrying any of these tags will be excluded from export.
141 This is without condition, so even subtrees inside that carry one of the
142 `org-export-select-tags' will be removed."
143 :group
'org-export-general
144 :type
'(repeat (string :tag
"Tag")))
146 ;; FIXME: rename, this is a general variable
147 (defcustom org-export-html-expand t
148 "Non-nil means for HTML export, treat @<...> as HTML tag.
149 When nil, these tags will be exported as plain text and therefore
150 not be interpreted by a browser.
152 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
153 :group
'org-export-html
154 :group
'org-export-general
157 (defcustom org-export-with-special-strings t
158 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
159 When this option is turned on, these strings will be exported as:
162 -----+----------+--------
168 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
169 :group
'org-export-translation
172 (defcustom org-export-html-link-up
""
173 "Where should the \"UP\" link of exported HTML pages lead?"
174 :group
'org-export-html
175 :group
'org-export-general
176 :type
'(string :tag
"File or URL"))
178 (defcustom org-export-html-link-home
""
179 "Where should the \"HOME\" link of exported HTML pages lead?"
180 :group
'org-export-html
181 :group
'org-export-general
182 :type
'(string :tag
"File or URL"))
184 (defcustom org-export-language-setup
185 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
186 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
187 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
188 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
189 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
190 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
191 ("es" "Autor" "Fecha" "Índice" "Pies de página")
192 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
193 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
194 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
195 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
196 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
197 ;; Use numeric character entities for proper rendering of non-UTF8 documents
198 ;; ("ja" "著者" "日付" "目次" "脚注")
199 ("ja" "著者" "日付" "目次" "脚注")
200 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
201 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
202 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
203 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
204 ("pl" "Autor" "Data" "Spis treści" "Przypis")
205 ;; Use numeric character entities for proper rendering of non-UTF8 documents
206 ;; ("ru" "Автор" "Дата" "Содержание" "Сноски")
207 ("ru" "Автор" "Дата" "Содержание" "Сноски")
208 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter")
209 ;; Use numeric character entities for proper rendering of non-UTF8 documents
210 ;; ("uk" "Автор" "Дата" "Зміст" "Примітки")
211 ("uk" "Автор" "Дата" "Зміст" "Примітки")
212 ;; Use numeric character entities for proper rendering of non-UTF8 documents
213 ;; ("zh-CN" "作者" "日期" "目录" "脚注")
214 ("zh-CN" "作者" "日期" "目录" "脚注")
215 ;; Use numeric character entities for proper rendering of non-UTF8 documents
216 ;; ("zh-TW" "作者" "日期" "目錄" "腳註")
217 ("zh-TW" "作者" "日期" "目錄" "腳註"))
218 "Terms used in export text, translated to different languages.
219 Use the variable `org-export-default-language' to set the language,
220 or use the +OPTION lines for a per-file setting."
221 :group
'org-export-general
224 (string :tag
"HTML language tag")
225 (string :tag
"Author")
227 (string :tag
"Table of Contents")
228 (string :tag
"Footnotes"))))
230 (defcustom org-export-default-language
"en"
231 "The default language for export and clocktable translations, as a string.
232 This should have an association in `org-export-language-setup'
233 and in `org-clock-clocktable-language-setup'."
234 :group
'org-export-general
237 (defcustom org-export-date-timestamp-format
"%Y-%m-%d"
238 "Time string format for Org timestamps in the #+DATE option."
239 :group
'org-export-general
243 (defvar org-export-page-description
""
244 "The page description, for the XHTML meta tag.
245 This is best set with the #+DESCRIPTION line in a file, it does not make
246 sense to set this globally.")
248 (defvar org-export-page-keywords
""
249 "The page description, for the XHTML meta tag.
250 This is best set with the #+KEYWORDS line in a file, it does not make
251 sense to set this globally.")
253 (defcustom org-export-skip-text-before-1st-heading nil
254 "Non-nil means skip all text before the first headline when exporting.
255 When nil, that text is exported as well."
256 :group
'org-export-general
259 (defcustom org-export-headline-levels
3
260 "The last level which is still exported as a headline.
261 Inferior levels will produce itemize lists when exported.
262 Note that a numeric prefix argument to an exporter function overrides
265 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
266 :group
'org-export-general
269 (defcustom org-export-with-section-numbers t
270 "Non-nil means add section numbers to headlines when exporting.
272 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
273 :group
'org-export-general
276 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
277 "Format of section numbers for export.
278 The variable has two components.
279 1. A list of lists, each indicating a counter type and a separator.
280 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
281 It causes causes numeric, alphabetic, or roman counters, respectively.
282 The separator is only used if another counter for a subsection is being
284 If there are more numbered section levels than entries in this lists,
285 then the last entry will be reused.
286 2. A terminator string that will be added after the entire
288 :group
'org-export-general
292 (string :tag
"Counter Type")
293 (string :tag
"Separator ")))
294 (string :tag
"Terminator")))
296 (defcustom org-export-with-toc t
297 "Non-nil means create a table of contents in exported files.
298 The TOC contains headlines with levels up to`org-export-headline-levels'.
299 When an integer, include levels up to N in the toc, this may then be
300 different from `org-export-headline-levels', but it will not be allowed
301 to be larger than the number of headline levels.
302 When nil, no table of contents is made.
304 Headlines which contain any TODO items will be marked with \"(*)\" in
305 ASCII export, and with red color in HTML output, if the option
306 `org-export-mark-todo-in-toc' is set.
308 In HTML output, the TOC will be clickable.
310 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
312 :group
'org-export-general
314 (const :tag
"No Table of Contents" nil
)
315 (const :tag
"Full Table of Contents" t
)
316 (integer :tag
"TOC to level")))
318 (defcustom org-export-mark-todo-in-toc nil
319 "Non-nil means mark TOC lines that contain any open TODO items."
320 :group
'org-export-general
323 (defcustom org-export-with-todo-keywords t
324 "Non-nil means include TODO keywords in export.
325 When nil, remove all these keywords from the export."
326 :group
'org-export-general
329 (defcustom org-export-with-tasks t
330 "Non-nil means include TODO items for export.
331 This may have the following values:
332 t include tasks independent of state.
333 todo include only tasks that are not yet done.
334 done include only tasks that are already done.
335 nil remove all tasks before export
336 list of TODO kwds keep only tasks with these keywords"
337 :group
'org-export-general
340 (const :tag
"All tasks" t
)
341 (const :tag
"No tasks" nil
)
342 (const :tag
"Not-done tasks" todo
)
343 (const :tag
"Only done tasks" done
)
344 (repeat :tag
"Specific TODO keywords"
345 (string :tag
"Keyword"))))
347 (defcustom org-export-with-priority nil
348 "Non-nil means include priority cookies in export.
349 When nil, remove priority cookies for export."
350 :group
'org-export-general
353 (defcustom org-export-preserve-breaks nil
354 "Non-nil means preserve all line breaks when exporting.
355 Normally, in HTML output paragraphs will be reformatted. In ASCII
356 export, line breaks will always be preserved, regardless of this variable.
358 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
359 :group
'org-export-general
362 (defcustom org-export-with-archived-trees
'headline
363 "Whether subtrees with the ARCHIVE tag should be exported.
364 This can have three different values
365 nil Do not export, pretend this tree is not present
366 t Do export the entire tree
367 headline Only export the headline, but skip the tree below it."
368 :group
'org-export-general
371 (const :tag
"not at all" nil
)
372 (const :tag
"headline only" 'headline
)
373 (const :tag
"entirely" t
)))
375 (defcustom org-export-author-info t
376 "Non-nil means insert author name and email into the exported file.
378 This option can also be set with the +OPTIONS line,
379 e.g. \"author:nil\"."
380 :group
'org-export-general
383 (defcustom org-export-email-info nil
384 "Non-nil means insert author name and email into the exported file.
386 This option can also be set with the +OPTIONS line,
388 :group
'org-export-general
392 (defcustom org-export-creator-info t
393 "Non-nil means the postamble should contain a creator sentence.
394 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
395 :group
'org-export-general
398 (defcustom org-export-time-stamp-file t
399 "Non-nil means insert a time stamp into the exported file.
400 The time stamp shows when the file was created.
402 This option can also be set with the +OPTIONS line,
403 e.g. \"timestamp:nil\"."
404 :group
'org-export-general
407 (defcustom org-export-with-timestamps t
408 "If nil, do not export time stamps and associated keywords."
409 :group
'org-export-general
412 (defcustom org-export-remove-timestamps-from-toc t
413 "If t, remove timestamps from the table of contents entries."
414 :group
'org-export-general
417 (defcustom org-export-with-tags
'not-in-toc
418 "If nil, do not export tags, just remove them from headlines.
419 If this is the symbol `not-in-toc', tags will be removed from table of
420 contents entries, but still be shown in the headlines of the document.
422 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
423 :group
'org-export-general
425 (const :tag
"Off" nil
)
426 (const :tag
"Not in TOC" not-in-toc
)
427 (const :tag
"On" t
)))
429 (defcustom org-export-with-drawers nil
430 "Non-nil means export with drawers like the property drawer.
431 When t, all drawers are exported. This may also be a list of
432 drawer names to export."
433 :group
'org-export-general
435 (const :tag
"All drawers" t
)
436 (const :tag
"None" nil
)
437 (repeat :tag
"Selected drawers"
438 (string :tag
"Drawer name"))))
440 (defvar org-export-first-hook nil
441 "Hook called as the first thing in each exporter.
442 Point will be still in the original buffer.
443 Good for general initialization")
445 (defvar org-export-preprocess-hook nil
446 "Hook for preprocessing an export buffer.
447 Pretty much the first thing when exporting is running this hook.
448 Point will be in a temporary buffer that contains a copy of
449 the original buffer, or of the section that is being exported.
450 All the other hooks in the org-export-preprocess... category
451 also work in that temporary buffer, already modified by various
452 stages of the processing.")
454 (defvar org-export-preprocess-after-include-files-hook nil
455 "Hook for preprocessing an export buffer.
456 This is run after the contents of included files have been inserted.")
458 (defvar org-export-preprocess-after-tree-selection-hook nil
459 "Hook for preprocessing an export buffer.
460 This is run after selection of trees to be exported has happened.
461 This selection includes tags-based selection, as well as removal
462 of commented and archived trees.")
464 (defvar org-export-preprocess-after-headline-targets-hook nil
465 "Hook for preprocessing export buffer.
466 This is run just after the headline targets have been defined and
467 the target-alist has been set up.")
469 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
470 "Hook for preprocessing an export buffer.
471 This is run just before backend-specific blocks get selected.")
473 (defvar org-export-preprocess-after-blockquote-hook nil
474 "Hook for preprocessing an export buffer.
475 This is run after blockquote/quote/verse/center have been marked
478 (defvar org-export-preprocess-after-radio-targets-hook nil
479 "Hook for preprocessing an export buffer.
480 This is run after radio target processing.")
482 (defvar org-export-preprocess-before-normalizing-links-hook nil
483 "Hook for preprocessing an export buffer.
484 This hook is run before links are normalized.")
486 (defvar org-export-preprocess-before-backend-specifics-hook nil
487 "Hook run before backend-specific functions are called during preprocessing.")
489 (defvar org-export-preprocess-final-hook nil
490 "Hook for preprocessing an export buffer.
491 This is run as the last thing in the preprocessing buffer, just before
492 returning the buffer string to the backend.")
494 (defgroup org-export-translation nil
495 "Options for translating special ascii sequences for the export backends."
496 :tag
"Org Export Translation"
499 (defcustom org-export-with-emphasize t
500 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
501 If the export target supports emphasizing text, the word will be
502 typeset in bold, italic, or underlined, respectively. Works only for
503 single words, but you can say: I *really* *mean* *this*.
504 Not all export backends support this.
506 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
507 :group
'org-export-translation
510 (defcustom org-export-with-footnotes t
511 "If nil, export [1] as a footnote marker.
512 Lines starting with [1] will be formatted as footnotes.
514 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
515 :group
'org-export-translation
518 (defcustom org-export-with-TeX-macros t
519 "Non-nil means interpret simple TeX-like macros when exporting.
520 For example, HTML export converts \\alpha to α and \\AA to Å.
521 Not only real TeX macros will work here, but the standard HTML entities
522 for math can be used as macro names as well. For a list of supported
523 names in HTML export, see the constant `org-entities' and the user option
525 Not all export backends support this.
527 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
528 :group
'org-export-translation
529 :group
'org-export-latex
532 (defcustom org-export-with-LaTeX-fragments t
533 "Non-nil means process LaTeX math fragments for HTML display.
534 When set, the exporter will find and process LaTeX environments if the
535 \\begin line is the first non-white thing on a line. It will also find
536 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
537 $$a=b$$ and \\=\\[ a=b \\] for display math.
539 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
543 nil Don't do anything.
544 verbatim Keep everything in verbatim
545 dvipng Process the LaTeX fragments to images.
546 This will also include processing of non-math environments.
547 t Do MathJax preprocessing if there is at least on math snippet,
548 and arrange for MathJax.js to be loaded.
550 The default is nil, because this option needs the `dvipng' program which
551 is not available on all systems."
552 :group
'org-export-translation
553 :group
'org-export-latex
555 (const :tag
"Do not process math in any way" nil
)
556 (const :tag
"Obsolete, use dvipng setting" t
)
557 (const :tag
"Use dvipng to make images" dvipng
)
558 (const :tag
"Use MathJax to display math" mathjax
)
559 (const :tag
"Leave math verbatim" verbatim
)))
561 (defcustom org-export-with-fixed-width t
562 "Non-nil means lines starting with \":\" will be in fixed width font.
563 This can be used to have pre-formatted text, fragments of code etc. For
565 : ;; Some Lisp examples
568 will be looking just like this in also HTML. See also the QUOTE keyword.
569 Not all export backends support this.
571 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
572 :group
'org-export-translation
575 (defgroup org-export-tables nil
576 "Options for exporting tables in Org-mode."
577 :tag
"Org Export Tables"
580 (defcustom org-export-with-tables t
581 "If non-nil, lines starting with \"|\" define a table.
584 | Name | Address | Birthday |
585 |-------------+----------+-----------|
586 | Arthur Dent | England | 29.2.2100 |
588 Not all export backends support this.
590 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
591 :group
'org-export-tables
594 (defcustom org-export-highlight-first-table-line t
595 "Non-nil means highlight the first table line.
596 In HTML export, this means use <th> instead of <td>.
597 In tables created with table.el, this applies to the first table line.
598 In Org-mode tables, all lines before the first horizontal separator
599 line will be formatted with <th> tags."
600 :group
'org-export-tables
603 (defcustom org-export-table-remove-special-lines t
604 "Remove special lines and marking characters in calculating tables.
605 This removes the special marking character column from tables that are set
606 up for spreadsheet calculations. It also removes the entire lines
607 marked with `!', `_', or `^'. The lines with `$' are kept, because
608 the values of constants may be useful to have."
609 :group
'org-export-tables
612 (defcustom org-export-table-remove-empty-lines t
613 "Remove empty lines when exporting tables.
614 This is the global equivalent of the :remove-nil-lines option
615 when locally sending a table with #+ORGTBL."
616 :group
'org-export-tables
620 (defcustom org-export-prefer-native-exporter-for-tables nil
621 "Non-nil means always export tables created with table.el natively.
622 Natively means use the HTML code generator in table.el.
623 When nil, Org-mode's own HTML generator is used when possible (i.e. if
624 the table does not use row- or column-spanning). This has the
625 advantage, that the automatic HTML conversions for math symbols and
626 sub/superscripts can be applied. Org-mode's HTML generator is also
627 much faster. The LaTeX exporter always use the native exporter for
629 :group
'org-export-tables
634 ;;; Variables, constants, and parameter plists
636 (defconst org-level-max
20)
638 (defvar org-export-current-backend nil
639 "During export, this will be bound to a symbol such as 'html,
640 'latex, 'docbook, 'ascii, etc, indicating which of the export
641 backends is in use. Otherwise it has the value nil. Users
642 should not attempt to change the value of this variable
643 directly, but it can be used in code to test whether export is
644 in progress, and if so, what the backend is.")
646 (defvar org-current-export-file nil
) ; dynamically scoped parameter
647 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
648 (defvar org-export-opt-plist nil
649 "Contains the current option plist.")
650 (defvar org-last-level nil
) ; dynamically scoped variable
651 (defvar org-min-level nil
) ; dynamically scoped variable
652 (defvar org-levels-open nil
) ; dynamically scoped parameter
653 (defvar org-export-footnotes-data nil
654 "Alist of labels used in buffers, along with their definition.")
655 (defvar org-export-footnotes-seen nil
656 "Alist of labels encountered so far by the exporter, along with their definition.")
659 (defconst org-export-plist-vars
660 '((:link-up nil org-export-html-link-up
)
661 (:link-home nil org-export-html-link-home
)
662 (:language nil org-export-default-language
)
663 (:keywords nil org-export-page-keywords
)
664 (:description nil org-export-page-description
)
665 (:customtime nil org-display-custom-times
)
666 (:headline-levels
"H" org-export-headline-levels
)
667 (:section-numbers
"num" org-export-with-section-numbers
)
668 (:section-number-format nil org-export-section-number-format
)
669 (:table-of-contents
"toc" org-export-with-toc
)
670 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
671 (:archived-trees nil org-export-with-archived-trees
)
672 (:emphasize
"*" org-export-with-emphasize
)
673 (:sub-superscript
"^" org-export-with-sub-superscripts
)
674 (:special-strings
"-" org-export-with-special-strings
)
675 (:footnotes
"f" org-export-with-footnotes
)
676 (:drawers
"d" org-export-with-drawers
)
677 (:tags
"tags" org-export-with-tags
)
678 (:todo-keywords
"todo" org-export-with-todo-keywords
)
679 (:tasks
"tasks" org-export-with-tasks
)
680 (:priority
"pri" org-export-with-priority
)
681 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
682 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
683 (:latex-listings nil org-export-latex-listings
)
684 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
685 (:fixed-width
":" org-export-with-fixed-width
)
686 (:timestamps
"<" org-export-with-timestamps
)
687 (:author nil user-full-name
)
688 (:email nil user-mail-address
)
689 (:author-info
"author" org-export-author-info
)
690 (:email-info
"email" org-export-email-info
)
691 (:creator-info
"creator" org-export-creator-info
)
692 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
693 (:tables
"|" org-export-with-tables
)
694 (:table-auto-headline nil org-export-highlight-first-table-line
)
695 (:style-include-default nil org-export-html-style-include-default
)
696 (:style-include-scripts nil org-export-html-style-include-scripts
)
697 (:style nil org-export-html-style
)
698 (:style-extra nil org-export-html-style-extra
)
699 (:agenda-style nil org-agenda-export-html-style
)
700 (:convert-org-links nil org-export-html-link-org-files-as-html
)
701 (:inline-images nil org-export-html-inline-images
)
702 (:html-extension nil org-export-html-extension
)
703 (:html-preamble nil org-export-html-preamble
)
704 (:html-postamble nil org-export-html-postamble
)
705 (:xml-declaration nil org-export-html-xml-declaration
)
706 (:html-table-tag nil org-export-html-table-tag
)
707 (:expand-quoted-html
"@" org-export-html-expand
)
708 (:timestamp nil org-export-html-with-timestamp
)
709 (:publishing-directory nil org-export-publishing-directory
)
710 (:select-tags nil org-export-select-tags
)
711 (:exclude-tags nil org-export-exclude-tags
)
713 (:latex-image-options nil org-export-latex-image-default-option
))
714 "List of properties that represent export/publishing variables.
715 Each element is a list of 3 items:
716 1. The property that is used internally, and also for org-publish-project-alist
717 2. The string that can be used in the OPTION lines to set this option,
718 or nil if this option cannot be changed in this way
719 3. The customization variable that sets the default for this option."
722 (defun org-default-export-plist ()
723 "Return the property list with default settings for the export variables."
724 (let* ((infile (org-infile-export-plist))
725 (letbind (plist-get infile
:let-bind
))
726 (l org-export-plist-vars
) rtn e s v
)
727 (while (setq e
(pop l
))
730 ((assq s letbind
) (nth 1 (assq s letbind
)))
731 ((boundp s
) (symbol-value s
))
733 rtn
(cons (car e
) (cons v rtn
))))
736 (defvar org-export-inbuffer-options-extra nil
737 "List of additional in-buffer options that should be detected.
738 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
739 etc. Extensions can add to this list to get their options detected, and they
740 can then add a function to `org-export-options-filters' to process these
742 Each element in this list must be a list, with the in-buffer keyword as car,
743 and a property (a symbol) as the next element. All occurrences of the
744 keyword will be found, the values concatenated with a space character
745 in between, and the result stored in the export options property list.")
747 (defvar org-export-options-filters nil
748 "Functions to be called to finalize the export/publishing options.
749 All these options are stored in a property list, and each of the functions
750 in this hook gets a chance to modify this property list. Each function
751 must accept the property list as an argument, and must return the (possibly
754 ;; FIXME: should we fold case here?
756 (defun org-infile-export-plist ()
757 "Return the property list with file-local settings for export."
761 (goto-char (point-min))
762 (let ((re (org-make-options-regexp
764 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
766 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
767 "LATEX_HEADER" "LATEX_CLASS" "LATEX_CLASS_OPTIONS"
768 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
769 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
770 (mapcar 'car org-export-inbuffer-options-extra
))))
772 p key val text options mathjax a pr style
773 latex-header latex-class latex-class-options macros letbind
774 ext-setup-or-nil setup-file setup-dir setup-contents
(start 0))
775 (while (or (and ext-setup-or-nil
776 (string-match re ext-setup-or-nil start
)
777 (setq start
(match-end 0)))
778 (and (setq ext-setup-or-nil nil start
0)
779 (re-search-forward re nil t
)))
780 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
781 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
783 ((setq a
(assoc key org-export-inbuffer-options-extra
))
785 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
786 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
787 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
788 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
789 ((string-equal key
"DATE")
790 ;; If date is an Org timestamp, convert it to a time
791 ;; string using `org-export-date-timestamp-format'
792 (when (string-match org-ts-regexp3 val
)
793 (setq val
(format-time-string
794 org-export-date-timestamp-format
795 (apply 'encode-time
(org-parse-time-string
796 (match-string 0 val
))))))
797 (setq p
(plist-put p
:date val
)))
798 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
799 ((string-equal key
"DESCRIPTION")
800 (setq p
(plist-put p
:description val
)))
801 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
802 ((string-equal key
"STYLE")
803 (setq style
(concat style
"\n" val
)))
804 ((string-equal key
"LATEX_HEADER")
805 (setq latex-header
(concat latex-header
"\n" val
)))
806 ((string-equal key
"LATEX_CLASS")
807 (setq latex-class val
))
808 ((string-equal key
"LATEX_CLASS_OPTIONS")
809 (setq latex-class-options val
))
810 ((string-equal key
"TEXT")
811 (setq text
(if text
(concat text
"\n" val
) val
)))
812 ((string-equal key
"OPTIONS")
813 (setq options
(concat val
" " options
)))
814 ((string-equal key
"MATHJAX")
815 (setq mathjax
(concat val
" " mathjax
)))
816 ((string-equal key
"BIND")
817 (push (read (concat "(" val
")")) letbind
))
818 ((string-equal key
"XSLT")
819 (setq p
(plist-put p
:xslt val
)))
820 ((string-equal key
"LINK_UP")
821 (setq p
(plist-put p
:link-up val
)))
822 ((string-equal key
"LINK_HOME")
823 (setq p
(plist-put p
:link-home val
)))
824 ((string-equal key
"EXPORT_SELECT_TAGS")
825 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
826 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
827 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
828 ((string-equal key
"MACRO")
830 ((equal key
"SETUPFILE")
831 (setq setup-file
(org-remove-double-quotes (org-trim val
))
832 ;; take care of recursive inclusion of setupfiles
833 setup-file
(if (or (file-name-absolute-p val
) (not setup-dir
))
834 (expand-file-name setup-file
)
835 (let ((default-directory setup-dir
))
836 (expand-file-name setup-file
))))
837 (setq setup-dir
(file-name-directory setup-file
))
838 (setq setup-contents
(org-file-contents setup-file
'noerror
))
839 (if (not ext-setup-or-nil
)
840 (setq ext-setup-or-nil setup-contents start
0)
841 (setq ext-setup-or-nil
842 (concat (substring ext-setup-or-nil
0 start
)
843 "\n" setup-contents
"\n"
844 (substring ext-setup-or-nil start
)))))))
845 (setq p
(plist-put p
:text text
))
846 (when (and letbind
(org-export-confirm-letbind))
847 (setq p
(plist-put p
:let-bind letbind
)))
848 (when style
(setq p
(plist-put p
:style-extra style
)))
850 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
852 (setq p
(plist-put p
:latex-class latex-class
)))
853 (when latex-class-options
854 (setq p
(plist-put p
:latex-class-options latex-class-options
)))
856 (setq p
(org-export-add-options-to-plist p options
)))
858 (setq p
(plist-put p
:mathjax mathjax
)))
859 ;; Add macro definitions
860 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
861 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
862 (setq p
(plist-put p
:macro-property
"(eval (org-entry-get nil \"$1\" 'selective))"))
864 p
:macro-modification-time
865 (and (buffer-file-name)
866 (file-exists-p (buffer-file-name))
868 "(eval (format-time-string \"$1\" '"
869 (prin1-to-string (nth 5 (file-attributes
870 (buffer-file-name))))
872 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
873 (file-name-nondirectory
874 (buffer-file-name)))))
875 (while (setq val
(pop macros
))
876 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
879 (concat ":macro-" (downcase (match-string 1 val
))))
880 (org-export-interpolate-newlines (match-string 2 val
))))))
883 (defun org-export-interpolate-newlines (s)
884 (while (string-match "\\\\n" s
)
885 (setq s
(replace-match "\n" t t s
)))
888 (defvar org-export-allow-BIND-local nil
)
889 (defun org-export-confirm-letbind ()
890 "Can we use #+BIND values during export?
891 By default this will ask for confirmation by the user, to divert possible
894 ((not org-export-allow-BIND
) nil
)
895 ((eq org-export-allow-BIND t
) t
)
896 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
897 org-export-allow-BIND-local
)
898 (t (org-set-local 'org-export-allow-BIND-local
899 (yes-or-no-p "Allow BIND values in this buffer? ")))))
901 (defun org-install-letbind ()
902 "Install the values from #+BIND lines as local variables."
903 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
905 (while (setq pair
(pop letbind
))
906 (org-set-local (car pair
) (nth 1 pair
)))))
908 (defun org-export-add-options-to-plist (p options
)
909 "Parse an OPTIONS line and set values in the property list P."
912 (let ((op org-export-plist-vars
))
913 (while (setq o
(pop op
))
915 (string-match (concat "\\(\\`\\|[ \t]\\)"
916 (regexp-quote (nth 1 o
))
917 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
919 (setq p
(plist-put p
(car o
)
920 (car (read-from-string
921 (match-string 2 options
))))))))))
924 (defun org-export-add-subtree-options (p pos
)
925 "Add options in subtree at position POS to property list P."
928 (when (org-at-heading-p)
930 ;; This is actually read in `org-export-get-title-from-subtree'
931 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
932 ;; (setq p (plist-put p :title a)))
933 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
934 (setq p
(plist-put p
:text a
)))
935 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
936 (setq p
(plist-put p
:author a
)))
937 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
938 (setq p
(plist-put p
:date a
)))
939 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
940 (setq p
(org-export-add-options-to-plist p a
)))))
943 (defun org-export-directory (type plist
)
944 (let* ((val (plist-get plist
:publishing-directory
))
946 (or (cdr (assoc type val
)) ".")
950 (defun org-export-process-option-filters (plist)
951 (let ((functions org-export-options-filters
) f
)
952 (while (setq f
(pop functions
))
953 (setq plist
(funcall f plist
))))
957 (defun org-export (&optional arg
)
958 "Export dispatcher for Org-mode.
959 When `org-export-run-in-background' is non-nil, try to run the command
960 in the background. This will be done only for commands that write
961 to a file. For details see the docstring of `org-export-run-in-background'.
963 The prefix argument ARG will be passed to the exporter. However, if
964 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
965 that means to inverse the
966 value of `org-export-run-in-background'.
968 If `org-export-initial-scope' is set to 'subtree, try to export
969 the current subtree, otherwise try to export the whole buffer.
970 Pressing `1' will switch between these two options."
972 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
973 (subtree-p (or (org-region-active-p)
974 (eq org-export-initial-scope
'subtree
)))
975 (help "[t] insert the export option template
976 \[v] limit export to visible part of outline tree
977 \[1] switch buffer/subtree export
978 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
980 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
982 \[h] export as HTML [H] to temporary buffer [R] export region
983 \[b] export as HTML and open in browser
985 \[l] export as LaTeX [L] to temporary buffer
986 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
988 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
990 \[o] export as OpenDocument Text [O] ... and open
992 \[j] export as TaskJuggler [J] ... and open
994 \[m] export as Freemind mind map
996 \[g] export using Wes Hardaker's generic exporter
998 \[i] export current file as iCalendar file
999 \[I] export all agenda files as iCalendar files [c] ...as one combined file
1001 \[F] publish current file [P] publish current project
1002 \[X] publish a project... [E] publish every projects")
1004 '((?t org-insert-export-options-template nil
)
1005 (?v org-export-visible nil
)
1006 (?a org-export-as-ascii t
)
1007 (?A org-export-as-ascii-to-buffer t
)
1008 (?n org-export-as-latin1 t
)
1009 (?N org-export-as-latin1-to-buffer t
)
1010 (?u org-export-as-utf8 t
)
1011 (?U org-export-as-utf8-to-buffer t
)
1012 (?h org-export-as-html t
)
1013 (?b org-export-as-html-and-open t
)
1014 (?H org-export-as-html-to-buffer nil
)
1015 (?R org-export-region-as-html nil
)
1016 (?x org-export-as-xoxo t
)
1017 (?g org-export-generic t
)
1018 (?D org-export-as-docbook t
)
1019 (?V org-export-as-docbook-pdf-and-open t
)
1020 (?o org-export-as-odt t
)
1021 (?O org-export-as-odt-and-open t
)
1022 (?j org-export-as-taskjuggler t
)
1023 (?J org-export-as-taskjuggler-and-open t
)
1024 (?m org-export-as-freemind t
)
1025 (?l org-export-as-latex t
)
1026 (?p org-export-as-pdf t
)
1027 (?d org-export-as-pdf-and-open t
)
1028 (?L org-export-as-latex-to-buffer nil
)
1029 (?i org-export-icalendar-this-file t
)
1030 (?I org-export-icalendar-all-agenda-files t
)
1031 (?c org-export-icalendar-combine-agenda-files t
)
1032 (?F org-publish-current-file t
)
1033 (?P org-publish-current-project t
)
1035 (?E org-publish-all t
)))
1037 (cpos (point)) (cbuf (current-buffer)) bpos
)
1039 (save-window-excursion
1041 (message "Export subtree: ")
1042 (message "Export buffer: "))
1043 (delete-other-windows)
1044 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1046 (org-fit-window-to-buffer (get-buffer-window
1047 "*Org Export/Publishing Help*"))
1048 (while (eq (setq r1
(read-char-exclusive)) ?
1)
1050 (setq subtree-p nil
)
1051 (message "Export buffer: "))
1055 (message "Export subtree: "))))
1057 (let ((case-fold-search t
)
1058 (end (save-excursion (while (org-up-heading-safe)) (point))))
1059 (outline-next-heading)
1060 (if (re-search-backward
1061 "^[ \t]+\\(:latex_class:\\|:export_title:\\|:export_file_name:\\)[ \t]+\\S-"
1064 (org-back-to-heading t
)
1067 (message "Select command (for subtree): ")
1068 (setq r1
(read-char-exclusive)))
1069 (error "No enclosing node with LaTeX_CLASS or EXPORT_TITLE or EXPORT_FILE_NAME")
1071 (if (fboundp 'redisplay
) (redisplay)) ;; XEmacs does not have/need (redisplay)
1072 (and bpos
(goto-char bpos
))
1073 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1074 (unless (setq ass
(assq r2 cmds
))
1075 (error "No command associated with key %c" r1
))
1076 (if (and bg
(nth 2 ass
)
1077 (not (buffer-base-buffer))
1078 (not (org-region-active-p)))
1079 ;; execute in background
1080 (let ((p (start-process
1081 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1083 (expand-file-name invocation-name invocation-directory
)
1086 "--eval" "(require 'org-exp)"
1087 "--eval" "(setq org-wait .2)"
1089 "-f" (symbol-name (nth 1 ass
)))))
1090 (set-process-sentinel p
'org-export-process-sentinel
)
1091 (message "Background process \"%s\": started" p
))
1092 ;; background processing not requested, or not possible
1093 (if subtree-p
(progn (org-mark-subtree) (org-activate-mark)))
1094 (call-interactively (nth 1 ass
))
1095 (when (and bpos
(get-buffer-window cbuf
))
1096 (let ((cw (selected-window)))
1097 (select-window (get-buffer-window cbuf
))
1100 (select-window cw
))))))
1102 (defun org-export-process-sentinel (process status
)
1103 (if (string-match "\n+\\'" status
)
1104 (setq status
(substring status
0 -
1)))
1105 (message "Background process \"%s\": %s" process status
))
1107 ;;; General functions for all backends
1109 (defvar org-export-target-aliases nil
1110 "Alist of targets with invisible aliases.")
1111 (defvar org-export-preferred-target-alist nil
1112 "Alist of section id's with preferred aliases.")
1113 (defvar org-export-id-target-alist nil
1114 "Alist of section id's with preferred aliases.")
1115 (defvar org-export-code-refs nil
1116 "Alist of code references and line numbers.")
1118 (defun org-export-preprocess-string (string &rest parameters
)
1119 "Cleanup STRING so that the true exported has a more consistent source.
1120 This function takes STRING, which should be a buffer-string of an org-file
1121 to export. It then creates a temporary buffer where it does its job.
1122 The result is then again returned as a string, and the exporter works
1123 on this string to produce the exported version."
1125 (let* ((org-export-current-backend (or (plist-get parameters
:for-backend
)
1126 org-export-current-backend
))
1127 (archived-trees (plist-get parameters
:archived-trees
))
1128 (inhibit-read-only t
)
1129 (drawers org-drawers
)
1130 (source-buffer (current-buffer))
1133 (setq org-export-target-aliases nil
1134 org-export-preferred-target-alist nil
1135 org-export-id-target-alist nil
1136 org-export-code-refs nil
)
1141 (setq case-fold-search t
)
1143 (let ((inhibit-read-only t
))
1144 (remove-text-properties (point-min) (point-max)
1147 ;; Remove license-to-kill stuff
1148 ;; The caller marks some stuff for killing, stuff that has been
1149 ;; used to create the page title, for example.
1150 (org-export-kill-licensed-text)
1152 (let ((org-inhibit-startup t
)) (org-mode))
1153 (setq case-fold-search t
)
1154 (org-clone-local-variables source-buffer
"^\\(org-\\|orgtbl-\\)")
1155 (org-install-letbind)
1158 (run-hooks 'org-export-preprocess-hook
)
1160 (untabify (point-min) (point-max))
1162 ;; Handle include files, and call a hook
1163 (org-export-handle-include-files-recurse)
1164 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1166 ;; Get rid of archived trees
1167 (org-export-remove-archived-trees archived-trees
)
1169 ;; Remove comment environment and comment subtrees
1170 (org-export-remove-comment-blocks-and-subtrees)
1172 ;; Get rid of excluded trees, and call a hook
1173 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1174 (plist-get parameters
:exclude-tags
))
1175 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1177 ;; Get rid of tasks, depending on configuration
1178 (org-export-remove-tasks (plist-get parameters
:tasks
))
1180 ;; Prepare footnotes for export. During that process, footnotes
1181 ;; actually included in the exported part of the buffer go
1182 ;; though some transformations:
1184 ;; 1. They have their label normalized (like "[N]");
1186 ;; 2. They get moved at the same place in the buffer (usually at
1187 ;; its end, but backends may define another place via
1188 ;; `org-footnote-insert-pos-for-preprocessor');
1190 ;; 3. The are stored in `org-export-footnotes-seen', while
1191 ;; `org-export-preprocess-string' is applied to their
1194 ;; Line-wise exporters ignore `org-export-footnotes-seen', as
1195 ;; they interpret footnotes at the moment they see them in the
1196 ;; buffer. Context-wise exporters grab all the info needed in
1197 ;; that variable and delete moved definitions (as described in
1199 (when (plist-get parameters
:footnotes
)
1200 (org-footnote-normalize nil parameters
))
1202 ;; Change lists ending. Other parts of export may insert blank
1203 ;; lines and lists' structure could be altered.
1204 (org-export-mark-list-end)
1206 ;; Process the macros
1207 (org-export-preprocess-apply-macros)
1208 (run-hooks 'org-export-preprocess-after-macros-hook
)
1210 ;; Export code blocks
1211 (org-export-blocks-preprocess)
1213 ;; Mark lists with properties
1214 (org-export-mark-list-properties)
1216 ;; Handle source code snippets
1217 (org-export-replace-src-segments-and-examples)
1219 ;; Protect short examples marked by a leading colon
1220 (org-export-protect-colon-examples)
1223 (org-export-convert-protected-spaces)
1225 ;; Find all headings and compute the targets for them
1226 (setq target-alist
(org-export-define-heading-targets target-alist
))
1228 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1230 ;; Find HTML special classes for headlines
1231 (org-export-remember-html-container-classes)
1233 ;; Get rid of drawers
1234 (org-export-remove-or-extract-drawers
1235 drawers
(plist-get parameters
:drawers
))
1237 ;; Get the correct stuff before the first headline
1238 (when (plist-get parameters
:skip-before-1st-heading
)
1239 (goto-char (point-min))
1240 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1241 (delete-region (point-min) (match-beginning 0))
1242 (goto-char (point-min))
1244 (when (plist-get parameters
:add-text
)
1245 (goto-char (point-min))
1246 (insert (plist-get parameters
:add-text
) "\n"))
1248 ;; Remove todo-keywords before exporting, if the user has requested so
1249 (org-export-remove-headline-metadata parameters
)
1251 ;; Find targets in comments and move them out of comments,
1252 ;; but mark them as targets that should be invisible
1253 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1255 ;; Select and protect backend specific stuff, throw away stuff
1256 ;; that is specific for other backends
1257 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1258 (org-export-select-backend-specific-text)
1260 ;; Protect quoted subtrees
1261 (org-export-protect-quoted-subtrees)
1263 ;; Remove clock lines
1264 (org-export-remove-clock-lines)
1266 ;; Protect verbatim elements
1267 (org-export-protect-verbatim)
1269 ;; Blockquotes, verse, and center
1270 (org-export-mark-blockquote-verse-center)
1271 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1273 ;; Remove timestamps, if the user has requested so
1274 (unless (plist-get parameters
:timestamps
)
1275 (org-export-remove-timestamps))
1277 ;; Attach captions to the correct object
1278 (setq target-alist
(org-export-attach-captions-and-attributes target-alist
))
1280 ;; Find matches for radio targets and turn them into internal links
1281 (org-export-mark-radio-links)
1282 (run-hooks 'org-export-preprocess-after-radio-targets-hook
)
1284 ;; Find all links that contain a newline and put them into a single line
1285 (org-export-concatenate-multiline-links)
1287 ;; Normalize links: Convert angle and plain links into bracket links
1288 ;; and expand link abbreviations
1289 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1290 (org-export-normalize-links)
1292 ;; Find all internal links. If they have a fuzzy match (i.e. not
1293 ;; a *dedicated* target match, let the link point to the
1294 ;; corresponding section.
1295 (org-export-target-internal-links target-alist
)
1297 ;; Find multiline emphasis and put them into single line
1298 (when (plist-get parameters
:emph-multiline
)
1299 (org-export-concatenate-multiline-emphasis))
1301 ;; Remove special table lines, and store alignment information
1302 (org-store-forced-table-alignment)
1303 (when org-export-table-remove-special-lines
1304 (org-export-remove-special-table-lines))
1307 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1309 ;; Backend-specific preprocessing
1310 (let* ((backend-name (symbol-name org-export-current-backend
))
1311 (f (intern (format "org-export-%s-preprocess" backend-name
))))
1312 (require (intern (concat "org-" backend-name
)) nil
)
1313 (funcall f parameters
))
1315 ;; Remove or replace comments
1316 (org-export-handle-comments (plist-get parameters
:comments
))
1318 ;; Remove #+TBLFM and #+TBLNAME lines
1319 (org-export-handle-table-metalines)
1321 ;; Remove #+results and #+name lines
1322 (org-export-res/src-name-cleanup
)
1324 ;; Run the final hook
1325 (run-hooks 'org-export-preprocess-final-hook
)
1327 (setq rtn
(buffer-string)))
1330 (defun org-export-kill-licensed-text ()
1331 "Remove all text that is marked with a :org-license-to-kill property."
1333 (while (setq p
(text-property-any (point-min) (point-max)
1334 :org-license-to-kill t
))
1336 p
(or (next-single-property-change p
:org-license-to-kill
)
1339 (defvar org-export-define-heading-targets-headline-hook nil
1340 "Hook that is run when a headline was matched during target search.
1341 This is part of the preprocessing for export.")
1343 (defun org-export-define-heading-targets (target-alist)
1344 "Find all headings and define the targets for them.
1345 The new targets are added to TARGET-ALIST, which is also returned.
1346 Also find all ID and CUSTOM_ID properties and store them."
1347 (goto-char (point-min))
1348 (org-init-section-numbers)
1349 (let ((re (concat "^" org-outline-regexp
1351 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1352 level target last-section-target a id
)
1353 (while (re-search-forward re nil t
)
1354 (org-if-unprotected-at (match-beginning 0)
1357 (setq id
(org-match-string-no-properties 2))
1358 (push (cons id target
) target-alist
)
1359 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1361 (push (list last-section-target
)
1362 org-export-target-aliases
)
1363 (car org-export-target-aliases
))))
1364 (push (caar target-alist
) (cdr a
))
1365 (when (equal (match-string 1) "CUSTOM_ID")
1366 (if (not (assoc last-section-target
1367 org-export-preferred-target-alist
))
1368 (push (cons last-section-target id
)
1369 org-export-preferred-target-alist
)))
1370 (when (equal (match-string 1) "ID")
1371 (if (not (assoc last-section-target
1372 org-export-id-target-alist
))
1373 (push (cons last-section-target
(concat "ID-" id
))
1374 org-export-id-target-alist
))))
1375 (setq level
(org-reduced-level
1376 (save-excursion (goto-char (point-at-bol))
1377 (org-outline-level))))
1378 (setq target
(org-solidify-link-text
1379 (format "sec-%s" (replace-regexp-in-string
1381 (org-section-number level
)))))
1382 (setq last-section-target target
)
1383 (push (cons target target
) target-alist
)
1384 (add-text-properties
1385 (point-at-bol) (point-at-eol)
1386 (list 'target target
))
1387 (run-hooks 'org-export-define-heading-targets-headline-hook
)))))
1390 (defun org-export-handle-invisible-targets (target-alist)
1391 "Find targets in comments and move them out of comments.
1392 Mark them as invisible targets."
1394 (goto-char (point-min))
1395 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1396 ;; Check if the line before or after is a headline with a target
1397 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1398 (get-text-property (point-at-bol 2) 'target
)))
1400 ;; use the existing target in a neighboring line
1401 (setq tmp
(match-string 2))
1403 (and (looking-at "\n") (delete-char 1))
1404 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1406 (setq a
(or (assoc target org-export-target-aliases
)
1408 (push (list target
) org-export-target-aliases
)
1409 (car org-export-target-aliases
))))
1411 ;; Make an invisible target
1412 (replace-match "\\1(INVISIBLE)"))))
1415 (defun org-export-target-internal-links (target-alist)
1416 "Find all internal links and assign targets to them.
1417 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1418 let the link point to the corresponding section.
1419 This function also handles the id links, if they have a match in
1421 (goto-char (point-min))
1422 (while (re-search-forward org-bracket-link-regexp nil t
)
1423 (org-if-unprotected-at (1+ (match-beginning 0))
1424 (let* ((org-link-search-must-match-exact-headline t
)
1426 (desc (match-end 2))
1427 (link (org-link-unescape (match-string 1)))
1428 (slink (org-solidify-link-text link
))
1429 found props pos cref
1432 ((= (string-to-char link
) ?
#)
1433 ;; user wants exactly this link
1435 ((cdr (assoc slink target-alist
))
1436 (or (cdr (assoc (assoc slink target-alist
)
1437 org-export-preferred-target-alist
))
1438 (cdr (assoc slink target-alist
))))
1439 ((and (string-match "^id:" link
)
1440 (cdr (assoc (substring link
3) target-alist
))))
1441 ((string-match "^(\\(.*\\))$" link
)
1442 (setq cref
(match-string 1 link
))
1443 (concat "coderef:" cref
))
1444 ((string-match org-link-types-re link
) nil
)
1445 ((or (file-name-absolute-p link
)
1446 (string-match "^\\." link
))
1449 (let ((org-link-search-inhibit-query t
))
1451 (setq found
(condition-case nil
(org-link-search link
)
1454 (or (org-at-heading-p)
1455 (not (eq found
'dedicated
))))
1456 (or (get-text-property (point) 'target
)
1459 (1- (or (previous-single-property-change
1460 (point) 'target
) 0)))
1464 (goto-char (match-beginning 1))
1465 (setq props
(text-properties-at (point)))
1466 (delete-region (match-beginning 1) (match-end 1))
1469 (unless desc
(insert "][" link
))
1470 (add-text-properties pos
(point) props
))))))
1472 (defun org-export-remember-html-container-classes ()
1473 "Store the HTML_CONTAINER_CLASS properties in a text property."
1474 (goto-char (point-min))
1476 (while (re-search-forward
1477 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t
)
1478 (setq class
(match-string 1))
1480 (org-back-to-heading t
)
1481 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1483 (defvar org-export-format-drawer-function nil
1484 "Function to be called to format the contents of a drawer.
1485 The function must accept two parameters:
1486 NAME the drawer name, like \"PROPERTIES\"
1487 CONTENT the content of the drawer.
1488 You can check the export backend through `org-export-current-backend'.
1489 The function should return the text to be inserted into the buffer.
1490 If this is nil, `org-export-format-drawer' is used as a default.")
1492 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1493 "Remove drawers, or extract and format the content.
1494 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1495 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1496 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1497 EXP-DRAWERS will be removed."
1498 (goto-char (point-min))
1499 (let ((re (concat "^[ \t]*:\\("
1500 (mapconcat 'identity all-drawers
"\\|")
1502 name beg beg-content eol content
)
1503 (while (re-search-forward re nil t
)
1505 (setq name
(match-string 1))
1506 (setq beg
(match-beginning 0)
1507 beg-content
(1+ (point-at-eol))
1509 (if (not (and (re-search-forward
1510 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1513 (goto-char (match-beginning 0))
1514 (and (looking-at ".*\n?") (replace-match ""))
1515 (setq content
(buffer-substring beg-content
(point)))
1516 (delete-region beg
(point))
1517 (when (or (eq exp-drawers t
)
1518 (member name exp-drawers
))
1519 (setq content
(funcall (or org-export-format-drawer-function
1520 'org-export-format-drawer
)
1522 (insert content
)))))))
1524 (defun org-export-format-drawer (name content
)
1525 "Format the content of a drawer as a colon example."
1526 (if (string-match "[ \t]+\\'" content
)
1527 (setq content
(substring content
(match-beginning 0))))
1528 (while (string-match "\\`[ \t]*\n" content
)
1529 (setq content
(substring content
(match-end 0))))
1530 (setq content
(org-remove-indentation content
))
1531 (setq content
(concat ": " (mapconcat 'identity
1532 (org-split-string content
"\n")
1535 (setq content
(concat " : " (upcase name
) "\n" content
))
1536 (org-add-props content nil
'org-protected t
))
1538 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1539 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1540 Both arguments are lists of tags.
1541 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1543 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1545 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1546 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1549 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1553 (goto-char (point-min))
1554 (when (and select-tags
1556 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1557 ;; At least one tree is marked for export, this means
1558 ;; all the unmarked stuff needs to go.
1559 ;; Dig out the trees that should be exported
1560 (goto-char (point-min))
1561 (outline-next-heading)
1563 (put-text-property beg
(point-max) :org-delete t
)
1564 (while (re-search-forward re-sel nil t
)
1565 (when (org-at-heading-p)
1566 (org-back-to-heading)
1567 (remove-text-properties
1568 (max (1- (point)) (point-min))
1569 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1571 (while (and (org-up-heading-safe)
1572 (get-text-property (point) :org-delete
))
1573 (remove-text-properties (max (1- (point)) (point-min))
1574 (point-at-eol) '(:org-delete t
)))
1576 ;; Remove the trees explicitly marked for noexport
1578 (goto-char (point-min))
1579 (while (re-search-forward re-excl nil t
)
1580 (when (org-at-heading-p)
1581 (org-back-to-heading t
)
1583 (org-end-of-subtree t t
)
1584 (delete-region beg
(point))
1585 (when (featurep 'org-inlinetask
)
1586 (org-inlinetask-remove-END-maybe)))))
1587 ;; Remove everything that is now still marked for deletion
1588 (goto-char (point-min))
1589 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1590 (setq end
(or (next-single-property-change beg
:org-delete
)
1592 (delete-region beg end
))))
1594 (defun org-export-remove-tasks (keep)
1595 "Remove tasks depending on configuration.
1596 When KEEP is nil, remove all tasks.
1597 When KEEP is `todo', remove the tasks that are DONE.
1598 When KEEP is `done', remove the tasks that are not yet done.
1599 When it is a list of strings, keep only tasks with these TODO keywords."
1600 (when (or (listp keep
) (memq keep
'(todo done nil
)))
1601 (let ((re (concat "^\\*+[ \t]+\\("
1604 (cond ((not keep
) org-todo-keywords-1
)
1605 ((eq keep
'todo
) org-done-keywords
)
1606 ((eq keep
'done
) org-not-done-keywords
)
1608 (org-delete-all keep
(copy-sequence
1609 org-todo-keywords-1
))))
1611 "\\)\\($\\|[ \t]\\)"))
1612 (case-fold-search nil
)
1614 (goto-char (point-min))
1615 (while (re-search-forward re nil t
)
1617 (setq beg
(match-beginning 0))
1618 (org-end-of-subtree t t
)
1619 (if (looking-at "^\\*+[ \t]+END[ \t]*$")
1620 ;; Kill the END line of the inline task
1621 (goto-char (min (point-max) (1+ (match-end 0)))))
1622 (delete-region beg
(point)))))))
1624 (defun org-export-remove-archived-trees (export-archived-trees)
1625 "Remove archived trees.
1626 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1627 When it is t, the entire archived tree will be exported.
1628 When it is nil the entire tree including the headline will be removed
1630 (let ((re-archive (concat ":" org-archive-tag
":"))
1632 (when (not (eq export-archived-trees t
))
1633 (goto-char (point-min))
1634 (while (re-search-forward re-archive nil t
)
1635 (if (not (org-at-heading-p t
))
1636 (goto-char (point-at-eol))
1637 (beginning-of-line 1)
1638 (setq a
(if export-archived-trees
1639 (1+ (point-at-eol)) (point))
1640 b
(org-end-of-subtree t
))
1641 (if (> b a
) (delete-region a b
)))))))
1643 (defun org-export-remove-headline-metadata (opts)
1644 "Remove meta data from the headline, according to user options."
1645 (let ((re org-complex-heading-regexp
)
1646 (todo (plist-get opts
:todo-keywords
))
1647 (tags (plist-get opts
:tags
))
1648 (pri (plist-get opts
:priority
))
1650 (case-fold-search nil
)
1652 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1653 (when (or (not todo
) (not tags
) (not pri
))
1654 (goto-char (point-min))
1655 (while (re-search-forward re nil t
)
1657 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1659 (replace-match rpl t t
))))))
1661 (defun org-export-remove-timestamps ()
1662 "Remove timestamps and keywords for export."
1663 (goto-char (point-min))
1664 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1667 (unless (save-match-data (org-at-table-p))
1669 (beginning-of-line 1)
1670 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1671 (replace-match ""))))))
1673 (defun org-export-remove-clock-lines ()
1674 "Remove clock lines for export."
1675 (goto-char (point-min))
1676 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1677 (while (re-search-forward re nil t
)
1679 (replace-match "")))))
1681 (defvar org-heading-keyword-regexp-format
) ; defined in org.el
1682 (defun org-export-protect-quoted-subtrees ()
1683 "Mark quoted subtrees with the protection property."
1684 (let ((org-re-quote (format org-heading-keyword-regexp-format
1686 (goto-char (point-min))
1687 (while (re-search-forward org-re-quote nil t
)
1688 (goto-char (match-beginning 0))
1690 (add-text-properties (point) (org-end-of-subtree t
)
1691 '(org-protected t
)))))
1693 (defun org-export-convert-protected-spaces ()
1694 "Convert strings like \\____ to protected spaces in all backends."
1695 (goto-char (point-min))
1696 (while (re-search-forward "\\\\__+" nil t
)
1697 (org-if-unprotected-1
1701 ((eq org-export-current-backend
'latex
)
1702 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1703 ((eq org-export-current-backend
'html
)
1704 (org-add-props (match-string 0) nil
1705 'org-whitespace
(- (match-end 0) (match-beginning 0))))
1706 ;; ((eq org-export-current-backend 'docbook))
1707 ((eq org-export-current-backend
'ascii
)
1708 (org-add-props (match-string 0) '(org-whitespace t
)))
1709 (t (make-string (- (match-end 0) (match-beginning 0)) ?\
)))
1713 (defun org-export-protect-verbatim ()
1714 "Mark verbatim snippets with the protection property."
1715 (goto-char (point-min))
1716 (while (re-search-forward org-verbatim-re nil t
)
1718 (add-text-properties (match-beginning 4) (match-end 4)
1719 '(org-protected t org-verbatim-emph t
))
1720 (goto-char (1+ (match-end 4))))))
1722 (defun org-export-protect-colon-examples ()
1723 "Protect lines starting with a colon."
1724 (goto-char (point-min))
1725 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1726 (while (re-search-forward re nil t
)
1727 (beginning-of-line 1)
1729 (while (looking-at re
)
1731 (or (eobp) (forward-char 1)))
1732 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1733 '(org-protected t
)))))
1735 (defvar org-export-backends
1736 '(docbook html beamer ascii latex
)
1737 "List of Org supported export backends.")
1739 (defun org-export-select-backend-specific-text ()
1740 (let ((formatters org-export-backends
)
1741 (case-fold-search t
)
1742 backend backend-name beg beg-content end end-content ind
)
1745 (setq backend
(pop formatters
)
1746 backend-name
(symbol-name backend
))
1748 ;; Handle #+BACKEND: stuff
1749 (goto-char (point-min))
1750 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" backend-name
1751 ":[ \t]*\\(.*\\)") nil t
)
1752 (if (not (eq backend org-export-current-backend
))
1753 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1754 (let ((ind (get-text-property (point-at-bol) 'original-indentation
)))
1755 (replace-match "\\1\\2" t
)
1756 (add-text-properties
1757 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1758 `(org-protected t original-indentation
,ind org-native-text t
)))))
1759 ;; Delete #+ATTR_BACKEND: stuff of another backend. Those
1760 ;; matching the current backend will be taken care of by
1761 ;; `org-export-attach-captions-and-attributes'
1762 (goto-char (point-min))
1763 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+ATTR_" backend-name
1764 ":[ \t]*\\(.*\\)") nil t
)
1765 (setq ind
(org-get-indentation))
1766 (when (not (eq backend org-export-current-backend
))
1767 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1768 ;; Handle #+BEGIN_BACKEND and #+END_BACKEND stuff
1769 (goto-char (point-min))
1770 (while (re-search-forward (concat "^[ \t]*#\\+BEGIN_" backend-name
"\\>.*\n?")
1772 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1773 (setq ind
(or (get-text-property beg
'original-indentation
)
1774 (save-excursion (goto-char beg
) (org-get-indentation))))
1775 (when (re-search-forward (concat "^[ \t]*#\\+END_" backend-name
"\\>.*\n?")
1777 (setq end
(match-end 0) end-content
(match-beginning 0))
1778 (if (eq backend org-export-current-backend
)
1781 (add-text-properties
1782 beg-content end-content
1783 `(org-protected t original-indentation
,ind org-native-text t
))
1784 ;; strip protective commas
1785 (org-strip-protective-commas beg-content end-content
)
1786 (delete-region (match-beginning 0) (match-end 0))
1789 (delete-region (point) (1+ (point-at-eol)))))
1790 ;; No, this is for a different backend, kill it
1791 (delete-region beg end
)))))))
1793 (defun org-export-mark-blockquote-verse-center ()
1794 "Mark block quote and verse environments with special cookies.
1795 These special cookies will later be interpreted by the backend."
1797 (let (type t1 ind beg end beg1 end1 content
)
1798 (goto-char (point-min))
1799 (while (re-search-forward
1800 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1802 (setq ind
(length (match-string 1))
1803 type
(downcase (match-string 3))
1804 t1
(if (equal type
"quote") "blockquote" type
))
1805 (setq beg
(match-beginning 0)
1806 beg1
(1+ (match-end 0)))
1807 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1808 (setq end1
(1- (match-beginning 0))
1809 end
(+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1810 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1811 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1813 "ORG-" (upcase t1
) "-END\n"))
1814 (delete-region beg end
)
1815 (insert (org-add-props content nil
'original-indentation ind
))))))
1817 (defun org-export-mark-list-end ()
1818 "Mark all list endings with a special string."
1819 (unless (eq org-export-current-backend
'ascii
)
1822 ;; For each type allowing list export, find every list, remove
1823 ;; ending regexp if needed, and insert org-list-end.
1824 (goto-char (point-min))
1825 (while (re-search-forward (org-item-beginning-re) nil t
)
1826 (when (eq (nth 2 (org-list-context)) e
)
1827 (let* ((struct (org-list-struct))
1828 (bottom (org-list-get-bottom-point struct
))
1829 (top (point-at-bol))
1830 (top-ind (org-list-get-ind top struct
)))
1832 (when (and (not (looking-at "[ \t]*$"))
1833 (looking-at org-list-end-re
))
1835 (unless (bolp) (insert "\n"))
1836 ;; As org-list-end is inserted at column 0, it would end
1837 ;; by indentation any list. It can be problematic when
1838 ;; there are lists within lists: the inner list end would
1839 ;; also become the outer list end. To avoid this, text
1840 ;; property `original-indentation' is added, as
1841 ;; `org-list-struct' pays attention to it when reading a
1843 (insert (org-add-props
1844 "ORG-LIST-END-MARKER\n"
1845 (list 'original-indentation top-ind
)))))))
1846 (cons nil org-list-export-context
))))
1848 (defun org-export-mark-list-properties ()
1849 "Mark list with special properties.
1850 These special properties will later be interpreted by the backend."
1853 ;; Mark a list with 3 properties: `list-item' which is
1854 ;; position at beginning of line, `list-struct' which is
1855 ;; list structure, and `list-prevs' which is the alist of
1856 ;; item and its predecessor. Leave point at list ending.
1858 (let* ((struct (org-list-struct))
1859 (top (org-list-get-top-point struct
))
1860 (bottom (org-list-get-bottom-point struct
))
1861 (prevs (org-list-prevs-alist struct
))
1863 ;; Get every item and ending position, without dups and
1864 ;; without bottom point of list.
1868 (unless (memq pos poi
)
1870 (unless (or (= end bottom
) (memq end poi
))
1873 (setq poi
(sort poi
'<))
1874 ;; For every point of interest, mark the whole line with
1875 ;; its position in list.
1879 (add-text-properties (point-at-bol) (point-at-eol)
1880 (list 'list-item
(point-at-bol)
1882 'list-prevs prevs
)))
1884 ;; Take care of bottom point. As babel may have inserted
1885 ;; a new list in buffer, list ending isn't always
1886 ;; marked. Now mark every list ending and add properties
1887 ;; useful to line processing exporters.
1889 (when (or (looking-at "^ORG-LIST-END-MARKER\n")
1890 (and (not (looking-at "[ \t]*$"))
1891 (looking-at org-list-end-re
)))
1893 (unless (bolp) (insert "\n"))
1895 (org-add-props "ORG-LIST-END-MARKER\n" (list 'list-item bottom
1897 'list-prevs prevs
)))
1898 ;; Following property is used by LaTeX exporter.
1899 (add-text-properties top
(point) (list 'list-context ctxt
)))))))
1900 ;; Mark lists except for backends not interpreting them.
1901 (unless (eq org-export-current-backend
'ascii
)
1902 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
1905 (goto-char (point-min))
1906 (while (re-search-forward (org-item-beginning-re) nil t
)
1907 (let ((context (nth 2 (org-list-context))))
1909 (funcall mark-list e
)
1910 (put-text-property (point-at-bol) (point-at-eol)
1911 'list-context context
)))))
1912 (cons nil org-list-export-context
))))))
1914 (defun org-export-attach-captions-and-attributes (target-alist)
1915 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1916 If the next thing following is a table, add the text properties to the first
1917 table line. If it is a link, add it to the line containing the link."
1918 (goto-char (point-min))
1919 (remove-text-properties (point-min) (point-max)
1920 '(org-caption nil org-attributes nil
))
1921 (let ((case-fold-search t
)
1922 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1924 "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend
) ":[ \t]+\\(.*\\)"
1926 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1928 "^[ \t]*\\(|[^-]\\)"
1930 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1931 cap shortn attr label end
)
1932 (while (re-search-forward re nil t
)
1934 ;; there is a caption
1937 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1))))
1938 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap
)
1939 (setq shortn
(match-string 1 cap
)
1940 cap
(match-string 2 cap
)))
1941 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1942 ;; there is an attribute
1945 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2))))
1946 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1950 (setq label
(org-trim (match-string 3)))
1951 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1953 (setq end
(if (match-end 4)
1954 (let ((ee (org-table-end)))
1955 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1957 (add-text-properties (point-at-bol) end
1958 (list 'org-caption cap
1959 'org-caption-shortn shortn
1960 'org-attributes attr
1962 (if label
(push (cons label label
) target-alist
))
1964 (setq cap nil shortn nil attr nil label nil
)))))
1967 (defun org-export-remove-comment-blocks-and-subtrees ()
1968 "Remove the comment environment, and also commented subtrees."
1969 (let ((re-commented (format org-heading-keyword-regexp-format
1970 org-comment-string
))
1972 ;; Remove comment environment
1973 (goto-char (point-min))
1974 (setq case-fold-search t
)
1975 (while (re-search-forward
1976 "^#\\+begin_comment[ \t]*\n[^\000]*?\n#\\+end_comment\\>.*" nil t
)
1977 (replace-match "" t t
))
1978 ;; Remove subtrees that are commented
1979 (goto-char (point-min))
1980 (setq case-fold-search nil
)
1981 (while (re-search-forward re-commented nil t
)
1982 (goto-char (match-beginning 0))
1983 (delete-region (point) (org-end-of-subtree t
)))))
1985 (defun org-export-handle-comments (org-commentsp)
1986 "Remove comments, or convert to backend-specific format.
1987 ORG-COMMENTSP can be a format string for publishing comments.
1988 When it is nil, all comments will be removed."
1989 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1991 (goto-char (point-min))
1992 (while (or (looking-at re
)
1993 (re-search-forward re nil t
))
1994 (setq pos
(match-beginning 0))
1995 (if (get-text-property pos
'org-protected
)
1996 (goto-char (1+ pos
))
1997 (if (and org-commentsp
1998 (not (equal (char-before (match-end 1)) ?
+)))
1999 (progn (add-text-properties
2000 (match-beginning 0) (match-end 0) '(org-protected t
))
2001 (replace-match (org-add-props
2002 (format org-commentsp
(match-string 2))
2003 nil
'org-protected t
)
2005 (goto-char (1+ pos
))
2007 (goto-char (max (point-min) (1- pos
))))))))
2009 (defun org-export-handle-table-metalines ()
2010 "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
2011 (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
2013 (goto-char (point-min))
2014 (while (or (looking-at re
)
2015 (re-search-forward re nil t
))
2016 (setq pos
(match-beginning 0))
2017 (if (get-text-property (match-beginning 1) 'org-protected
)
2018 (goto-char (1+ pos
))
2019 (goto-char (1+ pos
))
2021 (goto-char (max (point-min) (1- pos
)))))))
2023 (defun org-export-res/src-name-cleanup
()
2024 "Clean up #+results and #+name lines for export.
2025 This function should only be called after all block processing
2029 (goto-char (point-min))
2030 (let ((case-fold-search t
))
2031 (while (org-re-search-forward-unprotected
2032 "#\\+\\(name\\|results\\(\\[[a-z0-9]+\\]\\)?\\):" nil t
)
2033 (delete-region (match-beginning 0) (progn (forward-line) (point)))))))
2035 (defun org-export-mark-radio-links ()
2036 "Find all matches for radio targets and turn them into internal links."
2037 (let ((re-radio (and org-target-link-regexp
2038 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
2039 (goto-char (point-min))
2041 (while (re-search-forward re-radio nil t
)
2044 (or (org-in-regexp org-bracket-link-regexp
)
2045 (org-in-regexp org-plain-link-re
)
2046 (org-in-regexp "<<[^<>]+>>")))
2048 (replace-match "\\1[[\\2]]")))))))
2050 (defun org-store-forced-table-alignment ()
2051 "Find table lines which force alignment, store the results in properties."
2052 (let (line cnt cookies
)
2053 (goto-char (point-min))
2054 (while (re-search-forward "|[ \t]*<\\([lrc]?[0-9]+\\|[lrc]\\)>[ \t]*|"
2056 ;; OK, this looks like a table line with an alignment cookie
2058 (setq line
(buffer-substring (point-at-bol) (point-at-eol)))
2059 (when (and (org-at-table-p)
2060 (org-table-cookie-line-p line
))
2061 (setq cnt
0 cookies nil
)
2065 (when (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'" x
)
2066 (let ((align (and (match-end 1)
2067 (downcase (match-string 1 x
))))
2068 (width (and (match-end 2)
2069 (string-to-number (match-string 2 x
)))))
2070 (push (cons cnt
(list align width
)) cookies
))))
2071 (org-split-string line
"[ \t]*|[ \t]*"))
2072 (add-text-properties (org-table-begin) (org-table-end)
2073 (list 'org-col-cookies cookies
))))
2074 (goto-char (point-at-eol)))))
2076 (defun org-export-remove-special-table-lines ()
2077 "Remove tables lines that are used for internal purposes.
2078 Also, store forced alignment information found in such lines."
2079 (goto-char (point-min))
2080 (while (re-search-forward "^[ \t]*|" nil t
)
2081 (org-if-unprotected-at (1- (point))
2082 (beginning-of-line 1)
2083 (if (or (looking-at "[ \t]*| *[!_^] *|")
2089 (or (and org-export-table-remove-empty-lines
(= (length f
) 0))
2091 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f
)))
2092 (org-split-string ;; FIXME, can't we do without splitting???
2093 (buffer-substring (point-at-bol) (point-at-eol))
2094 "[ \t]*|[ \t]*")))))
2095 (delete-region (max (point-min) (1- (point-at-bol)))
2099 (defun org-export-protect-sub-super (s)
2101 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
2102 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
2105 (defun org-export-normalize-links ()
2106 "Convert all links to bracket links, and expand link abbreviations."
2107 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2108 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
2110 (goto-char (point-min))
2111 (while (re-search-forward org-bracket-link-regexp nil t
)
2112 (put-text-property (match-beginning 0) (match-end 0) 'org-normalized-link t
))
2113 (goto-char (point-min))
2114 (while (re-search-forward re-plain-link nil t
)
2115 (unless (get-text-property (match-beginning 0) 'org-normalized-link
)
2116 (goto-char (1- (match-end 0)))
2117 (org-if-unprotected-at (1+ (match-beginning 0))
2118 (let* ((s (concat (match-string 1)
2119 "[[" (match-string 2) ":" (match-string 3)
2120 "][" (match-string 2) ":" (org-export-protect-sub-super
2123 ;; added 'org-link face to links
2124 (put-text-property 0 (length s
) 'face
'org-link s
)
2125 (replace-match s t t
)))))
2126 (goto-char (point-min))
2127 (while (re-search-forward re-angle-link nil t
)
2128 (goto-char (1- (match-end 0)))
2130 (let* ((s (concat (match-string 1)
2131 "[[" (match-string 2) ":" (match-string 3)
2132 "][" (match-string 2) ":" (org-export-protect-sub-super
2135 (put-text-property 0 (length s
) 'face
'org-link s
)
2136 (replace-match s t t
))))
2137 (goto-char (point-min))
2138 (while (re-search-forward org-bracket-link-regexp nil t
)
2139 (goto-char (1- (match-end 0)))
2140 (setq nodesc
(not (match-end 3)))
2142 (let* ((xx (save-match-data
2144 (org-link-expand-abbrev (match-string 1)))))
2146 "[[" (org-add-props (copy-sequence xx
)
2147 nil
'org-protected t
'org-no-description nodesc
)
2151 (concat "[" (copy-sequence xx
)
2154 (put-text-property 0 (length s
) 'face
'org-link s
)
2155 (replace-match s t t
))))))
2157 (defun org-export-concatenate-multiline-links ()
2158 "Find multi-line links and put it all into a single line.
2159 This is to make sure that the line-processing export backends
2160 can work correctly."
2161 (goto-char (point-min))
2162 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2163 (org-if-unprotected-at (match-beginning 1)
2164 (replace-match "\\1 \\3")
2165 (goto-char (match-beginning 0)))))
2167 (defun org-export-concatenate-multiline-emphasis ()
2168 "Find multi-line emphasis and put it all into a single line.
2169 This is to make sure that the line-processing export backends
2170 can work correctly."
2171 (goto-char (point-min))
2172 (while (re-search-forward org-emph-re nil t
)
2173 (if (and (not (= (char-after (match-beginning 3))
2174 (char-after (match-beginning 4))))
2175 (save-excursion (goto-char (match-beginning 0))
2177 (and (not (org-at-table-p))
2178 (not (org-at-heading-p))))))
2180 (subst-char-in-region (match-beginning 0) (match-end 0)
2182 (goto-char (1- (match-end 0))))
2183 (goto-char (1+ (match-beginning 0))))))
2185 (defun org-export-grab-title-from-buffer ()
2186 "Get a title for the current document, from looking at the buffer."
2187 (let ((inhibit-read-only t
))
2189 (goto-char (point-min))
2190 (let ((end (if (looking-at org-outline-regexp
)
2192 (save-excursion (outline-next-heading) (point)))))
2193 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2194 ;; Mark the line so that it will not be exported as normal text.
2195 (unless (org-in-block-p org-list-forbidden-blocks
)
2197 (add-text-properties (match-beginning 0) (match-end 0)
2198 (list :org-license-to-kill t
))))
2199 ;; Return the title string
2200 (org-trim (match-string 0)))))))
2202 (defun org-export-get-title-from-subtree ()
2203 "Return subtree title and exclude it from export."
2204 (let ((rbeg (region-beginning)) (rend (region-end))
2205 (inhibit-read-only t
)
2206 (tags (plist-get (org-infile-export-plist) :tags
))
2210 (when (and (org-at-heading-p)
2211 (>= (org-end-of-subtree t t
) rend
))
2212 (when (plist-member org-export-opt-plist
:tags
)
2213 (setq tags
(or (plist-get org-export-opt-plist
:tags
) tags
)))
2214 ;; This is a subtree, we take the title from the first heading
2216 (looking-at org-todo-line-tags-regexp
)
2217 (setq title
(if (and (eq tags t
) (match-string 4))
2218 (format "%s\t%s" (match-string 3) (match-string 4))
2221 (add-text-properties (point) (1+ (point-at-eol))
2222 (list :org-license-to-kill t
)))
2223 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2226 (defun org-solidify-link-text (s &optional alist
)
2227 "Take link text and make a safe target out of it."
2232 (org-split-string s
"[^a-zA-Z0-9_\\.-]+") "-"))
2233 (a (assoc rtn alist
)))
2236 (defun org-get-min-level (lines &optional offset
)
2237 "Get the minimum level in LINES."
2238 (let ((re "^\\(\\*+\\) ") l
)
2240 (while (setq l
(pop lines
))
2241 (if (string-match re l
)
2242 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2246 ;; Variable holding the vector with section numbers
2247 (defvar org-section-numbers
(make-vector org-level-max
0))
2249 (defun org-init-section-numbers ()
2250 "Initialize the vector for the section numbers."
2252 (numbers (nreverse (org-split-string "" "\\.")))
2253 (depth (1- (length org-section-numbers
)))
2254 (i depth
) number-string
)
2257 (aset org-section-numbers i
0)
2258 (setq number-string
(or (car numbers
) "0"))
2259 (if (string-match "\\`[A-Z]\\'" number-string
)
2260 (aset org-section-numbers i
2261 (- (string-to-char number-string
) ?A -
1))
2262 (aset org-section-numbers i
(string-to-number number-string
)))
2266 (defun org-section-number (&optional level
)
2267 "Return a string with the current section number.
2268 When LEVEL is non-nil, increase section numbers on that level."
2269 (let* ((depth (1- (length org-section-numbers
)))
2271 (fmts (car org-export-section-number-format
))
2272 (term (cdr org-export-section-number-format
))
2277 (aset org-section-numbers
2278 level
(1+ (aref org-section-numbers level
))))
2279 (setq idx
(1+ level
))
2280 (while (<= idx depth
)
2282 (aset org-section-numbers idx
0))
2283 (setq idx
(1+ idx
))))
2285 (while (<= idx depth
)
2286 (when (> (aref org-section-numbers idx
) 0)
2287 (setq fmt
(or (pop fmts
) fmt
)
2289 n
(aref org-section-numbers idx
)
2291 (concat string sep
(org-number-to-counter n ctype
))
2292 (concat string
".0"))
2294 (setq idx
(1+ idx
)))
2296 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2297 (setq string
(replace-match "" t nil string
)))
2298 (if (string-match "\\(\\.0\\)+\\'" string
)
2299 (setq string
(replace-match "" t nil string
))))
2300 (concat string term
)))
2302 (defun org-number-to-counter (n type
)
2303 "Concert number N to a string counter, according to TYPE.
2304 TYPE must be a string, any of:
2308 I upper case roman numeral
2309 i lower case roman numeral"
2311 ((equal type
"1") (number-to-string n
))
2312 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2313 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2314 ((equal type
"I") (org-number-to-roman n
))
2315 ((equal type
"i") (downcase (org-number-to-roman n
)))
2316 (t (error "Invalid counter type `%s'" type
))))
2318 (defun org-number-to-roman (n)
2319 "Convert integer N into a roman numeral."
2320 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2321 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2322 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2326 (number-to-string n
)
2328 (if (>= n
(caar roman
))
2329 (setq n
(- n
(caar roman
))
2330 res
(concat res
(cdar roman
)))
2336 (defun org-export-preprocess-apply-macros ()
2337 "Replace macro references."
2338 (goto-char (point-min))
2339 (let (sy val key args args2 ind-str s n
)
2340 (while (re-search-forward
2341 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2343 (unless (save-match-data (save-excursion
2344 (goto-char (point-at-bol))
2345 (looking-at "[ \t]*#\\+macro")))
2346 ;; Get macro name (KEY), arguments (ARGS), and indentation of
2347 ;; current line (IND-STR) as strings.
2348 (setq key
(downcase (match-string 1))
2349 args
(match-string 3)
2350 ind-str
(save-match-data (save-excursion
2352 (looking-at "^\\([ \t]*\\).*")
2354 ;; When macro is defined, retrieve replacement text in VAL,
2355 ;; and proceed with expansion.
2356 (when (setq val
(or (plist-get org-export-opt-plist
2357 (intern (concat ":macro-" key
)))
2358 (plist-get org-export-opt-plist
2359 (intern (concat ":" key
)))))
2361 ;; If arguments are provided, first retrieve them properly
2362 ;; (in ARGS, as a list), then replace them in VAL.
2364 (setq args
(org-split-string args
",") args2 nil
)
2366 (while (string-match "\\\\\\'" (car args
))
2367 ;; Repair bad splits.
2368 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2371 (push (pop args
) args2
))
2372 (setq args
(mapcar 'org-trim
(nreverse args2
)))
2374 (while (string-match "\\$\\([0-9]+\\)" val s
)
2375 (setq s
(1+ (match-beginning 0))
2376 n
(string-to-number (match-string 1 val
)))
2377 (and (>= (length args
) n
)
2378 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2379 ;; VAL starts with "(eval": it is a sexp, `eval' it.
2380 (when (string-match "\\`(eval\\>" val
)
2381 (setq val
(eval (read val
))))
2382 ;; Ensure VAL is a string (or nil) and that each new line
2383 ;; is indented as the first one.
2385 (mapconcat 'identity
2387 (if (stringp val
) val
(format "%s" val
))
2389 (concat "\n" ind-str
)))))
2390 ;; Eventually do the replacement, if VAL isn't nil. Move
2391 ;; point at beginning of macro for recursive expansions.
2393 (replace-match val t t
)
2394 (goto-char (match-beginning 0))))))))
2396 (defun org-export-apply-macros-in-string (s)
2397 "Apply the macros in string S."
2401 (org-export-preprocess-apply-macros)
2406 (defun org-export-handle-include-files ()
2407 "Include the contents of include files, with proper formatting."
2408 (let ((case-fold-search t
)
2409 params file markup lang start end prefix prefix1 switches all minlevel lines
)
2410 (goto-char (point-min))
2411 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2412 (setq params
(read (concat "(" (match-string 1) ")"))
2413 prefix
(org-get-and-remove-property 'params
:prefix
)
2414 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2415 minlevel
(org-get-and-remove-property 'params
:minlevel
)
2416 lines
(org-get-and-remove-property 'params
:lines
)
2417 file
(org-symname-or-string (pop params
))
2418 markup
(org-symname-or-string (pop params
))
2419 lang
(and (member markup
'("src" "SRC"))
2420 (org-symname-or-string (pop params
)))
2421 switches
(mapconcat #'(lambda (x) (format "%s" x
)) params
" ")
2423 (delete-region (match-beginning 0) (match-end 0))
2425 (not (file-exists-p file
))
2426 (not (file-readable-p file
)))
2427 (insert (format "CANNOT INCLUDE FILE %s" file
))
2428 (setq all
(cons file all
))
2430 (if (equal (downcase markup
) "src")
2431 (setq start
(format "#+begin_src %s %s\n"
2432 (or lang
"fundamental")
2435 (setq start
(format "#+begin_%s %s\n" markup switches
)
2436 end
(format "#+end_%s" markup
))))
2437 (insert (or start
""))
2438 (insert (org-get-file-contents (expand-file-name file
)
2439 prefix prefix1 markup minlevel lines
))
2440 (or (bolp) (newline))
2441 (insert (or end
""))))
2444 (defun org-export-handle-include-files-recurse ()
2445 "Recursively include files aborting on circular inclusion."
2446 (let ((now (list org-current-export-file
)) all
)
2448 (setq all
(append now all
))
2449 (setq now
(org-export-handle-include-files))
2452 (mapcar (lambda (el) (when (member el all
) el
)) now
))))
2454 (error "Recursive #+INCLUDE: %S" intersection
))))))
2456 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel lines
)
2457 "Get the contents of FILE and return them as a string.
2458 If PREFIX is a string, prepend it to each line. If PREFIX1
2459 is a string, prepend it to the first line instead of PREFIX.
2460 If MARKUP, don't protect org-like lines, the exporter will
2461 take care of the block they are in. If LINES is a string
2462 specifying a range of lines, include only those lines ."
2463 (if (stringp markup
) (setq markup
(downcase markup
)))
2465 (insert-file-contents file
)
2467 (let* ((lines (split-string lines
"-"))
2468 (lbeg (string-to-number (car lines
)))
2469 (lend (string-to-number (cadr lines
)))
2470 (beg (if (zerop lbeg
) (point-min)
2471 (goto-char (point-min))
2472 (forward-line (1- lbeg
))
2474 (end (if (zerop lend
) (point-max)
2475 (goto-char (point-min))
2476 (forward-line (1- lend
))
2478 (narrow-to-region beg end
)))
2479 (when (or prefix prefix1
)
2480 (goto-char (point-min))
2482 (insert (or prefix1 prefix
))
2484 (beginning-of-line 2)))
2486 (when (member markup
'("src" "example"))
2487 (goto-char (point-min))
2488 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2489 (goto-char (match-beginning 0))
2493 (dotimes (lvl minlevel
)
2494 (org-map-region 'org-demote
(point-min) (point-max))))
2497 (defun org-get-and-remove-property (listvar prop
)
2498 "Check if the value of LISTVAR contains PROP as a property.
2499 If yes, return the value of that property (i.e. the element following
2500 in the list) and remove property and value from the list in LISTVAR."
2501 (let ((list (symbol-value listvar
)) m v
)
2502 (when (setq m
(member prop list
))
2504 (if (equal (car list
) prop
)
2505 (set listvar
(cddr list
))
2506 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2508 (set listvar list
)))
2511 (defun org-symname-or-string (s)
2513 (if s
(symbol-name s
) s
)
2516 ;;; Fontification and line numbers for code examples
2518 (defvar org-export-last-code-line-counter-value
0)
2520 (defun org-export-replace-src-segments-and-examples ()
2521 "Replace source code segments with special code for export."
2522 (setq org-export-last-code-line-counter-value
0)
2523 (let ((case-fold-search t
)
2524 lang code trans opts indent caption
)
2525 (goto-char (point-min))
2526 (while (re-search-forward
2527 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2530 (if (not (match-string 4))
2531 (error "Source block missing language specification: %s"
2532 (let* ((body (match-string 6))
2533 (nothing (message "body:%s" body
))
2534 (preview (or (and (string-match
2535 "^[ \t]*\\([^\n\r]*\\)" body
)
2536 (match-string 1 body
)) body
)))
2537 (if (> (length preview
) 35)
2538 (concat (substring preview
0 32) "...")
2541 (setq lang
(match-string 4)
2542 opts
(match-string 5)
2543 code
(match-string 6)
2544 indent
(length (match-string 2))
2545 caption
(get-text-property 0 'org-caption
(match-string 0))))
2547 opts
(match-string 9)
2548 code
(match-string 10)
2549 indent
(length (match-string 8))
2550 caption
(get-text-property 0 'org-caption
(match-string 0))))
2552 (setq trans
(org-export-format-source-code-or-example
2553 lang code opts indent caption
))
2554 (replace-match trans t t
))))
2556 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2557 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2558 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2559 (defvar org-export-latex-listings-w-names
) ;; defined in org-latex.el
2560 (defvar org-export-latex-minted-langs
) ;; defined in org-latex.el
2561 (defvar org-export-latex-custom-lang-environments
) ;; defined in org-latex.el
2562 (defvar org-export-latex-listings-options
) ;; defined in org-latex.el
2563 (defvar org-export-latex-minted-options
) ;; defined in org-latex.el
2565 (defun org-remove-formatting-on-newlines-in-region (beg end
)
2566 "Remove formatting on newline characters"
2570 (while (progn (end-of-line) (< (point) end
))
2571 (put-text-property (point) (1+ (point)) 'face nil
)
2574 (defun org-export-format-source-code-or-example
2575 (lang code
&optional opts indent caption
)
2576 "Format CODE from language LANG and return it formatted for export.
2577 The CODE is marked up in `org-export-current-backend' format.
2579 Check if a function by name
2580 \"org-<backend>-format-source-code-or-example\" is bound. If yes,
2581 use it as the custom formatter. Otherwise, use the default
2582 formatter. Default formatters are provided for docbook, html,
2583 latex and ascii backends. For example, use
2584 `org-html-format-source-code-or-example' to provide a custom
2585 formatter for export to \"html\".
2587 If LANG is nil, do not add any fontification.
2588 OPTS contains formatting options, like `-n' for triggering numbering lines,
2589 and `+n' for continuing previous numbering.
2590 Code formatting according to language currently only works for HTML.
2591 Numbering lines works for all three major backends (html, latex, and ascii).
2592 INDENT was the original indentation of the block."
2594 (let* ((backend-name (symbol-name org-export-current-backend
))
2596 (intern (format "org-%s-format-source-code-or-example"
2598 (backend-feature (intern (concat "org-" backend-name
)))
2600 (and (require (intern (concat "org-" backend-name
)) nil
)
2601 (fboundp backend-formatter
) backend-formatter
))
2602 num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2603 (setq opts
(or opts
"")
2604 num
(string-match "[-+]n\\>" opts
)
2605 cont
(string-match "\\+n\\>" opts
)
2606 rpllbl
(string-match "-r\\>" opts
)
2607 keepp
(string-match "-k\\>" opts
)
2608 textareap
(string-match "-t\\>" opts
)
2609 preserve-indentp
(or org-src-preserve-indentation
2610 (string-match "-i\\>" opts
))
2611 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2612 (string-to-number (match-string 1 opts
))
2614 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2615 (string-to-number (match-string 1 opts
))
2616 (org-count-lines code
))
2617 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2618 (match-string 1 opts
)))
2619 (when (and textareap
(eq org-export-current-backend
'html
))
2620 ;; we cannot use numbering or highlighting.
2621 (setq num nil cont nil lang nil
))
2622 (if keepp
(setq rpllbl
'keep
))
2623 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2624 (when (string-match "^," rtn
)
2625 (setq rtn
(with-temp-buffer
2627 ;; Free up the protected lines
2628 (goto-char (point-min))
2629 (while (re-search-forward "^," nil t
)
2630 (if (or (equal lang
"org")
2632 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2636 ;; Now backend-specific coding
2640 (funcall backend-formatter rtn lang caption textareap cols rows num
2642 ((eq org-export-current-backend
'docbook
)
2643 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2644 (concat "<programlisting><![CDATA["
2646 "]]></programlisting>\n"))
2647 ((eq org-export-current-backend
'html
)
2648 ;; We are exporting to HTML
2650 (if (featurep 'xemacs
)
2652 (require 'htmlize nil t
))
2653 (when (not (fboundp 'htmlize-region-for-paste
))
2654 ;; we do not have htmlize.el, or an old version of it
2657 "htmlize.el 1.34 or later is needed for source code formatting")))
2660 (let* ((lang-m (when lang
2661 (or (cdr (assoc lang org-src-lang-modes
))
2663 (mode (and lang-m
(intern
2665 (if (symbolp lang-m
)
2666 (symbol-name lang-m
)
2669 (org-inhibit-startup t
)
2670 (org-startup-folded nil
))
2674 (if (functionp mode
)
2677 (font-lock-fontify-buffer)
2678 ;; markup each line separately
2679 (org-remove-formatting-on-newlines-in-region (point-min) (point-max))
2681 (set-buffer-modified-p nil
)
2682 (org-export-htmlize-region-for-paste
2683 (point-min) (point-max))))
2684 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2689 "<div class=\"org-src-container\">"
2691 "<label class=\"org-src-name\">%s</label>"
2695 (format "<pre class=\"src src-%s\">\n" lang
)
2697 (if caption
"</div>" "")))))
2700 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2702 rtn
"</textarea>\n</p>\n"))
2705 (goto-char (point-min))
2706 (while (re-search-forward "[<>&]" nil t
)
2707 (replace-match (cdr (assq (char-before)
2708 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2710 (setq rtn
(buffer-string)))
2711 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2713 (setq rtn
(org-export-number-lines rtn
1 1 num cont rpllbl fmt
)))
2714 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2715 (setq rtn
(replace-match "\\1" t nil rtn
)))
2717 ((eq org-export-current-backend
'latex
)
2718 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2720 ((and lang org-export-latex-listings
)
2721 (flet ((make-option-string
2723 (concat (first pair
)
2724 (if (> (length (second pair
)) 0)
2725 (concat "=" (second pair
))))))
2726 (let* ((lang-sym (intern lang
))
2727 (minted-p (eq org-export-latex-listings
'minted
))
2728 (listings-p (not minted-p
))
2734 (minted-p org-export-latex-minted-langs
)
2735 (listings-p org-export-latex-listings-langs
))))
2741 org-export-latex-custom-lang-environments
))))
2743 (when (and listings-p
(not custom-environment
))
2747 #'make-option-string
2748 (append org-export-latex-listings-options
2749 `(("language" ,backend-lang
))) ",")))
2750 (when (and caption org-export-latex-listings-w-names
)
2753 (replace-regexp-in-string "_" "\\\\_" caption
)))
2756 (format "\\begin{%s}\n%s\\end{%s}\n"
2757 custom-environment rtn custom-environment
))
2759 (format "\\begin{%s}\n%s\\end{%s}"
2760 "lstlisting" rtn
"lstlisting"))
2763 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2764 (mapconcat #'make-option-string
2765 org-export-latex-minted-options
",")
2766 backend-lang rtn
)))))))
2767 (t (concat (car org-export-latex-verbatim-wrap
)
2768 rtn
(cdr org-export-latex-verbatim-wrap
)))))
2769 ((eq org-export-current-backend
'ascii
)
2770 ;; This is not HTML or LaTeX, so just make it an example.
2771 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2772 (concat caption
"\n"
2775 (lambda (l) (concat " " l
))
2776 (org-split-string rtn
"\n")
2781 (error "Don't know how to markup source or example block in %s"
2782 (upcase backend-name
)))))
2785 "\n#+BEGIN_" backend-name
"\n"
2787 '(org-protected t org-example t org-native-text t
))
2788 "\n#+END_" backend-name
"\n"))
2789 (org-add-props rtn nil
'original-indentation indent
))))
2791 (defun org-export-number-lines (text &optional skip1 skip2 number cont
2792 replace-labels label-format preprocess
)
2793 "Apply line numbers to literal examples and handle code references.
2794 Handle user-specified options under info node `(org)Literal
2795 examples' and return the modified source block.
2797 TEXT contains the source or example block.
2799 SKIP1 and SKIP2 are the number of lines that are to be skipped at
2800 the beginning and end of TEXT. Use these to skip over
2801 backend-specific lines pre-pended or appended to the original
2804 NUMBER is non-nil if the literal example specifies \"+n\" or
2805 \"-n\" switch. If NUMBER is non-nil add line numbers.
2807 CONT is non-nil if the literal example specifies \"+n\" switch.
2808 If CONT is nil, start numbering this block from 1. Otherwise
2809 continue numbering from the last numbered block.
2811 REPLACE-LABELS is dual-purpose.
2812 1. It controls the retention of labels in the exported block.
2813 2. It specifies in what manner the links (or references) to a
2814 labeled line be formatted.
2816 REPLACE-LABELS is the symbol `keep' if the literal example
2817 specifies \"-k\" option, is numeric if the literal example
2818 specifies \"-r\" option and is nil otherwise.
2820 Handle REPLACE-LABELS as below:
2821 - If nil, retain labels in the exported block and use
2822 user-provided labels for referencing the labeled lines.
2823 - If it is a number, remove labels in the exported block and use
2824 one of line numbers or labels for referencing labeled lines based
2826 - If it is a keep, retain labels in the exported block and use
2827 one of line numbers or labels for referencing labeled lines
2828 based on NUMBER option.
2830 LABEL-FORMAT is the value of \"-l\" switch associated with
2831 literal example. See `org-coderef-label-format'.
2833 PREPROCESS is intended for backend-agnostic handling of source
2834 block numbering. When non-nil do the following:
2835 - do not number the lines
2836 - always strip the labels from exported block
2837 - do not make the labeled line a target of an incoming link.
2838 Instead mark the labeled line with `org-coderef' property and
2839 store the label in it."
2840 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2841 (if (and number
(not cont
)) (setq org-export-last-code-line-counter-value
0))
2844 (goto-char (point-max))
2845 (skip-chars-backward " \t\n\r")
2846 (delete-region (point) (point-max))
2847 (beginning-of-line (- 1 skip2
))
2848 (let* ((last (org-current-line))
2849 (n org-export-last-code-line-counter-value
)
2850 (nmax (+ n
(- last skip1
)))
2851 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2854 ((eq org-export-current-backend
'html
) (format "<span class=\"linenr\">%s</span>"
2856 ((eq org-export-current-backend
'ascii
) fmt
)
2857 ((eq org-export-current-backend
'latex
) fmt
)
2858 ((eq org-export-current-backend
'docbook
) fmt
)
2860 (label-format (or label-format org-coderef-label-format
))
2861 (label-pre (if (string-match "%s" label-format
)
2862 (substring label-format
0 (match-beginning 0))
2864 (label-post (if (string-match "%s" label-format
)
2865 (substring label-format
(match-end 0))
2869 ".*?\\S-.*?\\([ \t]*\\("
2870 (regexp-quote label-pre
)
2871 "\\([-a-zA-Z0-9_ ]+\\)"
2872 (regexp-quote label-post
)
2876 (org-goto-line (1+ skip1
))
2877 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2878 (when number
(incf n
))
2879 (if (or preprocess
(not number
))
2881 (insert (format fm n
)))
2882 (when (looking-at lbl-re
)
2883 (setq ref
(match-string 3))
2884 (cond ((numberp replace-labels
)
2885 ;; remove labels; use numbers for references when lines
2886 ;; are numbered, use labels otherwise
2887 (delete-region (match-beginning 1) (match-end 1))
2888 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2889 ((eq replace-labels
'keep
)
2890 ;; don't remove labels; use numbers for references when
2891 ;; lines are numbered, use labels otherwise
2892 (goto-char (match-beginning 2))
2893 (delete-region (match-beginning 2) (match-end 2))
2895 (insert "(" ref
")"))
2896 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2897 org-export-code-refs
))
2899 ;; don't remove labels and don't use numbers for
2901 (goto-char (match-beginning 2))
2902 (delete-region (match-beginning 2) (match-end 2))
2904 (insert "(" ref
")"))
2905 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2906 (when (and (eq org-export-current-backend
'html
) (not preprocess
))
2908 (beginning-of-line 1)
2909 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2912 (insert "</span>")))
2914 (add-text-properties
2915 (point-at-bol) (point-at-eol) (list 'org-coderef ref
)))))
2916 (setq org-export-last-code-line-counter-value n
)
2917 (goto-char (point-max))
2921 (defun org-search-todo-below (line lines level
)
2922 "Search the subtree below LINE for any TODO entries."
2923 (let ((rest (cdr (memq line lines
)))
2924 (re org-todo-line-regexp
)
2927 (while (setq line
(pop rest
))
2928 (if (string-match re line
)
2930 (setq lv
(- (match-end 1) (match-beginning 1))
2931 todo
(and (match-beginning 2)
2932 (not (member (match-string 2 line
)
2933 org-done-keywords
))))
2935 (if (<= lv level
) (throw 'exit nil
))
2936 (if todo
(throw 'exit t
))))))))
2939 (defun org-export-visible (type arg
)
2940 "Create a copy of the visible part of the current buffer, and export it.
2941 The copy is created in a temporary buffer and removed after use.
2942 TYPE is the final key (as a string) that also selects the export command in
2943 the \\<org-mode-map>\\[org-export] export dispatcher.
2944 As a special case, if the you type SPC at the prompt, the temporary
2945 org-mode file will not be removed but presented to you so that you can
2946 continue to use it. The prefix arg ARG is passed through to the exporting
2950 (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")
2951 (read-char-exclusive))
2952 current-prefix-arg
))
2953 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L ?H ?R
)))
2954 (error "Invalid export key"))
2955 (let* ((binding (cdr (assoc type
2957 (?a . org-export-as-ascii
)
2958 (?A . org-export-as-ascii-to-buffer
)
2959 (?n . org-export-as-latin1
)
2960 (?N . org-export-as-latin1-to-buffer
)
2961 (?u . org-export-as-utf8
)
2962 (?U . org-export-as-utf8-to-buffer
)
2963 (?\C-a . org-export-as-ascii
)
2964 (?b . org-export-as-html-and-open
)
2965 (?\C-b . org-export-as-html-and-open
)
2966 (?h . org-export-as-html
)
2967 (?H . org-export-as-html-to-buffer
)
2968 (?R . org-export-region-as-html
)
2969 (?D . org-export-as-docbook
)
2971 (?l . org-export-as-latex
)
2972 (?p . org-export-as-pdf
)
2973 (?d . org-export-as-pdf-and-open
)
2974 (?L . org-export-as-latex-to-buffer
)
2976 (?x . org-export-as-xoxo
)))))
2977 (keepp (equal type ?\
))
2978 (file buffer-file-name
)
2979 (buffer (get-buffer-create "*Org Export Visible*"))
2981 ;; Need to hack the drawers here.
2983 (goto-char (point-min))
2984 (while (re-search-forward org-drawer-regexp nil t
)
2985 (goto-char (match-beginning 1))
2986 (or (outline-invisible-p) (org-flag-drawer nil
))))
2987 (with-current-buffer buffer
(erase-buffer))
2989 (setq s
(goto-char (point-min)))
2990 (while (not (= (point) (point-max)))
2991 (goto-char (org-find-invisible))
2992 (append-to-buffer buffer s
(point))
2993 (setq s
(goto-char (org-find-visible))))
2994 (org-cycle-hide-drawers 'all
)
2995 (goto-char (point-min))
2997 ;; Copy all comment lines to the end, to make sure #+ settings are
2998 ;; still available for the second export step. Kind of a hack, but
2999 ;; does do the trick.
3000 (if (looking-at "#[^\r\n]*")
3001 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
3002 (when (re-search-forward "^\\*+[ \t]+" nil t
)
3003 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t
)
3004 (append-to-buffer buffer
(1+ (match-beginning 0))
3005 (min (point-max) (1+ (match-end 0)))))))
3007 (let ((buffer-file-name file
)
3008 (org-inhibit-startup t
))
3011 (unless keepp
(funcall binding arg
))))
3013 (kill-buffer buffer
)
3014 (switch-to-buffer-other-window buffer
)
3015 (goto-char (point-min)))))
3017 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
3019 (defun org-export-string (string fmt
&optional dir
)
3020 "Export STRING to FMT using existing export facilities.
3021 During export STRING is saved to a temporary file whose location
3022 could vary. Optional argument DIR can be used to force the
3023 directory in which the temporary file is created during export
3024 which can be useful for resolving relative paths. Dir defaults
3025 to the value of `temporary-file-directory'."
3026 (let ((temporary-file-directory (or dir temporary-file-directory
))
3027 (tmp-file (make-temp-file "org-")))
3031 (write-file tmp-file
)
3032 (org-load-modules-maybe)
3033 (unless org-local-vars
3034 (setq org-local-vars
(org-get-local-variables)))
3035 (eval ;; convert to fmt -- mimicking `org-run-like-in-org-mode'
3036 (list 'let org-local-vars
3037 (list (intern (format "org-export-as-%s" fmt
))
3038 nil nil nil
''string t
))))
3039 (delete-file tmp-file
))))
3042 (defun org-export-as-org (arg &optional hidden ext-plist
3043 to-buffer body-only pub-dir
)
3044 "Make a copy with not-exporting stuff removed.
3045 The purpose of this function is to provide a way to export the source
3046 Org file of a webpage in Org format, but with sensitive and/or irrelevant
3047 stuff removed. This command will remove the following:
3049 - archived trees (if the variable `org-export-with-archived-trees' is nil)
3050 - comment blocks and trees starting with the COMMENT keyword
3051 - only trees that are consistent with `org-export-select-tags'
3052 and `org-export-exclude-tags'.
3054 The only arguments that will be used are EXT-PLIST and PUB-DIR,
3055 all the others will be ignored (but are present so that the general
3056 mechanism to call publishing functions will work).
3058 EXT-PLIST is a property list with external parameters overriding
3059 org-mode's default settings, but still inferior to file-local
3060 settings. When PUB-DIR is set, use this as the publishing
3063 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
3065 (org-infile-export-plist)))
3066 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3067 (filename (concat (file-name-as-directory
3069 (org-export-directory :org opt-plist
)))
3070 (file-name-sans-extension
3071 (file-name-nondirectory bfname
))
3073 (filename (and filename
3074 (if (equal (file-truename filename
)
3075 (file-truename bfname
))
3076 (concat (file-name-sans-extension filename
)
3078 (file-name-extension filename
))
3080 (backup-inhibited t
)
3081 (buffer (find-file-noselect filename
))
3082 (region (buffer-string))
3085 (org-pop-to-buffer-same-window buffer
)
3088 (let ((org-inhibit-startup t
)) (org-mode))
3089 (org-install-letbind)
3091 ;; Get rid of archived trees
3092 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
3094 ;; Remove comment environment and comment subtrees
3095 (org-export-remove-comment-blocks-and-subtrees)
3097 ;; Get rid of excluded trees
3098 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
3099 (plist-get opt-plist
:exclude-tags
))
3101 (when (or (plist-get opt-plist
:plain-source
)
3102 (not (or (plist-get opt-plist
:plain-source
)
3103 (plist-get opt-plist
:htmlized-source
))))
3104 ;; Either nothing special is requested (default call)
3105 ;; or the plain source is explicitly requested
3108 (when (plist-get opt-plist
:htmlized-source
)
3109 ;; Make the htmlized version
3112 (font-lock-fontify-buffer)
3113 (let* ((htmlize-output-type 'css
)
3114 (newbuf (htmlize-buffer)))
3115 (with-current-buffer newbuf
3116 (when org-export-htmlized-org-css-url
3117 (goto-char (point-min))
3118 (and (re-search-forward
3119 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
3123 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
3124 org-export-htmlized-org-css-url
)
3126 (write-file (concat filename
".html")))
3127 (kill-buffer newbuf
)))
3128 (set-buffer-modified-p nil
)
3129 (if (equal to-buffer
'string
)
3130 (progn (setq str-ret
(buffer-string))
3131 (kill-buffer (current-buffer))
3133 (kill-buffer (current-buffer))))))
3135 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
3136 (defun org-get-current-options ()
3137 "Return a string with current options as keyword options.
3138 Does include HTML export options as well as TODO and CATEGORY stuff."
3139 (require 'org-archive
)
3148 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
3149 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
3151 #+EXPORT_SELECT_TAGS: %s
3152 #+EXPORT_EXCLUDE_TAGS: %s
3159 #+PRIORITIES: %c %c %c
3161 #+STARTUP: %s %s %s %s %s
3167 (buffer-name) (user-full-name) user-mail-address
3168 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
3169 org-export-default-language
3170 org-export-headline-levels
3171 org-export-with-section-numbers
3173 org-export-preserve-breaks
3174 org-export-html-expand
3175 org-export-with-fixed-width
3176 org-export-with-tables
3177 org-export-with-sub-superscripts
3178 org-export-with-special-strings
3179 org-export-with-footnotes
3180 org-export-with-emphasize
3181 org-export-with-timestamps
3182 org-export-with-TeX-macros
3183 org-export-with-LaTeX-fragments
3184 org-export-skip-text-before-1st-heading
3185 org-export-with-drawers
3186 org-export-with-todo-keywords
3187 org-export-with-priority
3188 org-export-with-tags
3189 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
3190 (mapconcat 'identity org-export-select-tags
" ")
3191 (mapconcat 'identity org-export-exclude-tags
" ")
3192 org-export-html-link-up
3193 org-export-html-link-home
3195 (file-name-sans-extension
3196 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3198 "TODO FEEDBACK VERIFY DONE"
3199 "Me Jason Marie DONE"
3200 org-highest-priority org-lowest-priority org-default-priority
3201 (mapconcat 'identity org-drawers
" ")
3202 (cdr (assoc org-startup-folded
3203 '((nil .
"showall") (t .
"overview") (content .
"content"))))
3204 (if org-odd-levels-only
"odd" "oddeven")
3205 (if org-hide-leading-stars
"hidestars" "showstars")
3206 (if org-startup-align-all-tables
"align" "noalign")
3207 (cond ((eq org-log-done t
) "logdone")
3208 ((equal org-log-done
'note
) "lognotedone")
3209 ((not org-log-done
) "nologdone"))
3210 (or (mapconcat (lambda (x)
3212 ((equal :startgroup
(car x
)) "{")
3213 ((equal :endgroup
(car x
)) "}")
3214 ((equal :newline
(car x
)) "")
3215 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
3217 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
3218 (mapconcat 'identity org-file-tags
" ")
3219 org-archive-location
3220 "org file:~/org/%s.org"
3224 (defun org-insert-export-options-template ()
3225 "Insert into the buffer a template with information for exporting."
3227 (if (not (bolp)) (newline))
3228 (let ((s (org-get-current-options)))
3229 (and (string-match "#\\+CATEGORY" s
)
3230 (setq s
(substring s
0 (match-beginning 0))))
3233 (defvar org-table-colgroup-info nil
)
3235 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
3236 "Check if the table has a marking column.
3237 If yes remove the column and the special lines."
3238 (setq org-table-colgroup-info nil
)
3241 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3244 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
3245 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
3248 ;; No special marking column
3250 (setq org-table-clean-did-remove-column nil
)
3255 ((org-table-colgroup-line-p x
)
3256 ;; This line contains colgroup info, extract it
3257 ;; and then discard the line
3258 (setq org-table-colgroup-info
3260 (cond ((member x
'("<" "<")) :start
)
3261 ((member x
'(">" ">")) :end
)
3262 ((member x
'("<>" "<>")) :startend
)
3264 (org-split-string x
"[ \t]*|[ \t]*")))
3266 ((org-table-cookie-line-p x
)
3267 ;; This line contains formatting cookies, discard it
3271 ;; there is a special marking column
3272 (setq org-table-clean-did-remove-column t
)
3277 ((org-table-colgroup-line-p x
)
3278 ;; This line contains colgroup info, extract it
3279 ;; and then discard the line
3280 (setq org-table-colgroup-info
3282 (cond ((member x
'("<" "<")) :start
)
3283 ((member x
'(">" ">")) :end
)
3284 ((member x
'("<>" "<>")) :startend
)
3286 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3288 ((org-table-cookie-line-p x
)
3289 ;; This line contains formatting cookies, discard it
3291 ((string-match "^[ \t]*| *\\([!_^/$]\\|\\\\\\$\\) *|" x
)
3294 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3295 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3296 ;; remove the first column
3297 (replace-match "\\1|" t nil x
))))
3300 (defun org-export-cleanup-toc-line (s)
3301 "Remove tags and timestamps from lines going into the toc."
3302 (when (memq org-export-with-tags
'(not-in-toc nil
))
3303 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s
)
3304 (setq s
(replace-match "" t t s
))))
3305 (when org-export-remove-timestamps-from-toc
3306 (while (string-match org-maybe-keyword-time-regexp s
)
3307 (setq s
(replace-match "" t t s
))))
3308 (while (string-match org-bracket-link-regexp s
)
3309 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3311 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
3312 (setq s
(replace-match "" t t s
)))
3316 (defun org-get-text-property-any (pos prop
&optional object
)
3317 (or (get-text-property pos prop object
)
3318 (and (setq pos
(next-single-property-change pos prop object
))
3319 (get-text-property pos prop object
))))
3321 (defun org-export-get-coderef-format (path desc
)
3323 (if (and desc
(string-match
3324 (regexp-quote (concat "(" path
")"))
3326 (replace-match "%s" t t desc
)
3329 (defun org-export-push-to-kill-ring (format)
3330 "Push buffer content to kill ring.
3331 The depends on the variable `org-export-copy-to-kill-ring'."
3332 (when org-export-copy-to-kill-ring
3333 (org-kill-new (buffer-string))
3334 (when (fboundp 'x-set-selection
)
3335 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
3336 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
3337 (message "%s export done, pushed to kill ring and clipboard" format
)))
3341 ;;; org-exp.el ends here