org.texi: Fix misleading documentation
[org-mode.git] / lisp / ox.el
blob4eb00edb5b40d6fd6738e4dbc505d65f430fcc8b
1 ;;; ox.el --- Generic Export Engine for Org Mode
3 ;; Copyright (C) 2012, 2013 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; GNU Emacs 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 ;; GNU Emacs 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 GNU Emacs. 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 about initial environment
32 ;; or contextual data, all in a single place. The exhaustive list
33 ;; of 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. See "The Filter System"
45 ;; section for more information.
47 ;; The core function is `org-export-as'. It returns the transcoded
48 ;; buffer as a string.
50 ;; An export back-end is defined with `org-export-define-backend',
51 ;; which defines one mandatory information: his translation table.
52 ;; Its value is an alist whose keys are elements and objects types and
53 ;; values translator functions. See function's docstring for more
54 ;; information about translators.
56 ;; Optionally, `org-export-define-backend' can also support specific
57 ;; buffer keywords, OPTION keyword's items and filters. Also refer to
58 ;; function documentation for more information.
60 ;; If the new back-end shares most properties with another one,
61 ;; `org-export-define-derived-backend' can be used to simplify the
62 ;; process.
64 ;; Any back-end can define its own variables. Among them, those
65 ;; customizable should belong to the `org-export-BACKEND' group.
67 ;; Tools for common tasks across back-ends are implemented in the
68 ;; following part of the file.
70 ;; Then, a wrapper macro for asynchronous export,
71 ;; `org-export-async-start', along with tools to display results. are
72 ;; given in the penultimate part.
74 ;; Eventually, a dispatcher (`org-export-dispatch') for standard
75 ;; back-ends is provided in the last one.
77 ;;; Code:
79 (eval-when-compile (require 'cl))
80 (require 'org-element)
81 (require 'org-macro)
82 (require 'ob-exp)
84 (declare-function org-publish "ox-publish" (project &optional force async))
85 (declare-function org-publish-all "ox-publish" (&optional force async))
86 (declare-function
87 org-publish-current-file "ox-publish" (&optional force async))
88 (declare-function org-publish-current-project "ox-publish"
89 (&optional force async))
91 (defvar org-publish-project-alist)
92 (defvar org-table-number-fraction)
93 (defvar org-table-number-regexp)
97 ;;; Internal Variables
99 ;; Among internal variables, the most important is
100 ;; `org-export-options-alist'. This variable define the global export
101 ;; options, shared between every exporter, and how they are acquired.
103 (defconst org-export-max-depth 19
104 "Maximum nesting depth for headlines, counting from 0.")
106 (defconst org-export-options-alist
107 '((:author "AUTHOR" nil user-full-name t)
108 (:creator "CREATOR" nil org-export-creator-string)
109 (:date "DATE" nil nil t)
110 (:description "DESCRIPTION" nil nil newline)
111 (:email "EMAIL" nil user-mail-address t)
112 (:exclude-tags "EXCLUDE_TAGS" nil org-export-exclude-tags split)
113 (:headline-levels nil "H" org-export-headline-levels)
114 (:keywords "KEYWORDS" nil nil space)
115 (:language "LANGUAGE" nil org-export-default-language t)
116 (:preserve-breaks nil "\\n" org-export-preserve-breaks)
117 (:section-numbers nil "num" org-export-with-section-numbers)
118 (:select-tags "SELECT_TAGS" nil org-export-select-tags split)
119 (:time-stamp-file nil "timestamp" org-export-time-stamp-file)
120 (:title "TITLE" nil nil space)
121 (:with-archived-trees nil "arch" org-export-with-archived-trees)
122 (:with-author nil "author" org-export-with-author)
123 (:with-clocks nil "c" org-export-with-clocks)
124 (:with-creator nil "creator" org-export-with-creator)
125 (:with-date nil "date" org-export-with-date)
126 (:with-drawers nil "d" org-export-with-drawers)
127 (:with-email nil "email" org-export-with-email)
128 (:with-emphasize nil "*" org-export-with-emphasize)
129 (:with-entities nil "e" org-export-with-entities)
130 (:with-fixed-width nil ":" org-export-with-fixed-width)
131 (:with-footnotes nil "f" org-export-with-footnotes)
132 (:with-inlinetasks nil "inline" org-export-with-inlinetasks)
133 (:with-latex nil "tex" org-export-with-latex)
134 (:with-planning nil "p" org-export-with-planning)
135 (:with-priority nil "pri" org-export-with-priority)
136 (:with-smart-quotes nil "'" org-export-with-smart-quotes)
137 (:with-special-strings nil "-" org-export-with-special-strings)
138 (:with-statistics-cookies nil "stat" org-export-with-statistics-cookies)
139 (:with-sub-superscript nil "^" org-export-with-sub-superscripts)
140 (:with-toc nil "toc" org-export-with-toc)
141 (:with-tables nil "|" org-export-with-tables)
142 (:with-tags nil "tags" org-export-with-tags)
143 (:with-tasks nil "tasks" org-export-with-tasks)
144 (:with-timestamps nil "<" org-export-with-timestamps)
145 (:with-todo-keywords nil "todo" org-export-with-todo-keywords))
146 "Alist between export properties and ways to set them.
148 The CAR of the alist is the property name, and the CDR is a list
149 like (KEYWORD OPTION DEFAULT BEHAVIOUR) where:
151 KEYWORD is a string representing a buffer keyword, or nil. Each
152 property defined this way can also be set, during subtree
153 export, through a headline property named after the keyword
154 with the \"EXPORT_\" prefix (i.e. DATE keyword and EXPORT_DATE
155 property).
156 OPTION is a string that could be found in an #+OPTIONS: line.
157 DEFAULT is the default value for the property.
158 BEHAVIOUR determines how Org should handle multiple keywords for
159 the same property. It is a symbol among:
160 nil Keep old value and discard the new one.
161 t Replace old value with the new one.
162 `space' Concatenate the values, separating them with a space.
163 `newline' Concatenate the values, separating them with
164 a newline.
165 `split' Split values at white spaces, and cons them to the
166 previous list.
168 Values set through KEYWORD and OPTION have precedence over
169 DEFAULT.
171 All these properties should be back-end agnostic. Back-end
172 specific properties are set through `org-export-define-backend'.
173 Properties redefined there have precedence over these.")
175 (defconst org-export-special-keywords '("FILETAGS" "SETUPFILE" "OPTIONS")
176 "List of in-buffer keywords that require special treatment.
177 These keywords are not directly associated to a property. The
178 way they are handled must be hard-coded into
179 `org-export--get-inbuffer-options' function.")
181 (defconst org-export-filters-alist
182 '((:filter-bold . org-export-filter-bold-functions)
183 (:filter-babel-call . org-export-filter-babel-call-functions)
184 (:filter-center-block . org-export-filter-center-block-functions)
185 (:filter-clock . org-export-filter-clock-functions)
186 (:filter-code . org-export-filter-code-functions)
187 (:filter-comment . org-export-filter-comment-functions)
188 (:filter-comment-block . org-export-filter-comment-block-functions)
189 (:filter-diary-sexp . org-export-filter-diary-sexp-functions)
190 (:filter-drawer . org-export-filter-drawer-functions)
191 (:filter-dynamic-block . org-export-filter-dynamic-block-functions)
192 (:filter-entity . org-export-filter-entity-functions)
193 (:filter-example-block . org-export-filter-example-block-functions)
194 (:filter-export-block . org-export-filter-export-block-functions)
195 (:filter-export-snippet . org-export-filter-export-snippet-functions)
196 (:filter-final-output . org-export-filter-final-output-functions)
197 (:filter-fixed-width . org-export-filter-fixed-width-functions)
198 (:filter-footnote-definition . org-export-filter-footnote-definition-functions)
199 (:filter-footnote-reference . org-export-filter-footnote-reference-functions)
200 (:filter-headline . org-export-filter-headline-functions)
201 (:filter-horizontal-rule . org-export-filter-horizontal-rule-functions)
202 (:filter-inline-babel-call . org-export-filter-inline-babel-call-functions)
203 (:filter-inline-src-block . org-export-filter-inline-src-block-functions)
204 (:filter-inlinetask . org-export-filter-inlinetask-functions)
205 (:filter-italic . org-export-filter-italic-functions)
206 (:filter-item . org-export-filter-item-functions)
207 (:filter-keyword . org-export-filter-keyword-functions)
208 (:filter-latex-environment . org-export-filter-latex-environment-functions)
209 (:filter-latex-fragment . org-export-filter-latex-fragment-functions)
210 (:filter-line-break . org-export-filter-line-break-functions)
211 (:filter-link . org-export-filter-link-functions)
212 (:filter-node-property . org-export-filter-node-property-functions)
213 (:filter-options . org-export-filter-options-functions)
214 (:filter-paragraph . org-export-filter-paragraph-functions)
215 (:filter-parse-tree . org-export-filter-parse-tree-functions)
216 (:filter-plain-list . org-export-filter-plain-list-functions)
217 (:filter-plain-text . org-export-filter-plain-text-functions)
218 (:filter-planning . org-export-filter-planning-functions)
219 (:filter-property-drawer . org-export-filter-property-drawer-functions)
220 (:filter-quote-block . org-export-filter-quote-block-functions)
221 (:filter-quote-section . org-export-filter-quote-section-functions)
222 (:filter-radio-target . org-export-filter-radio-target-functions)
223 (:filter-section . org-export-filter-section-functions)
224 (:filter-special-block . org-export-filter-special-block-functions)
225 (:filter-src-block . org-export-filter-src-block-functions)
226 (:filter-statistics-cookie . org-export-filter-statistics-cookie-functions)
227 (:filter-strike-through . org-export-filter-strike-through-functions)
228 (:filter-subscript . org-export-filter-subscript-functions)
229 (:filter-superscript . org-export-filter-superscript-functions)
230 (:filter-table . org-export-filter-table-functions)
231 (:filter-table-cell . org-export-filter-table-cell-functions)
232 (:filter-table-row . org-export-filter-table-row-functions)
233 (:filter-target . org-export-filter-target-functions)
234 (:filter-timestamp . org-export-filter-timestamp-functions)
235 (:filter-underline . org-export-filter-underline-functions)
236 (:filter-verbatim . org-export-filter-verbatim-functions)
237 (:filter-verse-block . org-export-filter-verse-block-functions))
238 "Alist between filters properties and initial values.
240 The key of each association is a property name accessible through
241 the communication channel. Its value is a configurable global
242 variable defining initial filters.
244 This list is meant to install user specified filters. Back-end
245 developers may install their own filters using
246 `org-export-define-backend'. Filters defined there will always
247 be prepended to the current list, so they always get applied
248 first.")
250 (defconst org-export-default-inline-image-rule
251 `(("file" .
252 ,(format "\\.%s\\'"
253 (regexp-opt
254 '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
255 "xpm" "pbm" "pgm" "ppm") t))))
256 "Default rule for link matching an inline image.
257 This rule applies to links with no description. By default, it
258 will be considered as an inline image if it targets a local file
259 whose extension is either \"png\", \"jpeg\", \"jpg\", \"gif\",
260 \"tiff\", \"tif\", \"xbm\", \"xpm\", \"pbm\", \"pgm\" or \"ppm\".
261 See `org-export-inline-image-p' for more information about
262 rules.")
264 (defvar org-export-async-debug nil
265 "Non-nil means asynchronous export process should leave data behind.
267 This data is found in the appropriate \"*Org Export Process*\"
268 buffer, and in files prefixed with \"org-export-process\" and
269 located in `temporary-file-directory'.
271 When non-nil, it will also set `debug-on-error' to a non-nil
272 value in the external process.")
274 (defvar org-export-stack-contents nil
275 "Record asynchronously generated export results and processes.
276 This is an alist: its CAR is the source of the
277 result (destination file or buffer for a finished process,
278 original buffer for a running one) and its CDR is a list
279 containing the back-end used, as a symbol, and either a process
280 or the time at which it finished. It is used to build the menu
281 from `org-export-stack'.")
283 (defvar org-export-registered-backends nil
284 "List of backends currently available in the exporter.
286 A backend is stored as a list where CAR is its name, as a symbol,
287 and CDR is a plist with the following properties:
288 `:filters-alist', `:menu-entry', `:options-alist' and
289 `:translate-alist'.
291 This variable is set with `org-export-define-backend' and
292 `org-export-define-derived-backend' functions.")
294 (defvar org-export-dispatch-last-action nil
295 "Last command called from the dispatcher.
296 The value should be a list. Its CAR is the action, as a symbol,
297 and its CDR is a list of export options.")
299 (defvar org-export-dispatch-last-position (make-marker)
300 "The position where the last export command was created using the dispatcher.
301 This marker will be used with `C-u C-c C-e' to make sure export repetition
302 uses the same subtree if the previous command was restricted to a subtree.")
304 ;; For compatibility with Org < 8
305 (defvar org-export-current-backend nil
306 "Name, if any, of the back-end used during an export process.
308 Its value is a symbol such as `html', `latex', `ascii', or nil if
309 the back-end is anonymous (see `org-export-create-backend') or if
310 there is no export process in progress.
312 It can be used to teach Babel blocks how to act differently
313 according to the back-end used.")
316 ;;; User-configurable Variables
318 ;; Configuration for the masses.
320 ;; They should never be accessed directly, as their value is to be
321 ;; stored in a property list (cf. `org-export-options-alist').
322 ;; Back-ends will read their value from there instead.
324 (defgroup org-export nil
325 "Options for exporting Org mode files."
326 :tag "Org Export"
327 :group 'org)
329 (defgroup org-export-general nil
330 "General options for export engine."
331 :tag "Org Export General"
332 :group 'org-export)
334 (defcustom org-export-with-archived-trees 'headline
335 "Whether sub-trees with the ARCHIVE tag should be exported.
337 This can have three different values:
338 nil Do not export, pretend this tree is not present.
339 t Do export the entire tree.
340 `headline' Only export the headline, but skip the tree below it.
342 This option can also be set with the OPTIONS keyword,
343 e.g. \"arch:nil\"."
344 :group 'org-export-general
345 :type '(choice
346 (const :tag "Not at all" nil)
347 (const :tag "Headline only" 'headline)
348 (const :tag "Entirely" t)))
350 (defcustom org-export-with-author t
351 "Non-nil means insert author name into the exported file.
352 This option can also be set with the OPTIONS keyword,
353 e.g. \"author:nil\"."
354 :group 'org-export-general
355 :type 'boolean)
357 (defcustom org-export-with-clocks nil
358 "Non-nil means export CLOCK keywords.
359 This option can also be set with the OPTIONS keyword,
360 e.g. \"c:t\"."
361 :group 'org-export-general
362 :type 'boolean)
364 (defcustom org-export-with-creator 'comment
365 "Non-nil means the postamble should contain a creator sentence.
367 The sentence can be set in `org-export-creator-string' and
368 defaults to \"Generated by Org mode XX in Emacs XXX.\".
370 If the value is `comment' insert it as a comment."
371 :group 'org-export-general
372 :type '(choice
373 (const :tag "No creator sentence" nil)
374 (const :tag "Sentence as a comment" 'comment)
375 (const :tag "Insert the sentence" t)))
377 (defcustom org-export-with-date t
378 "Non-nil means insert date in the exported document.
379 This option can also be set with the OPTIONS keyword,
380 e.g. \"date:nil\"."
381 :group 'org-export-general
382 :type 'boolean)
384 (defcustom org-export-date-timestamp-format nil
385 "Time-stamp format string to use for DATE keyword.
387 The format string, when specified, only applies if date consists
388 in a single time-stamp. Otherwise its value will be ignored.
390 See `format-time-string' for details on how to build this
391 string."
392 :group 'org-export-general
393 :type '(choice
394 (string :tag "Time-stamp format string")
395 (const :tag "No format string" nil)))
397 (defcustom org-export-creator-string
398 (format "Emacs %s (Org mode %s)"
399 emacs-version
400 (if (fboundp 'org-version) (org-version) "unknown version"))
401 "Information about the creator of the document.
402 This option can also be set on with the CREATOR keyword."
403 :group 'org-export-general
404 :type '(string :tag "Creator string"))
406 (defcustom org-export-with-drawers '(not "LOGBOOK")
407 "Non-nil means export contents of standard drawers.
409 When t, all drawers are exported. This may also be a list of
410 drawer names to export. If that list starts with `not', only
411 drawers with such names will be ignored.
413 This variable doesn't apply to properties drawers.
415 This option can also be set with the OPTIONS keyword,
416 e.g. \"d:nil\"."
417 :group 'org-export-general
418 :version "24.4"
419 :package-version '(Org . "8.0")
420 :type '(choice
421 (const :tag "All drawers" t)
422 (const :tag "None" nil)
423 (repeat :tag "Selected drawers"
424 (string :tag "Drawer name"))
425 (list :tag "Ignored drawers"
426 (const :format "" not)
427 (repeat :tag "Specify names of drawers to ignore during export"
428 :inline t
429 (string :tag "Drawer name")))))
431 (defcustom org-export-with-email nil
432 "Non-nil means insert author email into the exported file.
433 This option can also be set with the OPTIONS keyword,
434 e.g. \"email:t\"."
435 :group 'org-export-general
436 :type 'boolean)
438 (defcustom org-export-with-emphasize t
439 "Non-nil means interpret *word*, /word/, _word_ and +word+.
441 If the export target supports emphasizing text, the word will be
442 typeset in bold, italic, with an underline or strike-through,
443 respectively.
445 This option can also be set with the OPTIONS keyword,
446 e.g. \"*:nil\"."
447 :group 'org-export-general
448 :type 'boolean)
450 (defcustom org-export-exclude-tags '("noexport")
451 "Tags that exclude a tree from export.
453 All trees carrying any of these tags will be excluded from
454 export. This is without condition, so even subtrees inside that
455 carry one of the `org-export-select-tags' will be removed.
457 This option can also be set with the EXCLUDE_TAGS keyword."
458 :group 'org-export-general
459 :type '(repeat (string :tag "Tag")))
461 (defcustom org-export-with-fixed-width t
462 "Non-nil means lines starting with \":\" will be in fixed width font.
464 This can be used to have pre-formatted text, fragments of code
465 etc. For example:
466 : ;; Some Lisp examples
467 : (while (defc cnt)
468 : (ding))
469 will be looking just like this in also HTML. See also the QUOTE
470 keyword. Not all export backends support this.
472 This option can also be set with the OPTIONS keyword,
473 e.g. \"::nil\"."
474 :group 'org-export-general
475 :type 'boolean)
477 (defcustom org-export-with-footnotes t
478 "Non-nil means Org footnotes should be exported.
479 This option can also be set with the OPTIONS keyword,
480 e.g. \"f:nil\"."
481 :group 'org-export-general
482 :type 'boolean)
484 (defcustom org-export-with-latex t
485 "Non-nil means process LaTeX environments and fragments.
487 This option can also be set with the OPTIONS line,
488 e.g. \"tex:verbatim\". Allowed values are:
490 nil Ignore math snippets.
491 `verbatim' Keep everything in verbatim.
492 t Allow export of math snippets."
493 :group 'org-export-general
494 :version "24.4"
495 :package-version '(Org . "8.0")
496 :type '(choice
497 (const :tag "Do not process math in any way" nil)
498 (const :tag "Interpret math snippets" t)
499 (const :tag "Leave math verbatim" verbatim)))
501 (defcustom org-export-headline-levels 3
502 "The last level which is still exported as a headline.
504 Inferior levels will usually produce itemize or enumerate lists
505 when exported, but back-end behaviour may differ.
507 This option can also be set with the OPTIONS keyword,
508 e.g. \"H:2\"."
509 :group 'org-export-general
510 :type 'integer)
512 (defcustom org-export-default-language "en"
513 "The default language for export and clocktable translations, as a string.
514 This may have an association in
515 `org-clock-clocktable-language-setup'. This option can also be
516 set with the LANGUAGE keyword."
517 :group 'org-export-general
518 :type '(string :tag "Language"))
520 (defcustom org-export-preserve-breaks nil
521 "Non-nil means preserve all line breaks when exporting.
522 This option can also be set with the OPTIONS keyword,
523 e.g. \"\\n:t\"."
524 :group 'org-export-general
525 :type 'boolean)
527 (defcustom org-export-with-entities t
528 "Non-nil means interpret entities when exporting.
530 For example, HTML export converts \\alpha to &alpha; and \\AA to
531 &Aring;.
533 For a list of supported names, see the constant `org-entities'
534 and the user option `org-entities-user'.
536 This option can also be set with the OPTIONS keyword,
537 e.g. \"e:nil\"."
538 :group 'org-export-general
539 :type 'boolean)
541 (defcustom org-export-with-inlinetasks t
542 "Non-nil means inlinetasks should be exported.
543 This option can also be set with the OPTIONS keyword,
544 e.g. \"inline:nil\"."
545 :group 'org-export-general
546 :version "24.4"
547 :package-version '(Org . "8.0")
548 :type 'boolean)
550 (defcustom org-export-with-planning nil
551 "Non-nil means include planning info in export.
553 Planning info is the line containing either SCHEDULED:,
554 DEADLINE:, CLOSED: time-stamps, or a combination of them.
556 This option can also be set with the OPTIONS keyword,
557 e.g. \"p:t\"."
558 :group 'org-export-general
559 :version "24.4"
560 :package-version '(Org . "8.0")
561 :type 'boolean)
563 (defcustom org-export-with-priority nil
564 "Non-nil means include priority cookies in export.
565 This option can also be set with the OPTIONS keyword,
566 e.g. \"pri:t\"."
567 :group 'org-export-general
568 :type 'boolean)
570 (defcustom org-export-with-section-numbers t
571 "Non-nil means add section numbers to headlines when exporting.
573 When set to an integer n, numbering will only happen for
574 headlines whose relative level is higher or equal to n.
576 This option can also be set with the OPTIONS keyword,
577 e.g. \"num:t\"."
578 :group 'org-export-general
579 :type 'boolean)
581 (defcustom org-export-select-tags '("export")
582 "Tags that select a tree for export.
584 If any such tag is found in a buffer, all trees that do not carry
585 one of these tags will be ignored during export. Inside trees
586 that are selected like this, you can still deselect a subtree by
587 tagging it with one of the `org-export-exclude-tags'.
589 This option can also be set with the SELECT_TAGS keyword."
590 :group 'org-export-general
591 :type '(repeat (string :tag "Tag")))
593 (defcustom org-export-with-smart-quotes nil
594 "Non-nil means activate smart quotes during export.
595 This option can also be set with the OPTIONS keyword,
596 e.g., \"':t\".
598 When setting this to non-nil, you need to take care of
599 using the correct Babel package when exporting to LaTeX.
600 E.g., you can load Babel for french like this:
602 #+LATEX_HEADER: \\usepackage[french]{babel}"
603 :group 'org-export-general
604 :version "24.4"
605 :package-version '(Org . "8.0")
606 :type 'boolean)
608 (defcustom org-export-with-special-strings t
609 "Non-nil means interpret \"\\-\", \"--\" and \"---\" for export.
611 When this option is turned on, these strings will be exported as:
613 Org HTML LaTeX UTF-8
614 -----+----------+--------+-------
615 \\- &shy; \\-
616 -- &ndash; -- –
617 --- &mdash; --- —
618 ... &hellip; \\ldots …
620 This option can also be set with the OPTIONS keyword,
621 e.g. \"-:nil\"."
622 :group 'org-export-general
623 :type 'boolean)
625 (defcustom org-export-with-statistics-cookies t
626 "Non-nil means include statistics cookies in export.
627 This option can also be set with the OPTIONS keyword,
628 e.g. \"stat:nil\""
629 :group 'org-export-general
630 :version "24.4"
631 :package-version '(Org . "8.0")
632 :type 'boolean)
634 (defcustom org-export-with-sub-superscripts t
635 "Non-nil means interpret \"_\" and \"^\" for export.
637 When this option is turned on, you can use TeX-like syntax for
638 sub- and superscripts. Several characters after \"_\" or \"^\"
639 will be considered as a single item - so grouping with {} is
640 normally not needed. For example, the following things will be
641 parsed as single sub- or superscripts.
643 10^24 or 10^tau several digits will be considered 1 item.
644 10^-12 or 10^-tau a leading sign with digits or a word
645 x^2-y^3 will be read as x^2 - y^3, because items are
646 terminated by almost any nonword/nondigit char.
647 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
649 Still, ambiguity is possible - so when in doubt use {} to enclose
650 the sub/superscript. If you set this variable to the symbol
651 `{}', the braces are *required* in order to trigger
652 interpretations as sub/superscript. This can be helpful in
653 documents that need \"_\" frequently in plain text.
655 This option can also be set with the OPTIONS keyword,
656 e.g. \"^:nil\"."
657 :group 'org-export-general
658 :type '(choice
659 (const :tag "Interpret them" t)
660 (const :tag "Curly brackets only" {})
661 (const :tag "Do not interpret them" nil)))
663 (defcustom org-export-with-toc t
664 "Non-nil means create a table of contents in exported files.
666 The TOC contains headlines with levels up
667 to`org-export-headline-levels'. When an integer, include levels
668 up to N in the toc, this may then be different from
669 `org-export-headline-levels', but it will not be allowed to be
670 larger than the number of headline levels. When nil, no table of
671 contents is made.
673 This option can also be set with the OPTIONS keyword,
674 e.g. \"toc:nil\" or \"toc:3\"."
675 :group 'org-export-general
676 :type '(choice
677 (const :tag "No Table of Contents" nil)
678 (const :tag "Full Table of Contents" t)
679 (integer :tag "TOC to level")))
681 (defcustom org-export-with-tables t
682 "If non-nil, lines starting with \"|\" define a table.
683 For example:
685 | Name | Address | Birthday |
686 |-------------+----------+-----------|
687 | Arthur Dent | England | 29.2.2100 |
689 This option can also be set with the OPTIONS keyword,
690 e.g. \"|:nil\"."
691 :group 'org-export-general
692 :type 'boolean)
694 (defcustom org-export-with-tags t
695 "If nil, do not export tags, just remove them from headlines.
697 If this is the symbol `not-in-toc', tags will be removed from
698 table of contents entries, but still be shown in the headlines of
699 the document.
701 This option can also be set with the OPTIONS keyword,
702 e.g. \"tags:nil\"."
703 :group 'org-export-general
704 :type '(choice
705 (const :tag "Off" nil)
706 (const :tag "Not in TOC" not-in-toc)
707 (const :tag "On" t)))
709 (defcustom org-export-with-tasks t
710 "Non-nil means include TODO items for export.
712 This may have the following values:
713 t include tasks independent of state.
714 `todo' include only tasks that are not yet done.
715 `done' include only tasks that are already done.
716 nil ignore all tasks.
717 list of keywords include tasks with these keywords.
719 This option can also be set with the OPTIONS keyword,
720 e.g. \"tasks:nil\"."
721 :group 'org-export-general
722 :type '(choice
723 (const :tag "All tasks" t)
724 (const :tag "No tasks" nil)
725 (const :tag "Not-done tasks" todo)
726 (const :tag "Only done tasks" done)
727 (repeat :tag "Specific TODO keywords"
728 (string :tag "Keyword"))))
730 (defcustom org-export-time-stamp-file t
731 "Non-nil means insert a time stamp into the exported file.
732 The time stamp shows when the file was created. This option can
733 also be set with the OPTIONS keyword, e.g. \"timestamp:nil\"."
734 :group 'org-export-general
735 :type 'boolean)
737 (defcustom org-export-with-timestamps t
738 "Non nil means allow timestamps in export.
740 It can be set to any of the following values:
741 t export all timestamps.
742 `active' export active timestamps only.
743 `inactive' export inactive timestamps only.
744 nil do not export timestamps
746 This only applies to timestamps isolated in a paragraph
747 containing only timestamps. Other timestamps are always
748 exported.
750 This option can also be set with the OPTIONS keyword, e.g.
751 \"<:nil\"."
752 :group 'org-export-general
753 :type '(choice
754 (const :tag "All timestamps" t)
755 (const :tag "Only active timestamps" active)
756 (const :tag "Only inactive timestamps" inactive)
757 (const :tag "No timestamp" nil)))
759 (defcustom org-export-with-todo-keywords t
760 "Non-nil means include TODO keywords in export.
761 When nil, remove all these keywords from the export. This option
762 can also be set with the OPTIONS keyword, e.g. \"todo:nil\"."
763 :group 'org-export-general
764 :type 'boolean)
766 (defcustom org-export-allow-bind-keywords nil
767 "Non-nil means BIND keywords can define local variable values.
768 This is a potential security risk, which is why the default value
769 is nil. You can also allow them through local buffer variables."
770 :group 'org-export-general
771 :version "24.4"
772 :package-version '(Org . "8.0")
773 :type 'boolean)
775 (defcustom org-export-snippet-translation-alist nil
776 "Alist between export snippets back-ends and exporter back-ends.
778 This variable allows to provide shortcuts for export snippets.
780 For example, with a value of '\(\(\"h\" . \"html\"\)\), the
781 HTML back-end will recognize the contents of \"@@h:<b>@@\" as
782 HTML code while every other back-end will ignore it."
783 :group 'org-export-general
784 :version "24.4"
785 :package-version '(Org . "8.0")
786 :type '(repeat
787 (cons (string :tag "Shortcut")
788 (string :tag "Back-end"))))
790 (defcustom org-export-coding-system nil
791 "Coding system for the exported file."
792 :group 'org-export-general
793 :version "24.4"
794 :package-version '(Org . "8.0")
795 :type 'coding-system)
797 (defcustom org-export-copy-to-kill-ring 'if-interactive
798 "Should we push exported content to the kill ring?"
799 :group 'org-export-general
800 :version "24.3"
801 :type '(choice
802 (const :tag "Always" t)
803 (const :tag "When export is done interactively" if-interactive)
804 (const :tag "Never" nil)))
806 (defcustom org-export-initial-scope 'buffer
807 "The initial scope when exporting with `org-export-dispatch'.
808 This variable can be either set to `buffer' or `subtree'."
809 :group 'org-export-general
810 :type '(choice
811 (const :tag "Export current buffer" 'buffer)
812 (const :tag "Export current subtree" 'subtree)))
814 (defcustom org-export-show-temporary-export-buffer t
815 "Non-nil means show buffer after exporting to temp buffer.
816 When Org exports to a file, the buffer visiting that file is ever
817 shown, but remains buried. However, when exporting to
818 a temporary buffer, that buffer is popped up in a second window.
819 When this variable is nil, the buffer remains buried also in
820 these cases."
821 :group 'org-export-general
822 :type 'boolean)
824 (defcustom org-export-in-background nil
825 "Non-nil means export and publishing commands will run in background.
826 Results from an asynchronous export are never displayed
827 automatically. But you can retrieve them with \\[org-export-stack]."
828 :group 'org-export-general
829 :version "24.4"
830 :package-version '(Org . "8.0")
831 :type 'boolean)
833 (defcustom org-export-async-init-file user-init-file
834 "File used to initialize external export process.
835 Value must be an absolute file name. It defaults to user's
836 initialization file. Though, a specific configuration makes the
837 process faster and the export more portable."
838 :group 'org-export-general
839 :version "24.4"
840 :package-version '(Org . "8.0")
841 :type '(file :must-match t))
843 (defcustom org-export-invisible-backends nil
844 "List of back-ends that shouldn't appear in the dispatcher.
846 Any back-end belonging to this list or derived from a back-end
847 belonging to it will not appear in the dispatcher menu.
849 Indeed, Org may require some export back-ends without notice. If
850 these modules are never to be used interactively, adding them
851 here will avoid cluttering the dispatcher menu."
852 :group 'org-export-general
853 :version "24.4"
854 :package-version '(Org . "8.0")
855 :type '(repeat (symbol :tag "Back-End")))
857 (defcustom org-export-dispatch-use-expert-ui nil
858 "Non-nil means using a non-intrusive `org-export-dispatch'.
859 In that case, no help buffer is displayed. Though, an indicator
860 for current export scope is added to the prompt (\"b\" when
861 output is restricted to body only, \"s\" when it is restricted to
862 the current subtree, \"v\" when only visible elements are
863 considered for export, \"f\" when publishing functions should be
864 passed the FORCE argument and \"a\" when the export should be
865 asynchronous). Also, \[?] allows to switch back to standard
866 mode."
867 :group 'org-export-general
868 :version "24.4"
869 :package-version '(Org . "8.0")
870 :type 'boolean)
874 ;;; Defining Back-ends
876 ;; `org-export-define-backend' is the standard way to define an export
877 ;; back-end. It allows to specify translators, filters, buffer
878 ;; options and a menu entry. If the new back-end shares translators
879 ;; with another back-end, `org-export-define-derived-backend' may be
880 ;; used instead.
882 ;; Internally, a back-end is stored as a list, of which CAR is the
883 ;; name of the back-end, as a symbol, and CDR a plist. Accessors to
884 ;; properties of a given back-end are: `org-export-backend-filters',
885 ;; `org-export-backend-menu', `org-export-backend-options' and
886 ;; `org-export-backend-translate-table'.
888 ;; Eventually `org-export-barf-if-invalid-backend' returns an error
889 ;; when a given back-end hasn't been registered yet.
891 (defun org-export-define-backend (backend translators &rest body)
892 "Define a new back-end BACKEND.
894 TRANSLATORS is an alist between object or element types and
895 functions handling them.
897 These functions should return a string without any trailing
898 space, or nil. They must accept three arguments: the object or
899 element itself, its contents or nil when it isn't recursive and
900 the property list used as a communication channel.
902 Contents, when not nil, are stripped from any global indentation
903 \(although the relative one is preserved). They also always end
904 with a single newline character.
906 If, for a given type, no function is found, that element or
907 object type will simply be ignored, along with any blank line or
908 white space at its end. The same will happen if the function
909 returns the nil value. If that function returns the empty
910 string, the type will be ignored, but the blank lines or white
911 spaces will be kept.
913 In addition to element and object types, one function can be
914 associated to the `template' (or `inner-template') symbol and
915 another one to the `plain-text' symbol.
917 The former returns the final transcoded string, and can be used
918 to add a preamble and a postamble to document's body. It must
919 accept two arguments: the transcoded string and the property list
920 containing export options. A function associated to `template'
921 will not be applied if export has option \"body-only\".
922 A function associated to `inner-template' is always applied.
924 The latter, when defined, is to be called on every text not
925 recognized as an element or an object. It must accept two
926 arguments: the text string and the information channel. It is an
927 appropriate place to protect special chars relative to the
928 back-end.
930 BODY can start with pre-defined keyword arguments. The following
931 keywords are understood:
933 :export-block
935 String, or list of strings, representing block names that
936 will not be parsed. This is used to specify blocks that will
937 contain raw code specific to the back-end. These blocks
938 still have to be handled by the relative `export-block' type
939 translator.
941 :filters-alist
943 Alist between filters and function, or list of functions,
944 specific to the back-end. See `org-export-filters-alist' for
945 a list of all allowed filters. Filters defined here
946 shouldn't make a back-end test, as it may prevent back-ends
947 derived from this one to behave properly.
949 :menu-entry
951 Menu entry for the export dispatcher. It should be a list
952 like:
954 '(KEY DESCRIPTION-OR-ORDINAL ACTION-OR-MENU)
956 where :
958 KEY is a free character selecting the back-end.
960 DESCRIPTION-OR-ORDINAL is either a string or a number.
962 If it is a string, is will be used to name the back-end in
963 its menu entry. If it is a number, the following menu will
964 be displayed as a sub-menu of the back-end with the same
965 KEY. Also, the number will be used to determine in which
966 order such sub-menus will appear (lowest first).
968 ACTION-OR-MENU is either a function or an alist.
970 If it is an action, it will be called with four
971 arguments (booleans): ASYNC, SUBTREEP, VISIBLE-ONLY and
972 BODY-ONLY. See `org-export-as' for further explanations on
973 some of them.
975 If it is an alist, associations should follow the
976 pattern:
978 '(KEY DESCRIPTION ACTION)
980 where KEY, DESCRIPTION and ACTION are described above.
982 Valid values include:
984 '(?m \"My Special Back-end\" my-special-export-function)
988 '(?l \"Export to LaTeX\"
989 \(?p \"As PDF file\" org-latex-export-to-pdf)
990 \(?o \"As PDF file and open\"
991 \(lambda (a s v b)
992 \(if a (org-latex-export-to-pdf t s v b)
993 \(org-open-file
994 \(org-latex-export-to-pdf nil s v b)))))))
996 or the following, which will be added to the previous
997 sub-menu,
999 '(?l 1
1000 \((?B \"As TEX buffer (Beamer)\" org-beamer-export-as-latex)
1001 \(?P \"As PDF file (Beamer)\" org-beamer-export-to-pdf)))
1003 :options-alist
1005 Alist between back-end specific properties introduced in
1006 communication channel and how their value are acquired. See
1007 `org-export-options-alist' for more information about
1008 structure of the values."
1009 (declare (indent 1))
1010 (let (export-block filters menu-entry options contents)
1011 (while (keywordp (car body))
1012 (case (pop body)
1013 (:export-block (let ((names (pop body)))
1014 (setq export-block
1015 (if (consp names) (mapcar 'upcase names)
1016 (list (upcase names))))))
1017 (:filters-alist (setq filters (pop body)))
1018 (:menu-entry (setq menu-entry (pop body)))
1019 (:options-alist (setq options (pop body)))
1020 (t (pop body))))
1021 (setq contents (append (list :translate-alist translators)
1022 (and filters (list :filters-alist filters))
1023 (and options (list :options-alist options))
1024 (and menu-entry (list :menu-entry menu-entry))))
1025 ;; Register back-end.
1026 (let ((registeredp (assq backend org-export-registered-backends)))
1027 (if registeredp (setcdr registeredp contents)
1028 (push (cons backend contents) org-export-registered-backends)))
1029 ;; Tell parser to not parse EXPORT-BLOCK blocks.
1030 (when export-block
1031 (mapc
1032 (lambda (name)
1033 (add-to-list 'org-element-block-name-alist
1034 `(,name . org-element-export-block-parser)))
1035 export-block))))
1037 (defun org-export-define-derived-backend (child parent &rest body)
1038 "Create a new back-end as a variant of an existing one.
1040 CHILD is the name of the derived back-end. PARENT is the name of
1041 the parent back-end.
1043 BODY can start with pre-defined keyword arguments. The following
1044 keywords are understood:
1046 :export-block
1048 String, or list of strings, representing block names that
1049 will not be parsed. This is used to specify blocks that will
1050 contain raw code specific to the back-end. These blocks
1051 still have to be handled by the relative `export-block' type
1052 translator.
1054 :filters-alist
1056 Alist of filters that will overwrite or complete filters
1057 defined in PARENT back-end. See `org-export-filters-alist'
1058 for a list of allowed filters.
1060 :menu-entry
1062 Menu entry for the export dispatcher. See
1063 `org-export-define-backend' for more information about the
1064 expected value.
1066 :options-alist
1068 Alist of back-end specific properties that will overwrite or
1069 complete those defined in PARENT back-end. Refer to
1070 `org-export-options-alist' for more information about
1071 structure of the values.
1073 :translate-alist
1075 Alist of element and object types and transcoders that will
1076 overwrite or complete transcode table from PARENT back-end.
1077 Refer to `org-export-define-backend' for detailed information
1078 about transcoders.
1080 As an example, here is how one could define \"my-latex\" back-end
1081 as a variant of `latex' back-end with a custom template function:
1083 \(org-export-define-derived-backend 'my-latex 'latex
1084 :translate-alist '((template . my-latex-template-fun)))
1086 The back-end could then be called with, for example:
1088 \(org-export-to-buffer 'my-latex \"*Test my-latex*\")"
1089 (declare (indent 2))
1090 (let (export-block filters menu-entry options translators contents)
1091 (while (keywordp (car body))
1092 (case (pop body)
1093 (:export-block (let ((names (pop body)))
1094 (setq export-block
1095 (if (consp names) (mapcar 'upcase names)
1096 (list (upcase names))))))
1097 (:filters-alist (setq filters (pop body)))
1098 (:menu-entry (setq menu-entry (pop body)))
1099 (:options-alist (setq options (pop body)))
1100 (:translate-alist (setq translators (pop body)))
1101 (t (pop body))))
1102 (setq contents (append
1103 (list :parent parent)
1104 (let ((p-table (org-export-backend-translate-table parent)))
1105 (list :translate-alist (append translators p-table)))
1106 (let ((p-filters (org-export-backend-filters parent)))
1107 (list :filters-alist (append filters p-filters)))
1108 (let ((p-options (org-export-backend-options parent)))
1109 (list :options-alist (append options p-options)))
1110 (and menu-entry (list :menu-entry menu-entry))))
1111 (org-export-barf-if-invalid-backend parent)
1112 ;; Register back-end.
1113 (let ((registeredp (assq child org-export-registered-backends)))
1114 (if registeredp (setcdr registeredp contents)
1115 (push (cons child contents) org-export-registered-backends)))
1116 ;; Tell parser to not parse EXPORT-BLOCK blocks.
1117 (when export-block
1118 (mapc
1119 (lambda (name)
1120 (add-to-list 'org-element-block-name-alist
1121 `(,name . org-element-export-block-parser)))
1122 export-block))))
1124 (defun org-export-backend-parent (backend)
1125 "Return back-end from which BACKEND is derived, or nil."
1126 (plist-get (cdr (assq backend org-export-registered-backends)) :parent))
1128 (defun org-export-backend-filters (backend)
1129 "Return filters for BACKEND."
1130 (plist-get (cdr (assq backend org-export-registered-backends))
1131 :filters-alist))
1133 (defun org-export-backend-menu (backend)
1134 "Return menu entry for BACKEND."
1135 (plist-get (cdr (assq backend org-export-registered-backends))
1136 :menu-entry))
1138 (defun org-export-backend-options (backend)
1139 "Return export options for BACKEND."
1140 (plist-get (cdr (assq backend org-export-registered-backends))
1141 :options-alist))
1143 (defun org-export-backend-translate-table (backend)
1144 "Return translate table for BACKEND."
1145 (plist-get (cdr (assq backend org-export-registered-backends))
1146 :translate-alist))
1148 (defun org-export-barf-if-invalid-backend (backend)
1149 "Signal an error if BACKEND isn't defined."
1150 (unless (org-export-backend-translate-table backend)
1151 (error "Unknown \"%s\" back-end: Aborting export" backend)))
1153 (defun org-export-derived-backend-p (backend &rest backends)
1154 "Non-nil if BACKEND is derived from one of BACKENDS."
1155 (let ((parent backend))
1156 (while (and (not (memq parent backends))
1157 (setq parent (org-export-backend-parent parent))))
1158 parent))
1162 ;;; The Communication Channel
1164 ;; During export process, every function has access to a number of
1165 ;; properties. They are of two types:
1167 ;; 1. Environment options are collected once at the very beginning of
1168 ;; the process, out of the original buffer and configuration.
1169 ;; Collecting them is handled by `org-export-get-environment'
1170 ;; function.
1172 ;; Most environment options are defined through the
1173 ;; `org-export-options-alist' variable.
1175 ;; 2. Tree properties are extracted directly from the parsed tree,
1176 ;; just before export, by `org-export-collect-tree-properties'.
1178 ;; Here is the full list of properties available during transcode
1179 ;; process, with their category and their value type.
1181 ;; + `:author' :: Author's name.
1182 ;; - category :: option
1183 ;; - type :: string
1185 ;; + `:back-end' :: Current back-end used for transcoding.
1186 ;; - category :: tree
1187 ;; - type :: symbol
1189 ;; + `:creator' :: String to write as creation information.
1190 ;; - category :: option
1191 ;; - type :: string
1193 ;; + `:date' :: String to use as date.
1194 ;; - category :: option
1195 ;; - type :: string
1197 ;; + `:description' :: Description text for the current data.
1198 ;; - category :: option
1199 ;; - type :: string
1201 ;; + `:email' :: Author's email.
1202 ;; - category :: option
1203 ;; - type :: string
1205 ;; + `:exclude-tags' :: Tags for exclusion of subtrees from export
1206 ;; process.
1207 ;; - category :: option
1208 ;; - type :: list of strings
1210 ;; + `:export-options' :: List of export options available for current
1211 ;; process.
1212 ;; - category :: none
1213 ;; - type :: list of symbols, among `subtree', `body-only' and
1214 ;; `visible-only'.
1216 ;; + `:exported-data' :: Hash table used for memoizing
1217 ;; `org-export-data'.
1218 ;; - category :: tree
1219 ;; - type :: hash table
1221 ;; + `:filetags' :: List of global tags for buffer. Used by
1222 ;; `org-export-get-tags' to get tags with inheritance.
1223 ;; - category :: option
1224 ;; - type :: list of strings
1226 ;; + `:footnote-definition-alist' :: Alist between footnote labels and
1227 ;; their definition, as parsed data. Only non-inlined footnotes
1228 ;; are represented in this alist. Also, every definition isn't
1229 ;; guaranteed to be referenced in the parse tree. The purpose of
1230 ;; this property is to preserve definitions from oblivion
1231 ;; (i.e. when the parse tree comes from a part of the original
1232 ;; buffer), it isn't meant for direct use in a back-end. To
1233 ;; retrieve a definition relative to a reference, use
1234 ;; `org-export-get-footnote-definition' instead.
1235 ;; - category :: option
1236 ;; - type :: alist (STRING . LIST)
1238 ;; + `:headline-levels' :: Maximum level being exported as an
1239 ;; headline. Comparison is done with the relative level of
1240 ;; headlines in the parse tree, not necessarily with their
1241 ;; actual level.
1242 ;; - category :: option
1243 ;; - type :: integer
1245 ;; + `:headline-offset' :: Difference between relative and real level
1246 ;; of headlines in the parse tree. For example, a value of -1
1247 ;; means a level 2 headline should be considered as level
1248 ;; 1 (cf. `org-export-get-relative-level').
1249 ;; - category :: tree
1250 ;; - type :: integer
1252 ;; + `:headline-numbering' :: Alist between headlines and their
1253 ;; numbering, as a list of numbers
1254 ;; (cf. `org-export-get-headline-number').
1255 ;; - category :: tree
1256 ;; - type :: alist (INTEGER . LIST)
1258 ;; + `:id-alist' :: Alist between ID strings and destination file's
1259 ;; path, relative to current directory. It is used by
1260 ;; `org-export-resolve-id-link' to resolve ID links targeting an
1261 ;; external file.
1262 ;; - category :: option
1263 ;; - type :: alist (STRING . STRING)
1265 ;; + `:ignore-list' :: List of elements and objects that should be
1266 ;; ignored during export.
1267 ;; - category :: tree
1268 ;; - type :: list of elements and objects
1270 ;; + `:input-file' :: Full path to input file, if any.
1271 ;; - category :: option
1272 ;; - type :: string or nil
1274 ;; + `:keywords' :: List of keywords attached to data.
1275 ;; - category :: option
1276 ;; - type :: string
1278 ;; + `:language' :: Default language used for translations.
1279 ;; - category :: option
1280 ;; - type :: string
1282 ;; + `:parse-tree' :: Whole parse tree, available at any time during
1283 ;; transcoding.
1284 ;; - category :: option
1285 ;; - type :: list (as returned by `org-element-parse-buffer')
1287 ;; + `:preserve-breaks' :: Non-nil means transcoding should preserve
1288 ;; all line breaks.
1289 ;; - category :: option
1290 ;; - type :: symbol (nil, t)
1292 ;; + `:section-numbers' :: Non-nil means transcoding should add
1293 ;; section numbers to headlines.
1294 ;; - category :: option
1295 ;; - type :: symbol (nil, t)
1297 ;; + `:select-tags' :: List of tags enforcing inclusion of sub-trees
1298 ;; in transcoding. When such a tag is present, subtrees without
1299 ;; it are de facto excluded from the process. See
1300 ;; `use-select-tags'.
1301 ;; - category :: option
1302 ;; - type :: list of strings
1304 ;; + `:time-stamp-file' :: Non-nil means transcoding should insert
1305 ;; a time stamp in the output.
1306 ;; - category :: option
1307 ;; - type :: symbol (nil, t)
1309 ;; + `:translate-alist' :: Alist between element and object types and
1310 ;; transcoding functions relative to the current back-end.
1311 ;; Special keys `inner-template', `template' and `plain-text' are
1312 ;; also possible.
1313 ;; - category :: option
1314 ;; - type :: alist (SYMBOL . FUNCTION)
1316 ;; + `:with-archived-trees' :: Non-nil when archived subtrees should
1317 ;; also be transcoded. If it is set to the `headline' symbol,
1318 ;; only the archived headline's name is retained.
1319 ;; - category :: option
1320 ;; - type :: symbol (nil, t, `headline')
1322 ;; + `:with-author' :: Non-nil means author's name should be included
1323 ;; in the output.
1324 ;; - category :: option
1325 ;; - type :: symbol (nil, t)
1327 ;; + `:with-clocks' :: Non-nil means clock keywords should be exported.
1328 ;; - category :: option
1329 ;; - type :: symbol (nil, t)
1331 ;; + `:with-creator' :: Non-nil means a creation sentence should be
1332 ;; inserted at the end of the transcoded string. If the value
1333 ;; is `comment', it should be commented.
1334 ;; - category :: option
1335 ;; - type :: symbol (`comment', nil, t)
1337 ;; + `:with-date' :: Non-nil means output should contain a date.
1338 ;; - category :: option
1339 ;; - type :. symbol (nil, t)
1341 ;; + `:with-drawers' :: Non-nil means drawers should be exported. If
1342 ;; its value is a list of names, only drawers with such names
1343 ;; will be transcoded. If that list starts with `not', drawer
1344 ;; with these names will be skipped.
1345 ;; - category :: option
1346 ;; - type :: symbol (nil, t) or list of strings
1348 ;; + `:with-email' :: Non-nil means output should contain author's
1349 ;; email.
1350 ;; - category :: option
1351 ;; - type :: symbol (nil, t)
1353 ;; + `:with-emphasize' :: Non-nil means emphasized text should be
1354 ;; interpreted.
1355 ;; - category :: option
1356 ;; - type :: symbol (nil, t)
1358 ;; + `:with-fixed-width' :: Non-nil if transcoder should interpret
1359 ;; strings starting with a colon as a fixed-with (verbatim) area.
1360 ;; - category :: option
1361 ;; - type :: symbol (nil, t)
1363 ;; + `:with-footnotes' :: Non-nil if transcoder should interpret
1364 ;; footnotes.
1365 ;; - category :: option
1366 ;; - type :: symbol (nil, t)
1368 ;; + `:with-latex' :: Non-nil means `latex-environment' elements and
1369 ;; `latex-fragment' objects should appear in export output. When
1370 ;; this property is set to `verbatim', they will be left as-is.
1371 ;; - category :: option
1372 ;; - type :: symbol (`verbatim', nil, t)
1374 ;; + `:with-planning' :: Non-nil means transcoding should include
1375 ;; planning info.
1376 ;; - category :: option
1377 ;; - type :: symbol (nil, t)
1379 ;; + `:with-priority' :: Non-nil means transcoding should include
1380 ;; priority cookies.
1381 ;; - category :: option
1382 ;; - type :: symbol (nil, t)
1384 ;; + `:with-smart-quotes' :: Non-nil means activate smart quotes in
1385 ;; plain text.
1386 ;; - category :: option
1387 ;; - type :: symbol (nil, t)
1389 ;; + `:with-special-strings' :: Non-nil means transcoding should
1390 ;; interpret special strings in plain text.
1391 ;; - category :: option
1392 ;; - type :: symbol (nil, t)
1394 ;; + `:with-sub-superscript' :: Non-nil means transcoding should
1395 ;; interpret subscript and superscript. With a value of "{}",
1396 ;; only interpret those using curly brackets.
1397 ;; - category :: option
1398 ;; - type :: symbol (nil, {}, t)
1400 ;; + `:with-tables' :: Non-nil means transcoding should interpret
1401 ;; tables.
1402 ;; - category :: option
1403 ;; - type :: symbol (nil, t)
1405 ;; + `:with-tags' :: Non-nil means transcoding should keep tags in
1406 ;; headlines. A `not-in-toc' value will remove them from the
1407 ;; table of contents, if any, nonetheless.
1408 ;; - category :: option
1409 ;; - type :: symbol (nil, t, `not-in-toc')
1411 ;; + `:with-tasks' :: Non-nil means transcoding should include
1412 ;; headlines with a TODO keyword. A `todo' value will only
1413 ;; include headlines with a todo type keyword while a `done'
1414 ;; value will do the contrary. If a list of strings is provided,
1415 ;; only tasks with keywords belonging to that list will be kept.
1416 ;; - category :: option
1417 ;; - type :: symbol (t, todo, done, nil) or list of strings
1419 ;; + `:with-timestamps' :: Non-nil means transcoding should include
1420 ;; time stamps. Special value `active' (resp. `inactive') ask to
1421 ;; export only active (resp. inactive) timestamps. Otherwise,
1422 ;; completely remove them.
1423 ;; - category :: option
1424 ;; - type :: symbol: (`active', `inactive', t, nil)
1426 ;; + `:with-toc' :: Non-nil means that a table of contents has to be
1427 ;; added to the output. An integer value limits its depth.
1428 ;; - category :: option
1429 ;; - type :: symbol (nil, t or integer)
1431 ;; + `:with-todo-keywords' :: Non-nil means transcoding should
1432 ;; include TODO keywords.
1433 ;; - category :: option
1434 ;; - type :: symbol (nil, t)
1437 ;;;; Environment Options
1439 ;; Environment options encompass all parameters defined outside the
1440 ;; scope of the parsed data. They come from five sources, in
1441 ;; increasing precedence order:
1443 ;; - Global variables,
1444 ;; - Buffer's attributes,
1445 ;; - Options keyword symbols,
1446 ;; - Buffer keywords,
1447 ;; - Subtree properties.
1449 ;; The central internal function with regards to environment options
1450 ;; is `org-export-get-environment'. It updates global variables with
1451 ;; "#+BIND:" keywords, then retrieve and prioritize properties from
1452 ;; the different sources.
1454 ;; The internal functions doing the retrieval are:
1455 ;; `org-export--get-global-options',
1456 ;; `org-export--get-buffer-attributes',
1457 ;; `org-export--parse-option-keyword',
1458 ;; `org-export--get-subtree-options' and
1459 ;; `org-export--get-inbuffer-options'
1461 ;; Also, `org-export--install-letbind-maybe' takes care of the part
1462 ;; relative to "#+BIND:" keywords.
1464 (defun org-export-get-environment (&optional backend subtreep ext-plist)
1465 "Collect export options from the current buffer.
1467 Optional argument BACKEND is a symbol specifying which back-end
1468 specific options to read, if any.
1470 When optional argument SUBTREEP is non-nil, assume the export is
1471 done against the current sub-tree.
1473 Third optional argument EXT-PLIST is a property list with
1474 external parameters overriding Org default settings, but still
1475 inferior to file-local settings."
1476 ;; First install #+BIND variables since these must be set before
1477 ;; global options are read.
1478 (dolist (pair (org-export--list-bound-variables))
1479 (org-set-local (car pair) (nth 1 pair)))
1480 ;; Get and prioritize export options...
1481 (org-combine-plists
1482 ;; ... from global variables...
1483 (org-export--get-global-options backend)
1484 ;; ... from an external property list...
1485 ext-plist
1486 ;; ... from in-buffer settings...
1487 (org-export--get-inbuffer-options backend)
1488 ;; ... and from subtree, when appropriate.
1489 (and subtreep (org-export--get-subtree-options backend))
1490 ;; Eventually add misc. properties.
1491 (list
1492 :back-end
1493 backend
1494 :translate-alist
1495 (org-export-backend-translate-table backend)
1496 :footnote-definition-alist
1497 ;; Footnotes definitions must be collected in the original
1498 ;; buffer, as there's no insurance that they will still be in
1499 ;; the parse tree, due to possible narrowing.
1500 (let (alist)
1501 (org-with-wide-buffer
1502 (goto-char (point-min))
1503 (while (re-search-forward org-footnote-definition-re nil t)
1504 (let ((def (save-match-data (org-element-at-point))))
1505 (when (eq (org-element-type def) 'footnote-definition)
1506 (push
1507 (cons (org-element-property :label def)
1508 (let ((cbeg (org-element-property :contents-begin def)))
1509 (when cbeg
1510 (org-element--parse-elements
1511 cbeg (org-element-property :contents-end def)
1512 nil nil nil nil (list 'org-data nil)))))
1513 alist))))
1514 alist))
1515 :id-alist
1516 ;; Collect id references.
1517 (let (alist)
1518 (org-with-wide-buffer
1519 (goto-char (point-min))
1520 (while (re-search-forward "\\[\\[id:\\S-+?\\]" nil t)
1521 (let ((link (org-element-context)))
1522 (when (eq (org-element-type link) 'link)
1523 (let* ((id (org-element-property :path link))
1524 (file (org-id-find-id-file id)))
1525 (when file
1526 (push (cons id (file-relative-name file)) alist)))))))
1527 alist))))
1529 (defun org-export--parse-option-keyword (options &optional backend)
1530 "Parse an OPTIONS line and return values as a plist.
1531 Optional argument BACKEND is a symbol specifying which back-end
1532 specific items to read, if any."
1533 (let* ((all
1534 ;; Priority is given to back-end specific options.
1535 (append (and backend (org-export-backend-options backend))
1536 org-export-options-alist))
1537 plist)
1538 (dolist (option all)
1539 (let ((property (car option))
1540 (item (nth 2 option)))
1541 (when (and item
1542 (not (plist-member plist property))
1543 (string-match (concat "\\(\\`\\|[ \t]\\)"
1544 (regexp-quote item)
1545 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
1546 options))
1547 (setq plist (plist-put plist
1548 property
1549 (car (read-from-string
1550 (match-string 2 options))))))))
1551 plist))
1553 (defun org-export--get-subtree-options (&optional backend)
1554 "Get export options in subtree at point.
1555 Optional argument BACKEND is a symbol specifying back-end used
1556 for export. Return options as a plist."
1557 ;; For each buffer keyword, create a headline property setting the
1558 ;; same property in communication channel. The name for the property
1559 ;; is the keyword with "EXPORT_" appended to it.
1560 (org-with-wide-buffer
1561 (let (prop plist)
1562 ;; Make sure point is at a heading.
1563 (if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t))
1564 ;; Take care of EXPORT_TITLE. If it isn't defined, use headline's
1565 ;; title as its fallback value.
1566 (when (setq prop (or (org-entry-get (point) "EXPORT_TITLE")
1567 (progn (looking-at org-todo-line-regexp)
1568 (org-match-string-no-properties 3))))
1569 (setq plist
1570 (plist-put
1571 plist :title
1572 (org-element-parse-secondary-string
1573 prop (org-element-restriction 'keyword)))))
1574 ;; EXPORT_OPTIONS are parsed in a non-standard way.
1575 (when (setq prop (org-entry-get (point) "EXPORT_OPTIONS"))
1576 (setq plist
1577 (nconc plist (org-export--parse-option-keyword prop backend))))
1578 ;; Handle other keywords. TITLE keyword is excluded as it has
1579 ;; been handled already.
1580 (let ((seen '("TITLE")))
1581 (mapc
1582 (lambda (option)
1583 (let ((property (car option))
1584 (keyword (nth 1 option)))
1585 (when (and keyword (not (member keyword seen)))
1586 (let* ((subtree-prop (concat "EXPORT_" keyword))
1587 ;; Export properties are not case-sensitive.
1588 (value (let ((case-fold-search t))
1589 (org-entry-get (point) subtree-prop))))
1590 (push keyword seen)
1591 (when (and value (not (plist-member plist property)))
1592 (setq plist
1593 (plist-put
1594 plist
1595 property
1596 (cond
1597 ;; Parse VALUE if required.
1598 ((member keyword org-element-document-properties)
1599 (org-element-parse-secondary-string
1600 value (org-element-restriction 'keyword)))
1601 ;; If BEHAVIOUR is `split' expected value is
1602 ;; a list of strings, not a string.
1603 ((eq (nth 4 option) 'split) (org-split-string value))
1604 (t value)))))))))
1605 ;; Look for both general keywords and back-end specific
1606 ;; options, with priority given to the latter.
1607 (append (and backend (org-export-backend-options backend))
1608 org-export-options-alist)))
1609 ;; Return value.
1610 plist)))
1612 (defun org-export--get-inbuffer-options (&optional backend)
1613 "Return current buffer export options, as a plist.
1615 Optional argument BACKEND, when non-nil, is a symbol specifying
1616 which back-end specific options should also be read in the
1617 process.
1619 Assume buffer is in Org mode. Narrowing, if any, is ignored."
1620 (let* (plist
1621 get-options ; For byte-compiler.
1622 (case-fold-search t)
1623 (options (append
1624 ;; Priority is given to back-end specific options.
1625 (and backend (org-export-backend-options backend))
1626 org-export-options-alist))
1627 (regexp (format "^[ \t]*#\\+%s:"
1628 (regexp-opt (nconc (delq nil (mapcar 'cadr options))
1629 org-export-special-keywords))))
1630 (find-opt
1631 (lambda (keyword)
1632 ;; Return property name associated to KEYWORD.
1633 (catch 'exit
1634 (mapc (lambda (option)
1635 (when (equal (nth 1 option) keyword)
1636 (throw 'exit (car option))))
1637 options))))
1638 (get-options
1639 (lambda (&optional files plist)
1640 ;; Recursively read keywords in buffer. FILES is a list
1641 ;; of files read so far. PLIST is the current property
1642 ;; list obtained.
1643 (org-with-wide-buffer
1644 (goto-char (point-min))
1645 (while (re-search-forward regexp nil t)
1646 (let ((element (org-element-at-point)))
1647 (when (eq (org-element-type element) 'keyword)
1648 (let ((key (org-element-property :key element))
1649 (val (org-element-property :value element)))
1650 (cond
1651 ;; Options in `org-export-special-keywords'.
1652 ((equal key "SETUPFILE")
1653 (let ((file (expand-file-name
1654 (org-remove-double-quotes (org-trim val)))))
1655 ;; Avoid circular dependencies.
1656 (unless (member file files)
1657 (with-temp-buffer
1658 (insert (org-file-contents file 'noerror))
1659 (let ((org-inhibit-startup t)) (org-mode))
1660 (setq plist (funcall get-options
1661 (cons file files) plist))))))
1662 ((equal key "OPTIONS")
1663 (setq plist
1664 (org-combine-plists
1665 plist
1666 (org-export--parse-option-keyword val backend))))
1667 ((equal key "FILETAGS")
1668 (setq plist
1669 (org-combine-plists
1670 plist
1671 (list :filetags
1672 (org-uniquify
1673 (append (org-split-string val ":")
1674 (plist-get plist :filetags)))))))
1676 ;; Options in `org-export-options-alist'.
1677 (let* ((prop (funcall find-opt key))
1678 (behaviour (nth 4 (assq prop options))))
1679 (setq plist
1680 (plist-put
1681 plist prop
1682 ;; Handle value depending on specified
1683 ;; BEHAVIOUR.
1684 (case behaviour
1685 (space
1686 (if (not (plist-get plist prop))
1687 (org-trim val)
1688 (concat (plist-get plist prop)
1690 (org-trim val))))
1691 (newline
1692 (org-trim (concat (plist-get plist prop)
1693 "\n"
1694 (org-trim val))))
1695 (split `(,@(plist-get plist prop)
1696 ,@(org-split-string val)))
1697 ('t val)
1698 (otherwise
1699 (if (not (plist-member plist prop)) val
1700 (plist-get plist prop)))))))))))))
1701 ;; Return final value.
1702 plist))))
1703 ;; Read options in the current buffer.
1704 (setq plist
1705 (funcall get-options
1706 (and buffer-file-name (list buffer-file-name)) nil))
1707 ;; Parse keywords specified in `org-element-document-properties'.
1708 (mapc (lambda (keyword)
1709 ;; Find the property associated to the keyword.
1710 (let* ((prop (funcall find-opt keyword))
1711 (value (and prop (plist-get plist prop))))
1712 (when (stringp value)
1713 (setq plist
1714 (plist-put plist prop
1715 (org-element-parse-secondary-string
1716 value (org-element-restriction 'keyword)))))))
1717 org-element-document-properties)
1718 ;; Return value.
1719 plist))
1721 (defun org-export--get-buffer-attributes ()
1722 "Return properties related to buffer attributes, as a plist."
1723 ;; Store full path of input file name, or nil. For internal use.
1724 (let ((visited-file (buffer-file-name (buffer-base-buffer))))
1725 (list :input-file visited-file
1726 :title (if (not visited-file) (buffer-name (buffer-base-buffer))
1727 (file-name-sans-extension
1728 (file-name-nondirectory visited-file))))))
1730 (defun org-export--get-global-options (&optional backend)
1731 "Return global export options as a plist.
1732 Optional argument BACKEND, if non-nil, is a symbol specifying
1733 which back-end specific export options should also be read in the
1734 process."
1735 (let (plist
1736 ;; Priority is given to back-end specific options.
1737 (all (append (and backend (org-export-backend-options backend))
1738 org-export-options-alist)))
1739 (dolist (cell all plist)
1740 (let ((prop (car cell))
1741 (default-value (nth 3 cell)))
1742 (unless (or (not default-value) (plist-member plist prop))
1743 (setq plist
1744 (plist-put
1745 plist
1746 prop
1747 ;; Eval default value provided. If keyword is
1748 ;; a member of `org-element-document-properties',
1749 ;; parse it as a secondary string before storing it.
1750 (let ((value (eval (nth 3 cell))))
1751 (if (not (stringp value)) value
1752 (let ((keyword (nth 1 cell)))
1753 (if (member keyword org-element-document-properties)
1754 (org-element-parse-secondary-string
1755 value (org-element-restriction 'keyword))
1756 value)))))))))))
1758 (defun org-export--list-bound-variables ()
1759 "Return variables bound from BIND keywords in current buffer.
1760 Also look for BIND keywords in setup files. The return value is
1761 an alist where associations are (VARIABLE-NAME VALUE)."
1762 (when org-export-allow-bind-keywords
1763 (let* (collect-bind ; For byte-compiler.
1764 (collect-bind
1765 (lambda (files alist)
1766 ;; Return an alist between variable names and their
1767 ;; value. FILES is a list of setup files names read so
1768 ;; far, used to avoid circular dependencies. ALIST is
1769 ;; the alist collected so far.
1770 (let ((case-fold-search t))
1771 (org-with-wide-buffer
1772 (goto-char (point-min))
1773 (while (re-search-forward
1774 "^[ \t]*#\\+\\(BIND\\|SETUPFILE\\):" nil t)
1775 (let ((element (org-element-at-point)))
1776 (when (eq (org-element-type element) 'keyword)
1777 (let ((val (org-element-property :value element)))
1778 (if (equal (org-element-property :key element) "BIND")
1779 (push (read (format "(%s)" val)) alist)
1780 ;; Enter setup file.
1781 (let ((file (expand-file-name
1782 (org-remove-double-quotes val))))
1783 (unless (member file files)
1784 (with-temp-buffer
1785 (let ((org-inhibit-startup t)) (org-mode))
1786 (insert (org-file-contents file 'noerror))
1787 (setq alist
1788 (funcall collect-bind
1789 (cons file files)
1790 alist))))))))))
1791 alist)))))
1792 ;; Return value in appropriate order of appearance.
1793 (nreverse (funcall collect-bind nil nil)))))
1796 ;;;; Tree Properties
1798 ;; Tree properties are information extracted from parse tree. They
1799 ;; are initialized at the beginning of the transcoding process by
1800 ;; `org-export-collect-tree-properties'.
1802 ;; Dedicated functions focus on computing the value of specific tree
1803 ;; properties during initialization. Thus,
1804 ;; `org-export--populate-ignore-list' lists elements and objects that
1805 ;; should be skipped during export, `org-export--get-min-level' gets
1806 ;; the minimal exportable level, used as a basis to compute relative
1807 ;; level for headlines. Eventually
1808 ;; `org-export--collect-headline-numbering' builds an alist between
1809 ;; headlines and their numbering.
1811 (defun org-export-collect-tree-properties (data info)
1812 "Extract tree properties from parse tree.
1814 DATA is the parse tree from which information is retrieved. INFO
1815 is a list holding export options.
1817 Following tree properties are set or updated:
1819 `:exported-data' Hash table used to memoize results from
1820 `org-export-data'.
1822 `:footnote-definition-alist' List of footnotes definitions in
1823 original buffer and current parse tree.
1825 `:headline-offset' Offset between true level of headlines and
1826 local level. An offset of -1 means a headline
1827 of level 2 should be considered as a level
1828 1 headline in the context.
1830 `:headline-numbering' Alist of all headlines as key an the
1831 associated numbering as value.
1833 `:ignore-list' List of elements that should be ignored during
1834 export.
1836 Return updated plist."
1837 ;; Install the parse tree in the communication channel, in order to
1838 ;; use `org-export-get-genealogy' and al.
1839 (setq info (plist-put info :parse-tree data))
1840 ;; Get the list of elements and objects to ignore, and put it into
1841 ;; `:ignore-list'. Do not overwrite any user ignore that might have
1842 ;; been done during parse tree filtering.
1843 (setq info
1844 (plist-put info
1845 :ignore-list
1846 (append (org-export--populate-ignore-list data info)
1847 (plist-get info :ignore-list))))
1848 ;; Compute `:headline-offset' in order to be able to use
1849 ;; `org-export-get-relative-level'.
1850 (setq info
1851 (plist-put info
1852 :headline-offset
1853 (- 1 (org-export--get-min-level data info))))
1854 ;; Update footnotes definitions list with definitions in parse tree.
1855 ;; This is required since buffer expansion might have modified
1856 ;; boundaries of footnote definitions contained in the parse tree.
1857 ;; This way, definitions in `footnote-definition-alist' are bound to
1858 ;; match those in the parse tree.
1859 (let ((defs (plist-get info :footnote-definition-alist)))
1860 (org-element-map data 'footnote-definition
1861 (lambda (fn)
1862 (push (cons (org-element-property :label fn)
1863 `(org-data nil ,@(org-element-contents fn)))
1864 defs)))
1865 (setq info (plist-put info :footnote-definition-alist defs)))
1866 ;; Properties order doesn't matter: get the rest of the tree
1867 ;; properties.
1868 (nconc
1869 `(:headline-numbering ,(org-export--collect-headline-numbering data info)
1870 :exported-data ,(make-hash-table :test 'eq :size 4001))
1871 info))
1873 (defun org-export--get-min-level (data options)
1874 "Return minimum exportable headline's level in DATA.
1875 DATA is parsed tree as returned by `org-element-parse-buffer'.
1876 OPTIONS is a plist holding export options."
1877 (catch 'exit
1878 (let ((min-level 10000))
1879 (mapc
1880 (lambda (blob)
1881 (when (and (eq (org-element-type blob) 'headline)
1882 (not (org-element-property :footnote-section-p blob))
1883 (not (memq blob (plist-get options :ignore-list))))
1884 (setq min-level (min (org-element-property :level blob) min-level)))
1885 (when (= min-level 1) (throw 'exit 1)))
1886 (org-element-contents data))
1887 ;; If no headline was found, for the sake of consistency, set
1888 ;; minimum level to 1 nonetheless.
1889 (if (= min-level 10000) 1 min-level))))
1891 (defun org-export--collect-headline-numbering (data options)
1892 "Return numbering of all exportable headlines in a parse tree.
1894 DATA is the parse tree. OPTIONS is the plist holding export
1895 options.
1897 Return an alist whose key is a headline and value is its
1898 associated numbering \(in the shape of a list of numbers\) or nil
1899 for a footnotes section."
1900 (let ((numbering (make-vector org-export-max-depth 0)))
1901 (org-element-map data 'headline
1902 (lambda (headline)
1903 (unless (org-element-property :footnote-section-p headline)
1904 (let ((relative-level
1905 (1- (org-export-get-relative-level headline options))))
1906 (cons
1907 headline
1908 (loop for n across numbering
1909 for idx from 0 to org-export-max-depth
1910 when (< idx relative-level) collect n
1911 when (= idx relative-level) collect (aset numbering idx (1+ n))
1912 when (> idx relative-level) do (aset numbering idx 0))))))
1913 options)))
1915 (defun org-export--populate-ignore-list (data options)
1916 "Return list of elements and objects to ignore during export.
1917 DATA is the parse tree to traverse. OPTIONS is the plist holding
1918 export options."
1919 (let* (ignore
1920 walk-data
1921 ;; First find trees containing a select tag, if any.
1922 (selected (org-export--selected-trees data options))
1923 (walk-data
1924 (lambda (data)
1925 ;; Collect ignored elements or objects into IGNORE-LIST.
1926 (let ((type (org-element-type data)))
1927 (if (org-export--skip-p data options selected) (push data ignore)
1928 (if (and (eq type 'headline)
1929 (eq (plist-get options :with-archived-trees) 'headline)
1930 (org-element-property :archivedp data))
1931 ;; If headline is archived but tree below has
1932 ;; to be skipped, add it to ignore list.
1933 (mapc (lambda (e) (push e ignore))
1934 (org-element-contents data))
1935 ;; Move into secondary string, if any.
1936 (let ((sec-prop
1937 (cdr (assq type org-element-secondary-value-alist))))
1938 (when sec-prop
1939 (mapc walk-data (org-element-property sec-prop data))))
1940 ;; Move into recursive objects/elements.
1941 (mapc walk-data (org-element-contents data))))))))
1942 ;; Main call.
1943 (funcall walk-data data)
1944 ;; Return value.
1945 ignore))
1947 (defun org-export--selected-trees (data info)
1948 "Return list of headlines and inlinetasks with a select tag in their tree.
1949 DATA is parsed data as returned by `org-element-parse-buffer'.
1950 INFO is a plist holding export options."
1951 (let* (selected-trees
1952 walk-data ; For byte-compiler.
1953 (walk-data
1954 (function
1955 (lambda (data genealogy)
1956 (let ((type (org-element-type data)))
1957 (cond
1958 ((memq type '(headline inlinetask))
1959 (let ((tags (org-element-property :tags data)))
1960 (if (loop for tag in (plist-get info :select-tags)
1961 thereis (member tag tags))
1962 ;; When a select tag is found, mark full
1963 ;; genealogy and every headline within the tree
1964 ;; as acceptable.
1965 (setq selected-trees
1966 (append
1967 genealogy
1968 (org-element-map data '(headline inlinetask)
1969 'identity)
1970 selected-trees))
1971 ;; If at a headline, continue searching in tree,
1972 ;; recursively.
1973 (when (eq type 'headline)
1974 (mapc (lambda (el)
1975 (funcall walk-data el (cons data genealogy)))
1976 (org-element-contents data))))))
1977 ((or (eq type 'org-data)
1978 (memq type org-element-greater-elements))
1979 (mapc (lambda (el) (funcall walk-data el genealogy))
1980 (org-element-contents data)))))))))
1981 (funcall walk-data data nil)
1982 selected-trees))
1984 (defun org-export--skip-p (blob options selected)
1985 "Non-nil when element or object BLOB should be skipped during export.
1986 OPTIONS is the plist holding export options. SELECTED, when
1987 non-nil, is a list of headlines or inlinetasks belonging to
1988 a tree with a select tag."
1989 (case (org-element-type blob)
1990 (clock (not (plist-get options :with-clocks)))
1991 (drawer
1992 (let ((with-drawers-p (plist-get options :with-drawers)))
1993 (or (not with-drawers-p)
1994 (and (consp with-drawers-p)
1995 ;; If `:with-drawers' value starts with `not', ignore
1996 ;; every drawer whose name belong to that list.
1997 ;; Otherwise, ignore drawers whose name isn't in that
1998 ;; list.
1999 (let ((name (org-element-property :drawer-name blob)))
2000 (if (eq (car with-drawers-p) 'not)
2001 (member-ignore-case name (cdr with-drawers-p))
2002 (not (member-ignore-case name with-drawers-p))))))))
2003 ((footnote-definition footnote-reference)
2004 (not (plist-get options :with-footnotes)))
2005 ((headline inlinetask)
2006 (let ((with-tasks (plist-get options :with-tasks))
2007 (todo (org-element-property :todo-keyword blob))
2008 (todo-type (org-element-property :todo-type blob))
2009 (archived (plist-get options :with-archived-trees))
2010 (tags (org-element-property :tags blob)))
2012 (and (eq (org-element-type blob) 'inlinetask)
2013 (not (plist-get options :with-inlinetasks)))
2014 ;; Ignore subtrees with an exclude tag.
2015 (loop for k in (plist-get options :exclude-tags)
2016 thereis (member k tags))
2017 ;; When a select tag is present in the buffer, ignore any tree
2018 ;; without it.
2019 (and selected (not (memq blob selected)))
2020 ;; Ignore commented sub-trees.
2021 (org-element-property :commentedp blob)
2022 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
2023 (and (not archived) (org-element-property :archivedp blob))
2024 ;; Ignore tasks, if specified by `:with-tasks' property.
2025 (and todo
2026 (or (not with-tasks)
2027 (and (memq with-tasks '(todo done))
2028 (not (eq todo-type with-tasks)))
2029 (and (consp with-tasks) (not (member todo with-tasks))))))))
2030 ((latex-environment latex-fragment) (not (plist-get options :with-latex)))
2031 (planning (not (plist-get options :with-planning)))
2032 (statistics-cookie (not (plist-get options :with-statistics-cookies)))
2033 (table-cell
2034 (and (org-export-table-has-special-column-p
2035 (org-export-get-parent-table blob))
2036 (not (org-export-get-previous-element blob options))))
2037 (table-row (org-export-table-row-is-special-p blob options))
2038 (timestamp
2039 ;; `:with-timestamps' only applies to isolated timestamps
2040 ;; objects, i.e. timestamp objects in a paragraph containing only
2041 ;; timestamps and whitespaces.
2042 (when (let ((parent (org-export-get-parent-element blob)))
2043 (and (memq (org-element-type parent) '(paragraph verse-block))
2044 (not (org-element-map parent
2045 (cons 'plain-text
2046 (remq 'timestamp org-element-all-objects))
2047 (lambda (obj)
2048 (or (not (stringp obj)) (org-string-nw-p obj)))
2049 options t))))
2050 (case (plist-get options :with-timestamps)
2051 ('nil t)
2052 (active
2053 (not (memq (org-element-property :type blob) '(active active-range))))
2054 (inactive
2055 (not (memq (org-element-property :type blob)
2056 '(inactive inactive-range)))))))))
2059 ;;; The Transcoder
2061 ;; `org-export-data' reads a parse tree (obtained with, i.e.
2062 ;; `org-element-parse-buffer') and transcodes it into a specified
2063 ;; back-end output. It takes care of filtering out elements or
2064 ;; objects according to export options and organizing the output blank
2065 ;; lines and white space are preserved. The function memoizes its
2066 ;; results, so it is cheap to call it within translators.
2068 ;; It is possible to modify locally the back-end used by
2069 ;; `org-export-data' or even use a temporary back-end by using
2070 ;; `org-export-data-with-translations' and
2071 ;; `org-export-data-with-backend'.
2073 ;; Internally, three functions handle the filtering of objects and
2074 ;; elements during the export. In particular,
2075 ;; `org-export-ignore-element' marks an element or object so future
2076 ;; parse tree traversals skip it, `org-export--interpret-p' tells which
2077 ;; elements or objects should be seen as real Org syntax and
2078 ;; `org-export-expand' transforms the others back into their original
2079 ;; shape
2081 ;; `org-export-transcoder' is an accessor returning appropriate
2082 ;; translator function for a given element or object.
2084 (defun org-export-transcoder (blob info)
2085 "Return appropriate transcoder for BLOB.
2086 INFO is a plist containing export directives."
2087 (let ((type (org-element-type blob)))
2088 ;; Return contents only for complete parse trees.
2089 (if (eq type 'org-data) (lambda (blob contents info) contents)
2090 (let ((transcoder (cdr (assq type (plist-get info :translate-alist)))))
2091 (and (functionp transcoder) transcoder)))))
2093 (defun org-export-data (data info)
2094 "Convert DATA into current back-end format.
2096 DATA is a parse tree, an element or an object or a secondary
2097 string. INFO is a plist holding export options.
2099 Return transcoded string."
2100 (let ((memo (gethash data (plist-get info :exported-data) 'no-memo)))
2101 (if (not (eq memo 'no-memo)) memo
2102 (let* ((type (org-element-type data))
2103 (results
2104 (cond
2105 ;; Ignored element/object.
2106 ((memq data (plist-get info :ignore-list)) nil)
2107 ;; Plain text.
2108 ((eq type 'plain-text)
2109 (org-export-filter-apply-functions
2110 (plist-get info :filter-plain-text)
2111 (let ((transcoder (org-export-transcoder data info)))
2112 (if transcoder (funcall transcoder data info) data))
2113 info))
2114 ;; Uninterpreted element/object: change it back to Org
2115 ;; syntax and export again resulting raw string.
2116 ((not (org-export--interpret-p data info))
2117 (org-export-data
2118 (org-export-expand
2119 data
2120 (mapconcat (lambda (blob) (org-export-data blob info))
2121 (org-element-contents data)
2122 ""))
2123 info))
2124 ;; Secondary string.
2125 ((not type)
2126 (mapconcat (lambda (obj) (org-export-data obj info)) data ""))
2127 ;; Element/Object without contents or, as a special case,
2128 ;; headline with archive tag and archived trees restricted
2129 ;; to title only.
2130 ((or (not (org-element-contents data))
2131 (and (eq type 'headline)
2132 (eq (plist-get info :with-archived-trees) 'headline)
2133 (org-element-property :archivedp data)))
2134 (let ((transcoder (org-export-transcoder data info)))
2135 (or (and (functionp transcoder)
2136 (funcall transcoder data nil info))
2137 ;; Export snippets never return a nil value so
2138 ;; that white spaces following them are never
2139 ;; ignored.
2140 (and (eq type 'export-snippet) ""))))
2141 ;; Element/Object with contents.
2143 (let ((transcoder (org-export-transcoder data info)))
2144 (when transcoder
2145 (let* ((greaterp (memq type org-element-greater-elements))
2146 (objectp
2147 (and (not greaterp)
2148 (memq type org-element-recursive-objects)))
2149 (contents
2150 (mapconcat
2151 (lambda (element) (org-export-data element info))
2152 (org-element-contents
2153 (if (or greaterp objectp) data
2154 ;; Elements directly containing objects
2155 ;; must have their indentation normalized
2156 ;; first.
2157 (org-element-normalize-contents
2158 data
2159 ;; When normalizing contents of the first
2160 ;; paragraph in an item or a footnote
2161 ;; definition, ignore first line's
2162 ;; indentation: there is none and it
2163 ;; might be misleading.
2164 (when (eq type 'paragraph)
2165 (let ((parent (org-export-get-parent data)))
2166 (and
2167 (eq (car (org-element-contents parent))
2168 data)
2169 (memq (org-element-type parent)
2170 '(footnote-definition item))))))))
2171 "")))
2172 (funcall transcoder data
2173 (if (not greaterp) contents
2174 (org-element-normalize-string contents))
2175 info))))))))
2176 ;; Final result will be memoized before being returned.
2177 (puthash
2178 data
2179 (cond
2180 ((not results) nil)
2181 ((memq type '(org-data plain-text nil)) results)
2182 ;; Append the same white space between elements or objects as in
2183 ;; the original buffer, and call appropriate filters.
2185 (let ((results
2186 (org-export-filter-apply-functions
2187 (plist-get info (intern (format ":filter-%s" type)))
2188 (let ((post-blank (or (org-element-property :post-blank data)
2189 0)))
2190 (if (memq type org-element-all-elements)
2191 (concat (org-element-normalize-string results)
2192 (make-string post-blank ?\n))
2193 (concat results (make-string post-blank ? ))))
2194 info)))
2195 results)))
2196 (plist-get info :exported-data))))))
2198 (defun org-export-data-with-translations (data translations info)
2199 "Convert DATA into another format using a given translation table.
2200 DATA is an element, an object, a secondary string or a string.
2201 TRANSLATIONS is an alist between element or object types and
2202 a functions handling them. See `org-export-define-backend' for
2203 more information. INFO is a plist used as a communication
2204 channel."
2205 (org-export-data
2206 data
2207 ;; Set-up a new communication channel with TRANSLATIONS as the
2208 ;; translate table and a new hash table for memoization.
2209 (org-combine-plists
2210 info
2211 (list :translate-alist translations
2212 ;; Size of the hash table is reduced since this function
2213 ;; will probably be used on short trees.
2214 :exported-data (make-hash-table :test 'eq :size 401)))))
2216 (defun org-export-data-with-backend (data backend info)
2217 "Convert DATA into BACKEND format.
2219 DATA is an element, an object, a secondary string or a string.
2220 BACKEND is a symbol. INFO is a plist used as a communication
2221 channel.
2223 Unlike to `org-export-with-backend', this function will
2224 recursively convert DATA using BACKEND translation table."
2225 (org-export-barf-if-invalid-backend backend)
2226 (org-export-data-with-translations
2227 data (org-export-backend-translate-table backend) info))
2229 (defun org-export--interpret-p (blob info)
2230 "Non-nil if element or object BLOB should be interpreted during export.
2231 If nil, BLOB will appear as raw Org syntax. Check is done
2232 according to export options INFO, stored as a plist."
2233 (case (org-element-type blob)
2234 ;; ... entities...
2235 (entity (plist-get info :with-entities))
2236 ;; ... emphasis...
2237 ((bold italic strike-through underline)
2238 (plist-get info :with-emphasize))
2239 ;; ... fixed-width areas.
2240 (fixed-width (plist-get info :with-fixed-width))
2241 ;; ... LaTeX environments and fragments...
2242 ((latex-environment latex-fragment)
2243 (let ((with-latex-p (plist-get info :with-latex)))
2244 (and with-latex-p (not (eq with-latex-p 'verbatim)))))
2245 ;; ... sub/superscripts...
2246 ((subscript superscript)
2247 (let ((sub/super-p (plist-get info :with-sub-superscript)))
2248 (if (eq sub/super-p '{})
2249 (org-element-property :use-brackets-p blob)
2250 sub/super-p)))
2251 ;; ... tables...
2252 (table (plist-get info :with-tables))
2253 (otherwise t)))
2255 (defun org-export-expand (blob contents &optional with-affiliated)
2256 "Expand a parsed element or object to its original state.
2258 BLOB is either an element or an object. CONTENTS is its
2259 contents, as a string or nil.
2261 When optional argument WITH-AFFILIATED is non-nil, add affiliated
2262 keywords before output."
2263 (let ((type (org-element-type blob)))
2264 (concat (and with-affiliated (memq type org-element-all-elements)
2265 (org-element--interpret-affiliated-keywords blob))
2266 (funcall (intern (format "org-element-%s-interpreter" type))
2267 blob contents))))
2269 (defun org-export-ignore-element (element info)
2270 "Add ELEMENT to `:ignore-list' in INFO.
2272 Any element in `:ignore-list' will be skipped when using
2273 `org-element-map'. INFO is modified by side effects."
2274 (plist-put info :ignore-list (cons element (plist-get info :ignore-list))))
2278 ;;; The Filter System
2280 ;; Filters allow end-users to tweak easily the transcoded output.
2281 ;; They are the functional counterpart of hooks, as every filter in
2282 ;; a set is applied to the return value of the previous one.
2284 ;; Every set is back-end agnostic. Although, a filter is always
2285 ;; called, in addition to the string it applies to, with the back-end
2286 ;; used as argument, so it's easy for the end-user to add back-end
2287 ;; specific filters in the set. The communication channel, as
2288 ;; a plist, is required as the third argument.
2290 ;; From the developer side, filters sets can be installed in the
2291 ;; process with the help of `org-export-define-backend', which
2292 ;; internally stores filters as an alist. Each association has a key
2293 ;; among the following symbols and a function or a list of functions
2294 ;; as value.
2296 ;; - `:filter-options' applies to the property list containing export
2297 ;; options. Unlike to other filters, functions in this list accept
2298 ;; two arguments instead of three: the property list containing
2299 ;; export options and the back-end. Users can set its value through
2300 ;; `org-export-filter-options-functions' variable.
2302 ;; - `:filter-parse-tree' applies directly to the complete parsed
2303 ;; tree. Users can set it through
2304 ;; `org-export-filter-parse-tree-functions' variable.
2306 ;; - `:filter-final-output' applies to the final transcoded string.
2307 ;; Users can set it with `org-export-filter-final-output-functions'
2308 ;; variable
2310 ;; - `:filter-plain-text' applies to any string not recognized as Org
2311 ;; syntax. `org-export-filter-plain-text-functions' allows users to
2312 ;; configure it.
2314 ;; - `:filter-TYPE' applies on the string returned after an element or
2315 ;; object of type TYPE has been transcoded. A user can modify
2316 ;; `org-export-filter-TYPE-functions'
2318 ;; All filters sets are applied with
2319 ;; `org-export-filter-apply-functions' function. Filters in a set are
2320 ;; applied in a LIFO fashion. It allows developers to be sure that
2321 ;; their filters will be applied first.
2323 ;; Filters properties are installed in communication channel with
2324 ;; `org-export-install-filters' function.
2326 ;; Eventually, two hooks (`org-export-before-processing-hook' and
2327 ;; `org-export-before-parsing-hook') are run at the beginning of the
2328 ;; export process and just before parsing to allow for heavy structure
2329 ;; modifications.
2332 ;;;; Hooks
2334 (defvar org-export-before-processing-hook nil
2335 "Hook run at the beginning of the export process.
2337 This is run before include keywords and macros are expanded and
2338 Babel code blocks executed, on a copy of the original buffer
2339 being exported. Visibility and narrowing are preserved. Point
2340 is at the beginning of the buffer.
2342 Every function in this hook will be called with one argument: the
2343 back-end currently used, as a symbol.")
2345 (defvar org-export-before-parsing-hook nil
2346 "Hook run before parsing an export buffer.
2348 This is run after include keywords and macros have been expanded
2349 and Babel code blocks executed, on a copy of the original buffer
2350 being exported. Visibility and narrowing are preserved. Point
2351 is at the beginning of the buffer.
2353 Every function in this hook will be called with one argument: the
2354 back-end currently used, as a symbol.")
2357 ;;;; Special Filters
2359 (defvar org-export-filter-options-functions nil
2360 "List of functions applied to the export options.
2361 Each filter is called with two arguments: the export options, as
2362 a plist, and the back-end, as a symbol. It must return
2363 a property list containing export options.")
2365 (defvar org-export-filter-parse-tree-functions nil
2366 "List of functions applied to the parsed tree.
2367 Each filter is called with three arguments: the parse tree, as
2368 returned by `org-element-parse-buffer', the back-end, as
2369 a symbol, and the communication channel, as a plist. It must
2370 return the modified parse tree to transcode.")
2372 (defvar org-export-filter-plain-text-functions nil
2373 "List of functions applied to plain text.
2374 Each filter is called with three arguments: a string which
2375 contains no Org syntax, the back-end, as a symbol, and the
2376 communication channel, as a plist. It must return a string or
2377 nil.")
2379 (defvar org-export-filter-final-output-functions nil
2380 "List of functions applied to the transcoded string.
2381 Each filter is called with three arguments: the full transcoded
2382 string, the back-end, as a symbol, and the communication channel,
2383 as a plist. It must return a string that will be used as the
2384 final export output.")
2387 ;;;; Elements Filters
2389 (defvar org-export-filter-babel-call-functions nil
2390 "List of functions applied to a transcoded babel-call.
2391 Each filter is called with three arguments: the transcoded data,
2392 as a string, the back-end, as a symbol, and the communication
2393 channel, as a plist. It must return a string or nil.")
2395 (defvar org-export-filter-center-block-functions nil
2396 "List of functions applied to a transcoded center block.
2397 Each filter is called with three arguments: the transcoded data,
2398 as a string, the back-end, as a symbol, and the communication
2399 channel, as a plist. It must return a string or nil.")
2401 (defvar org-export-filter-clock-functions nil
2402 "List of functions applied to a transcoded clock.
2403 Each filter is called with three arguments: the transcoded data,
2404 as a string, the back-end, as a symbol, and the communication
2405 channel, as a plist. It must return a string or nil.")
2407 (defvar org-export-filter-comment-functions nil
2408 "List of functions applied to a transcoded comment.
2409 Each filter is called with three arguments: the transcoded data,
2410 as a string, the back-end, as a symbol, and the communication
2411 channel, as a plist. It must return a string or nil.")
2413 (defvar org-export-filter-comment-block-functions nil
2414 "List of functions applied to a transcoded comment-block.
2415 Each filter is called with three arguments: the transcoded data,
2416 as a string, the back-end, as a symbol, and the communication
2417 channel, as a plist. It must return a string or nil.")
2419 (defvar org-export-filter-diary-sexp-functions nil
2420 "List of functions applied to a transcoded diary-sexp.
2421 Each filter is called with three arguments: the transcoded data,
2422 as a string, the back-end, as a symbol, and the communication
2423 channel, as a plist. It must return a string or nil.")
2425 (defvar org-export-filter-drawer-functions nil
2426 "List of functions applied to a transcoded drawer.
2427 Each filter is called with three arguments: the transcoded data,
2428 as a string, the back-end, as a symbol, and the communication
2429 channel, as a plist. It must return a string or nil.")
2431 (defvar org-export-filter-dynamic-block-functions nil
2432 "List of functions applied to a transcoded dynamic-block.
2433 Each filter is called with three arguments: the transcoded data,
2434 as a string, the back-end, as a symbol, and the communication
2435 channel, as a plist. It must return a string or nil.")
2437 (defvar org-export-filter-example-block-functions nil
2438 "List of functions applied to a transcoded example-block.
2439 Each filter is called with three arguments: the transcoded data,
2440 as a string, the back-end, as a symbol, and the communication
2441 channel, as a plist. It must return a string or nil.")
2443 (defvar org-export-filter-export-block-functions nil
2444 "List of functions applied to a transcoded export-block.
2445 Each filter is called with three arguments: the transcoded data,
2446 as a string, the back-end, as a symbol, and the communication
2447 channel, as a plist. It must return a string or nil.")
2449 (defvar org-export-filter-fixed-width-functions nil
2450 "List of functions applied to a transcoded fixed-width.
2451 Each filter is called with three arguments: the transcoded data,
2452 as a string, the back-end, as a symbol, and the communication
2453 channel, as a plist. It must return a string or nil.")
2455 (defvar org-export-filter-footnote-definition-functions nil
2456 "List of functions applied to a transcoded footnote-definition.
2457 Each filter is called with three arguments: the transcoded data,
2458 as a string, the back-end, as a symbol, and the communication
2459 channel, as a plist. It must return a string or nil.")
2461 (defvar org-export-filter-headline-functions nil
2462 "List of functions applied to a transcoded headline.
2463 Each filter is called with three arguments: the transcoded data,
2464 as a string, the back-end, as a symbol, and the communication
2465 channel, as a plist. It must return a string or nil.")
2467 (defvar org-export-filter-horizontal-rule-functions nil
2468 "List of functions applied to a transcoded horizontal-rule.
2469 Each filter is called with three arguments: the transcoded data,
2470 as a string, the back-end, as a symbol, and the communication
2471 channel, as a plist. It must return a string or nil.")
2473 (defvar org-export-filter-inlinetask-functions nil
2474 "List of functions applied to a transcoded inlinetask.
2475 Each filter is called with three arguments: the transcoded data,
2476 as a string, the back-end, as a symbol, and the communication
2477 channel, as a plist. It must return a string or nil.")
2479 (defvar org-export-filter-item-functions nil
2480 "List of functions applied to a transcoded item.
2481 Each filter is called with three arguments: the transcoded data,
2482 as a string, the back-end, as a symbol, and the communication
2483 channel, as a plist. It must return a string or nil.")
2485 (defvar org-export-filter-keyword-functions nil
2486 "List of functions applied to a transcoded keyword.
2487 Each filter is called with three arguments: the transcoded data,
2488 as a string, the back-end, as a symbol, and the communication
2489 channel, as a plist. It must return a string or nil.")
2491 (defvar org-export-filter-latex-environment-functions nil
2492 "List of functions applied to a transcoded latex-environment.
2493 Each filter is called with three arguments: the transcoded data,
2494 as a string, the back-end, as a symbol, and the communication
2495 channel, as a plist. It must return a string or nil.")
2497 (defvar org-export-filter-node-property-functions nil
2498 "List of functions applied to a transcoded node-property.
2499 Each filter is called with three arguments: the transcoded data,
2500 as a string, the back-end, as a symbol, and the communication
2501 channel, as a plist. It must return a string or nil.")
2503 (defvar org-export-filter-paragraph-functions nil
2504 "List of functions applied to a transcoded paragraph.
2505 Each filter is called with three arguments: the transcoded data,
2506 as a string, the back-end, as a symbol, and the communication
2507 channel, as a plist. It must return a string or nil.")
2509 (defvar org-export-filter-plain-list-functions nil
2510 "List of functions applied to a transcoded plain-list.
2511 Each filter is called with three arguments: the transcoded data,
2512 as a string, the back-end, as a symbol, and the communication
2513 channel, as a plist. It must return a string or nil.")
2515 (defvar org-export-filter-planning-functions nil
2516 "List of functions applied to a transcoded planning.
2517 Each filter is called with three arguments: the transcoded data,
2518 as a string, the back-end, as a symbol, and the communication
2519 channel, as a plist. It must return a string or nil.")
2521 (defvar org-export-filter-property-drawer-functions nil
2522 "List of functions applied to a transcoded property-drawer.
2523 Each filter is called with three arguments: the transcoded data,
2524 as a string, the back-end, as a symbol, and the communication
2525 channel, as a plist. It must return a string or nil.")
2527 (defvar org-export-filter-quote-block-functions nil
2528 "List of functions applied to a transcoded quote block.
2529 Each filter is called with three arguments: the transcoded quote
2530 data, as a string, the back-end, as a symbol, and the
2531 communication channel, as a plist. It must return a string or
2532 nil.")
2534 (defvar org-export-filter-quote-section-functions nil
2535 "List of functions applied to a transcoded quote-section.
2536 Each filter is called with three arguments: the transcoded data,
2537 as a string, the back-end, as a symbol, and the communication
2538 channel, as a plist. It must return a string or nil.")
2540 (defvar org-export-filter-section-functions nil
2541 "List of functions applied to a transcoded section.
2542 Each filter is called with three arguments: the transcoded data,
2543 as a string, the back-end, as a symbol, and the communication
2544 channel, as a plist. It must return a string or nil.")
2546 (defvar org-export-filter-special-block-functions nil
2547 "List of functions applied to a transcoded special block.
2548 Each filter is called with three arguments: the transcoded data,
2549 as a string, the back-end, as a symbol, and the communication
2550 channel, as a plist. It must return a string or nil.")
2552 (defvar org-export-filter-src-block-functions nil
2553 "List of functions applied to a transcoded src-block.
2554 Each filter is called with three arguments: the transcoded data,
2555 as a string, the back-end, as a symbol, and the communication
2556 channel, as a plist. It must return a string or nil.")
2558 (defvar org-export-filter-table-functions nil
2559 "List of functions applied to a transcoded table.
2560 Each filter is called with three arguments: the transcoded data,
2561 as a string, the back-end, as a symbol, and the communication
2562 channel, as a plist. It must return a string or nil.")
2564 (defvar org-export-filter-table-cell-functions nil
2565 "List of functions applied to a transcoded table-cell.
2566 Each filter is called with three arguments: the transcoded data,
2567 as a string, the back-end, as a symbol, and the communication
2568 channel, as a plist. It must return a string or nil.")
2570 (defvar org-export-filter-table-row-functions nil
2571 "List of functions applied to a transcoded table-row.
2572 Each filter is called with three arguments: the transcoded data,
2573 as a string, the back-end, as a symbol, and the communication
2574 channel, as a plist. It must return a string or nil.")
2576 (defvar org-export-filter-verse-block-functions nil
2577 "List of functions applied to a transcoded verse block.
2578 Each filter is called with three arguments: the transcoded data,
2579 as a string, the back-end, as a symbol, and the communication
2580 channel, as a plist. It must return a string or nil.")
2583 ;;;; Objects Filters
2585 (defvar org-export-filter-bold-functions nil
2586 "List of functions applied to transcoded bold text.
2587 Each filter is called with three arguments: the transcoded data,
2588 as a string, the back-end, as a symbol, and the communication
2589 channel, as a plist. It must return a string or nil.")
2591 (defvar org-export-filter-code-functions nil
2592 "List of functions applied to transcoded code text.
2593 Each filter is called with three arguments: the transcoded data,
2594 as a string, the back-end, as a symbol, and the communication
2595 channel, as a plist. It must return a string or nil.")
2597 (defvar org-export-filter-entity-functions nil
2598 "List of functions applied to a transcoded entity.
2599 Each filter is called with three arguments: the transcoded data,
2600 as a string, the back-end, as a symbol, and the communication
2601 channel, as a plist. It must return a string or nil.")
2603 (defvar org-export-filter-export-snippet-functions nil
2604 "List of functions applied to a transcoded export-snippet.
2605 Each filter is called with three arguments: the transcoded data,
2606 as a string, the back-end, as a symbol, and the communication
2607 channel, as a plist. It must return a string or nil.")
2609 (defvar org-export-filter-footnote-reference-functions nil
2610 "List of functions applied to a transcoded footnote-reference.
2611 Each filter is called with three arguments: the transcoded data,
2612 as a string, the back-end, as a symbol, and the communication
2613 channel, as a plist. It must return a string or nil.")
2615 (defvar org-export-filter-inline-babel-call-functions nil
2616 "List of functions applied to a transcoded inline-babel-call.
2617 Each filter is called with three arguments: the transcoded data,
2618 as a string, the back-end, as a symbol, and the communication
2619 channel, as a plist. It must return a string or nil.")
2621 (defvar org-export-filter-inline-src-block-functions nil
2622 "List of functions applied to a transcoded inline-src-block.
2623 Each filter is called with three arguments: the transcoded data,
2624 as a string, the back-end, as a symbol, and the communication
2625 channel, as a plist. It must return a string or nil.")
2627 (defvar org-export-filter-italic-functions nil
2628 "List of functions applied to transcoded italic text.
2629 Each filter is called with three arguments: the transcoded data,
2630 as a string, the back-end, as a symbol, and the communication
2631 channel, as a plist. It must return a string or nil.")
2633 (defvar org-export-filter-latex-fragment-functions nil
2634 "List of functions applied to a transcoded latex-fragment.
2635 Each filter is called with three arguments: the transcoded data,
2636 as a string, the back-end, as a symbol, and the communication
2637 channel, as a plist. It must return a string or nil.")
2639 (defvar org-export-filter-line-break-functions nil
2640 "List of functions applied to a transcoded line-break.
2641 Each filter is called with three arguments: the transcoded data,
2642 as a string, the back-end, as a symbol, and the communication
2643 channel, as a plist. It must return a string or nil.")
2645 (defvar org-export-filter-link-functions nil
2646 "List of functions applied to a transcoded link.
2647 Each filter is called with three arguments: the transcoded data,
2648 as a string, the back-end, as a symbol, and the communication
2649 channel, as a plist. It must return a string or nil.")
2651 (defvar org-export-filter-radio-target-functions nil
2652 "List of functions applied to a transcoded radio-target.
2653 Each filter is called with three arguments: the transcoded data,
2654 as a string, the back-end, as a symbol, and the communication
2655 channel, as a plist. It must return a string or nil.")
2657 (defvar org-export-filter-statistics-cookie-functions nil
2658 "List of functions applied to a transcoded statistics-cookie.
2659 Each filter is called with three arguments: the transcoded data,
2660 as a string, the back-end, as a symbol, and the communication
2661 channel, as a plist. It must return a string or nil.")
2663 (defvar org-export-filter-strike-through-functions nil
2664 "List of functions applied to transcoded strike-through text.
2665 Each filter is called with three arguments: the transcoded data,
2666 as a string, the back-end, as a symbol, and the communication
2667 channel, as a plist. It must return a string or nil.")
2669 (defvar org-export-filter-subscript-functions nil
2670 "List of functions applied to a transcoded subscript.
2671 Each filter is called with three arguments: the transcoded data,
2672 as a string, the back-end, as a symbol, and the communication
2673 channel, as a plist. It must return a string or nil.")
2675 (defvar org-export-filter-superscript-functions nil
2676 "List of functions applied to a transcoded superscript.
2677 Each filter is called with three arguments: the transcoded data,
2678 as a string, the back-end, as a symbol, and the communication
2679 channel, as a plist. It must return a string or nil.")
2681 (defvar org-export-filter-target-functions nil
2682 "List of functions applied to a transcoded target.
2683 Each filter is called with three arguments: the transcoded data,
2684 as a string, the back-end, as a symbol, and the communication
2685 channel, as a plist. It must return a string or nil.")
2687 (defvar org-export-filter-timestamp-functions nil
2688 "List of functions applied to a transcoded timestamp.
2689 Each filter is called with three arguments: the transcoded data,
2690 as a string, the back-end, as a symbol, and the communication
2691 channel, as a plist. It must return a string or nil.")
2693 (defvar org-export-filter-underline-functions nil
2694 "List of functions applied to transcoded underline text.
2695 Each filter is called with three arguments: the transcoded data,
2696 as a string, the back-end, as a symbol, and the communication
2697 channel, as a plist. It must return a string or nil.")
2699 (defvar org-export-filter-verbatim-functions nil
2700 "List of functions applied to transcoded verbatim text.
2701 Each filter is called with three arguments: the transcoded data,
2702 as a string, the back-end, as a symbol, and the communication
2703 channel, as a plist. It must return a string or nil.")
2706 ;;;; Filters Tools
2708 ;; Internal function `org-export-install-filters' installs filters
2709 ;; hard-coded in back-ends (developer filters) and filters from global
2710 ;; variables (user filters) in the communication channel.
2712 ;; Internal function `org-export-filter-apply-functions' takes care
2713 ;; about applying each filter in order to a given data. It ignores
2714 ;; filters returning a nil value but stops whenever a filter returns
2715 ;; an empty string.
2717 (defun org-export-filter-apply-functions (filters value info)
2718 "Call every function in FILTERS.
2720 Functions are called with arguments VALUE, current export
2721 back-end and INFO. A function returning a nil value will be
2722 skipped. If it returns the empty string, the process ends and
2723 VALUE is ignored.
2725 Call is done in a LIFO fashion, to be sure that developer
2726 specified filters, if any, are called first."
2727 (catch 'exit
2728 (dolist (filter filters value)
2729 (let ((result (funcall filter value (plist-get info :back-end) info)))
2730 (cond ((not result) value)
2731 ((equal value "") (throw 'exit nil))
2732 (t (setq value result)))))))
2734 (defun org-export-install-filters (info)
2735 "Install filters properties in communication channel.
2736 INFO is a plist containing the current communication channel.
2737 Return the updated communication channel."
2738 (let (plist)
2739 ;; Install user-defined filters with `org-export-filters-alist'
2740 ;; and filters already in INFO (through ext-plist mechanism).
2741 (mapc (lambda (p)
2742 (let* ((prop (car p))
2743 (info-value (plist-get info prop))
2744 (default-value (symbol-value (cdr p))))
2745 (setq plist
2746 (plist-put plist prop
2747 ;; Filters in INFO will be called
2748 ;; before those user provided.
2749 (append (if (listp info-value) info-value
2750 (list info-value))
2751 default-value)))))
2752 org-export-filters-alist)
2753 ;; Prepend back-end specific filters to that list.
2754 (mapc (lambda (p)
2755 ;; Single values get consed, lists are appended.
2756 (let ((key (car p)) (value (cdr p)))
2757 (when value
2758 (setq plist
2759 (plist-put
2760 plist key
2761 (if (atom value) (cons value (plist-get plist key))
2762 (append value (plist-get plist key))))))))
2763 (org-export-backend-filters (plist-get info :back-end)))
2764 ;; Return new communication channel.
2765 (org-combine-plists info plist)))
2769 ;;; Core functions
2771 ;; This is the room for the main function, `org-export-as', along with
2772 ;; its derivatives, `org-export-to-buffer', `org-export-to-file' and
2773 ;; `org-export-string-as'. They differ either by the way they output
2774 ;; the resulting code (for the first two) or by the input type (for
2775 ;; the latter). `org-export--copy-to-kill-ring-p' determines if
2776 ;; output of these function should be added to kill ring.
2778 ;; `org-export-output-file-name' is an auxiliary function meant to be
2779 ;; used with `org-export-to-file'. With a given extension, it tries
2780 ;; to provide a canonical file name to write export output to.
2782 ;; Note that `org-export-as' doesn't really parse the current buffer,
2783 ;; but a copy of it (with the same buffer-local variables and
2784 ;; visibility), where macros and include keywords are expanded and
2785 ;; Babel blocks are executed, if appropriate.
2786 ;; `org-export-with-buffer-copy' macro prepares that copy.
2788 ;; File inclusion is taken care of by
2789 ;; `org-export-expand-include-keyword' and
2790 ;; `org-export--prepare-file-contents'. Structure wise, including
2791 ;; a whole Org file in a buffer often makes little sense. For
2792 ;; example, if the file contains a headline and the include keyword
2793 ;; was within an item, the item should contain the headline. That's
2794 ;; why file inclusion should be done before any structure can be
2795 ;; associated to the file, that is before parsing.
2797 ;; `org-export-insert-default-template' is a command to insert
2798 ;; a default template (or a back-end specific template) at point or in
2799 ;; current subtree.
2801 (defun org-export-copy-buffer ()
2802 "Return a copy of the current buffer.
2803 The copy preserves Org buffer-local variables, visibility and
2804 narrowing."
2805 (let ((copy-buffer-fun (org-export--generate-copy-script (current-buffer)))
2806 (new-buf (generate-new-buffer (buffer-name))))
2807 (with-current-buffer new-buf
2808 (funcall copy-buffer-fun)
2809 (set-buffer-modified-p nil))
2810 new-buf))
2812 (defmacro org-export-with-buffer-copy (&rest body)
2813 "Apply BODY in a copy of the current buffer.
2814 The copy preserves local variables, visibility and contents of
2815 the original buffer. Point is at the beginning of the buffer
2816 when BODY is applied."
2817 (declare (debug t))
2818 (org-with-gensyms (buf-copy)
2819 `(let ((,buf-copy (org-export-copy-buffer)))
2820 (unwind-protect
2821 (with-current-buffer ,buf-copy
2822 (goto-char (point-min))
2823 (progn ,@body))
2824 (and (buffer-live-p ,buf-copy)
2825 ;; Kill copy without confirmation.
2826 (progn (with-current-buffer ,buf-copy
2827 (restore-buffer-modified-p nil))
2828 (kill-buffer ,buf-copy)))))))
2830 (defun org-export--generate-copy-script (buffer)
2831 "Generate a function duplicating BUFFER.
2833 The copy will preserve local variables, visibility, contents and
2834 narrowing of the original buffer. If a region was active in
2835 BUFFER, contents will be narrowed to that region instead.
2837 The resulting function can be evaled at a later time, from
2838 another buffer, effectively cloning the original buffer there.
2840 The function assumes BUFFER's major mode is `org-mode'."
2841 (with-current-buffer buffer
2842 `(lambda ()
2843 (let ((inhibit-modification-hooks t))
2844 ;; Set major mode. Ignore `org-mode-hook' as it has been run
2845 ;; already in BUFFER.
2846 (let ((org-mode-hook nil) (org-inhibit-startup t)) (org-mode))
2847 ;; Copy specific buffer local variables and variables set
2848 ;; through BIND keywords.
2849 ,@(let ((bound-variables (org-export--list-bound-variables))
2850 vars)
2851 (dolist (entry (buffer-local-variables (buffer-base-buffer)) vars)
2852 (when (consp entry)
2853 (let ((var (car entry))
2854 (val (cdr entry)))
2855 (and (not (eq var 'org-font-lock-keywords))
2856 (or (memq var
2857 '(default-directory
2858 buffer-file-name
2859 buffer-file-coding-system))
2860 (assq var bound-variables)
2861 (string-match "^\\(org-\\|orgtbl-\\)"
2862 (symbol-name var)))
2863 ;; Skip unreadable values, as they cannot be
2864 ;; sent to external process.
2865 (or (not val) (ignore-errors (read (format "%S" val))))
2866 (push `(set (make-local-variable (quote ,var))
2867 (quote ,val))
2868 vars))))))
2869 ;; Whole buffer contents.
2870 (insert
2871 ,(org-with-wide-buffer
2872 (buffer-substring-no-properties
2873 (point-min) (point-max))))
2874 ;; Narrowing.
2875 ,(if (org-region-active-p)
2876 `(narrow-to-region ,(region-beginning) ,(region-end))
2877 `(narrow-to-region ,(point-min) ,(point-max)))
2878 ;; Current position of point.
2879 (goto-char ,(point))
2880 ;; Overlays with invisible property.
2881 ,@(let (ov-set)
2882 (mapc
2883 (lambda (ov)
2884 (let ((invis-prop (overlay-get ov 'invisible)))
2885 (when invis-prop
2886 (push `(overlay-put
2887 (make-overlay ,(overlay-start ov)
2888 ,(overlay-end ov))
2889 'invisible (quote ,invis-prop))
2890 ov-set))))
2891 (overlays-in (point-min) (point-max)))
2892 ov-set)))))
2894 ;;;###autoload
2895 (defun org-export-as
2896 (backend &optional subtreep visible-only body-only ext-plist)
2897 "Transcode current Org buffer into BACKEND code.
2899 If narrowing is active in the current buffer, only transcode its
2900 narrowed part.
2902 If a region is active, transcode that region.
2904 When optional argument SUBTREEP is non-nil, transcode the
2905 sub-tree at point, extracting information from the headline
2906 properties first.
2908 When optional argument VISIBLE-ONLY is non-nil, don't export
2909 contents of hidden elements.
2911 When optional argument BODY-ONLY is non-nil, only return body
2912 code, without surrounding template.
2914 Optional argument EXT-PLIST, when provided, is a property list
2915 with external parameters overriding Org default settings, but
2916 still inferior to file-local settings.
2918 Return code as a string."
2919 (org-export-barf-if-invalid-backend backend)
2920 (save-excursion
2921 (save-restriction
2922 ;; Narrow buffer to an appropriate region or subtree for
2923 ;; parsing. If parsing subtree, be sure to remove main headline
2924 ;; too.
2925 (cond ((org-region-active-p)
2926 (narrow-to-region (region-beginning) (region-end)))
2927 (subtreep
2928 (org-narrow-to-subtree)
2929 (goto-char (point-min))
2930 (forward-line)
2931 (narrow-to-region (point) (point-max))))
2932 ;; Initialize communication channel with original buffer
2933 ;; attributes, unavailable in its copy.
2934 (let* ((org-export-current-backend backend)
2935 (info (org-combine-plists
2936 (list :export-options
2937 (delq nil
2938 (list (and subtreep 'subtree)
2939 (and visible-only 'visible-only)
2940 (and body-only 'body-only))))
2941 (org-export--get-buffer-attributes)))
2942 tree)
2943 ;; Update communication channel and get parse tree. Buffer
2944 ;; isn't parsed directly. Instead, a temporary copy is
2945 ;; created, where include keywords, macros are expanded and
2946 ;; code blocks are evaluated.
2947 (org-export-with-buffer-copy
2948 ;; Run first hook with current back-end as argument.
2949 (run-hook-with-args 'org-export-before-processing-hook backend)
2950 (org-export-expand-include-keyword)
2951 ;; Update macro templates since #+INCLUDE keywords might have
2952 ;; added some new ones.
2953 (org-macro-initialize-templates)
2954 (org-macro-replace-all org-macro-templates)
2955 (org-export-execute-babel-code)
2956 ;; Update radio targets since keyword inclusion might have
2957 ;; added some more.
2958 (org-update-radio-target-regexp)
2959 ;; Run last hook with current back-end as argument.
2960 (goto-char (point-min))
2961 (save-excursion
2962 (run-hook-with-args 'org-export-before-parsing-hook backend))
2963 ;; Update communication channel with environment. Also
2964 ;; install user's and developer's filters.
2965 (setq info
2966 (org-export-install-filters
2967 (org-combine-plists
2968 info (org-export-get-environment backend subtreep ext-plist))))
2969 ;; Expand export-specific set of macros: {{{author}}},
2970 ;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done
2971 ;; once regular macros have been expanded, since document
2972 ;; keywords may contain one of them.
2973 (org-macro-replace-all
2974 (list (cons "author"
2975 (org-element-interpret-data (plist-get info :author)))
2976 (cons "date"
2977 (org-element-interpret-data (plist-get info :date)))
2978 ;; EMAIL is not a parsed keyword: store it as-is.
2979 (cons "email" (or (plist-get info :email) ""))
2980 (cons "title"
2981 (org-element-interpret-data (plist-get info :title)))))
2982 ;; Call options filters and update export options. We do not
2983 ;; use `org-export-filter-apply-functions' here since the
2984 ;; arity of such filters is different.
2985 (dolist (filter (plist-get info :filter-options))
2986 (let ((result (funcall filter info backend)))
2987 (when result (setq info result))))
2988 ;; Parse buffer and call parse-tree filter on it.
2989 (setq tree
2990 (org-export-filter-apply-functions
2991 (plist-get info :filter-parse-tree)
2992 (org-element-parse-buffer nil visible-only) info))
2993 ;; Now tree is complete, compute its properties and add them
2994 ;; to communication channel.
2995 (setq info
2996 (org-combine-plists
2997 info (org-export-collect-tree-properties tree info)))
2998 ;; Eventually transcode TREE. Wrap the resulting string into
2999 ;; a template.
3000 (let* ((body (org-element-normalize-string
3001 (or (org-export-data tree info) "")))
3002 (inner-template (cdr (assq 'inner-template
3003 (plist-get info :translate-alist))))
3004 (full-body (if (not (functionp inner-template)) body
3005 (funcall inner-template body info)))
3006 (template (cdr (assq 'template
3007 (plist-get info :translate-alist)))))
3008 ;; Remove all text properties since they cannot be
3009 ;; retrieved from an external process. Finally call
3010 ;; final-output filter and return result.
3011 (org-no-properties
3012 (org-export-filter-apply-functions
3013 (plist-get info :filter-final-output)
3014 (if (or (not (functionp template)) body-only) full-body
3015 (funcall template full-body info))
3016 info))))))))
3018 ;;;###autoload
3019 (defun org-export-to-buffer
3020 (backend buffer &optional subtreep visible-only body-only ext-plist)
3021 "Call `org-export-as' with output to a specified buffer.
3023 BACKEND is the back-end used for transcoding, as a symbol.
3025 BUFFER is the output buffer. If it already exists, it will be
3026 erased first, otherwise, it will be created.
3028 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
3029 EXT-PLIST are similar to those used in `org-export-as', which
3030 see.
3032 Depending on `org-export-copy-to-kill-ring', add buffer contents
3033 to kill ring. Return buffer."
3034 (let ((out (org-export-as backend subtreep visible-only body-only ext-plist))
3035 (buffer (get-buffer-create buffer)))
3036 (with-current-buffer buffer
3037 (erase-buffer)
3038 (insert out)
3039 (goto-char (point-min)))
3040 ;; Maybe add buffer contents to kill ring.
3041 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p out))
3042 (org-kill-new out))
3043 ;; Return buffer.
3044 buffer))
3046 ;;;###autoload
3047 (defun org-export-to-file
3048 (backend file &optional subtreep visible-only body-only ext-plist)
3049 "Call `org-export-as' with output to a specified file.
3051 BACKEND is the back-end used for transcoding, as a symbol. FILE
3052 is the name of the output file, as a string.
3054 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
3055 EXT-PLIST are similar to those used in `org-export-as', which
3056 see.
3058 Depending on `org-export-copy-to-kill-ring', add file contents
3059 to kill ring. Return output file's name."
3060 ;; Checks for FILE permissions. `write-file' would do the same, but
3061 ;; we'd rather avoid needless transcoding of parse tree.
3062 (unless (file-writable-p file) (error "Output file not writable"))
3063 ;; Insert contents to a temporary buffer and write it to FILE.
3064 (let ((coding buffer-file-coding-system)
3065 (out (org-export-as backend subtreep visible-only body-only ext-plist)))
3066 (with-temp-buffer
3067 (insert out)
3068 (let ((coding-system-for-write (or org-export-coding-system coding)))
3069 (write-file file)))
3070 ;; Maybe add file contents to kill ring.
3071 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p out))
3072 (org-kill-new out)))
3073 ;; Return full path.
3074 file)
3076 ;;;###autoload
3077 (defun org-export-string-as (string backend &optional body-only ext-plist)
3078 "Transcode STRING into BACKEND code.
3080 When optional argument BODY-ONLY is non-nil, only return body
3081 code, without preamble nor postamble.
3083 Optional argument EXT-PLIST, when provided, is a property list
3084 with external parameters overriding Org default settings, but
3085 still inferior to file-local settings.
3087 Return code as a string."
3088 (with-temp-buffer
3089 (insert string)
3090 (let ((org-inhibit-startup t)) (org-mode))
3091 (org-export-as backend nil nil body-only ext-plist)))
3093 ;;;###autoload
3094 (defun org-export-replace-region-by (backend)
3095 "Replace the active region by its export to BACKEND."
3096 (if (not (org-region-active-p))
3097 (user-error "No active region to replace")
3098 (let* ((beg (region-beginning))
3099 (end (region-end))
3100 (str (buffer-substring beg end)) rpl)
3101 (setq rpl (org-export-string-as str backend t))
3102 (delete-region beg end)
3103 (insert rpl))))
3105 ;;;###autoload
3106 (defun org-export-insert-default-template (&optional backend subtreep)
3107 "Insert all export keywords with default values at beginning of line.
3109 BACKEND is a symbol representing the export back-end for which
3110 specific export options should be added to the template, or
3111 `default' for default template. When it is nil, the user will be
3112 prompted for a category.
3114 If SUBTREEP is non-nil, export configuration will be set up
3115 locally for the subtree through node properties."
3116 (interactive)
3117 (unless (derived-mode-p 'org-mode) (user-error "Not in an Org mode buffer"))
3118 (when (and subtreep (org-before-first-heading-p))
3119 (user-error "No subtree to set export options for"))
3120 (let ((node (and subtreep (save-excursion (org-back-to-heading t) (point))))
3121 (backend (or backend
3122 (intern
3123 (org-completing-read
3124 "Options category: "
3125 (cons "default"
3126 (mapcar (lambda (b) (symbol-name (car b)))
3127 org-export-registered-backends))))))
3128 options keywords)
3129 ;; Populate OPTIONS and KEYWORDS.
3130 (dolist (entry (if (eq backend 'default) org-export-options-alist
3131 (org-export-backend-options backend)))
3132 (let ((keyword (nth 1 entry))
3133 (option (nth 2 entry)))
3134 (cond
3135 (keyword (unless (assoc keyword keywords)
3136 (let ((value
3137 (if (eq (nth 4 entry) 'split)
3138 (mapconcat 'identity (eval (nth 3 entry)) " ")
3139 (eval (nth 3 entry)))))
3140 (push (cons keyword value) keywords))))
3141 (option (unless (assoc option options)
3142 (push (cons option (eval (nth 3 entry))) options))))))
3143 ;; Move to an appropriate location in order to insert options.
3144 (unless subtreep (beginning-of-line))
3145 ;; First get TITLE, DATE, AUTHOR and EMAIL if they belong to the
3146 ;; list of available keywords.
3147 (when (assoc "TITLE" keywords)
3148 (let ((title
3149 (or (let ((visited-file (buffer-file-name (buffer-base-buffer))))
3150 (and visited-file
3151 (file-name-sans-extension
3152 (file-name-nondirectory visited-file))))
3153 (buffer-name (buffer-base-buffer)))))
3154 (if (not subtreep) (insert (format "#+TITLE: %s\n" title))
3155 (org-entry-put node "EXPORT_TITLE" title))))
3156 (when (assoc "DATE" keywords)
3157 (let ((date (with-temp-buffer (org-insert-time-stamp (current-time)))))
3158 (if (not subtreep) (insert "#+DATE: " date "\n")
3159 (org-entry-put node "EXPORT_DATE" date))))
3160 (when (assoc "AUTHOR" keywords)
3161 (let ((author (cdr (assoc "AUTHOR" keywords))))
3162 (if subtreep (org-entry-put node "EXPORT_AUTHOR" author)
3163 (insert
3164 (format "#+AUTHOR:%s\n"
3165 (if (not (org-string-nw-p author)) ""
3166 (concat " " author)))))))
3167 (when (assoc "EMAIL" keywords)
3168 (let ((email (cdr (assoc "EMAIL" keywords))))
3169 (if subtreep (org-entry-put node "EXPORT_EMAIL" email)
3170 (insert
3171 (format "#+EMAIL:%s\n"
3172 (if (not (org-string-nw-p email)) ""
3173 (concat " " email)))))))
3174 ;; Then (multiple) OPTIONS lines. Never go past fill-column.
3175 (when options
3176 (let ((items
3177 (mapcar
3178 (lambda (opt)
3179 (format "%s:%s" (car opt) (format "%s" (cdr opt))))
3180 (sort options (lambda (k1 k2) (string< (car k1) (car k2)))))))
3181 (if subtreep
3182 (org-entry-put
3183 node "EXPORT_OPTIONS" (mapconcat 'identity items " "))
3184 (while items
3185 (insert "#+OPTIONS:")
3186 (let ((width 10))
3187 (while (and items
3188 (< (+ width (length (car items)) 1) fill-column))
3189 (let ((item (pop items)))
3190 (insert " " item)
3191 (incf width (1+ (length item))))))
3192 (insert "\n")))))
3193 ;; And the rest of keywords.
3194 (dolist (key (sort keywords (lambda (k1 k2) (string< (car k1) (car k2)))))
3195 (unless (member (car key) '("TITLE" "DATE" "AUTHOR" "EMAIL"))
3196 (let ((val (cdr key)))
3197 (if subtreep (org-entry-put node (concat "EXPORT_" (car key)) val)
3198 (insert
3199 (format "#+%s:%s\n"
3200 (car key)
3201 (if (org-string-nw-p val) (format " %s" val) "")))))))))
3203 (defun org-export-output-file-name (extension &optional subtreep pub-dir)
3204 "Return output file's name according to buffer specifications.
3206 EXTENSION is a string representing the output file extension,
3207 with the leading dot.
3209 With a non-nil optional argument SUBTREEP, try to determine
3210 output file's name by looking for \"EXPORT_FILE_NAME\" property
3211 of subtree at point.
3213 When optional argument PUB-DIR is set, use it as the publishing
3214 directory.
3216 When optional argument VISIBLE-ONLY is non-nil, don't export
3217 contents of hidden elements.
3219 Return file name as a string."
3220 (let* ((visited-file (buffer-file-name (buffer-base-buffer)))
3221 (base-name
3222 ;; File name may come from EXPORT_FILE_NAME subtree
3223 ;; property, assuming point is at beginning of said
3224 ;; sub-tree.
3225 (file-name-sans-extension
3226 (or (and subtreep
3227 (org-entry-get
3228 (save-excursion
3229 (ignore-errors (org-back-to-heading) (point)))
3230 "EXPORT_FILE_NAME" t))
3231 ;; File name may be extracted from buffer's associated
3232 ;; file, if any.
3233 (and visited-file (file-name-nondirectory visited-file))
3234 ;; Can't determine file name on our own: Ask user.
3235 (let ((read-file-name-function
3236 (and org-completion-use-ido 'ido-read-file-name)))
3237 (read-file-name
3238 "Output file: " pub-dir nil nil nil
3239 (lambda (name)
3240 (string= (file-name-extension name t) extension)))))))
3241 (output-file
3242 ;; Build file name. Enforce EXTENSION over whatever user
3243 ;; may have come up with. PUB-DIR, if defined, always has
3244 ;; precedence over any provided path.
3245 (cond
3246 (pub-dir
3247 (concat (file-name-as-directory pub-dir)
3248 (file-name-nondirectory base-name)
3249 extension))
3250 ((file-name-absolute-p base-name) (concat base-name extension))
3251 (t (concat (file-name-as-directory ".") base-name extension)))))
3252 ;; If writing to OUTPUT-FILE would overwrite original file, append
3253 ;; EXTENSION another time to final name.
3254 (if (and visited-file (org-file-equal-p visited-file output-file))
3255 (concat output-file extension)
3256 output-file)))
3258 (defun org-export-expand-include-keyword (&optional included dir)
3259 "Expand every include keyword in buffer.
3260 Optional argument INCLUDED is a list of included file names along
3261 with their line restriction, when appropriate. It is used to
3262 avoid infinite recursion. Optional argument DIR is the current
3263 working directory. It is used to properly resolve relative
3264 paths."
3265 (let ((case-fold-search t))
3266 (goto-char (point-min))
3267 (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
3268 (let ((element (save-match-data (org-element-at-point))))
3269 (when (eq (org-element-type element) 'keyword)
3270 (beginning-of-line)
3271 ;; Extract arguments from keyword's value.
3272 (let* ((value (org-element-property :value element))
3273 (ind (org-get-indentation))
3274 (file (and (string-match
3275 "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value)
3276 (prog1 (expand-file-name
3277 (org-remove-double-quotes
3278 (match-string 1 value))
3279 dir)
3280 (setq value (replace-match "" nil nil value)))))
3281 (lines
3282 (and (string-match
3283 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
3284 value)
3285 (prog1 (match-string 1 value)
3286 (setq value (replace-match "" nil nil value)))))
3287 (env (cond ((string-match "\\<example\\>" value) 'example)
3288 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
3289 (match-string 1 value))))
3290 ;; Minimal level of included file defaults to the child
3291 ;; level of the current headline, if any, or one. It
3292 ;; only applies is the file is meant to be included as
3293 ;; an Org one.
3294 (minlevel
3295 (and (not env)
3296 (if (string-match ":minlevel +\\([0-9]+\\)" value)
3297 (prog1 (string-to-number (match-string 1 value))
3298 (setq value (replace-match "" nil nil value)))
3299 (let ((cur (org-current-level)))
3300 (if cur (1+ (org-reduced-level cur)) 1))))))
3301 ;; Remove keyword.
3302 (delete-region (point) (progn (forward-line) (point)))
3303 (cond
3304 ((not file) nil)
3305 ((not (file-readable-p file))
3306 (error "Cannot include file %s" file))
3307 ;; Check if files has already been parsed. Look after
3308 ;; inclusion lines too, as different parts of the same file
3309 ;; can be included too.
3310 ((member (list file lines) included)
3311 (error "Recursive file inclusion: %s" file))
3313 (cond
3314 ((eq env 'example)
3315 (insert
3316 (let ((ind-str (make-string ind ? ))
3317 (contents
3318 (org-escape-code-in-string
3319 (org-export--prepare-file-contents file lines))))
3320 (format "%s#+BEGIN_EXAMPLE\n%s%s#+END_EXAMPLE\n"
3321 ind-str contents ind-str))))
3322 ((stringp env)
3323 (insert
3324 (let ((ind-str (make-string ind ? ))
3325 (contents
3326 (org-escape-code-in-string
3327 (org-export--prepare-file-contents file lines))))
3328 (format "%s#+BEGIN_SRC %s\n%s%s#+END_SRC\n"
3329 ind-str env contents ind-str))))
3331 (insert
3332 (with-temp-buffer
3333 (let ((org-inhibit-startup t)) (org-mode))
3334 (insert
3335 (org-export--prepare-file-contents file lines ind minlevel))
3336 (org-export-expand-include-keyword
3337 (cons (list file lines) included)
3338 (file-name-directory file))
3339 (buffer-string)))))))))))))
3341 (defun org-export--prepare-file-contents (file &optional lines ind minlevel)
3342 "Prepare the contents of FILE for inclusion and return them as a string.
3344 When optional argument LINES is a string specifying a range of
3345 lines, include only those lines.
3347 Optional argument IND, when non-nil, is an integer specifying the
3348 global indentation of returned contents. Since its purpose is to
3349 allow an included file to stay in the same environment it was
3350 created \(i.e. a list item), it doesn't apply past the first
3351 headline encountered.
3353 Optional argument MINLEVEL, when non-nil, is an integer
3354 specifying the level that any top-level headline in the included
3355 file should have."
3356 (with-temp-buffer
3357 (insert-file-contents file)
3358 (when lines
3359 (let* ((lines (split-string lines "-"))
3360 (lbeg (string-to-number (car lines)))
3361 (lend (string-to-number (cadr lines)))
3362 (beg (if (zerop lbeg) (point-min)
3363 (goto-char (point-min))
3364 (forward-line (1- lbeg))
3365 (point)))
3366 (end (if (zerop lend) (point-max)
3367 (goto-char (point-min))
3368 (forward-line (1- lend))
3369 (point))))
3370 (narrow-to-region beg end)))
3371 ;; Remove blank lines at beginning and end of contents. The logic
3372 ;; behind that removal is that blank lines around include keyword
3373 ;; override blank lines in included file.
3374 (goto-char (point-min))
3375 (org-skip-whitespace)
3376 (beginning-of-line)
3377 (delete-region (point-min) (point))
3378 (goto-char (point-max))
3379 (skip-chars-backward " \r\t\n")
3380 (forward-line)
3381 (delete-region (point) (point-max))
3382 ;; If IND is set, preserve indentation of include keyword until
3383 ;; the first headline encountered.
3384 (when ind
3385 (unless (eq major-mode 'org-mode)
3386 (let ((org-inhibit-startup t)) (org-mode)))
3387 (goto-char (point-min))
3388 (let ((ind-str (make-string ind ? )))
3389 (while (not (or (eobp) (looking-at org-outline-regexp-bol)))
3390 ;; Do not move footnote definitions out of column 0.
3391 (unless (and (looking-at org-footnote-definition-re)
3392 (eq (org-element-type (org-element-at-point))
3393 'footnote-definition))
3394 (insert ind-str))
3395 (forward-line))))
3396 ;; When MINLEVEL is specified, compute minimal level for headlines
3397 ;; in the file (CUR-MIN), and remove stars to each headline so
3398 ;; that headlines with minimal level have a level of MINLEVEL.
3399 (when minlevel
3400 (unless (eq major-mode 'org-mode)
3401 (let ((org-inhibit-startup t)) (org-mode)))
3402 (org-with-limited-levels
3403 (let ((levels (org-map-entries
3404 (lambda () (org-reduced-level (org-current-level))))))
3405 (when levels
3406 (let ((offset (- minlevel (apply 'min levels))))
3407 (unless (zerop offset)
3408 (when org-odd-levels-only (setq offset (* offset 2)))
3409 ;; Only change stars, don't bother moving whole
3410 ;; sections.
3411 (org-map-entries
3412 (lambda () (if (< offset 0) (delete-char (abs offset))
3413 (insert (make-string offset ?*)))))))))))
3414 (org-element-normalize-string (buffer-string))))
3416 (defun org-export-execute-babel-code ()
3417 "Execute every Babel code in the visible part of current buffer."
3418 ;; Get a pristine copy of current buffer so Babel references can be
3419 ;; properly resolved.
3420 (let ((reference (org-export-copy-buffer)))
3421 (unwind-protect (let ((org-current-export-file reference))
3422 (org-babel-exp-process-buffer))
3423 (kill-buffer reference))))
3425 (defun org-export--copy-to-kill-ring-p ()
3426 "Return a non-nil value when output should be added to the kill ring.
3427 See also `org-export-copy-to-kill-ring'."
3428 (if (eq org-export-copy-to-kill-ring 'if-interactive)
3429 (not (or executing-kbd-macro noninteractive))
3430 (eq org-export-copy-to-kill-ring t)))
3434 ;;; Tools For Back-Ends
3436 ;; A whole set of tools is available to help build new exporters. Any
3437 ;; function general enough to have its use across many back-ends
3438 ;; should be added here.
3440 ;;;; For Affiliated Keywords
3442 ;; `org-export-read-attribute' reads a property from a given element
3443 ;; as a plist. It can be used to normalize affiliated keywords'
3444 ;; syntax.
3446 ;; Since captions can span over multiple lines and accept dual values,
3447 ;; their internal representation is a bit tricky. Therefore,
3448 ;; `org-export-get-caption' transparently returns a given element's
3449 ;; caption as a secondary string.
3451 (defun org-export-read-attribute (attribute element &optional property)
3452 "Turn ATTRIBUTE property from ELEMENT into a plist.
3454 When optional argument PROPERTY is non-nil, return the value of
3455 that property within attributes.
3457 This function assumes attributes are defined as \":keyword
3458 value\" pairs. It is appropriate for `:attr_html' like
3459 properties.
3461 All values will become strings except the empty string and
3462 \"nil\", which will become nil. Also, values containing only
3463 double quotes will be read as-is, which means that \"\" value
3464 will become the empty string."
3465 (let* ((prepare-value
3466 (lambda (str)
3467 (save-match-data
3468 (cond ((member str '(nil "" "nil")) nil)
3469 ((string-match "^\"\\(\"+\\)?\"$" str)
3470 (or (match-string 1 str) ""))
3471 (t str)))))
3472 (attributes
3473 (let ((value (org-element-property attribute element)))
3474 (when value
3475 (let ((s (mapconcat 'identity value " ")) result)
3476 (while (string-match
3477 "\\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ \t]+\\|$\\)"
3479 (let ((value (substring s 0 (match-beginning 0))))
3480 (push (funcall prepare-value value) result))
3481 (push (intern (match-string 1 s)) result)
3482 (setq s (substring s (match-end 0))))
3483 ;; Ignore any string before first property with `cdr'.
3484 (cdr (nreverse (cons (funcall prepare-value s) result))))))))
3485 (if property (plist-get attributes property) attributes)))
3487 (defun org-export-get-caption (element &optional shortp)
3488 "Return caption from ELEMENT as a secondary string.
3490 When optional argument SHORTP is non-nil, return short caption,
3491 as a secondary string, instead.
3493 Caption lines are separated by a white space."
3494 (let ((full-caption (org-element-property :caption element)) caption)
3495 (dolist (line full-caption (cdr caption))
3496 (let ((cap (funcall (if shortp 'cdr 'car) line)))
3497 (when cap
3498 (setq caption (nconc (list " ") (copy-sequence cap) caption)))))))
3501 ;;;; For Derived Back-ends
3503 ;; `org-export-with-backend' is a function allowing to locally use
3504 ;; another back-end to transcode some object or element. In a derived
3505 ;; back-end, it may be used as a fall-back function once all specific
3506 ;; cases have been treated.
3508 (defun org-export-with-backend (back-end data &optional contents info)
3509 "Call a transcoder from BACK-END on DATA.
3510 CONTENTS, when non-nil, is the transcoded contents of DATA
3511 element, as a string. INFO, when non-nil, is the communication
3512 channel used for export, as a plist.."
3513 (org-export-barf-if-invalid-backend back-end)
3514 (let ((type (org-element-type data)))
3515 (if (memq type '(nil org-data)) (error "No foreign transcoder available")
3516 (let ((transcoder
3517 (cdr (assq type (org-export-backend-translate-table back-end)))))
3518 (if (functionp transcoder) (funcall transcoder data contents info)
3519 (error "No foreign transcoder available"))))))
3522 ;;;; For Export Snippets
3524 ;; Every export snippet is transmitted to the back-end. Though, the
3525 ;; latter will only retain one type of export-snippet, ignoring
3526 ;; others, based on the former's target back-end. The function
3527 ;; `org-export-snippet-backend' returns that back-end for a given
3528 ;; export-snippet.
3530 (defun org-export-snippet-backend (export-snippet)
3531 "Return EXPORT-SNIPPET targeted back-end as a symbol.
3532 Translation, with `org-export-snippet-translation-alist', is
3533 applied."
3534 (let ((back-end (org-element-property :back-end export-snippet)))
3535 (intern
3536 (or (cdr (assoc back-end org-export-snippet-translation-alist))
3537 back-end))))
3540 ;;;; For Footnotes
3542 ;; `org-export-collect-footnote-definitions' is a tool to list
3543 ;; actually used footnotes definitions in the whole parse tree, or in
3544 ;; a headline, in order to add footnote listings throughout the
3545 ;; transcoded data.
3547 ;; `org-export-footnote-first-reference-p' is a predicate used by some
3548 ;; back-ends, when they need to attach the footnote definition only to
3549 ;; the first occurrence of the corresponding label.
3551 ;; `org-export-get-footnote-definition' and
3552 ;; `org-export-get-footnote-number' provide easier access to
3553 ;; additional information relative to a footnote reference.
3555 (defun org-export-collect-footnote-definitions (data info)
3556 "Return an alist between footnote numbers, labels and definitions.
3558 DATA is the parse tree from which definitions are collected.
3559 INFO is the plist used as a communication channel.
3561 Definitions are sorted by order of references. They either
3562 appear as Org data or as a secondary string for inlined
3563 footnotes. Unreferenced definitions are ignored."
3564 (let* (num-alist
3565 collect-fn ; for byte-compiler.
3566 (collect-fn
3567 (function
3568 (lambda (data)
3569 ;; Collect footnote number, label and definition in DATA.
3570 (org-element-map data 'footnote-reference
3571 (lambda (fn)
3572 (when (org-export-footnote-first-reference-p fn info)
3573 (let ((def (org-export-get-footnote-definition fn info)))
3574 (push
3575 (list (org-export-get-footnote-number fn info)
3576 (org-element-property :label fn)
3577 def)
3578 num-alist)
3579 ;; Also search in definition for nested footnotes.
3580 (when (eq (org-element-property :type fn) 'standard)
3581 (funcall collect-fn def)))))
3582 ;; Don't enter footnote definitions since it will happen
3583 ;; when their first reference is found.
3584 info nil 'footnote-definition)))))
3585 (funcall collect-fn (plist-get info :parse-tree))
3586 (reverse num-alist)))
3588 (defun org-export-footnote-first-reference-p (footnote-reference info)
3589 "Non-nil when a footnote reference is the first one for its label.
3591 FOOTNOTE-REFERENCE is the footnote reference being considered.
3592 INFO is the plist used as a communication channel."
3593 (let ((label (org-element-property :label footnote-reference)))
3594 ;; Anonymous footnotes are always a first reference.
3595 (if (not label) t
3596 ;; Otherwise, return the first footnote with the same LABEL and
3597 ;; test if it is equal to FOOTNOTE-REFERENCE.
3598 (let* (search-refs ; for byte-compiler.
3599 (search-refs
3600 (function
3601 (lambda (data)
3602 (org-element-map data 'footnote-reference
3603 (lambda (fn)
3604 (cond
3605 ((string= (org-element-property :label fn) label)
3606 (throw 'exit fn))
3607 ;; If FN isn't inlined, be sure to traverse its
3608 ;; definition before resuming search. See
3609 ;; comments in `org-export-get-footnote-number'
3610 ;; for more information.
3611 ((eq (org-element-property :type fn) 'standard)
3612 (funcall search-refs
3613 (org-export-get-footnote-definition fn info)))))
3614 ;; Don't enter footnote definitions since it will
3615 ;; happen when their first reference is found.
3616 info 'first-match 'footnote-definition)))))
3617 (eq (catch 'exit (funcall search-refs (plist-get info :parse-tree)))
3618 footnote-reference)))))
3620 (defun org-export-get-footnote-definition (footnote-reference info)
3621 "Return definition of FOOTNOTE-REFERENCE as parsed data.
3622 INFO is the plist used as a communication channel. If no such
3623 definition can be found, return the \"DEFINITION NOT FOUND\"
3624 string."
3625 (let ((label (org-element-property :label footnote-reference)))
3626 (or (org-element-property :inline-definition footnote-reference)
3627 (cdr (assoc label (plist-get info :footnote-definition-alist)))
3628 "DEFINITION NOT FOUND.")))
3630 (defun org-export-get-footnote-number (footnote info)
3631 "Return number associated to a footnote.
3633 FOOTNOTE is either a footnote reference or a footnote definition.
3634 INFO is the plist used as a communication channel."
3635 (let* ((label (org-element-property :label footnote))
3636 seen-refs
3637 search-ref ; For byte-compiler.
3638 (search-ref
3639 (function
3640 (lambda (data)
3641 ;; Search footnote references through DATA, filling
3642 ;; SEEN-REFS along the way.
3643 (org-element-map data 'footnote-reference
3644 (lambda (fn)
3645 (let ((fn-lbl (org-element-property :label fn)))
3646 (cond
3647 ;; Anonymous footnote match: return number.
3648 ((and (not fn-lbl) (eq fn footnote))
3649 (throw 'exit (1+ (length seen-refs))))
3650 ;; Labels match: return number.
3651 ((and label (string= label fn-lbl))
3652 (throw 'exit (1+ (length seen-refs))))
3653 ;; Anonymous footnote: it's always a new one.
3654 ;; Also, be sure to return nil from the `cond' so
3655 ;; `first-match' doesn't get us out of the loop.
3656 ((not fn-lbl) (push 'inline seen-refs) nil)
3657 ;; Label not seen so far: add it so SEEN-REFS.
3659 ;; Also search for subsequent references in
3660 ;; footnote definition so numbering follows
3661 ;; reading logic. Note that we don't have to care
3662 ;; about inline definitions, since
3663 ;; `org-element-map' already traverses them at the
3664 ;; right time.
3666 ;; Once again, return nil to stay in the loop.
3667 ((not (member fn-lbl seen-refs))
3668 (push fn-lbl seen-refs)
3669 (funcall search-ref
3670 (org-export-get-footnote-definition fn info))
3671 nil))))
3672 ;; Don't enter footnote definitions since it will
3673 ;; happen when their first reference is found.
3674 info 'first-match 'footnote-definition)))))
3675 (catch 'exit (funcall search-ref (plist-get info :parse-tree)))))
3678 ;;;; For Headlines
3680 ;; `org-export-get-relative-level' is a shortcut to get headline
3681 ;; level, relatively to the lower headline level in the parsed tree.
3683 ;; `org-export-get-headline-number' returns the section number of an
3684 ;; headline, while `org-export-number-to-roman' allows to convert it
3685 ;; to roman numbers.
3687 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
3688 ;; `org-export-last-sibling-p' are three useful predicates when it
3689 ;; comes to fulfill the `:headline-levels' property.
3691 ;; `org-export-get-tags', `org-export-get-category' and
3692 ;; `org-export-get-node-property' extract useful information from an
3693 ;; headline or a parent headline. They all handle inheritance.
3695 ;; `org-export-get-alt-title' tries to retrieve an alternative title,
3696 ;; as a secondary string, suitable for table of contents. It falls
3697 ;; back onto default title.
3699 (defun org-export-get-relative-level (headline info)
3700 "Return HEADLINE relative level within current parsed tree.
3701 INFO is a plist holding contextual information."
3702 (+ (org-element-property :level headline)
3703 (or (plist-get info :headline-offset) 0)))
3705 (defun org-export-low-level-p (headline info)
3706 "Non-nil when HEADLINE is considered as low level.
3708 INFO is a plist used as a communication channel.
3710 A low level headlines has a relative level greater than
3711 `:headline-levels' property value.
3713 Return value is the difference between HEADLINE relative level
3714 and the last level being considered as high enough, or nil."
3715 (let ((limit (plist-get info :headline-levels)))
3716 (when (wholenump limit)
3717 (let ((level (org-export-get-relative-level headline info)))
3718 (and (> level limit) (- level limit))))))
3720 (defun org-export-get-headline-number (headline info)
3721 "Return HEADLINE numbering as a list of numbers.
3722 INFO is a plist holding contextual information."
3723 (cdr (assoc headline (plist-get info :headline-numbering))))
3725 (defun org-export-numbered-headline-p (headline info)
3726 "Return a non-nil value if HEADLINE element should be numbered.
3727 INFO is a plist used as a communication channel."
3728 (let ((sec-num (plist-get info :section-numbers))
3729 (level (org-export-get-relative-level headline info)))
3730 (if (wholenump sec-num) (<= level sec-num) sec-num)))
3732 (defun org-export-number-to-roman (n)
3733 "Convert integer N into a roman numeral."
3734 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
3735 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
3736 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
3737 ( 1 . "I")))
3738 (res ""))
3739 (if (<= n 0)
3740 (number-to-string n)
3741 (while roman
3742 (if (>= n (caar roman))
3743 (setq n (- n (caar roman))
3744 res (concat res (cdar roman)))
3745 (pop roman)))
3746 res)))
3748 (defun org-export-get-tags (element info &optional tags inherited)
3749 "Return list of tags associated to ELEMENT.
3751 ELEMENT has either an `headline' or an `inlinetask' type. INFO
3752 is a plist used as a communication channel.
3754 Select tags (see `org-export-select-tags') and exclude tags (see
3755 `org-export-exclude-tags') are removed from the list.
3757 When non-nil, optional argument TAGS should be a list of strings.
3758 Any tag belonging to this list will also be removed.
3760 When optional argument INHERITED is non-nil, tags can also be
3761 inherited from parent headlines and FILETAGS keywords."
3762 (org-remove-if
3763 (lambda (tag) (or (member tag (plist-get info :select-tags))
3764 (member tag (plist-get info :exclude-tags))
3765 (member tag tags)))
3766 (if (not inherited) (org-element-property :tags element)
3767 ;; Build complete list of inherited tags.
3768 (let ((current-tag-list (org-element-property :tags element)))
3769 (mapc
3770 (lambda (parent)
3771 (mapc
3772 (lambda (tag)
3773 (when (and (memq (org-element-type parent) '(headline inlinetask))
3774 (not (member tag current-tag-list)))
3775 (push tag current-tag-list)))
3776 (org-element-property :tags parent)))
3777 (org-export-get-genealogy element))
3778 ;; Add FILETAGS keywords and return results.
3779 (org-uniquify (append (plist-get info :filetags) current-tag-list))))))
3781 (defun org-export-get-node-property (property blob &optional inherited)
3782 "Return node PROPERTY value for BLOB.
3784 PROPERTY is an upcase symbol (i.e. `:COOKIE_DATA'). BLOB is an
3785 element or object.
3787 If optional argument INHERITED is non-nil, the value can be
3788 inherited from a parent headline.
3790 Return value is a string or nil."
3791 (let ((headline (if (eq (org-element-type blob) 'headline) blob
3792 (org-export-get-parent-headline blob))))
3793 (if (not inherited) (org-element-property property blob)
3794 (let ((parent headline) value)
3795 (catch 'found
3796 (while parent
3797 (when (plist-member (nth 1 parent) property)
3798 (throw 'found (org-element-property property parent)))
3799 (setq parent (org-element-property :parent parent))))))))
3801 (defun org-export-get-category (blob info)
3802 "Return category for element or object BLOB.
3804 INFO is a plist used as a communication channel.
3806 CATEGORY is automatically inherited from a parent headline, from
3807 #+CATEGORY: keyword or created out of original file name. If all
3808 fail, the fall-back value is \"???\"."
3809 (or (let ((headline (if (eq (org-element-type blob) 'headline) blob
3810 (org-export-get-parent-headline blob))))
3811 ;; Almost like `org-export-node-property', but we cannot trust
3812 ;; `plist-member' as every headline has a `:CATEGORY'
3813 ;; property, would it be nil or equal to "???" (which has the
3814 ;; same meaning).
3815 (let ((parent headline) value)
3816 (catch 'found
3817 (while parent
3818 (let ((category (org-element-property :CATEGORY parent)))
3819 (and category (not (equal "???" category))
3820 (throw 'found category)))
3821 (setq parent (org-element-property :parent parent))))))
3822 (org-element-map (plist-get info :parse-tree) 'keyword
3823 (lambda (kwd)
3824 (when (equal (org-element-property :key kwd) "CATEGORY")
3825 (org-element-property :value kwd)))
3826 info 'first-match)
3827 (let ((file (plist-get info :input-file)))
3828 (and file (file-name-sans-extension (file-name-nondirectory file))))
3829 "???"))
3831 (defun org-export-get-alt-title (headline info)
3832 "Return alternative title for HEADLINE, as a secondary string.
3833 INFO is a plist used as a communication channel. If no optional
3834 title is defined, fall-back to the regular title."
3835 (or (org-element-property :alt-title headline)
3836 (org-element-property :title headline)))
3838 (defun org-export-first-sibling-p (headline info)
3839 "Non-nil when HEADLINE is the first sibling in its sub-tree.
3840 INFO is a plist used as a communication channel."
3841 (not (eq (org-element-type (org-export-get-previous-element headline info))
3842 'headline)))
3844 (defun org-export-last-sibling-p (headline info)
3845 "Non-nil when HEADLINE is the last sibling in its sub-tree.
3846 INFO is a plist used as a communication channel."
3847 (not (org-export-get-next-element headline info)))
3850 ;;;; For Keywords
3852 ;; `org-export-get-date' returns a date appropriate for the document
3853 ;; to about to be exported. In particular, it takes care of
3854 ;; `org-export-date-timestamp-format'.
3856 (defun org-export-get-date (info &optional fmt)
3857 "Return date value for the current document.
3859 INFO is a plist used as a communication channel. FMT, when
3860 non-nil, is a time format string that will be applied on the date
3861 if it consists in a single timestamp object. It defaults to
3862 `org-export-date-timestamp-format' when nil.
3864 A proper date can be a secondary string, a string or nil. It is
3865 meant to be translated with `org-export-data' or alike."
3866 (let ((date (plist-get info :date))
3867 (fmt (or fmt org-export-date-timestamp-format)))
3868 (cond ((not date) nil)
3869 ((and fmt
3870 (not (cdr date))
3871 (eq (org-element-type (car date)) 'timestamp))
3872 (org-timestamp-format (car date) fmt))
3873 (t date))))
3876 ;;;; For Links
3878 ;; `org-export-solidify-link-text' turns a string into a safer version
3879 ;; for links, replacing most non-standard characters with hyphens.
3881 ;; `org-export-get-coderef-format' returns an appropriate format
3882 ;; string for coderefs.
3884 ;; `org-export-inline-image-p' returns a non-nil value when the link
3885 ;; provided should be considered as an inline image.
3887 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
3888 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
3889 ;; returns an appropriate unique identifier when found, or nil.
3891 ;; `org-export-resolve-id-link' returns the first headline with
3892 ;; specified id or custom-id in parse tree, the path to the external
3893 ;; file with the id or nil when neither was found.
3895 ;; `org-export-resolve-coderef' associates a reference to a line
3896 ;; number in the element it belongs, or returns the reference itself
3897 ;; when the element isn't numbered.
3899 (defun org-export-solidify-link-text (s)
3900 "Take link text S and make a safe target out of it."
3901 (save-match-data
3902 (mapconcat 'identity (org-split-string s "[^a-zA-Z0-9_.-:]+") "-")))
3904 (defun org-export-get-coderef-format (path desc)
3905 "Return format string for code reference link.
3906 PATH is the link path. DESC is its description."
3907 (save-match-data
3908 (cond ((not desc) "%s")
3909 ((string-match (regexp-quote (concat "(" path ")")) desc)
3910 (replace-match "%s" t t desc))
3911 (t desc))))
3913 (defun org-export-inline-image-p (link &optional rules)
3914 "Non-nil if LINK object points to an inline image.
3916 Optional argument is a set of RULES defining inline images. It
3917 is an alist where associations have the following shape:
3919 \(TYPE . REGEXP)
3921 Applying a rule means apply REGEXP against LINK's path when its
3922 type is TYPE. The function will return a non-nil value if any of
3923 the provided rules is non-nil. The default rule is
3924 `org-export-default-inline-image-rule'.
3926 This only applies to links without a description."
3927 (and (not (org-element-contents link))
3928 (let ((case-fold-search t)
3929 (rules (or rules org-export-default-inline-image-rule)))
3930 (catch 'exit
3931 (mapc
3932 (lambda (rule)
3933 (and (string= (org-element-property :type link) (car rule))
3934 (string-match (cdr rule)
3935 (org-element-property :path link))
3936 (throw 'exit t)))
3937 rules)
3938 ;; Return nil if no rule matched.
3939 nil))))
3941 (defun org-export-resolve-coderef (ref info)
3942 "Resolve a code reference REF.
3944 INFO is a plist used as a communication channel.
3946 Return associated line number in source code, or REF itself,
3947 depending on src-block or example element's switches."
3948 (org-element-map (plist-get info :parse-tree) '(example-block src-block)
3949 (lambda (el)
3950 (with-temp-buffer
3951 (insert (org-trim (org-element-property :value el)))
3952 (let* ((label-fmt (regexp-quote
3953 (or (org-element-property :label-fmt el)
3954 org-coderef-label-format)))
3955 (ref-re
3956 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
3957 (replace-regexp-in-string "%s" ref label-fmt nil t))))
3958 ;; Element containing REF is found. Resolve it to either
3959 ;; a label or a line number, as needed.
3960 (when (re-search-backward ref-re nil t)
3961 (cond
3962 ((org-element-property :use-labels el) ref)
3963 ((eq (org-element-property :number-lines el) 'continued)
3964 (+ (org-export-get-loc el info) (line-number-at-pos)))
3965 (t (line-number-at-pos)))))))
3966 info 'first-match))
3968 (defun org-export-resolve-fuzzy-link (link info)
3969 "Return LINK destination.
3971 INFO is a plist holding contextual information.
3973 Return value can be an object, an element, or nil:
3975 - If LINK path matches a target object (i.e. <<path>>) return it.
3977 - If LINK path exactly matches the name affiliated keyword
3978 \(i.e. #+NAME: path) of an element, return that element.
3980 - If LINK path exactly matches any headline name, return that
3981 element. If more than one headline share that name, priority
3982 will be given to the one with the closest common ancestor, if
3983 any, or the first one in the parse tree otherwise.
3985 - Otherwise, return nil.
3987 Assume LINK type is \"fuzzy\". White spaces are not
3988 significant."
3989 (let* ((raw-path (org-element-property :path link))
3990 (match-title-p (eq (aref raw-path 0) ?*))
3991 ;; Split PATH at white spaces so matches are space
3992 ;; insensitive.
3993 (path (org-split-string
3994 (if match-title-p (substring raw-path 1) raw-path)))
3995 ;; Cache for destinations that are not position dependent.
3996 (link-cache
3997 (or (plist-get info :resolve-fuzzy-link-cache)
3998 (plist-get (setq info (plist-put info :resolve-fuzzy-link-cache
3999 (make-hash-table :test 'equal)))
4000 :resolve-fuzzy-link-cache)))
4001 (cached (gethash path link-cache 'not-found)))
4002 (cond
4003 ;; Destination is not position dependent: use cached value.
4004 ((and (not match-title-p) (not (eq cached 'not-found))) cached)
4005 ;; First try to find a matching "<<path>>" unless user specified
4006 ;; he was looking for a headline (path starts with a "*"
4007 ;; character).
4008 ((and (not match-title-p)
4009 (let ((match (org-element-map (plist-get info :parse-tree) 'target
4010 (lambda (blob)
4011 (and (equal (org-split-string
4012 (org-element-property :value blob))
4013 path)
4014 blob))
4015 info 'first-match)))
4016 (and match (puthash path match link-cache)))))
4017 ;; Then try to find an element with a matching "#+NAME: path"
4018 ;; affiliated keyword.
4019 ((and (not match-title-p)
4020 (let ((match (org-element-map (plist-get info :parse-tree)
4021 org-element-all-elements
4022 (lambda (el)
4023 (let ((name (org-element-property :name el)))
4024 (when (and name
4025 (equal (org-split-string name) path))
4026 el)))
4027 info 'first-match)))
4028 (and match (puthash path match link-cache)))))
4029 ;; Last case: link either points to a headline or to nothingness.
4030 ;; Try to find the source, with priority given to headlines with
4031 ;; the closest common ancestor. If such candidate is found,
4032 ;; return it, otherwise return nil.
4034 (let ((find-headline
4035 (function
4036 ;; Return first headline whose `:raw-value' property is
4037 ;; NAME in parse tree DATA, or nil. Statistics cookies
4038 ;; are ignored.
4039 (lambda (name data)
4040 (org-element-map data 'headline
4041 (lambda (headline)
4042 (when (equal (org-split-string
4043 (replace-regexp-in-string
4044 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
4045 (org-element-property :raw-value headline)))
4046 name)
4047 headline))
4048 info 'first-match)))))
4049 ;; Search among headlines sharing an ancestor with link, from
4050 ;; closest to farthest.
4051 (catch 'exit
4052 (mapc
4053 (lambda (parent)
4054 (let ((foundp (funcall find-headline path parent)))
4055 (when foundp (throw 'exit foundp))))
4056 (let ((parent-hl (org-export-get-parent-headline link)))
4057 (if (not parent-hl) (list (plist-get info :parse-tree))
4058 (cons parent-hl (org-export-get-genealogy parent-hl)))))
4059 ;; No destination found: return nil.
4060 (and (not match-title-p) (puthash path nil link-cache))))))))
4062 (defun org-export-resolve-id-link (link info)
4063 "Return headline referenced as LINK destination.
4065 INFO is a plist used as a communication channel.
4067 Return value can be the headline element matched in current parse
4068 tree, a file name or nil. Assume LINK type is either \"id\" or
4069 \"custom-id\"."
4070 (let ((id (org-element-property :path link)))
4071 ;; First check if id is within the current parse tree.
4072 (or (org-element-map (plist-get info :parse-tree) 'headline
4073 (lambda (headline)
4074 (when (or (string= (org-element-property :ID headline) id)
4075 (string= (org-element-property :CUSTOM_ID headline) id))
4076 headline))
4077 info 'first-match)
4078 ;; Otherwise, look for external files.
4079 (cdr (assoc id (plist-get info :id-alist))))))
4081 (defun org-export-resolve-radio-link (link info)
4082 "Return radio-target object referenced as LINK destination.
4084 INFO is a plist used as a communication channel.
4086 Return value can be a radio-target object or nil. Assume LINK
4087 has type \"radio\"."
4088 (let ((path (replace-regexp-in-string
4089 "[ \r\t\n]+" " " (org-element-property :path link))))
4090 (org-element-map (plist-get info :parse-tree) 'radio-target
4091 (lambda (radio)
4092 (and (eq (compare-strings
4093 (replace-regexp-in-string
4094 "[ \r\t\n]+" " " (org-element-property :value radio))
4095 nil nil path nil nil t)
4097 radio))
4098 info 'first-match)))
4101 ;;;; For References
4103 ;; `org-export-get-ordinal' associates a sequence number to any object
4104 ;; or element.
4106 (defun org-export-get-ordinal (element info &optional types predicate)
4107 "Return ordinal number of an element or object.
4109 ELEMENT is the element or object considered. INFO is the plist
4110 used as a communication channel.
4112 Optional argument TYPES, when non-nil, is a list of element or
4113 object types, as symbols, that should also be counted in.
4114 Otherwise, only provided element's type is considered.
4116 Optional argument PREDICATE is a function returning a non-nil
4117 value if the current element or object should be counted in. It
4118 accepts two arguments: the element or object being considered and
4119 the plist used as a communication channel. This allows to count
4120 only a certain type of objects (i.e. inline images).
4122 Return value is a list of numbers if ELEMENT is a headline or an
4123 item. It is nil for keywords. It represents the footnote number
4124 for footnote definitions and footnote references. If ELEMENT is
4125 a target, return the same value as if ELEMENT was the closest
4126 table, item or headline containing the target. In any other
4127 case, return the sequence number of ELEMENT among elements or
4128 objects of the same type."
4129 ;; Ordinal of a target object refer to the ordinal of the closest
4130 ;; table, item, or headline containing the object.
4131 (when (eq (org-element-type element) 'target)
4132 (setq element
4133 (loop for parent in (org-export-get-genealogy element)
4134 when
4135 (memq
4136 (org-element-type parent)
4137 '(footnote-definition footnote-reference headline item
4138 table))
4139 return parent)))
4140 (case (org-element-type element)
4141 ;; Special case 1: A headline returns its number as a list.
4142 (headline (org-export-get-headline-number element info))
4143 ;; Special case 2: An item returns its number as a list.
4144 (item (let ((struct (org-element-property :structure element)))
4145 (org-list-get-item-number
4146 (org-element-property :begin element)
4147 struct
4148 (org-list-prevs-alist struct)
4149 (org-list-parents-alist struct))))
4150 ((footnote-definition footnote-reference)
4151 (org-export-get-footnote-number element info))
4152 (otherwise
4153 (let ((counter 0))
4154 ;; Increment counter until ELEMENT is found again.
4155 (org-element-map (plist-get info :parse-tree)
4156 (or types (org-element-type element))
4157 (lambda (el)
4158 (cond
4159 ((eq element el) (1+ counter))
4160 ((not predicate) (incf counter) nil)
4161 ((funcall predicate el info) (incf counter) nil)))
4162 info 'first-match)))))
4165 ;;;; For Src-Blocks
4167 ;; `org-export-get-loc' counts number of code lines accumulated in
4168 ;; src-block or example-block elements with a "+n" switch until
4169 ;; a given element, excluded. Note: "-n" switches reset that count.
4171 ;; `org-export-unravel-code' extracts source code (along with a code
4172 ;; references alist) from an `element-block' or `src-block' type
4173 ;; element.
4175 ;; `org-export-format-code' applies a formatting function to each line
4176 ;; of code, providing relative line number and code reference when
4177 ;; appropriate. Since it doesn't access the original element from
4178 ;; which the source code is coming, it expects from the code calling
4179 ;; it to know if lines should be numbered and if code references
4180 ;; should appear.
4182 ;; Eventually, `org-export-format-code-default' is a higher-level
4183 ;; function (it makes use of the two previous functions) which handles
4184 ;; line numbering and code references inclusion, and returns source
4185 ;; code in a format suitable for plain text or verbatim output.
4187 (defun org-export-get-loc (element info)
4188 "Return accumulated lines of code up to ELEMENT.
4190 INFO is the plist used as a communication channel.
4192 ELEMENT is excluded from count."
4193 (let ((loc 0))
4194 (org-element-map (plist-get info :parse-tree)
4195 `(src-block example-block ,(org-element-type element))
4196 (lambda (el)
4197 (cond
4198 ;; ELEMENT is reached: Quit the loop.
4199 ((eq el element))
4200 ;; Only count lines from src-block and example-block elements
4201 ;; with a "+n" or "-n" switch. A "-n" switch resets counter.
4202 ((not (memq (org-element-type el) '(src-block example-block))) nil)
4203 ((let ((linums (org-element-property :number-lines el)))
4204 (when linums
4205 ;; Accumulate locs or reset them.
4206 (let ((lines (org-count-lines
4207 (org-trim (org-element-property :value el)))))
4208 (setq loc (if (eq linums 'new) lines (+ loc lines))))))
4209 ;; Return nil to stay in the loop.
4210 nil)))
4211 info 'first-match)
4212 ;; Return value.
4213 loc))
4215 (defun org-export-unravel-code (element)
4216 "Clean source code and extract references out of it.
4218 ELEMENT has either a `src-block' an `example-block' type.
4220 Return a cons cell whose CAR is the source code, cleaned from any
4221 reference and protective comma and CDR is an alist between
4222 relative line number (integer) and name of code reference on that
4223 line (string)."
4224 (let* ((line 0) refs
4225 ;; Get code and clean it. Remove blank lines at its
4226 ;; beginning and end.
4227 (code (replace-regexp-in-string
4228 "\\`\\([ \t]*\n\\)+" ""
4229 (replace-regexp-in-string
4230 "\\([ \t]*\n\\)*[ \t]*\\'" "\n"
4231 (org-element-property :value element))))
4232 ;; Get format used for references.
4233 (label-fmt (regexp-quote
4234 (or (org-element-property :label-fmt element)
4235 org-coderef-label-format)))
4236 ;; Build a regexp matching a loc with a reference.
4237 (with-ref-re
4238 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)[ \t]*\\)$"
4239 (replace-regexp-in-string
4240 "%s" "\\([-a-zA-Z0-9_ ]+\\)" label-fmt nil t))))
4241 ;; Return value.
4242 (cons
4243 ;; Code with references removed.
4244 (org-element-normalize-string
4245 (mapconcat
4246 (lambda (loc)
4247 (incf line)
4248 (if (not (string-match with-ref-re loc)) loc
4249 ;; Ref line: remove ref, and signal its position in REFS.
4250 (push (cons line (match-string 3 loc)) refs)
4251 (replace-match "" nil nil loc 1)))
4252 (org-split-string code "\n") "\n"))
4253 ;; Reference alist.
4254 refs)))
4256 (defun org-export-format-code (code fun &optional num-lines ref-alist)
4257 "Format CODE by applying FUN line-wise and return it.
4259 CODE is a string representing the code to format. FUN is
4260 a function. It must accept three arguments: a line of
4261 code (string), the current line number (integer) or nil and the
4262 reference associated to the current line (string) or nil.
4264 Optional argument NUM-LINES can be an integer representing the
4265 number of code lines accumulated until the current code. Line
4266 numbers passed to FUN will take it into account. If it is nil,
4267 FUN's second argument will always be nil. This number can be
4268 obtained with `org-export-get-loc' function.
4270 Optional argument REF-ALIST can be an alist between relative line
4271 number (i.e. ignoring NUM-LINES) and the name of the code
4272 reference on it. If it is nil, FUN's third argument will always
4273 be nil. It can be obtained through the use of
4274 `org-export-unravel-code' function."
4275 (let ((--locs (org-split-string code "\n"))
4276 (--line 0))
4277 (org-element-normalize-string
4278 (mapconcat
4279 (lambda (--loc)
4280 (incf --line)
4281 (let ((--ref (cdr (assq --line ref-alist))))
4282 (funcall fun --loc (and num-lines (+ num-lines --line)) --ref)))
4283 --locs "\n"))))
4285 (defun org-export-format-code-default (element info)
4286 "Return source code from ELEMENT, formatted in a standard way.
4288 ELEMENT is either a `src-block' or `example-block' element. INFO
4289 is a plist used as a communication channel.
4291 This function takes care of line numbering and code references
4292 inclusion. Line numbers, when applicable, appear at the
4293 beginning of the line, separated from the code by two white
4294 spaces. Code references, on the other hand, appear flushed to
4295 the right, separated by six white spaces from the widest line of
4296 code."
4297 ;; Extract code and references.
4298 (let* ((code-info (org-export-unravel-code element))
4299 (code (car code-info))
4300 (code-lines (org-split-string code "\n")))
4301 (if (null code-lines) ""
4302 (let* ((refs (and (org-element-property :retain-labels element)
4303 (cdr code-info)))
4304 ;; Handle line numbering.
4305 (num-start (case (org-element-property :number-lines element)
4306 (continued (org-export-get-loc element info))
4307 (new 0)))
4308 (num-fmt
4309 (and num-start
4310 (format "%%%ds "
4311 (length (number-to-string
4312 (+ (length code-lines) num-start))))))
4313 ;; Prepare references display, if required. Any reference
4314 ;; should start six columns after the widest line of code,
4315 ;; wrapped with parenthesis.
4316 (max-width
4317 (+ (apply 'max (mapcar 'length code-lines))
4318 (if (not num-start) 0 (length (format num-fmt num-start))))))
4319 (org-export-format-code
4320 code
4321 (lambda (loc line-num ref)
4322 (let ((number-str (and num-fmt (format num-fmt line-num))))
4323 (concat
4324 number-str
4326 (and ref
4327 (concat (make-string
4328 (- (+ 6 max-width)
4329 (+ (length loc) (length number-str))) ? )
4330 (format "(%s)" ref))))))
4331 num-start refs)))))
4334 ;;;; For Tables
4336 ;; `org-export-table-has-special-column-p' and and
4337 ;; `org-export-table-row-is-special-p' are predicates used to look for
4338 ;; meta-information about the table structure.
4340 ;; `org-table-has-header-p' tells when the rows before the first rule
4341 ;; should be considered as table's header.
4343 ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
4344 ;; and `org-export-table-cell-borders' extract information from
4345 ;; a table-cell element.
4347 ;; `org-export-table-dimensions' gives the number on rows and columns
4348 ;; in the table, ignoring horizontal rules and special columns.
4349 ;; `org-export-table-cell-address', given a table-cell object, returns
4350 ;; the absolute address of a cell. On the other hand,
4351 ;; `org-export-get-table-cell-at' does the contrary.
4353 ;; `org-export-table-cell-starts-colgroup-p',
4354 ;; `org-export-table-cell-ends-colgroup-p',
4355 ;; `org-export-table-row-starts-rowgroup-p',
4356 ;; `org-export-table-row-ends-rowgroup-p',
4357 ;; `org-export-table-row-starts-header-p' and
4358 ;; `org-export-table-row-ends-header-p' indicate position of current
4359 ;; row or cell within the table.
4361 (defun org-export-table-has-special-column-p (table)
4362 "Non-nil when TABLE has a special column.
4363 All special columns will be ignored during export."
4364 ;; The table has a special column when every first cell of every row
4365 ;; has an empty value or contains a symbol among "/", "#", "!", "$",
4366 ;; "*" "_" and "^". Though, do not consider a first row containing
4367 ;; only empty cells as special.
4368 (let ((special-column-p 'empty))
4369 (catch 'exit
4370 (mapc
4371 (lambda (row)
4372 (when (eq (org-element-property :type row) 'standard)
4373 (let ((value (org-element-contents
4374 (car (org-element-contents row)))))
4375 (cond ((member value '(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
4376 (setq special-column-p 'special))
4377 ((not value))
4378 (t (throw 'exit nil))))))
4379 (org-element-contents table))
4380 (eq special-column-p 'special))))
4382 (defun org-export-table-has-header-p (table info)
4383 "Non-nil when TABLE has a header.
4385 INFO is a plist used as a communication channel.
4387 A table has a header when it contains at least two row groups."
4388 (let ((cache (or (plist-get info :table-header-cache)
4389 (plist-get (setq info
4390 (plist-put info :table-header-cache
4391 (make-hash-table :test 'eq)))
4392 :table-header-cache))))
4393 (or (gethash table cache)
4394 (let ((rowgroup 1) row-flag)
4395 (puthash
4396 table
4397 (org-element-map table 'table-row
4398 (lambda (row)
4399 (cond
4400 ((> rowgroup 1) t)
4401 ((and row-flag (eq (org-element-property :type row) 'rule))
4402 (incf rowgroup) (setq row-flag nil))
4403 ((and (not row-flag) (eq (org-element-property :type row)
4404 'standard))
4405 (setq row-flag t) nil)))
4406 info 'first-match)
4407 cache)))))
4409 (defun org-export-table-row-is-special-p (table-row info)
4410 "Non-nil if TABLE-ROW is considered special.
4412 INFO is a plist used as the communication channel.
4414 All special rows will be ignored during export."
4415 (when (eq (org-element-property :type table-row) 'standard)
4416 (let ((first-cell (org-element-contents
4417 (car (org-element-contents table-row)))))
4418 ;; A row is special either when...
4420 ;; ... it starts with a field only containing "/",
4421 (equal first-cell '("/"))
4422 ;; ... the table contains a special column and the row start
4423 ;; with a marking character among, "^", "_", "$" or "!",
4424 (and (org-export-table-has-special-column-p
4425 (org-export-get-parent table-row))
4426 (member first-cell '(("^") ("_") ("$") ("!"))))
4427 ;; ... it contains only alignment cookies and empty cells.
4428 (let ((special-row-p 'empty))
4429 (catch 'exit
4430 (mapc
4431 (lambda (cell)
4432 (let ((value (org-element-contents cell)))
4433 ;; Since VALUE is a secondary string, the following
4434 ;; checks avoid expanding it with `org-export-data'.
4435 (cond ((not value))
4436 ((and (not (cdr value))
4437 (stringp (car value))
4438 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
4439 (car value)))
4440 (setq special-row-p 'cookie))
4441 (t (throw 'exit nil)))))
4442 (org-element-contents table-row))
4443 (eq special-row-p 'cookie)))))))
4445 (defun org-export-table-row-group (table-row info)
4446 "Return TABLE-ROW's group number, as an integer.
4448 INFO is a plist used as the communication channel.
4450 Return value is the group number, as an integer, or nil for
4451 special rows and rows separators. First group is also table's
4452 header."
4453 (let ((cache (or (plist-get info :table-row-group-cache)
4454 (plist-get (setq info
4455 (plist-put info :table-row-group-cache
4456 (make-hash-table :test 'eq)))
4457 :table-row-group-cache))))
4458 (cond ((gethash table-row cache))
4459 ((eq (org-element-property :type table-row) 'rule) nil)
4460 (t (let ((group 0) row-flag)
4461 (org-element-map (org-export-get-parent table-row) 'table-row
4462 (lambda (row)
4463 (if (eq (org-element-property :type row) 'rule)
4464 (setq row-flag nil)
4465 (unless row-flag (incf group) (setq row-flag t)))
4466 (when (eq table-row row) (puthash table-row group cache)))
4467 info 'first-match))))))
4469 (defun org-export-table-cell-width (table-cell info)
4470 "Return TABLE-CELL contents width.
4472 INFO is a plist used as the communication channel.
4474 Return value is the width given by the last width cookie in the
4475 same column as TABLE-CELL, or nil."
4476 (let* ((row (org-export-get-parent table-cell))
4477 (table (org-export-get-parent row))
4478 (cells (org-element-contents row))
4479 (columns (length cells))
4480 (column (- columns (length (memq table-cell cells))))
4481 (cache (or (plist-get info :table-cell-width-cache)
4482 (plist-get (setq info
4483 (plist-put info :table-cell-width-cache
4484 (make-hash-table :test 'eq)))
4485 :table-cell-width-cache)))
4486 (width-vector (or (gethash table cache)
4487 (puthash table (make-vector columns 'empty) cache)))
4488 (value (aref width-vector column)))
4489 (if (not (eq value 'empty)) value
4490 (let (cookie-width)
4491 (dolist (row (org-element-contents table)
4492 (aset width-vector column cookie-width))
4493 (when (org-export-table-row-is-special-p row info)
4494 ;; In a special row, try to find a width cookie at COLUMN.
4495 (let* ((value (org-element-contents
4496 (elt (org-element-contents row) column)))
4497 (cookie (car value)))
4498 ;; The following checks avoid expanding unnecessarily
4499 ;; the cell with `org-export-data'.
4500 (when (and value
4501 (not (cdr value))
4502 (stringp cookie)
4503 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" cookie)
4504 (match-string 1 cookie))
4505 (setq cookie-width
4506 (string-to-number (match-string 1 cookie)))))))))))
4508 (defun org-export-table-cell-alignment (table-cell info)
4509 "Return TABLE-CELL contents alignment.
4511 INFO is a plist used as the communication channel.
4513 Return alignment as specified by the last alignment cookie in the
4514 same column as TABLE-CELL. If no such cookie is found, a default
4515 alignment value will be deduced from fraction of numbers in the
4516 column (see `org-table-number-fraction' for more information).
4517 Possible values are `left', `right' and `center'."
4518 ;; Load `org-table-number-fraction' and `org-table-number-regexp'.
4519 (require 'org-table)
4520 (let* ((row (org-export-get-parent table-cell))
4521 (table (org-export-get-parent row))
4522 (cells (org-element-contents row))
4523 (columns (length cells))
4524 (column (- columns (length (memq table-cell cells))))
4525 (cache (or (plist-get info :table-cell-alignment-cache)
4526 (plist-get (setq info
4527 (plist-put info :table-cell-alignment-cache
4528 (make-hash-table :test 'eq)))
4529 :table-cell-alignment-cache)))
4530 (align-vector (or (gethash table cache)
4531 (puthash table (make-vector columns nil) cache))))
4532 (or (aref align-vector column)
4533 (let ((number-cells 0)
4534 (total-cells 0)
4535 cookie-align
4536 previous-cell-number-p)
4537 (dolist (row (org-element-contents (org-export-get-parent row)))
4538 (cond
4539 ;; In a special row, try to find an alignment cookie at
4540 ;; COLUMN.
4541 ((org-export-table-row-is-special-p row info)
4542 (let ((value (org-element-contents
4543 (elt (org-element-contents row) column))))
4544 ;; Since VALUE is a secondary string, the following
4545 ;; checks avoid useless expansion through
4546 ;; `org-export-data'.
4547 (when (and value
4548 (not (cdr value))
4549 (stringp (car value))
4550 (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
4551 (car value))
4552 (match-string 1 (car value)))
4553 (setq cookie-align (match-string 1 (car value))))))
4554 ;; Ignore table rules.
4555 ((eq (org-element-property :type row) 'rule))
4556 ;; In a standard row, check if cell's contents are
4557 ;; expressing some kind of number. Increase NUMBER-CELLS
4558 ;; accordingly. Though, don't bother if an alignment
4559 ;; cookie has already defined cell's alignment.
4560 ((not cookie-align)
4561 (let ((value (org-export-data
4562 (org-element-contents
4563 (elt (org-element-contents row) column))
4564 info)))
4565 (incf total-cells)
4566 ;; Treat an empty cell as a number if it follows
4567 ;; a number.
4568 (if (not (or (string-match org-table-number-regexp value)
4569 (and (string= value "") previous-cell-number-p)))
4570 (setq previous-cell-number-p nil)
4571 (setq previous-cell-number-p t)
4572 (incf number-cells))))))
4573 ;; Return value. Alignment specified by cookies has
4574 ;; precedence over alignment deduced from cell's contents.
4575 (aset align-vector
4576 column
4577 (cond ((equal cookie-align "l") 'left)
4578 ((equal cookie-align "r") 'right)
4579 ((equal cookie-align "c") 'center)
4580 ((>= (/ (float number-cells) total-cells)
4581 org-table-number-fraction)
4582 'right)
4583 (t 'left)))))))
4585 (defun org-export-table-cell-borders (table-cell info)
4586 "Return TABLE-CELL borders.
4588 INFO is a plist used as a communication channel.
4590 Return value is a list of symbols, or nil. Possible values are:
4591 `top', `bottom', `above', `below', `left' and `right'. Note:
4592 `top' (resp. `bottom') only happen for a cell in the first
4593 row (resp. last row) of the table, ignoring table rules, if any.
4595 Returned borders ignore special rows."
4596 (let* ((row (org-export-get-parent table-cell))
4597 (table (org-export-get-parent-table table-cell))
4598 borders)
4599 ;; Top/above border? TABLE-CELL has a border above when a rule
4600 ;; used to demarcate row groups can be found above. Hence,
4601 ;; finding a rule isn't sufficient to push `above' in BORDERS:
4602 ;; another regular row has to be found above that rule.
4603 (let (rule-flag)
4604 (catch 'exit
4605 (mapc (lambda (row)
4606 (cond ((eq (org-element-property :type row) 'rule)
4607 (setq rule-flag t))
4608 ((not (org-export-table-row-is-special-p row info))
4609 (if rule-flag (throw 'exit (push 'above borders))
4610 (throw 'exit nil)))))
4611 ;; Look at every row before the current one.
4612 (cdr (memq row (reverse (org-element-contents table)))))
4613 ;; No rule above, or rule found starts the table (ignoring any
4614 ;; special row): TABLE-CELL is at the top of the table.
4615 (when rule-flag (push 'above borders))
4616 (push 'top borders)))
4617 ;; Bottom/below border? TABLE-CELL has a border below when next
4618 ;; non-regular row below is a rule.
4619 (let (rule-flag)
4620 (catch 'exit
4621 (mapc (lambda (row)
4622 (cond ((eq (org-element-property :type row) 'rule)
4623 (setq rule-flag t))
4624 ((not (org-export-table-row-is-special-p row info))
4625 (if rule-flag (throw 'exit (push 'below borders))
4626 (throw 'exit nil)))))
4627 ;; Look at every row after the current one.
4628 (cdr (memq row (org-element-contents table))))
4629 ;; No rule below, or rule found ends the table (modulo some
4630 ;; special row): TABLE-CELL is at the bottom of the table.
4631 (when rule-flag (push 'below borders))
4632 (push 'bottom borders)))
4633 ;; Right/left borders? They can only be specified by column
4634 ;; groups. Column groups are defined in a row starting with "/".
4635 ;; Also a column groups row only contains "<", "<>", ">" or blank
4636 ;; cells.
4637 (catch 'exit
4638 (let ((column (let ((cells (org-element-contents row)))
4639 (- (length cells) (length (memq table-cell cells))))))
4640 (mapc
4641 (lambda (row)
4642 (unless (eq (org-element-property :type row) 'rule)
4643 (when (equal (org-element-contents
4644 (car (org-element-contents row)))
4645 '("/"))
4646 (let ((column-groups
4647 (mapcar
4648 (lambda (cell)
4649 (let ((value (org-element-contents cell)))
4650 (when (member value '(("<") ("<>") (">") nil))
4651 (car value))))
4652 (org-element-contents row))))
4653 ;; There's a left border when previous cell, if
4654 ;; any, ends a group, or current one starts one.
4655 (when (or (and (not (zerop column))
4656 (member (elt column-groups (1- column))
4657 '(">" "<>")))
4658 (member (elt column-groups column) '("<" "<>")))
4659 (push 'left borders))
4660 ;; There's a right border when next cell, if any,
4661 ;; starts a group, or current one ends one.
4662 (when (or (and (/= (1+ column) (length column-groups))
4663 (member (elt column-groups (1+ column))
4664 '("<" "<>")))
4665 (member (elt column-groups column) '(">" "<>")))
4666 (push 'right borders))
4667 (throw 'exit nil)))))
4668 ;; Table rows are read in reverse order so last column groups
4669 ;; row has precedence over any previous one.
4670 (reverse (org-element-contents table)))))
4671 ;; Return value.
4672 borders))
4674 (defun org-export-table-cell-starts-colgroup-p (table-cell info)
4675 "Non-nil when TABLE-CELL is at the beginning of a row group.
4676 INFO is a plist used as a communication channel."
4677 ;; A cell starts a column group either when it is at the beginning
4678 ;; of a row (or after the special column, if any) or when it has
4679 ;; a left border.
4680 (or (eq (org-element-map (org-export-get-parent table-cell) 'table-cell
4681 'identity info 'first-match)
4682 table-cell)
4683 (memq 'left (org-export-table-cell-borders table-cell info))))
4685 (defun org-export-table-cell-ends-colgroup-p (table-cell info)
4686 "Non-nil when TABLE-CELL is at the end of a row group.
4687 INFO is a plist used as a communication channel."
4688 ;; A cell ends a column group either when it is at the end of a row
4689 ;; or when it has a right border.
4690 (or (eq (car (last (org-element-contents
4691 (org-export-get-parent table-cell))))
4692 table-cell)
4693 (memq 'right (org-export-table-cell-borders table-cell info))))
4695 (defun org-export-table-row-starts-rowgroup-p (table-row info)
4696 "Non-nil when TABLE-ROW is at the beginning of a column group.
4697 INFO is a plist used as a communication channel."
4698 (unless (or (eq (org-element-property :type table-row) 'rule)
4699 (org-export-table-row-is-special-p table-row info))
4700 (let ((borders (org-export-table-cell-borders
4701 (car (org-element-contents table-row)) info)))
4702 (or (memq 'top borders) (memq 'above borders)))))
4704 (defun org-export-table-row-ends-rowgroup-p (table-row info)
4705 "Non-nil when TABLE-ROW is at the end of a column group.
4706 INFO is a plist used as a communication channel."
4707 (unless (or (eq (org-element-property :type table-row) 'rule)
4708 (org-export-table-row-is-special-p table-row info))
4709 (let ((borders (org-export-table-cell-borders
4710 (car (org-element-contents table-row)) info)))
4711 (or (memq 'bottom borders) (memq 'below borders)))))
4713 (defun org-export-table-row-starts-header-p (table-row info)
4714 "Non-nil when TABLE-ROW is the first table header's row.
4715 INFO is a plist used as a communication channel."
4716 (and (org-export-table-has-header-p
4717 (org-export-get-parent-table table-row) info)
4718 (org-export-table-row-starts-rowgroup-p table-row info)
4719 (= (org-export-table-row-group table-row info) 1)))
4721 (defun org-export-table-row-ends-header-p (table-row info)
4722 "Non-nil when TABLE-ROW is the last table header's row.
4723 INFO is a plist used as a communication channel."
4724 (and (org-export-table-has-header-p
4725 (org-export-get-parent-table table-row) info)
4726 (org-export-table-row-ends-rowgroup-p table-row info)
4727 (= (org-export-table-row-group table-row info) 1)))
4729 (defun org-export-table-row-number (table-row info)
4730 "Return TABLE-ROW number.
4731 INFO is a plist used as a communication channel. Return value is
4732 zero-based and ignores separators. The function returns nil for
4733 special colums and separators."
4734 (when (and (eq (org-element-property :type table-row) 'standard)
4735 (not (org-export-table-row-is-special-p table-row info)))
4736 (let ((number 0))
4737 (org-element-map (org-export-get-parent-table table-row) 'table-row
4738 (lambda (row)
4739 (cond ((eq row table-row) number)
4740 ((eq (org-element-property :type row) 'standard)
4741 (incf number) nil)))
4742 info 'first-match))))
4744 (defun org-export-table-dimensions (table info)
4745 "Return TABLE dimensions.
4747 INFO is a plist used as a communication channel.
4749 Return value is a CONS like (ROWS . COLUMNS) where
4750 ROWS (resp. COLUMNS) is the number of exportable
4751 rows (resp. columns)."
4752 (let (first-row (columns 0) (rows 0))
4753 ;; Set number of rows, and extract first one.
4754 (org-element-map table 'table-row
4755 (lambda (row)
4756 (when (eq (org-element-property :type row) 'standard)
4757 (incf rows)
4758 (unless first-row (setq first-row row)))) info)
4759 ;; Set number of columns.
4760 (org-element-map first-row 'table-cell (lambda (cell) (incf columns)) info)
4761 ;; Return value.
4762 (cons rows columns)))
4764 (defun org-export-table-cell-address (table-cell info)
4765 "Return address of a regular TABLE-CELL object.
4767 TABLE-CELL is the cell considered. INFO is a plist used as
4768 a communication channel.
4770 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4771 zero-based index. Only exportable cells are considered. The
4772 function returns nil for other cells."
4773 (let* ((table-row (org-export-get-parent table-cell))
4774 (row-number (org-export-table-row-number table-row info)))
4775 (when row-number
4776 (cons row-number
4777 (let ((col-count 0))
4778 (org-element-map table-row 'table-cell
4779 (lambda (cell)
4780 (if (eq cell table-cell) col-count (incf col-count) nil))
4781 info 'first-match))))))
4783 (defun org-export-get-table-cell-at (address table info)
4784 "Return regular table-cell object at ADDRESS in TABLE.
4786 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4787 zero-based index. TABLE is a table type element. INFO is
4788 a plist used as a communication channel.
4790 If no table-cell, among exportable cells, is found at ADDRESS,
4791 return nil."
4792 (let ((column-pos (cdr address)) (column-count 0))
4793 (org-element-map
4794 ;; Row at (car address) or nil.
4795 (let ((row-pos (car address)) (row-count 0))
4796 (org-element-map table 'table-row
4797 (lambda (row)
4798 (cond ((eq (org-element-property :type row) 'rule) nil)
4799 ((= row-count row-pos) row)
4800 (t (incf row-count) nil)))
4801 info 'first-match))
4802 'table-cell
4803 (lambda (cell)
4804 (if (= column-count column-pos) cell
4805 (incf column-count) nil))
4806 info 'first-match)))
4809 ;;;; For Tables Of Contents
4811 ;; `org-export-collect-headlines' builds a list of all exportable
4812 ;; headline elements, maybe limited to a certain depth. One can then
4813 ;; easily parse it and transcode it.
4815 ;; Building lists of tables, figures or listings is quite similar.
4816 ;; Once the generic function `org-export-collect-elements' is defined,
4817 ;; `org-export-collect-tables', `org-export-collect-figures' and
4818 ;; `org-export-collect-listings' can be derived from it.
4820 (defun org-export-collect-headlines (info &optional n)
4821 "Collect headlines in order to build a table of contents.
4823 INFO is a plist used as a communication channel.
4825 When optional argument N is an integer, it specifies the depth of
4826 the table of contents. Otherwise, it is set to the value of the
4827 last headline level. See `org-export-headline-levels' for more
4828 information.
4830 Return a list of all exportable headlines as parsed elements.
4831 Footnote sections, if any, will be ignored."
4832 (let ((limit (plist-get info :headline-levels)))
4833 (setq n (if (wholenump n) (min n limit) limit))
4834 (org-element-map (plist-get info :parse-tree) 'headline
4835 #'(lambda (headline)
4836 (unless (org-element-property :footnote-section-p headline)
4837 (let ((level (org-export-get-relative-level headline info)))
4838 (and (<= level n) headline))))
4839 info)))
4841 (defun org-export-collect-elements (type info &optional predicate)
4842 "Collect referenceable elements of a determined type.
4844 TYPE can be a symbol or a list of symbols specifying element
4845 types to search. Only elements with a caption are collected.
4847 INFO is a plist used as a communication channel.
4849 When non-nil, optional argument PREDICATE is a function accepting
4850 one argument, an element of type TYPE. It returns a non-nil
4851 value when that element should be collected.
4853 Return a list of all elements found, in order of appearance."
4854 (org-element-map (plist-get info :parse-tree) type
4855 (lambda (element)
4856 (and (org-element-property :caption element)
4857 (or (not predicate) (funcall predicate element))
4858 element))
4859 info))
4861 (defun org-export-collect-tables (info)
4862 "Build a list of tables.
4863 INFO is a plist used as a communication channel.
4865 Return a list of table elements with a caption."
4866 (org-export-collect-elements 'table info))
4868 (defun org-export-collect-figures (info predicate)
4869 "Build a list of figures.
4871 INFO is a plist used as a communication channel. PREDICATE is
4872 a function which accepts one argument: a paragraph element and
4873 whose return value is non-nil when that element should be
4874 collected.
4876 A figure is a paragraph type element, with a caption, verifying
4877 PREDICATE. The latter has to be provided since a \"figure\" is
4878 a vague concept that may depend on back-end.
4880 Return a list of elements recognized as figures."
4881 (org-export-collect-elements 'paragraph info predicate))
4883 (defun org-export-collect-listings (info)
4884 "Build a list of src blocks.
4886 INFO is a plist used as a communication channel.
4888 Return a list of src-block elements with a caption."
4889 (org-export-collect-elements 'src-block info))
4892 ;;;; Smart Quotes
4894 ;; The main function for the smart quotes sub-system is
4895 ;; `org-export-activate-smart-quotes', which replaces every quote in
4896 ;; a given string from the parse tree with its "smart" counterpart.
4898 ;; Dictionary for smart quotes is stored in
4899 ;; `org-export-smart-quotes-alist'.
4901 ;; Internally, regexps matching potential smart quotes (checks at
4902 ;; string boundaries are also necessary) are defined in
4903 ;; `org-export-smart-quotes-regexps'.
4905 (defconst org-export-smart-quotes-alist
4906 '(("de"
4907 (opening-double-quote :utf-8 "„" :html "&bdquo;" :latex "\"`"
4908 :texinfo "@quotedblbase{}")
4909 (closing-double-quote :utf-8 "“" :html "&ldquo;" :latex "\"'"
4910 :texinfo "@quotedblleft{}")
4911 (opening-single-quote :utf-8 "‚" :html "&sbquo;" :latex "\\glq{}"
4912 :texinfo "@quotesinglbase{}")
4913 (closing-single-quote :utf-8 "‘" :html "&lsquo;" :latex "\\grq{}"
4914 :texinfo "@quoteleft{}")
4915 (apostrophe :utf-8 "’" :html "&rsquo;"))
4916 ("en"
4917 (opening-double-quote :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
4918 (closing-double-quote :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
4919 (opening-single-quote :utf-8 "‘" :html "&lsquo;" :latex "`" :texinfo "`")
4920 (closing-single-quote :utf-8 "’" :html "&rsquo;" :latex "'" :texinfo "'")
4921 (apostrophe :utf-8 "’" :html "&rsquo;"))
4922 ("es"
4923 (opening-double-quote :utf-8 "«" :html "&laquo;" :latex "\\guillemotleft{}"
4924 :texinfo "@guillemetleft{}")
4925 (closing-double-quote :utf-8 "»" :html "&raquo;" :latex "\\guillemotright{}"
4926 :texinfo "@guillemetright{}")
4927 (opening-single-quote :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
4928 (closing-single-quote :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
4929 (apostrophe :utf-8 "’" :html "&rsquo;"))
4930 ("fr"
4931 (opening-double-quote :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
4932 :texinfo "@guillemetleft{}@tie{}")
4933 (closing-double-quote :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
4934 :texinfo "@tie{}@guillemetright{}")
4935 (opening-single-quote :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
4936 :texinfo "@guillemetleft{}@tie{}")
4937 (closing-single-quote :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
4938 :texinfo "@tie{}@guillemetright{}")
4939 (apostrophe :utf-8 "’" :html "&rsquo;")))
4940 "Smart quotes translations.
4942 Alist whose CAR is a language string and CDR is an alist with
4943 quote type as key and a plist associating various encodings to
4944 their translation as value.
4946 A quote type can be any symbol among `opening-double-quote',
4947 `closing-double-quote', `opening-single-quote',
4948 `closing-single-quote' and `apostrophe'.
4950 Valid encodings include `:utf-8', `:html', `:latex' and
4951 `:texinfo'.
4953 If no translation is found, the quote character is left as-is.")
4955 (defconst org-export-smart-quotes-regexps
4956 (list
4957 ;; Possible opening quote at beginning of string.
4958 "\\`\\([\"']\\)\\(\\w\\|\\s.\\|\\s_\\)"
4959 ;; Possible closing quote at beginning of string.
4960 "\\`\\([\"']\\)\\(\\s-\\|\\s)\\|\\s.\\)"
4961 ;; Possible apostrophe at beginning of string.
4962 "\\`\\('\\)\\S-"
4963 ;; Opening single and double quotes.
4964 "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\(?:\\w\\|\\s.\\|\\s_\\)"
4965 ;; Closing single and double quotes.
4966 "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\(?:\\s-\\|\\s)\\|\\s.\\)"
4967 ;; Apostrophe.
4968 "\\S-\\('\\)\\S-"
4969 ;; Possible opening quote at end of string.
4970 "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\'"
4971 ;; Possible closing quote at end of string.
4972 "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\'"
4973 ;; Possible apostrophe at end of string.
4974 "\\S-\\('\\)\\'")
4975 "List of regexps matching a quote or an apostrophe.
4976 In every regexp, quote or apostrophe matched is put in group 1.")
4978 (defun org-export-activate-smart-quotes (s encoding info &optional original)
4979 "Replace regular quotes with \"smart\" quotes in string S.
4981 ENCODING is a symbol among `:html', `:latex', `:texinfo' and
4982 `:utf-8'. INFO is a plist used as a communication channel.
4984 The function has to retrieve information about string
4985 surroundings in parse tree. It can only happen with an
4986 unmodified string. Thus, if S has already been through another
4987 process, a non-nil ORIGINAL optional argument will provide that
4988 original string.
4990 Return the new string."
4991 (if (equal s "") ""
4992 (let* ((prev (org-export-get-previous-element (or original s) info))
4993 ;; Try to be flexible when computing number of blanks
4994 ;; before object. The previous object may be a string
4995 ;; introduced by the back-end and not completely parsed.
4996 (pre-blank (and prev
4997 (or (org-element-property :post-blank prev)
4998 ;; A string with missing `:post-blank'
4999 ;; property.
5000 (and (stringp prev)
5001 (string-match " *\\'" prev)
5002 (length (match-string 0 prev)))
5003 ;; Fallback value.
5004 0)))
5005 (next (org-export-get-next-element (or original s) info))
5006 (get-smart-quote
5007 (lambda (q type)
5008 ;; Return smart quote associated to a give quote Q, as
5009 ;; a string. TYPE is a symbol among `open', `close' and
5010 ;; `apostrophe'.
5011 (let ((key (case type
5012 (apostrophe 'apostrophe)
5013 (open (if (equal "'" q) 'opening-single-quote
5014 'opening-double-quote))
5015 (otherwise (if (equal "'" q) 'closing-single-quote
5016 'closing-double-quote)))))
5017 (or (plist-get
5018 (cdr (assq key
5019 (cdr (assoc (plist-get info :language)
5020 org-export-smart-quotes-alist))))
5021 encoding)
5022 q)))))
5023 (if (or (equal "\"" s) (equal "'" s))
5024 ;; Only a quote: no regexp can match. We have to check both
5025 ;; sides and decide what to do.
5026 (cond ((and (not prev) (not next)) s)
5027 ((not prev) (funcall get-smart-quote s 'open))
5028 ((and (not next) (zerop pre-blank))
5029 (funcall get-smart-quote s 'close))
5030 ((not next) s)
5031 ((zerop pre-blank) (funcall get-smart-quote s 'apostrophe))
5032 (t (funcall get-smart-quote 'open)))
5033 ;; 1. Replace quote character at the beginning of S.
5034 (cond
5035 ;; Apostrophe?
5036 ((and prev (zerop pre-blank)
5037 (string-match (nth 2 org-export-smart-quotes-regexps) s))
5038 (setq s (replace-match
5039 (funcall get-smart-quote (match-string 1 s) 'apostrophe)
5040 nil t s 1)))
5041 ;; Closing quote?
5042 ((and prev (zerop pre-blank)
5043 (string-match (nth 1 org-export-smart-quotes-regexps) s))
5044 (setq s (replace-match
5045 (funcall get-smart-quote (match-string 1 s) 'close)
5046 nil t s 1)))
5047 ;; Opening quote?
5048 ((and (or (not prev) (> pre-blank 0))
5049 (string-match (nth 0 org-export-smart-quotes-regexps) s))
5050 (setq s (replace-match
5051 (funcall get-smart-quote (match-string 1 s) 'open)
5052 nil t s 1))))
5053 ;; 2. Replace quotes in the middle of the string.
5054 (setq s (replace-regexp-in-string
5055 ;; Opening quotes.
5056 (nth 3 org-export-smart-quotes-regexps)
5057 (lambda (text)
5058 (funcall get-smart-quote (match-string 1 text) 'open))
5059 s nil t 1))
5060 (setq s (replace-regexp-in-string
5061 ;; Closing quotes.
5062 (nth 4 org-export-smart-quotes-regexps)
5063 (lambda (text)
5064 (funcall get-smart-quote (match-string 1 text) 'close))
5065 s nil t 1))
5066 (setq s (replace-regexp-in-string
5067 ;; Apostrophes.
5068 (nth 5 org-export-smart-quotes-regexps)
5069 (lambda (text)
5070 (funcall get-smart-quote (match-string 1 text) 'apostrophe))
5071 s nil t 1))
5072 ;; 3. Replace quote character at the end of S.
5073 (cond
5074 ;; Apostrophe?
5075 ((and next (string-match (nth 8 org-export-smart-quotes-regexps) s))
5076 (setq s (replace-match
5077 (funcall get-smart-quote (match-string 1 s) 'apostrophe)
5078 nil t s 1)))
5079 ;; Closing quote?
5080 ((and (not next)
5081 (string-match (nth 7 org-export-smart-quotes-regexps) s))
5082 (setq s (replace-match
5083 (funcall get-smart-quote (match-string 1 s) 'close)
5084 nil t s 1)))
5085 ;; Opening quote?
5086 ((and next (string-match (nth 6 org-export-smart-quotes-regexps) s))
5087 (setq s (replace-match
5088 (funcall get-smart-quote (match-string 1 s) 'open)
5089 nil t s 1))))
5090 ;; Return string with smart quotes.
5091 s))))
5093 ;;;; Topology
5095 ;; Here are various functions to retrieve information about the
5096 ;; neighbourhood of a given element or object. Neighbours of interest
5097 ;; are direct parent (`org-export-get-parent'), parent headline
5098 ;; (`org-export-get-parent-headline'), first element containing an
5099 ;; object, (`org-export-get-parent-element'), parent table
5100 ;; (`org-export-get-parent-table'), previous element or object
5101 ;; (`org-export-get-previous-element') and next element or object
5102 ;; (`org-export-get-next-element').
5104 ;; `org-export-get-genealogy' returns the full genealogy of a given
5105 ;; element or object, from closest parent to full parse tree.
5107 (defsubst org-export-get-parent (blob)
5108 "Return BLOB parent or nil.
5109 BLOB is the element or object considered."
5110 (org-element-property :parent blob))
5112 (defun org-export-get-genealogy (blob)
5113 "Return full genealogy relative to a given element or object.
5115 BLOB is the element or object being considered.
5117 Ancestors are returned from closest to farthest, the last one
5118 being the full parse tree."
5119 (let (genealogy (parent blob))
5120 (while (setq parent (org-element-property :parent parent))
5121 (push parent genealogy))
5122 (nreverse genealogy)))
5124 (defun org-export-get-parent-headline (blob)
5125 "Return BLOB parent headline or nil.
5126 BLOB is the element or object being considered."
5127 (let ((parent blob))
5128 (while (and (setq parent (org-element-property :parent parent))
5129 (not (eq (org-element-type parent) 'headline))))
5130 parent))
5132 (defun org-export-get-parent-element (object)
5133 "Return first element containing OBJECT or nil.
5134 OBJECT is the object to consider."
5135 (let ((parent object))
5136 (while (and (setq parent (org-element-property :parent parent))
5137 (memq (org-element-type parent) org-element-all-objects)))
5138 parent))
5140 (defun org-export-get-parent-table (object)
5141 "Return OBJECT parent table or nil.
5142 OBJECT is either a `table-cell' or `table-element' type object."
5143 (let ((parent object))
5144 (while (and (setq parent (org-element-property :parent parent))
5145 (not (eq (org-element-type parent) 'table))))
5146 parent))
5148 (defun org-export-get-previous-element (blob info &optional n)
5149 "Return previous element or object.
5151 BLOB is an element or object. INFO is a plist used as
5152 a communication channel. Return previous exportable element or
5153 object, a string, or nil.
5155 When optional argument N is a positive integer, return a list
5156 containing up to N siblings before BLOB, from farthest to
5157 closest. With any other non-nil value, return a list containing
5158 all of them."
5159 (let ((siblings
5160 ;; An object can belong to the contents of its parent or
5161 ;; to a secondary string. We check the latter option
5162 ;; first.
5163 (let ((parent (org-export-get-parent blob)))
5164 (or (and (not (memq (org-element-type blob)
5165 org-element-all-elements))
5166 (let ((sec-value
5167 (org-element-property
5168 (cdr (assq (org-element-type parent)
5169 org-element-secondary-value-alist))
5170 parent)))
5171 (and (memq blob sec-value) sec-value)))
5172 (org-element-contents parent))))
5173 prev)
5174 (catch 'exit
5175 (mapc (lambda (obj)
5176 (cond ((memq obj (plist-get info :ignore-list)))
5177 ((null n) (throw 'exit obj))
5178 ((not (wholenump n)) (push obj prev))
5179 ((zerop n) (throw 'exit prev))
5180 (t (decf n) (push obj prev))))
5181 (cdr (memq blob (reverse siblings))))
5182 prev)))
5184 (defun org-export-get-next-element (blob info &optional n)
5185 "Return next element or object.
5187 BLOB is an element or object. INFO is a plist used as
5188 a communication channel. Return next exportable element or
5189 object, a string, or nil.
5191 When optional argument N is a positive integer, return a list
5192 containing up to N siblings after BLOB, from closest to farthest.
5193 With any other non-nil value, return a list containing all of
5194 them."
5195 (let ((siblings
5196 ;; An object can belong to the contents of its parent or to
5197 ;; a secondary string. We check the latter option first.
5198 (let ((parent (org-export-get-parent blob)))
5199 (or (and (not (memq (org-element-type blob)
5200 org-element-all-objects))
5201 (let ((sec-value
5202 (org-element-property
5203 (cdr (assq (org-element-type parent)
5204 org-element-secondary-value-alist))
5205 parent)))
5206 (cdr (memq blob sec-value))))
5207 (cdr (memq blob (org-element-contents parent))))))
5208 next)
5209 (catch 'exit
5210 (mapc (lambda (obj)
5211 (cond ((memq obj (plist-get info :ignore-list)))
5212 ((null n) (throw 'exit obj))
5213 ((not (wholenump n)) (push obj next))
5214 ((zerop n) (throw 'exit (nreverse next)))
5215 (t (decf n) (push obj next))))
5216 siblings)
5217 (nreverse next))))
5220 ;;;; Translation
5222 ;; `org-export-translate' translates a string according to the language
5223 ;; specified by the LANGUAGE keyword. `org-export-dictionary' contains
5224 ;; the dictionary used for the translation.
5226 (defconst org-export-dictionary
5227 '(("Author"
5228 ("ca" :default "Autor")
5229 ("cs" :default "Autor")
5230 ("da" :default "Ophavsmand")
5231 ("de" :default "Autor")
5232 ("eo" :html "A&#365;toro")
5233 ("es" :default "Autor")
5234 ("fi" :html "Tekij&auml;")
5235 ("fr" :default "Auteur")
5236 ("hu" :default "Szerz&otilde;")
5237 ("is" :html "H&ouml;fundur")
5238 ("it" :default "Autore")
5239 ("ja" :html "&#33879;&#32773;" :utf-8 "著者")
5240 ("nl" :default "Auteur")
5241 ("no" :default "Forfatter")
5242 ("nb" :default "Forfatter")
5243 ("nn" :default "Forfattar")
5244 ("pl" :default "Autor")
5245 ("ru" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
5246 ("sv" :html "F&ouml;rfattare")
5247 ("uk" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
5248 ("zh-CN" :html "&#20316;&#32773;" :utf-8 "作者")
5249 ("zh-TW" :html "&#20316;&#32773;" :utf-8 "作者"))
5250 ("Date"
5251 ("ca" :default "Data")
5252 ("cs" :default "Datum")
5253 ("da" :default "Dato")
5254 ("de" :default "Datum")
5255 ("eo" :default "Dato")
5256 ("es" :default "Fecha")
5257 ("fi" :html "P&auml;iv&auml;m&auml;&auml;r&auml;")
5258 ("hu" :html "D&aacute;tum")
5259 ("is" :default "Dagsetning")
5260 ("it" :default "Data")
5261 ("ja" :html "&#26085;&#20184;" :utf-8 "日付")
5262 ("nl" :default "Datum")
5263 ("no" :default "Dato")
5264 ("nb" :default "Dato")
5265 ("nn" :default "Dato")
5266 ("pl" :default "Data")
5267 ("ru" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
5268 ("sv" :default "Datum")
5269 ("uk" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
5270 ("zh-CN" :html "&#26085;&#26399;" :utf-8 "日期")
5271 ("zh-TW" :html "&#26085;&#26399;" :utf-8 "日期"))
5272 ("Equation"
5273 ("de" :default "Gleichung")
5274 ("es" :html "Ecuaci&oacute;n" :default "Ecuación")
5275 ("fr" :ascii "Equation" :default "Équation"))
5276 ("Figure"
5277 ("de" :default "Abbildung")
5278 ("es" :default "Figura"))
5279 ("Footnotes"
5280 ("ca" :html "Peus de p&agrave;gina")
5281 ("cs" :default "Pozn\xe1mky pod carou")
5282 ("da" :default "Fodnoter")
5283 ("de" :html "Fu&szlig;noten" :default "Fußnoten")
5284 ("eo" :default "Piednotoj")
5285 ("es" :html "Nota al pie de p&aacute;gina" :default "Nota al pie de página")
5286 ("fi" :default "Alaviitteet")
5287 ("fr" :default "Notes de bas de page")
5288 ("hu" :html "L&aacute;bjegyzet")
5289 ("is" :html "Aftanm&aacute;lsgreinar")
5290 ("it" :html "Note a pi&egrave; di pagina")
5291 ("ja" :html "&#33050;&#27880;" :utf-8 "脚注")
5292 ("nl" :default "Voetnoten")
5293 ("no" :default "Fotnoter")
5294 ("nb" :default "Fotnoter")
5295 ("nn" :default "Fotnotar")
5296 ("pl" :default "Przypis")
5297 ("ru" :html "&#1057;&#1085;&#1086;&#1089;&#1082;&#1080;" :utf-8 "Сноски")
5298 ("sv" :default "Fotnoter")
5299 ("uk" :html "&#1055;&#1088;&#1080;&#1084;&#1110;&#1090;&#1082;&#1080;"
5300 :utf-8 "Примітки")
5301 ("zh-CN" :html "&#33050;&#27880;" :utf-8 "脚注")
5302 ("zh-TW" :html "&#33139;&#35387;" :utf-8 "腳註"))
5303 ("List of Listings"
5304 ("de" :default "Programmauflistungsverzeichnis")
5305 ("es" :default "Indice de Listados de programas")
5306 ("fr" :default "Liste des programmes"))
5307 ("List of Tables"
5308 ("de" :default "Tabellenverzeichnis")
5309 ("es" :default "Indice de tablas")
5310 ("fr" :default "Liste des tableaux"))
5311 ("Listing %d:"
5312 ("de" :default "Programmlisting %d")
5313 ("es" :default "Listado de programa %d")
5314 ("fr"
5315 :ascii "Programme %d :" :default "Programme nº %d :"
5316 :latin1 "Programme %d :"))
5317 ("See section %s"
5318 ("de" :default "siehe Abschnitt %s")
5319 ("es" :default "vea seccion %s")
5320 ("fr" :default "cf. section %s"))
5321 ("Table %d:"
5322 ("de" :default "Tabelle %d")
5323 ("es" :default "Tabla %d")
5324 ("fr"
5325 :ascii "Tableau %d :" :default "Tableau nº %d :" :latin1 "Tableau %d :"))
5326 ("Table of Contents"
5327 ("ca" :html "&Iacute;ndex")
5328 ("cs" :default "Obsah")
5329 ("da" :default "Indhold")
5330 ("de" :default "Inhaltsverzeichnis")
5331 ("eo" :default "Enhavo")
5332 ("es" :html "&Iacute;ndice")
5333 ("fi" :html "Sis&auml;llysluettelo")
5334 ("fr" :ascii "Sommaire" :default "Table des matières")
5335 ("hu" :html "Tartalomjegyz&eacute;k")
5336 ("is" :default "Efnisyfirlit")
5337 ("it" :default "Indice")
5338 ("ja" :html "&#30446;&#27425;" :utf-8 "目次")
5339 ("nl" :default "Inhoudsopgave")
5340 ("no" :default "Innhold")
5341 ("nb" :default "Innhold")
5342 ("nn" :default "Innhald")
5343 ("pl" :html "Spis tre&#x015b;ci")
5344 ("ru" :html "&#1057;&#1086;&#1076;&#1077;&#1088;&#1078;&#1072;&#1085;&#1080;&#1077;"
5345 :utf-8 "Содержание")
5346 ("sv" :html "Inneh&aring;ll")
5347 ("uk" :html "&#1047;&#1084;&#1110;&#1089;&#1090;" :utf-8 "Зміст")
5348 ("zh-CN" :html "&#30446;&#24405;" :utf-8 "目录")
5349 ("zh-TW" :html "&#30446;&#37636;" :utf-8 "目錄"))
5350 ("Unknown reference"
5351 ("de" :default "Unbekannter Verweis")
5352 ("es" :default "referencia desconocida")
5353 ("fr" :ascii "Destination inconnue" :default "Référence inconnue")))
5354 "Dictionary for export engine.
5356 Alist whose CAR is the string to translate and CDR is an alist
5357 whose CAR is the language string and CDR is a plist whose
5358 properties are possible charsets and values translated terms.
5360 It is used as a database for `org-export-translate'. Since this
5361 function returns the string as-is if no translation was found,
5362 the variable only needs to record values different from the
5363 entry.")
5365 (defun org-export-translate (s encoding info)
5366 "Translate string S according to language specification.
5368 ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
5369 and `:utf-8'. INFO is a plist used as a communication channel.
5371 Translation depends on `:language' property. Return the
5372 translated string. If no translation is found, try to fall back
5373 to `:default' encoding. If it fails, return S."
5374 (let* ((lang (plist-get info :language))
5375 (translations (cdr (assoc lang
5376 (cdr (assoc s org-export-dictionary))))))
5377 (or (plist-get translations encoding)
5378 (plist-get translations :default)
5379 s)))
5383 ;;; Asynchronous Export
5385 ;; `org-export-async-start' is the entry point for asynchronous
5386 ;; export. It recreates current buffer (including visibility,
5387 ;; narrowing and visited file) in an external Emacs process, and
5388 ;; evaluates a command there. It then applies a function on the
5389 ;; returned results in the current process.
5391 ;; Asynchronously generated results are never displayed directly.
5392 ;; Instead, they are stored in `org-export-stack-contents'. They can
5393 ;; then be retrieved by calling `org-export-stack'.
5395 ;; Export Stack is viewed through a dedicated major mode
5396 ;;`org-export-stack-mode' and tools: `org-export-stack-refresh',
5397 ;;`org-export-stack-delete', `org-export-stack-view' and
5398 ;;`org-export-stack-clear'.
5400 ;; For back-ends, `org-export-add-to-stack' add a new source to stack.
5401 ;; It should used whenever `org-export-async-start' is called.
5403 (defmacro org-export-async-start (fun &rest body)
5404 "Call function FUN on the results returned by BODY evaluation.
5406 BODY evaluation happens in an asynchronous process, from a buffer
5407 which is an exact copy of the current one.
5409 Use `org-export-add-to-stack' in FUN in order to register results
5410 in the stack. Examples for, respectively a temporary buffer and
5411 a file are:
5413 \(org-export-async-start
5414 \(lambda (output)
5415 \(with-current-buffer (get-buffer-create \"*Org BACKEND Export*\")
5416 \(erase-buffer)
5417 \(insert output)
5418 \(goto-char (point-min))
5419 \(org-export-add-to-stack (current-buffer) 'backend)))
5420 `(org-export-as 'backend ,subtreep ,visible-only ,body-only ',ext-plist))
5424 \(org-export-async-start
5425 \(lambda (f) (org-export-add-to-stack f 'backend))
5426 `(expand-file-name
5427 \(org-export-to-file
5428 'backend ,outfile ,subtreep ,visible-only ,body-only ',ext-plist)))"
5429 (declare (indent 1) (debug t))
5430 (org-with-gensyms (process temp-file copy-fun proc-buffer handler coding)
5431 ;; Write the full sexp evaluating BODY in a copy of the current
5432 ;; buffer to a temporary file, as it may be too long for program
5433 ;; args in `start-process'.
5434 `(with-temp-message "Initializing asynchronous export process"
5435 (let ((,copy-fun (org-export--generate-copy-script (current-buffer)))
5436 (,temp-file (make-temp-file "org-export-process"))
5437 (,coding buffer-file-coding-system))
5438 (with-temp-file ,temp-file
5439 (insert
5440 ;; Null characters (from variable values) are inserted
5441 ;; within the file. As a consequence, coding system for
5442 ;; buffer contents will not be recognized properly. So,
5443 ;; we make sure it is the same as the one used to display
5444 ;; the original buffer.
5445 (format ";; -*- coding: %s; -*-\n%S"
5446 ,coding
5447 `(with-temp-buffer
5448 ,(when org-export-async-debug '(setq debug-on-error t))
5449 ;; Ignore `kill-emacs-hook' and code evaluation
5450 ;; queries from Babel as we need a truly
5451 ;; non-interactive process.
5452 (setq kill-emacs-hook nil
5453 org-babel-confirm-evaluate-answer-no t)
5454 ;; Initialize export framework.
5455 (require 'ox)
5456 ;; Re-create current buffer there.
5457 (funcall ,,copy-fun)
5458 (restore-buffer-modified-p nil)
5459 ;; Sexp to evaluate in the buffer.
5460 (print (progn ,,@body))))))
5461 ;; Start external process.
5462 (let* ((process-connection-type nil)
5463 (,proc-buffer (generate-new-buffer-name "*Org Export Process*"))
5464 (,process
5465 (start-process
5466 "org-export-process" ,proc-buffer
5467 (expand-file-name invocation-name invocation-directory)
5468 "-Q" "--batch"
5469 "-l" org-export-async-init-file
5470 "-l" ,temp-file)))
5471 ;; Register running process in stack.
5472 (org-export-add-to-stack (get-buffer ,proc-buffer) nil ,process)
5473 ;; Set-up sentinel in order to catch results.
5474 (set-process-sentinel
5475 ,process
5476 (let ((handler ',fun))
5477 `(lambda (p status)
5478 (let ((proc-buffer (process-buffer p)))
5479 (when (eq (process-status p) 'exit)
5480 (unwind-protect
5481 (if (zerop (process-exit-status p))
5482 (unwind-protect
5483 (let ((results
5484 (with-current-buffer proc-buffer
5485 (goto-char (point-max))
5486 (backward-sexp)
5487 (read (current-buffer)))))
5488 (funcall ,handler results))
5489 (unless org-export-async-debug
5490 (and (get-buffer proc-buffer)
5491 (kill-buffer proc-buffer))))
5492 (org-export-add-to-stack proc-buffer nil p)
5493 (ding)
5494 (message "Process '%s' exited abnormally" p))
5495 (unless org-export-async-debug
5496 (delete-file ,,temp-file)))))))))))))
5498 (defun org-export-add-to-stack (source backend &optional process)
5499 "Add a new result to export stack if not present already.
5501 SOURCE is a buffer or a file name containing export results.
5502 BACKEND is a symbol representing export back-end used to generate
5505 Entries already pointing to SOURCE and unavailable entries are
5506 removed beforehand. Return the new stack."
5507 (setq org-export-stack-contents
5508 (cons (list source backend (or process (current-time)))
5509 (org-export-stack-remove source))))
5511 (defun org-export-stack ()
5512 "Menu for asynchronous export results and running processes."
5513 (interactive)
5514 (let ((buffer (get-buffer-create "*Org Export Stack*")))
5515 (set-buffer buffer)
5516 (when (zerop (buffer-size)) (org-export-stack-mode))
5517 (org-export-stack-refresh)
5518 (pop-to-buffer buffer))
5519 (message "Type \"q\" to quit, \"?\" for help"))
5521 (defun org-export--stack-source-at-point ()
5522 "Return source from export results at point in stack."
5523 (let ((source (car (nth (1- (org-current-line)) org-export-stack-contents))))
5524 (if (not source) (error "Source unavailable, please refresh buffer")
5525 (let ((source-name (if (stringp source) source (buffer-name source))))
5526 (if (save-excursion
5527 (beginning-of-line)
5528 (looking-at (concat ".* +" (regexp-quote source-name) "$")))
5529 source
5530 ;; SOURCE is not consistent with current line. The stack
5531 ;; view is outdated.
5532 (error "Source unavailable; type `g' to update buffer"))))))
5534 (defun org-export-stack-clear ()
5535 "Remove all entries from export stack."
5536 (interactive)
5537 (setq org-export-stack-contents nil))
5539 (defun org-export-stack-refresh (&rest dummy)
5540 "Refresh the asynchronous export stack.
5541 DUMMY is ignored. Unavailable sources are removed from the list.
5542 Return the new stack."
5543 (let ((inhibit-read-only t))
5544 (org-preserve-lc
5545 (erase-buffer)
5546 (insert (concat
5547 (let ((counter 0))
5548 (mapconcat
5549 (lambda (entry)
5550 (let ((proc-p (processp (nth 2 entry))))
5551 (concat
5552 ;; Back-end.
5553 (format " %-12s " (or (nth 1 entry) ""))
5554 ;; Age.
5555 (let ((data (nth 2 entry)))
5556 (if proc-p (format " %6s " (process-status data))
5557 ;; Compute age of the results.
5558 (org-format-seconds
5559 "%4h:%.2m "
5560 (float-time (time-since data)))))
5561 ;; Source.
5562 (format " %s"
5563 (let ((source (car entry)))
5564 (if (stringp source) source
5565 (buffer-name source)))))))
5566 ;; Clear stack from exited processes, dead buffers or
5567 ;; non-existent files.
5568 (setq org-export-stack-contents
5569 (org-remove-if-not
5570 (lambda (el)
5571 (if (processp (nth 2 el))
5572 (buffer-live-p (process-buffer (nth 2 el)))
5573 (let ((source (car el)))
5574 (if (bufferp source) (buffer-live-p source)
5575 (file-exists-p source)))))
5576 org-export-stack-contents)) "\n")))))))
5578 (defun org-export-stack-remove (&optional source)
5579 "Remove export results at point from stack.
5580 If optional argument SOURCE is non-nil, remove it instead."
5581 (interactive)
5582 (let ((source (or source (org-export--stack-source-at-point))))
5583 (setq org-export-stack-contents
5584 (org-remove-if (lambda (el) (equal (car el) source))
5585 org-export-stack-contents))))
5587 (defun org-export-stack-view (&optional in-emacs)
5588 "View export results at point in stack.
5589 With an optional prefix argument IN-EMACS, force viewing files
5590 within Emacs."
5591 (interactive "P")
5592 (let ((source (org-export--stack-source-at-point)))
5593 (cond ((processp source)
5594 (org-switch-to-buffer-other-window (process-buffer source)))
5595 ((bufferp source) (org-switch-to-buffer-other-window source))
5596 (t (org-open-file source in-emacs)))))
5598 (defvar org-export-stack-mode-map
5599 (let ((km (make-sparse-keymap)))
5600 (define-key km " " 'next-line)
5601 (define-key km "n" 'next-line)
5602 (define-key km "\C-n" 'next-line)
5603 (define-key km [down] 'next-line)
5604 (define-key km "p" 'previous-line)
5605 (define-key km "\C-p" 'previous-line)
5606 (define-key km "\C-?" 'previous-line)
5607 (define-key km [up] 'previous-line)
5608 (define-key km "C" 'org-export-stack-clear)
5609 (define-key km "v" 'org-export-stack-view)
5610 (define-key km (kbd "RET") 'org-export-stack-view)
5611 (define-key km "d" 'org-export-stack-remove)
5613 "Keymap for Org Export Stack.")
5615 (define-derived-mode org-export-stack-mode special-mode "Org-Stack"
5616 "Mode for displaying asynchronous export stack.
5618 Type \\[org-export-stack] to visualize the asynchronous export
5619 stack.
5621 In an Org Export Stack buffer, use \\<org-export-stack-mode-map>\\[org-export-stack-view] to view export output
5622 on current line, \\[org-export-stack-remove] to remove it from the stack and \\[org-export-stack-clear] to clear
5623 stack completely.
5625 Removing entries in an Org Export Stack buffer doesn't affect
5626 files or buffers, only the display.
5628 \\{org-export-stack-mode-map}"
5629 (abbrev-mode 0)
5630 (auto-fill-mode 0)
5631 (setq buffer-read-only t
5632 buffer-undo-list t
5633 truncate-lines t
5634 header-line-format
5635 '(:eval
5636 (format " %-12s | %6s | %s" "Back-End" "Age" "Source")))
5637 (org-add-hook 'post-command-hook 'org-export-stack-refresh nil t)
5638 (set (make-local-variable 'revert-buffer-function)
5639 'org-export-stack-refresh))
5643 ;;; The Dispatcher
5645 ;; `org-export-dispatch' is the standard interactive way to start an
5646 ;; export process. It uses `org-export--dispatch-ui' as a subroutine
5647 ;; for its interface, which, in turn, delegates response to key
5648 ;; pressed to `org-export--dispatch-action'.
5650 ;;;###autoload
5651 (defun org-export-dispatch (&optional arg)
5652 "Export dispatcher for Org mode.
5654 It provides an access to common export related tasks in a buffer.
5655 Its interface comes in two flavours: standard and expert.
5657 While both share the same set of bindings, only the former
5658 displays the valid keys associations in a dedicated buffer.
5659 Scrolling (resp. line-wise motion) in this buffer is done with
5660 SPC and DEL (resp. C-n and C-p) keys.
5662 Set variable `org-export-dispatch-use-expert-ui' to switch to one
5663 flavour or the other.
5665 When ARG is \\[universal-argument], repeat the last export action, with the same set
5666 of options used back then, on the current buffer.
5668 When ARG is \\[universal-argument] \\[universal-argument], display the asynchronous export stack."
5669 (interactive "P")
5670 (let* ((input
5671 (cond ((equal arg '(16)) '(stack))
5672 ((and arg org-export-dispatch-last-action))
5673 (t (save-window-excursion
5674 (unwind-protect
5675 (progn
5676 ;; Remember where we are
5677 (move-marker org-export-dispatch-last-position
5678 (point)
5679 (org-base-buffer (current-buffer)))
5680 ;; Get and store an export command
5681 (setq org-export-dispatch-last-action
5682 (org-export--dispatch-ui
5683 (list org-export-initial-scope
5684 (and org-export-in-background 'async))
5686 org-export-dispatch-use-expert-ui)))
5687 (and (get-buffer "*Org Export Dispatcher*")
5688 (kill-buffer "*Org Export Dispatcher*")))))))
5689 (action (car input))
5690 (optns (cdr input)))
5691 (unless (memq 'subtree optns)
5692 (move-marker org-export-dispatch-last-position nil))
5693 (case action
5694 ;; First handle special hard-coded actions.
5695 (template (org-export-insert-default-template nil optns))
5696 (stack (org-export-stack))
5697 (publish-current-file
5698 (org-publish-current-file (memq 'force optns) (memq 'async optns)))
5699 (publish-current-project
5700 (org-publish-current-project (memq 'force optns) (memq 'async optns)))
5701 (publish-choose-project
5702 (org-publish (assoc (org-icompleting-read
5703 "Publish project: "
5704 org-publish-project-alist nil t)
5705 org-publish-project-alist)
5706 (memq 'force optns)
5707 (memq 'async optns)))
5708 (publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
5709 (otherwise
5710 (save-excursion
5711 (when arg
5712 ;; Repeating command, maybe move cursor to restore subtree
5713 ;; context.
5714 (if (eq (marker-buffer org-export-dispatch-last-position)
5715 (org-base-buffer (current-buffer)))
5716 (goto-char org-export-dispatch-last-position)
5717 ;; We are in a different buffer, forget position.
5718 (move-marker org-export-dispatch-last-position nil)))
5719 (funcall action
5720 ;; Return a symbol instead of a list to ease
5721 ;; asynchronous export macro use.
5722 (and (memq 'async optns) t)
5723 (and (memq 'subtree optns) t)
5724 (and (memq 'visible optns) t)
5725 (and (memq 'body optns) t)))))))
5727 (defun org-export--dispatch-ui (options first-key expertp)
5728 "Handle interface for `org-export-dispatch'.
5730 OPTIONS is a list containing current interactive options set for
5731 export. It can contain any of the following symbols:
5732 `body' toggles a body-only export
5733 `subtree' restricts export to current subtree
5734 `visible' restricts export to visible part of buffer.
5735 `force' force publishing files.
5736 `async' use asynchronous export process
5738 FIRST-KEY is the key pressed to select the first level menu. It
5739 is nil when this menu hasn't been selected yet.
5741 EXPERTP, when non-nil, triggers expert UI. In that case, no help
5742 buffer is provided, but indications about currently active
5743 options are given in the prompt. Moreover, \[?] allows to switch
5744 back to standard interface."
5745 (let* ((fontify-key
5746 (lambda (key &optional access-key)
5747 ;; Fontify KEY string. Optional argument ACCESS-KEY, when
5748 ;; non-nil is the required first-level key to activate
5749 ;; KEY. When its value is t, activate KEY independently
5750 ;; on the first key, if any. A nil value means KEY will
5751 ;; only be activated at first level.
5752 (if (or (eq access-key t) (eq access-key first-key))
5753 (org-propertize key 'face 'org-warning)
5754 key)))
5755 (fontify-value
5756 (lambda (value)
5757 ;; Fontify VALUE string.
5758 (org-propertize value 'face 'font-lock-variable-name-face)))
5759 ;; Prepare menu entries by extracting them from
5760 ;; `org-export-registered-backends', and sorting them by
5761 ;; access key and by ordinal, if any.
5762 (backends
5763 (sort
5764 (sort
5765 (delq nil
5766 (mapcar
5767 (lambda (b)
5768 (let ((name (car b)))
5769 (catch 'ignored
5770 ;; Ignore any back-end belonging to
5771 ;; `org-export-invisible-backends' or derived
5772 ;; from one of them.
5773 (dolist (ignored org-export-invisible-backends)
5774 (when (org-export-derived-backend-p name ignored)
5775 (throw 'ignored nil)))
5776 (org-export-backend-menu name))))
5777 org-export-registered-backends))
5778 (lambda (a b)
5779 (let ((key-a (nth 1 a))
5780 (key-b (nth 1 b)))
5781 (cond ((and (numberp key-a) (numberp key-b))
5782 (< key-a key-b))
5783 ((numberp key-b) t)))))
5784 (lambda (a b) (< (car a) (car b)))))
5785 ;; Compute a list of allowed keys based on the first key
5786 ;; pressed, if any. Some keys
5787 ;; (?^B, ?^V, ?^S, ?^F, ?^A, ?&, ?# and ?q) are always
5788 ;; available.
5789 (allowed-keys
5790 (nconc (list 2 22 19 6 1)
5791 (if (not first-key) (org-uniquify (mapcar 'car backends))
5792 (let (sub-menu)
5793 (dolist (backend backends (sort (mapcar 'car sub-menu) '<))
5794 (when (eq (car backend) first-key)
5795 (setq sub-menu (append (nth 2 backend) sub-menu))))))
5796 (cond ((eq first-key ?P) (list ?f ?p ?x ?a))
5797 ((not first-key) (list ?P)))
5798 (list ?& ?#)
5799 (when expertp (list ??))
5800 (list ?q)))
5801 ;; Build the help menu for standard UI.
5802 (help
5803 (unless expertp
5804 (concat
5805 ;; Options are hard-coded.
5806 (format "[%s] Body only: %s [%s] Visible only: %s
5807 \[%s] Export scope: %s [%s] Force publishing: %s
5808 \[%s] Async export: %s\n\n"
5809 (funcall fontify-key "C-b" t)
5810 (funcall fontify-value
5811 (if (memq 'body options) "On " "Off"))
5812 (funcall fontify-key "C-v" t)
5813 (funcall fontify-value
5814 (if (memq 'visible options) "On " "Off"))
5815 (funcall fontify-key "C-s" t)
5816 (funcall fontify-value
5817 (if (memq 'subtree options) "Subtree" "Buffer "))
5818 (funcall fontify-key "C-f" t)
5819 (funcall fontify-value
5820 (if (memq 'force options) "On " "Off"))
5821 (funcall fontify-key "C-a" t)
5822 (funcall fontify-value
5823 (if (memq 'async options) "On " "Off")))
5824 ;; Display registered back-end entries. When a key
5825 ;; appears for the second time, do not create another
5826 ;; entry, but append its sub-menu to existing menu.
5827 (let (last-key)
5828 (mapconcat
5829 (lambda (entry)
5830 (let ((top-key (car entry)))
5831 (concat
5832 (unless (eq top-key last-key)
5833 (setq last-key top-key)
5834 (format "\n[%s] %s\n"
5835 (funcall fontify-key (char-to-string top-key))
5836 (nth 1 entry)))
5837 (let ((sub-menu (nth 2 entry)))
5838 (unless (functionp sub-menu)
5839 ;; Split sub-menu into two columns.
5840 (let ((index -1))
5841 (concat
5842 (mapconcat
5843 (lambda (sub-entry)
5844 (incf index)
5845 (format
5846 (if (zerop (mod index 2)) " [%s] %-26s"
5847 "[%s] %s\n")
5848 (funcall fontify-key
5849 (char-to-string (car sub-entry))
5850 top-key)
5851 (nth 1 sub-entry)))
5852 sub-menu "")
5853 (when (zerop (mod index 2)) "\n"))))))))
5854 backends ""))
5855 ;; Publishing menu is hard-coded.
5856 (format "\n[%s] Publish
5857 [%s] Current file [%s] Current project
5858 [%s] Choose project [%s] All projects\n\n\n"
5859 (funcall fontify-key "P")
5860 (funcall fontify-key "f" ?P)
5861 (funcall fontify-key "p" ?P)
5862 (funcall fontify-key "x" ?P)
5863 (funcall fontify-key "a" ?P))
5864 (format "[%s] Export stack [%s] Insert template\n"
5865 (funcall fontify-key "&" t)
5866 (funcall fontify-key "#" t))
5867 (format "[%s] %s"
5868 (funcall fontify-key "q" t)
5869 (if first-key "Main menu" "Exit")))))
5870 ;; Build prompts for both standard and expert UI.
5871 (standard-prompt (unless expertp "Export command: "))
5872 (expert-prompt
5873 (when expertp
5874 (format
5875 "Export command (C-%s%s%s%s%s) [%s]: "
5876 (if (memq 'body options) (funcall fontify-key "b" t) "b")
5877 (if (memq 'visible options) (funcall fontify-key "v" t) "v")
5878 (if (memq 'subtree options) (funcall fontify-key "s" t) "s")
5879 (if (memq 'force options) (funcall fontify-key "f" t) "f")
5880 (if (memq 'async options) (funcall fontify-key "a" t) "a")
5881 (mapconcat (lambda (k)
5882 ;; Strip control characters.
5883 (unless (< k 27) (char-to-string k)))
5884 allowed-keys "")))))
5885 ;; With expert UI, just read key with a fancy prompt. In standard
5886 ;; UI, display an intrusive help buffer.
5887 (if expertp
5888 (org-export--dispatch-action
5889 expert-prompt allowed-keys backends options first-key expertp)
5890 ;; At first call, create frame layout in order to display menu.
5891 (unless (get-buffer "*Org Export Dispatcher*")
5892 (delete-other-windows)
5893 (org-switch-to-buffer-other-window
5894 (get-buffer-create "*Org Export Dispatcher*"))
5895 (setq cursor-type nil
5896 header-line-format "Use SPC, DEL, C-n or C-p to navigate.")
5897 ;; Make sure that invisible cursor will not highlight square
5898 ;; brackets.
5899 (set-syntax-table (copy-syntax-table))
5900 (modify-syntax-entry ?\[ "w"))
5901 ;; At this point, the buffer containing the menu exists and is
5902 ;; visible in the current window. So, refresh it.
5903 (with-current-buffer "*Org Export Dispatcher*"
5904 ;; Refresh help. Maintain display continuity by re-visiting
5905 ;; previous window position.
5906 (let ((pos (window-start)))
5907 (erase-buffer)
5908 (insert help)
5909 (set-window-start nil pos)))
5910 (org-fit-window-to-buffer)
5911 (org-export--dispatch-action
5912 standard-prompt allowed-keys backends options first-key expertp))))
5914 (defun org-export--dispatch-action
5915 (prompt allowed-keys backends options first-key expertp)
5916 "Read a character from command input and act accordingly.
5918 PROMPT is the displayed prompt, as a string. ALLOWED-KEYS is
5919 a list of characters available at a given step in the process.
5920 BACKENDS is a list of menu entries. OPTIONS, FIRST-KEY and
5921 EXPERTP are the same as defined in `org-export--dispatch-ui',
5922 which see.
5924 Toggle export options when required. Otherwise, return value is
5925 a list with action as CAR and a list of interactive export
5926 options as CDR."
5927 (let (key)
5928 ;; Scrolling: when in non-expert mode, act on motion keys (C-n,
5929 ;; C-p, SPC, DEL).
5930 (while (and (setq key (read-char-exclusive prompt))
5931 (not expertp)
5932 (memq key '(14 16 ?\s ?\d)))
5933 (case key
5934 (14 (if (not (pos-visible-in-window-p (point-max)))
5935 (ignore-errors (scroll-up 1))
5936 (message "End of buffer")
5937 (sit-for 1)))
5938 (16 (if (not (pos-visible-in-window-p (point-min)))
5939 (ignore-errors (scroll-down 1))
5940 (message "Beginning of buffer")
5941 (sit-for 1)))
5942 (?\s (if (not (pos-visible-in-window-p (point-max)))
5943 (scroll-up nil)
5944 (message "End of buffer")
5945 (sit-for 1)))
5946 (?\d (if (not (pos-visible-in-window-p (point-min)))
5947 (scroll-down nil)
5948 (message "Beginning of buffer")
5949 (sit-for 1)))))
5950 (cond
5951 ;; Ignore undefined associations.
5952 ((not (memq key allowed-keys))
5953 (ding)
5954 (unless expertp (message "Invalid key") (sit-for 1))
5955 (org-export--dispatch-ui options first-key expertp))
5956 ;; q key at first level aborts export. At second level, cancel
5957 ;; first key instead.
5958 ((eq key ?q) (if (not first-key) (error "Export aborted")
5959 (org-export--dispatch-ui options nil expertp)))
5960 ;; Help key: Switch back to standard interface if expert UI was
5961 ;; active.
5962 ((eq key ??) (org-export--dispatch-ui options first-key nil))
5963 ;; Send request for template insertion along with export scope.
5964 ((eq key ?#) (cons 'template (memq 'subtree options)))
5965 ;; Switch to asynchronous export stack.
5966 ((eq key ?&) '(stack))
5967 ;; Toggle options: C-b (2) C-v (22) C-s (19) C-f (6) C-a (1).
5968 ((memq key '(2 22 19 6 1))
5969 (org-export--dispatch-ui
5970 (let ((option (case key (2 'body) (22 'visible) (19 'subtree)
5971 (6 'force) (1 'async))))
5972 (if (memq option options) (remq option options)
5973 (cons option options)))
5974 first-key expertp))
5975 ;; Action selected: Send key and options back to
5976 ;; `org-export-dispatch'.
5977 ((or first-key (functionp (nth 2 (assq key backends))))
5978 (cons (cond
5979 ((not first-key) (nth 2 (assq key backends)))
5980 ;; Publishing actions are hard-coded. Send a special
5981 ;; signal to `org-export-dispatch'.
5982 ((eq first-key ?P)
5983 (case key
5984 (?f 'publish-current-file)
5985 (?p 'publish-current-project)
5986 (?x 'publish-choose-project)
5987 (?a 'publish-all)))
5988 ;; Return first action associated to FIRST-KEY + KEY
5989 ;; path. Indeed, derived backends can share the same
5990 ;; FIRST-KEY.
5991 (t (catch 'found
5992 (mapc (lambda (backend)
5993 (let ((match (assq key (nth 2 backend))))
5994 (when match (throw 'found (nth 2 match)))))
5995 (member (assq first-key backends) backends)))))
5996 options))
5997 ;; Otherwise, enter sub-menu.
5998 (t (org-export--dispatch-ui options key expertp)))))
6002 (provide 'ox)
6004 ;; Local variables:
6005 ;; generated-autoload-file: "org-loaddefs.el"
6006 ;; End:
6008 ;;; ox.el ends here