1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004-2011 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
103 (defcustom org-export-run-in-background nil
104 "Non-nil means export and publishing commands will run in background.
105 This works by starting up a separate Emacs process visiting the same file
106 and doing the export from there.
107 Not all export commands are affected by this - only the ones which
108 actually write to a file, and that do not depend on the buffer state.
110 If this option is nil, you can still get background export by calling
111 `org-export' with a double prefix arg: \
112 \\[universal-argument] \\[universal-argument] \\[org-export].
114 If this option is t, the double prefix can be used to exceptionally
115 force an export command into the current process."
116 :group
'org-export-general
119 (defcustom org-export-initial-scope
'buffer
120 "The initial scope when exporting with `org-export'.
121 This variable can be either set to 'buffer or 'subtree."
122 :group
'org-export-general
124 (const :tag
"Export current buffer" 'buffer
)
125 (const :tag
"Export current subtree" 'subtree
)))
127 (defcustom org-export-select-tags
'("export")
128 "Tags that select a tree for export.
129 If any such tag is found in a buffer, all trees that do not carry one
130 of these tags will be deleted before export.
131 Inside trees that are selected like this, you can still deselect a
132 subtree by tagging it with one of the `org-export-exclude-tags'."
133 :group
'org-export-general
134 :type
'(repeat (string :tag
"Tag")))
136 (defcustom org-export-exclude-tags
'("noexport")
137 "Tags that exclude a tree from export.
138 All trees carrying any of these tags will be excluded from export.
139 This is without condition, so even subtrees inside that carry one of the
140 `org-export-select-tags' will be removed."
141 :group
'org-export-general
142 :type
'(repeat (string :tag
"Tag")))
144 ;; FIXME: rename, this is a general variable
145 (defcustom org-export-html-expand t
146 "Non-nil means for HTML export, treat @<...> as HTML tag.
147 When nil, these tags will be exported as plain text and therefore
148 not be interpreted by a browser.
150 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
151 :group
'org-export-html
152 :group
'org-export-general
155 (defcustom org-export-with-special-strings t
156 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
157 When this option is turned on, these strings will be exported as:
160 -----+----------+--------
166 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
167 :group
'org-export-translation
170 (defcustom org-export-html-link-up
""
171 "Where should the \"UP\" link of exported HTML pages lead?"
172 :group
'org-export-html
173 :group
'org-export-general
174 :type
'(string :tag
"File or URL"))
176 (defcustom org-export-html-link-home
""
177 "Where should the \"HOME\" link of exported HTML pages lead?"
178 :group
'org-export-html
179 :group
'org-export-general
180 :type
'(string :tag
"File or URL"))
182 (defcustom org-export-language-setup
183 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
184 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
185 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
186 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
187 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
188 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
189 ("es" "Autor" "Fecha" "Índice" "Pies de página")
190 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
191 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
192 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
193 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
194 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
195 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
196 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
197 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
198 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
199 ("pl" "Autor" "Data" "Spis treści" "Przypis")
200 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
201 "Terms used in export text, translated to different languages.
202 Use the variable `org-export-default-language' to set the language,
203 or use the +OPTION lines for a per-file setting."
204 :group
'org-export-general
207 (string :tag
"HTML language tag")
208 (string :tag
"Author")
210 (string :tag
"Table of Contents")
211 (string :tag
"Footnotes"))))
213 (defcustom org-export-default-language
"en"
214 "The default language for export and clocktable translations, as a string.
215 This should have an association in `org-export-language-setup'
216 and in `org-clock-clocktable-language-setup'."
217 :group
'org-export-general
220 (defcustom org-export-date-timestamp-format
"%Y-%m-%d"
221 "Time string format for Org timestamps in the #+DATE option."
222 :group
'org-export-general
225 (defvar org-export-page-description
""
226 "The page description, for the XHTML meta tag.
227 This is best set with the #+DESCRIPTION line in a file, it does not make
228 sense to set this globally.")
230 (defvar org-export-page-keywords
""
231 "The page description, for the XHTML meta tag.
232 This is best set with the #+KEYWORDS line in a file, it does not make
233 sense to set this globally.")
235 (defcustom org-export-skip-text-before-1st-heading nil
236 "Non-nil means skip all text before the first headline when exporting.
237 When nil, that text is exported as well."
238 :group
'org-export-general
241 (defcustom org-export-headline-levels
3
242 "The last level which is still exported as a headline.
243 Inferior levels will produce itemize lists when exported.
244 Note that a numeric prefix argument to an exporter function overrides
247 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
248 :group
'org-export-general
251 (defcustom org-export-with-section-numbers t
252 "Non-nil means add section numbers to headlines when exporting.
254 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
255 :group
'org-export-general
258 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
259 "Format of section numbers for export.
260 The variable has two components.
261 1. A list of lists, each indicating a counter type and a separator.
262 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
263 It causes causes numeric, alphabetic, or roman counters, respectively.
264 The separator is only used if another counter for a subsection is being
266 If there are more numbered section levels than entries in this lists,
267 then the last entry will be reused.
268 2. A terminator string that will be added after the entire
270 :group
'org-export-general
274 (string :tag
"Counter Type")
275 (string :tag
"Separator ")))
276 (string :tag
"Terminator")))
278 (defcustom org-export-with-toc t
279 "Non-nil means create a table of contents in exported files.
280 The TOC contains headlines with levels up to`org-export-headline-levels'.
281 When an integer, include levels up to N in the toc, this may then be
282 different from `org-export-headline-levels', but it will not be allowed
283 to be larger than the number of headline levels.
284 When nil, no table of contents is made.
286 Headlines which contain any TODO items will be marked with \"(*)\" in
287 ASCII export, and with red color in HTML output, if the option
288 `org-export-mark-todo-in-toc' is set.
290 In HTML output, the TOC will be clickable.
292 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
294 :group
'org-export-general
296 (const :tag
"No Table of Contents" nil
)
297 (const :tag
"Full Table of Contents" t
)
298 (integer :tag
"TOC to level")))
300 (defcustom org-export-mark-todo-in-toc nil
301 "Non-nil means mark TOC lines that contain any open TODO items."
302 :group
'org-export-general
305 (defcustom org-export-with-todo-keywords t
306 "Non-nil means include TODO keywords in export.
307 When nil, remove all these keywords from the export."
308 :group
'org-export-general
311 (defcustom org-export-with-tasks t
312 "Non-nil means include TODO items for export.
313 This may have the following values:
314 t include tasks independent of state.
315 todo include only tasks that are not yet done.
316 done include only tasks that are already done.
317 nil remove all tasks before export
318 list of TODO kwds keep only tasks with these keywords"
319 :group
'org-export-general
321 (const :tag
"All tasks" t
)
322 (const :tag
"No tasks" nil
)
323 (const :tag
"Not-done tasks" todo
)
324 (const :tag
"Only done tasks" done
)
325 (repeat :tag
"Specific TODO keywords"
326 (string :tag
"Keyword"))))
328 (defcustom org-export-with-priority nil
329 "Non-nil means include priority cookies in export.
330 When nil, remove priority cookies for export."
331 :group
'org-export-general
334 (defcustom org-export-preserve-breaks nil
335 "Non-nil means preserve all line breaks when exporting.
336 Normally, in HTML output paragraphs will be reformatted. In ASCII
337 export, line breaks will always be preserved, regardless of this variable.
339 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
340 :group
'org-export-general
343 (defcustom org-export-with-archived-trees
'headline
344 "Whether subtrees with the ARCHIVE tag should be exported.
345 This can have three different values
346 nil Do not export, pretend this tree is not present
347 t Do export the entire tree
348 headline Only export the headline, but skip the tree below it."
349 :group
'org-export-general
352 (const :tag
"not at all" nil
)
353 (const :tag
"headline only" 'headline
)
354 (const :tag
"entirely" t
)))
356 (defcustom org-export-author-info t
357 "Non-nil means insert author name and email into the exported file.
359 This option can also be set with the +OPTIONS line,
360 e.g. \"author:nil\"."
361 :group
'org-export-general
364 (defcustom org-export-email-info nil
365 "Non-nil means insert author name and email into the exported file.
367 This option can also be set with the +OPTIONS line,
369 :group
'org-export-general
372 (defcustom org-export-creator-info t
373 "Non-nil means the postamble should contain a creator sentence.
374 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
375 :group
'org-export-general
378 (defcustom org-export-time-stamp-file t
379 "Non-nil means insert a time stamp into the exported file.
380 The time stamp shows when the file was created.
382 This option can also be set with the +OPTIONS line,
383 e.g. \"timestamp:nil\"."
384 :group
'org-export-general
387 (defcustom org-export-with-timestamps t
388 "If nil, do not export time stamps and associated keywords."
389 :group
'org-export-general
392 (defcustom org-export-remove-timestamps-from-toc t
393 "If t, remove timestamps from the table of contents entries."
394 :group
'org-export-general
397 (defcustom org-export-with-tags
'not-in-toc
398 "If nil, do not export tags, just remove them from headlines.
399 If this is the symbol `not-in-toc', tags will be removed from table of
400 contents entries, but still be shown in the headlines of the document.
402 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
403 :group
'org-export-general
405 (const :tag
"Off" nil
)
406 (const :tag
"Not in TOC" not-in-toc
)
407 (const :tag
"On" t
)))
409 (defcustom org-export-with-drawers nil
410 "Non-nil means export with drawers like the property drawer.
411 When t, all drawers are exported. This may also be a list of
412 drawer names to export."
413 :group
'org-export-general
415 (const :tag
"All drawers" t
)
416 (const :tag
"None" nil
)
417 (repeat :tag
"Selected drawers"
418 (string :tag
"Drawer name"))))
420 (defvar org-export-first-hook nil
421 "Hook called as the first thing in each exporter.
422 Point will be still in the original buffer.
423 Good for general initialization")
425 (defvar org-export-preprocess-hook nil
426 "Hook for preprocessing an export buffer.
427 Pretty much the first thing when exporting is running this hook.
428 Point will be in a temporary buffer that contains a copy of
429 the original buffer, or of the section that is being exported.
430 All the other hooks in the org-export-preprocess... category
431 also work in that temporary buffer, already modified by various
432 stages of the processing.")
434 (defvar org-export-preprocess-after-include-files-hook nil
435 "Hook for preprocessing an export buffer.
436 This is run after the contents of included files have been inserted.")
438 (defvar org-export-preprocess-after-tree-selection-hook nil
439 "Hook for preprocessing an export buffer.
440 This is run after selection of trees to be exported has happened.
441 This selection includes tags-based selection, as well as removal
442 of commented and archived trees.")
444 (defvar org-export-preprocess-after-headline-targets-hook nil
445 "Hook for preprocessing export buffer.
446 This is run just after the headline targets have been defined and
447 the target-alist has been set up.")
449 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
450 "Hook for preprocessing an export buffer.
451 This is run just before backend-specific blocks get selected.")
453 (defvar org-export-preprocess-after-blockquote-hook nil
454 "Hook for preprocessing an export buffer.
455 This is run after blockquote/quote/verse/center have been marked
458 (defvar org-export-preprocess-after-radio-targets-hook nil
459 "Hook for preprocessing an export buffer.
460 This is run after radio target processing.")
462 (defvar org-export-preprocess-before-normalizing-links-hook nil
463 "Hook for preprocessing an export buffer.
464 This hook is run before links are normalized.")
466 (defvar org-export-preprocess-before-backend-specifics-hook nil
467 "Hook run before backend-specific functions are called during preprocessing.")
469 (defvar org-export-preprocess-final-hook nil
470 "Hook for preprocessing an export buffer.
471 This is run as the last thing in the preprocessing buffer, just before
472 returning the buffer string to the backend.")
474 (defgroup org-export-translation nil
475 "Options for translating special ascii sequences for the export backends."
476 :tag
"Org Export Translation"
479 (defcustom org-export-with-emphasize t
480 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
481 If the export target supports emphasizing text, the word will be
482 typeset in bold, italic, or underlined, respectively. Works only for
483 single words, but you can say: I *really* *mean* *this*.
484 Not all export backends support this.
486 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
487 :group
'org-export-translation
490 (defcustom org-export-with-footnotes t
491 "If nil, export [1] as a footnote marker.
492 Lines starting with [1] will be formatted as footnotes.
494 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
495 :group
'org-export-translation
498 (defcustom org-export-with-TeX-macros t
499 "Non-nil means interpret simple TeX-like macros when exporting.
500 For example, HTML export converts \\alpha to α and \\AA to Å.
501 Not only real TeX macros will work here, but the standard HTML entities
502 for math can be used as macro names as well. For a list of supported
503 names in HTML export, see the constant `org-entities' and the user option
505 Not all export backends support this.
507 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
508 :group
'org-export-translation
509 :group
'org-export-latex
512 (defcustom org-export-with-LaTeX-fragments t
513 "Non-nil means process LaTeX math fragments for HTML display.
514 When set, the exporter will find and process LaTeX environments if the
515 \\begin line is the first non-white thing on a line. It will also find
516 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
517 $$a=b$$ and \\=\\[ a=b \\] for display math.
519 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
523 nil Don't do anything.
524 verbatim Keep everything in verbatim
525 dvipng Process the LaTeX fragments to images.
526 This will also include processing of non-math environments.
527 t Do MathJax preprocessing if there is at least on math snippet,
528 and arrange for MathJax.js to be loaded.
530 The default is nil, because this option needs the `dvipng' program which
531 is not available on all systems."
532 :group
'org-export-translation
533 :group
'org-export-latex
535 (const :tag
"Do not process math in any way" nil
)
536 (const :tag
"Obsolete, use dvipng setting" t
)
537 (const :tag
"Use dvipng to make images" dvipng
)
538 (const :tag
"Use MathJax to display math" mathjax
)
539 (const :tag
"Leave math verbatim" verbatim
)))
541 (defcustom org-export-with-fixed-width t
542 "Non-nil means lines starting with \":\" will be in fixed width font.
543 This can be used to have pre-formatted text, fragments of code etc. For
545 : ;; Some Lisp examples
548 will be looking just like this in also HTML. See also the QUOTE keyword.
549 Not all export backends support this.
551 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
552 :group
'org-export-translation
555 (defgroup org-export-tables nil
556 "Options for exporting tables in Org-mode."
557 :tag
"Org Export Tables"
560 (defcustom org-export-with-tables t
561 "If non-nil, lines starting with \"|\" define a table.
564 | Name | Address | Birthday |
565 |-------------+----------+-----------|
566 | Arthur Dent | England | 29.2.2100 |
568 Not all export backends support this.
570 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
571 :group
'org-export-tables
574 (defcustom org-export-highlight-first-table-line t
575 "Non-nil means highlight the first table line.
576 In HTML export, this means use <th> instead of <td>.
577 In tables created with table.el, this applies to the first table line.
578 In Org-mode tables, all lines before the first horizontal separator
579 line will be formatted with <th> tags."
580 :group
'org-export-tables
583 (defcustom org-export-table-remove-special-lines t
584 "Remove special lines and marking characters in calculating tables.
585 This removes the special marking character column from tables that are set
586 up for spreadsheet calculations. It also removes the entire lines
587 marked with `!', `_', or `^'. The lines with `$' are kept, because
588 the values of constants may be useful to have."
589 :group
'org-export-tables
592 (defcustom org-export-table-remove-empty-lines t
593 "Remove empty lines when exporting tables.
594 This is the global equivalent of the :remove-nil-lines option
595 when locally sending a table with #+ORGTBL."
596 :group
'org-export-tables
599 (defcustom org-export-prefer-native-exporter-for-tables nil
600 "Non-nil means always export tables created with table.el natively.
601 Natively means use the HTML code generator in table.el.
602 When nil, Org-mode's own HTML generator is used when possible (i.e. if
603 the table does not use row- or column-spanning). This has the
604 advantage, that the automatic HTML conversions for math symbols and
605 sub/superscripts can be applied. Org-mode's HTML generator is also
606 much faster. The LaTeX exporter always use the native exporter for
608 :group
'org-export-tables
613 ;;; Variables, constants, and parameter plists
615 (defconst org-level-max
20)
617 (defvar org-export-current-backend nil
618 "During export, this will be bound to a symbol such as 'html,
619 'latex, 'docbook, 'ascii, etc, indicating which of the export
620 backends is in use. Otherwise it has the value nil. Users
621 should not attempt to change the value of this variable
622 directly, but it can be used in code to test whether export is
623 in progress, and if so, what the backend is.")
625 (defvar org-current-export-file nil
) ; dynamically scoped parameter
626 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
627 (defvar org-export-opt-plist nil
628 "Contains the current option plist.")
629 (defvar org-last-level nil
) ; dynamically scoped variable
630 (defvar org-min-level nil
) ; dynamically scoped variable
631 (defvar org-levels-open nil
) ; dynamically scoped parameter
632 (defvar org-export-footnotes-data nil
633 "Alist of labels used in buffers, along with their definition.")
634 (defvar org-export-footnotes-seen nil
635 "Alist of labels encountered so far by the exporter, along with their definition.")
638 (defconst org-export-plist-vars
639 '((:link-up nil org-export-html-link-up
)
640 (:link-home nil org-export-html-link-home
)
641 (:language nil org-export-default-language
)
642 (:keywords nil org-export-page-keywords
)
643 (:description nil org-export-page-description
)
644 (:customtime nil org-display-custom-times
)
645 (:headline-levels
"H" org-export-headline-levels
)
646 (:section-numbers
"num" org-export-with-section-numbers
)
647 (:section-number-format nil org-export-section-number-format
)
648 (:table-of-contents
"toc" org-export-with-toc
)
649 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
650 (:archived-trees nil org-export-with-archived-trees
)
651 (:emphasize
"*" org-export-with-emphasize
)
652 (:sub-superscript
"^" org-export-with-sub-superscripts
)
653 (:special-strings
"-" org-export-with-special-strings
)
654 (:footnotes
"f" org-export-with-footnotes
)
655 (:drawers
"d" org-export-with-drawers
)
656 (:tags
"tags" org-export-with-tags
)
657 (:todo-keywords
"todo" org-export-with-todo-keywords
)
658 (:tasks
"tasks" org-export-with-tasks
)
659 (:priority
"pri" org-export-with-priority
)
660 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
661 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
662 (:latex-listings nil org-export-latex-listings
)
663 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
664 (:fixed-width
":" org-export-with-fixed-width
)
665 (:timestamps
"<" org-export-with-timestamps
)
666 (:author nil user-full-name
)
667 (:email nil user-mail-address
)
668 (:author-info
"author" org-export-author-info
)
669 (:email-info
"email" org-export-email-info
)
670 (:creator-info
"creator" org-export-creator-info
)
671 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
672 (:tables
"|" org-export-with-tables
)
673 (:table-auto-headline nil org-export-highlight-first-table-line
)
674 (:style-include-default nil org-export-html-style-include-default
)
675 (:style-include-scripts nil org-export-html-style-include-scripts
)
676 (:style nil org-export-html-style
)
677 (:style-extra nil org-export-html-style-extra
)
678 (:agenda-style nil org-agenda-export-html-style
)
679 (:convert-org-links nil org-export-html-link-org-files-as-html
)
680 (:inline-images nil org-export-html-inline-images
)
681 (:html-extension nil org-export-html-extension
)
682 (:html-preamble nil org-export-html-preamble
)
683 (:html-postamble nil org-export-html-postamble
)
684 (:xml-declaration nil org-export-html-xml-declaration
)
685 (:html-table-tag nil org-export-html-table-tag
)
686 (:expand-quoted-html
"@" org-export-html-expand
)
687 (:timestamp nil org-export-html-with-timestamp
)
688 (:publishing-directory nil org-export-publishing-directory
)
689 (:select-tags nil org-export-select-tags
)
690 (:exclude-tags nil org-export-exclude-tags
)
692 (:latex-image-options nil org-export-latex-image-default-option
))
693 "List of properties that represent export/publishing variables.
694 Each element is a list of 3 items:
695 1. The property that is used internally, and also for org-publish-project-alist
696 2. The string that can be used in the OPTION lines to set this option,
697 or nil if this option cannot be changed in this way
698 3. The customization variable that sets the default for this option."
701 (defun org-default-export-plist ()
702 "Return the property list with default settings for the export variables."
703 (let* ((infile (org-infile-export-plist))
704 (letbind (plist-get infile
:let-bind
))
705 (l org-export-plist-vars
) rtn e s v
)
706 (while (setq e
(pop l
))
709 ((assq s letbind
) (nth 1 (assq s letbind
)))
710 ((boundp s
) (symbol-value s
))
712 rtn
(cons (car e
) (cons v rtn
))))
715 (defvar org-export-inbuffer-options-extra nil
716 "List of additional in-buffer options that should be detected.
717 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
718 etc. Extensions can add to this list to get their options detected, and they
719 can then add a function to `org-export-options-filters' to process these
721 Each element in this list must be a list, with the in-buffer keyword as car,
722 and a property (a symbol) as the next element. All occurrences of the
723 keyword will be found, the values concatenated with a space character
724 in between, and the result stored in the export options property list.")
726 (defvar org-export-options-filters nil
727 "Functions to be called to finalize the export/publishing options.
728 All these options are stored in a property list, and each of the functions
729 in this hook gets a chance to modify this property list. Each function
730 must accept the property list as an argument, and must return the (possibly
733 ;; FIXME: should we fold case here?
735 (defun org-infile-export-plist ()
736 "Return the property list with file-local settings for export."
740 (goto-char (point-min))
741 (let ((re (org-make-options-regexp
743 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
745 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
746 "LATEX_HEADER" "LATEX_CLASS" "LATEX_CLASS_OPTIONS"
747 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
748 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
749 (mapcar 'car org-export-inbuffer-options-extra
))))
751 p key val text options mathjax a pr style
752 latex-header latex-class latex-class-options macros letbind
753 ext-setup-or-nil setup-file setup-dir setup-contents
(start 0))
754 (while (or (and ext-setup-or-nil
755 (string-match re ext-setup-or-nil start
)
756 (setq start
(match-end 0)))
757 (and (setq ext-setup-or-nil nil start
0)
758 (re-search-forward re nil t
)))
759 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
760 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
762 ((setq a
(assoc key org-export-inbuffer-options-extra
))
764 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
765 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
766 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
767 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
768 ((string-equal key
"DATE")
769 ;; If date is an Org timestamp, convert it to a time
770 ;; string using `org-export-date-timestamp-format'
771 (when (string-match org-ts-regexp3 val
)
772 (setq val
(format-time-string
773 org-export-date-timestamp-format
774 (apply 'encode-time
(org-parse-time-string
775 (match-string 0 val
))))))
776 (setq p
(plist-put p
:date val
)))
777 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
778 ((string-equal key
"DESCRIPTION")
779 (setq p
(plist-put p
:description val
)))
780 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
781 ((string-equal key
"STYLE")
782 (setq style
(concat style
"\n" val
)))
783 ((string-equal key
"LATEX_HEADER")
784 (setq latex-header
(concat latex-header
"\n" val
)))
785 ((string-equal key
"LATEX_CLASS")
786 (setq latex-class val
))
787 ((string-equal key
"LATEX_CLASS_OPTIONS")
788 (setq latex-class-options val
))
789 ((string-equal key
"TEXT")
790 (setq text
(if text
(concat text
"\n" val
) val
)))
791 ((string-equal key
"OPTIONS")
792 (setq options
(concat val
" " options
)))
793 ((string-equal key
"MATHJAX")
794 (setq mathjax
(concat val
" " mathjax
)))
795 ((string-equal key
"BIND")
796 (push (read (concat "(" val
")")) letbind
))
797 ((string-equal key
"XSLT")
798 (setq p
(plist-put p
:xslt val
)))
799 ((string-equal key
"LINK_UP")
800 (setq p
(plist-put p
:link-up val
)))
801 ((string-equal key
"LINK_HOME")
802 (setq p
(plist-put p
:link-home val
)))
803 ((string-equal key
"EXPORT_SELECT_TAGS")
804 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
805 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
806 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
807 ((string-equal key
"MACRO")
809 ((equal key
"SETUPFILE")
810 (setq setup-file
(org-remove-double-quotes (org-trim val
))
811 ;; take care of recursive inclusion of setupfiles
812 setup-file
(if (or (file-name-absolute-p val
) (not setup-dir
))
813 (expand-file-name setup-file
)
814 (let ((default-directory setup-dir
))
815 (expand-file-name setup-file
))))
816 (setq setup-dir
(file-name-directory setup-file
))
817 (setq setup-contents
(org-file-contents setup-file
'noerror
))
818 (if (not ext-setup-or-nil
)
819 (setq ext-setup-or-nil setup-contents start
0)
820 (setq ext-setup-or-nil
821 (concat (substring ext-setup-or-nil
0 start
)
822 "\n" setup-contents
"\n"
823 (substring ext-setup-or-nil start
)))))))
824 (setq p
(plist-put p
:text text
))
825 (when (and letbind
(org-export-confirm-letbind))
826 (setq p
(plist-put p
:let-bind letbind
)))
827 (when style
(setq p
(plist-put p
:style-extra style
)))
829 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
831 (setq p
(plist-put p
:latex-class latex-class
)))
832 (when latex-class-options
833 (setq p
(plist-put p
:latex-class-options latex-class-options
)))
835 (setq p
(org-export-add-options-to-plist p options
)))
837 (setq p
(plist-put p
:mathjax mathjax
)))
838 ;; Add macro definitions
839 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
840 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
841 (setq p
(plist-put p
:macro-property
"(eval (org-entry-get nil \"$1\" 'selective))"))
843 p
:macro-modification-time
844 (and (buffer-file-name)
845 (file-exists-p (buffer-file-name))
847 "(eval (format-time-string \"$1\" '"
848 (prin1-to-string (nth 5 (file-attributes
849 (buffer-file-name))))
851 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
852 (file-name-nondirectory
853 (buffer-file-name)))))
854 (while (setq val
(pop macros
))
855 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
858 (concat ":macro-" (downcase (match-string 1 val
))))
859 (org-export-interpolate-newlines (match-string 2 val
))))))
862 (defun org-export-interpolate-newlines (s)
863 (while (string-match "\\\\n" s
)
864 (setq s
(replace-match "\n" t t s
)))
867 (defvar org-export-allow-BIND-local nil
)
868 (defun org-export-confirm-letbind ()
869 "Can we use #+BIND values during export?
870 By default this will ask for confirmation by the user, to divert possible
873 ((not org-export-allow-BIND
) nil
)
874 ((eq org-export-allow-BIND t
) t
)
875 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
876 org-export-allow-BIND-local
)
877 (t (org-set-local 'org-export-allow-BIND-local
878 (yes-or-no-p "Allow BIND values in this buffer? ")))))
880 (defun org-install-letbind ()
881 "Install the values from #+BIND lines as local variables."
882 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
884 (while (setq pair
(pop letbind
))
885 (org-set-local (car pair
) (nth 1 pair
)))))
887 (defun org-export-add-options-to-plist (p options
)
888 "Parse an OPTIONS line and set values in the property list P."
891 (let ((op org-export-plist-vars
))
892 (while (setq o
(pop op
))
894 (string-match (concat "\\(\\`\\|[ \t]\\)"
895 (regexp-quote (nth 1 o
))
896 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
898 (setq p
(plist-put p
(car o
)
899 (car (read-from-string
900 (match-string 2 options
))))))))))
903 (defun org-export-add-subtree-options (p pos
)
904 "Add options in subtree at position POS to property list P."
907 (when (org-at-heading-p)
909 ;; This is actually read in `org-export-get-title-from-subtree'
910 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
911 ;; (setq p (plist-put p :title a)))
912 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
913 (setq p
(plist-put p
:text a
)))
914 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
915 (setq p
(plist-put p
:author a
)))
916 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
917 (setq p
(plist-put p
:date a
)))
918 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
919 (setq p
(org-export-add-options-to-plist p a
)))))
922 (defun org-export-directory (type plist
)
923 (let* ((val (plist-get plist
:publishing-directory
))
925 (or (cdr (assoc type val
)) ".")
929 (defun org-export-process-option-filters (plist)
930 (let ((functions org-export-options-filters
) f
)
931 (while (setq f
(pop functions
))
932 (setq plist
(funcall f plist
))))
936 (defun org-export (&optional arg
)
937 "Export dispatcher for Org-mode.
938 When `org-export-run-in-background' is non-nil, try to run the command
939 in the background. This will be done only for commands that write
940 to a file. For details see the docstring of `org-export-run-in-background'.
942 The prefix argument ARG will be passed to the exporter. However, if
943 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
944 that means to inverse the
945 value of `org-export-run-in-background'.
947 If `org-export-initial-scope' is set to 'subtree, try to export
948 the current subtree, otherwise try to export the whole buffer.
949 Pressing `1' will switch between these two options."
951 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
952 (subtree-p (or (org-region-active-p)
953 (eq org-export-initial-scope
'subtree
)))
954 (help "[t] insert the export option template
955 \[v] limit export to visible part of outline tree
956 \[1] switch buffer/subtree export
957 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
959 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
961 \[h] export as HTML [H] to temporary buffer [R] export region
962 \[b] export as HTML and open in browser
964 \[l] export as LaTeX [L] to temporary buffer
965 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
967 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
969 \[o] export as OpenDocument Text [O] ... and open
971 \[j] export as TaskJuggler [J] ... and open
973 \[m] export as Freemind mind map
975 \[g] export using Wes Hardaker's generic exporter
977 \[i] export current file as iCalendar file
978 \[I] export all agenda files as iCalendar files [c] ...as one combined file
980 \[F] publish current file [P] publish current project
981 \[X] publish a project... [E] publish every projects")
983 '((?t org-insert-export-options-template nil
)
984 (?v org-export-visible nil
)
985 (?a org-export-as-ascii t
)
986 (?A org-export-as-ascii-to-buffer t
)
987 (?n org-export-as-latin1 t
)
988 (?N org-export-as-latin1-to-buffer t
)
989 (?u org-export-as-utf8 t
)
990 (?U org-export-as-utf8-to-buffer t
)
991 (?h org-export-as-html t
)
992 (?b org-export-as-html-and-open t
)
993 (?H org-export-as-html-to-buffer nil
)
994 (?R org-export-region-as-html nil
)
995 (?x org-export-as-xoxo t
)
996 (?g org-export-generic t
)
997 (?D org-export-as-docbook t
)
998 (?V org-export-as-docbook-pdf-and-open t
)
999 (?o org-export-as-odt t
)
1000 (?O org-export-as-odt-and-open t
)
1001 (?j org-export-as-taskjuggler t
)
1002 (?J org-export-as-taskjuggler-and-open t
)
1003 (?m org-export-as-freemind t
)
1004 (?l org-export-as-latex t
)
1005 (?p org-export-as-pdf t
)
1006 (?d org-export-as-pdf-and-open t
)
1007 (?L org-export-as-latex-to-buffer nil
)
1008 (?i org-export-icalendar-this-file t
)
1009 (?I org-export-icalendar-all-agenda-files t
)
1010 (?c org-export-icalendar-combine-agenda-files t
)
1011 (?F org-publish-current-file t
)
1012 (?P org-publish-current-project t
)
1014 (?E org-publish-all t
)))
1016 (cpos (point)) (cbuf (current-buffer)) bpos
)
1018 (save-window-excursion
1020 (message "Export subtree: ")
1021 (message "Export buffer: "))
1022 (delete-other-windows)
1023 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1025 (org-fit-window-to-buffer (get-buffer-window
1026 "*Org Export/Publishing Help*"))
1027 (while (eq (setq r1
(read-char-exclusive)) ?
1)
1029 (setq subtree-p nil
)
1030 (message "Export buffer: "))
1034 (message "Export subtree: "))))
1036 (let ((case-fold-search t
)
1037 (end (save-excursion (while (org-up-heading-safe)) (point))))
1038 (outline-next-heading)
1039 (if (re-search-backward
1040 "^[ \t]+\\(:latex_class:\\|:export_title:\\|:export_file_name:\\)[ \t]+\\S-"
1043 (org-back-to-heading t
)
1046 (message "Select command (for subtree): ")
1047 (setq r1
(read-char-exclusive)))
1048 (error "No enclosing node with LaTeX_CLASS or EXPORT_TITLE or EXPORT_FILE_NAME")
1050 (if (fboundp 'redisplay
) (redisplay)) ;; XEmacs does not have/need (redisplay)
1051 (and bpos
(goto-char bpos
))
1052 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1053 (unless (setq ass
(assq r2 cmds
))
1054 (error "No command associated with key %c" r1
))
1055 (if (and bg
(nth 2 ass
)
1056 (not (buffer-base-buffer))
1057 (not (org-region-active-p)))
1058 ;; execute in background
1059 (let ((p (start-process
1060 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1062 (expand-file-name invocation-name invocation-directory
)
1065 "--eval" "(require 'org-exp)"
1066 "--eval" "(setq org-wait .2)"
1068 "-f" (symbol-name (nth 1 ass
)))))
1069 (set-process-sentinel p
'org-export-process-sentinel
)
1070 (message "Background process \"%s\": started" p
))
1071 ;; background processing not requested, or not possible
1072 (if subtree-p
(progn (org-mark-subtree) (org-activate-mark)))
1073 (call-interactively (nth 1 ass
))
1074 (when (and bpos
(get-buffer-window cbuf
))
1075 (let ((cw (selected-window)))
1076 (select-window (get-buffer-window cbuf
))
1079 (select-window cw
))))))
1081 (defun org-export-process-sentinel (process status
)
1082 (if (string-match "\n+\\'" status
)
1083 (setq status
(substring status
0 -
1)))
1084 (message "Background process \"%s\": %s" process status
))
1086 ;;; General functions for all backends
1088 (defvar org-export-target-aliases nil
1089 "Alist of targets with invisible aliases.")
1090 (defvar org-export-preferred-target-alist nil
1091 "Alist of section id's with preferred aliases.")
1092 (defvar org-export-id-target-alist nil
1093 "Alist of section id's with preferred aliases.")
1094 (defvar org-export-code-refs nil
1095 "Alist of code references and line numbers.")
1097 (defun org-export-preprocess-string (string &rest parameters
)
1098 "Cleanup STRING so that the true exported has a more consistent source.
1099 This function takes STRING, which should be a buffer-string of an org-file
1100 to export. It then creates a temporary buffer where it does its job.
1101 The result is then again returned as a string, and the exporter works
1102 on this string to produce the exported version."
1104 (let* ((org-export-current-backend (or (plist-get parameters
:for-backend
)
1105 org-export-current-backend
))
1106 (archived-trees (plist-get parameters
:archived-trees
))
1107 (inhibit-read-only t
)
1108 (drawers org-drawers
)
1109 (source-buffer (current-buffer))
1112 (setq org-export-target-aliases nil
1113 org-export-preferred-target-alist nil
1114 org-export-id-target-alist nil
1115 org-export-code-refs nil
)
1120 (setq case-fold-search t
)
1122 (let ((inhibit-read-only t
))
1123 (remove-text-properties (point-min) (point-max)
1126 ;; Remove license-to-kill stuff
1127 ;; The caller marks some stuff for killing, stuff that has been
1128 ;; used to create the page title, for example.
1129 (org-export-kill-licensed-text)
1131 (let ((org-inhibit-startup t
)) (org-mode))
1132 (setq case-fold-search t
)
1133 (org-clone-local-variables source-buffer
"^\\(org-\\|orgtbl-\\)")
1134 (org-install-letbind)
1137 (run-hooks 'org-export-preprocess-hook
)
1139 (untabify (point-min) (point-max))
1141 ;; Handle include files, and call a hook
1142 (org-export-handle-include-files-recurse)
1143 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1145 ;; Get rid of archived trees
1146 (org-export-remove-archived-trees archived-trees
)
1148 ;; Remove comment environment and comment subtrees
1149 (org-export-remove-comment-blocks-and-subtrees)
1151 ;; Get rid of excluded trees, and call a hook
1152 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1153 (plist-get parameters
:exclude-tags
))
1154 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1156 ;; Get rid of tasks, depending on configuration
1157 (org-export-remove-tasks (plist-get parameters
:tasks
))
1159 ;; Prepare footnotes for export. During that process, footnotes
1160 ;; actually included in the exported part of the buffer go
1161 ;; though some transformations:
1163 ;; 1. They have their label normalized (like "[N]");
1165 ;; 2. They get moved at the same place in the buffer (usually at
1166 ;; its end, but backends may define another place via
1167 ;; `org-footnote-insert-pos-for-preprocessor');
1169 ;; 3. The are stored in `org-export-footnotes-seen', while
1170 ;; `org-export-preprocess-string' is applied to their
1173 ;; Line-wise exporters ignore `org-export-footnotes-seen', as
1174 ;; they interpret footnotes at the moment they see them in the
1175 ;; buffer. Context-wise exporters grab all the info needed in
1176 ;; that variable and delete moved definitions (as described in
1178 (when (plist-get parameters
:footnotes
)
1179 (org-footnote-normalize nil parameters
))
1181 ;; Change lists ending. Other parts of export may insert blank
1182 ;; lines and lists' structure could be altered.
1183 (org-export-mark-list-end)
1185 ;; Process the macros
1186 (org-export-preprocess-apply-macros)
1187 (run-hooks 'org-export-preprocess-after-macros-hook
)
1189 ;; Export code blocks
1190 (org-export-blocks-preprocess)
1192 ;; Mark lists with properties
1193 (org-export-mark-list-properties)
1195 ;; Handle source code snippets
1196 (org-export-replace-src-segments-and-examples)
1198 ;; Protect short examples marked by a leading colon
1199 (org-export-protect-colon-examples)
1202 (org-export-convert-protected-spaces)
1204 ;; Find all headings and compute the targets for them
1205 (setq target-alist
(org-export-define-heading-targets target-alist
))
1207 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1209 ;; Find HTML special classes for headlines
1210 (org-export-remember-html-container-classes)
1212 ;; Get rid of drawers
1213 (org-export-remove-or-extract-drawers
1214 drawers
(plist-get parameters
:drawers
))
1216 ;; Get the correct stuff before the first headline
1217 (when (plist-get parameters
:skip-before-1st-heading
)
1218 (goto-char (point-min))
1219 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1220 (delete-region (point-min) (match-beginning 0))
1221 (goto-char (point-min))
1223 (when (plist-get parameters
:add-text
)
1224 (goto-char (point-min))
1225 (insert (plist-get parameters
:add-text
) "\n"))
1227 ;; Remove todo-keywords before exporting, if the user has requested so
1228 (org-export-remove-headline-metadata parameters
)
1230 ;; Find targets in comments and move them out of comments,
1231 ;; but mark them as targets that should be invisible
1232 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1234 ;; Select and protect backend specific stuff, throw away stuff
1235 ;; that is specific for other backends
1236 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1237 (org-export-select-backend-specific-text)
1239 ;; Protect quoted subtrees
1240 (org-export-protect-quoted-subtrees)
1242 ;; Remove clock lines
1243 (org-export-remove-clock-lines)
1245 ;; Protect verbatim elements
1246 (org-export-protect-verbatim)
1248 ;; Blockquotes, verse, and center
1249 (org-export-mark-blockquote-verse-center)
1250 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1252 ;; Remove timestamps, if the user has requested so
1253 (unless (plist-get parameters
:timestamps
)
1254 (org-export-remove-timestamps))
1256 ;; Attach captions to the correct object
1257 (setq target-alist
(org-export-attach-captions-and-attributes target-alist
))
1259 ;; Find matches for radio targets and turn them into internal links
1260 (org-export-mark-radio-links)
1261 (run-hooks 'org-export-preprocess-after-radio-targets-hook
)
1263 ;; Find all links that contain a newline and put them into a single line
1264 (org-export-concatenate-multiline-links)
1266 ;; Normalize links: Convert angle and plain links into bracket links
1267 ;; and expand link abbreviations
1268 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1269 (org-export-normalize-links)
1271 ;; Find all internal links. If they have a fuzzy match (i.e. not
1272 ;; a *dedicated* target match, let the link point to the
1273 ;; corresponding section.
1274 (org-export-target-internal-links target-alist
)
1276 ;; Find multiline emphasis and put them into single line
1277 (when (plist-get parameters
:emph-multiline
)
1278 (org-export-concatenate-multiline-emphasis))
1280 ;; Remove special table lines, and store alignment information
1281 (org-store-forced-table-alignment)
1282 (when org-export-table-remove-special-lines
1283 (org-export-remove-special-table-lines))
1286 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1288 ;; Backend-specific preprocessing
1289 (let* ((backend-name (symbol-name org-export-current-backend
))
1290 (f (intern (format "org-export-%s-preprocess" backend-name
))))
1291 (require (intern (concat "org-" backend-name
)) nil
)
1292 (funcall f parameters
))
1294 ;; Remove or replace comments
1295 (org-export-handle-comments (plist-get parameters
:comments
))
1297 ;; Remove #+TBLFM and #+TBLNAME lines
1298 (org-export-handle-table-metalines)
1300 ;; Remove #+results and #+name lines
1301 (org-export-res/src-name-cleanup
)
1303 ;; Run the final hook
1304 (run-hooks 'org-export-preprocess-final-hook
)
1306 (setq rtn
(buffer-string)))
1309 (defun org-export-kill-licensed-text ()
1310 "Remove all text that is marked with a :org-license-to-kill property."
1312 (while (setq p
(text-property-any (point-min) (point-max)
1313 :org-license-to-kill t
))
1315 p
(or (next-single-property-change p
:org-license-to-kill
)
1318 (defvar org-export-define-heading-targets-headline-hook nil
1319 "Hook that is run when a headline was matched during target search.
1320 This is part of the preprocessing for export.")
1322 (defun org-export-define-heading-targets (target-alist)
1323 "Find all headings and define the targets for them.
1324 The new targets are added to TARGET-ALIST, which is also returned.
1325 Also find all ID and CUSTOM_ID properties and store them."
1326 (goto-char (point-min))
1327 (org-init-section-numbers)
1328 (let ((re (concat "^" org-outline-regexp
1330 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1331 level target last-section-target a id
)
1332 (while (re-search-forward re nil t
)
1333 (org-if-unprotected-at (match-beginning 0)
1336 (setq id
(org-match-string-no-properties 2))
1337 (push (cons id target
) target-alist
)
1338 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1340 (push (list last-section-target
)
1341 org-export-target-aliases
)
1342 (car org-export-target-aliases
))))
1343 (push (caar target-alist
) (cdr a
))
1344 (when (equal (match-string 1) "CUSTOM_ID")
1345 (if (not (assoc last-section-target
1346 org-export-preferred-target-alist
))
1347 (push (cons last-section-target id
)
1348 org-export-preferred-target-alist
)))
1349 (when (equal (match-string 1) "ID")
1350 (if (not (assoc last-section-target
1351 org-export-id-target-alist
))
1352 (push (cons last-section-target
(concat "ID-" id
))
1353 org-export-id-target-alist
))))
1354 (setq level
(org-reduced-level
1355 (save-excursion (goto-char (point-at-bol))
1356 (org-outline-level))))
1357 (setq target
(org-solidify-link-text
1358 (format "sec-%s" (replace-regexp-in-string
1360 (org-section-number level
)))))
1361 (setq last-section-target target
)
1362 (push (cons target target
) target-alist
)
1363 (add-text-properties
1364 (point-at-bol) (point-at-eol)
1365 (list 'target target
))
1366 (run-hooks 'org-export-define-heading-targets-headline-hook
)))))
1369 (defun org-export-handle-invisible-targets (target-alist)
1370 "Find targets in comments and move them out of comments.
1371 Mark them as invisible targets."
1373 (goto-char (point-min))
1374 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1375 ;; Check if the line before or after is a headline with a target
1376 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1377 (get-text-property (point-at-bol 2) 'target
)))
1379 ;; use the existing target in a neighboring line
1380 (setq tmp
(match-string 2))
1382 (and (looking-at "\n") (delete-char 1))
1383 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1385 (setq a
(or (assoc target org-export-target-aliases
)
1387 (push (list target
) org-export-target-aliases
)
1388 (car org-export-target-aliases
))))
1390 ;; Make an invisible target
1391 (replace-match "\\1(INVISIBLE)"))))
1394 (defun org-export-target-internal-links (target-alist)
1395 "Find all internal links and assign targets to them.
1396 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1397 let the link point to the corresponding section.
1398 This function also handles the id links, if they have a match in
1400 (goto-char (point-min))
1401 (while (re-search-forward org-bracket-link-regexp nil t
)
1402 (org-if-unprotected-at (1+ (match-beginning 0))
1403 (let* ((org-link-search-must-match-exact-headline t
)
1405 (desc (match-end 2))
1406 (link (org-link-unescape (match-string 1)))
1407 (slink (org-solidify-link-text link
))
1408 found props pos cref
1411 ((= (string-to-char link
) ?
#)
1412 ;; user wants exactly this link
1414 ((cdr (assoc slink target-alist
))
1415 (or (cdr (assoc (assoc slink target-alist
)
1416 org-export-preferred-target-alist
))
1417 (cdr (assoc slink target-alist
))))
1418 ((and (string-match "^id:" link
)
1419 (cdr (assoc (substring link
3) target-alist
))))
1420 ((string-match "^(\\(.*\\))$" link
)
1421 (setq cref
(match-string 1 link
))
1422 (concat "coderef:" cref
))
1423 ((string-match org-link-types-re link
) nil
)
1424 ((or (file-name-absolute-p link
)
1425 (string-match "^\\." link
))
1428 (let ((org-link-search-inhibit-query t
))
1430 (setq found
(condition-case nil
(org-link-search link
)
1433 (or (org-at-heading-p)
1434 (not (eq found
'dedicated
))))
1435 (or (get-text-property (point) 'target
)
1438 (1- (or (previous-single-property-change
1439 (point) 'target
) 0)))
1443 (goto-char (match-beginning 1))
1444 (setq props
(text-properties-at (point)))
1445 (delete-region (match-beginning 1) (match-end 1))
1448 (unless desc
(insert "][" link
))
1449 (add-text-properties pos
(point) props
))))))
1451 (defun org-export-remember-html-container-classes ()
1452 "Store the HTML_CONTAINER_CLASS properties in a text property."
1453 (goto-char (point-min))
1455 (while (re-search-forward
1456 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t
)
1457 (setq class
(match-string 1))
1459 (org-back-to-heading t
)
1460 (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class
)))))
1462 (defvar org-export-format-drawer-function nil
1463 "Function to be called to format the contents of a drawer.
1464 The function must accept two parameters:
1465 NAME the drawer name, like \"PROPERTIES\"
1466 CONTENT the content of the drawer.
1467 You can check the export backend through `org-export-current-backend'.
1468 The function should return the text to be inserted into the buffer.
1469 If this is nil, `org-export-format-drawer' is used as a default.")
1471 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1472 "Remove drawers, or extract and format the content.
1473 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1474 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1475 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1476 EXP-DRAWERS will be removed."
1477 (goto-char (point-min))
1478 (let ((re (concat "^[ \t]*:\\("
1479 (mapconcat 'identity all-drawers
"\\|")
1481 name beg beg-content eol content
)
1482 (while (re-search-forward re nil t
)
1484 (setq name
(match-string 1))
1485 (setq beg
(match-beginning 0)
1486 beg-content
(1+ (point-at-eol))
1488 (if (not (and (re-search-forward
1489 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1492 (goto-char (match-beginning 0))
1493 (and (looking-at ".*\n?") (replace-match ""))
1494 (setq content
(buffer-substring beg-content
(point)))
1495 (delete-region beg
(point))
1496 (when (or (eq exp-drawers t
)
1497 (member name exp-drawers
))
1498 (setq content
(funcall (or org-export-format-drawer-function
1499 'org-export-format-drawer
)
1501 (insert content
)))))))
1503 (defun org-export-format-drawer (name content
)
1504 "Format the content of a drawer as a colon example."
1505 (if (string-match "[ \t]+\\'" content
)
1506 (setq content
(substring content
(match-beginning 0))))
1507 (while (string-match "\\`[ \t]*\n" content
)
1508 (setq content
(substring content
(match-end 0))))
1509 (setq content
(org-remove-indentation content
))
1510 (setq content
(concat ": " (mapconcat 'identity
1511 (org-split-string content
"\n")
1514 (setq content
(concat " : " (upcase name
) "\n" content
))
1515 (org-add-props content nil
'org-protected t
))
1517 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1518 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1519 Both arguments are lists of tags.
1520 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1522 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1524 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1525 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1528 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1532 (goto-char (point-min))
1533 (when (and select-tags
1535 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1536 ;; At least one tree is marked for export, this means
1537 ;; all the unmarked stuff needs to go.
1538 ;; Dig out the trees that should be exported
1539 (goto-char (point-min))
1540 (outline-next-heading)
1542 (put-text-property beg
(point-max) :org-delete t
)
1543 (while (re-search-forward re-sel nil t
)
1544 (when (org-at-heading-p)
1545 (org-back-to-heading)
1546 (remove-text-properties
1547 (max (1- (point)) (point-min))
1548 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1550 (while (and (org-up-heading-safe)
1551 (get-text-property (point) :org-delete
))
1552 (remove-text-properties (max (1- (point)) (point-min))
1553 (point-at-eol) '(:org-delete t
)))
1555 ;; Remove the trees explicitly marked for noexport
1557 (goto-char (point-min))
1558 (while (re-search-forward re-excl nil t
)
1559 (when (org-at-heading-p)
1560 (org-back-to-heading t
)
1562 (org-end-of-subtree t t
)
1563 (delete-region beg
(point))
1564 (when (featurep 'org-inlinetask
)
1565 (org-inlinetask-remove-END-maybe)))))
1566 ;; Remove everything that is now still marked for deletion
1567 (goto-char (point-min))
1568 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1569 (setq end
(or (next-single-property-change beg
:org-delete
)
1571 (delete-region beg end
))))
1573 (defun org-export-remove-tasks (keep)
1574 "Remove tasks depending on configuration.
1575 When KEEP is nil, remove all tasks.
1576 When KEEP is `todo', remove the tasks that are DONE.
1577 When KEEP is `done', remove the tasks that are not yet done.
1578 When it is a list of strings, keep only tasks with these TODO keywords."
1579 (when (or (listp keep
) (memq keep
'(todo done nil
)))
1580 (let ((re (concat "^\\*+[ \t]+\\("
1583 (cond ((not keep
) org-todo-keywords-1
)
1584 ((eq keep
'todo
) org-done-keywords
)
1585 ((eq keep
'done
) org-not-done-keywords
)
1587 (org-delete-all keep
(copy-sequence
1588 org-todo-keywords-1
))))
1590 "\\)\\($\\|[ \t]\\)"))
1591 (case-fold-search nil
)
1593 (goto-char (point-min))
1594 (while (re-search-forward re nil t
)
1596 (setq beg
(match-beginning 0))
1597 (org-end-of-subtree t t
)
1598 (if (looking-at "^\\*+[ \t]+END[ \t]*$")
1599 ;; Kill the END line of the inline task
1600 (goto-char (min (point-max) (1+ (match-end 0)))))
1601 (delete-region beg
(point)))))))
1603 (defun org-export-remove-archived-trees (export-archived-trees)
1604 "Remove archived trees.
1605 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1606 When it is t, the entire archived tree will be exported.
1607 When it is nil the entire tree including the headline will be removed
1609 (let ((re-archive (concat ":" org-archive-tag
":"))
1611 (when (not (eq export-archived-trees t
))
1612 (goto-char (point-min))
1613 (while (re-search-forward re-archive nil t
)
1614 (if (not (org-at-heading-p t
))
1615 (goto-char (point-at-eol))
1616 (beginning-of-line 1)
1617 (setq a
(if export-archived-trees
1618 (1+ (point-at-eol)) (point))
1619 b
(org-end-of-subtree t
))
1620 (if (> b a
) (delete-region a b
)))))))
1622 (defun org-export-remove-headline-metadata (opts)
1623 "Remove meta data from the headline, according to user options."
1624 (let ((re org-complex-heading-regexp
)
1625 (todo (plist-get opts
:todo-keywords
))
1626 (tags (plist-get opts
:tags
))
1627 (pri (plist-get opts
:priority
))
1629 (case-fold-search nil
)
1631 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1632 (when (or (not todo
) (not tags
) (not pri
))
1633 (goto-char (point-min))
1634 (while (re-search-forward re nil t
)
1636 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1638 (replace-match rpl t t
))))))
1640 (defun org-export-remove-timestamps ()
1641 "Remove timestamps and keywords for export."
1642 (goto-char (point-min))
1643 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1646 (unless (save-match-data (org-at-table-p))
1648 (beginning-of-line 1)
1649 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1650 (replace-match ""))))))
1652 (defun org-export-remove-clock-lines ()
1653 "Remove clock lines for export."
1654 (goto-char (point-min))
1655 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1656 (while (re-search-forward re nil t
)
1658 (replace-match "")))))
1660 (defvar org-heading-keyword-regexp-format
) ; defined in org.el
1661 (defun org-export-protect-quoted-subtrees ()
1662 "Mark quoted subtrees with the protection property."
1663 (let ((org-re-quote (format org-heading-keyword-regexp-format
1665 (goto-char (point-min))
1666 (while (re-search-forward org-re-quote nil t
)
1667 (goto-char (match-beginning 0))
1669 (add-text-properties (point) (org-end-of-subtree t
)
1670 '(org-protected t
)))))
1672 (defun org-export-convert-protected-spaces ()
1673 "Convert strings like \\____ to protected spaces in all backends."
1674 (goto-char (point-min))
1675 (while (re-search-forward "\\\\__+" nil t
)
1676 (org-if-unprotected-1
1680 ((eq org-export-current-backend
'latex
)
1681 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1682 ((eq org-export-current-backend
'html
)
1683 (org-add-props (match-string 0) nil
1684 'org-whitespace
(- (match-end 0) (match-beginning 0))))
1685 ;; ((eq org-export-current-backend 'docbook))
1686 ((eq org-export-current-backend
'ascii
)
1687 (org-add-props (match-string 0) '(org-whitespace t
)))
1688 (t (make-string (- (match-end 0) (match-beginning 0)) ?\
)))
1692 (defun org-export-protect-verbatim ()
1693 "Mark verbatim snippets with the protection property."
1694 (goto-char (point-min))
1695 (while (re-search-forward org-verbatim-re nil t
)
1697 (add-text-properties (match-beginning 4) (match-end 4)
1698 '(org-protected t org-verbatim-emph t
))
1699 (goto-char (1+ (match-end 4))))))
1701 (defun org-export-protect-colon-examples ()
1702 "Protect lines starting with a colon."
1703 (goto-char (point-min))
1704 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1705 (while (re-search-forward re nil t
)
1706 (beginning-of-line 1)
1708 (while (looking-at re
)
1710 (or (eobp) (forward-char 1)))
1711 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1712 '(org-protected t
)))))
1714 (defvar org-export-backends
1715 '(docbook html beamer ascii latex
)
1716 "List of Org supported export backends.")
1718 (defun org-export-select-backend-specific-text ()
1719 (let ((formatters org-export-backends
)
1720 (case-fold-search t
)
1721 backend backend-name beg beg-content end end-content ind
)
1724 (setq backend
(pop formatters
)
1725 backend-name
(symbol-name backend
))
1727 ;; Handle #+BACKEND: stuff
1728 (goto-char (point-min))
1729 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" backend-name
1730 ":[ \t]*\\(.*\\)") nil t
)
1731 (if (not (eq backend org-export-current-backend
))
1732 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1733 (let ((ind (get-text-property (point-at-bol) 'original-indentation
)))
1734 (replace-match "\\1\\2" t
)
1735 (add-text-properties
1736 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1737 `(org-protected t original-indentation
,ind org-native-text t
)))))
1738 ;; Delete #+ATTR_BACKEND: stuff of another backend. Those
1739 ;; matching the current backend will be taken care of by
1740 ;; `org-export-attach-captions-and-attributes'
1741 (goto-char (point-min))
1742 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+ATTR_" backend-name
1743 ":[ \t]*\\(.*\\)") nil t
)
1744 (setq ind
(org-get-indentation))
1745 (when (not (eq backend org-export-current-backend
))
1746 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1747 ;; Handle #+BEGIN_BACKEND and #+END_BACKEND stuff
1748 (goto-char (point-min))
1749 (while (re-search-forward (concat "^[ \t]*#\\+BEGIN_" backend-name
"\\>.*\n?")
1751 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1752 (setq ind
(or (get-text-property beg
'original-indentation
)
1753 (save-excursion (goto-char beg
) (org-get-indentation))))
1754 (when (re-search-forward (concat "^[ \t]*#\\+END_" backend-name
"\\>.*\n?")
1756 (setq end
(match-end 0) end-content
(match-beginning 0))
1757 (if (eq backend org-export-current-backend
)
1760 (add-text-properties
1761 beg-content end-content
1762 `(org-protected t original-indentation
,ind org-native-text t
))
1763 ;; strip protective commas
1764 (org-strip-protective-commas beg-content end-content
)
1765 (delete-region (match-beginning 0) (match-end 0))
1768 (delete-region (point) (1+ (point-at-eol)))))
1769 ;; No, this is for a different backend, kill it
1770 (delete-region beg end
)))))))
1772 (defun org-export-mark-blockquote-verse-center ()
1773 "Mark block quote and verse environments with special cookies.
1774 These special cookies will later be interpreted by the backend."
1776 (let (type t1 ind beg end beg1 end1 content
)
1777 (goto-char (point-min))
1778 (while (re-search-forward
1779 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1781 (setq ind
(length (match-string 1))
1782 type
(downcase (match-string 3))
1783 t1
(if (equal type
"quote") "blockquote" type
))
1784 (setq beg
(match-beginning 0)
1785 beg1
(1+ (match-end 0)))
1786 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1787 (setq end1
(1- (match-beginning 0))
1788 end
(+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1789 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1790 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1792 "ORG-" (upcase t1
) "-END\n"))
1793 (delete-region beg end
)
1794 (insert (org-add-props content nil
'original-indentation ind
))))))
1796 (defun org-export-mark-list-end ()
1797 "Mark all list endings with a special string."
1798 (unless (eq org-export-current-backend
'ascii
)
1801 ;; For each type allowing list export, find every list, remove
1802 ;; ending regexp if needed, and insert org-list-end.
1803 (goto-char (point-min))
1804 (while (re-search-forward (org-item-beginning-re) nil t
)
1805 (when (eq (nth 2 (org-list-context)) e
)
1806 (let* ((struct (org-list-struct))
1807 (bottom (org-list-get-bottom-point struct
))
1808 (top (point-at-bol))
1809 (top-ind (org-list-get-ind top struct
)))
1811 (when (and (not (eq org-list-ending-method
'indent
))
1812 (not (looking-at "[ \t]*$"))
1813 (looking-at org-list-end-re
))
1815 (unless (bolp) (insert "\n"))
1816 ;; As org-list-end is inserted at column 0, it would end
1817 ;; by indentation any list. It can be problematic when
1818 ;; there are lists within lists: the inner list end would
1819 ;; also become the outer list end. To avoid this, text
1820 ;; property `original-indentation' is added, as
1821 ;; `org-list-struct' pays attention to it when reading a
1823 (insert (org-add-props
1824 "ORG-LIST-END-MARKER\n"
1825 (list 'original-indentation top-ind
)))))))
1826 (cons nil org-list-export-context
))))
1828 (defun org-export-mark-list-properties ()
1829 "Mark list with special properties.
1830 These special properties will later be interpreted by the backend."
1833 ;; Mark a list with 3 properties: `list-item' which is
1834 ;; position at beginning of line, `list-struct' which is
1835 ;; list structure, and `list-prevs' which is the alist of
1836 ;; item and its predecessor. Leave point at list ending.
1838 (let* ((struct (org-list-struct))
1839 (top (org-list-get-top-point struct
))
1840 (bottom (org-list-get-bottom-point struct
))
1841 (prevs (org-list-prevs-alist struct
))
1843 ;; Get every item and ending position, without dups and
1844 ;; without bottom point of list.
1848 (unless (memq pos poi
)
1850 (unless (or (= end bottom
) (memq end poi
))
1853 (setq poi
(sort poi
'<))
1854 ;; For every point of interest, mark the whole line with
1855 ;; its position in list.
1859 (add-text-properties (point-at-bol) (point-at-eol)
1860 (list 'list-item
(point-at-bol)
1862 'list-prevs prevs
)))
1864 ;; Take care of bottom point. As babel may have inserted
1865 ;; a new list in buffer, list ending isn't always
1866 ;; marked. Now mark every list ending and add properties
1867 ;; useful to line processing exporters.
1869 (when (or (looking-at "^ORG-LIST-END-MARKER\n")
1870 (and (not (eq org-list-ending-method
'indent
))
1871 (not (looking-at "[ \t]*$"))
1872 (looking-at org-list-end-re
)))
1874 (unless (bolp) (insert "\n"))
1876 (org-add-props "ORG-LIST-END-MARKER\n" (list 'list-item bottom
1878 'list-prevs prevs
)))
1879 ;; Following property is used by LaTeX exporter.
1880 (add-text-properties top
(point) (list 'list-context ctxt
)))))))
1881 ;; Mark lists except for backends not interpreting them.
1882 (unless (eq org-export-current-backend
'ascii
)
1883 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
1886 (goto-char (point-min))
1887 (while (re-search-forward (org-item-beginning-re) nil t
)
1888 (let ((context (nth 2 (org-list-context))))
1890 (funcall mark-list e
)
1891 (put-text-property (point-at-bol) (point-at-eol)
1892 'list-context context
)))))
1893 (cons nil org-list-export-context
))))))
1895 (defun org-export-attach-captions-and-attributes (target-alist)
1896 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1897 If the next thing following is a table, add the text properties to the first
1898 table line. If it is a link, add it to the line containing the link."
1899 (goto-char (point-min))
1900 (remove-text-properties (point-min) (point-max)
1901 '(org-caption nil org-attributes nil
))
1902 (let ((case-fold-search t
)
1903 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1905 "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend
) ":[ \t]+\\(.*\\)"
1907 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1909 "^[ \t]*\\(|[^-]\\)"
1911 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1912 cap shortn attr label end
)
1913 (while (re-search-forward re nil t
)
1915 ;; there is a caption
1918 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1))))
1919 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap
)
1920 (setq shortn
(match-string 1 cap
)
1921 cap
(match-string 2 cap
)))
1922 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1923 ;; there is an attribute
1926 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2))))
1927 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1931 (setq label
(org-trim (match-string 3)))
1932 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1934 (setq end
(if (match-end 4)
1935 (let ((ee (org-table-end)))
1936 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1938 (add-text-properties (point-at-bol) end
1939 (list 'org-caption cap
1940 'org-caption-shortn shortn
1941 'org-attributes attr
1943 (if label
(push (cons label label
) target-alist
))
1945 (setq cap nil shortn nil attr nil label nil
)))))
1948 (defun org-export-remove-comment-blocks-and-subtrees ()
1949 "Remove the comment environment, and also commented subtrees."
1950 (let ((re-commented (format org-heading-keyword-regexp-format
1951 org-comment-string
))
1953 ;; Remove comment environment
1954 (goto-char (point-min))
1955 (setq case-fold-search t
)
1956 (while (re-search-forward
1957 "^#\\+begin_comment[ \t]*\n[^\000]*?\n#\\+end_comment\\>.*" nil t
)
1958 (replace-match "" t t
))
1959 ;; Remove subtrees that are commented
1960 (goto-char (point-min))
1961 (setq case-fold-search nil
)
1962 (while (re-search-forward re-commented nil t
)
1963 (goto-char (match-beginning 0))
1964 (delete-region (point) (org-end-of-subtree t
)))))
1966 (defun org-export-handle-comments (org-commentsp)
1967 "Remove comments, or convert to backend-specific format.
1968 ORG-COMMENTSP can be a format string for publishing comments.
1969 When it is nil, all comments will be removed."
1970 (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
1972 (goto-char (point-min))
1973 (while (or (looking-at re
)
1974 (re-search-forward re nil t
))
1975 (setq pos
(match-beginning 0))
1976 (if (get-text-property pos
'org-protected
)
1977 (goto-char (1+ pos
))
1978 (if (and org-commentsp
1979 (not (equal (char-before (match-end 1)) ?
+)))
1980 (progn (add-text-properties
1981 (match-beginning 0) (match-end 0) '(org-protected t
))
1982 (replace-match (org-add-props
1983 (format org-commentsp
(match-string 2))
1984 nil
'org-protected t
)
1986 (goto-char (1+ pos
))
1988 (goto-char (max (point-min) (1- pos
))))))))
1990 (defun org-export-handle-table-metalines ()
1991 "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
1992 (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
1994 (goto-char (point-min))
1995 (while (or (looking-at re
)
1996 (re-search-forward re nil t
))
1997 (setq pos
(match-beginning 0))
1998 (if (get-text-property (match-beginning 1) 'org-protected
)
1999 (goto-char (1+ pos
))
2000 (goto-char (1+ pos
))
2002 (goto-char (max (point-min) (1- pos
)))))))
2004 (defun org-export-res/src-name-cleanup
()
2005 "Clean up #+results and #+name lines for export.
2006 This function should only be called after all block processing
2010 (goto-char (point-min))
2011 (let ((case-fold-search t
))
2012 (while (org-re-search-forward-unprotected
2013 "#\\+\\(name\\|results\\(\\[[a-z0-9]+\\]\\)?\\):" nil t
)
2014 (delete-region (match-beginning 0) (progn (forward-line) (point)))))))
2016 (defun org-export-mark-radio-links ()
2017 "Find all matches for radio targets and turn them into internal links."
2018 (let ((re-radio (and org-target-link-regexp
2019 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
2020 (goto-char (point-min))
2022 (while (re-search-forward re-radio nil t
)
2025 (or (org-in-regexp org-bracket-link-regexp
)
2026 (org-in-regexp org-plain-link-re
)
2027 (org-in-regexp "<<[^<>]+>>")))
2029 (replace-match "\\1[[\\2]]")))))))
2031 (defun org-store-forced-table-alignment ()
2032 "Find table lines which force alignment, store the results in properties."
2033 (let (line cnt cookies
)
2034 (goto-char (point-min))
2035 (while (re-search-forward "|[ \t]*<\\([lrc]?[0-9]+\\|[lrc]\\)>[ \t]*|"
2037 ;; OK, this looks like a table line with an alignment cookie
2039 (setq line
(buffer-substring (point-at-bol) (point-at-eol)))
2040 (when (and (org-at-table-p)
2041 (org-table-cookie-line-p line
))
2042 (setq cnt
0 cookies nil
)
2046 (when (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'" x
)
2047 (let ((align (and (match-end 1)
2048 (downcase (match-string 1 x
))))
2049 (width (and (match-end 2)
2050 (string-to-number (match-string 2 x
)))))
2051 (push (cons cnt
(list align width
)) cookies
))))
2052 (org-split-string line
"[ \t]*|[ \t]*"))
2053 (add-text-properties (org-table-begin) (org-table-end)
2054 (list 'org-col-cookies cookies
))))
2055 (goto-char (point-at-eol)))))
2057 (defun org-export-remove-special-table-lines ()
2058 "Remove tables lines that are used for internal purposes.
2059 Also, store forced alignment information found in such lines."
2060 (goto-char (point-min))
2061 (while (re-search-forward "^[ \t]*|" nil t
)
2062 (org-if-unprotected-at (1- (point))
2063 (beginning-of-line 1)
2064 (if (or (looking-at "[ \t]*| *[!_^] *|")
2070 (or (and org-export-table-remove-empty-lines
(= (length f
) 0))
2072 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f
)))
2073 (org-split-string ;; FIXME, can't we do without splitting???
2074 (buffer-substring (point-at-bol) (point-at-eol))
2075 "[ \t]*|[ \t]*")))))
2076 (delete-region (max (point-min) (1- (point-at-bol)))
2080 (defun org-export-protect-sub-super (s)
2082 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
2083 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
2086 (defun org-export-normalize-links ()
2087 "Convert all links to bracket links, and expand link abbreviations."
2088 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2089 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
2091 (goto-char (point-min))
2092 (while (re-search-forward org-bracket-link-regexp nil t
)
2093 (put-text-property (match-beginning 0) (match-end 0) 'org-normalized-link t
))
2094 (goto-char (point-min))
2095 (while (re-search-forward re-plain-link nil t
)
2096 (unless (get-text-property (match-beginning 0) 'org-normalized-link
)
2097 (goto-char (1- (match-end 0)))
2098 (org-if-unprotected-at (1+ (match-beginning 0))
2099 (let* ((s (concat (match-string 1)
2100 "[[" (match-string 2) ":" (match-string 3)
2101 "][" (match-string 2) ":" (org-export-protect-sub-super
2104 ;; added 'org-link face to links
2105 (put-text-property 0 (length s
) 'face
'org-link s
)
2106 (replace-match s t t
)))))
2107 (goto-char (point-min))
2108 (while (re-search-forward re-angle-link nil t
)
2109 (goto-char (1- (match-end 0)))
2111 (let* ((s (concat (match-string 1)
2112 "[[" (match-string 2) ":" (match-string 3)
2113 "][" (match-string 2) ":" (org-export-protect-sub-super
2116 (put-text-property 0 (length s
) 'face
'org-link s
)
2117 (replace-match s t t
))))
2118 (goto-char (point-min))
2119 (while (re-search-forward org-bracket-link-regexp nil t
)
2120 (goto-char (1- (match-end 0)))
2121 (setq nodesc
(not (match-end 3)))
2123 (let* ((xx (save-match-data
2125 (org-link-expand-abbrev (match-string 1)))))
2127 "[[" (org-add-props (copy-sequence xx
)
2128 nil
'org-protected t
'org-no-description nodesc
)
2132 (concat "[" (copy-sequence xx
)
2135 (put-text-property 0 (length s
) 'face
'org-link s
)
2136 (replace-match s t t
))))))
2138 (defun org-export-concatenate-multiline-links ()
2139 "Find multi-line links and put it all into a single line.
2140 This is to make sure that the line-processing export backends
2141 can work correctly."
2142 (goto-char (point-min))
2143 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2144 (org-if-unprotected-at (match-beginning 1)
2145 (replace-match "\\1 \\3")
2146 (goto-char (match-beginning 0)))))
2148 (defun org-export-concatenate-multiline-emphasis ()
2149 "Find multi-line emphasis and put it all into a single line.
2150 This is to make sure that the line-processing export backends
2151 can work correctly."
2152 (goto-char (point-min))
2153 (while (re-search-forward org-emph-re nil t
)
2154 (if (and (not (= (char-after (match-beginning 3))
2155 (char-after (match-beginning 4))))
2156 (save-excursion (goto-char (match-beginning 0))
2158 (and (not (org-at-table-p))
2159 (not (org-at-heading-p))))))
2161 (subst-char-in-region (match-beginning 0) (match-end 0)
2163 (goto-char (1- (match-end 0))))
2164 (goto-char (1+ (match-beginning 0))))))
2166 (defun org-export-grab-title-from-buffer ()
2167 "Get a title for the current document, from looking at the buffer."
2168 (let ((inhibit-read-only t
))
2170 (goto-char (point-min))
2171 (let ((end (if (looking-at org-outline-regexp
)
2173 (save-excursion (outline-next-heading) (point)))))
2174 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2175 ;; Mark the line so that it will not be exported as normal text.
2176 (unless (org-in-block-p org-list-forbidden-blocks
)
2178 (add-text-properties (match-beginning 0) (match-end 0)
2179 (list :org-license-to-kill t
))))
2180 ;; Return the title string
2181 (org-trim (match-string 0)))))))
2183 (defun org-export-get-title-from-subtree ()
2184 "Return subtree title and exclude it from export."
2185 (let ((rbeg (region-beginning)) (rend (region-end))
2186 (inhibit-read-only t
)
2187 (tags (plist-get (org-infile-export-plist) :tags
))
2191 (when (and (org-at-heading-p)
2192 (>= (org-end-of-subtree t t
) rend
))
2193 (when (plist-member org-export-opt-plist
:tags
)
2194 (setq tags
(or (plist-get org-export-opt-plist
:tags
) tags
)))
2195 ;; This is a subtree, we take the title from the first heading
2197 (looking-at org-todo-line-tags-regexp
)
2198 (setq title
(if (eq tags t
)
2199 (format "%s\t%s" (match-string 3) (match-string 4))
2202 (add-text-properties (point) (1+ (point-at-eol))
2203 (list :org-license-to-kill t
)))
2204 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2207 (defun org-solidify-link-text (s &optional alist
)
2208 "Take link text and make a safe target out of it."
2213 (org-split-string s
"[^a-zA-Z0-9_\\.-]+") "-"))
2214 (a (assoc rtn alist
)))
2217 (defun org-get-min-level (lines &optional offset
)
2218 "Get the minimum level in LINES."
2219 (let ((re "^\\(\\*+\\) ") l
)
2221 (while (setq l
(pop lines
))
2222 (if (string-match re l
)
2223 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2227 ;; Variable holding the vector with section numbers
2228 (defvar org-section-numbers
(make-vector org-level-max
0))
2230 (defun org-init-section-numbers ()
2231 "Initialize the vector for the section numbers."
2233 (numbers (nreverse (org-split-string "" "\\.")))
2234 (depth (1- (length org-section-numbers
)))
2235 (i depth
) number-string
)
2238 (aset org-section-numbers i
0)
2239 (setq number-string
(or (car numbers
) "0"))
2240 (if (string-match "\\`[A-Z]\\'" number-string
)
2241 (aset org-section-numbers i
2242 (- (string-to-char number-string
) ?A -
1))
2243 (aset org-section-numbers i
(string-to-number number-string
)))
2247 (defun org-section-number (&optional level
)
2248 "Return a string with the current section number.
2249 When LEVEL is non-nil, increase section numbers on that level."
2250 (let* ((depth (1- (length org-section-numbers
)))
2252 (fmts (car org-export-section-number-format
))
2253 (term (cdr org-export-section-number-format
))
2258 (aset org-section-numbers
2259 level
(1+ (aref org-section-numbers level
))))
2260 (setq idx
(1+ level
))
2261 (while (<= idx depth
)
2263 (aset org-section-numbers idx
0))
2264 (setq idx
(1+ idx
))))
2266 (while (<= idx depth
)
2267 (when (> (aref org-section-numbers idx
) 0)
2268 (setq fmt
(or (pop fmts
) fmt
)
2270 n
(aref org-section-numbers idx
)
2272 (concat string sep
(org-number-to-counter n ctype
))
2273 (concat string
".0"))
2275 (setq idx
(1+ idx
)))
2277 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2278 (setq string
(replace-match "" t nil string
)))
2279 (if (string-match "\\(\\.0\\)+\\'" string
)
2280 (setq string
(replace-match "" t nil string
))))
2281 (concat string term
)))
2283 (defun org-number-to-counter (n type
)
2284 "Concert number N to a string counter, according to TYPE.
2285 TYPE must be a string, any of:
2289 I upper case roman numeral
2290 i lower case roman numeral"
2292 ((equal type
"1") (number-to-string n
))
2293 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2294 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2295 ((equal type
"I") (org-number-to-roman n
))
2296 ((equal type
"i") (downcase (org-number-to-roman n
)))
2297 (t (error "Invalid counter type `%s'" type
))))
2299 (defun org-number-to-roman (n)
2300 "Convert integer N into a roman numeral."
2301 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2302 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2303 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2307 (number-to-string n
)
2309 (if (>= n
(caar roman
))
2310 (setq n
(- n
(caar roman
))
2311 res
(concat res
(cdar roman
)))
2317 (defun org-export-preprocess-apply-macros ()
2318 "Replace macro references."
2319 (goto-char (point-min))
2320 (let (sy val key args args2 ind-str s n
)
2321 (while (re-search-forward
2322 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2324 (unless (save-match-data (save-excursion
2325 (goto-char (point-at-bol))
2326 (looking-at "[ \t]*#\\+macro")))
2327 ;; Get macro name (KEY), arguments (ARGS), and indentation of
2328 ;; current line (IND-STR) as strings.
2329 (setq key
(downcase (match-string 1))
2330 args
(match-string 3)
2331 ind-str
(save-match-data (save-excursion
2333 (looking-at "^\\([ \t]*\\).*")
2335 ;; When macro is defined, retrieve replacement text in VAL,
2336 ;; and proceed with expansion.
2337 (when (setq val
(or (plist-get org-export-opt-plist
2338 (intern (concat ":macro-" key
)))
2339 (plist-get org-export-opt-plist
2340 (intern (concat ":" key
)))))
2342 ;; If arguments are provided, first retrieve them properly
2343 ;; (in ARGS, as a list), then replace them in VAL.
2345 (setq args
(org-split-string args
",") args2 nil
)
2347 (while (string-match "\\\\\\'" (car args
))
2348 ;; Repair bad splits.
2349 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2352 (push (pop args
) args2
))
2353 (setq args
(mapcar 'org-trim
(nreverse args2
)))
2355 (while (string-match "\\$\\([0-9]+\\)" val s
)
2356 (setq s
(1+ (match-beginning 0))
2357 n
(string-to-number (match-string 1 val
)))
2358 (and (>= (length args
) n
)
2359 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2360 ;; VAL starts with "(eval": it is a sexp, `eval' it.
2361 (when (string-match "\\`(eval\\>" val
)
2362 (setq val
(eval (read val
))))
2363 ;; Ensure VAL is a string (or nil) and that each new line
2364 ;; is indented as the first one.
2366 (mapconcat 'identity
2368 (if (stringp val
) val
(format "%s" val
))
2370 (concat "\n" ind-str
)))))
2371 ;; Eventually do the replacement, if VAL isn't nil. Move
2372 ;; point at beginning of macro for recursive expansions.
2374 (replace-match val t t
)
2375 (goto-char (match-beginning 0))))))))
2377 (defun org-export-apply-macros-in-string (s)
2378 "Apply the macros in string S."
2382 (org-export-preprocess-apply-macros)
2387 (defun org-export-handle-include-files ()
2388 "Include the contents of include files, with proper formatting."
2389 (let ((case-fold-search t
)
2390 params file markup lang start end prefix prefix1 switches all minlevel lines
)
2391 (goto-char (point-min))
2392 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2393 (setq params
(read (concat "(" (match-string 1) ")"))
2394 prefix
(org-get-and-remove-property 'params
:prefix
)
2395 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2396 minlevel
(org-get-and-remove-property 'params
:minlevel
)
2397 lines
(org-get-and-remove-property 'params
:lines
)
2398 file
(org-symname-or-string (pop params
))
2399 markup
(org-symname-or-string (pop params
))
2400 lang
(and (member markup
'("src" "SRC"))
2401 (org-symname-or-string (pop params
)))
2402 switches
(mapconcat #'(lambda (x) (format "%s" x
)) params
" ")
2404 (delete-region (match-beginning 0) (match-end 0))
2406 (not (file-exists-p file
))
2407 (not (file-readable-p file
)))
2408 (insert (format "CANNOT INCLUDE FILE %s" file
))
2409 (setq all
(cons file all
))
2411 (if (equal (downcase markup
) "src")
2412 (setq start
(format "#+begin_src %s %s\n"
2413 (or lang
"fundamental")
2416 (setq start
(format "#+begin_%s %s\n" markup switches
)
2417 end
(format "#+end_%s" markup
))))
2418 (insert (or start
""))
2419 (insert (org-get-file-contents (expand-file-name file
)
2420 prefix prefix1 markup minlevel lines
))
2421 (or (bolp) (newline))
2422 (insert (or end
""))))
2425 (defun org-export-handle-include-files-recurse ()
2426 "Recursively include files aborting on circular inclusion."
2427 (let ((now (list org-current-export-file
)) all
)
2429 (setq all
(append now all
))
2430 (setq now
(org-export-handle-include-files))
2433 (mapcar (lambda (el) (when (member el all
) el
)) now
))))
2435 (error "Recursive #+INCLUDE: %S" intersection
))))))
2437 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel lines
)
2438 "Get the contents of FILE and return them as a string.
2439 If PREFIX is a string, prepend it to each line. If PREFIX1
2440 is a string, prepend it to the first line instead of PREFIX.
2441 If MARKUP, don't protect org-like lines, the exporter will
2442 take care of the block they are in. If LINES is a string
2443 specifying a range of lines, include only those lines ."
2444 (if (stringp markup
) (setq markup
(downcase markup
)))
2446 (insert-file-contents file
)
2448 (let* ((lines (split-string lines
"-"))
2449 (lbeg (string-to-number (car lines
)))
2450 (lend (string-to-number (cadr lines
)))
2451 (beg (if (zerop lbeg
) (point-min)
2452 (goto-char (point-min))
2453 (forward-line (1- lbeg
))
2455 (end (if (zerop lend
) (point-max)
2456 (goto-char (point-min))
2457 (forward-line (1- lend
))
2459 (narrow-to-region beg end
)))
2460 (when (or prefix prefix1
)
2461 (goto-char (point-min))
2463 (insert (or prefix1 prefix
))
2465 (beginning-of-line 2)))
2467 (when (member markup
'("src" "example"))
2468 (goto-char (point-min))
2469 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2470 (goto-char (match-beginning 0))
2474 (dotimes (lvl minlevel
)
2475 (org-map-region 'org-demote
(point-min) (point-max))))
2478 (defun org-get-and-remove-property (listvar prop
)
2479 "Check if the value of LISTVAR contains PROP as a property.
2480 If yes, return the value of that property (i.e. the element following
2481 in the list) and remove property and value from the list in LISTVAR."
2482 (let ((list (symbol-value listvar
)) m v
)
2483 (when (setq m
(member prop list
))
2485 (if (equal (car list
) prop
)
2486 (set listvar
(cddr list
))
2487 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2489 (set listvar list
)))
2492 (defun org-symname-or-string (s)
2494 (if s
(symbol-name s
) s
)
2497 ;;; Fontification and line numbers for code examples
2499 (defvar org-export-last-code-line-counter-value
0)
2501 (defun org-export-replace-src-segments-and-examples ()
2502 "Replace source code segments with special code for export."
2503 (setq org-export-last-code-line-counter-value
0)
2504 (let ((case-fold-search t
)
2505 lang code trans opts indent caption
)
2506 (goto-char (point-min))
2507 (while (re-search-forward
2508 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2511 (if (not (match-string 4))
2512 (error "Source block missing language specification: %s"
2513 (let* ((body (match-string 6))
2514 (nothing (message "body:%s" body
))
2515 (preview (or (and (string-match
2516 "^[ \t]*\\([^\n\r]*\\)" body
)
2517 (match-string 1 body
)) body
)))
2518 (if (> (length preview
) 35)
2519 (concat (substring preview
0 32) "...")
2522 (setq lang
(match-string 4)
2523 opts
(match-string 5)
2524 code
(match-string 6)
2525 indent
(length (match-string 2))
2526 caption
(get-text-property 0 'org-caption
(match-string 0))))
2528 opts
(match-string 9)
2529 code
(match-string 10)
2530 indent
(length (match-string 8))
2531 caption
(get-text-property 0 'org-caption
(match-string 0))))
2533 (setq trans
(org-export-format-source-code-or-example
2534 lang code opts indent caption
))
2535 (replace-match trans t t
))))
2537 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2538 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2539 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2540 (defvar org-export-latex-listings-w-names
) ;; defined in org-latex.el
2541 (defvar org-export-latex-minted-langs
) ;; defined in org-latex.el
2542 (defvar org-export-latex-custom-lang-environments
) ;; defined in org-latex.el
2543 (defvar org-export-latex-listings-options
) ;; defined in org-latex.el
2544 (defvar org-export-latex-minted-options
) ;; defined in org-latex.el
2546 (defun org-remove-formatting-on-newlines-in-region (beg end
)
2547 "Remove formatting on newline characters"
2551 (while (progn (end-of-line) (< (point) end
))
2552 (put-text-property (point) (1+ (point)) 'face nil
)
2555 (defun org-export-format-source-code-or-example
2556 (lang code
&optional opts indent caption
)
2557 "Format CODE from language LANG and return it formatted for export.
2558 The CODE is marked up in `org-export-current-backend' format.
2560 Check if a function by name
2561 \"org-<backend>-format-source-code-or-example\" is bound. If yes,
2562 use it as the custom formatter. Otherwise, use the default
2563 formatter. Default formatters are provided for docbook, html,
2564 latex and ascii backends. For example, use
2565 `org-html-format-source-code-or-example' to provide a custom
2566 formatter for export to \"html\".
2568 If LANG is nil, do not add any fontification.
2569 OPTS contains formatting options, like `-n' for triggering numbering lines,
2570 and `+n' for continuing previous numbering.
2571 Code formatting according to language currently only works for HTML.
2572 Numbering lines works for all three major backends (html, latex, and ascii).
2573 INDENT was the original indentation of the block."
2575 (let* ((backend-name (symbol-name org-export-current-backend
))
2577 (intern (format "org-%s-format-source-code-or-example"
2579 (backend-feature (intern (concat "org-" backend-name
)))
2581 (and (require (intern (concat "org-" backend-name
)) nil
)
2582 (fboundp backend-formatter
) backend-formatter
))
2583 num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2584 (setq opts
(or opts
"")
2585 num
(string-match "[-+]n\\>" opts
)
2586 cont
(string-match "\\+n\\>" opts
)
2587 rpllbl
(string-match "-r\\>" opts
)
2588 keepp
(string-match "-k\\>" opts
)
2589 textareap
(string-match "-t\\>" opts
)
2590 preserve-indentp
(or org-src-preserve-indentation
2591 (string-match "-i\\>" opts
))
2592 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2593 (string-to-number (match-string 1 opts
))
2595 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2596 (string-to-number (match-string 1 opts
))
2597 (org-count-lines code
))
2598 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2599 (match-string 1 opts
)))
2600 (when (and textareap
(eq org-export-current-backend
'html
))
2601 ;; we cannot use numbering or highlighting.
2602 (setq num nil cont nil lang nil
))
2603 (if keepp
(setq rpllbl
'keep
))
2604 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2605 (when (string-match "^," rtn
)
2606 (setq rtn
(with-temp-buffer
2608 ;; Free up the protected lines
2609 (goto-char (point-min))
2610 (while (re-search-forward "^," nil t
)
2611 (if (or (equal lang
"org")
2613 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2617 ;; Now backend-specific coding
2621 (funcall backend-formatter rtn lang caption textareap cols rows num
2623 ((eq org-export-current-backend
'docbook
)
2624 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2625 (concat "<programlisting><![CDATA["
2627 "]]></programlisting>\n"))
2628 ((eq org-export-current-backend
'html
)
2629 ;; We are exporting to HTML
2631 (if (featurep 'xemacs
)
2633 (require 'htmlize nil t
))
2634 (when (not (fboundp 'htmlize-region-for-paste
))
2635 ;; we do not have htmlize.el, or an old version of it
2638 "htmlize.el 1.34 or later is needed for source code formatting")))
2641 (let* ((lang-m (when lang
2642 (or (cdr (assoc lang org-src-lang-modes
))
2644 (mode (and lang-m
(intern
2646 (if (symbolp lang-m
)
2647 (symbol-name lang-m
)
2650 (org-inhibit-startup t
)
2651 (org-startup-folded nil
))
2655 (if (functionp mode
)
2658 (font-lock-fontify-buffer)
2659 ;; markup each line separately
2660 (org-remove-formatting-on-newlines-in-region (point-min) (point-max))
2662 (set-buffer-modified-p nil
)
2663 (org-export-htmlize-region-for-paste
2664 (point-min) (point-max))))
2665 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2670 "<div class=\"org-src-container\">"
2672 "<label class=\"org-src-name\">%s</label>"
2676 (format "<pre class=\"src src-%s\">\n" lang
)
2678 (if caption
"</div>" "")))))
2681 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2683 rtn
"</textarea>\n</p>\n"))
2686 (goto-char (point-min))
2687 (while (re-search-forward "[<>&]" nil t
)
2688 (replace-match (cdr (assq (char-before)
2689 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2691 (setq rtn
(buffer-string)))
2692 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2694 (setq rtn
(org-export-number-lines rtn
1 1 num cont rpllbl fmt
)))
2695 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2696 (setq rtn
(replace-match "\\1" t nil rtn
)))
2698 ((eq org-export-current-backend
'latex
)
2699 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2701 ((and lang org-export-latex-listings
)
2702 (flet ((make-option-string
2704 (concat (first pair
)
2705 (if (> (length (second pair
)) 0)
2706 (concat "=" (second pair
))))))
2707 (let* ((lang-sym (intern lang
))
2708 (minted-p (eq org-export-latex-listings
'minted
))
2709 (listings-p (not minted-p
))
2715 (minted-p org-export-latex-minted-langs
)
2716 (listings-p org-export-latex-listings-langs
))))
2722 org-export-latex-custom-lang-environments
))))
2724 (when (and listings-p
(not custom-environment
))
2728 #'make-option-string
2729 (append org-export-latex-listings-options
2730 `(("language" ,backend-lang
))) ",")))
2731 (when (and caption org-export-latex-listings-w-names
)
2734 (replace-regexp-in-string "_" "\\\\_" caption
)))
2737 (format "\\begin{%s}\n%s\\end{%s}\n"
2738 custom-environment rtn custom-environment
))
2740 (format "\\begin{%s}\n%s\\end{%s}"
2741 "lstlisting" rtn
"lstlisting"))
2744 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2745 (mapconcat #'make-option-string
2746 org-export-latex-minted-options
",")
2747 backend-lang rtn
)))))))
2748 (t (concat (car org-export-latex-verbatim-wrap
)
2749 rtn
(cdr org-export-latex-verbatim-wrap
)))))
2750 ((eq org-export-current-backend
'ascii
)
2751 ;; This is not HTML or LaTeX, so just make it an example.
2752 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2753 (concat caption
"\n"
2756 (lambda (l) (concat " " l
))
2757 (org-split-string rtn
"\n")
2762 (error "Don't know how to markup source or example block in %s"
2763 (upcase backend-name
)))))
2766 "\n#+BEGIN_" backend-name
"\n"
2768 '(org-protected t org-example t org-native-text t
))
2769 "\n#+END_" backend-name
"\n"))
2770 (org-add-props rtn nil
'original-indentation indent
))))
2772 (defun org-export-number-lines (text &optional skip1 skip2 number cont
2773 replace-labels label-format preprocess
)
2774 "Apply line numbers to literal examples and handle code references.
2775 Handle user-specified options under info node `(org)Literal
2776 examples' and return the modified source block.
2778 TEXT contains the source or example block.
2780 SKIP1 and SKIP2 are the number of lines that are to be skipped at
2781 the beginning and end of TEXT. Use these to skip over
2782 backend-specific lines pre-pended or appended to the original
2785 NUMBER is non-nil if the literal example specifies \"+n\" or
2786 \"-n\" switch. If NUMBER is non-nil add line numbers.
2788 CONT is non-nil if the literal example specifies \"+n\" switch.
2789 If CONT is nil, start numbering this block from 1. Otherwise
2790 continue numbering from the last numbered block.
2792 REPLACE-LABELS is dual-purpose.
2793 1. It controls the retention of labels in the exported block.
2794 2. It specifies in what manner the links (or references) to a
2795 labelled line be formatted.
2797 REPLACE-LABELS is the symbol `keep' if the literal example
2798 specifies \"-k\" option, is numeric if the literal example
2799 specifies \"-r\" option and is nil otherwise.
2801 Handle REPLACE-LABELS as below:
2802 - If nil, retain labels in the exported block and use
2803 user-provided labels for referencing the labelled lines.
2804 - If it is a number, remove labels in the exported block and use
2805 one of line numbers or labels for referencing labelled lines based
2807 - If it is a keep, retain labels in the exported block and use
2808 one of line numbers or labels for referencing labelled lines
2809 based on NUMBER option.
2811 LABEL-FORMAT is the value of \"-l\" switch associated with
2812 literal example. See `org-coderef-label-format'.
2814 PREPROCESS is intended for backend-agnostic handling of source
2815 block numbering. When non-nil do the following:
2816 - do not number the lines
2817 - always strip the labels from exported block
2818 - do not make the labelled line a target of an incoming link.
2819 Instead mark the labelled line with `org-coderef' property and
2820 store the label in it."
2821 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2822 (if (and number
(not cont
)) (setq org-export-last-code-line-counter-value
0))
2825 (goto-char (point-max))
2826 (skip-chars-backward " \t\n\r")
2827 (delete-region (point) (point-max))
2828 (beginning-of-line (- 1 skip2
))
2829 (let* ((last (org-current-line))
2830 (n org-export-last-code-line-counter-value
)
2831 (nmax (+ n
(- last skip1
)))
2832 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2835 ((eq org-export-current-backend
'html
) (format "<span class=\"linenr\">%s</span>"
2837 ((eq org-export-current-backend
'ascii
) fmt
)
2838 ((eq org-export-current-backend
'latex
) fmt
)
2839 ((eq org-export-current-backend
'docbook
) fmt
)
2841 (label-format (or label-format org-coderef-label-format
))
2842 (label-pre (if (string-match "%s" label-format
)
2843 (substring label-format
0 (match-beginning 0))
2845 (label-post (if (string-match "%s" label-format
)
2846 (substring label-format
(match-end 0))
2850 ".*?\\S-.*?\\([ \t]*\\("
2851 (regexp-quote label-pre
)
2852 "\\([-a-zA-Z0-9_ ]+\\)"
2853 (regexp-quote label-post
)
2857 (org-goto-line (1+ skip1
))
2858 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2859 (when number
(incf n
))
2860 (if (or preprocess
(not number
))
2862 (insert (format fm n
)))
2863 (when (looking-at lbl-re
)
2864 (setq ref
(match-string 3))
2865 (cond ((numberp replace-labels
)
2866 ;; remove labels; use numbers for references when lines
2867 ;; are numbered, use labels otherwise
2868 (delete-region (match-beginning 1) (match-end 1))
2869 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2870 ((eq replace-labels
'keep
)
2871 ;; don't remove labels; use numbers for references when
2872 ;; lines are numbered, use labels otherwise
2873 (goto-char (match-beginning 2))
2874 (delete-region (match-beginning 2) (match-end 2))
2876 (insert "(" ref
")"))
2877 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2878 org-export-code-refs
))
2880 ;; don't remove labels and don't use numbers for
2882 (goto-char (match-beginning 2))
2883 (delete-region (match-beginning 2) (match-end 2))
2885 (insert "(" ref
")"))
2886 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2887 (when (and (eq org-export-current-backend
'html
) (not preprocess
))
2889 (beginning-of-line 1)
2890 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2893 (insert "</span>")))
2895 (add-text-properties
2896 (point-at-bol) (point-at-eol) (list 'org-coderef ref
)))))
2897 (setq org-export-last-code-line-counter-value n
)
2898 (goto-char (point-max))
2902 (defun org-search-todo-below (line lines level
)
2903 "Search the subtree below LINE for any TODO entries."
2904 (let ((rest (cdr (memq line lines
)))
2905 (re org-todo-line-regexp
)
2908 (while (setq line
(pop rest
))
2909 (if (string-match re line
)
2911 (setq lv
(- (match-end 1) (match-beginning 1))
2912 todo
(and (match-beginning 2)
2913 (not (member (match-string 2 line
)
2914 org-done-keywords
))))
2916 (if (<= lv level
) (throw 'exit nil
))
2917 (if todo
(throw 'exit t
))))))))
2920 (defun org-export-visible (type arg
)
2921 "Create a copy of the visible part of the current buffer, and export it.
2922 The copy is created in a temporary buffer and removed after use.
2923 TYPE is the final key (as a string) that also selects the export command in
2924 the \\<org-mode-map>\\[org-export] export dispatcher.
2925 As a special case, if the you type SPC at the prompt, the temporary
2926 org-mode file will not be removed but presented to you so that you can
2927 continue to use it. The prefix arg ARG is passed through to the exporting
2931 (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")
2932 (read-char-exclusive))
2933 current-prefix-arg
))
2934 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L ?H ?R
)))
2935 (error "Invalid export key"))
2936 (let* ((binding (cdr (assoc type
2938 (?a . org-export-as-ascii
)
2939 (?A . org-export-as-ascii-to-buffer
)
2940 (?n . org-export-as-latin1
)
2941 (?N . org-export-as-latin1-to-buffer
)
2942 (?u . org-export-as-utf8
)
2943 (?U . org-export-as-utf8-to-buffer
)
2944 (?\C-a . org-export-as-ascii
)
2945 (?b . org-export-as-html-and-open
)
2946 (?\C-b . org-export-as-html-and-open
)
2947 (?h . org-export-as-html
)
2948 (?H . org-export-as-html-to-buffer
)
2949 (?R . org-export-region-as-html
)
2950 (?D . org-export-as-docbook
)
2952 (?l . org-export-as-latex
)
2953 (?p . org-export-as-pdf
)
2954 (?d . org-export-as-pdf-and-open
)
2955 (?L . org-export-as-latex-to-buffer
)
2957 (?x . org-export-as-xoxo
)))))
2958 (keepp (equal type ?\
))
2959 (file buffer-file-name
)
2960 (buffer (get-buffer-create "*Org Export Visible*"))
2962 ;; Need to hack the drawers here.
2964 (goto-char (point-min))
2965 (while (re-search-forward org-drawer-regexp nil t
)
2966 (goto-char (match-beginning 1))
2967 (or (outline-invisible-p) (org-flag-drawer nil
))))
2968 (with-current-buffer buffer
(erase-buffer))
2970 (setq s
(goto-char (point-min)))
2971 (while (not (= (point) (point-max)))
2972 (goto-char (org-find-invisible))
2973 (append-to-buffer buffer s
(point))
2974 (setq s
(goto-char (org-find-visible))))
2975 (org-cycle-hide-drawers 'all
)
2976 (goto-char (point-min))
2978 ;; Copy all comment lines to the end, to make sure #+ settings are
2979 ;; still available for the second export step. Kind of a hack, but
2980 ;; does do the trick.
2981 (if (looking-at "#[^\r\n]*")
2982 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2983 (when (re-search-forward "^\\*+[ \t]+" nil t
)
2984 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t
)
2985 (append-to-buffer buffer
(1+ (match-beginning 0))
2986 (min (point-max) (1+ (match-end 0)))))))
2988 (let ((buffer-file-name file
)
2989 (org-inhibit-startup t
))
2992 (unless keepp
(funcall binding arg
))))
2994 (kill-buffer buffer
)
2995 (switch-to-buffer-other-window buffer
)
2996 (goto-char (point-min)))))
2998 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
3000 (defun org-export-string (string fmt
&optional dir
)
3001 "Export STRING to FMT using existing export facilities.
3002 During export STRING is saved to a temporary file whose location
3003 could vary. Optional argument DIR can be used to force the
3004 directory in which the temporary file is created during export
3005 which can be useful for resolving relative paths. Dir defaults
3006 to the value of `temporary-file-directory'."
3007 (let ((temporary-file-directory (or dir temporary-file-directory
))
3008 (tmp-file (make-temp-file "org-")))
3012 (write-file tmp-file
)
3013 (org-load-modules-maybe)
3014 (unless org-local-vars
3015 (setq org-local-vars
(org-get-local-variables)))
3016 (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
3017 (list 'let org-local-vars
3018 (list (intern (format "org-export-as-%s" fmt
))
3019 nil nil nil
''string t
))))
3020 (delete-file tmp-file
))))
3023 (defun org-export-as-org (arg &optional hidden ext-plist
3024 to-buffer body-only pub-dir
)
3025 "Make a copy with not-exporting stuff removed.
3026 The purpose of this function is to provide a way to export the source
3027 Org file of a webpage in Org format, but with sensitive and/or irrelevant
3028 stuff removed. This command will remove the following:
3030 - archived trees (if the variable `org-export-with-archived-trees' is nil)
3031 - comment blocks and trees starting with the COMMENT keyword
3032 - only trees that are consistent with `org-export-select-tags'
3033 and `org-export-exclude-tags'.
3035 The only arguments that will be used are EXT-PLIST and PUB-DIR,
3036 all the others will be ignored (but are present so that the general
3037 mechanism to call publishing functions will work).
3039 EXT-PLIST is a property list with external parameters overriding
3040 org-mode's default settings, but still inferior to file-local
3041 settings. When PUB-DIR is set, use this as the publishing
3044 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
3046 (org-infile-export-plist)))
3047 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3048 (filename (concat (file-name-as-directory
3050 (org-export-directory :org opt-plist
)))
3051 (file-name-sans-extension
3052 (file-name-nondirectory bfname
))
3054 (filename (and filename
3055 (if (equal (file-truename filename
)
3056 (file-truename bfname
))
3057 (concat (file-name-sans-extension filename
)
3059 (file-name-extension filename
))
3061 (backup-inhibited t
)
3062 (buffer (find-file-noselect filename
))
3063 (region (buffer-string))
3066 (org-pop-to-buffer-same-window buffer
)
3069 (let ((org-inhibit-startup t
)) (org-mode))
3070 (org-install-letbind)
3072 ;; Get rid of archived trees
3073 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
3075 ;; Remove comment environment and comment subtrees
3076 (org-export-remove-comment-blocks-and-subtrees)
3078 ;; Get rid of excluded trees
3079 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
3080 (plist-get opt-plist
:exclude-tags
))
3082 (when (or (plist-get opt-plist
:plain-source
)
3083 (not (or (plist-get opt-plist
:plain-source
)
3084 (plist-get opt-plist
:htmlized-source
))))
3085 ;; Either nothing special is requested (default call)
3086 ;; or the plain source is explicitly requested
3089 (when (plist-get opt-plist
:htmlized-source
)
3090 ;; Make the htmlized version
3093 (font-lock-fontify-buffer)
3094 (let* ((htmlize-output-type 'css
)
3095 (newbuf (htmlize-buffer)))
3096 (with-current-buffer newbuf
3097 (when org-export-htmlized-org-css-url
3098 (goto-char (point-min))
3099 (and (re-search-forward
3100 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
3104 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
3105 org-export-htmlized-org-css-url
)
3107 (write-file (concat filename
".html")))
3108 (kill-buffer newbuf
)))
3109 (set-buffer-modified-p nil
)
3110 (if (equal to-buffer
'string
)
3111 (progn (setq str-ret
(buffer-string))
3112 (kill-buffer (current-buffer))
3114 (kill-buffer (current-buffer))))))
3116 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
3117 (defun org-get-current-options ()
3118 "Return a string with current options as keyword options.
3119 Does include HTML export options as well as TODO and CATEGORY stuff."
3120 (require 'org-archive
)
3129 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
3130 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
3132 #+EXPORT_SELECT_TAGS: %s
3133 #+EXPORT_EXCLUDE_TAGS: %s
3140 #+PRIORITIES: %c %c %c
3142 #+STARTUP: %s %s %s %s %s
3148 (buffer-name) (user-full-name) user-mail-address
3149 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
3150 org-export-default-language
3151 org-export-headline-levels
3152 org-export-with-section-numbers
3154 org-export-preserve-breaks
3155 org-export-html-expand
3156 org-export-with-fixed-width
3157 org-export-with-tables
3158 org-export-with-sub-superscripts
3159 org-export-with-special-strings
3160 org-export-with-footnotes
3161 org-export-with-emphasize
3162 org-export-with-timestamps
3163 org-export-with-TeX-macros
3164 org-export-with-LaTeX-fragments
3165 org-export-skip-text-before-1st-heading
3166 org-export-with-drawers
3167 org-export-with-todo-keywords
3168 org-export-with-priority
3169 org-export-with-tags
3170 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
3171 (mapconcat 'identity org-export-select-tags
" ")
3172 (mapconcat 'identity org-export-exclude-tags
" ")
3173 org-export-html-link-up
3174 org-export-html-link-home
3176 (file-name-sans-extension
3177 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3179 "TODO FEEDBACK VERIFY DONE"
3180 "Me Jason Marie DONE"
3181 org-highest-priority org-lowest-priority org-default-priority
3182 (mapconcat 'identity org-drawers
" ")
3183 (cdr (assoc org-startup-folded
3184 '((nil .
"showall") (t .
"overview") (content .
"content"))))
3185 (if org-odd-levels-only
"odd" "oddeven")
3186 (if org-hide-leading-stars
"hidestars" "showstars")
3187 (if org-startup-align-all-tables
"align" "noalign")
3188 (cond ((eq org-log-done t
) "logdone")
3189 ((equal org-log-done
'note
) "lognotedone")
3190 ((not org-log-done
) "nologdone"))
3191 (or (mapconcat (lambda (x)
3193 ((equal :startgroup
(car x
)) "{")
3194 ((equal :endgroup
(car x
)) "}")
3195 ((equal :newline
(car x
)) "")
3196 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
3198 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
3199 (mapconcat 'identity org-file-tags
" ")
3200 org-archive-location
3201 "org file:~/org/%s.org"
3205 (defun org-insert-export-options-template ()
3206 "Insert into the buffer a template with information for exporting."
3208 (if (not (bolp)) (newline))
3209 (let ((s (org-get-current-options)))
3210 (and (string-match "#\\+CATEGORY" s
)
3211 (setq s
(substring s
0 (match-beginning 0))))
3214 (defvar org-table-colgroup-info nil
)
3216 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
3217 "Check if the table has a marking column.
3218 If yes remove the column and the special lines."
3219 (setq org-table-colgroup-info nil
)
3222 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3225 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
3226 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
3229 ;; No special marking column
3231 (setq org-table-clean-did-remove-column nil
)
3236 ((org-table-colgroup-line-p x
)
3237 ;; This line contains colgroup info, extract it
3238 ;; and then discard the line
3239 (setq org-table-colgroup-info
3241 (cond ((member x
'("<" "<")) :start
)
3242 ((member x
'(">" ">")) :end
)
3243 ((member x
'("<>" "<>")) :startend
)
3245 (org-split-string x
"[ \t]*|[ \t]*")))
3247 ((org-table-cookie-line-p x
)
3248 ;; This line contains formatting cookies, discard it
3252 ;; there is a special marking column
3253 (setq org-table-clean-did-remove-column t
)
3258 ((org-table-colgroup-line-p x
)
3259 ;; This line contains colgroup info, extract it
3260 ;; and then discard the line
3261 (setq org-table-colgroup-info
3263 (cond ((member x
'("<" "<")) :start
)
3264 ((member x
'(">" ">")) :end
)
3265 ((member x
'("<>" "<>")) :startend
)
3267 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3269 ((org-table-cookie-line-p x
)
3270 ;; This line contains formatting cookies, discard it
3272 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3275 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3276 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3277 ;; remove the first column
3278 (replace-match "\\1|" t nil x
))))
3281 (defun org-export-cleanup-toc-line (s)
3282 "Remove tags and timestamps from lines going into the toc."
3283 (when (memq org-export-with-tags
'(not-in-toc nil
))
3284 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s
)
3285 (setq s
(replace-match "" t t s
))))
3286 (when org-export-remove-timestamps-from-toc
3287 (while (string-match org-maybe-keyword-time-regexp s
)
3288 (setq s
(replace-match "" t t s
))))
3289 (while (string-match org-bracket-link-regexp s
)
3290 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3292 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
3293 (setq s
(replace-match "" t t s
)))
3297 (defun org-get-text-property-any (pos prop
&optional object
)
3298 (or (get-text-property pos prop object
)
3299 (and (setq pos
(next-single-property-change pos prop object
))
3300 (get-text-property pos prop object
))))
3302 (defun org-export-get-coderef-format (path desc
)
3304 (if (and desc
(string-match
3305 (regexp-quote (concat "(" path
")"))
3307 (replace-match "%s" t t desc
)
3310 (defun org-export-push-to-kill-ring (format)
3311 "Push buffer content to kill ring.
3312 The depends on the variable `org-export-copy-to-kill-ring'."
3313 (when org-export-copy-to-kill-ring
3314 (org-kill-new (buffer-string))
3315 (when (fboundp 'x-set-selection
)
3316 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
3317 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
3318 (message "%s export done, pushed to kill ring and clipboard" format
)))
3322 ;;; org-exp.el ends here