org-export: Fix docstrings
[org-mode.git] / contrib / lisp / org-export.el
blob85fb268615c198ee2ceff68627189994ff38c548
1 ;;; org-export.el --- Generic Export Engine For Org
3 ;; Copyright (C) 2012 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements a generic export engine for Org, built on
24 ;; its syntactical parser: Org Elements.
26 ;; Besides that parser, the generic exporter is made of three distinct
27 ;; parts:
29 ;; - The communication channel consists in a property list, which is
30 ;; created and updated during the process. Its use is to offer
31 ;; every piece of information, would it be export options or
32 ;; contextual data, all in a single place. The exhaustive list of
33 ;; properties is given in "The Communication Channel" section of
34 ;; this file.
36 ;; - The transcoder walks the parse tree, ignores or treat as plain
37 ;; text elements and objects according to export options, and
38 ;; eventually calls back-end specific functions to do the real
39 ;; transcoding, concatenating their return value along the way.
41 ;; - The filter system is activated at the very beginning and the very
42 ;; end of the export process, and each time an element or an object
43 ;; has been converted. It is the entry point to fine-tune standard
44 ;; output from back-end transcoders.
46 ;; The core function is `org-export-as'. It returns the transcoded
47 ;; buffer as a string.
49 ;; In order to derive an exporter out of this generic implementation,
50 ;; one can define a transcode function for each element or object.
51 ;; Such function should return a string for the corresponding element,
52 ;; without any trailing space, or nil. It must accept three
53 ;; arguments:
54 ;; 1. the element or object itself,
55 ;; 2. its contents, or nil when it isn't recursive,
56 ;; 3. the property list used as a communication channel.
58 ;; If no such function is found, that element or object type will
59 ;; simply be ignored, along with any separating blank line. The same
60 ;; will happen if the function returns the nil value. If that
61 ;; function returns the empty string, the type will be ignored, but
62 ;; the blank lines will be kept.
64 ;; Contents, when not nil, are stripped from any global indentation
65 ;; (although the relative one is preserved). They also always end
66 ;; with a single newline character.
68 ;; These functions must follow a strict naming convention:
69 ;; `org-BACKEND-TYPE' where, obviously, BACKEND is the name of the
70 ;; export back-end and TYPE the type of the element or object handled.
72 ;; Moreover, two additional functions can be defined. On the one
73 ;; hand, `org-BACKEND-template' returns the final transcoded string,
74 ;; and can be used to add a preamble and a postamble to document's
75 ;; body. It must accept two arguments: the transcoded string and the
76 ;; property list containing export options. On the other hand,
77 ;; `org-BACKEND-plain-text', when defined, is to be called on every
78 ;; text not recognized as an element or an object. It must accept two
79 ;; arguments: the text string and the information channel.
81 ;; Any back-end can define its own variables. Among them, those
82 ;; customizables should belong to the `org-export-BACKEND' group.
83 ;; Also, a special variable, `org-BACKEND-option-alist', allows to
84 ;; define buffer keywords and "#+options:" items specific to that
85 ;; back-end. See `org-export-option-alist' for supported defaults and
86 ;; syntax.
88 ;; Tools for common tasks across back-ends are implemented in the
89 ;; penultimate part of this file. A dispatcher for standard back-ends
90 ;; is provided in the last one.
92 ;;; Code:
93 (eval-when-compile (require 'cl))
94 (require 'org-element)
95 ;; Require major back-ends
96 (require 'org-e-ascii "../../EXPERIMENTAL/org-e-ascii.el")
97 (require 'org-e-latex "../../EXPERIMENTAL/org-e-latex.el")
100 ;;; Internal Variables
102 ;; Among internal variables, the most important is
103 ;; `org-export-option-alist'. This variable define the global export
104 ;; options, shared between every exporter, and how they are acquired.
106 (defconst org-export-max-depth 19
107 "Maximum nesting depth for headlines, counting from 0.")
109 (defconst org-export-option-alist
110 '((:author "AUTHOR" nil user-full-name t)
111 (:creator "CREATOR" nil org-export-creator-string)
112 (:date "DATE" nil nil t)
113 (:description "DESCRIPTION" nil nil newline)
114 (:email "EMAIL" nil user-mail-address t)
115 (:exclude-tags "EXPORT_EXCLUDE_TAGS" nil org-export-exclude-tags split)
116 (:filter-babel-call nil nil org-export-filter-babel-call-functions)
117 (:filter-center-block nil nil org-export-filter-center-block-functions)
118 (:filter-comment nil nil org-export-filter-comment-functions)
119 (:filter-comment-block nil nil org-export-filter-comment-block-functions)
120 (:filter-drawer nil nil org-export-filter-drawer-functions)
121 (:filter-dynamic-block nil nil org-export-filter-dynamic-block-functions)
122 (:filter-emphasis nil nil org-export-filter-emphasis-functions)
123 (:filter-entity nil nil org-export-filter-entity-functions)
124 (:filter-example-block nil nil org-export-filter-example-block-functions)
125 (:filter-export-block nil nil org-export-filter-export-block-functions)
126 (:filter-export-snippet nil nil org-export-filter-export-snippet-functions)
127 (:filter-final-output nil nil org-export-filter-final-output-functions)
128 (:filter-fixed-width nil nil org-export-filter-fixed-width-functions)
129 (:filter-footnote-definition nil nil org-export-filter-footnote-definition-functions)
130 (:filter-footnote-reference nil nil org-export-filter-footnote-reference-functions)
131 (:filter-headline nil nil org-export-filter-headline-functions)
132 (:filter-horizontal-rule nil nil org-export-filter-horizontal-rule-functions)
133 (:filter-inline-babel-call nil nil org-export-filter-inline-babel-call-functions)
134 (:filter-inline-src-block nil nil org-export-filter-inline-src-block-functions)
135 (:filter-inlinetask nil nil org-export-filter-inlinetask-functions)
136 (:filter-item nil nil org-export-filter-item-functions)
137 (:filter-keyword nil nil org-export-filter-keyword-functions)
138 (:filter-latex-environment nil nil org-export-filter-latex-environment-functions)
139 (:filter-latex-fragment nil nil org-export-filter-latex-fragment-functions)
140 (:filter-line-break nil nil org-export-filter-line-break-functions)
141 (:filter-link nil nil org-export-filter-link-functions)
142 (:filter-macro nil nil org-export-filter-macro-functions)
143 (:filter-paragraph nil nil org-export-filter-paragraph-functions)
144 (:filter-parse-tree nil nil org-export-filter-parse-tree-functions)
145 (:filter-plain-list nil nil org-export-filter-plain-list-functions)
146 (:filter-plain-text nil nil org-export-filter-plain-text-functions)
147 (:filter-property-drawer nil nil org-export-filter-property-drawer-functions)
148 (:filter-quote-block nil nil org-export-filter-quote-block-functions)
149 (:filter-quote-section nil nil org-export-filter-quote-section-functions)
150 (:filter-radio-target nil nil org-export-filter-radio-target-functions)
151 (:filter-section nil nil org-export-filter-section-functions)
152 (:filter-special-block nil nil org-export-filter-special-block-functions)
153 (:filter-src-block nil nil org-export-filter-src-block-functions)
154 (:filter-statistics-cookie nil nil org-export-filter-statistics-cookie-functions)
155 (:filter-subscript nil nil org-export-filter-subscript-functions)
156 (:filter-superscript nil nil org-export-filter-superscript-functions)
157 (:filter-table nil nil org-export-filter-table-functions)
158 (:filter-target nil nil org-export-filter-target-functions)
159 (:filter-time-stamp nil nil org-export-filter-time-stamp-functions)
160 (:filter-verbatim nil nil org-export-filter-verbatim-functions)
161 (:filter-verse-block nil nil org-export-filter-verse-block-functions)
162 (:headline-levels nil "H" org-export-headline-levels)
163 (:keywords "KEYWORDS" nil nil space)
164 (:language "LANGUAGE" nil org-export-default-language t)
165 (:preserve-breaks nil "\\n" org-export-preserve-breaks)
166 (:section-numbers nil "num" org-export-with-section-numbers)
167 (:select-tags "EXPORT_SELECT_TAGS" nil org-export-select-tags split)
168 (:time-stamp-file nil "timestamp" org-export-time-stamp-file)
169 (:title "TITLE" nil nil space)
170 (:with-archived-trees nil "arch" org-export-with-archived-trees)
171 (:with-author nil "author" org-export-with-author)
172 (:with-creator nil "creator" org-export-with-creator)
173 (:with-drawers nil "d" org-export-with-drawers)
174 (:with-email nil "email" org-export-with-email)
175 (:with-emphasize nil "*" org-export-with-emphasize)
176 (:with-entities nil "e" org-export-with-entities)
177 (:with-fixed-width nil ":" org-export-with-fixed-width)
178 (:with-footnotes nil "f" org-export-with-footnotes)
179 (:with-priority nil "pri" org-export-with-priority)
180 (:with-special-strings nil "-" org-export-with-special-strings)
181 (:with-sub-superscript nil "^" org-export-with-sub-superscripts)
182 (:with-toc nil "toc" org-export-with-toc)
183 (:with-tables nil "|" org-export-with-tables)
184 (:with-tags nil "tags" org-export-with-tags)
185 (:with-tasks nil "tasks" org-export-with-tasks)
186 (:with-timestamps nil "<" org-export-with-timestamps)
187 (:with-todo-keywords nil "todo" org-export-with-todo-keywords))
188 "Alist between export properties and ways to set them.
190 The car of the alist is the property name, and the cdr is a list
191 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
193 KEYWORD is a string representing a buffer keyword, or nil.
194 OPTION is a string that could be found in an #+OPTIONS: line.
195 DEFAULT is the default value for the property.
196 BEHAVIOUR determine how Org should handle multiple keywords for
197 the same property. It is a symbol among:
198 nil Keep old value and discard the new one.
199 t Replace old value with the new one.
200 `space' Concatenate the values, separating them with a space.
201 `newline' Concatenate the values, separating them with
202 a newline.
203 `split' Split values at white spaces, and cons them to the
204 previous list.
206 KEYWORD and OPTION have precedence over DEFAULT.
208 All these properties should be back-end agnostic. For back-end
209 specific properties, define a similar variable named
210 `org-BACKEND-option-alist', replacing BACKEND with the name of
211 the appropriate back-end. You can also redefine properties
212 there, as they have precedence over these.")
214 (defconst org-export-special-keywords
215 '("SETUP_FILE" "OPTIONS" "MACRO")
216 "List of in-buffer keywords that require special treatment.
217 These keywords are not directly associated to a property. The
218 way they are handled must be hard-coded into
219 `org-export-get-inbuffer-options' function.")
223 ;;; User-configurable Variables
225 ;; Configuration for the masses.
227 ;; They should never be evaled directly, as their value is to be
228 ;; stored in a property list (cf. `org-export-option-alist').
230 (defgroup org-export nil
231 "Options for exporting Org mode files."
232 :tag "Org Export"
233 :group 'org)
235 (defgroup org-export-general nil
236 "General options for export engine."
237 :tag "Org Export General"
238 :group 'org-export)
240 (defcustom org-export-with-archived-trees 'headline
241 "Whether sub-trees with the ARCHIVE tag should be exported.
243 This can have three different values:
244 nil Do not export, pretend this tree is not present.
245 t Do export the entire tree.
246 `headline' Only export the headline, but skip the tree below it.
248 This option can also be set with the #+OPTIONS line,
249 e.g. \"arch:nil\"."
250 :group 'org-export-general
251 :type '(choice
252 (const :tag "Not at all" nil)
253 (const :tag "Headline only" 'headline)
254 (const :tag "Entirely" t)))
256 (defcustom org-export-with-author t
257 "Non-nil means insert author name into the exported file.
258 This option can also be set with the #+OPTIONS line,
259 e.g. \"author:nil\"."
260 :group 'org-export-general
261 :type 'boolean)
263 (defcustom org-export-with-creator 'comment
264 "Non-nil means the postamble should contain a creator sentence.
266 The sentence can be set in `org-export-creator-string' and
267 defaults to \"Generated by Org mode XX in Emacs XXX.\".
269 If the value is `comment' insert it as a comment."
270 :group 'org-export-general
271 :type '(choice
272 (const :tag "No creator sentence" nil)
273 (const :tag "Sentence as a comment" 'comment)
274 (const :tag "Insert the sentence" t)))
276 (defcustom org-export-creator-string
277 (format "Generated by Org mode %s in Emacs %s." org-version emacs-version)
278 "String to insert at the end of the generated document."
279 :group 'org-export-general
280 :type '(string :tag "Creator string"))
282 (defcustom org-export-with-drawers t
283 "Non-nil means export contents of standard drawers.
285 When t, all drawers are exported. This may also be a list of
286 drawer names to export. This variable doesn't apply to
287 properties drawers.
289 This option can also be set with the #+OPTIONS line,
290 e.g. \"d:nil\"."
291 :group 'org-export-general
292 :type '(choice
293 (const :tag "All drawers" t)
294 (const :tag "None" nil)
295 (repeat :tag "Selected drawers"
296 (string :tag "Drawer name"))))
298 (defcustom org-export-with-email nil
299 "Non-nil means insert author email into the exported file.
300 This option can also be set with the #+OPTIONS line,
301 e.g. \"email:t\"."
302 :group 'org-export-general
303 :type 'boolean)
305 (defcustom org-export-with-emphasize t
306 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
308 If the export target supports emphasizing text, the word will be
309 typeset in bold, italic, or underlined, respectively. Not all
310 export backends support this.
312 This option can also be set with the #+OPTIONS line, e.g. \"*:nil\"."
313 :group 'org-export-general
314 :type 'boolean)
316 (defcustom org-export-exclude-tags '("noexport")
317 "Tags that exclude a tree from export.
318 All trees carrying any of these tags will be excluded from
319 export. This is without condition, so even subtrees inside that
320 carry one of the `org-export-select-tags' will be removed."
321 :group 'org-export-general
322 :type '(repeat (string :tag "Tag")))
324 (defcustom org-export-with-fixed-width t
325 "Non-nil means lines starting with \":\" will be in fixed width font.
327 This can be used to have pre-formatted text, fragments of code
328 etc. For example:
329 : ;; Some Lisp examples
330 : (while (defc cnt)
331 : (ding))
332 will be looking just like this in also HTML. See also the QUOTE
333 keyword. Not all export backends support this.
335 This option can also be set with the #+OPTIONS line, e.g. \"::nil\"."
336 :group 'org-export-translation
337 :type 'boolean)
339 (defcustom org-export-with-footnotes t
340 "Non-nil means Org footnotes should be exported.
341 This option can also be set with the #+OPTIONS line,
342 e.g. \"f:nil\"."
343 :group 'org-export-general
344 :type 'boolean)
346 (defcustom org-export-headline-levels 3
347 "The last level which is still exported as a headline.
349 Inferior levels will produce itemize lists when exported. Note
350 that a numeric prefix argument to an exporter function overrides
351 this setting.
353 This option can also be set with the #+OPTIONS line, e.g. \"H:2\"."
354 :group 'org-export-general
355 :type 'integer)
357 (defcustom org-export-default-language "en"
358 "The default language for export and clocktable translations, as a string.
359 This may have an association in
360 `org-clock-clocktable-language-setup'."
361 :group 'org-export-general
362 :type '(string :tag "Language"))
364 (defcustom org-export-preserve-breaks nil
365 "Non-nil means preserve all line breaks when exporting.
367 Normally, in HTML output paragraphs will be reformatted.
369 This option can also be set with the #+OPTIONS line,
370 e.g. \"\\n:t\"."
371 :group 'org-export-general
372 :type 'boolean)
374 (defcustom org-export-with-entities t
375 "Non-nil means interpret entities when exporting.
377 For example, HTML export converts \\alpha to &alpha; and \\AA to
378 &Aring;.
380 For a list of supported names, see the constant `org-entities'
381 and the user option `org-entities-user'.
383 This option can also be set with the #+OPTIONS line,
384 e.g. \"e:nil\"."
385 :group 'org-export-general
386 :type 'boolean)
388 (defcustom org-export-with-priority nil
389 "Non-nil means include priority cookies in export.
390 When nil, remove priority cookies for export."
391 :group 'org-export-general
392 :type 'boolean)
394 (defcustom org-export-with-section-numbers t
395 "Non-nil means add section numbers to headlines when exporting.
397 When set to an integer n, numbering will only happen for
398 headlines whose relative level is higher or equal to n.
400 This option can also be set with the #+OPTIONS line,
401 e.g. \"num:t\"."
402 :group 'org-export-general
403 :type 'boolean)
405 (defcustom org-export-select-tags '("export")
406 "Tags that select a tree for export.
407 If any such tag is found in a buffer, all trees that do not carry
408 one of these tags will be deleted before export. Inside trees
409 that are selected like this, you can still deselect a subtree by
410 tagging it with one of the `org-export-exclude-tags'."
411 :group 'org-export-general
412 :type '(repeat (string :tag "Tag")))
414 (defcustom org-export-with-special-strings t
415 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
417 When this option is turned on, these strings will be exported as:
419 Org HTML LaTeX
420 -----+----------+--------
421 \\- &shy; \\-
422 -- &ndash; --
423 --- &mdash; ---
424 ... &hellip; \ldots
426 This option can also be set with the #+OPTIONS line,
427 e.g. \"-:nil\"."
428 :group 'org-export-general
429 :type 'boolean)
431 (defcustom org-export-with-sub-superscripts t
432 "Non-nil means interpret \"_\" and \"^\" for export.
434 When this option is turned on, you can use TeX-like syntax for
435 sub- and superscripts. Several characters after \"_\" or \"^\"
436 will be considered as a single item - so grouping with {} is
437 normally not needed. For example, the following things will be
438 parsed as single sub- or superscripts.
440 10^24 or 10^tau several digits will be considered 1 item.
441 10^-12 or 10^-tau a leading sign with digits or a word
442 x^2-y^3 will be read as x^2 - y^3, because items are
443 terminated by almost any nonword/nondigit char.
444 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
446 Still, ambiguity is possible - so when in doubt use {} to enclose
447 the sub/superscript. If you set this variable to the symbol
448 `{}', the braces are *required* in order to trigger
449 interpretations as sub/superscript. This can be helpful in
450 documents that need \"_\" frequently in plain text.
452 This option can also be set with the #+OPTIONS line,
453 e.g. \"^:nil\"."
454 :group 'org-export-general
455 :type '(choice
456 (const :tag "Interpret them" t)
457 (const :tag "Curly brackets only" {})
458 (const :tag "Do not interpret them" nil)))
460 (defcustom org-export-with-toc t
461 "Non-nil means create a table of contents in exported files.
463 The TOC contains headlines with levels up
464 to`org-export-headline-levels'. When an integer, include levels
465 up to N in the toc, this may then be different from
466 `org-export-headline-levels', but it will not be allowed to be
467 larger than the number of headline levels. When nil, no table of
468 contents is made.
470 This option can also be set with the #+OPTIONS line,
471 e.g. \"toc:nil\" or \"toc:3\"."
472 :group 'org-export-general
473 :type '(choice
474 (const :tag "No Table of Contents" nil)
475 (const :tag "Full Table of Contents" t)
476 (integer :tag "TOC to level")))
478 (defcustom org-export-with-tables t
479 "If non-nil, lines starting with \"|\" define a table.
480 For example:
482 | Name | Address | Birthday |
483 |-------------+----------+-----------|
484 | Arthur Dent | England | 29.2.2100 |
486 This option can also be set with the #+OPTIONS line, e.g. \"|:nil\"."
487 :group 'org-export-general
488 :type 'boolean)
490 (defcustom org-export-with-tags t
491 "If nil, do not export tags, just remove them from headlines.
493 If this is the symbol `not-in-toc', tags will be removed from
494 table of contents entries, but still be shown in the headlines of
495 the document.
497 This option can also be set with the #+OPTIONS line,
498 e.g. \"tags:nil\"."
499 :group 'org-export-general
500 :type '(choice
501 (const :tag "Off" nil)
502 (const :tag "Not in TOC" not-in-toc)
503 (const :tag "On" t)))
505 (defcustom org-export-with-tasks t
506 "Non-nil means include TODO items for export.
507 This may have the following values:
508 t include tasks independent of state.
509 todo include only tasks that are not yet done.
510 done include only tasks that are already done.
511 nil remove all tasks before export
512 list of keywords keep only tasks with these keywords"
513 :group 'org-export-general
514 :type '(choice
515 (const :tag "All tasks" t)
516 (const :tag "No tasks" nil)
517 (const :tag "Not-done tasks" todo)
518 (const :tag "Only done tasks" done)
519 (repeat :tag "Specific TODO keywords"
520 (string :tag "Keyword"))))
522 (defcustom org-export-time-stamp-file t
523 "Non-nil means insert a time stamp into the exported file.
524 The time stamp shows when the file was created.
526 This option can also be set with the #+OPTIONS line,
527 e.g. \"timestamp:nil\"."
528 :group 'org-export-general
529 :type 'boolean)
531 (defcustom org-export-with-timestamps t
532 "If nil, do not export time stamps and associated keywords."
533 :group 'org-export-general
534 :type 'boolean)
536 (defcustom org-export-with-todo-keywords t
537 "Non-nil means include TODO keywords in export.
538 When nil, remove all these keywords from the export.")
540 (defcustom org-export-allow-BIND 'confirm
541 "Non-nil means allow #+BIND to define local variable values for export.
542 This is a potential security risk, which is why the user must
543 confirm the use of these lines."
544 :group 'org-export-general
545 :type '(choice
546 (const :tag "Never" nil)
547 (const :tag "Always" t)
548 (const :tag "Ask a confirmation for each file" confirm)))
550 (defcustom org-export-snippet-translation-alist nil
551 "Alist between export snippets back-ends and exporter back-ends.
553 This variable allows to provide shortcuts for export snippets.
555 For example, with a value of '\(\(\"h\" . \"html\"\)\), the HTML
556 back-end will recognize the contents of \"@h{<b>}\" as HTML code
557 while every other back-end will ignore it."
558 :group 'org-export-general
559 :type '(repeat
560 (cons
561 (string :tag "Shortcut")
562 (string :tag "Back-end"))))
564 (defcustom org-export-coding-system nil
565 "Coding system for the exported file."
566 :group 'org-export-general
567 :type 'coding-system)
569 (defcustom org-export-copy-to-kill-ring t
570 "Non-nil means exported stuff will also be pushed onto the kill ring."
571 :group 'org-export-general
572 :type 'boolean)
574 (defcustom org-export-initial-scope 'buffer
575 "The initial scope when exporting with `org-export-dispatch'.
576 This variable can be either set to `buffer' or `subtree'."
577 :group 'org-export-general
578 :type '(choice
579 (const :tag "Export current buffer" 'buffer)
580 (const :tag "Export current subtree" 'subtree)))
582 (defcustom org-export-show-temporary-export-buffer t
583 "Non-nil means show buffer after exporting to temp buffer.
584 When Org exports to a file, the buffer visiting that file is ever
585 shown, but remains buried. However, when exporting to a temporary
586 buffer, that buffer is popped up in a second window. When this variable
587 is nil, the buffer remains buried also in these cases."
588 :group 'org-export-general
589 :type 'boolean)
591 (defcustom org-export-dispatch-use-expert-ui nil
592 "Non-nil means using a non-intrusive `org-export-dispatch'.
593 In that case, no help buffer is displayed. Though, an indicator
594 for current export scope is added to the prompt \(i.e. \"b\" when
595 output is restricted to body only, \"s\" when it is restricted to
596 the current subtree and \"v\" when only visible elements are
597 considered for export\). Also, \[?] allows to switch back to
598 standard mode."
599 :group 'org-export-general
600 :type 'boolean)
604 ;;; The Communication Channel
606 ;; During export process, every function has access to a number of
607 ;; properties. They are of three types:
609 ;; 1. Export options are collected once at the very beginning of the
610 ;; process, out of the original buffer and environment. The task
611 ;; is handled by `org-export-collect-options' function.
613 ;; All export options are defined through the
614 ;; `org-export-option-alist' variable.
616 ;; 2. Tree properties are extracted directly from the parsed tree, by
617 ;; `org-export-collect-tree-properties' and depend on export
618 ;; options (whole trees may be filtered out of the export process).
620 ;; 3. Local options are updated during parsing, and their value
621 ;; depends on the level of recursion. For now, only `:genealogy'
622 ;; belongs to that category.
624 ;; Here is the full list of properties available during transcode
625 ;; process, with their category (option, tree or local), their
626 ;; value type and the function updating them, when appropriate.
628 ;; + `author' :: Author's name.
629 ;; - category :: option
630 ;; - type :: string
632 ;; + `back-end' :: Current back-end used for transcoding.
633 ;; - category :: tree
634 ;; - type :: symbol
636 ;; + `creator' :: String to write as creation information.
637 ;; - category :: option
638 ;; - type :: string
640 ;; + `date' :: String to use as date.
641 ;; - category :: option
642 ;; - type :: string
644 ;; + `description' :: Description text for the current data.
645 ;; - category :: option
646 ;; - type :: string
648 ;; + `email' :: Author's email.
649 ;; - category :: option
650 ;; - type :: string
652 ;; + `exclude-tags' :: Tags for exclusion of subtrees from export
653 ;; process.
654 ;; - category :: option
655 ;; - type :: list of strings
657 ;; + `footnote-definition-alist' :: Alist between footnote labels and
658 ;; their definition, as parsed data. Only non-inlined footnotes
659 ;; are represented in this alist. Also, every definition isn't
660 ;; guaranteed to be referenced in the parse tree. The purpose of
661 ;; this property is to preserve definitions from oblivion
662 ;; (i.e. when the parse tree comes from a part of the original
663 ;; buffer), it isn't meant for direct use in a back-end. To
664 ;; retrieve a definition relative to a reference, use
665 ;; `org-export-get-footnote-definition' instead.
666 ;; - category :: option
667 ;; - type :: alist (STRING . LIST)
669 ;; + `genealogy' :: Flat list of current object or element's parents
670 ;; from closest to farthest.
671 ;; - category :: local
672 ;; - type :: list of elements and objects
674 ;; + `headline-levels' :: Maximum level being exported as an
675 ;; headline. Comparison is done with the relative level of
676 ;; headlines in the parse tree, not necessarily with their
677 ;; actual level.
678 ;; - category :: option
679 ;; - type :: integer
681 ;; + `headline-offset' :: Difference between relative and real level
682 ;; of headlines in the parse tree. For example, a value of -1
683 ;; means a level 2 headline should be considered as level
684 ;; 1 (cf. `org-export-get-relative-level').
685 ;; - category :: tree
686 ;; - type :: integer
688 ;; + `headline-numbering' :: Alist between headlines' beginning
689 ;; position and their numbering, as a list of numbers
690 ;; (cf. `org-export-get-headline-number').
691 ;; - category :: tree
692 ;; - type :: alist (INTEGER . LIST)
694 ;; + `included-files' :: List of files, with full path, included in
695 ;; the current buffer, through the "#+include:" keyword. It is
696 ;; mainly used to verify that no infinite recursive inclusion
697 ;; happens.
698 ;; - category :: local
699 ;; - type :: list of strings
701 ;; + `keywords' :: List of keywords attached to data.
702 ;; - category :: option
703 ;; - type :: string
705 ;; + `language' :: Default language used for translations.
706 ;; - category :: option
707 ;; - type :: string
709 ;; + `parse-tree' :: Whole parse tree, available at any time during
710 ;; transcoding.
711 ;; - category :: global
712 ;; - type :: list (as returned by `org-element-parse-buffer')
714 ;; + `preserve-breaks' :: Non-nil means transcoding should preserve
715 ;; all line breaks.
716 ;; - category :: option
717 ;; - type :: symbol (nil, t)
719 ;; + `section-numbers' :: Non-nil means transcoding should add
720 ;; section numbers to headlines.
721 ;; - category :: option
722 ;; - type :: symbol (nil, t)
724 ;; + `select-tags' :: List of tags enforcing inclusion of sub-trees in
725 ;; transcoding. When such a tag is present,
726 ;; subtrees without it are de facto excluded from
727 ;; the process. See `use-select-tags'.
728 ;; - category :: option
729 ;; - type :: list of strings
731 ;; + `target-list' :: List of targets encountered in the parse tree.
732 ;; This is used to partly resolve "fuzzy" links
733 ;; (cf. `org-export-resolve-fuzzy-link').
734 ;; - category :: tree
735 ;; - type :: list of strings
737 ;; + `time-stamp-file' :: Non-nil means transcoding should insert
738 ;; a time stamp in the output.
739 ;; - category :: option
740 ;; - type :: symbol (nil, t)
742 ;; + `use-select-tags' :: When non-nil, a select tags has been found
743 ;; in the parse tree. Thus, any headline without one will be
744 ;; filtered out. See `select-tags'.
745 ;; - category :: tree
746 ;; - type :: interger or nil
748 ;; + `with-archived-trees' :: Non-nil when archived subtrees should
749 ;; also be transcoded. If it is set to the `headline' symbol,
750 ;; only the archived headline's name is retained.
751 ;; - category :: option
752 ;; - type :: symbol (nil, t, `headline')
754 ;; + `with-author' :: Non-nil means author's name should be included
755 ;; in the output.
756 ;; - category :: option
757 ;; - type :: symbol (nil, t)
759 ;; + `with-creator' :: Non-nild means a creation sentence should be
760 ;; inserted at the end of the transcoded string. If the value
761 ;; is `comment', it should be commented.
762 ;; - category :: option
763 ;; - type :: symbol (`comment', nil, t)
765 ;; + `with-drawers' :: Non-nil means drawers should be exported. If
766 ;; its value is a list of names, only drawers with such names
767 ;; will be transcoded.
768 ;; - category :: option
769 ;; - type :: symbol (nil, t) or list of strings
771 ;; + `with-email' :: Non-nil means output should contain author's
772 ;; email.
773 ;; - category :: option
774 ;; - type :: symbol (nil, t)
776 ;; + `with-emphasize' :: Non-nil means emphasized text should be
777 ;; interpreted.
778 ;; - category :: option
779 ;; - type :: symbol (nil, t)
781 ;; + `with-fixed-width' :: Non-nil if transcoder should interpret
782 ;; strings starting with a colon as a fixed-with (verbatim)
783 ;; area.
784 ;; - category :: option
785 ;; - type :: symbol (nil, t)
787 ;; + `with-footnotes' :: Non-nil if transcoder should interpret
788 ;; footnotes.
789 ;; - category :: option
790 ;; - type :: symbol (nil, t)
792 ;; + `with-priority' :: Non-nil means transcoding should include
793 ;; priority cookies.
794 ;; - category :: option
795 ;; - type :: symbol (nil, t)
797 ;; + `with-special-strings' :: Non-nil means transcoding should
798 ;; interpret special strings in plain text.
799 ;; - category :: option
800 ;; - type :: symbol (nil, t)
802 ;; + `with-sub-superscript' :: Non-nil means transcoding should
803 ;; interpret subscript and superscript. With a value of "{}",
804 ;; only interpret those using curly brackets.
805 ;; - category :: option
806 ;; - type :: symbol (nil, {}, t)
808 ;; + `with-tables' :: Non-nil means transcoding should interpret
809 ;; tables.
810 ;; - category :: option
811 ;; - type :: symbol (nil, t)
813 ;; + `with-tags' :: Non-nil means transcoding should keep tags in
814 ;; headlines. A `not-in-toc' value will remove them
815 ;; from the table of contents, if any, nonetheless.
816 ;; - category :: option
817 ;; - type :: symbol (nil, t, `not-in-toc')
819 ;; + `with-tasks' :: Non-nil means transcoding should include
820 ;; headlines with a TODO keyword. A `todo' value
821 ;; will only include headlines with a todo type
822 ;; keyword while a `done' value will do the
823 ;; contrary. If a list of strings is provided, only
824 ;; tasks with keywords belonging to that list will
825 ;; be kept.
826 ;; - category :: option
827 ;; - type :: symbol (t, todo, done, nil) or list of strings
829 ;; + `with-timestamps' :: Non-nil means transcoding should include
830 ;; time stamps and associated keywords. Otherwise, completely
831 ;; remove them.
832 ;; - category :: option
833 ;; - type :: symbol: (t, nil)
835 ;; + `with-toc' :: Non-nil means that a table of contents has to be
836 ;; added to the output. An integer value limits its
837 ;; depth.
838 ;; - category :: option
839 ;; - type :: symbol (nil, t or integer)
841 ;; + `with-todo-keywords' :: Non-nil means transcoding should
842 ;; include TODO keywords.
843 ;; - category :: option
844 ;; - type :: symbol (nil, t)
846 ;;;; Export Options
848 ;; Export options come from five sources, in increasing precedence
849 ;; order:
851 ;; - Global variables,
852 ;; - External options provided at export time,
853 ;; - Options keyword symbols,
854 ;; - Buffer keywords,
855 ;; - Subtree properties.
857 ;; The central internal function with regards to export options is
858 ;; `org-export-collect-options'. It updates global variables with
859 ;; "#+BIND:" keywords, then retrieve and prioritize properties from
860 ;; the different sources.
862 ;; The internal functions doing the retrieval are:
863 ;; `org-export-parse-option-keyword' ,
864 ;; `org-export-get-subtree-options' ,
865 ;; `org-export-get-inbuffer-options' and
866 ;; `org-export-get-global-options'.
868 ;; Some properties do not rely on the previous sources but still
869 ;; depend on the original buffer are taken care of in
870 ;; `org-export-initial-options'.
872 ;; Also, `org-export-confirm-letbind' and `org-export-install-letbind'
873 ;; take care of the part relative to "#+BIND:" keywords.
875 (defun org-export-collect-options (backend subtreep ext-plist)
876 "Collect export options from the current buffer.
878 BACKEND is a symbol specifying the back-end to use.
880 When SUBTREEP is non-nil, assume the export is done against the
881 current sub-tree.
883 EXT-PLIST is a property list with external parameters overriding
884 org-mode's default settings, but still inferior to file-local
885 settings."
886 ;; First install #+BIND variables.
887 (org-export-install-letbind-maybe)
888 ;; Get and prioritize export options...
889 (let ((options (org-combine-plists
890 ;; ... from global variables...
891 (org-export-get-global-options backend)
892 ;; ... from buffer's name (default title)...
893 `(:title
894 ,(or (let ((file (buffer-file-name (buffer-base-buffer))))
895 (and file
896 (file-name-sans-extension
897 (file-name-nondirectory file))))
898 (buffer-name (buffer-base-buffer))))
899 ;; ... from an external property list...
900 ext-plist
901 ;; ... from in-buffer settings...
902 (org-export-get-inbuffer-options
903 (org-with-wide-buffer (buffer-string)) backend
904 (and buffer-file-name
905 (org-remove-double-quotes buffer-file-name)))
906 ;; ... and from subtree, when appropriate.
907 (and subtreep
908 (org-export-get-subtree-options)))))
909 ;; Add initial options.
910 (setq options (append (org-export-initial-options options) options))
911 ;; Return plist.
912 options))
914 (defun org-export-parse-option-keyword (options backend)
915 "Parse an OPTIONS line and return values as a plist.
916 BACKEND is a symbol specifying the back-end to use."
917 (let* ((all (append org-export-option-alist
918 (let ((var (intern
919 (format "org-%s-option-alist" backend))))
920 (and (boundp var) (eval var)))))
921 ;; Build an alist between #+OPTION: item and property-name.
922 (alist (delq nil
923 (mapcar (lambda (e)
924 (when (nth 2 e) (cons (regexp-quote (nth 2 e))
925 (car e))))
926 all)))
927 plist)
928 (mapc (lambda (e)
929 (when (string-match (concat "\\(\\`\\|[ \t]\\)"
930 (car e)
931 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
932 options)
933 (setq plist (plist-put plist
934 (cdr e)
935 (car (read-from-string
936 (match-string 2 options)))))))
937 alist)
938 plist))
940 (defun org-export-get-subtree-options ()
941 "Get export options in subtree at point.
943 Assume point is at subtree's beginning.
945 Return options as a plist."
946 (let (prop plist)
947 (when (setq prop (progn (looking-at org-todo-line-regexp)
948 (or (save-match-data
949 (org-entry-get (point) "EXPORT_TITLE"))
950 (org-match-string-no-properties 3))))
951 (setq plist
952 (plist-put
953 plist :title
954 (org-element-parse-secondary-string
955 prop
956 (cdr (assq 'keyword org-element-string-restrictions))))))
957 (when (setq prop (org-entry-get (point) "EXPORT_TEXT"))
958 (setq plist (plist-put plist :text prop)))
959 (when (setq prop (org-entry-get (point) "EXPORT_AUTHOR"))
960 (setq plist (plist-put plist :author prop)))
961 (when (setq prop (org-entry-get (point) "EXPORT_DATE"))
962 (setq plist (plist-put plist :date prop)))
963 (when (setq prop (org-entry-get (point) "EXPORT_OPTIONS"))
964 (setq plist (org-export-add-options-to-plist plist prop)))
965 plist))
967 (defun org-export-get-inbuffer-options (buffer-string backend files)
968 "Return in-buffer options as a plist.
969 BUFFER-STRING is the string of the buffer. BACKEND is a symbol
970 specifying which back-end should be used. FILES is a list of
971 setup files names read so far, used to avoid circular
972 dependencies."
973 (let ((case-fold-search t) plist)
974 ;; 1. Special keywords, as in `org-export-special-keywords'.
975 (let ((start 0)
976 (special-re (org-make-options-regexp org-export-special-keywords)))
977 (while (string-match special-re buffer-string start)
978 (setq start (match-end 0))
979 (let ((key (upcase (org-match-string-no-properties 1 buffer-string)))
980 ;; Special keywords do not have their value expanded.
981 (val (org-match-string-no-properties 2 buffer-string)))
982 (setq plist
983 (org-combine-plists
984 (cond
985 ((string= key "SETUP_FILE")
986 (let ((file (expand-file-name
987 (org-remove-double-quotes (org-trim val)))))
988 ;; Avoid circular dependencies.
989 (unless (member file files)
990 (org-export-get-inbuffer-options
991 (org-file-contents file 'noerror)
992 backend
993 (cons file files)))))
994 ((string= key "OPTIONS")
995 (org-export-parse-option-keyword val backend))
996 ((string= key "MACRO")
997 (when (string-match
998 "^\\([-a-zA-Z0-9_]+\\)\\(?:[ \t]+\\(.*?\\)[ \t]*$\\)?"
999 val)
1000 (let ((key (intern
1001 (concat ":macro-"
1002 (downcase (match-string 1 val)))))
1003 (value (match-string 2 val)))
1004 (cond
1005 ((not value) "")
1006 ((string-match "\\`(eval\\>" value) (list key value))
1008 (list
1010 ;; If user explicitly asks for a newline, be
1011 ;; sure to preserve it from further filling
1012 ;; with `hard-newline'.
1013 (replace-regexp-in-string
1014 "\\\\n" hard-newline value))))))))
1015 plist)))))
1016 ;; 2. Standard options, as in `org-export-option-alist'.
1017 (let* ((all (append org-export-option-alist
1018 (let ((var (intern
1019 (format "org-%s-option-alist" backend))))
1020 (and (boundp var) (eval var)))))
1021 ;; Build alist between keyword name and property name.
1022 (alist (delq nil (mapcar (lambda (e)
1023 (when (nth 1 e) (cons (nth 1 e) (car e))))
1024 all)))
1025 ;; Build regexp matching all keywords associated to export
1026 ;; options. Note: the search is case insensitive.
1027 (opt-re (org-make-options-regexp
1028 (delq nil (mapcar (lambda (e) (nth 1 e)) all))))
1029 (start 0))
1030 (while (string-match opt-re buffer-string start)
1031 (setq start (match-end 0))
1032 (let* ((key (upcase (org-match-string-no-properties 1 buffer-string)))
1033 ;; Expand value, applying restrictions for keywords.
1034 (val (org-match-string-no-properties 2 buffer-string))
1035 (prop (cdr (assoc key alist)))
1036 (behaviour (nth 4 (assq prop all))))
1037 (setq plist
1038 (plist-put
1039 plist prop
1040 ;; Handle value depending on specified BEHAVIOUR.
1041 (case behaviour
1042 (space (if (plist-get plist prop)
1043 (concat (plist-get plist prop) " " (org-trim val))
1044 (org-trim val)))
1045 (newline (org-trim
1046 (concat
1047 (plist-get plist prop) "\n" (org-trim val))))
1048 (split `(,@(plist-get plist prop) ,@(org-split-string val)))
1049 ('t val)
1050 (otherwise (plist-get plist prop)))))))
1051 ;; Parse keywords specified in `org-element-parsed-keywords'.
1052 (mapc
1053 (lambda (key)
1054 (let* ((prop (cdr (assoc (upcase key) alist)))
1055 (value (and prop (plist-get plist prop))))
1056 (when (stringp value)
1057 (setq plist
1058 (plist-put
1059 plist prop
1060 (org-element-parse-secondary-string
1061 value
1062 (cdr (assq 'keyword org-element-string-restrictions))))))))
1063 org-element-parsed-keywords))
1064 ;; Return final value.
1065 plist))
1067 (defun org-export-get-global-options (backend)
1068 "Return global export options as a plist.
1069 BACKEND is a symbol specifying which back-end should be used."
1070 (let ((all (append org-export-option-alist
1071 (let ((var (intern
1072 (format "org-%s-option-alist" backend))))
1073 (and (boundp var) (eval var)))))
1074 ;; Output value.
1075 plist)
1076 (mapc (lambda (cell)
1077 (setq plist
1078 (plist-put plist (car cell) (eval (nth 3 cell)))))
1079 all)
1080 ;; Return value.
1081 plist))
1083 (defun org-export-initial-options (options)
1084 "Return a plist with non-optional properties.
1085 OPTIONS is the export options plist computed so far."
1086 (list
1087 ;; `:macro-date', `:macro-time' and `:macro-property' could as well
1088 ;; be initialized as tree properties, since they don't depend on
1089 ;; initial environment. Though, it may be more logical to keep
1090 ;; them close to other ":macro-" properties.
1091 :macro-date "(eval (format-time-string \"$1\"))"
1092 :macro-time "(eval (format-time-string \"$1\"))"
1093 :macro-property "(eval (org-entry-get nil \"$1\" 'selective))"
1094 :macro-modification-time
1095 (and (buffer-file-name)
1096 (file-exists-p (buffer-file-name))
1097 (concat "(eval (format-time-string \"$1\" '"
1098 (prin1-to-string (nth 5 (file-attributes (buffer-file-name))))
1099 "))"))
1100 :macro-input-file (and (buffer-file-name)
1101 (file-name-nondirectory (buffer-file-name)))
1102 ;; Footnotes definitions must be collected in the original buffer,
1103 ;; as there's no insurance that they will still be in the parse
1104 ;; tree, due to some narrowing.
1105 :footnote-definition-alist
1106 (let (alist)
1107 (org-with-wide-buffer
1108 (goto-char (point-min))
1109 (while (re-search-forward org-footnote-definition-re nil t)
1110 (let ((def (org-footnote-at-definition-p)))
1111 (when def
1112 (org-skip-whitespace)
1113 (push (cons (car def)
1114 (save-restriction
1115 (narrow-to-region (point) (nth 2 def))
1116 ;; Like `org-element-parse-buffer', but
1117 ;; makes sure the definition doesn't start
1118 ;; with a section element.
1119 (nconc
1120 (list 'org-data nil)
1121 (org-element-parse-elements
1122 (point-min) (point-max) nil nil nil nil nil))))
1123 alist))))
1124 alist))))
1126 (defvar org-export-allow-BIND-local nil)
1127 (defun org-export-confirm-letbind ()
1128 "Can we use #+BIND values during export?
1129 By default this will ask for confirmation by the user, to divert
1130 possible security risks."
1131 (cond
1132 ((not org-export-allow-BIND) nil)
1133 ((eq org-export-allow-BIND t) t)
1134 ((local-variable-p 'org-export-allow-BIND-local) org-export-allow-BIND-local)
1135 (t (org-set-local 'org-export-allow-BIND-local
1136 (yes-or-no-p "Allow BIND values in this buffer? ")))))
1138 (defun org-export-install-letbind-maybe ()
1139 "Install the values from #+BIND lines as local variables.
1140 Variables must be installed before in-buffer options are
1141 retrieved."
1142 (let (letbind pair)
1143 (org-with-wide-buffer
1144 (goto-char (point-min))
1145 (while (re-search-forward (org-make-options-regexp '("BIND")) nil t)
1146 (when (org-export-confirm-letbind)
1147 (push (read (concat "(" (org-match-string-no-properties 2) ")"))
1148 letbind))))
1149 (while (setq pair (pop letbind))
1150 (org-set-local (car pair) (nth 1 pair)))))
1153 ;;;; Tree Properties
1155 ;; They are initialized at the beginning of the transcoding process by
1156 ;; `org-export-collect-tree-properties'.
1158 ;; Dedicated functions focus on computing the value of specific tree
1159 ;; properties during initialization. Thus,
1160 ;; `org-export-use-select-tag-p' determines if an headline makes use
1161 ;; of an export tag enforcing inclusion. `org-export-get-min-level'
1162 ;; gets the minimal exportable level, used as a basis to compute
1163 ;; relative level for headlines. `org-export-get-point-max' returns
1164 ;; the maximum exportable ending position in the parse tree.
1165 ;; Eventually `org-export-collect-headline-numbering' builds an alist
1166 ;; between headlines' beginning position and their numbering.
1168 (defun org-export-collect-tree-properties (data info backend)
1169 "Extract tree properties from parse tree.
1171 DATA is the parse tree from which information is retrieved. INFO
1172 is a list holding export options. BACKEND is the back-end called
1173 for transcoding, as a symbol.
1175 Following tree properties are set:
1176 `:back-end' Back-end used for transcoding.
1178 `:headline-offset' Offset between true level of headlines and
1179 local level. An offset of -1 means an headline
1180 of level 2 should be considered as a level
1181 1 headline in the context.
1183 `:headline-numbering' Alist of all headlines' beginning position
1184 as key an the associated numbering as value.
1186 `:parse-tree' Whole parse tree.
1188 `:target-list' List of all targets in the parse tree.
1190 `:use-select-tags' Non-nil when parsed tree use a special tag to
1191 enforce transcoding of the headline."
1192 ;; First, set `:use-select-tags' property, as it will be required
1193 ;; for further computations.
1194 (setq info
1195 (org-combine-plists
1196 info `(:use-select-tags ,(org-export-use-select-tags-p data info))))
1197 ;; Then get `:headline-offset' in order to be able to use
1198 ;; `org-export-get-relative-level'.
1199 (setq info
1200 (org-combine-plists
1201 info `(:headline-offset ,(- 1 (org-export-get-min-level data info)))))
1202 ;; Now, get the rest of the tree properties, now `:use-select-tags'
1203 ;; is set...
1204 (nconc
1205 `(:parse-tree
1206 ,data
1207 :target-list
1208 ,(org-element-map data 'target (lambda (target local) target) info)
1209 :headline-numbering ,(org-export-collect-headline-numbering data info)
1210 :back-end ,backend)
1211 info))
1213 (defun org-export-use-select-tags-p (data options)
1214 "Non-nil when data use a tag enforcing transcoding.
1215 DATA is parsed data as returned by `org-element-parse-buffer'.
1216 OPTIONS is a plist holding export options."
1217 (org-element-map
1218 data
1219 'headline
1220 (lambda (headline info)
1221 (let ((tags (org-element-get-property :with-tags headline)))
1222 (and tags (string-match
1223 (format ":%s:" (plist-get info :select-tags)) tags))))
1224 options
1225 'stop-at-first-match))
1227 (defun org-export-get-min-level (data options)
1228 "Return minimum exportable headline's level in DATA.
1229 DATA is parsed tree as returned by `org-element-parse-buffer'.
1230 OPTIONS is a plist holding export options."
1231 (catch 'exit
1232 (let ((min-level 10000))
1233 (mapc (lambda (blob)
1234 (when (and (eq (car blob) 'headline)
1235 (not (org-export-skip-p blob options)))
1236 (setq min-level
1237 (min (org-element-get-property :level blob) min-level)))
1238 (when (= min-level 1) (throw 'exit 1)))
1239 (org-element-get-contents data))
1240 ;; If no headline was found, for the sake of consistency, set
1241 ;; minimum level to 1 nonetheless.
1242 (if (= min-level 10000) 1 min-level))))
1244 (defun org-export-collect-headline-numbering (data options)
1245 "Return numbering of all exportable headlines in a parse tree.
1247 DATA is the parse tree. OPTIONS is the plist holding export
1248 options.
1250 Return an alist whose key is an headline and value is its
1251 associated numbering \(in the shape of a list of numbers\)."
1252 (let ((numbering (make-vector org-export-max-depth 0)))
1253 (org-element-map
1254 data
1255 'headline
1256 (lambda (headline info)
1257 (let ((relative-level
1258 (1- (org-export-get-relative-level headline info))))
1259 (cons
1260 headline
1261 (loop for n across numbering
1262 for idx from 0 to org-export-max-depth
1263 when (< idx relative-level) collect n
1264 when (= idx relative-level) collect (aset numbering idx (1+ n))
1265 when (> idx relative-level) do (aset numbering idx 0)))))
1266 options)))
1270 ;;; The Transcoder
1272 ;; This function reads Org data (obtained with, i.e.
1273 ;; `org-element-parse-buffer') and transcodes it into a specified
1274 ;; back-end output. It takes care of updating local properties,
1275 ;; filtering out elements or objects according to export options and
1276 ;; organizing the output blank lines and white space are preserved.
1278 ;; Though, this function is inapropriate for secondary strings, which
1279 ;; require a fresh copy of the plist passed as INFO argument. Thus,
1280 ;; `org-export-secondary-string' is provided for that specific task.
1282 ;; Internally, three functions handle the filtering of objects and
1283 ;; elements during the export. More precisely, `org-export-skip-p'
1284 ;; determines if the considered object or element should be ignored
1285 ;; altogether, `org-export-interpret-p' tells which elements or
1286 ;; objects should be seen as real Org syntax and `org-export-expand'
1287 ;; transforms the others back into their original shape.
1289 (defun org-export-data (data backend info)
1290 "Convert DATA to a string into BACKEND format.
1292 DATA is a nested list as returned by `org-element-parse-buffer'.
1294 BACKEND is a symbol among supported exporters.
1296 INFO is a plist holding export options and also used as
1297 a communication channel between elements when walking the nested
1298 list. See `org-export-update-info' function for more
1299 details.
1301 Return transcoded string."
1302 (mapconcat
1303 ;; BLOB can be an element, an object, a string, or nil.
1304 (lambda (blob)
1305 (cond
1306 ((not blob) nil)
1307 ;; BLOB is a string. Check if the optional transcoder for plain
1308 ;; text exists, and call it in that case. Otherwise, simply
1309 ;; return string. Also update INFO and call
1310 ;; `org-export-filter-plain-text-functions'.
1311 ((stringp blob)
1312 (let ((transcoder (intern (format "org-%s-plain-text" backend))))
1313 (org-export-filter-apply-functions
1314 (plist-get info :filter-plain-text)
1315 (if (fboundp transcoder) (funcall transcoder blob info) blob)
1316 backend info)))
1317 ;; BLOB is an element or an object.
1319 (let* ((type (if (stringp blob) 'plain-text (car blob)))
1320 ;; 1. Determine the appropriate TRANSCODER.
1321 (transcoder
1322 (cond
1323 ;; 1.0 A full Org document is inserted.
1324 ((eq type 'org-data) 'identity)
1325 ;; 1.1. BLOB should be ignored.
1326 ((org-export-skip-p blob info) nil)
1327 ;; 1.2. BLOB shouldn't be transcoded. Interpret it
1328 ;; back into Org syntax.
1329 ((not (org-export-interpret-p blob info))
1330 'org-export-expand)
1331 ;; 1.3. Else apply naming convention.
1332 (t (let ((trans (intern
1333 (format "org-%s-%s" backend type))))
1334 (and (fboundp trans) trans)))))
1335 ;; 2. Compute CONTENTS of BLOB.
1336 (contents
1337 (cond
1338 ;; Case 0. No transcoder defined: ignore BLOB.
1339 ((not transcoder) nil)
1340 ;; Case 1. Transparently export an Org document.
1341 ((eq type 'org-data) (org-export-data blob backend info))
1342 ;; Case 2. For a recursive object.
1343 ((memq type org-element-recursive-objects)
1344 (org-export-data
1345 blob backend
1346 (org-combine-plists
1347 info
1348 `(:genealogy ,(cons blob (plist-get info :genealogy))))))
1349 ;; Case 3. For a recursive element.
1350 ((memq type org-element-greater-elements)
1351 ;; Ignore contents of an archived tree
1352 ;; when `:with-archived-trees' is `headline'.
1353 (unless (and
1354 (eq type 'headline)
1355 (eq (plist-get info :with-archived-trees) 'headline)
1356 (org-element-get-property :archivedp blob))
1357 (org-element-normalize-string
1358 (org-export-data
1359 blob backend
1360 (org-combine-plists
1361 info `(:genealogy
1362 ,(cons blob (plist-get info :genealogy))))))))
1363 ;; Case 4. For a paragraph.
1364 ((eq type 'paragraph)
1365 (let ((paragraph
1366 (org-element-normalize-contents
1367 blob
1368 ;; When normalizing contents of an item or
1369 ;; a footnote definition, ignore first line's
1370 ;; indentation: there is none and it might be
1371 ;; misleading.
1372 (and (not (org-export-get-previous-element blob info))
1373 (let ((parent (caar (plist-get info :genealogy))))
1374 (memq parent '(footnote-definition item)))))))
1375 (org-export-data
1376 paragraph backend
1377 (org-combine-plists
1378 info `(:genealogy
1379 ,(cons paragraph (plist-get info :genealogy)))))))))
1380 ;; 3. Transcode BLOB into RESULTS string.
1381 (results (cond
1382 ((not transcoder) nil)
1383 ((eq transcoder 'org-export-expand)
1384 (org-export-data
1385 `(org-data nil ,(funcall transcoder blob contents))
1386 backend info))
1387 (t (funcall transcoder blob contents info)))))
1388 ;; 4. Discard nil results. Otherwise, update INFO, append
1389 ;; the same white space between elements or objects as in
1390 ;; the original buffer, and call appropriate filters.
1391 (when results
1392 ;; No filter for a full document.
1393 (if (eq type 'org-data) results
1394 (org-export-filter-apply-functions
1395 (plist-get info (intern (format ":filter-%s" type)))
1396 (let ((post-blank (org-element-get-property :post-blank blob)))
1397 (if (memq type org-element-all-elements)
1398 (concat (org-element-normalize-string results)
1399 (make-string post-blank ?\n))
1400 (concat results (make-string post-blank ? ))))
1401 backend info)))))))
1402 (org-element-get-contents data) ""))
1404 (defun org-export-secondary-string (secondary backend info)
1405 "Convert SECONDARY string into BACKEND format.
1407 SECONDARY is a nested list as returned by
1408 `org-element-parse-secondary-string'.
1410 BACKEND is a symbol among supported exporters. INFO is a plist
1411 used as a communication channel.
1413 Return transcoded string."
1414 ;; Make SECONDARY acceptable for `org-export-data'.
1415 (let ((s (if (listp secondary) secondary (list secondary))))
1416 (org-export-data `(org-data nil ,@s) backend (copy-sequence info))))
1418 (defun org-export-skip-p (blob info)
1419 "Non-nil when element or object BLOB should be skipped during export.
1420 INFO is the plist holding export options."
1421 ;; Check headline.
1422 (unless (stringp blob)
1423 (case (car blob)
1424 ('headline
1425 (let ((with-tasks (plist-get info :with-tasks))
1426 (todo (org-element-get-property :todo-keyword blob))
1427 (todo-type (org-element-get-property :todo-type blob))
1428 (archived (plist-get info :with-archived-trees))
1429 (tag-list (let ((tags (org-element-get-property :tags blob)))
1430 (and tags (org-split-string tags ":")))))
1432 ;; Ignore subtrees with an exclude tag.
1433 (loop for k in (plist-get info :exclude-tags)
1434 thereis (member k tag-list))
1435 ;; Ignore subtrees without a select tag, when such tag is found
1436 ;; in the buffer.
1437 (and (plist-get info :use-select-tags)
1438 (loop for k in (plist-get info :select-tags)
1439 never (member k tag-list)))
1440 ;; Ignore commented sub-trees.
1441 (org-element-get-property :commentedp blob)
1442 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
1443 (and (not archived) (org-element-get-property :archivedp blob))
1444 ;; Ignore tasks, if specified by `:with-tasks' property.
1445 (and todo (not with-tasks))
1446 (and todo
1447 (memq with-tasks '(todo done))
1448 (not (eq todo-type with-tasks)))
1449 (and todo
1450 (consp with-tasks)
1451 (not (member todo with-tasks))))))
1452 ;; Check time-stamp.
1453 ('time-stamp (not (plist-get info :with-timestamps)))
1454 ;; Check drawer.
1455 ('drawer
1456 (or (not (plist-get info :with-drawers))
1457 (and (consp (plist-get info :with-drawers))
1458 (not (member (org-element-get-property :drawer-name blob)
1459 (plist-get info :with-drawers))))))
1460 ;; Check export snippet.
1461 ('export-snippet
1462 (let* ((raw-back-end (org-element-get-property :back-end blob))
1463 (true-back-end
1464 (or (cdr (assoc raw-back-end org-export-snippet-translation-alist))
1465 raw-back-end)))
1466 (not (string= (symbol-name (plist-get info :back-end))
1467 true-back-end)))))))
1469 (defun org-export-interpret-p (blob info)
1470 "Non-nil if element or object BLOB should be interpreted as Org syntax.
1471 Check is done according to export options INFO, stored as
1472 a plist."
1473 (case (car blob)
1474 ;; ... entities...
1475 (entity (plist-get info :with-entities))
1476 ;; ... emphasis...
1477 (emphasis (plist-get info :with-emphasize))
1478 ;; ... fixed-width areas.
1479 (fixed-width (plist-get info :with-fixed-width))
1480 ;; ... footnotes...
1481 ((footnote-definition footnote-reference)
1482 (plist-get info :with-footnotes))
1483 ;; ... sub/superscripts...
1484 ((subscript superscript)
1485 (let ((sub/super-p (plist-get info :with-sub-superscript)))
1486 (if (eq sub/super-p '{})
1487 (org-element-get-property :use-brackets-p blob)
1488 sub/super-p)))
1489 ;; ... tables...
1490 (table (plist-get info :with-tables))
1491 (otherwise t)))
1493 (defsubst org-export-expand (blob contents)
1494 "Expand a parsed element or object to its original state.
1495 BLOB is either an element or an object. CONTENTS is its
1496 contents, as a string or nil."
1497 (funcall
1498 (intern (format "org-element-%s-interpreter" (car blob))) blob contents))
1502 ;;; The Filter System
1504 ;; Filters allow end-users to tweak easily the transcoded output.
1505 ;; They are the functional counterpart of hooks, as every filter in
1506 ;; a set is applied to the return value of the previous one.
1508 ;; Every set is back-end agnostic. Although, a filter is always
1509 ;; called, in addition to the string it applies to, with the back-end
1510 ;; used as argument, so it's easy enough for the end-user to add
1511 ;; back-end specific filters in the set. The communication channel,
1512 ;; as a plist, is required as the third argument.
1514 ;; Filters sets are defined below. There are of four types:
1516 ;; - `org-export-filter-parse-tree-functions' applies directly on the
1517 ;; complete parsed tree. It's the only filters set that doesn't
1518 ;; apply to a string.
1519 ;; - `org-export-filter-final-output-functions' applies to the final
1520 ;; transcoded string.
1521 ;; - `org-export-filter-plain-text-functions' applies to any string
1522 ;; not recognized as Org syntax.
1523 ;; - `org-export-filter-TYPE-functions' applies on the string returned
1524 ;; after an element or object of type TYPE has been transcoded.
1526 ;; All filters sets are applied through
1527 ;; `org-export-filter-apply-functions' function. Filters in a set are
1528 ;; applied in a LIFO fashion. It allows developers to be sure that
1529 ;; their filters will be applied first.
1531 ;;;; Special Filters
1532 (defvar org-export-filter-parse-tree-functions nil
1533 "Filter, or list of filters, applied to the parsed tree.
1534 Each filter is called with three arguments: the parse tree, as
1535 returned by `org-element-parse-buffer', the back-end, as
1536 a symbol, and the communication channel, as a plist. It must
1537 return the modified parse tree to transcode.")
1539 (defvar org-export-filter-final-output-functions nil
1540 "Filter, or list of filters, applied to the transcoded string.
1541 Each filter is called with three arguments: the full transcoded
1542 string, the back-end, as a symbol, and the communication channel,
1543 as a plist. It must return a string that will be used as the
1544 final export output.")
1546 (defvar org-export-filter-plain-text-functions nil
1547 "Filter, or list of filters, applied to plain text.
1548 Each filter is called with three arguments: a string which
1549 contains no Org syntax, the back-end, as a symbol, and the
1550 communication channel, as a plist. It must return a string or
1551 nil.")
1554 ;;;; Elements Filters
1556 (defvar org-export-filter-center-block-functions nil
1557 "List of functions applied to a transcoded center block.
1558 Each filter is called with three arguments: the transcoded center
1559 block, as a string, the back-end, as a symbol, and the
1560 communication channel, as a plist. It must return a string or
1561 nil.")
1563 (defvar org-export-filter-drawer-functions nil
1564 "List of functions applied to a transcoded drawer.
1565 Each filter is called with three arguments: the transcoded
1566 drawer, as a string, the back-end, as a symbol, and the
1567 communication channel, as a plist. It must return a string or
1568 nil.")
1570 (defvar org-export-filter-dynamic-block-functions nil
1571 "List of functions applied to a transcoded dynamic-block.
1572 Each filter is called with three arguments: the transcoded
1573 dynamic-block, as a string, the back-end, as a symbol, and the
1574 communication channel, as a plist. It must return a string or
1575 nil.")
1577 (defvar org-export-filter-headline-functions nil
1578 "List of functions applied to a transcoded headline.
1579 Each filter is called with three arguments: the transcoded
1580 headline, as a string, the back-end, as a symbol, and the
1581 communication channel, as a plist. It must return a string or
1582 nil.")
1584 (defvar org-export-filter-inlinetask-functions nil
1585 "List of functions applied to a transcoded inlinetask.
1586 Each filter is called with three arguments: the transcoded
1587 inlinetask, as a string, the back-end, as a symbol, and the
1588 communication channel, as a plist. It must return a string or
1589 nil.")
1591 (defvar org-export-filter-plain-list-functions nil
1592 "List of functions applied to a transcoded plain-list.
1593 Each filter is called with three arguments: the transcoded
1594 plain-list, as a string, the back-end, as a symbol, and the
1595 communication channel, as a plist. It must return a string or
1596 nil.")
1598 (defvar org-export-filter-item-functions nil
1599 "List of functions applied to a transcoded item.
1600 Each filter is called with three arguments: the transcoded item,
1601 as a string, the back-end, as a symbol, and the communication
1602 channel, as a plist. It must return a string or nil.")
1604 (defvar org-export-filter-comment-functions nil
1605 "List of functions applied to a transcoded comment.
1606 Each filter is called with three arguments: the transcoded
1607 comment, as a string, the back-end, as a symbol, and the
1608 communication channel, as a plist. It must return a string or
1609 nil.")
1611 (defvar org-export-filter-comment-block-functions nil
1612 "List of functions applied to a transcoded comment-comment.
1613 Each filter is called with three arguments: the transcoded
1614 comment-block, as a string, the back-end, as a symbol, and the
1615 communication channel, as a plist. It must return a string or
1616 nil.")
1618 (defvar org-export-filter-example-block-functions nil
1619 "List of functions applied to a transcoded example-block.
1620 Each filter is called with three arguments: the transcoded
1621 example-block, as a string, the back-end, as a symbol, and the
1622 communication channel, as a plist. It must return a string or
1623 nil.")
1625 (defvar org-export-filter-export-block-functions nil
1626 "List of functions applied to a transcoded export-block.
1627 Each filter is called with three arguments: the transcoded
1628 export-block, as a string, the back-end, as a symbol, and the
1629 communication channel, as a plist. It must return a string or
1630 nil.")
1632 (defvar org-export-filter-fixed-width-functions nil
1633 "List of functions applied to a transcoded fixed-width.
1634 Each filter is called with three arguments: the transcoded
1635 fixed-width, as a string, the back-end, as a symbol, and the
1636 communication channel, as a plist. It must return a string or
1637 nil.")
1639 (defvar org-export-filter-footnote-definition-functions nil
1640 "List of functions applied to a transcoded footnote-definition.
1641 Each filter is called with three arguments: the transcoded
1642 footnote-definition, as a string, the back-end, as a symbol, and
1643 the communication channel, as a plist. It must return a string
1644 or nil.")
1646 (defvar org-export-filter-horizontal-rule-functions nil
1647 "List of functions applied to a transcoded horizontal-rule.
1648 Each filter is called with three arguments: the transcoded
1649 horizontal-rule, as a string, the back-end, as a symbol, and the
1650 communication channel, as a plist. It must return a string or
1651 nil.")
1653 (defvar org-export-filter-keyword-functions nil
1654 "List of functions applied to a transcoded keyword.
1655 Each filter is called with three arguments: the transcoded
1656 keyword, as a string, the back-end, as a symbol, and the
1657 communication channel, as a plist. It must return a string or
1658 nil.")
1660 (defvar org-export-filter-latex-environment-functions nil
1661 "List of functions applied to a transcoded latex-environment.
1662 Each filter is called with three arguments: the transcoded
1663 latex-environment, as a string, the back-end, as a symbol, and
1664 the communication channel, as a plist. It must return a string
1665 or nil.")
1667 (defvar org-export-filter-babel-call-functions nil
1668 "List of functions applied to a transcoded babel-call.
1669 Each filter is called with three arguments: the transcoded
1670 babel-call, as a string, the back-end, as a symbol, and the
1671 communication channel, as a plist. It must return a string or
1672 nil.")
1674 (defvar org-export-filter-paragraph-functions nil
1675 "List of functions applied to a transcoded paragraph.
1676 Each filter is called with three arguments: the transcoded
1677 paragraph, as a string, the back-end, as a symbol, and the
1678 communication channel, as a plist. It must return a string or
1679 nil.")
1681 (defvar org-export-filter-property-drawer-functions nil
1682 "List of functions applied to a transcoded property-drawer.
1683 Each filter is called with three arguments: the transcoded
1684 property-drawer, as a string, the back-end, as a symbol, and the
1685 communication channel, as a plist. It must return a string or
1686 nil.")
1688 (defvar org-export-filter-quote-block-functions nil
1689 "List of functions applied to a transcoded quote block.
1690 Each filter is called with three arguments: the transcoded quote
1691 block, as a string, the back-end, as a symbol, and the
1692 communication channel, as a plist. It must return a string or
1693 nil.")
1695 (defvar org-export-filter-quote-section-functions nil
1696 "List of functions applied to a transcoded quote-section.
1697 Each filter is called with three arguments: the transcoded
1698 quote-section, as a string, the back-end, as a symbol, and the
1699 communication channel, as a plist. It must return a string or
1700 nil.")
1702 (defvar org-export-filter-section-functions nil
1703 "List of functions applied to a transcoded section.
1704 Each filter is called with three arguments: the transcoded
1705 section, as a string, the back-end, as a symbol, and the
1706 communication channel, as a plist. It must return a string or
1707 nil.")
1709 (defvar org-export-filter-special-block-functions nil
1710 "List of functions applied to a transcoded special block.
1711 Each filter is called with three arguments: the transcoded
1712 special block, as a string, the back-end, as a symbol, and the
1713 communication channel, as a plist. It must return a string or
1714 nil.")
1716 (defvar org-export-filter-src-block-functions nil
1717 "List of functions applied to a transcoded src-block.
1718 Each filter is called with three arguments: the transcoded
1719 src-block, as a string, the back-end, as a symbol, and the
1720 communication channel, as a plist. It must return a string or
1721 nil.")
1723 (defvar org-export-filter-table-functions nil
1724 "List of functions applied to a transcoded table.
1725 Each filter is called with three arguments: the transcoded table,
1726 as a string, the back-end, as a symbol, and the communication
1727 channel, as a plist. It must return a string or nil.")
1729 (defvar org-export-filter-verse-block-functions nil
1730 "List of functions applied to a transcoded verse block.
1731 Each filter is called with three arguments: the transcoded verse
1732 block, as a string, the back-end, as a symbol, and the
1733 communication channel, as a plist. It must return a string or
1734 nil.")
1737 ;;;; Objects Filters
1739 (defvar org-export-filter-emphasis-functions nil
1740 "List of functions applied to a transcoded emphasis.
1741 Each filter is called with three arguments: the transcoded
1742 emphasis, as a string, the back-end, as a symbol, and the
1743 communication channel, as a plist. It must return a string or
1744 nil.")
1746 (defvar org-export-filter-entity-functions nil
1747 "List of functions applied to a transcoded entity.
1748 Each filter is called with three arguments: the transcoded
1749 entity, as a string, the back-end, as a symbol, and the
1750 communication channel, as a plist. It must return a string or
1751 nil.")
1753 (defvar org-export-filter-export-snippet-functions nil
1754 "List of functions applied to a transcoded export-snippet.
1755 Each filter is called with three arguments: the transcoded
1756 export-snippet, as a string, the back-end, as a symbol, and the
1757 communication channel, as a plist. It must return a string or
1758 nil.")
1760 (defvar org-export-filter-footnote-reference-functions nil
1761 "List of functions applied to a transcoded footnote-reference.
1762 Each filter is called with three arguments: the transcoded
1763 footnote-reference, as a string, the back-end, as a symbol, and
1764 the communication channel, as a plist. It must return a string
1765 or nil.")
1767 (defvar org-export-filter-inline-babel-call-functions nil
1768 "List of functions applied to a transcoded inline-babel-call.
1769 Each filter is called with three arguments: the transcoded
1770 inline-babel-call, as a string, the back-end, as a symbol, and
1771 the communication channel, as a plist. It must return a string
1772 or nil.")
1774 (defvar org-export-filter-inline-src-block-functions nil
1775 "List of functions applied to a transcoded inline-src-block.
1776 Each filter is called with three arguments: the transcoded
1777 inline-src-block, as a string, the back-end, as a symbol, and the
1778 communication channel, as a plist. It must return a string or
1779 nil.")
1781 (defvar org-export-filter-latex-fragment-functions nil
1782 "List of functions applied to a transcoded latex-fragment.
1783 Each filter is called with three arguments: the transcoded
1784 latex-fragment, as a string, the back-end, as a symbol, and the
1785 communication channel, as a plist. It must return a string or
1786 nil.")
1788 (defvar org-export-filter-line-break-functions nil
1789 "List of functions applied to a transcoded line-break.
1790 Each filter is called with three arguments: the transcoded
1791 line-break, as a string, the back-end, as a symbol, and the
1792 communication channel, as a plist. It must return a string or
1793 nil.")
1795 (defvar org-export-filter-link-functions nil
1796 "List of functions applied to a transcoded link.
1797 Each filter is called with three arguments: the transcoded link,
1798 as a string, the back-end, as a symbol, and the communication
1799 channel, as a plist. It must return a string or nil.")
1801 (defvar org-export-filter-macro-functions nil
1802 "List of functions applied to a transcoded macro.
1803 Each filter is called with three arguments: the transcoded macro,
1804 as a string, the back-end, as a symbol, and the communication
1805 channel, as a plist. It must return a string or nil.")
1807 (defvar org-export-filter-radio-target-functions nil
1808 "List of functions applied to a transcoded radio-target.
1809 Each filter is called with three arguments: the transcoded
1810 radio-target, as a string, the back-end, as a symbol, and the
1811 communication channel, as a plist. It must return a string or
1812 nil.")
1814 (defvar org-export-filter-statistics-cookie-functions nil
1815 "List of functions applied to a transcoded statistics-cookie.
1816 Each filter is called with three arguments: the transcoded
1817 statistics-cookie, as a string, the back-end, as a symbol, and
1818 the communication channel, as a plist. It must return a string
1819 or nil.")
1821 (defvar org-export-filter-subscript-functions nil
1822 "List of functions applied to a transcoded subscript.
1823 Each filter is called with three arguments: the transcoded
1824 subscript, as a string, the back-end, as a symbol, and the
1825 communication channel, as a plist. It must return a string or
1826 nil.")
1828 (defvar org-export-filter-superscript-functions nil
1829 "List of functions applied to a transcoded superscript.
1830 Each filter is called with three arguments: the transcoded
1831 superscript, as a string, the back-end, as a symbol, and the
1832 communication channel, as a plist. It must return a string or
1833 nil.")
1835 (defvar org-export-filter-target-functions nil
1836 "List of functions applied to a transcoded target.
1837 Each filter is called with three arguments: the transcoded
1838 target, as a string, the back-end, as a symbol, and the
1839 communication channel, as a plist. It must return a string or
1840 nil.")
1842 (defvar org-export-filter-time-stamp-functions nil
1843 "List of functions applied to a transcoded time-stamp.
1844 Each filter is called with three arguments: the transcoded
1845 time-stamp, as a string, the back-end, as a symbol, and the
1846 communication channel, as a plist. It must return a string or
1847 nil.")
1849 (defvar org-export-filter-verbatim-functions nil
1850 "List of functions applied to a transcoded verbatim.
1851 Each filter is called with three arguments: the transcoded
1852 verbatim, as a string, the back-end, as a symbol, and the
1853 communication channel, as a plist. It must return a string or
1854 nil.")
1856 (defun org-export-filter-apply-functions (filters value backend info)
1857 "Call every function in FILTERS with arguments VALUE, BACKEND and INFO.
1858 Functions are called in a LIFO fashion, to be sure that developer
1859 specified filters, if any, are called first."
1860 (loop for filter in filters
1861 if (not value) return nil else
1862 do (setq value (funcall filter value backend info)))
1863 value)
1867 ;;; Core functions
1869 ;; This is the room for the main function, `org-export-as', along with
1870 ;; its derivatives, `org-export-to-buffer' and `org-export-to-file'.
1871 ;; They differ only by the way they output the resulting code.
1873 ;; `org-export-output-file-name' is an auxiliary function meant to be
1874 ;; used with `org-export-to-file'. With a given extension, it tries
1875 ;; to provide a canonical file name to write export output to.
1877 ;; Note that `org-export-as' doesn't really parse the current buffer,
1878 ;; but a copy of it (with the same buffer-local variables and
1879 ;; visibility), where Babel blocks are executed, if appropriate.
1880 ;; `org-export-with-current-buffer-copy' macro prepares that copy.
1882 (defun org-export-as (backend
1883 &optional subtreep visible-only body-only ext-plist)
1884 "Transcode current Org buffer into BACKEND code.
1886 If narrowing is active in the current buffer, only transcode its
1887 narrowed part.
1889 If a region is active, transcode that region.
1891 When optional argument SUBTREEP is non-nil, transcode the
1892 sub-tree at point, extracting information from the headline
1893 properties first.
1895 When optional argument VISIBLE-ONLY is non-nil, don't export
1896 contents of hidden elements.
1898 When optional argument BODY-ONLY is non-nil, only return body
1899 code, without preamble nor postamble.
1901 EXT-PLIST, when provided, is a property list with external
1902 parameters overriding Org default settings, but still inferior to
1903 file-local settings.
1905 Return code as a string."
1906 (save-excursion
1907 (save-restriction
1908 ;; Narrow buffer to an appropriate region for parsing.
1909 (when (org-region-active-p)
1910 (narrow-to-region (region-beginning) (region-end))
1911 (goto-char (point-min)))
1912 (when (and subtreep (not (org-at-heading-p)))
1913 ;; Ensure point is at sub-tree's beginning.
1914 (org-with-limited-levels (org-back-to-heading (not visible-only))))
1915 ;; Retrieve export options (INFO) and parsed tree (RAW-DATA),
1916 ;; Then options can be completed with tree properties. Note:
1917 ;; Buffer isn't parsed directly. Instead, a temporary copy is
1918 ;; created, where all code blocks are evaluated. RAW-DATA is
1919 ;; the parsed tree of the buffer resulting from that process.
1920 ;; Eventually call `org-export-filter-parse-tree-functions'.
1921 (let* ((info (org-export-collect-options backend subtreep ext-plist))
1922 (raw-data (progn
1923 (when subtreep ; Only parse subtree contents.
1924 (let ((end (save-excursion (org-end-of-subtree t))))
1925 (narrow-to-region
1926 (progn (forward-line) (point)) end)))
1927 (org-export-filter-apply-functions
1928 (plist-get info :filter-parse-tree)
1929 (org-export-with-current-buffer-copy
1930 (let ((org-current-export-file (current-buffer)))
1931 (org-export-blocks-preprocess))
1932 (org-element-parse-buffer nil visible-only))
1933 backend info))))
1934 ;; Now get full initial options with tree properties.
1935 (setq info
1936 (org-combine-plists
1937 info
1938 (org-export-collect-tree-properties raw-data info backend)))
1939 ;; Now transcode RAW-DATA. Also call
1940 ;; `org-export-filter-final-output-functions'.
1941 (let* ((body (org-element-normalize-string
1942 (org-export-data raw-data backend info)))
1943 (template (intern (format "org-%s-template" backend)))
1944 (output (org-export-filter-apply-functions
1945 (plist-get info :filter-final-output)
1946 (if (or (not (fboundp template)) body-only) body
1947 (funcall template body info))
1948 backend info)))
1949 ;; Maybe add final OUTPUT to kill ring before returning it.
1950 (when org-export-copy-to-kill-ring (org-kill-new output))
1951 output)))))
1953 (defun org-export-to-buffer (backend buffer &optional subtreep visible-only
1954 body-only ext-plist)
1955 "Call `org-export-as' with output to a specified buffer.
1957 BACKEND is the back-end used for transcoding, as a symbol.
1959 BUFFER is the output buffer. If it already exists, it will be
1960 erased first, otherwise, it will be created.
1962 Arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and EXT-PLIST are
1963 similar to those used in `org-export-as', which see.
1965 Return buffer."
1966 (let ((out (org-export-as backend subtreep visible-only body-only ext-plist))
1967 (buffer (get-buffer-create buffer)))
1968 (with-current-buffer buffer
1969 (erase-buffer)
1970 (insert out)
1971 (goto-char (point-min)))
1972 buffer))
1974 (defun org-export-to-file (backend file &optional subtreep visible-only
1975 body-only ext-plist)
1976 "Call `org-export-as' with output to a specified file.
1978 BACKEND is the back-end used for transcoding, as a symbol. FILE
1979 is the name of the output file, as a string.
1981 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
1982 EXT-PLIST are similar to those used in `org-export-as', which
1983 see.
1985 Return output file's name."
1986 ;; Checks for FILE permissions. `write-file' would do the same, but
1987 ;; we'd rather avoid needless transcoding of parse tree.
1988 (unless (file-writable-p file) (error "Output file not writable"))
1989 ;; Insert contents to a temporary buffer and write it to FILE.
1990 (let ((out (org-export-as
1991 backend subtreep visible-only body-only ext-plist)))
1992 (with-temp-buffer
1993 (insert out)
1994 (let ((coding-system-for-write org-export-coding-system))
1995 (write-file file))))
1996 ;; Return full path.
1997 file)
1999 (defun org-export-output-file-name (extension &optional subtreep pub-dir)
2000 "Return output file's name according to buffer specifications.
2002 EXTENSION is a string representing the output file extension,
2003 with the leading dot.
2005 With a non-nil optional argument SUBTREEP, try to determine
2006 output file's name by looking for \"EXPORT_FILE_NAME\" property
2007 of subtree at point.
2009 When optional argument PUB-DIR is set, use it as the publishing
2010 directory.
2012 Return file name as a string, or nil if it couldn't be
2013 determined."
2014 (let ((base-name
2015 ;; File name may come from EXPORT_FILE_NAME subtree property,
2016 ;; assuming point is at beginning of said sub-tree.
2017 (file-name-sans-extension
2018 (or (and subtreep
2019 (org-entry-get
2020 (save-excursion
2021 (ignore-errors
2022 (org-back-to-heading (not visible-only)) (point)))
2023 "EXPORT_FILE_NAME" t))
2024 ;; File name may be extracted from buffer's associated
2025 ;; file, if any.
2026 (buffer-file-name (buffer-base-buffer))
2027 ;; Can't determine file name on our own: Ask user.
2028 (let ((read-file-name-function
2029 (and org-completion-use-ido 'ido-read-file-name)))
2030 (read-file-name
2031 "Output file: " pub-dir nil nil nil
2032 (lambda (name)
2033 (string= (file-name-extension name t) extension))))))))
2034 ;; Build file name. Enforce EXTENSION over whatever user may have
2035 ;; come up with. PUB-DIR, if defined, always has precedence over
2036 ;; any provided path.
2037 (cond
2038 (pub-dir
2039 (concat (file-name-as-directory pub-dir)
2040 (file-name-nondirectory base-name)
2041 extension))
2042 ((string= (file-name-nondirectory base-name) base-name)
2043 (concat (file-name-as-directory ".") base-name extension))
2044 (t (concat base-name extension)))))
2046 (defmacro org-export-with-current-buffer-copy (&rest body)
2047 "Apply BODY in a copy of the current buffer.
2049 The copy preserves local variables and visibility of the original
2050 buffer.
2052 Point is at buffer's beginning when BODY is applied."
2053 (org-with-gensyms (original-buffer offset buffer-string overlays)
2054 `(let ((,original-buffer ,(current-buffer))
2055 (,offset ,(1- (point-min)))
2056 (,buffer-string ,(buffer-string))
2057 (,overlays (mapcar
2058 'copy-overlay (overlays-in (point-min) (point-max)))))
2059 (with-temp-buffer
2060 (let ((buffer-invisibility-spec nil))
2061 (org-clone-local-variables
2062 ,original-buffer
2063 "^\\(org-\\|orgtbl-\\|major-mode$\\|outline-\\(regexp\\|level\\)$\\)")
2064 (insert ,buffer-string)
2065 (mapc (lambda (ov)
2066 (move-overlay
2068 (- (overlay-start ov) ,offset)
2069 (- (overlay-end ov) ,offset)
2070 (current-buffer)))
2071 ,overlays)
2072 (goto-char (point-min))
2073 (progn ,@body))))))
2074 (def-edebug-spec org-export-with-current-buffer-copy (body))
2078 ;;; Tools For Back-Ends
2080 ;; A whole set of tools is available to help build new exporters. Any
2081 ;; function general enough to have its use across many back-ends
2082 ;; should be added here.
2084 ;; As of now, functions operating on footnotes, headlines, include
2085 ;; keywords, links, macros, references, src-blocks, tables and tables
2086 ;; of contents are implemented.
2088 ;;;; For Footnotes
2090 ;; `org-export-collect-footnote-definitions' is a tool to list
2091 ;; actually used footnotes definitions in the whole parse tree, or in
2092 ;; an headline, in order to add footnote listings throughout the
2093 ;; transcoded data.
2095 ;; `org-export-footnote-first-reference-p' is a predicate used by some
2096 ;; back-ends, when they need to attach the footnote definition only to
2097 ;; the first occurrence of the corresponding label.
2099 ;; `org-export-get-footnote-definition' and
2100 ;; `org-export-get-footnote-number' provide easier access to
2101 ;; additional information relative to a footnote reference.
2103 (defun org-export-collect-footnote-definitions (data info)
2104 "Return an alist between footnote numbers, labels and definitions.
2106 DATA is the parse tree from which definitions are collected.
2107 INFO is the plist used as a communication channel.
2109 Definitions are sorted by order of references. They either
2110 appear as Org data \(transcoded with `org-export-data'\) or as
2111 a secondary string for inlined footnotes \(transcoded with
2112 `org-export-secondary-string'\). Unreferenced definitions are
2113 ignored."
2114 (let (refs)
2115 ;; Collect seen references in REFS.
2116 (org-element-map
2117 data 'footnote-reference
2118 (lambda (footnote local)
2119 (when (org-export-footnote-first-reference-p footnote local)
2120 (list (org-export-get-footnote-number footnote local)
2121 (org-element-get-property :label footnote)
2122 (org-export-get-footnote-definition footnote local))))
2123 info)))
2125 (defun org-export-footnote-first-reference-p (footnote-reference info)
2126 "Non-nil when a footnote reference is the first one for its label.
2128 FOOTNOTE-REFERENCE is the footnote reference being considered.
2129 INFO is the plist used as a communication channel."
2130 (let ((label (org-element-get-property :label footnote-reference)))
2131 (or (not label)
2132 (equal
2133 footnote-reference
2134 (org-element-map
2135 (plist-get info :parse-tree) 'footnote-reference
2136 (lambda (footnote local)
2137 (when (string= (org-element-get-property :label footnote) label)
2138 footnote))
2139 info 'first-match)))))
2141 (defun org-export-get-footnote-definition (footnote-reference info)
2142 "Return definition of FOOTNOTE-REFERENCE as parsed data.
2143 INFO is the plist used as a communication channel."
2144 (let ((label (org-element-get-property :label footnote-reference)))
2145 (or (org-element-get-property :inline-definition footnote-reference)
2146 (cdr (assoc label (plist-get info :footnote-definition-alist))))))
2148 (defun org-export-get-footnote-number (footnote info)
2149 "Return number associated to a footnote.
2151 FOOTNOTE is either a footnote reference or a footnote definition.
2152 INFO is the plist used as a communication channel."
2153 (let ((label (org-element-get-property :label footnote)) seen-refs)
2154 (org-element-map
2155 (plist-get info :parse-tree) 'footnote-reference
2156 (lambda (fn local)
2157 (let ((fn-lbl (org-element-get-property :label fn)))
2158 (cond
2159 ((and (not fn-lbl) (equal fn footnote)) (1+ (length seen-refs)))
2160 ((and label (string= label fn-lbl)) (1+ (length seen-refs)))
2161 ;; Anonymous footnote: it's always a new one. Also, be sure
2162 ;; to return nil from the `cond' so `first-match' doesn't
2163 ;; get us out of the loop.
2164 ((not fn-lbl) (push 'inline seen-refs) nil)
2165 ;; Label not seen so far: add it so SEEN-REFS. Again,
2166 ;; return nil to stay in the loop.
2167 ((not (member fn-lbl seen-refs)) (push fn-lbl seen-refs) nil))))
2168 info 'first-match)))
2171 ;;;; For Headlines
2173 ;; `org-export-get-relative-level' is a shortcut to get headline
2174 ;; level, relatively to the lower headline level in the parsed tree.
2176 ;; `org-export-get-headline-number' returns the section number of an
2177 ;; headline, while `org-export-number-to-roman' allows to convert it
2178 ;; to roman numbers.
2180 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
2181 ;; `org-export-last-sibling-p' are three useful predicates when it
2182 ;; comes to fulfill the `:headline-levels' property.
2184 (defun org-export-get-relative-level (headline info)
2185 "Return HEADLINE relative level within current parsed tree.
2186 INFO is a plist holding contextual information."
2187 (+ (org-element-get-property :level headline)
2188 (or (plist-get info :headline-offset) 0)))
2190 (defun org-export-low-level-p (headline info)
2191 "Non-nil when HEADLINE is considered as low level.
2193 INFO is a plist used as a communication channel.
2195 A low level headlines has a relative level greater than
2196 `:headline-levels' property value.
2198 Return value is the difference between HEADLINE relative level
2199 and the last level being considered as high enough, or nil."
2200 (let ((limit (plist-get info :headline-levels)))
2201 (when (wholenump limit)
2202 (let ((level (org-export-get-relative-level headline info)))
2203 (and (> level limit) (- level limit))))))
2205 (defun org-export-get-headline-number (headline info)
2206 "Return HEADLINE numbering as a list of numbers.
2207 INFO is a plist holding contextual information."
2208 (cdr (assoc headline (plist-get info :headline-numbering))))
2210 (defun org-export-number-to-roman (n)
2211 "Convert integer N into a roman numeral."
2212 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2213 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2214 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2215 ( 1 . "I")))
2216 (res ""))
2217 (if (<= n 0)
2218 (number-to-string n)
2219 (while roman
2220 (if (>= n (caar roman))
2221 (setq n (- n (caar roman))
2222 res (concat res (cdar roman)))
2223 (pop roman)))
2224 res)))
2226 (defun org-export-first-sibling-p (headline info)
2227 "Non-nil when HEADLINE is the first sibling in its sub-tree.
2228 INFO is the plist used as a communication channel."
2229 (not (eq (car (org-export-get-previous-element headline info)) 'headline)))
2231 (defun org-export-last-sibling-p (headline info)
2232 "Non-nil when HEADLINE is the last sibling in its sub-tree.
2233 INFO is the plist used as a communication channel."
2234 (equal
2235 (car (last (org-element-get-contents (car (plist-get info :genealogy)))))
2236 headline))
2239 ;;;; For Include Keywords
2241 ;; This section provides a tool to properly handle insertion of files
2242 ;; during export: `org-export-included-files'. It recursively
2243 ;; transcodes a file specfied by an include keyword.
2245 ;; It uses two helper functions: `org-export-get-file-contents'
2246 ;; returns contents of a file according to parameters specified in the
2247 ;; keyword while `org-export-parse-included-file' parses the file
2248 ;; specified by it.
2250 (defun org-export-included-file (keyword backend info)
2251 "Transcode file specified with include KEYWORD.
2253 KEYWORD is the include keyword element transcoded. BACKEND is
2254 the language back-end used for transcoding. INFO is the plist
2255 used as a communication channel.
2257 This function updates `:included-files' and `:headline-offset'
2258 properties.
2260 Return the transcoded string."
2261 (let ((data (org-export-parse-included-file keyword info))
2262 (file (let ((value (org-element-get-property :value keyword)))
2263 (and (string-match "^\"\\(\\S-+\\)\"" value)
2264 (match-string 1 value)))))
2265 (org-element-normalize-string
2266 (org-export-data
2267 data backend
2268 (org-combine-plists
2269 info
2270 ;; Store full path of already included files to avoid recursive
2271 ;; file inclusion.
2272 `(:included-files
2273 ,(cons (expand-file-name file) (plist-get info :included-files))
2274 ;; Ensure that a top-level headline in the included file
2275 ;; becomes a direct child of the current headline in the
2276 ;; buffer.
2277 :headline-offset
2278 ,(- (let ((parent (org-export-get-parent-headline keyword info)))
2279 (if (not parent) 0
2280 (org-export-get-relative-level parent info)))
2281 (1- (org-export-get-min-level data info)))))))))
2283 (defun org-export-get-file-contents (file &optional lines)
2284 "Get the contents of FILE and return them as a string.
2285 When optional argument LINES is a string specifying a range of
2286 lines, include only those lines."
2287 (with-temp-buffer
2288 (insert-file-contents file)
2289 (when lines
2290 (let* ((lines (split-string lines "-"))
2291 (lbeg (string-to-number (car lines)))
2292 (lend (string-to-number (cadr lines)))
2293 (beg (if (zerop lbeg) (point-min)
2294 (goto-char (point-min))
2295 (forward-line (1- lbeg))
2296 (point)))
2297 (end (if (zerop lend) (point-max)
2298 (goto-char (point-min))
2299 (forward-line (1- lend))
2300 (point))))
2301 (narrow-to-region beg end)))
2302 (buffer-string)))
2304 (defun org-export-parse-included-file (keyword info)
2305 "Parse file specified by include KEYWORD.
2307 KEYWORD is the include keyword element transcoded. BACKEND is
2308 the language back-end used for transcoding. INFO is the plist
2309 used as a communication channel.
2311 Return the parsed tree."
2312 (let* ((value (org-element-get-property :value keyword))
2313 (file (and (string-match "^\"\\(\\S-+\\)\"" value)
2314 (prog1 (match-string 1 value)
2315 (setq value (replace-match "" nil nil value)))))
2316 (lines (and (string-match
2317 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\"" value)
2318 (prog1 (match-string 1 value)
2319 (setq value (replace-match "" nil nil value)))))
2320 (env (cond ((string-match "\\<example\\>" value) "example")
2321 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
2322 (match-string 1 value)))))
2323 (cond
2324 ((or (not file)
2325 (not (file-exists-p file))
2326 (not (file-readable-p file)))
2327 (format "Cannot include file %s" file))
2328 ((and (not env)
2329 (member (expand-file-name file) (plist-get info :included-files)))
2330 (error "Recursive file inclusion: %S" file))
2331 (t (let ((raw (org-element-normalize-string
2332 (org-export-get-file-contents
2333 (expand-file-name file) lines))))
2334 ;; If environment isn't specified, Insert file in
2335 ;; a temporary buffer and parse it as Org syntax.
2336 ;; Otherwise, build the element representing the file.
2337 (cond
2338 ((not env)
2339 (with-temp-buffer
2340 (insert raw) (org-mode) (org-element-parse-buffer)))
2341 ((string= "example" env)
2342 `(org-data nil (example-block (:value ,raw :post-blank 0))))
2344 `(org-data
2346 (src-block (:value ,raw :language ,env :post-blank 0))))))))))
2349 ;;;; For Links
2351 ;; `org-export-solidify-link-text' turns a string into a safer version
2352 ;; for links, replacing most non-standard characters with hyphens.
2354 ;; `org-export-get-coderef-format' returns an appropriate format
2355 ;; string for coderefs.
2357 ;; `org-export-inline-image-p' returns a non-nil value when the link
2358 ;; provided should be considered as an inline image.
2360 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
2361 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
2362 ;; returns an appropriate unique identifier when found, or nil.
2364 ;; `org-export-resolve-id-link' returns the first headline with
2365 ;; specified id or custom-id in parse tree, or nil when none was
2366 ;; found.
2368 ;; `org-export-resolve-coderef' associates a reference to a line
2369 ;; number in the element it belongs, or returns the reference itself
2370 ;; when the element isn't numbered.
2372 (defun org-export-solidify-link-text (s)
2373 "Take link text S and make a safe target out of it."
2374 (save-match-data
2375 (mapconcat 'identity (org-split-string s "[^a-zA-Z0-9_\\.-]+") "-")))
2377 (defun org-export-get-coderef-format (path desc)
2378 "Return format string for code reference link.
2379 PATH is the link path. DESC is its description."
2380 (save-match-data
2381 (cond ((string-match (regexp-quote (concat "(" path ")")) desc)
2382 (replace-match "%s" t t desc))
2383 ((string= desc "") "%s")
2384 (t desc))))
2386 (defun org-export-inline-image-p (link &optional extensions)
2387 "Non-nil if LINK object points to an inline image.
2389 When non-nil, optional argument EXTENSIONS is a list of valid
2390 extensions for image files, as strings. Otherwise, a default
2391 list is provided \(cf `org-image-file-name-regexp'\)."
2392 (and (not (org-element-get-contents link))
2393 (string= (org-element-get-property :type link) "file")
2394 (org-file-image-p
2395 (expand-file-name (org-element-get-property :path link))
2396 extensions)))
2398 (defun org-export-resolve-fuzzy-link (link info)
2399 "Return LINK destination.
2401 INFO is a plist holding contextual information.
2403 Return value can be an object, an element, or nil:
2405 - If LINK path exactly matches any target, return the target
2406 object.
2408 - If LINK path exactly matches any headline name, return that
2409 element. If more than one headline share that name, priority
2410 will be given to the one with the closest common ancestor, if
2411 any, or the first one in the parse tree otherwise.
2413 - Otherwise, return nil.
2415 Assume LINK type is \"fuzzy\"."
2416 (let ((path (org-element-get-property :path link)))
2417 ;; Link points to a target: return it.
2418 (or (loop for target in (plist-get info :target-list)
2419 when (string= (org-element-get-property :raw-value target) path)
2420 return target)
2421 ;; Link either points to an headline or nothing. Try to find
2422 ;; the source, with priority given to headlines with the closest
2423 ;; common ancestor. If such candidate is found, return its
2424 ;; beginning position as an unique identifier, otherwise return
2425 ;; nil.
2426 (let ((find-headline
2427 (function
2428 ;; Return first headline whose `:raw-value' property
2429 ;; is NAME in parse tree DATA, or nil.
2430 (lambda (name data)
2431 (org-element-map
2432 data 'headline
2433 (lambda (headline local)
2434 (when (string=
2435 (org-element-get-property :raw-value headline)
2436 name)
2437 headline))
2438 info 'first-match)))))
2439 ;; Search among headlines sharing an ancestor with link,
2440 ;; from closest to farthest.
2441 (or (catch 'exit
2442 (mapc
2443 (lambda (parent)
2444 (when (eq (car parent) 'headline)
2445 (let ((foundp (funcall find-headline path parent)))
2446 (when foundp (throw 'exit foundp)))))
2447 (plist-get info :genealogy)) nil)
2448 ;; No match with a common ancestor: try the full parse-tree.
2449 (funcall find-headline path (plist-get info :parse-tree)))))))
2451 (defun org-export-resolve-id-link (link info)
2452 "Return headline referenced as LINK destination.
2454 INFO is a plist used as a communication channel.
2456 Return value can be an headline element or nil. Assume LINK type
2457 is either \"id\" or \"custom-id\"."
2458 (let ((id (org-element-get-property :path link)))
2459 (org-element-map
2460 (plist-get info :parse-tree) 'headline
2461 (lambda (headline local)
2462 (when (or (string= (org-element-get-property :id headline) id)
2463 (string= (org-element-get-property :custom-id headline) id))
2464 headline))
2465 info 'first-match)))
2467 (defun org-export-resolve-coderef (ref info)
2468 "Resolve a code reference REF.
2470 INFO is a plist used as a communication channel.
2472 Return associated line number in source code, or REF itself,
2473 depending on src-block or example element's switches."
2474 (org-element-map
2475 (plist-get info :parse-tree) '(src-block example)
2476 (lambda (el local)
2477 (let ((switches (or (org-element-get-property :switches el) "")))
2478 (with-temp-buffer
2479 (insert (org-trim (org-element-get-property :value el)))
2480 ;; Build reference regexp.
2481 (let* ((label
2482 (or (and (string-match "-l +\"\\([^\"\n]+\\)\"" switches)
2483 (match-string 1 switches))
2484 org-coderef-label-format))
2485 (ref-re
2486 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
2487 (replace-regexp-in-string "%s" ref label nil t))))
2488 ;; Element containing REF is found. Only associate REF to
2489 ;; a line number if element has "+n" or "-n" and "-k" or
2490 ;; "-r" as switches. When it has "+n", count accumulated
2491 ;; locs before, too.
2492 (when (re-search-backward ref-re nil t)
2493 (cond
2494 ((not (string-match "-[kr]\\>" switches)) ref)
2495 ((string-match "-n\\>" switches) (line-number-at-pos))
2496 ((string-match "\\+n\\>" switches)
2497 (+ (org-export-get-loc el local) (line-number-at-pos)))
2498 (t ref)))))))
2499 info 'first-match))
2502 ;;;; For Macros
2504 ;; `org-export-expand-macro' simply takes care of expanding macros.
2506 (defun org-export-expand-macro (macro info)
2507 "Expand MACRO and return it as a string.
2508 INFO is a plist holding export options."
2509 (let* ((key (org-element-get-property :key macro))
2510 (args (org-element-get-property :args macro))
2511 (value (plist-get info (intern (format ":macro-%s" key)))))
2512 ;; Replace arguments in VALUE.
2513 (let ((s 0) n)
2514 (while (string-match "\\$\\([0-9]+\\)" value s)
2515 (setq s (1+ (match-beginning 0))
2516 n (string-to-number (match-string 1 value)))
2517 (and (>= (length args) n)
2518 (setq value (replace-match (nth (1- n) args) t t value)))))
2519 ;; VALUE starts with "(eval": it is a s-exp, `eval' it.
2520 (when (string-match "\\`(eval\\>" value)
2521 (setq value (eval (read value))))
2522 ;; Return expanded string.
2523 (format "%s" value)))
2526 ;;;; For References
2528 ;; `org-export-get-ordinal' associates a sequence number to any object
2529 ;; or element.
2531 (defun org-export-get-ordinal
2532 (element info &optional types within-section predicate)
2533 "Return ordinal number of an element or object.
2535 ELEMENT is the element or object considered. INFO is the plist
2536 used as a communication channel.
2538 Optional argument TYPES, when non-nil, is a list of element or
2539 object types, as symbols, that should also be counted in.
2540 Otherwise, only provided element's type is considered.
2542 When optional argument WITHIN-SECTION is non-nil, narrow counting
2543 to the section containing ELEMENT.
2545 Optional argument PREDICATE is a function returning a non-nil
2546 value if the current element or object should be counted in. It
2547 accepts one argument: the element or object being considered.
2548 This argument allows to count only a certain type of objects,
2549 like inline images, which are a subset of links \(in that case,
2550 `org-export-inline-image-p' might be an useful predicate\)."
2551 (let ((counter 0)
2552 ;; Determine if search should apply to current section, in
2553 ;; which case it should be retrieved first, or to full parse
2554 ;; tree. As a special case, an element or object without
2555 ;; a parent headline will also trigger a full search,
2556 ;; notwithstanding WITHIN-SECTION value.
2557 (data
2558 (if (not within-section) (plist-get info :parse-tree)
2559 (or (org-export-get-parent-headline element info)
2560 (plist-get info :parse-tree)))))
2561 ;; Increment counter until ELEMENT is found again.
2562 (org-element-map
2563 data (or types (car element))
2564 (lambda (el local)
2565 (cond
2566 ((equal element el) (1+ counter))
2567 ((not predicate) (incf counter) nil)
2568 ((funcall predicate el) (incf counter) nil)))
2569 info 'first-match)))
2572 ;;;; For Src-Blocks
2574 ;; `org-export-get-loc' counts number of code lines accumulated in
2575 ;; src-block or example-block elements with a "+n" switch until
2576 ;; a given element, excluded. Note: "-n" switches reset that count.
2578 ;; `org-export-handle-code' takes care of line numbering and reference
2579 ;; cleaning in source code, when appropriate.
2581 (defun org-export-get-loc (element info)
2582 "Return accumulated lines of code up to ELEMENT.
2584 INFO is the plist used as a communication channel.
2586 ELEMENT is excluded from count."
2587 (let ((loc 0))
2588 (org-element-map
2589 (plist-get info :parse-tree) `(src-block example-block ,(car element))
2590 (lambda (el local)
2591 (cond
2592 ;; ELEMENT is reached: Quit the loop.
2593 ((equal el element) t)
2594 ;; Only count lines from src-block and example-block elements
2595 ;; with a "+n" or "-n" switch. A "-n" switch resets counter.
2596 ((not (memq (car el) '(src-block example-block))) nil)
2597 ((let ((switches (org-element-get-property :switches el)))
2598 (when (and switches (string-match "\\([-+]\\)n\\>" switches))
2599 ;; Accumulate locs or reset them.
2600 (let ((accumulatep (string= (match-string 1 switches) "-"))
2601 (lines (org-count-lines
2602 (org-trim (org-element-get-property :value el)))))
2603 (setq loc (if accumulatep lines (+ loc lines))))))
2604 ;; Return nil to stay in the loop.
2605 nil)))
2606 info 'first-match)
2607 ;; Return value.
2608 loc))
2610 (defun org-export-handle-code (element info &optional num-fmt ref-fmt delayed)
2611 "Handle line numbers and code references in ELEMENT.
2613 ELEMENT has either a `src-block' an `example-block' type. INFO
2614 is a plist used as a communication channel.
2616 If optional argument NUM-FMT is a string, it will be used as
2617 a format string for numbers at beginning of each line.
2619 If optional argument REF-FMT is a string, it will be used as
2620 a format string for each line of code containing a reference.
2622 When optional argument DELAYED is non-nil, `org-loc' and
2623 `org-coderef' properties, set to an adequate value, are applied
2624 to, respectively, numbered lines and lines with a reference. No
2625 line numbering is done and all references are stripped from the
2626 resulting string. Both NUM-FMT and REF-FMT arguments are ignored
2627 in that situation.
2629 Return new code as a string."
2630 (let* ((switches (or (org-element-get-property :switches element) ""))
2631 (code (org-element-get-property :value element))
2632 (numberp (string-match "[-+]n\\>" switches))
2633 (accumulatep (string-match "\\+n\\>" switches))
2634 ;; Initialize loc counter when any kind of numbering is
2635 ;; active.
2636 (total-LOC (cond
2637 (accumulatep (org-export-get-loc element info))
2638 (numberp 0)))
2639 ;; Get code and clean it. Remove blank lines at its
2640 ;; beginning and end. Also remove protective commas.
2641 (preserve-indent-p (or org-src-preserve-indentation
2642 (string-match "-i\\>" switches)))
2643 (replace-labels (when (string-match "-r\\>" switches)
2644 (if (string-match "-k\\>" switches) 'keep t)))
2645 (code (let ((c (replace-regexp-in-string
2646 "\\`\\([ \t]*\n\\)+" ""
2647 (replace-regexp-in-string
2648 "\\(:?[ \t]*\n\\)*[ \t]*\\'" "\n" code))))
2649 ;; If appropriate, remove global indentation.
2650 (unless preserve-indent-p (setq c (org-remove-indentation c)))
2651 ;; Free up the protected lines. Note: Org blocks
2652 ;; have commas at the beginning or every line.
2653 (if (string=
2654 (or (org-element-get-property :language element) "")
2655 "org")
2656 (replace-regexp-in-string "^," "" c)
2657 (replace-regexp-in-string
2658 "^\\(,\\)\\(:?\\*\\|[ \t]*#\\+\\)" "" c nil nil 1))))
2659 ;; Split code to process it line by line.
2660 (code-lines (org-split-string code "\n"))
2661 ;; If numbering is active, ensure line numbers will be
2662 ;; correctly padded before applying the format string.
2663 (num-fmt
2664 (when (and (not delayed) numberp)
2665 (format (if (stringp num-fmt) num-fmt "%s: ")
2666 (format "%%%ds"
2667 (length (number-to-string
2668 (+ (length code-lines) total-LOC)))))))
2669 ;; Get format used for references.
2670 (label-fmt (or (and (string-match "-l +\"\\([^\"\n]+\\)\"" switches)
2671 (match-string 1 switches))
2672 org-coderef-label-format))
2673 ;; Build a regexp matching a loc with a reference.
2674 (with-ref-re (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
2675 (replace-regexp-in-string
2676 "%s" "\\([-a-zA-Z0-9_ ]+\\)" label-fmt nil t))))
2677 (org-element-normalize-string
2678 (mapconcat
2679 (lambda (loc)
2680 ;; Maybe add line number to current line of code (LOC).
2681 (when numberp
2682 (incf total-LOC)
2683 (setq loc (if delayed (org-add-props loc nil 'org-loc total-LOC)
2684 (concat (format num-fmt total-LOC) loc))))
2685 ;; Take action if at a ref line.
2686 (when (string-match with-ref-re loc)
2687 (let ((ref (match-string 3 loc)))
2688 (setq loc
2689 ;; Option "-r" without "-k" removes labels.
2690 ;; A non-nil DELAYED removes labels unconditionally.
2691 (if (or delayed
2692 (and replace-labels (not (eq replace-labels 'keep))))
2693 (replace-match "" nil nil loc 1)
2694 (replace-match (format "(%s)" ref) nil nil loc 2)))
2695 ;; Store REF in `org-coderef' property if DELAYED asks to.
2696 (cond (delayed (setq loc (org-add-props loc nil 'org-coderef ref)))
2697 ;; If REF-FMT is defined, apply it to current LOC.
2698 ((stringp ref-fmt) (setq loc (format ref-fmt loc))))))
2699 ;; Return updated LOC for concatenation.
2700 loc)
2701 code-lines "\n"))))
2704 ;;;; For Tables
2706 ;; `org-export-table-format-info' extracts formatting information
2707 ;; (alignment, column groups and presence of a special column) from
2708 ;; a raw table and returns it as a property list.
2710 ;; `org-export-clean-table' cleans the raw table from any Org
2711 ;; table-specific syntax.
2713 (defun org-export-table-format-info (table)
2714 "Extract info from TABLE.
2715 Return a plist whose properties and values are:
2716 `:alignment' vector of strings among \"r\", \"l\" and \"c\",
2717 `:column-groups' vector of symbols among `start', `end', `start-end',
2718 `:row-groups' list of integers representing row groups.
2719 `:special-column-p' non-nil if table has a special column.
2720 `:width' vector of integers representing desired width of
2721 current column, or nil."
2722 (with-temp-buffer
2723 (insert table)
2724 (goto-char 1)
2725 (org-table-align)
2726 (let ((align (vconcat (mapcar (lambda (c) (if c "r" "l"))
2727 org-table-last-alignment)))
2728 (width (make-vector (length org-table-last-alignment) nil))
2729 (colgroups (make-vector (length org-table-last-alignment) nil))
2730 (row-group 0)
2731 (rowgroups)
2732 (special-column-p 'empty))
2733 (mapc (lambda (row)
2734 (if (string-match "^[ \t]*|[-+]+|[ \t]*$" row)
2735 (incf row-group)
2736 ;; Determine if a special column is present by looking
2737 ;; for special markers in the first column. More
2738 ;; accurately, the first column is considered special
2739 ;; if it only contains special markers and, maybe,
2740 ;; empty cells.
2741 (setq special-column-p
2742 (cond
2743 ((not special-column-p) nil)
2744 ((string-match "^[ \t]*| *\\\\?\\([/#!$*_^]\\) *|" row)
2745 'special)
2746 ((string-match "^[ \t]*| +|" row) special-column-p))))
2747 (cond
2748 ;; Read forced alignment and width information, if any,
2749 ;; and determine final alignment for the table.
2750 ((org-table-cookie-line-p row)
2751 (let ((col 0))
2752 (mapc (lambda (field)
2753 (when (string-match
2754 "<\\([lrc]\\)?\\([0-9]+\\)?>" field)
2755 (let ((align-data (match-string 1 field)))
2756 (when align-data (aset align col align-data)))
2757 (let ((w-data (match-string 2 field)))
2758 (when w-data
2759 (aset width col (string-to-number w-data)))))
2760 (incf col))
2761 (org-split-string row "[ \t]*|[ \t]*"))))
2762 ;; Read column groups information.
2763 ((org-table-colgroup-line-p row)
2764 (let ((col 0))
2765 (mapc (lambda (field)
2766 (aset colgroups col
2767 (cond ((string= "<" field) 'start)
2768 ((string= ">" field) 'end)
2769 ((string= "<>" field) 'start-end)))
2770 (incf col))
2771 (org-split-string row "[ \t]*|[ \t]*"))))
2772 ;; Contents line.
2773 (t (push row-group rowgroups))))
2774 (org-split-string table "\n"))
2775 ;; Return plist.
2776 (list :alignment align
2777 :column-groups colgroups
2778 :row-groups (reverse rowgroups)
2779 :special-column-p (eq special-column-p 'special)
2780 :width width))))
2782 (defun org-export-clean-table (table specialp)
2783 "Clean string TABLE from its formatting elements.
2784 Remove any row containing column groups or formatting cookies and
2785 rows starting with a special marker. If SPECIALP is non-nil,
2786 assume the table contains a special formatting column and remove
2787 it also."
2788 (let ((rows (org-split-string table "\n")))
2789 (mapconcat 'identity
2790 (delq nil
2791 (mapcar
2792 (lambda (row)
2793 (cond
2794 ((org-table-colgroup-line-p row) nil)
2795 ((org-table-cookie-line-p row) nil)
2796 ;; Ignore rows starting with a special marker.
2797 ((string-match "^[ \t]*| *[!_^/] *|" row) nil)
2798 ;; Remove special column.
2799 ((and specialp
2800 (or (string-match "^\\([ \t]*\\)|-+\\+" row)
2801 (string-match "^\\([ \t]*\\)|[^|]*|" row)))
2802 (replace-match "\\1|" t nil row))
2803 (t row)))
2804 rows))
2805 "\n")))
2808 ;;;; For Tables Of Contents
2810 ;; `org-export-collect-headlines' builds a list of all exportable
2811 ;; headline elements, maybe limited to a certain depth. One can then
2812 ;; easily parse it and transcode it.
2814 ;; Building lists of tables, figures or listings is quite similar.
2815 ;; Once the generic function `org-export-collect-elements' is defined,
2816 ;; `org-export-collect-tables', `org-export-collect-figures' and
2817 ;; `org-export-collect-listings' can be derived from it.
2819 (defun org-export-collect-headlines (info &optional n)
2820 "Collect headlines in order to build a table of contents.
2822 INFO is a plist used as a communication channel.
2824 When non-nil, optional argument N must be an integer. It
2825 specifies the depth of the table of contents.
2827 Return a list of all exportable headlines as parsed elements."
2828 (org-element-map
2829 (plist-get info :parse-tree)
2830 'headline
2831 (lambda (headline local)
2832 ;; Strip contents from HEADLINE.
2833 (let ((relative-level (org-export-get-relative-level headline local)))
2834 (unless (and n (> relative-level n)) headline)))
2835 info))
2837 (defun org-export-collect-elements (type info &optional predicate)
2838 "Collect referenceable elements of a determined type.
2840 TYPE can be a symbol or a list of symbols specifying element
2841 types to search. Only elements with a caption or a name are
2842 collected.
2844 INFO is a plist used as a communication channel.
2846 When non-nil, optional argument PREDICATE is a function accepting
2847 one argument, an element of type TYPE. It returns a non-nil
2848 value when that element should be collected.
2850 Return a list of all elements found, in order of appearance."
2851 (org-element-map
2852 (plist-get info :parse-tree) type
2853 (lambda (element local)
2854 (and (or (org-element-get-property :caption element)
2855 (org-element-get-property :name element))
2856 (or (not predicate) (funcall predicate element))
2857 element)) info))
2859 (defun org-export-collect-tables (info)
2860 "Build a list of tables.
2862 INFO is a plist used as a communication channel.
2864 Return a list of table elements with a caption or a name
2865 affiliated keyword."
2866 (org-export-collect-elements 'table info))
2868 (defun org-export-collect-figures (info predicate)
2869 "Build a list of figures.
2871 INFO is a plist used as a communication channel. PREDICATE is
2872 a function which accepts one argument: a paragraph element and
2873 whose return value is non-nil when that element should be
2874 collected.
2876 A figure is a paragraph type element, with a caption or a name,
2877 verifying PREDICATE. The latter has to be provided since
2878 a \"figure\" is a vague concept that may depend on back-end.
2880 Return a list of elements recognized as figures."
2881 (org-export-collect-elements 'paragraph info predicate))
2883 (defun org-export-collect-listings (info)
2884 "Build a list of src blocks.
2886 INFO is a plist used as a communication channel.
2888 Return a list of src-block elements with a caption or a name
2889 affiliated keyword."
2890 (org-export-collect-elements 'src-block info))
2893 ;;;; Topology
2895 (defun org-export-get-parent-headline (blob info)
2896 "Return BLOB's closest parent headline or nil.
2897 INFO is a plist used as a communication channel."
2898 (catch 'exit
2899 (mapc
2900 (lambda (el) (when (eq (car el) 'headline) (throw 'exit el)))
2901 (plist-get info :genealogy))
2902 nil))
2904 (defun org-export-get-previous-element (blob info)
2905 "Return previous element or object.
2907 BLOB is an element or object. INFO is a plist used as
2908 a communication channel.
2910 Return previous element or object, a string, or nil."
2911 (let ((parent (car (plist-get info :genealogy))))
2912 (cadr (member blob (reverse (org-element-get-contents parent))))))
2914 (defun org-export-get-next-element (blob info)
2915 "Return next element or object.
2917 BLOB is an element or object. INFO is a plist used as
2918 a communication channel.
2920 Return next element or object, a string, or nil."
2921 (let ((parent (car (plist-get info :genealogy))))
2922 (cadr (member blob (org-element-get-contents parent)))))
2926 ;;; The Dispatcher
2928 ;; `org-export-dispatch' is the standard interactive way to start an
2929 ;; export process. It uses `org-export-dispatch-ui' as a subroutine
2930 ;; for its interface. Most commons back-ends should have an entry in
2931 ;; it.
2933 (defun org-export-dispatch ()
2934 "Export dispatcher for Org mode.
2936 It provides an access to common export related tasks in a buffer.
2937 Its interface comes in two flavours: standard and expert. While
2938 both share the same set of bindings, only the former displays the
2939 valid keys associations. Set `org-export-dispatch-use-expert-ui'
2940 to switch to one or the other.
2942 Return an error if key pressed has no associated command."
2943 (interactive)
2944 (let* ((input (org-export-dispatch-ui
2945 (if (listp org-export-initial-scope) org-export-initial-scope
2946 (list org-export-initial-scope))
2947 org-export-dispatch-use-expert-ui))
2948 (raw-key (car input))
2949 (scope (cdr input)))
2950 ;; Translate "C-a", "C-b"... into "a", "b"... Then take action
2951 ;; depending on user's key pressed.
2952 (case (if (< raw-key 27) (+ raw-key 96) raw-key)
2953 ;; Export with `e-ascii' back-end.
2954 ((?A ?N ?U)
2955 (let ((outbuf
2956 (org-export-to-buffer
2957 'e-ascii "*Org E-ASCII Export*"
2958 (memq 'subtree scope) (memq 'visible scope) (memq 'body scope)
2959 `(:ascii-charset
2960 ,(case raw-key (?A 'ascii) (?N 'latin1) (t 'utf-8))))))
2961 (with-current-buffer outbuf (text-mode))
2962 (when org-export-show-temporary-export-buffer
2963 (switch-to-buffer-other-window outbuf))))
2964 ((?a ?n ?u)
2965 (org-e-ascii-export-to-ascii
2966 (memq 'subtree scope) (memq 'visible scope) (memq 'body scope)
2967 `(:ascii-charset ,(case raw-key (?a 'ascii) (?n 'latin1) (t 'utf-8)))))
2968 ;; Export with `e-latex' back-end.
2970 (let ((outbuf
2971 (org-export-to-buffer
2972 'e-latex "*Org E-LaTeX Export*"
2973 (memq 'subtree scope) (memq 'visible scope) (memq 'body scope))))
2974 (with-current-buffer outbuf (latex-mode))
2975 (when org-export-show-temporary-export-buffer
2976 (switch-to-buffer-other-window outbuf))))
2977 (?l (org-e-latex-export-to-latex
2978 (memq 'subtree scope) (memq 'visible scope) (memq 'body scope)))
2979 (?p (org-e-latex-export-to-pdf
2980 (memq 'subtree scope) (memq 'visible scope) (memq 'body scope)))
2981 (?d (org-open-file
2982 (org-e-latex-export-to-pdf
2983 (memq 'subtree scope) (memq 'visible scope) (memq 'body scope))))
2984 ;; Undefined command.
2985 (t (error "No command associated with key %s"
2986 (char-to-string raw-key))))))
2988 (defun org-export-dispatch-ui (scope expertp)
2989 "Handle interface for `org-export-dispatch'.
2991 SCOPE is a list containing current interactive options set for
2992 export. It can contain any of the following symbols:
2993 `body' toggles a body-only export
2994 `subtree' restricts export to current subtree
2995 `visible' restricts export to visible part of buffer.
2997 EXPERTP, when non-nil, triggers expert UI. In that case, no help
2998 buffer is provided, but indications about currently active
2999 options are given in the prompt. Moreover, \[?] allows to switch
3000 back to standard interface.
3002 Return value is a list with key pressed as car and a list of
3003 final interactive export options as cdr."
3004 (let ((help (format "------------------- General Options --------------------
3005 \[1] Body only: %s
3006 \[2] Export scope: %s
3007 \[3] Visible only: %s
3009 -------------- ASCII/Latin-1/UTF-8 Export --------------
3010 \[a/n/u] to TXT file [A/N/U] to temporary buffer
3012 --------------------- LaTeX Export ---------------------
3013 \[l] to TEX file [L] to temporary buffer
3014 \[p] to PDF file [d] ... and open it"
3015 (if (memq 'body scope) "On" "Off")
3016 (if (memq 'subtree scope) "Subtree" "Buffer")
3017 (if (memq 'visible scope) "On" "Off")))
3018 (standard-prompt "Export command: ")
3019 (expert-prompt (format "Export command (%s%s%s): "
3020 (if (memq 'body scope) "b" "-")
3021 (if (memq 'subtree scope) "s" "-")
3022 (if (memq 'visible scope) "v" "-")))
3023 (handle-keypress
3024 (function
3025 ;; Read a character from command input, toggling interactive
3026 ;; options when applicable. PROMPT is the displayed prompt,
3027 ;; as a string.
3028 (lambda (prompt)
3029 (let ((key (read-char-exclusive prompt)))
3030 (cond
3031 ;; Ignore non-standard characters (i.e. "M-a").
3032 ((not (characterp key)) (org-export-dispatch-ui scope expertp))
3033 ;; Switch back to standard interface.
3034 ((and (eq key ??) expertp) (org-export-dispatch-ui scope nil))
3035 ((eq key ?1)
3036 (org-export-dispatch-ui
3037 (if (memq 'body scope) (remq 'body scope) (cons 'body scope))
3038 expertp))
3039 ((eq key ?2)
3040 (org-export-dispatch-ui
3041 (if (memq 'subtree scope) (remq 'subtree scope)
3042 (cons 'subtree scope))
3043 expertp))
3044 ((eq key ?3)
3045 (org-export-dispatch-ui
3046 (if (memq 'visible scope) (remq 'visible scope)
3047 (cons 'visible scope))
3048 expertp))
3049 (t (cons key scope))))))))
3050 ;; With expert UI, just read key with a fancy prompt. In standard
3051 ;; UI, display an intrusive help buffer.
3052 (if expertp (funcall handle-keypress expert-prompt)
3053 (save-window-excursion
3054 (delete-other-windows)
3055 (with-output-to-temp-buffer "*Org Export/Publishing Help*" (princ help))
3056 (org-fit-window-to-buffer
3057 (get-buffer-window "*Org Export/Publishing Help*"))
3058 (funcall handle-keypress standard-prompt)))))
3061 (provide 'org-export)
3062 ;;; org-export.el ends here