1 ;;; ox.el --- Export Framework for Org Mode -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2015 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This library implements a generic export engine for Org, built on
26 ;; its syntactical parser: Org Elements.
28 ;; Besides that parser, the generic exporter is made of three distinct
31 ;; - The communication channel consists of a property list, which is
32 ;; created and updated during the process. Its use is to offer
33 ;; every piece of information, would it be about initial environment
34 ;; or contextual data, all in a single place.
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 functions is `org-export-as'. It returns the transcoded
48 ;; buffer as a string. Its derivatives are `org-export-to-buffer' and
49 ;; `org-export-to-file'.
51 ;; An export back-end is defined with `org-export-define-backend'.
52 ;; This function can also support specific buffer keywords, OPTION
53 ;; keyword's items and filters. Refer to function's documentation for
56 ;; If the new back-end shares most properties with another one,
57 ;; `org-export-define-derived-backend' can be used to simplify the
60 ;; Any back-end can define its own variables. Among them, those
61 ;; customizable should belong to the `org-export-BACKEND' group.
63 ;; Tools for common tasks across back-ends are implemented in the
64 ;; following part of the file.
66 ;; Eventually, a dispatcher (`org-export-dispatch') is provided in the
69 ;; See <http://orgmode.org/worg/dev/org-export-reference.html> for
75 (require 'org-element
)
79 (declare-function org-publish
"ox-publish" (project &optional force async
))
80 (declare-function org-publish-all
"ox-publish" (&optional force async
))
82 org-publish-current-file
"ox-publish" (&optional force async
))
83 (declare-function org-publish-current-project
"ox-publish"
84 (&optional force async
))
86 (defvar org-publish-project-alist
)
87 (defvar org-table-number-fraction
)
88 (defvar org-table-number-regexp
)
91 ;;; Internal Variables
93 ;; Among internal variables, the most important is
94 ;; `org-export-options-alist'. This variable define the global export
95 ;; options, shared between every exporter, and how they are acquired.
97 (defconst org-export-max-depth
19
98 "Maximum nesting depth for headlines, counting from 0.")
100 (defconst org-export-options-alist
101 '((:title
"TITLE" nil nil parse
)
102 (:date
"DATE" nil nil parse
)
103 (:author
"AUTHOR" nil user-full-name parse
)
104 (:email
"EMAIL" nil user-mail-address t
)
105 (:language
"LANGUAGE" nil org-export-default-language t
)
106 (:select-tags
"SELECT_TAGS" nil org-export-select-tags split
)
107 (:exclude-tags
"EXCLUDE_TAGS" nil org-export-exclude-tags split
)
108 (:creator
"CREATOR" nil org-export-creator-string
)
109 (:headline-levels nil
"H" org-export-headline-levels
)
110 (:preserve-breaks nil
"\\n" org-export-preserve-breaks
)
111 (:section-numbers nil
"num" org-export-with-section-numbers
)
112 (:time-stamp-file nil
"timestamp" org-export-time-stamp-file
)
113 (:with-archived-trees nil
"arch" org-export-with-archived-trees
)
114 (:with-author nil
"author" org-export-with-author
)
115 (:with-broken-links nil
"broken-links" org-export-with-broken-links
)
116 (:with-clocks nil
"c" org-export-with-clocks
)
117 (:with-creator nil
"creator" org-export-with-creator
)
118 (:with-date nil
"date" org-export-with-date
)
119 (:with-drawers nil
"d" org-export-with-drawers
)
120 (:with-email nil
"email" org-export-with-email
)
121 (:with-emphasize nil
"*" org-export-with-emphasize
)
122 (:with-entities nil
"e" org-export-with-entities
)
123 (:with-fixed-width nil
":" org-export-with-fixed-width
)
124 (:with-footnotes nil
"f" org-export-with-footnotes
)
125 (:with-inlinetasks nil
"inline" org-export-with-inlinetasks
)
126 (:with-latex nil
"tex" org-export-with-latex
)
127 (:with-planning nil
"p" org-export-with-planning
)
128 (:with-priority nil
"pri" org-export-with-priority
)
129 (:with-properties nil
"prop" org-export-with-properties
)
130 (:with-smart-quotes nil
"'" org-export-with-smart-quotes
)
131 (:with-special-strings nil
"-" org-export-with-special-strings
)
132 (:with-statistics-cookies nil
"stat" org-export-with-statistics-cookies
)
133 (:with-sub-superscript nil
"^" org-export-with-sub-superscripts
)
134 (:with-toc nil
"toc" org-export-with-toc
)
135 (:with-tables nil
"|" org-export-with-tables
)
136 (:with-tags nil
"tags" org-export-with-tags
)
137 (:with-tasks nil
"tasks" org-export-with-tasks
)
138 (:with-timestamps nil
"<" org-export-with-timestamps
)
139 (:with-title nil
"title" org-export-with-title
)
140 (:with-todo-keywords nil
"todo" org-export-with-todo-keywords
))
141 "Alist between export properties and ways to set them.
143 The key of the alist is the property name, and the value is a list
144 like (KEYWORD OPTION DEFAULT BEHAVIOR) where:
146 KEYWORD is a string representing a buffer keyword, or nil. Each
147 property defined this way can also be set, during subtree
148 export, through a headline property named after the keyword
149 with the \"EXPORT_\" prefix (i.e. DATE keyword and EXPORT_DATE
151 OPTION is a string that could be found in an #+OPTIONS: line.
152 DEFAULT is the default value for the property.
153 BEHAVIOR determines how Org should handle multiple keywords for
154 the same property. It is a symbol among:
155 nil Keep old value and discard the new one.
156 t Replace old value with the new one.
157 `space' Concatenate the values, separating them with a space.
158 `newline' Concatenate the values, separating them with
160 `split' Split values at white spaces, and cons them to the
162 `parse' Parse value as a list of strings and Org objects,
163 which can then be transcoded with, e.g.,
164 `org-export-data'. It implies `space' behavior.
166 Values set through KEYWORD and OPTION have precedence over
169 All these properties should be back-end agnostic. Back-end
170 specific properties are set through `org-export-define-backend'.
171 Properties redefined there have precedence over these.")
173 (defconst org-export-special-keywords
'("FILETAGS" "SETUPFILE" "OPTIONS")
174 "List of in-buffer keywords that require special treatment.
175 These keywords are not directly associated to a property. The
176 way they are handled must be hard-coded into
177 `org-export--get-inbuffer-options' function.")
179 (defconst org-export-filters-alist
180 '((:filter-body . org-export-filter-body-functions
)
181 (:filter-bold . org-export-filter-bold-functions
)
182 (:filter-babel-call . org-export-filter-babel-call-functions
)
183 (:filter-center-block . org-export-filter-center-block-functions
)
184 (:filter-clock . org-export-filter-clock-functions
)
185 (:filter-code . org-export-filter-code-functions
)
186 (:filter-diary-sexp . org-export-filter-diary-sexp-functions
)
187 (:filter-drawer . org-export-filter-drawer-functions
)
188 (:filter-dynamic-block . org-export-filter-dynamic-block-functions
)
189 (:filter-entity . org-export-filter-entity-functions
)
190 (:filter-example-block . org-export-filter-example-block-functions
)
191 (:filter-export-block . org-export-filter-export-block-functions
)
192 (:filter-export-snippet . org-export-filter-export-snippet-functions
)
193 (:filter-final-output . org-export-filter-final-output-functions
)
194 (:filter-fixed-width . org-export-filter-fixed-width-functions
)
195 (:filter-footnote-definition . org-export-filter-footnote-definition-functions
)
196 (:filter-footnote-reference . org-export-filter-footnote-reference-functions
)
197 (:filter-headline . org-export-filter-headline-functions
)
198 (:filter-horizontal-rule . org-export-filter-horizontal-rule-functions
)
199 (:filter-inline-babel-call . org-export-filter-inline-babel-call-functions
)
200 (:filter-inline-src-block . org-export-filter-inline-src-block-functions
)
201 (:filter-inlinetask . org-export-filter-inlinetask-functions
)
202 (:filter-italic . org-export-filter-italic-functions
)
203 (:filter-item . org-export-filter-item-functions
)
204 (:filter-keyword . org-export-filter-keyword-functions
)
205 (:filter-latex-environment . org-export-filter-latex-environment-functions
)
206 (:filter-latex-fragment . org-export-filter-latex-fragment-functions
)
207 (:filter-line-break . org-export-filter-line-break-functions
)
208 (:filter-link . org-export-filter-link-functions
)
209 (:filter-node-property . org-export-filter-node-property-functions
)
210 (:filter-options . org-export-filter-options-functions
)
211 (:filter-paragraph . org-export-filter-paragraph-functions
)
212 (:filter-parse-tree . org-export-filter-parse-tree-functions
)
213 (:filter-plain-list . org-export-filter-plain-list-functions
)
214 (:filter-plain-text . org-export-filter-plain-text-functions
)
215 (:filter-planning . org-export-filter-planning-functions
)
216 (:filter-property-drawer . org-export-filter-property-drawer-functions
)
217 (:filter-quote-block . org-export-filter-quote-block-functions
)
218 (:filter-radio-target . org-export-filter-radio-target-functions
)
219 (:filter-section . org-export-filter-section-functions
)
220 (:filter-special-block . org-export-filter-special-block-functions
)
221 (:filter-src-block . org-export-filter-src-block-functions
)
222 (:filter-statistics-cookie . org-export-filter-statistics-cookie-functions
)
223 (:filter-strike-through . org-export-filter-strike-through-functions
)
224 (:filter-subscript . org-export-filter-subscript-functions
)
225 (:filter-superscript . org-export-filter-superscript-functions
)
226 (:filter-table . org-export-filter-table-functions
)
227 (:filter-table-cell . org-export-filter-table-cell-functions
)
228 (:filter-table-row . org-export-filter-table-row-functions
)
229 (:filter-target . org-export-filter-target-functions
)
230 (:filter-timestamp . org-export-filter-timestamp-functions
)
231 (:filter-underline . org-export-filter-underline-functions
)
232 (:filter-verbatim . org-export-filter-verbatim-functions
)
233 (:filter-verse-block . org-export-filter-verse-block-functions
))
234 "Alist between filters properties and initial values.
236 The key of each association is a property name accessible through
237 the communication channel. Its value is a configurable global
238 variable defining initial filters.
240 This list is meant to install user specified filters. Back-end
241 developers may install their own filters using
242 `org-export-define-backend'. Filters defined there will always
243 be prepended to the current list, so they always get applied
246 (defconst org-export-default-inline-image-rule
250 '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
251 "xpm" "pbm" "pgm" "ppm") t
))))
252 "Default rule for link matching an inline image.
253 This rule applies to links with no description. By default, it
254 will be considered as an inline image if it targets a local file
255 whose extension is either \"png\", \"jpeg\", \"jpg\", \"gif\",
256 \"tiff\", \"tif\", \"xbm\", \"xpm\", \"pbm\", \"pgm\" or \"ppm\".
257 See `org-export-inline-image-p' for more information about
260 (defconst org-export-ignored-local-variables
261 '(org-font-lock-keywords
262 org-element--cache org-element--cache-objects org-element--cache-sync-keys
263 org-element--cache-sync-requests org-element--cache-sync-timer
)
264 "List of variables not copied through upon buffer duplication.
265 Export process takes place on a copy of the original buffer.
266 When this copy is created, all Org related local variables not in
267 this list are copied to the new buffer. Variables with an
268 unreadable value are also ignored.")
270 (defvar org-export-async-debug nil
271 "Non-nil means asynchronous export process should leave data behind.
273 This data is found in the appropriate \"*Org Export Process*\"
274 buffer, and in files prefixed with \"org-export-process\" and
275 located in `temporary-file-directory'.
277 When non-nil, it will also set `debug-on-error' to a non-nil
278 value in the external process.")
280 (defvar org-export-stack-contents nil
281 "Record asynchronously generated export results and processes.
282 This is an alist: its CAR is the source of the
283 result (destination file or buffer for a finished process,
284 original buffer for a running one) and its CDR is a list
285 containing the back-end used, as a symbol, and either a process
286 or the time at which it finished. It is used to build the menu
287 from `org-export-stack'.")
289 (defvar org-export-registered-backends nil
290 "List of backends currently available in the exporter.
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.")
317 ;;; User-configurable Variables
319 ;; Configuration for the masses.
321 ;; They should never be accessed directly, as their value is to be
322 ;; stored in a property list (cf. `org-export-options-alist').
323 ;; Back-ends will read their value from there instead.
325 (defgroup org-export nil
326 "Options for exporting Org mode files."
330 (defgroup org-export-general nil
331 "General options for export engine."
332 :tag
"Org Export General"
335 (defcustom org-export-with-archived-trees
'headline
336 "Whether sub-trees with the ARCHIVE tag should be exported.
338 This can have three different values:
339 nil Do not export, pretend this tree is not present.
340 t Do export the entire tree.
341 `headline' Only export the headline, but skip the tree below it.
343 This option can also be set with the OPTIONS keyword,
345 :group
'org-export-general
347 (const :tag
"Not at all" nil
)
348 (const :tag
"Headline only" headline
)
349 (const :tag
"Entirely" t
))
350 :safe
(lambda (x) (memq x
'(t nil headline
))))
352 (defcustom org-export-with-author t
353 "Non-nil means insert author name into the exported file.
354 This option can also be set with the OPTIONS keyword,
355 e.g. \"author:nil\"."
356 :group
'org-export-general
360 (defcustom org-export-with-clocks nil
361 "Non-nil means export CLOCK keywords.
362 This option can also be set with the OPTIONS keyword,
364 :group
'org-export-general
368 (defcustom org-export-with-creator nil
369 "Non-nil means the postamble should contain a creator sentence.
371 The sentence can be set in `org-export-creator-string', which
374 This option can also be set with the OPTIONS keyword, e.g.,
376 :group
'org-export-general
378 :package-version
'(Org .
"8.3")
382 (defcustom org-export-with-date t
383 "Non-nil means insert date in the exported document.
384 This option can also be set with the OPTIONS keyword,
386 :group
'org-export-general
390 (defcustom org-export-date-timestamp-format nil
391 "Time-stamp format string to use for DATE keyword.
393 The format string, when specified, only applies if date consists
394 in a single time-stamp. Otherwise its value will be ignored.
396 See `format-time-string' for details on how to build this
398 :group
'org-export-general
400 (string :tag
"Time-stamp format string")
401 (const :tag
"No format string" nil
))
402 :safe
(lambda (x) (or (null x
) (stringp x
))))
404 (defcustom org-export-creator-string
405 (format "Emacs %s (Org mode %s)"
407 (if (fboundp 'org-version
) (org-version) "unknown version"))
408 "Information about the creator of the document.
409 This option can also be set on with the CREATOR keyword."
410 :group
'org-export-general
411 :type
'(string :tag
"Creator string")
414 (defcustom org-export-with-drawers
'(not "LOGBOOK")
415 "Non-nil means export contents of standard drawers.
417 When t, all drawers are exported. This may also be a list of
418 drawer names to export, as strings. If that list starts with
419 `not', only drawers with such names will be ignored.
421 This variable doesn't apply to properties drawers. See
422 `org-export-with-properties' instead.
424 This option can also be set with the OPTIONS keyword,
426 :group
'org-export-general
428 :package-version
'(Org .
"8.0")
430 (const :tag
"All drawers" t
)
431 (const :tag
"None" nil
)
432 (repeat :tag
"Selected drawers"
433 (string :tag
"Drawer name"))
434 (list :tag
"Ignored drawers"
435 (const :format
"" not
)
436 (repeat :tag
"Specify names of drawers to ignore during export"
438 (string :tag
"Drawer name"))))
439 :safe
(lambda (x) (or (booleanp x
)
441 (or (cl-every #'stringp x
)
442 (and (eq (nth 0 x
) 'not
)
443 (cl-every #'stringp
(cdr x
))))))))
445 (defcustom org-export-with-email nil
446 "Non-nil means insert author email into the exported file.
447 This option can also be set with the OPTIONS keyword,
449 :group
'org-export-general
453 (defcustom org-export-with-emphasize t
454 "Non-nil means interpret *word*, /word/, _word_ and +word+.
456 If the export target supports emphasizing text, the word will be
457 typeset in bold, italic, with an underline or strike-through,
460 This option can also be set with the OPTIONS keyword,
462 :group
'org-export-general
466 (defcustom org-export-exclude-tags
'("noexport")
467 "Tags that exclude a tree from export.
469 All trees carrying any of these tags will be excluded from
470 export. This is without condition, so even subtrees inside that
471 carry one of the `org-export-select-tags' will be removed.
473 This option can also be set with the EXCLUDE_TAGS keyword."
474 :group
'org-export-general
475 :type
'(repeat (string :tag
"Tag"))
476 :safe
(lambda (x) (and (listp x
) (cl-every #'stringp x
))))
478 (defcustom org-export-with-fixed-width t
479 "Non-nil means export lines starting with \":\".
480 This option can also be set with the OPTIONS keyword,
482 :group
'org-export-general
484 :package-version
'(Org .
"8.0")
488 (defcustom org-export-with-footnotes t
489 "Non-nil means Org footnotes should be exported.
490 This option can also be set with the OPTIONS keyword,
492 :group
'org-export-general
496 (defcustom org-export-with-latex t
497 "Non-nil means process LaTeX environments and fragments.
499 This option can also be set with the OPTIONS line,
500 e.g. \"tex:verbatim\". Allowed values are:
502 nil Ignore math snippets.
503 `verbatim' Keep everything in verbatim.
504 t Allow export of math snippets."
505 :group
'org-export-general
507 :package-version
'(Org .
"8.0")
509 (const :tag
"Do not process math in any way" nil
)
510 (const :tag
"Interpret math snippets" t
)
511 (const :tag
"Leave math verbatim" verbatim
))
512 :safe
(lambda (x) (memq x
'(t nil verbatim
))))
514 (defcustom org-export-headline-levels
3
515 "The last level which is still exported as a headline.
517 Inferior levels will usually produce itemize or enumerate lists
518 when exported, but back-end behavior may differ.
520 This option can also be set with the OPTIONS keyword,
522 :group
'org-export-general
526 (defcustom org-export-default-language
"en"
527 "The default language for export and clocktable translations, as a string.
528 This may have an association in
529 `org-clock-clocktable-language-setup',
530 `org-export-smart-quotes-alist' and `org-export-dictionary'.
531 This option can also be set with the LANGUAGE keyword."
532 :group
'org-export-general
533 :type
'(string :tag
"Language")
536 (defcustom org-export-preserve-breaks nil
537 "Non-nil means preserve all line breaks when exporting.
538 This option can also be set with the OPTIONS keyword,
540 :group
'org-export-general
544 (defcustom org-export-with-entities t
545 "Non-nil means interpret entities when exporting.
547 For example, HTML export converts \\alpha to α and \\AA to
550 For a list of supported names, see the constant `org-entities'
551 and the user option `org-entities-user'.
553 This option can also be set with the OPTIONS keyword,
555 :group
'org-export-general
559 (defcustom org-export-with-inlinetasks t
560 "Non-nil means inlinetasks should be exported.
561 This option can also be set with the OPTIONS keyword,
562 e.g. \"inline:nil\"."
563 :group
'org-export-general
565 :package-version
'(Org .
"8.0")
569 (defcustom org-export-with-planning nil
570 "Non-nil means include planning info in export.
572 Planning info is the line containing either SCHEDULED:,
573 DEADLINE:, CLOSED: time-stamps, or a combination of them.
575 This option can also be set with the OPTIONS keyword,
577 :group
'org-export-general
579 :package-version
'(Org .
"8.0")
583 (defcustom org-export-with-priority nil
584 "Non-nil means include priority cookies in export.
585 This option can also be set with the OPTIONS keyword,
587 :group
'org-export-general
591 (defcustom org-export-with-properties nil
592 "Non-nil means export contents of properties drawers.
594 When t, all properties are exported. This may also be a list of
595 properties to export, as strings.
597 This option can also be set with the OPTIONS keyword,
599 :group
'org-export-general
601 :package-version
'(Org .
"8.3")
603 (const :tag
"All properties" t
)
604 (const :tag
"None" nil
)
605 (repeat :tag
"Selected properties"
606 (string :tag
"Property name")))
607 :safe
(lambda (x) (or (booleanp x
)
608 (and (listp x
) (cl-every #'stringp x
)))))
610 (defcustom org-export-with-section-numbers t
611 "Non-nil means add section numbers to headlines when exporting.
613 When set to an integer n, numbering will only happen for
614 headlines whose relative level is higher or equal to n.
616 This option can also be set with the OPTIONS keyword,
618 :group
'org-export-general
622 (defcustom org-export-select-tags
'("export")
623 "Tags that select a tree for export.
625 If any such tag is found in a buffer, all trees that do not carry
626 one of these tags will be ignored during export. Inside trees
627 that are selected like this, you can still deselect a subtree by
628 tagging it with one of the `org-export-exclude-tags'.
630 This option can also be set with the SELECT_TAGS keyword."
631 :group
'org-export-general
632 :type
'(repeat (string :tag
"Tag"))
633 :safe
(lambda (x) (and (listp x
) (cl-every #'stringp x
))))
635 (defcustom org-export-with-smart-quotes nil
636 "Non-nil means activate smart quotes during export.
637 This option can also be set with the OPTIONS keyword,
640 When setting this to non-nil, you need to take care of
641 using the correct Babel package when exporting to LaTeX.
642 E.g., you can load Babel for french like this:
644 #+LATEX_HEADER: \\usepackage[french]{babel}"
645 :group
'org-export-general
647 :package-version
'(Org .
"8.0")
651 (defcustom org-export-with-special-strings t
652 "Non-nil means interpret \"\\-\", \"--\" and \"---\" for export.
654 When this option is turned on, these strings will be exported as:
657 -----+----------+--------+-------
661 ... … \\ldots …
663 This option can also be set with the OPTIONS keyword,
665 :group
'org-export-general
669 (defcustom org-export-with-statistics-cookies t
670 "Non-nil means include statistics cookies in export.
671 This option can also be set with the OPTIONS keyword,
673 :group
'org-export-general
675 :package-version
'(Org .
"8.0")
679 (defcustom org-export-with-sub-superscripts t
680 "Non-nil means interpret \"_\" and \"^\" for export.
682 If you want to control how Org displays those characters, see
683 `org-use-sub-superscripts'. `org-export-with-sub-superscripts'
684 used to be an alias for `org-use-sub-superscripts' in Org <8.0,
687 When this option is turned on, you can use TeX-like syntax for
688 sub- and superscripts and see them exported correctly.
690 You can also set the option with #+OPTIONS: ^:t
692 Several characters after \"_\" or \"^\" will be considered as a
693 single item - so grouping with {} is normally not needed. For
694 example, the following things will be parsed as single sub- or
697 10^24 or 10^tau several digits will be considered 1 item.
698 10^-12 or 10^-tau a leading sign with digits or a word
699 x^2-y^3 will be read as x^2 - y^3, because items are
700 terminated by almost any nonword/nondigit char.
701 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
703 Still, ambiguity is possible. So when in doubt, use {} to enclose
704 the sub/superscript. If you set this variable to the symbol `{}',
705 the braces are *required* in order to trigger interpretations as
706 sub/superscript. This can be helpful in documents that need \"_\"
707 frequently in plain text."
708 :group
'org-export-general
710 :package-version
'(Org .
"8.0")
712 (const :tag
"Interpret them" t
)
713 (const :tag
"Curly brackets only" {})
714 (const :tag
"Do not interpret them" nil
))
715 :safe
(lambda (x) (memq x
'(t nil
{}))))
717 (defcustom org-export-with-toc t
718 "Non-nil means create a table of contents in exported files.
720 The TOC contains headlines with levels up
721 to`org-export-headline-levels'. When an integer, include levels
722 up to N in the toc, this may then be different from
723 `org-export-headline-levels', but it will not be allowed to be
724 larger than the number of headline levels. When nil, no table of
727 This option can also be set with the OPTIONS keyword,
728 e.g. \"toc:nil\" or \"toc:3\"."
729 :group
'org-export-general
731 (const :tag
"No Table of Contents" nil
)
732 (const :tag
"Full Table of Contents" t
)
733 (integer :tag
"TOC to level"))
734 :safe
(lambda (x) (or (booleanp x
)
737 (defcustom org-export-with-tables t
738 "Non-nil means export tables.
739 This option can also be set with the OPTIONS keyword,
741 :group
'org-export-general
743 :package-version
'(Org .
"8.0")
747 (defcustom org-export-with-tags t
748 "If nil, do not export tags, just remove them from headlines.
750 If this is the symbol `not-in-toc', tags will be removed from
751 table of contents entries, but still be shown in the headlines of
754 This option can also be set with the OPTIONS keyword,
756 :group
'org-export-general
758 (const :tag
"Off" nil
)
759 (const :tag
"Not in TOC" not-in-toc
)
761 :safe
(lambda (x) (memq x
'(t nil not-in-toc
))))
763 (defcustom org-export-with-tasks t
764 "Non-nil means include TODO items for export.
766 This may have the following values:
767 t include tasks independent of state.
768 `todo' include only tasks that are not yet done.
769 `done' include only tasks that are already done.
770 nil ignore all tasks.
771 list of keywords include tasks with these keywords.
773 This option can also be set with the OPTIONS keyword,
775 :group
'org-export-general
777 (const :tag
"All tasks" t
)
778 (const :tag
"No tasks" nil
)
779 (const :tag
"Not-done tasks" todo
)
780 (const :tag
"Only done tasks" done
)
781 (repeat :tag
"Specific TODO keywords"
782 (string :tag
"Keyword")))
783 :safe
(lambda (x) (or (memq x
'(nil t todo done
))
785 (cl-every #'stringp x
)))))
787 (defcustom org-export-with-title t
788 "Non-nil means print title into the exported file.
789 This option can also be set with the OPTIONS keyword,
791 :group
'org-export-general
793 :package-version
'(Org .
"8.3")
797 (defcustom org-export-time-stamp-file t
798 "Non-nil means insert a time stamp into the exported file.
799 The time stamp shows when the file was created. This option can
800 also be set with the OPTIONS keyword, e.g. \"timestamp:nil\"."
801 :group
'org-export-general
805 (defcustom org-export-with-timestamps t
806 "Non nil means allow timestamps in export.
808 It can be set to any of the following values:
809 t export all timestamps.
810 `active' export active timestamps only.
811 `inactive' export inactive timestamps only.
812 nil do not export timestamps
814 This only applies to timestamps isolated in a paragraph
815 containing only timestamps. Other timestamps are always
818 This option can also be set with the OPTIONS keyword, e.g.
820 :group
'org-export-general
822 (const :tag
"All timestamps" t
)
823 (const :tag
"Only active timestamps" active
)
824 (const :tag
"Only inactive timestamps" inactive
)
825 (const :tag
"No timestamp" nil
))
826 :safe
(lambda (x) (memq x
'(t nil active inactive
))))
828 (defcustom org-export-with-todo-keywords t
829 "Non-nil means include TODO keywords in export.
830 When nil, remove all these keywords from the export. This option
831 can also be set with the OPTIONS keyword, e.g. \"todo:nil\"."
832 :group
'org-export-general
835 (defcustom org-export-allow-bind-keywords nil
836 "Non-nil means BIND keywords can define local variable values.
837 This is a potential security risk, which is why the default value
838 is nil. You can also allow them through local buffer variables."
839 :group
'org-export-general
841 :package-version
'(Org .
"8.0")
844 (defcustom org-export-with-broken-links nil
845 "Non-nil means do not raise an error on broken links.
847 When this variable is non-nil, broken links are ignored, without
848 stopping the export process. If it is set to `mark', broken
849 links are marked as such in the output, with a string like
853 where PATH is the un-resolvable reference.
855 This option can also be set with the OPTIONS keyword, e.g.,
856 \"broken-links:mark\"."
857 :group
'org-export-general
859 :package-version
'(Org .
"9.0")
861 (const :tag
"Ignore broken links" t
)
862 (const :tag
"Mark broken links in output" mark
)
863 (const :tag
"Raise an error" nil
)))
865 (defcustom org-export-snippet-translation-alist nil
866 "Alist between export snippets back-ends and exporter back-ends.
868 This variable allows to provide shortcuts for export snippets.
870 For example, with a value of \\='((\"h\" . \"html\")), the
871 HTML back-end will recognize the contents of \"@@h:<b>@@\" as
872 HTML code while every other back-end will ignore it."
873 :group
'org-export-general
875 :package-version
'(Org .
"8.0")
877 (cons (string :tag
"Shortcut")
878 (string :tag
"Back-end")))
882 (cl-every #'stringp
(mapcar #'car x
))
883 (cl-every #'stringp
(mapcar #'cdr x
)))))
885 (defcustom org-export-coding-system nil
886 "Coding system for the exported file."
887 :group
'org-export-general
889 :package-version
'(Org .
"8.0")
890 :type
'coding-system
)
892 (defcustom org-export-copy-to-kill-ring nil
893 "Non-nil means pushing export output to the kill ring.
894 This variable is ignored during asynchronous export."
895 :group
'org-export-general
897 :package-version
'(Org .
"8.3")
899 (const :tag
"Always" t
)
900 (const :tag
"When export is done interactively" if-interactive
)
901 (const :tag
"Never" nil
)))
903 (defcustom org-export-initial-scope
'buffer
904 "The initial scope when exporting with `org-export-dispatch'.
905 This variable can be either set to `buffer' or `subtree'."
906 :group
'org-export-general
908 (const :tag
"Export current buffer" buffer
)
909 (const :tag
"Export current subtree" subtree
)))
911 (defcustom org-export-show-temporary-export-buffer t
912 "Non-nil means show buffer after exporting to temp buffer.
913 When Org exports to a file, the buffer visiting that file is never
914 shown, but remains buried. However, when exporting to
915 a temporary buffer, that buffer is popped up in a second window.
916 When this variable is nil, the buffer remains buried also in
918 :group
'org-export-general
921 (defcustom org-export-in-background nil
922 "Non-nil means export and publishing commands will run in background.
923 Results from an asynchronous export are never displayed
924 automatically. But you can retrieve them with \\[org-export-stack]."
925 :group
'org-export-general
927 :package-version
'(Org .
"8.0")
930 (defcustom org-export-async-init-file nil
931 "File used to initialize external export process.
933 Value must be either nil or an absolute file name. When nil, the
934 external process is launched like a regular Emacs session,
935 loading user's initialization file and any site specific
936 configuration. If a file is provided, it, and only it, is loaded
939 Therefore, using a specific configuration makes the process to
940 load faster and the export more portable."
941 :group
'org-export-general
943 :package-version
'(Org .
"8.0")
945 (const :tag
"Regular startup" nil
)
946 (file :tag
"Specific start-up file" :must-match t
)))
948 (defcustom org-export-dispatch-use-expert-ui nil
949 "Non-nil means using a non-intrusive `org-export-dispatch'.
950 In that case, no help buffer is displayed. Though, an indicator
951 for current export scope is added to the prompt (\"b\" when
952 output is restricted to body only, \"s\" when it is restricted to
953 the current subtree, \"v\" when only visible elements are
954 considered for export, \"f\" when publishing functions should be
955 passed the FORCE argument and \"a\" when the export should be
956 asynchronous). Also, [?] allows to switch back to standard
958 :group
'org-export-general
960 :package-version
'(Org .
"8.0")
965 ;;; Defining Back-ends
967 ;; An export back-end is a structure with `org-export-backend' type
968 ;; and `name', `parent', `transcoders', `options', `filters', `blocks'
971 ;; At the lowest level, a back-end is created with
972 ;; `org-export-create-backend' function.
974 ;; A named back-end can be registered with
975 ;; `org-export-register-backend' function. A registered back-end can
976 ;; later be referred to by its name, with `org-export-get-backend'
977 ;; function. Also, such a back-end can become the parent of a derived
978 ;; back-end from which slot values will be inherited by default.
979 ;; `org-export-derived-backend-p' can check if a given back-end is
980 ;; derived from a list of back-end names.
982 ;; `org-export-get-all-transcoders', `org-export-get-all-options' and
983 ;; `org-export-get-all-filters' return the full alist of transcoders,
984 ;; options and filters, including those inherited from ancestors.
986 ;; At a higher level, `org-export-define-backend' is the standard way
987 ;; to define an export back-end. If the new back-end is similar to
988 ;; a registered back-end, `org-export-define-derived-backend' may be
991 ;; Eventually `org-export-barf-if-invalid-backend' returns an error
992 ;; when a given back-end hasn't been registered yet.
994 (cl-defstruct (org-export-backend (:constructor org-export-create-backend
)
996 name parent transcoders options filters blocks menu
)
998 (defun org-export-get-backend (name)
999 "Return export back-end named after NAME.
1000 NAME is a symbol. Return nil if no such back-end is found."
1002 (dolist (b org-export-registered-backends
)
1003 (when (eq (org-export-backend-name b
) name
)
1004 (throw 'found b
)))))
1006 (defun org-export-register-backend (backend)
1007 "Register BACKEND as a known export back-end.
1008 BACKEND is a structure with `org-export-backend' type."
1009 ;; Refuse to register an unnamed back-end.
1010 (unless (org-export-backend-name backend
)
1011 (error "Cannot register a unnamed export back-end"))
1012 ;; Refuse to register a back-end with an unknown parent.
1013 (let ((parent (org-export-backend-parent backend
)))
1014 (when (and parent
(not (org-export-get-backend parent
)))
1015 (error "Cannot use unknown \"%s\" back-end as a parent" parent
)))
1016 ;; Register dedicated export blocks in the parser.
1017 (dolist (name (org-export-backend-blocks backend
))
1018 (add-to-list 'org-element-block-name-alist
1019 (cons name
'org-element-export-block-parser
)))
1020 ;; If a back-end with the same name as BACKEND is already
1021 ;; registered, replace it with BACKEND. Otherwise, simply add
1022 ;; BACKEND to the list of registered back-ends.
1023 (let ((old (org-export-get-backend (org-export-backend-name backend
))))
1024 (if old
(setcar (memq old org-export-registered-backends
) backend
)
1025 (push backend org-export-registered-backends
))))
1027 (defun org-export-barf-if-invalid-backend (backend)
1028 "Signal an error if BACKEND isn't defined."
1029 (unless (org-export-backend-p backend
)
1030 (error "Unknown \"%s\" back-end: Aborting export" backend
)))
1032 (defun org-export-derived-backend-p (backend &rest backends
)
1033 "Non-nil if BACKEND is derived from one of BACKENDS.
1034 BACKEND is an export back-end, as returned by, e.g.,
1035 `org-export-create-backend', or a symbol referring to
1036 a registered back-end. BACKENDS is constituted of symbols."
1037 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1040 (while (org-export-backend-parent backend
)
1041 (when (memq (org-export-backend-name backend
) backends
)
1044 (org-export-get-backend (org-export-backend-parent backend
))))
1045 (memq (org-export-backend-name backend
) backends
))))
1047 (defun org-export-get-all-transcoders (backend)
1048 "Return full translation table for BACKEND.
1050 BACKEND is an export back-end, as return by, e.g,,
1051 `org-export-create-backend'. Return value is an alist where
1052 keys are element or object types, as symbols, and values are
1055 Unlike to `org-export-backend-transcoders', this function
1056 also returns transcoders inherited from parent back-ends,
1058 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1060 (let ((transcoders (org-export-backend-transcoders backend
))
1062 (while (setq parent
(org-export-backend-parent backend
))
1063 (setq backend
(org-export-get-backend parent
))
1065 (append transcoders
(org-export-backend-transcoders backend
))))
1068 (defun org-export-get-all-options (backend)
1069 "Return export options for BACKEND.
1071 BACKEND is an export back-end, as return by, e.g,,
1072 `org-export-create-backend'. See `org-export-options-alist'
1073 for the shape of the return value.
1075 Unlike to `org-export-backend-options', this function also
1076 returns options inherited from parent back-ends, if any."
1077 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1079 (let ((options (org-export-backend-options backend
))
1081 (while (setq parent
(org-export-backend-parent backend
))
1082 (setq backend
(org-export-get-backend parent
))
1083 (setq options
(append options
(org-export-backend-options backend
))))
1086 (defun org-export-get-all-filters (backend)
1087 "Return complete list of filters for BACKEND.
1089 BACKEND is an export back-end, as return by, e.g,,
1090 `org-export-create-backend'. Return value is an alist where
1091 keys are symbols and values lists of functions.
1093 Unlike to `org-export-backend-filters', this function also
1094 returns filters inherited from parent back-ends, if any."
1095 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1097 (let ((filters (org-export-backend-filters backend
))
1099 (while (setq parent
(org-export-backend-parent backend
))
1100 (setq backend
(org-export-get-backend parent
))
1101 (setq filters
(append filters
(org-export-backend-filters backend
))))
1104 (defun org-export-define-backend (backend transcoders
&rest body
)
1105 "Define a new back-end BACKEND.
1107 TRANSCODERS is an alist between object or element types and
1108 functions handling them.
1110 These functions should return a string without any trailing
1111 space, or nil. They must accept three arguments: the object or
1112 element itself, its contents or nil when it isn't recursive and
1113 the property list used as a communication channel.
1115 Contents, when not nil, are stripped from any global indentation
1116 \(although the relative one is preserved). They also always end
1117 with a single newline character.
1119 If, for a given type, no function is found, that element or
1120 object type will simply be ignored, along with any blank line or
1121 white space at its end. The same will happen if the function
1122 returns the nil value. If that function returns the empty
1123 string, the type will be ignored, but the blank lines or white
1124 spaces will be kept.
1126 In addition to element and object types, one function can be
1127 associated to the `template' (or `inner-template') symbol and
1128 another one to the `plain-text' symbol.
1130 The former returns the final transcoded string, and can be used
1131 to add a preamble and a postamble to document's body. It must
1132 accept two arguments: the transcoded string and the property list
1133 containing export options. A function associated to `template'
1134 will not be applied if export has option \"body-only\".
1135 A function associated to `inner-template' is always applied.
1137 The latter, when defined, is to be called on every text not
1138 recognized as an element or an object. It must accept two
1139 arguments: the text string and the information channel. It is an
1140 appropriate place to protect special chars relative to the
1143 BODY can start with pre-defined keyword arguments. The following
1144 keywords are understood:
1148 String, or list of strings, representing block names that
1149 will not be parsed. This is used to specify blocks that will
1150 contain raw code specific to the back-end. These blocks
1151 still have to be handled by the relative `export-block' type
1156 Alist between filters and function, or list of functions,
1157 specific to the back-end. See `org-export-filters-alist' for
1158 a list of all allowed filters. Filters defined here
1159 shouldn't make a back-end test, as it may prevent back-ends
1160 derived from this one to behave properly.
1164 Menu entry for the export dispatcher. It should be a list
1167 \\='(KEY DESCRIPTION-OR-ORDINAL ACTION-OR-MENU)
1171 KEY is a free character selecting the back-end.
1173 DESCRIPTION-OR-ORDINAL is either a string or a number.
1175 If it is a string, is will be used to name the back-end in
1176 its menu entry. If it is a number, the following menu will
1177 be displayed as a sub-menu of the back-end with the same
1178 KEY. Also, the number will be used to determine in which
1179 order such sub-menus will appear (lowest first).
1181 ACTION-OR-MENU is either a function or an alist.
1183 If it is an action, it will be called with four
1184 arguments (booleans): ASYNC, SUBTREEP, VISIBLE-ONLY and
1185 BODY-ONLY. See `org-export-as' for further explanations on
1188 If it is an alist, associations should follow the
1191 \\='(KEY DESCRIPTION ACTION)
1193 where KEY, DESCRIPTION and ACTION are described above.
1195 Valid values include:
1197 \\='(?m \"My Special Back-end\" my-special-export-function)
1201 \\='(?l \"Export to LaTeX\"
1202 (?p \"As PDF file\" org-latex-export-to-pdf)
1203 (?o \"As PDF file and open\"
1205 (if a (org-latex-export-to-pdf t s v b)
1207 (org-latex-export-to-pdf nil s v b)))))))
1209 or the following, which will be added to the previous
1213 ((?B \"As TEX buffer (Beamer)\" org-beamer-export-as-latex)
1214 (?P \"As PDF file (Beamer)\" org-beamer-export-to-pdf)))
1218 Alist between back-end specific properties introduced in
1219 communication channel and how their value are acquired. See
1220 `org-export-options-alist' for more information about
1221 structure of the values."
1222 (declare (indent 1))
1223 (let (blocks filters menu-entry options
)
1224 (while (keywordp (car body
))
1225 (let ((keyword (pop body
)))
1227 (:export-block
(let ((names (pop body
)))
1228 (setq blocks
(if (consp names
) (mapcar 'upcase names
)
1229 (list (upcase names
))))))
1230 (:filters-alist
(setq filters
(pop body
)))
1231 (:menu-entry
(setq menu-entry
(pop body
)))
1232 (:options-alist
(setq options
(pop body
)))
1233 (t (error "Unknown keyword: %s" keyword
)))))
1234 (org-export-register-backend
1235 (org-export-create-backend :name backend
1236 :transcoders transcoders
1240 :menu menu-entry
))))
1242 (defun org-export-define-derived-backend (child parent
&rest body
)
1243 "Create a new back-end as a variant of an existing one.
1245 CHILD is the name of the derived back-end. PARENT is the name of
1246 the parent back-end.
1248 BODY can start with pre-defined keyword arguments. The following
1249 keywords are understood:
1253 String, or list of strings, representing block names that
1254 will not be parsed. This is used to specify blocks that will
1255 contain raw code specific to the back-end. These blocks
1256 still have to be handled by the relative `export-block' type
1261 Alist of filters that will overwrite or complete filters
1262 defined in PARENT back-end. See `org-export-filters-alist'
1263 for a list of allowed filters.
1267 Menu entry for the export dispatcher. See
1268 `org-export-define-backend' for more information about the
1273 Alist of back-end specific properties that will overwrite or
1274 complete those defined in PARENT back-end. Refer to
1275 `org-export-options-alist' for more information about
1276 structure of the values.
1280 Alist of element and object types and transcoders that will
1281 overwrite or complete transcode table from PARENT back-end.
1282 Refer to `org-export-define-backend' for detailed information
1285 As an example, here is how one could define \"my-latex\" back-end
1286 as a variant of `latex' back-end with a custom template function:
1288 (org-export-define-derived-backend \\='my-latex \\='latex
1289 :translate-alist \\='((template . my-latex-template-fun)))
1291 The back-end could then be called with, for example:
1293 (org-export-to-buffer \\='my-latex \"*Test my-latex*\")"
1294 (declare (indent 2))
1295 (let (blocks filters menu-entry options transcoders
)
1296 (while (keywordp (car body
))
1297 (let ((keyword (pop body
)))
1299 (:export-block
(let ((names (pop body
)))
1300 (setq blocks
(if (consp names
) (mapcar 'upcase names
)
1301 (list (upcase names
))))))
1302 (:filters-alist
(setq filters
(pop body
)))
1303 (:menu-entry
(setq menu-entry
(pop body
)))
1304 (:options-alist
(setq options
(pop body
)))
1305 (:translate-alist
(setq transcoders
(pop body
)))
1306 (t (error "Unknown keyword: %s" keyword
)))))
1307 (org-export-register-backend
1308 (org-export-create-backend :name child
1310 :transcoders transcoders
1314 :menu menu-entry
))))
1318 ;;; The Communication Channel
1320 ;; During export process, every function has access to a number of
1321 ;; properties. They are of two types:
1323 ;; 1. Environment options are collected once at the very beginning of
1324 ;; the process, out of the original buffer and configuration.
1325 ;; Collecting them is handled by `org-export-get-environment'
1328 ;; Most environment options are defined through the
1329 ;; `org-export-options-alist' variable.
1331 ;; 2. Tree properties are extracted directly from the parsed tree,
1332 ;; just before export, by `org-export--collect-tree-properties'.
1334 ;;;; Environment Options
1336 ;; Environment options encompass all parameters defined outside the
1337 ;; scope of the parsed data. They come from five sources, in
1338 ;; increasing precedence order:
1340 ;; - Global variables,
1341 ;; - Buffer's attributes,
1342 ;; - Options keyword symbols,
1343 ;; - Buffer keywords,
1344 ;; - Subtree properties.
1346 ;; The central internal function with regards to environment options
1347 ;; is `org-export-get-environment'. It updates global variables with
1348 ;; "#+BIND:" keywords, then retrieve and prioritize properties from
1349 ;; the different sources.
1351 ;; The internal functions doing the retrieval are:
1352 ;; `org-export--get-global-options',
1353 ;; `org-export--get-buffer-attributes',
1354 ;; `org-export--parse-option-keyword',
1355 ;; `org-export--get-subtree-options' and
1356 ;; `org-export--get-inbuffer-options'
1358 ;; Also, `org-export--list-bound-variables' collects bound variables
1359 ;; along with their value in order to set them as buffer local
1360 ;; variables later in the process.
1362 (defun org-export-get-environment (&optional backend subtreep ext-plist
)
1363 "Collect export options from the current buffer.
1365 Optional argument BACKEND is an export back-end, as returned by
1366 `org-export-create-backend'.
1368 When optional argument SUBTREEP is non-nil, assume the export is
1369 done against the current sub-tree.
1371 Third optional argument EXT-PLIST is a property list with
1372 external parameters overriding Org default settings, but still
1373 inferior to file-local settings."
1374 ;; First install #+BIND variables since these must be set before
1375 ;; global options are read.
1376 (dolist (pair (org-export--list-bound-variables))
1377 (set (make-local-variable (car pair
)) (nth 1 pair
)))
1378 ;; Get and prioritize export options...
1380 ;; ... from global variables...
1381 (org-export--get-global-options backend
)
1382 ;; ... from an external property list...
1384 ;; ... from in-buffer settings...
1385 (org-export--get-inbuffer-options backend
)
1386 ;; ... and from subtree, when appropriate.
1387 (and subtreep
(org-export--get-subtree-options backend
))))
1389 (defun org-export--parse-option-keyword (options &optional backend
)
1390 "Parse an OPTIONS line and return values as a plist.
1391 Optional argument BACKEND is an export back-end, as returned by,
1392 e.g., `org-export-create-backend'. It specifies which back-end
1393 specific items to read, if any."
1396 (while (string-match "\\(.+?\\):\\((.*?)\\|\\S-*\\)[ \t]*" options s
)
1397 (setq s
(match-end 0))
1398 (push (cons (match-string 1 options
)
1399 (read (match-string 2 options
)))
1402 ;; Priority is given to back-end specific options.
1403 (all (append (and backend
(org-export-get-all-options backend
))
1404 org-export-options-alist
))
1407 (dolist (entry all plist
)
1408 (let ((item (nth 2 entry
)))
1410 (let ((v (assoc-string item line t
)))
1411 (when v
(setq plist
(plist-put plist
(car entry
) (cdr v
)))))))))))
1413 (defun org-export--get-subtree-options (&optional backend
)
1414 "Get export options in subtree at point.
1415 Optional argument BACKEND is an export back-end, as returned by,
1416 e.g., `org-export-create-backend'. It specifies back-end used
1417 for export. Return options as a plist."
1418 ;; For each buffer keyword, create a headline property setting the
1419 ;; same property in communication channel. The name for the
1420 ;; property is the keyword with "EXPORT_" appended to it.
1421 (org-with-wide-buffer
1422 ;; Make sure point is at a heading.
1423 (if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t
))
1425 ;; EXPORT_OPTIONS are parsed in a non-standard way. Take
1426 ;; care of them right from the start.
1427 (let ((o (org-entry-get (point) "EXPORT_OPTIONS" 'selective
)))
1428 (and o
(org-export--parse-option-keyword o backend
))))
1429 ;; Take care of EXPORT_TITLE. If it isn't defined, use
1430 ;; headline's title (with no todo keyword, priority cookie or
1431 ;; tag) as its fallback value.
1434 (or (org-entry-get (point) "EXPORT_TITLE" 'selective
)
1435 (progn (looking-at org-complex-heading-regexp
)
1436 (org-match-string-no-properties 4))))))
1437 ;; Look for both general keywords and back-end specific
1438 ;; options, with priority given to the latter.
1439 (options (append (and backend
(org-export-get-all-options backend
))
1440 org-export-options-alist
)))
1441 ;; Handle other keywords. Then return PLIST.
1442 (dolist (option options plist
)
1443 (let ((property (car option
))
1444 (keyword (nth 1 option
)))
1447 (or (cdr (assoc keyword cache
))
1448 (let ((v (org-entry-get (point)
1449 (concat "EXPORT_" keyword
)
1451 (push (cons keyword v
) cache
) v
))))
1456 (cl-case (nth 4 option
)
1458 (org-element-parse-secondary-string
1459 value
(org-element-restriction 'keyword
)))
1460 (split (org-split-string value
))
1461 (t value
))))))))))))
1463 (defun org-export--get-inbuffer-options (&optional backend
)
1464 "Return current buffer export options, as a plist.
1466 Optional argument BACKEND, when non-nil, is an export back-end,
1467 as returned by, e.g., `org-export-create-backend'. It specifies
1468 which back-end specific options should also be read in the
1471 Assume buffer is in Org mode. Narrowing, if any, is ignored."
1472 (let* ((case-fold-search t
)
1474 ;; Priority is given to back-end specific options.
1475 (and backend
(org-export-get-all-options backend
))
1476 org-export-options-alist
))
1477 (regexp (format "^[ \t]*#\\+%s:"
1478 (regexp-opt (nconc (delq nil
(mapcar #'cadr options
))
1479 org-export-special-keywords
))))
1481 (letrec ((find-properties
1483 ;; Return all properties associated to KEYWORD.
1485 (dolist (option options properties
)
1486 (when (equal (nth 1 option
) keyword
)
1487 (cl-pushnew (car option
) properties
))))))
1489 (lambda (&optional files
)
1490 ;; Recursively read keywords in buffer. FILES is
1491 ;; a list of files read so far. PLIST is the current
1492 ;; property list obtained.
1493 (org-with-wide-buffer
1494 (goto-char (point-min))
1495 (while (re-search-forward regexp nil t
)
1496 (let ((element (org-element-at-point)))
1497 (when (eq (org-element-type element
) 'keyword
)
1498 (let ((key (org-element-property :key element
))
1499 (val (org-element-property :value element
)))
1501 ;; Options in `org-export-special-keywords'.
1502 ((equal key
"SETUPFILE")
1505 (org-remove-double-quotes (org-trim val
)))))
1506 ;; Avoid circular dependencies.
1507 (unless (member file files
)
1509 (setq default-directory
1510 (file-name-directory file
))
1511 (insert (org-file-contents file
'noerror
))
1512 (let ((org-inhibit-startup t
)) (org-mode))
1513 (funcall get-options
(cons file files
))))))
1514 ((equal key
"OPTIONS")
1518 (org-export--parse-option-keyword
1520 ((equal key
"FILETAGS")
1527 (org-split-string val
":")
1528 (plist-get plist
:filetags
)))))))
1530 ;; Options in `org-export-options-alist'.
1531 (dolist (property (funcall find-properties key
))
1536 ;; Handle value depending on specified
1538 (cl-case (nth 4 (assq property options
))
1540 (unless (memq property to-parse
)
1541 (push property to-parse
))
1542 ;; Even if `parse' implies `space'
1543 ;; behavior, we separate line with
1544 ;; "\n" so as to preserve
1545 ;; line-breaks. However, empty
1546 ;; lines are forbidden since `parse'
1547 ;; doesn't allow more than one
1549 (let ((old (plist-get plist property
)))
1550 (cond ((not (org-string-nw-p val
)) old
)
1551 (old (concat old
"\n" val
))
1554 (if (not (plist-get plist property
))
1556 (concat (plist-get plist property
)
1561 (concat (plist-get plist property
)
1564 (split `(,@(plist-get plist property
)
1565 ,@(org-split-string val
)))
1568 (if (not (plist-member plist property
)) val
1569 (plist-get plist property
)))))))))))))))))
1570 ;; Read options in the current buffer and return value.
1571 (funcall get-options
(and buffer-file-name
(list buffer-file-name
)))
1572 ;; Parse properties in TO-PARSE. Remove newline characters not
1573 ;; involved in line breaks to simulate `space' behavior.
1574 ;; Finally return options.
1575 (dolist (p to-parse plist
)
1576 (let ((value (org-element-parse-secondary-string
1578 (org-element-restriction 'keyword
))))
1579 (org-element-map value
'plain-text
1581 (org-element-set-element
1582 s
(replace-regexp-in-string "\n" " " s
))))
1583 (setq plist
(plist-put plist p value
)))))))
1585 (defun org-export--get-export-attributes
1586 (&optional backend subtreep visible-only body-only
)
1587 "Return properties related to export process, as a plist.
1588 Optional arguments BACKEND, SUBTREEP, VISIBLE-ONLY and BODY-ONLY
1589 are like the arguments with the same names of function
1591 (list :export-options
(delq nil
1592 (list (and subtreep
'subtree
)
1593 (and visible-only
'visible-only
)
1594 (and body-only
'body-only
)))
1596 :translate-alist
(org-export-get-all-transcoders backend
)
1597 :exported-data
(make-hash-table :test
#'eq
:size
4001)))
1599 (defun org-export--get-buffer-attributes ()
1600 "Return properties related to buffer attributes, as a plist."
1601 (list :input-buffer
(buffer-name (buffer-base-buffer))
1602 :input-file
(buffer-file-name (buffer-base-buffer))))
1604 (defun org-export--get-global-options (&optional backend
)
1605 "Return global export options as a plist.
1606 Optional argument BACKEND, if non-nil, is an export back-end, as
1607 returned by, e.g., `org-export-create-backend'. It specifies
1608 which back-end specific export options should also be read in the
1611 ;; Priority is given to back-end specific options.
1612 (all (append (and backend
(org-export-get-all-options backend
))
1613 org-export-options-alist
)))
1614 (dolist (cell all plist
)
1615 (let ((prop (car cell
)))
1616 (unless (plist-member plist prop
)
1621 ;; Evaluate default value provided.
1622 (let ((value (eval (nth 3 cell
))))
1623 (if (eq (nth 4 cell
) 'parse
)
1624 (org-element-parse-secondary-string
1625 value
(org-element-restriction 'keyword
))
1628 (defun org-export--list-bound-variables ()
1629 "Return variables bound from BIND keywords in current buffer.
1630 Also look for BIND keywords in setup files. The return value is
1631 an alist where associations are (VARIABLE-NAME VALUE)."
1632 (when org-export-allow-bind-keywords
1633 (letrec ((collect-bind
1634 (lambda (files alist
)
1635 ;; Return an alist between variable names and their
1636 ;; value. FILES is a list of setup files names read
1637 ;; so far, used to avoid circular dependencies. ALIST
1638 ;; is the alist collected so far.
1639 (let ((case-fold-search t
))
1640 (org-with-wide-buffer
1641 (goto-char (point-min))
1642 (while (re-search-forward
1643 "^[ \t]*#\\+\\(BIND\\|SETUPFILE\\):" nil t
)
1644 (let ((element (org-element-at-point)))
1645 (when (eq (org-element-type element
) 'keyword
)
1646 (let ((val (org-element-property :value element
)))
1647 (if (equal (org-element-property :key element
)
1649 (push (read (format "(%s)" val
)) alist
)
1650 ;; Enter setup file.
1651 (let ((file (expand-file-name
1652 (org-remove-double-quotes val
))))
1653 (unless (member file files
)
1655 (setq default-directory
1656 (file-name-directory file
))
1657 (let ((org-inhibit-startup t
)) (org-mode))
1658 (insert (org-file-contents file
'noerror
))
1660 (funcall collect-bind
1664 ;; Return value in appropriate order of appearance.
1665 (nreverse (funcall collect-bind nil nil
)))))
1667 ;; defsubst org-export-get-parent must be defined before first use,
1668 ;; was originally defined in the topology section
1670 (defsubst org-export-get-parent
(blob)
1671 "Return BLOB parent or nil.
1672 BLOB is the element or object considered."
1673 (org-element-property :parent blob
))
1675 ;;;; Tree Properties
1677 ;; Tree properties are information extracted from parse tree. They
1678 ;; are initialized at the beginning of the transcoding process by
1679 ;; `org-export--collect-tree-properties'.
1681 ;; Dedicated functions focus on computing the value of specific tree
1682 ;; properties during initialization. Thus,
1683 ;; `org-export--populate-ignore-list' lists elements and objects that
1684 ;; should be skipped during export, `org-export--get-min-level' gets
1685 ;; the minimal exportable level, used as a basis to compute relative
1686 ;; level for headlines. Eventually
1687 ;; `org-export--collect-headline-numbering' builds an alist between
1688 ;; headlines and their numbering.
1690 (defun org-export--collect-tree-properties (data info
)
1691 "Extract tree properties from parse tree.
1693 DATA is the parse tree from which information is retrieved. INFO
1694 is a list holding export options.
1696 Following tree properties are set or updated:
1698 `:headline-offset' Offset between true level of headlines and
1699 local level. An offset of -1 means a headline
1700 of level 2 should be considered as a level
1701 1 headline in the context.
1703 `:headline-numbering' Alist of all headlines as key and the
1704 associated numbering as value.
1706 `:id-alist' Alist of all ID references as key and associated file
1709 Return updated plist."
1710 ;; Install the parse tree in the communication channel.
1711 (setq info
(plist-put info
:parse-tree data
))
1712 ;; Compute `:headline-offset' in order to be able to use
1713 ;; `org-export-get-relative-level'.
1717 (- 1 (org-export--get-min-level data info
))))
1718 ;; From now on, properties order doesn't matter: get the rest of the
1722 (list :headline-numbering
(org-export--collect-headline-numbering data info
)
1724 (org-element-map data
'link
1726 (and (string= (org-element-property :type l
) "id")
1727 (let* ((id (org-element-property :path l
))
1728 (file (car (org-id-find id
))))
1729 (and file
(cons id
(file-relative-name file
))))))))))
1731 (defun org-export--get-min-level (data options
)
1732 "Return minimum exportable headline's level in DATA.
1733 DATA is parsed tree as returned by `org-element-parse-buffer'.
1734 OPTIONS is a plist holding export options."
1736 (let ((min-level 10000))
1737 (dolist (datum (org-element-contents data
))
1738 (when (and (eq (org-element-type datum
) 'headline
)
1739 (not (org-element-property :footnote-section-p datum
))
1740 (not (memq datum
(plist-get options
:ignore-list
))))
1741 (setq min-level
(min (org-element-property :level datum
) min-level
))
1742 (when (= min-level
1) (throw 'exit
1))))
1743 ;; If no headline was found, for the sake of consistency, set
1744 ;; minimum level to 1 nonetheless.
1745 (if (= min-level
10000) 1 min-level
))))
1747 (defun org-export--collect-headline-numbering (data options
)
1748 "Return numbering of all exportable, numbered headlines in a parse tree.
1750 DATA is the parse tree. OPTIONS is the plist holding export
1753 Return an alist whose key is a headline and value is its
1754 associated numbering \(in the shape of a list of numbers) or nil
1755 for a footnotes section."
1756 (let ((numbering (make-vector org-export-max-depth
0)))
1757 (org-element-map data
'headline
1759 (when (and (org-export-numbered-headline-p headline options
)
1760 (not (org-element-property :footnote-section-p headline
)))
1761 (let ((relative-level
1762 (1- (org-export-get-relative-level headline options
))))
1766 for n across numbering
1767 for idx from
0 to org-export-max-depth
1768 when
(< idx relative-level
) collect n
1769 when
(= idx relative-level
) collect
(aset numbering idx
(1+ n
))
1770 when
(> idx relative-level
) do
(aset numbering idx
0))))))
1773 (defun org-export--selected-trees (data info
)
1774 "List headlines and inlinetasks with a select tag in their tree.
1775 DATA is parsed data as returned by `org-element-parse-buffer'.
1776 INFO is a plist holding export options."
1777 (letrec ((selected-trees)
1779 (lambda (data genealogy
)
1780 (let ((type (org-element-type data
)))
1782 ((memq type
'(headline inlinetask
))
1783 (let ((tags (org-element-property :tags data
)))
1784 (if (cl-loop for tag in
(plist-get info
:select-tags
)
1785 thereis
(member tag tags
))
1786 ;; When a select tag is found, mark full
1787 ;; genealogy and every headline within the
1788 ;; tree as acceptable.
1789 (setq selected-trees
1792 (org-element-map data
'(headline inlinetask
)
1795 ;; If at a headline, continue searching in tree,
1797 (when (eq type
'headline
)
1798 (dolist (el (org-element-contents data
))
1799 (funcall walk-data el
(cons data genealogy
)))))))
1800 ((or (eq type
'org-data
)
1801 (memq type org-element-greater-elements
))
1802 (dolist (el (org-element-contents data
))
1803 (funcall walk-data el genealogy
))))))))
1804 (funcall walk-data data nil
)
1807 (defun org-export--skip-p (blob options selected
)
1808 "Non-nil when element or object BLOB should be skipped during export.
1809 OPTIONS is the plist holding export options. SELECTED, when
1810 non-nil, is a list of headlines or inlinetasks belonging to
1811 a tree with a select tag."
1812 (cl-case (org-element-type blob
)
1813 (clock (not (plist-get options
:with-clocks
)))
1815 (let ((with-drawers-p (plist-get options
:with-drawers
)))
1816 (or (not with-drawers-p
)
1817 (and (consp with-drawers-p
)
1818 ;; If `:with-drawers' value starts with `not', ignore
1819 ;; every drawer whose name belong to that list.
1820 ;; Otherwise, ignore drawers whose name isn't in that
1822 (let ((name (org-element-property :drawer-name blob
)))
1823 (if (eq (car with-drawers-p
) 'not
)
1824 (member-ignore-case name
(cdr with-drawers-p
))
1825 (not (member-ignore-case name with-drawers-p
))))))))
1826 (fixed-width (not (plist-get options
:with-fixed-width
)))
1827 ((footnote-definition footnote-reference
)
1828 (not (plist-get options
:with-footnotes
)))
1829 ((headline inlinetask
)
1830 (let ((with-tasks (plist-get options
:with-tasks
))
1831 (todo (org-element-property :todo-keyword blob
))
1832 (todo-type (org-element-property :todo-type blob
))
1833 (archived (plist-get options
:with-archived-trees
))
1834 (tags (org-element-property :tags blob
)))
1836 (and (eq (org-element-type blob
) 'inlinetask
)
1837 (not (plist-get options
:with-inlinetasks
)))
1838 ;; Ignore subtrees with an exclude tag.
1839 (cl-loop for k in
(plist-get options
:exclude-tags
)
1840 thereis
(member k tags
))
1841 ;; When a select tag is present in the buffer, ignore any tree
1843 (and selected
(not (memq blob selected
)))
1844 ;; Ignore commented sub-trees.
1845 (org-element-property :commentedp blob
)
1846 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
1847 (and (not archived
) (org-element-property :archivedp blob
))
1848 ;; Ignore tasks, if specified by `:with-tasks' property.
1850 (or (not with-tasks
)
1851 (and (memq with-tasks
'(todo done
))
1852 (not (eq todo-type with-tasks
)))
1853 (and (consp with-tasks
) (not (member todo with-tasks
))))))))
1854 ((latex-environment latex-fragment
) (not (plist-get options
:with-latex
)))
1856 (let ((properties-set (plist-get options
:with-properties
)))
1857 (cond ((null properties-set
) t
)
1858 ((consp properties-set
)
1859 (not (member-ignore-case (org-element-property :key blob
)
1860 properties-set
))))))
1861 (planning (not (plist-get options
:with-planning
)))
1862 (property-drawer (not (plist-get options
:with-properties
)))
1863 (statistics-cookie (not (plist-get options
:with-statistics-cookies
)))
1864 (table (not (plist-get options
:with-tables
)))
1866 (and (org-export-table-has-special-column-p
1867 (org-export-get-parent-table blob
))
1868 (org-export-first-sibling-p blob options
)))
1869 (table-row (org-export-table-row-is-special-p blob options
))
1871 ;; `:with-timestamps' only applies to isolated timestamps
1872 ;; objects, i.e. timestamp objects in a paragraph containing only
1873 ;; timestamps and whitespaces.
1874 (when (let ((parent (org-export-get-parent-element blob
)))
1875 (and (memq (org-element-type parent
) '(paragraph verse-block
))
1876 (not (org-element-map parent
1878 (remq 'timestamp org-element-all-objects
))
1880 (or (not (stringp obj
)) (org-string-nw-p obj
)))
1882 (cl-case (plist-get options
:with-timestamps
)
1885 (not (memq (org-element-property :type blob
) '(active active-range
))))
1887 (not (memq (org-element-property :type blob
)
1888 '(inactive inactive-range
)))))))))
1893 ;; `org-export-data' reads a parse tree (obtained with, i.e.
1894 ;; `org-element-parse-buffer') and transcodes it into a specified
1895 ;; back-end output. It takes care of filtering out elements or
1896 ;; objects according to export options and organizing the output blank
1897 ;; lines and white space are preserved. The function memoizes its
1898 ;; results, so it is cheap to call it within transcoders.
1900 ;; It is possible to modify locally the back-end used by
1901 ;; `org-export-data' or even use a temporary back-end by using
1902 ;; `org-export-data-with-backend'.
1904 ;; `org-export-transcoder' is an accessor returning appropriate
1905 ;; translator function for a given element or object.
1907 (defun org-export-transcoder (blob info
)
1908 "Return appropriate transcoder for BLOB.
1909 INFO is a plist containing export directives."
1910 (let ((type (org-element-type blob
)))
1911 ;; Return contents only for complete parse trees.
1912 (if (eq type
'org-data
) (lambda (_datum contents _info
) contents
)
1913 (let ((transcoder (cdr (assq type
(plist-get info
:translate-alist
)))))
1914 (and (functionp transcoder
) transcoder
)))))
1916 (defun org-export-data (data info
)
1917 "Convert DATA into current back-end format.
1919 DATA is a parse tree, an element or an object or a secondary
1920 string. INFO is a plist holding export options.
1923 (or (gethash data
(plist-get info
:exported-data
))
1924 ;; Handle broken links according to
1925 ;; `org-export-with-broken-links'.
1927 ((broken-link-handler
1929 `(condition-case err
1932 (pcase (plist-get info
:with-broken-links
)
1933 (`nil
(user-error "Unable to resolve link: %S" (nth 1 err
)))
1934 (`mark
(org-export-data
1935 (format "[BROKEN LINK: %s]" (nth 1 err
)) info
))
1937 (let* ((type (org-element-type data
))
1940 ;; Ignored element/object.
1941 ((memq data
(plist-get info
:ignore-list
)) nil
)
1943 ((eq type
'plain-text
)
1944 (org-export-filter-apply-functions
1945 (plist-get info
:filter-plain-text
)
1946 (let ((transcoder (org-export-transcoder data info
)))
1947 (if transcoder
(funcall transcoder data info
) data
))
1949 ;; Secondary string.
1951 (mapconcat (lambda (obj) (org-export-data obj info
)) data
""))
1952 ;; Element/Object without contents or, as a special
1953 ;; case, headline with archive tag and archived trees
1954 ;; restricted to title only.
1955 ((or (not (org-element-contents data
))
1956 (and (eq type
'headline
)
1957 (eq (plist-get info
:with-archived-trees
) 'headline
)
1958 (org-element-property :archivedp data
)))
1959 (let ((transcoder (org-export-transcoder data info
)))
1960 (or (and (functionp transcoder
)
1961 (broken-link-handler
1962 (funcall transcoder data nil info
)))
1963 ;; Export snippets never return a nil value so
1964 ;; that white spaces following them are never
1966 (and (eq type
'export-snippet
) ""))))
1967 ;; Element/Object with contents.
1969 (let ((transcoder (org-export-transcoder data info
)))
1971 (let* ((greaterp (memq type org-element-greater-elements
))
1974 (memq type org-element-recursive-objects
)))
1977 (lambda (element) (org-export-data element info
))
1978 (org-element-contents
1979 (if (or greaterp objectp
) data
1980 ;; Elements directly containing
1981 ;; objects must have their indentation
1982 ;; normalized first.
1983 (org-element-normalize-contents
1985 ;; When normalizing contents of the
1986 ;; first paragraph in an item or
1987 ;; a footnote definition, ignore
1988 ;; first line's indentation: there is
1989 ;; none and it might be misleading.
1990 (when (eq type
'paragraph
)
1991 (let ((parent (org-export-get-parent data
)))
1993 (eq (car (org-element-contents parent
))
1995 (memq (org-element-type parent
)
1996 '(footnote-definition item
))))))))
1998 (broken-link-handler
1999 (funcall transcoder data
2000 (if (not greaterp
) contents
2001 (org-element-normalize-string contents
))
2003 ;; Final result will be memoized before being returned.
2008 ((memq type
'(org-data plain-text nil
)) results
)
2009 ;; Append the same white space between elements or objects
2010 ;; as in the original buffer, and call appropriate filters.
2013 (org-export-filter-apply-functions
2014 (plist-get info
(intern (format ":filter-%s" type
)))
2015 (let ((post-blank (or (org-element-property :post-blank data
)
2017 (if (memq type org-element-all-elements
)
2018 (concat (org-element-normalize-string results
)
2019 (make-string post-blank ?
\n))
2020 (concat results
(make-string post-blank ?\s
))))
2023 (plist-get info
:exported-data
))))))
2025 (defun org-export-data-with-backend (data backend info
)
2026 "Convert DATA into BACKEND format.
2028 DATA is an element, an object, a secondary string or a string.
2029 BACKEND is a symbol. INFO is a plist used as a communication
2032 Unlike to `org-export-with-backend', this function will
2033 recursively convert DATA using BACKEND translation table."
2034 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
2037 ;; Set-up a new communication channel with translations defined in
2038 ;; BACKEND as the translate table and a new hash table for
2042 (list :back-end backend
2043 :translate-alist
(org-export-get-all-transcoders backend
)
2044 ;; Size of the hash table is reduced since this function
2045 ;; will probably be used on small trees.
2046 :exported-data
(make-hash-table :test
'eq
:size
401)))))
2048 (defun org-export-expand (blob contents
&optional with-affiliated
)
2049 "Expand a parsed element or object to its original state.
2051 BLOB is either an element or an object. CONTENTS is its
2052 contents, as a string or nil.
2054 When optional argument WITH-AFFILIATED is non-nil, add affiliated
2055 keywords before output."
2056 (let ((type (org-element-type blob
)))
2057 (concat (and with-affiliated
(memq type org-element-all-elements
)
2058 (org-element--interpret-affiliated-keywords blob
))
2059 (funcall (intern (format "org-element-%s-interpreter" type
))
2064 ;;; The Filter System
2066 ;; Filters allow end-users to tweak easily the transcoded output.
2067 ;; They are the functional counterpart of hooks, as every filter in
2068 ;; a set is applied to the return value of the previous one.
2070 ;; Every set is back-end agnostic. Although, a filter is always
2071 ;; called, in addition to the string it applies to, with the back-end
2072 ;; used as argument, so it's easy for the end-user to add back-end
2073 ;; specific filters in the set. The communication channel, as
2074 ;; a plist, is required as the third argument.
2076 ;; From the developer side, filters sets can be installed in the
2077 ;; process with the help of `org-export-define-backend', which
2078 ;; internally stores filters as an alist. Each association has a key
2079 ;; among the following symbols and a function or a list of functions
2082 ;; - `:filter-options' applies to the property list containing export
2083 ;; options. Unlike to other filters, functions in this list accept
2084 ;; two arguments instead of three: the property list containing
2085 ;; export options and the back-end. Users can set its value through
2086 ;; `org-export-filter-options-functions' variable.
2088 ;; - `:filter-parse-tree' applies directly to the complete parsed
2089 ;; tree. Users can set it through
2090 ;; `org-export-filter-parse-tree-functions' variable.
2092 ;; - `:filter-body' applies to the body of the output, before template
2093 ;; translator chimes in. Users can set it through
2094 ;; `org-export-filter-body-functions' variable.
2096 ;; - `:filter-final-output' applies to the final transcoded string.
2097 ;; Users can set it with `org-export-filter-final-output-functions'
2100 ;; - `:filter-plain-text' applies to any string not recognized as Org
2101 ;; syntax. `org-export-filter-plain-text-functions' allows users to
2104 ;; - `:filter-TYPE' applies on the string returned after an element or
2105 ;; object of type TYPE has been transcoded. A user can modify
2106 ;; `org-export-filter-TYPE-functions' to install these filters.
2108 ;; All filters sets are applied with
2109 ;; `org-export-filter-apply-functions' function. Filters in a set are
2110 ;; applied in a LIFO fashion. It allows developers to be sure that
2111 ;; their filters will be applied first.
2113 ;; Filters properties are installed in communication channel with
2114 ;; `org-export-install-filters' function.
2116 ;; Eventually, two hooks (`org-export-before-processing-hook' and
2117 ;; `org-export-before-parsing-hook') are run at the beginning of the
2118 ;; export process and just before parsing to allow for heavy structure
2124 (defvar org-export-before-processing-hook nil
2125 "Hook run at the beginning of the export process.
2127 This is run before include keywords and macros are expanded and
2128 Babel code blocks executed, on a copy of the original buffer
2129 being exported. Visibility and narrowing are preserved. Point
2130 is at the beginning of the buffer.
2132 Every function in this hook will be called with one argument: the
2133 back-end currently used, as a symbol.")
2135 (defvar org-export-before-parsing-hook nil
2136 "Hook run before parsing an export buffer.
2138 This is run after include keywords and macros have been expanded
2139 and Babel code blocks executed, on a copy of the original buffer
2140 being exported. Visibility and narrowing are preserved. Point
2141 is at the beginning of the buffer.
2143 Every function in this hook will be called with one argument: the
2144 back-end currently used, as a symbol.")
2147 ;;;; Special Filters
2149 (defvar org-export-filter-options-functions nil
2150 "List of functions applied to the export options.
2151 Each filter is called with two arguments: the export options, as
2152 a plist, and the back-end, as a symbol. It must return
2153 a property list containing export options.")
2155 (defvar org-export-filter-parse-tree-functions nil
2156 "List of functions applied to the parsed tree.
2157 Each filter is called with three arguments: the parse tree, as
2158 returned by `org-element-parse-buffer', the back-end, as
2159 a symbol, and the communication channel, as a plist. It must
2160 return the modified parse tree to transcode.")
2162 (defvar org-export-filter-plain-text-functions nil
2163 "List of functions applied to plain text.
2164 Each filter is called with three arguments: a string which
2165 contains no Org syntax, the back-end, as a symbol, and the
2166 communication channel, as a plist. It must return a string or
2169 (defvar org-export-filter-body-functions nil
2170 "List of functions applied to transcoded body.
2171 Each filter is called with three arguments: a string which
2172 contains no Org syntax, the back-end, as a symbol, and the
2173 communication channel, as a plist. It must return a string or
2176 (defvar org-export-filter-final-output-functions nil
2177 "List of functions applied to the transcoded string.
2178 Each filter is called with three arguments: the full transcoded
2179 string, the back-end, as a symbol, and the communication channel,
2180 as a plist. It must return a string that will be used as the
2181 final export output.")
2184 ;;;; Elements Filters
2186 (defvar org-export-filter-babel-call-functions nil
2187 "List of functions applied to a transcoded babel-call.
2188 Each filter is called with three arguments: the transcoded data,
2189 as a string, the back-end, as a symbol, and the communication
2190 channel, as a plist. It must return a string or nil.")
2192 (defvar org-export-filter-center-block-functions nil
2193 "List of functions applied to a transcoded center block.
2194 Each filter is called with three arguments: the transcoded data,
2195 as a string, the back-end, as a symbol, and the communication
2196 channel, as a plist. It must return a string or nil.")
2198 (defvar org-export-filter-clock-functions nil
2199 "List of functions applied to a transcoded clock.
2200 Each filter is called with three arguments: the transcoded data,
2201 as a string, the back-end, as a symbol, and the communication
2202 channel, as a plist. It must return a string or nil.")
2204 (defvar org-export-filter-diary-sexp-functions nil
2205 "List of functions applied to a transcoded diary-sexp.
2206 Each filter is called with three arguments: the transcoded data,
2207 as a string, the back-end, as a symbol, and the communication
2208 channel, as a plist. It must return a string or nil.")
2210 (defvar org-export-filter-drawer-functions nil
2211 "List of functions applied to a transcoded drawer.
2212 Each filter is called with three arguments: the transcoded data,
2213 as a string, the back-end, as a symbol, and the communication
2214 channel, as a plist. It must return a string or nil.")
2216 (defvar org-export-filter-dynamic-block-functions nil
2217 "List of functions applied to a transcoded dynamic-block.
2218 Each filter is called with three arguments: the transcoded data,
2219 as a string, the back-end, as a symbol, and the communication
2220 channel, as a plist. It must return a string or nil.")
2222 (defvar org-export-filter-example-block-functions nil
2223 "List of functions applied to a transcoded example-block.
2224 Each filter is called with three arguments: the transcoded data,
2225 as a string, the back-end, as a symbol, and the communication
2226 channel, as a plist. It must return a string or nil.")
2228 (defvar org-export-filter-export-block-functions nil
2229 "List of functions applied to a transcoded export-block.
2230 Each filter is called with three arguments: the transcoded data,
2231 as a string, the back-end, as a symbol, and the communication
2232 channel, as a plist. It must return a string or nil.")
2234 (defvar org-export-filter-fixed-width-functions nil
2235 "List of functions applied to a transcoded fixed-width.
2236 Each filter is called with three arguments: the transcoded data,
2237 as a string, the back-end, as a symbol, and the communication
2238 channel, as a plist. It must return a string or nil.")
2240 (defvar org-export-filter-footnote-definition-functions nil
2241 "List of functions applied to a transcoded footnote-definition.
2242 Each filter is called with three arguments: the transcoded data,
2243 as a string, the back-end, as a symbol, and the communication
2244 channel, as a plist. It must return a string or nil.")
2246 (defvar org-export-filter-headline-functions nil
2247 "List of functions applied to a transcoded headline.
2248 Each filter is called with three arguments: the transcoded data,
2249 as a string, the back-end, as a symbol, and the communication
2250 channel, as a plist. It must return a string or nil.")
2252 (defvar org-export-filter-horizontal-rule-functions nil
2253 "List of functions applied to a transcoded horizontal-rule.
2254 Each filter is called with three arguments: the transcoded data,
2255 as a string, the back-end, as a symbol, and the communication
2256 channel, as a plist. It must return a string or nil.")
2258 (defvar org-export-filter-inlinetask-functions nil
2259 "List of functions applied to a transcoded inlinetask.
2260 Each filter is called with three arguments: the transcoded data,
2261 as a string, the back-end, as a symbol, and the communication
2262 channel, as a plist. It must return a string or nil.")
2264 (defvar org-export-filter-item-functions nil
2265 "List of functions applied to a transcoded item.
2266 Each filter is called with three arguments: the transcoded data,
2267 as a string, the back-end, as a symbol, and the communication
2268 channel, as a plist. It must return a string or nil.")
2270 (defvar org-export-filter-keyword-functions nil
2271 "List of functions applied to a transcoded keyword.
2272 Each filter is called with three arguments: the transcoded data,
2273 as a string, the back-end, as a symbol, and the communication
2274 channel, as a plist. It must return a string or nil.")
2276 (defvar org-export-filter-latex-environment-functions nil
2277 "List of functions applied to a transcoded latex-environment.
2278 Each filter is called with three arguments: the transcoded data,
2279 as a string, the back-end, as a symbol, and the communication
2280 channel, as a plist. It must return a string or nil.")
2282 (defvar org-export-filter-node-property-functions nil
2283 "List of functions applied to a transcoded node-property.
2284 Each filter is called with three arguments: the transcoded data,
2285 as a string, the back-end, as a symbol, and the communication
2286 channel, as a plist. It must return a string or nil.")
2288 (defvar org-export-filter-paragraph-functions nil
2289 "List of functions applied to a transcoded paragraph.
2290 Each filter is called with three arguments: the transcoded data,
2291 as a string, the back-end, as a symbol, and the communication
2292 channel, as a plist. It must return a string or nil.")
2294 (defvar org-export-filter-plain-list-functions nil
2295 "List of functions applied to a transcoded plain-list.
2296 Each filter is called with three arguments: the transcoded data,
2297 as a string, the back-end, as a symbol, and the communication
2298 channel, as a plist. It must return a string or nil.")
2300 (defvar org-export-filter-planning-functions nil
2301 "List of functions applied to a transcoded planning.
2302 Each filter is called with three arguments: the transcoded data,
2303 as a string, the back-end, as a symbol, and the communication
2304 channel, as a plist. It must return a string or nil.")
2306 (defvar org-export-filter-property-drawer-functions nil
2307 "List of functions applied to a transcoded property-drawer.
2308 Each filter is called with three arguments: the transcoded data,
2309 as a string, the back-end, as a symbol, and the communication
2310 channel, as a plist. It must return a string or nil.")
2312 (defvar org-export-filter-quote-block-functions nil
2313 "List of functions applied to a transcoded quote block.
2314 Each filter is called with three arguments: the transcoded quote
2315 data, as a string, the back-end, as a symbol, and the
2316 communication channel, as a plist. It must return a string or
2319 (defvar org-export-filter-section-functions nil
2320 "List of functions applied to a transcoded section.
2321 Each filter is called with three arguments: the transcoded data,
2322 as a string, the back-end, as a symbol, and the communication
2323 channel, as a plist. It must return a string or nil.")
2325 (defvar org-export-filter-special-block-functions nil
2326 "List of functions applied to a transcoded special block.
2327 Each filter is called with three arguments: the transcoded data,
2328 as a string, the back-end, as a symbol, and the communication
2329 channel, as a plist. It must return a string or nil.")
2331 (defvar org-export-filter-src-block-functions nil
2332 "List of functions applied to a transcoded src-block.
2333 Each filter is called with three arguments: the transcoded data,
2334 as a string, the back-end, as a symbol, and the communication
2335 channel, as a plist. It must return a string or nil.")
2337 (defvar org-export-filter-table-functions nil
2338 "List of functions applied to a transcoded table.
2339 Each filter is called with three arguments: the transcoded data,
2340 as a string, the back-end, as a symbol, and the communication
2341 channel, as a plist. It must return a string or nil.")
2343 (defvar org-export-filter-table-cell-functions nil
2344 "List of functions applied to a transcoded table-cell.
2345 Each filter is called with three arguments: the transcoded data,
2346 as a string, the back-end, as a symbol, and the communication
2347 channel, as a plist. It must return a string or nil.")
2349 (defvar org-export-filter-table-row-functions nil
2350 "List of functions applied to a transcoded table-row.
2351 Each filter is called with three arguments: the transcoded data,
2352 as a string, the back-end, as a symbol, and the communication
2353 channel, as a plist. It must return a string or nil.")
2355 (defvar org-export-filter-verse-block-functions nil
2356 "List of functions applied to a transcoded verse block.
2357 Each filter is called with three arguments: the transcoded data,
2358 as a string, the back-end, as a symbol, and the communication
2359 channel, as a plist. It must return a string or nil.")
2362 ;;;; Objects Filters
2364 (defvar org-export-filter-bold-functions nil
2365 "List of functions applied to transcoded bold text.
2366 Each filter is called with three arguments: the transcoded data,
2367 as a string, the back-end, as a symbol, and the communication
2368 channel, as a plist. It must return a string or nil.")
2370 (defvar org-export-filter-code-functions nil
2371 "List of functions applied to transcoded code text.
2372 Each filter is called with three arguments: the transcoded data,
2373 as a string, the back-end, as a symbol, and the communication
2374 channel, as a plist. It must return a string or nil.")
2376 (defvar org-export-filter-entity-functions nil
2377 "List of functions applied to a transcoded entity.
2378 Each filter is called with three arguments: the transcoded data,
2379 as a string, the back-end, as a symbol, and the communication
2380 channel, as a plist. It must return a string or nil.")
2382 (defvar org-export-filter-export-snippet-functions nil
2383 "List of functions applied to a transcoded export-snippet.
2384 Each filter is called with three arguments: the transcoded data,
2385 as a string, the back-end, as a symbol, and the communication
2386 channel, as a plist. It must return a string or nil.")
2388 (defvar org-export-filter-footnote-reference-functions nil
2389 "List of functions applied to a transcoded footnote-reference.
2390 Each filter is called with three arguments: the transcoded data,
2391 as a string, the back-end, as a symbol, and the communication
2392 channel, as a plist. It must return a string or nil.")
2394 (defvar org-export-filter-inline-babel-call-functions nil
2395 "List of functions applied to a transcoded inline-babel-call.
2396 Each filter is called with three arguments: the transcoded data,
2397 as a string, the back-end, as a symbol, and the communication
2398 channel, as a plist. It must return a string or nil.")
2400 (defvar org-export-filter-inline-src-block-functions nil
2401 "List of functions applied to a transcoded inline-src-block.
2402 Each filter is called with three arguments: the transcoded data,
2403 as a string, the back-end, as a symbol, and the communication
2404 channel, as a plist. It must return a string or nil.")
2406 (defvar org-export-filter-italic-functions nil
2407 "List of functions applied to transcoded italic text.
2408 Each filter is called with three arguments: the transcoded data,
2409 as a string, the back-end, as a symbol, and the communication
2410 channel, as a plist. It must return a string or nil.")
2412 (defvar org-export-filter-latex-fragment-functions nil
2413 "List of functions applied to a transcoded latex-fragment.
2414 Each filter is called with three arguments: the transcoded data,
2415 as a string, the back-end, as a symbol, and the communication
2416 channel, as a plist. It must return a string or nil.")
2418 (defvar org-export-filter-line-break-functions nil
2419 "List of functions applied to a transcoded line-break.
2420 Each filter is called with three arguments: the transcoded data,
2421 as a string, the back-end, as a symbol, and the communication
2422 channel, as a plist. It must return a string or nil.")
2424 (defvar org-export-filter-link-functions nil
2425 "List of functions applied to a transcoded link.
2426 Each filter is called with three arguments: the transcoded data,
2427 as a string, the back-end, as a symbol, and the communication
2428 channel, as a plist. It must return a string or nil.")
2430 (defvar org-export-filter-radio-target-functions nil
2431 "List of functions applied to a transcoded radio-target.
2432 Each filter is called with three arguments: the transcoded data,
2433 as a string, the back-end, as a symbol, and the communication
2434 channel, as a plist. It must return a string or nil.")
2436 (defvar org-export-filter-statistics-cookie-functions nil
2437 "List of functions applied to a transcoded statistics-cookie.
2438 Each filter is called with three arguments: the transcoded data,
2439 as a string, the back-end, as a symbol, and the communication
2440 channel, as a plist. It must return a string or nil.")
2442 (defvar org-export-filter-strike-through-functions nil
2443 "List of functions applied to transcoded strike-through text.
2444 Each filter is called with three arguments: the transcoded data,
2445 as a string, the back-end, as a symbol, and the communication
2446 channel, as a plist. It must return a string or nil.")
2448 (defvar org-export-filter-subscript-functions nil
2449 "List of functions applied to a transcoded subscript.
2450 Each filter is called with three arguments: the transcoded data,
2451 as a string, the back-end, as a symbol, and the communication
2452 channel, as a plist. It must return a string or nil.")
2454 (defvar org-export-filter-superscript-functions nil
2455 "List of functions applied to a transcoded superscript.
2456 Each filter is called with three arguments: the transcoded data,
2457 as a string, the back-end, as a symbol, and the communication
2458 channel, as a plist. It must return a string or nil.")
2460 (defvar org-export-filter-target-functions nil
2461 "List of functions applied to a transcoded target.
2462 Each filter is called with three arguments: the transcoded data,
2463 as a string, the back-end, as a symbol, and the communication
2464 channel, as a plist. It must return a string or nil.")
2466 (defvar org-export-filter-timestamp-functions nil
2467 "List of functions applied to a transcoded timestamp.
2468 Each filter is called with three arguments: the transcoded data,
2469 as a string, the back-end, as a symbol, and the communication
2470 channel, as a plist. It must return a string or nil.")
2472 (defvar org-export-filter-underline-functions nil
2473 "List of functions applied to transcoded underline text.
2474 Each filter is called with three arguments: the transcoded data,
2475 as a string, the back-end, as a symbol, and the communication
2476 channel, as a plist. It must return a string or nil.")
2478 (defvar org-export-filter-verbatim-functions nil
2479 "List of functions applied to transcoded verbatim text.
2480 Each filter is called with three arguments: the transcoded data,
2481 as a string, the back-end, as a symbol, and the communication
2482 channel, as a plist. It must return a string or nil.")
2487 ;; Internal function `org-export-install-filters' installs filters
2488 ;; hard-coded in back-ends (developer filters) and filters from global
2489 ;; variables (user filters) in the communication channel.
2491 ;; Internal function `org-export-filter-apply-functions' takes care
2492 ;; about applying each filter in order to a given data. It ignores
2493 ;; filters returning a nil value but stops whenever a filter returns
2496 (defun org-export-filter-apply-functions (filters value info
)
2497 "Call every function in FILTERS.
2499 Functions are called with arguments VALUE, current export
2500 back-end's name and INFO. A function returning a nil value will
2501 be skipped. If it returns the empty string, the process ends and
2504 Call is done in a LIFO fashion, to be sure that developer
2505 specified filters, if any, are called first."
2507 (let* ((backend (plist-get info
:back-end
))
2508 (backend-name (and backend
(org-export-backend-name backend
))))
2509 (dolist (filter filters value
)
2510 (let ((result (funcall filter value backend-name info
)))
2511 (cond ((not result
) value
)
2512 ((equal value
"") (throw 'exit nil
))
2513 (t (setq value result
))))))))
2515 (defun org-export-install-filters (info)
2516 "Install filters properties in communication channel.
2517 INFO is a plist containing the current communication channel.
2518 Return the updated communication channel."
2520 ;; Install user-defined filters with `org-export-filters-alist'
2521 ;; and filters already in INFO (through ext-plist mechanism).
2522 (dolist (p org-export-filters-alist
)
2523 (let* ((prop (car p
))
2524 (info-value (plist-get info prop
))
2525 (default-value (symbol-value (cdr p
))))
2527 (plist-put plist prop
2528 ;; Filters in INFO will be called
2529 ;; before those user provided.
2530 (append (if (listp info-value
) info-value
2533 ;; Prepend back-end specific filters to that list.
2534 (dolist (p (org-export-get-all-filters (plist-get info
:back-end
)))
2535 ;; Single values get consed, lists are appended.
2536 (let ((key (car p
)) (value (cdr p
)))
2541 (if (atom value
) (cons value
(plist-get plist key
))
2542 (append value
(plist-get plist key
))))))))
2543 ;; Return new communication channel.
2544 (org-combine-plists info plist
)))
2550 ;; This is the room for the main function, `org-export-as', along with
2551 ;; its derivative, `org-export-string-as'.
2552 ;; `org-export--copy-to-kill-ring-p' determines if output of these
2553 ;; function should be added to kill ring.
2555 ;; Note that `org-export-as' doesn't really parse the current buffer,
2556 ;; but a copy of it (with the same buffer-local variables and
2557 ;; visibility), where macros and include keywords are expanded and
2558 ;; Babel blocks are executed, if appropriate.
2559 ;; `org-export-with-buffer-copy' macro prepares that copy.
2561 ;; File inclusion is taken care of by
2562 ;; `org-export-expand-include-keyword' and
2563 ;; `org-export--prepare-file-contents'. Structure wise, including
2564 ;; a whole Org file in a buffer often makes little sense. For
2565 ;; example, if the file contains a headline and the include keyword
2566 ;; was within an item, the item should contain the headline. That's
2567 ;; why file inclusion should be done before any structure can be
2568 ;; associated to the file, that is before parsing.
2570 ;; `org-export-insert-default-template' is a command to insert
2571 ;; a default template (or a back-end specific template) at point or in
2574 (defun org-export-copy-buffer ()
2575 "Return a copy of the current buffer.
2576 The copy preserves Org buffer-local variables, visibility and
2578 (let ((copy-buffer-fun (org-export--generate-copy-script (current-buffer)))
2579 (new-buf (generate-new-buffer (buffer-name))))
2580 (with-current-buffer new-buf
2581 (funcall copy-buffer-fun
)
2582 (set-buffer-modified-p nil
))
2585 (defmacro org-export-with-buffer-copy
(&rest body
)
2586 "Apply BODY in a copy of the current buffer.
2587 The copy preserves local variables, visibility and contents of
2588 the original buffer. Point is at the beginning of the buffer
2589 when BODY is applied."
2591 (org-with-gensyms (buf-copy)
2592 `(let ((,buf-copy
(org-export-copy-buffer)))
2594 (with-current-buffer ,buf-copy
2595 (goto-char (point-min))
2597 (and (buffer-live-p ,buf-copy
)
2598 ;; Kill copy without confirmation.
2599 (progn (with-current-buffer ,buf-copy
2600 (restore-buffer-modified-p nil
))
2601 (kill-buffer ,buf-copy
)))))))
2603 (defun org-export--generate-copy-script (buffer)
2604 "Generate a function duplicating BUFFER.
2606 The copy will preserve local variables, visibility, contents and
2607 narrowing of the original buffer. If a region was active in
2608 BUFFER, contents will be narrowed to that region instead.
2610 The resulting function can be evaluated at a later time, from
2611 another buffer, effectively cloning the original buffer there.
2613 The function assumes BUFFER's major mode is `org-mode'."
2614 (with-current-buffer buffer
2616 (let ((inhibit-modification-hooks t
))
2617 ;; Set major mode. Ignore `org-mode-hook' as it has been run
2618 ;; already in BUFFER.
2619 (let ((org-mode-hook nil
) (org-inhibit-startup t
)) (org-mode))
2620 ;; Copy specific buffer local variables and variables set
2621 ;; through BIND keywords.
2622 ,@(let ((bound-variables (org-export--list-bound-variables))
2624 (dolist (entry (buffer-local-variables (buffer-base-buffer)) vars
)
2626 (let ((var (car entry
))
2628 (and (not (memq var org-export-ignored-local-variables
))
2632 buffer-file-coding-system
))
2633 (assq var bound-variables
)
2634 (string-match "^\\(org-\\|orgtbl-\\)"
2636 ;; Skip unreadable values, as they cannot be
2637 ;; sent to external process.
2638 (or (not val
) (ignore-errors (read (format "%S" val
))))
2639 (push `(set (make-local-variable (quote ,var
))
2642 ;; Whole buffer contents.
2644 ,(org-with-wide-buffer
2645 (buffer-substring-no-properties
2646 (point-min) (point-max))))
2648 ,(if (org-region-active-p)
2649 `(narrow-to-region ,(region-beginning) ,(region-end))
2650 `(narrow-to-region ,(point-min) ,(point-max)))
2651 ;; Current position of point.
2652 (goto-char ,(point))
2653 ;; Overlays with invisible property.
2655 (dolist (ov (overlays-in (point-min) (point-max)) ov-set
)
2656 (let ((invis-prop (overlay-get ov
'invisible
)))
2659 (make-overlay ,(overlay-start ov
)
2661 'invisible
(quote ,invis-prop
))
2664 (defun org-export--delete-comments ()
2665 "Delete commented areas in the buffer.
2666 Commented areas are comments, comment blocks, commented trees and
2667 inlinetasks. Trailing blank lines after a comment or a comment
2668 block are preserved. Narrowing, if any, is ignored."
2669 (org-with-wide-buffer
2670 (goto-char (point-min))
2671 (let ((regexp (concat org-outline-regexp-bol
".*" org-comment-string
2673 "^[ \t]*#\\(?: \\|$\\|\\+begin_comment\\)"))
2674 (case-fold-search t
))
2675 (while (re-search-forward regexp nil t
)
2676 (let ((e (org-element-at-point)))
2677 (cl-case (org-element-type e
)
2678 ((comment comment-block
)
2679 (delete-region (org-element-property :begin e
)
2680 (progn (goto-char (org-element-property :end e
))
2681 (skip-chars-backward " \r\t\n")
2682 (line-beginning-position 2))))
2683 ((headline inlinetask
)
2684 (when (org-element-property :commentedp e
)
2685 (delete-region (org-element-property :begin e
)
2686 (org-element-property :end e
))))))))))
2688 (defun org-export--prune-tree (data info
)
2689 "Prune non exportable elements from DATA.
2690 DATA is the parse tree to traverse. INFO is the plist holding
2691 export info. Also set `:ignore-list' in INFO to a list of
2692 objects which should be ignored during export, but not removed
2695 ;; First find trees containing a select tag, if any.
2696 (selected (org-export--selected-trees data info
))
2699 ;; Prune non-exportable elements and objects from tree.
2700 ;; As a special case, special rows and cells from tables
2701 ;; are stored in IGNORE, as they still need to be
2702 ;; accessed during export.
2704 (let ((type (org-element-type data
)))
2705 (if (org-export--skip-p data info selected
)
2706 (if (memq type
'(table-cell table-row
)) (push data ignore
)
2707 (org-element-extract-element data
))
2708 (if (and (eq type
'headline
)
2709 (eq (plist-get info
:with-archived-trees
)
2711 (org-element-property :archivedp data
))
2712 ;; If headline is archived but tree below has
2713 ;; to be skipped, remove contents.
2714 (org-element-set-contents data
)
2715 ;; Move into recursive objects/elements.
2716 (mapc walk-data
(org-element-contents data
)))
2717 ;; Move into secondary string, if any.
2718 (dolist (p (cdr (assq type
2719 org-element-secondary-value-alist
)))
2720 (mapc walk-data
(org-element-property p data
)))))))))
2721 ;; If a select tag is active, also ignore the section before the
2722 ;; first headline, if any.
2724 (let ((first-element (car (org-element-contents data
))))
2725 (when (eq (org-element-type first-element
) 'section
)
2726 (org-element-extract-element first-element
))))
2727 ;; Prune tree and communication channel.
2728 (funcall walk-data data
)
2731 ;; Priority is given to back-end specific options.
2732 (org-export-get-all-options (plist-get info
:back-end
))
2733 org-export-options-alist
))
2734 (when (eq (nth 4 entry
) 'parse
)
2735 (funcall walk-data
(plist-get info
(car entry
)))))
2736 ;; Eventually set `:ignore-list'.
2737 (plist-put info
:ignore-list ignore
)))
2739 (defun org-export--remove-uninterpreted-data (data info
)
2740 "Change uninterpreted elements back into Org syntax.
2741 DATA is the parse tree. INFO is a plist containing export
2742 options. Each uninterpreted element or object is changed back
2743 into a string. Contents, if any, are not modified. The parse
2744 tree is modified by side effect."
2745 (org-export--remove-uninterpreted-data-1 data info
)
2746 (dolist (entry org-export-options-alist
)
2747 (when (eq (nth 4 entry
) 'parse
)
2748 (let ((p (car entry
)))
2751 (org-export--remove-uninterpreted-data-1
2755 (defun org-export--remove-uninterpreted-data-1 (data info
)
2756 "Change uninterpreted elements back into Org syntax.
2757 DATA is a parse tree or a secondary string. INFO is a plist
2758 containing export options. It is modified by side effect and
2759 returned by the function."
2760 (org-element-map data
2761 '(entity bold italic latex-environment latex-fragment strike-through
2762 subscript superscript underline
)
2765 (cl-case (org-element-type blob
)
2768 (and (not (plist-get info
:with-entities
))
2770 (org-export-expand blob nil
)
2772 (or (org-element-property :post-blank blob
) 0)
2775 ((bold italic strike-through underline
)
2776 (and (not (plist-get info
:with-emphasize
))
2777 (let ((marker (cl-case (org-element-type blob
)
2780 (strike-through "+")
2784 (org-element-contents blob
)
2788 (or (org-element-property :post-blank blob
)
2791 ;; ... LaTeX environments and fragments...
2792 ((latex-environment latex-fragment
)
2793 (and (eq (plist-get info
:with-latex
) 'verbatim
)
2794 (list (org-export-expand blob nil
))))
2795 ;; ... sub/superscripts...
2796 ((subscript superscript
)
2797 (let ((sub/super-p
(plist-get info
:with-sub-superscript
))
2798 (bracketp (org-element-property :use-brackets-p blob
)))
2799 (and (or (not sub
/super-p
)
2800 (and (eq sub
/super-p
'{}) (not bracketp
)))
2803 (if (eq (org-element-type blob
) 'subscript
)
2806 (and bracketp
"{")))
2807 (org-element-contents blob
)
2810 (and (org-element-property :post-blank blob
)
2812 (org-element-property :post-blank blob
)
2815 ;; Splice NEW at BLOB location in parse tree.
2816 (dolist (e new
(org-element-extract-element blob
))
2817 (unless (string= e
"") (org-element-insert-before e blob
))))))
2819 ;; Return modified parse tree.
2822 (defun org-export--merge-external-footnote-definitions (tree)
2823 "Insert footnote definitions outside parsing scope in TREE.
2825 If there is a footnote section in TREE, definitions found are
2826 appended to it. If `org-footnote-section' is non-nil, a new
2827 footnote section containing all definitions is inserted in TREE.
2828 Otherwise, definitions are appended at the end of the section
2829 containing their first reference.
2831 Only definitions actually referred to within TREE, directly or
2832 not, are considered."
2833 (let* ((collect-labels
2835 (org-element-map data
'footnote-reference
2837 (and (eq (org-element-property :type f
) 'standard
)
2838 (org-element-property :label f
))))))
2839 (referenced-labels (funcall collect-labels tree
)))
2840 (when referenced-labels
2841 (let* ((definitions)
2844 (cl-case (org-element-type datum
)
2845 (footnote-definition
2846 (push (save-restriction
2847 (narrow-to-region (org-element-property :begin datum
)
2848 (org-element-property :end datum
))
2849 (org-element-map (org-element-parse-buffer)
2850 'footnote-definition
#'identity nil t
))
2853 (let ((label (org-element-property :label datum
))
2854 (cbeg (org-element-property :contents-begin datum
)))
2855 (when (and label cbeg
2856 (eq (org-element-property :type datum
) 'inline
))
2858 (apply #'org-element-create
2859 'footnote-definition
2860 (list :label label
:post-blank
1)
2861 (org-element-parse-secondary-string
2863 cbeg
(org-element-property :contents-end datum
))
2864 (org-element-restriction 'footnote-reference
)))
2866 ;; Collect all out of scope definitions.
2868 (goto-char (point-min))
2869 (org-with-wide-buffer
2870 (while (re-search-backward org-footnote-re nil t
)
2871 (funcall push-definition
(org-element-context))))
2872 (goto-char (point-max))
2873 (org-with-wide-buffer
2874 (while (re-search-forward org-footnote-re nil t
)
2875 (funcall push-definition
(org-element-context)))))
2876 ;; Filter out definitions referenced neither in the original
2877 ;; tree nor in the external definitions.
2878 (let* ((directly-referenced
2881 (member (org-element-property :label d
) referenced-labels
))
2884 (append (funcall collect-labels directly-referenced
)
2885 referenced-labels
)))
2889 (member (org-element-property :label d
) all-labels
))
2891 ;; Install definitions in subtree.
2893 ((null definitions
))
2894 ;; If there is a footnote section, insert them here.
2895 ((let ((footnote-section
2896 (org-element-map tree
'headline
2898 (and (org-element-property :footnote-section-p h
) h
))
2900 (and footnote-section
2901 (apply #'org-element-adopt-elements
(nreverse definitions
)))))
2902 ;; If there should be a footnote section, create one containing
2903 ;; all the definitions at the end of the tree.
2904 (org-footnote-section
2905 (org-element-adopt-elements
2907 (org-element-create 'headline
2908 (list :footnote-section-p t
2910 :title org-footnote-section
)
2911 (apply #'org-element-create
2914 (nreverse definitions
)))))
2915 ;; Otherwise add each definition at the end of the section where
2916 ;; it is first referenced.
2921 ;; Insert definitions in the same section as
2922 ;; their first reference in DATA.
2923 (org-element-map data
'footnote-reference
2925 (when (eq (org-element-property :type f
) 'standard
)
2926 (let ((label (org-element-property :label f
)))
2927 (unless (member label seen
)
2931 (dolist (d definitions
)
2933 (org-element-property :label
2937 (delete d definitions
))
2938 (throw 'found d
))))))
2940 (org-element-adopt-elements
2941 (org-element-lineage f
'(section))
2943 (funcall insert-definitions
2944 definition
)))))))))))
2945 (funcall insert-definitions tree
))))))))
2948 (defun org-export-as
2949 (backend &optional subtreep visible-only body-only ext-plist
)
2950 "Transcode current Org buffer into BACKEND code.
2952 BACKEND is either an export back-end, as returned by, e.g.,
2953 `org-export-create-backend', or a symbol referring to
2954 a registered back-end.
2956 If narrowing is active in the current buffer, only transcode its
2959 If a region is active, transcode that region.
2961 When optional argument SUBTREEP is non-nil, transcode the
2962 sub-tree at point, extracting information from the headline
2965 When optional argument VISIBLE-ONLY is non-nil, don't export
2966 contents of hidden elements.
2968 When optional argument BODY-ONLY is non-nil, only return body
2969 code, without surrounding template.
2971 Optional argument EXT-PLIST, when provided, is a property list
2972 with external parameters overriding Org default settings, but
2973 still inferior to file-local settings.
2975 Return code as a string."
2976 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
2977 (org-export-barf-if-invalid-backend backend
)
2980 ;; Narrow buffer to an appropriate region or subtree for
2981 ;; parsing. If parsing subtree, be sure to remove main headline
2983 (cond ((org-region-active-p)
2984 (narrow-to-region (region-beginning) (region-end)))
2986 (org-narrow-to-subtree)
2987 (goto-char (point-min))
2989 (narrow-to-region (point) (point-max))))
2990 ;; Initialize communication channel with original buffer
2991 ;; attributes, unavailable in its copy.
2992 (let* ((org-export-current-backend (org-export-backend-name backend
))
2993 (info (org-combine-plists
2994 (org-export--get-export-attributes
2995 backend subtreep visible-only body-only
)
2996 (org-export--get-buffer-attributes)))
2999 (mapcar (lambda (o) (and (eq (nth 4 o
) 'parse
) (nth 1 o
)))
3000 (append (org-export-get-all-options backend
)
3001 org-export-options-alist
))))
3003 ;; Update communication channel and get parse tree. Buffer
3004 ;; isn't parsed directly. Instead, all buffer modifications
3005 ;; and consequent parsing are undertaken in a temporary copy.
3006 (org-export-with-buffer-copy
3007 ;; Run first hook with current back-end's name as argument.
3008 (run-hook-with-args 'org-export-before-processing-hook
3009 (org-export-backend-name backend
))
3010 ;; Include files, delete comments and expand macros.
3011 (org-export-expand-include-keyword)
3012 (org-export--delete-comments)
3013 (org-macro-initialize-templates)
3014 (org-macro-replace-all org-macro-templates nil parsed-keywords
)
3015 ;; Refresh buffer properties and radio targets after
3016 ;; potentially invasive previous changes. Likewise, do it
3017 ;; again after executing Babel code.
3018 (org-set-regexps-and-options)
3019 (org-update-radio-target-regexp)
3020 (org-export-execute-babel-code)
3021 (org-set-regexps-and-options)
3022 (org-update-radio-target-regexp)
3023 ;; Run last hook with current back-end's name as argument.
3024 ;; Update buffer properties and radio targets one last time
3026 (goto-char (point-min))
3028 (run-hook-with-args 'org-export-before-parsing-hook
3029 (org-export-backend-name backend
)))
3030 (org-set-regexps-and-options)
3031 (org-update-radio-target-regexp)
3032 ;; Update communication channel with environment. Also
3033 ;; install user's and developer's filters.
3035 (org-export-install-filters
3037 info
(org-export-get-environment backend subtreep ext-plist
))))
3038 ;; Call options filters and update export options. We do not
3039 ;; use `org-export-filter-apply-functions' here since the
3040 ;; arity of such filters is different.
3041 (let ((backend-name (org-export-backend-name backend
)))
3042 (dolist (filter (plist-get info
:filter-options
))
3043 (let ((result (funcall filter info backend-name
)))
3044 (when result
(setq info result
)))))
3045 ;; Expand export-specific set of macros: {{{author}}},
3046 ;; {{{date(FORMAT)}}}, {{{email}}} and {{{title}}}. It must
3047 ;; be done once regular macros have been expanded, since
3048 ;; parsed keywords may contain one of them.
3049 (org-macro-replace-all
3051 (cons "author" (org-element-interpret-data (plist-get info
:author
)))
3053 (let* ((date (plist-get info
:date
))
3054 (value (or (org-element-interpret-data date
) "")))
3055 (if (and (consp date
)
3057 (eq (org-element-type (car date
)) 'timestamp
))
3058 (format "(eval (if (org-string-nw-p \"$1\") %s %S))"
3059 (format "(org-timestamp-format '%S \"$1\")"
3060 (org-element-copy (car date
)))
3063 (cons "email" (org-element-interpret-data (plist-get info
:email
)))
3064 (cons "title" (org-element-interpret-data (plist-get info
:title
)))
3065 (cons "results" "$1"))
3069 (setq tree
(org-element-parse-buffer nil visible-only
))
3070 ;; Merge footnote definitions outside scope into parse tree.
3071 (org-export--merge-external-footnote-definitions tree
)
3072 ;; Prune tree from non-exported elements and transform
3073 ;; uninterpreted elements or objects in both parse tree and
3074 ;; communication channel.
3075 (org-export--prune-tree tree info
)
3076 (org-export--remove-uninterpreted-data tree info
)
3077 ;; Call parse tree filters.
3079 (org-export-filter-apply-functions
3080 (plist-get info
:filter-parse-tree
) tree info
))
3081 ;; Now tree is complete, compute its properties and add them
3082 ;; to communication channel.
3083 (setq info
(org-export--collect-tree-properties tree info
))
3084 ;; Eventually transcode TREE. Wrap the resulting string into
3086 (let* ((body (org-element-normalize-string
3087 (or (org-export-data tree info
) "")))
3088 (inner-template (cdr (assq 'inner-template
3089 (plist-get info
:translate-alist
))))
3090 (full-body (org-export-filter-apply-functions
3091 (plist-get info
:filter-body
)
3092 (if (not (functionp inner-template
)) body
3093 (funcall inner-template body info
))
3095 (template (cdr (assq 'template
3096 (plist-get info
:translate-alist
)))))
3097 ;; Remove all text properties since they cannot be
3098 ;; retrieved from an external process. Finally call
3099 ;; final-output filter and return result.
3101 (org-export-filter-apply-functions
3102 (plist-get info
:filter-final-output
)
3103 (if (or (not (functionp template
)) body-only
) full-body
3104 (funcall template full-body info
))
3108 (defun org-export-string-as (string backend
&optional body-only ext-plist
)
3109 "Transcode STRING into BACKEND code.
3111 BACKEND is either an export back-end, as returned by, e.g.,
3112 `org-export-create-backend', or a symbol referring to
3113 a registered back-end.
3115 When optional argument BODY-ONLY is non-nil, only return body
3116 code, without preamble nor postamble.
3118 Optional argument EXT-PLIST, when provided, is a property list
3119 with external parameters overriding Org default settings, but
3120 still inferior to file-local settings.
3122 Return code as a string."
3125 (let ((org-inhibit-startup t
)) (org-mode))
3126 (org-export-as backend nil nil body-only ext-plist
)))
3129 (defun org-export-replace-region-by (backend)
3130 "Replace the active region by its export to BACKEND.
3131 BACKEND is either an export back-end, as returned by, e.g.,
3132 `org-export-create-backend', or a symbol referring to
3133 a registered back-end."
3134 (unless (org-region-active-p) (user-error "No active region to replace"))
3136 (org-export-string-as
3137 (delete-and-extract-region (region-beginning) (region-end)) backend t
)))
3140 (defun org-export-insert-default-template (&optional backend subtreep
)
3141 "Insert all export keywords with default values at beginning of line.
3143 BACKEND is a symbol referring to the name of a registered export
3144 back-end, for which specific export options should be added to
3145 the template, or `default' for default template. When it is nil,
3146 the user will be prompted for a category.
3148 If SUBTREEP is non-nil, export configuration will be set up
3149 locally for the subtree through node properties."
3151 (unless (derived-mode-p 'org-mode
) (user-error "Not in an Org mode buffer"))
3152 (when (and subtreep
(org-before-first-heading-p))
3153 (user-error "No subtree to set export options for"))
3154 (let ((node (and subtreep
(save-excursion (org-back-to-heading t
) (point))))
3158 (org-completing-read
3159 "Options category: "
3162 (symbol-name (org-export-backend-name b
)))
3163 org-export-registered-backends
))
3166 ;; Populate OPTIONS and KEYWORDS.
3167 (dolist (entry (cond ((eq backend
'default
) org-export-options-alist
)
3168 ((org-export-backend-p backend
)
3169 (org-export-backend-options backend
))
3170 (t (org-export-backend-options
3171 (org-export-get-backend backend
)))))
3172 (let ((keyword (nth 1 entry
))
3173 (option (nth 2 entry
)))
3175 (keyword (unless (assoc keyword keywords
)
3177 (if (eq (nth 4 entry
) 'split
)
3178 (mapconcat #'identity
(eval (nth 3 entry
)) " ")
3179 (eval (nth 3 entry
)))))
3180 (push (cons keyword value
) keywords
))))
3181 (option (unless (assoc option options
)
3182 (push (cons option
(eval (nth 3 entry
))) options
))))))
3183 ;; Move to an appropriate location in order to insert options.
3184 (unless subtreep
(beginning-of-line))
3185 ;; First (multiple) OPTIONS lines. Never go past fill-column.
3189 #'(lambda (opt) (format "%s:%S" (car opt
) (cdr opt
)))
3190 (sort options
(lambda (k1 k2
) (string< (car k1
) (car k2
)))))))
3193 node
"EXPORT_OPTIONS" (mapconcat 'identity items
" "))
3195 (insert "#+OPTIONS:")
3198 (< (+ width
(length (car items
)) 1) fill-column
))
3199 (let ((item (pop items
)))
3201 (cl-incf width
(1+ (length item
))))))
3203 ;; Then the rest of keywords, in the order specified in either
3204 ;; `org-export-options-alist' or respective export back-ends.
3205 (dolist (key (nreverse keywords
))
3206 (let ((val (cond ((equal (car key
) "DATE")
3209 (org-insert-time-stamp (current-time)))))
3210 ((equal (car key
) "TITLE")
3211 (or (let ((visited-file
3212 (buffer-file-name (buffer-base-buffer))))
3214 (file-name-sans-extension
3215 (file-name-nondirectory visited-file
))))
3216 (buffer-name (buffer-base-buffer))))
3218 (if subtreep
(org-entry-put node
(concat "EXPORT_" (car key
)) val
)
3222 (if (org-string-nw-p val
) (format " %s" val
) ""))))))))
3224 (defun org-export-expand-include-keyword (&optional included dir footnotes
)
3225 "Expand every include keyword in buffer.
3226 Optional argument INCLUDED is a list of included file names along
3227 with their line restriction, when appropriate. It is used to
3228 avoid infinite recursion. Optional argument DIR is the current
3229 working directory. It is used to properly resolve relative
3230 paths. Optional argument FOOTNOTES is a hash-table used for
3231 storing and resolving footnotes. It is created automatically."
3232 (let ((case-fold-search t
)
3233 (file-prefix (make-hash-table :test
#'equal
))
3235 (footnotes (or footnotes
(make-hash-table :test
#'equal
)))
3236 (include-re "^[ \t]*#\\+INCLUDE:"))
3237 ;; If :minlevel is not set the text-property
3238 ;; `:org-include-induced-level' will be used to determine the
3239 ;; relative level when expanding INCLUDE.
3240 ;; Only affects included Org documents.
3241 (goto-char (point-min))
3242 (while (re-search-forward include-re nil t
)
3243 (put-text-property (line-beginning-position) (line-end-position)
3244 :org-include-induced-level
3245 (1+ (org-reduced-level (or (org-current-level) 0)))))
3246 ;; Expand INCLUDE keywords.
3247 (goto-char (point-min))
3248 (while (re-search-forward include-re nil t
)
3249 (let ((element (save-match-data (org-element-at-point))))
3250 (when (eq (org-element-type element
) 'keyword
)
3252 ;; Extract arguments from keyword's value.
3253 (let* ((value (org-element-property :value element
))
3254 (ind (org-get-indentation))
3258 "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value
)
3261 (let ((matched (match-string 1 value
)))
3262 (when (string-match "\\(::\\(.*?\\)\\)\"?\\'"
3264 (setq location
(match-string 2 matched
))
3266 (replace-match "" nil nil matched
1)))
3268 (org-remove-double-quotes
3271 (setq value
(replace-match "" nil nil value
)))))
3273 (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
3275 (prog1 (org-not-nil (match-string 1 value
))
3276 (setq value
(replace-match "" nil nil value
)))))
3279 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
3281 (prog1 (match-string 1 value
)
3282 (setq value
(replace-match "" nil nil value
)))))
3283 (env (cond ((string-match "\\<example\\>" value
)
3285 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value
)
3287 ;; Minimal level of included file defaults to the child
3288 ;; level of the current headline, if any, or one. It
3289 ;; only applies is the file is meant to be included as
3293 (if (string-match ":minlevel +\\([0-9]+\\)" value
)
3294 (prog1 (string-to-number (match-string 1 value
))
3295 (setq value
(replace-match "" nil nil value
)))
3296 (get-text-property (point)
3297 :org-include-induced-level
))))
3298 (src-args (and (eq env
'literal
)
3299 (match-string 1 value
)))
3300 (block (and (string-match "\\<\\(\\S-+\\)\\>" value
)
3301 (match-string 1 value
))))
3303 (delete-region (point) (progn (forward-line) (point)))
3306 ((not (file-readable-p file
))
3307 (error "Cannot include file %s" file
))
3308 ;; Check if files has already been parsed. Look after
3309 ;; inclusion lines too, as different parts of the same file
3310 ;; can be included too.
3311 ((member (list file lines
) included
)
3312 (error "Recursive file inclusion: %s" file
))
3317 (let ((ind-str (make-string ind ?
))
3318 (arg-str (if (stringp src-args
)
3319 (format " %s" src-args
)
3322 (org-escape-code-in-string
3323 (org-export--prepare-file-contents file lines
))))
3324 (format "%s#+BEGIN_%s%s\n%s%s#+END_%s\n"
3325 ind-str block arg-str contents ind-str block
))))
3328 (let ((ind-str (make-string ind ?
))
3330 (org-export--prepare-file-contents file lines
)))
3331 (format "%s#+BEGIN_%s\n%s%s#+END_%s\n"
3332 ind-str block contents ind-str block
))))
3336 (let ((org-inhibit-startup t
)
3339 (org-export--inclusion-absolute-lines
3340 file location only-contents lines
)
3344 (org-export--prepare-file-contents
3345 file lines ind minlevel
3346 (or (gethash file file-prefix
)
3347 (puthash file
(cl-incf current-prefix
) file-prefix
))
3349 (org-export-expand-include-keyword
3350 (cons (list file lines
) included
)
3351 (file-name-directory file
)
3354 ;; Expand footnotes after all files have been included.
3355 ;; Footnotes are stored at end of buffer.
3357 (org-with-wide-buffer
3358 (goto-char (point-max))
3359 (maphash (lambda (k v
) (insert (format "\n[%s] %s\n" k v
)))
3360 footnotes
)))))))))))
3362 (defun org-export--inclusion-absolute-lines (file location only-contents lines
)
3363 "Resolve absolute lines for an included file with file-link.
3365 FILE is string file-name of the file to include. LOCATION is a
3366 string name within FILE to be included (located via
3367 `org-link-search'). If ONLY-CONTENTS is non-nil only the
3368 contents of the named element will be included, as determined
3369 Org-Element. If LINES is non-nil only those lines are included.
3371 Return a string of lines to be included in the format expected by
3372 `org-export--prepare-file-contents'."
3374 (insert-file-contents file
)
3375 (unless (eq major-mode
'org-mode
)
3376 (let ((org-inhibit-startup t
)) (org-mode)))
3378 ;; Enforce consistent search.
3379 (let ((org-link-search-must-match-exact-headline nil
))
3380 (org-link-search location
))
3382 (error "%s for %s::%s" (error-message-string err
) file location
)))
3383 (let* ((element (org-element-at-point))
3385 (and only-contents
(org-element-property :contents-begin element
))))
3387 (or contents-begin
(org-element-property :begin element
))
3388 (org-element-property (if contents-begin
:contents-end
:end
) element
))
3389 (when (and only-contents
3390 (memq (org-element-type element
) '(headline inlinetask
)))
3391 ;; Skip planning line and property-drawer.
3392 (goto-char (point-min))
3393 (when (org-looking-at-p org-planning-line-re
) (forward-line))
3394 (when (looking-at org-property-drawer-re
) (goto-char (match-end 0)))
3395 (unless (bolp) (forward-line))
3396 (narrow-to-region (point) (point-max))))
3398 (org-skip-whitespace)
3400 (let* ((lines (split-string lines
"-"))
3401 (lbeg (string-to-number (car lines
)))
3402 (lend (string-to-number (cadr lines
)))
3403 (beg (if (zerop lbeg
) (point-min)
3404 (goto-char (point-min))
3405 (forward-line (1- lbeg
))
3407 (end (if (zerop lend
) (point-max)
3409 (forward-line (1- lend
))
3411 (narrow-to-region beg end
)))
3412 (let ((end (point-max)))
3413 (goto-char (point-min))
3415 (let ((start-line (line-number-at-pos)))
3421 (while (< (point) end
) (cl-incf counter
) (forward-line))
3424 (defun org-export--prepare-file-contents
3425 (file &optional lines ind minlevel id footnotes
)
3426 "Prepare contents of FILE for inclusion and return it as a string.
3428 When optional argument LINES is a string specifying a range of
3429 lines, include only those lines.
3431 Optional argument IND, when non-nil, is an integer specifying the
3432 global indentation of returned contents. Since its purpose is to
3433 allow an included file to stay in the same environment it was
3434 created (e.g., a list item), it doesn't apply past the first
3435 headline encountered.
3437 Optional argument MINLEVEL, when non-nil, is an integer
3438 specifying the level that any top-level headline in the included
3441 Optional argument ID is an integer that will be inserted before
3442 each footnote definition and reference if FILE is an Org file.
3443 This is useful to avoid conflicts when more than one Org file
3444 with footnotes is included in a document.
3446 Optional argument FOOTNOTES is a hash-table to store footnotes in
3447 the included document."
3449 (insert-file-contents file
)
3451 (let* ((lines (split-string lines
"-"))
3452 (lbeg (string-to-number (car lines
)))
3453 (lend (string-to-number (cadr lines
)))
3454 (beg (if (zerop lbeg
) (point-min)
3455 (goto-char (point-min))
3456 (forward-line (1- lbeg
))
3458 (end (if (zerop lend
) (point-max)
3459 (goto-char (point-min))
3460 (forward-line (1- lend
))
3462 (narrow-to-region beg end
)))
3463 ;; Remove blank lines at beginning and end of contents. The logic
3464 ;; behind that removal is that blank lines around include keyword
3465 ;; override blank lines in included file.
3466 (goto-char (point-min))
3467 (org-skip-whitespace)
3469 (delete-region (point-min) (point))
3470 (goto-char (point-max))
3471 (skip-chars-backward " \r\t\n")
3473 (delete-region (point) (point-max))
3474 ;; If IND is set, preserve indentation of include keyword until
3475 ;; the first headline encountered.
3476 (when (and ind
(> ind
0))
3477 (unless (eq major-mode
'org-mode
)
3478 (let ((org-inhibit-startup t
)) (org-mode)))
3479 (goto-char (point-min))
3480 (let ((ind-str (make-string ind ?
)))
3481 (while (not (or (eobp) (looking-at org-outline-regexp-bol
)))
3482 ;; Do not move footnote definitions out of column 0.
3483 (unless (and (looking-at org-footnote-definition-re
)
3484 (eq (org-element-type (org-element-at-point))
3485 'footnote-definition
))
3488 ;; When MINLEVEL is specified, compute minimal level for headlines
3489 ;; in the file (CUR-MIN), and remove stars to each headline so
3490 ;; that headlines with minimal level have a level of MINLEVEL.
3492 (unless (eq major-mode
'org-mode
)
3493 (let ((org-inhibit-startup t
)) (org-mode)))
3494 (org-with-limited-levels
3495 (let ((levels (org-map-entries
3496 (lambda () (org-reduced-level (org-current-level))))))
3498 (let ((offset (- minlevel
(apply #'min levels
))))
3499 (unless (zerop offset
)
3500 (when org-odd-levels-only
(setq offset
(* offset
2)))
3501 ;; Only change stars, don't bother moving whole
3505 (if (< offset
0) (delete-char (abs offset
))
3506 (insert (make-string offset ?
*)))))))))))
3507 ;; Append ID to all footnote references and definitions, so they
3508 ;; become file specific and cannot collide with footnotes in other
3509 ;; included files. Further, collect relevant footnote definitions
3510 ;; outside of LINES, in order to reintroduce them later.
3512 (let ((marker-min (point-min-marker))
3513 (marker-max (point-max-marker))
3516 ;; Generate new label from LABEL. If LABEL is akin to
3517 ;; [1] convert it to [fn:--ID-1]. Otherwise add "-ID-"
3519 (if (org-string-match-p "\\`[0-9]+\\'" label
)
3520 (format "fn:--%d-%s" id label
)
3521 (format "fn:-%d-%s" id
(substring label
3)))))
3524 ;; Replace OLD label with NEW in footnote F.
3526 (goto-char (1+ (org-element-property :begin f
)))
3527 (looking-at (regexp-quote old
))
3528 (replace-match new
))))
3530 (goto-char (point-min))
3531 (while (re-search-forward org-footnote-re nil t
)
3532 (let ((footnote (save-excursion
3534 (org-element-context))))
3535 (when (memq (org-element-type footnote
)
3536 '(footnote-definition footnote-reference
))
3537 (let* ((label (org-element-property :label footnote
)))
3538 ;; Update the footnote-reference at point and collect
3539 ;; the new label, which is only used for footnotes
3542 (let ((seen (cdr (assoc label seen-alist
))))
3543 (if seen
(funcall set-new-label footnote label seen
)
3544 (let ((new (funcall get-new-label label
)))
3545 (push (cons label new
) seen-alist
)
3546 (org-with-wide-buffer
3547 (let* ((def (org-footnote-get-definition label
))
3550 (or (< beg marker-min
)
3551 (>= beg marker-max
)))
3552 ;; Store since footnote-definition is
3553 ;; outside of LINES.
3555 (org-element-normalize-string (nth 3 def
))
3557 (funcall set-new-label footnote label new
)))))))))
3558 (set-marker marker-min nil
)
3559 (set-marker marker-max nil
)))
3560 (org-element-normalize-string (buffer-string))))
3562 (defun org-export-execute-babel-code ()
3563 "Execute every Babel code in the visible part of current buffer."
3564 ;; Get a pristine copy of current buffer so Babel references can be
3565 ;; properly resolved.
3566 (let ((reference (org-export-copy-buffer)))
3567 (unwind-protect (org-babel-exp-process-buffer reference
)
3568 (kill-buffer reference
))))
3570 (defun org-export--copy-to-kill-ring-p ()
3571 "Return a non-nil value when output should be added to the kill ring.
3572 See also `org-export-copy-to-kill-ring'."
3573 (if (eq org-export-copy-to-kill-ring
'if-interactive
)
3574 (not (or executing-kbd-macro noninteractive
))
3575 (eq org-export-copy-to-kill-ring t
)))
3579 ;;; Tools For Back-Ends
3581 ;; A whole set of tools is available to help build new exporters. Any
3582 ;; function general enough to have its use across many back-ends
3583 ;; should be added here.
3585 ;;;; For Affiliated Keywords
3587 ;; `org-export-read-attribute' reads a property from a given element
3588 ;; as a plist. It can be used to normalize affiliated keywords'
3591 ;; Since captions can span over multiple lines and accept dual values,
3592 ;; their internal representation is a bit tricky. Therefore,
3593 ;; `org-export-get-caption' transparently returns a given element's
3594 ;; caption as a secondary string.
3596 (defun org-export-read-attribute (attribute element
&optional property
)
3597 "Turn ATTRIBUTE property from ELEMENT into a plist.
3599 When optional argument PROPERTY is non-nil, return the value of
3600 that property within attributes.
3602 This function assumes attributes are defined as \":keyword
3603 value\" pairs. It is appropriate for `:attr_html' like
3606 All values will become strings except the empty string and
3607 \"nil\", which will become nil. Also, values containing only
3608 double quotes will be read as-is, which means that \"\" value
3609 will become the empty string."
3610 (let* ((prepare-value
3613 (cond ((member str
'(nil "" "nil")) nil
)
3614 ((string-match "^\"\\(\"+\\)?\"$" str
)
3615 (or (match-string 1 str
) ""))
3618 (let ((value (org-element-property attribute element
)))
3620 (let ((s (mapconcat 'identity value
" ")) result
)
3621 (while (string-match
3622 "\\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ \t]+\\|$\\)"
3624 (let ((value (substring s
0 (match-beginning 0))))
3625 (push (funcall prepare-value value
) result
))
3626 (push (intern (match-string 1 s
)) result
)
3627 (setq s
(substring s
(match-end 0))))
3628 ;; Ignore any string before first property with `cdr'.
3629 (cdr (nreverse (cons (funcall prepare-value s
) result
))))))))
3630 (if property
(plist-get attributes property
) attributes
)))
3632 (defun org-export-get-caption (element &optional shortp
)
3633 "Return caption from ELEMENT as a secondary string.
3635 When optional argument SHORTP is non-nil, return short caption,
3636 as a secondary string, instead.
3638 Caption lines are separated by a white space."
3639 (let ((full-caption (org-element-property :caption element
)) caption
)
3640 (dolist (line full-caption
(cdr caption
))
3641 (let ((cap (funcall (if shortp
'cdr
'car
) line
)))
3643 (setq caption
(nconc (list " ") (copy-sequence cap
) caption
)))))))
3646 ;;;; For Derived Back-ends
3648 ;; `org-export-with-backend' is a function allowing to locally use
3649 ;; another back-end to transcode some object or element. In a derived
3650 ;; back-end, it may be used as a fall-back function once all specific
3651 ;; cases have been treated.
3653 (defun org-export-with-backend (backend data
&optional contents info
)
3654 "Call a transcoder from BACKEND on DATA.
3655 BACKEND is an export back-end, as returned by, e.g.,
3656 `org-export-create-backend', or a symbol referring to
3657 a registered back-end. DATA is an Org element, object, secondary
3658 string or string. CONTENTS, when non-nil, is the transcoded
3659 contents of DATA element, as a string. INFO, when non-nil, is
3660 the communication channel used for export, as a plist."
3661 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
3662 (org-export-barf-if-invalid-backend backend
)
3663 (let ((type (org-element-type data
)))
3664 (if (memq type
'(nil org-data
)) (error "No foreign transcoder available")
3665 (let* ((all-transcoders (org-export-get-all-transcoders backend
))
3666 (transcoder (cdr (assq type all-transcoders
))))
3667 (if (not (functionp transcoder
))
3668 (error "No foreign transcoder available")
3670 transcoder data contents
3674 :translate-alist all-transcoders
3675 :exported-data
(make-hash-table :test
#'eq
:size
401)))))))))
3678 ;;;; For Export Snippets
3680 ;; Every export snippet is transmitted to the back-end. Though, the
3681 ;; latter will only retain one type of export-snippet, ignoring
3682 ;; others, based on the former's target back-end. The function
3683 ;; `org-export-snippet-backend' returns that back-end for a given
3686 (defun org-export-snippet-backend (export-snippet)
3687 "Return EXPORT-SNIPPET targeted back-end as a symbol.
3688 Translation, with `org-export-snippet-translation-alist', is
3690 (let ((back-end (org-element-property :back-end export-snippet
)))
3692 (or (cdr (assoc back-end org-export-snippet-translation-alist
))
3698 ;; `org-export-collect-footnote-definitions' is a tool to list
3699 ;; actually used footnotes definitions in the whole parse tree, or in
3700 ;; a headline, in order to add footnote listings throughout the
3703 ;; `org-export-footnote-first-reference-p' is a predicate used by some
3704 ;; back-ends, when they need to attach the footnote definition only to
3705 ;; the first occurrence of the corresponding label.
3707 ;; `org-export-get-footnote-definition' and
3708 ;; `org-export-get-footnote-number' provide easier access to
3709 ;; additional information relative to a footnote reference.
3711 (defun org-export-get-footnote-definition (footnote-reference info
)
3712 "Return definition of FOOTNOTE-REFERENCE as parsed data.
3713 INFO is the plist used as a communication channel. If no such
3714 definition can be found, raise an error."
3715 (let ((label (org-element-property :label footnote-reference
)))
3716 (if (not label
) (org-element-contents footnote-reference
)
3717 (let ((cache (or (plist-get info
:footnote-definition-cache
)
3718 (let ((hash (make-hash-table :test
#'equal
)))
3719 (plist-put info
:footnote-definition-cache hash
)
3721 (or (gethash label cache
)
3723 (org-element-map (plist-get info
:parse-tree
)
3724 '(footnote-definition footnote-reference
)
3726 (and (equal (org-element-property :label f
) label
)
3727 (org-element-contents f
)))
3730 (error "Definition not found for footnote %s" label
))))))
3732 (defun org-export--footnote-reference-map
3733 (function data info
&optional body-first
)
3734 "Apply FUNCTION on every footnote reference in DATA.
3735 INFO is a plist containing export state. By default, as soon as
3736 a new footnote reference is encountered, FUNCTION is called onto
3737 its definition. However, if BODY-FIRST is non-nil, this step is
3738 delayed until the end of the process."
3739 (letrec ((definitions)
3742 (lambda (data delayp
)
3743 ;; Search footnote references through DATA, filling
3744 ;; SEEN-REFS along the way. When DELAYP is non-nil,
3745 ;; store footnote definitions so they can be entered
3747 (org-element-map data
'footnote-reference
3749 (funcall function f
)
3750 (let ((--label (org-element-property :label f
)))
3751 (unless (and --label
(member --label seen-refs
))
3752 (when --label
(push --label seen-refs
))
3753 ;; Search for subsequent references in footnote
3754 ;; definition so numbering follows reading
3755 ;; logic, unless DELAYP in non-nil.
3758 (push (org-export-get-footnote-definition f info
)
3760 ;; Do not force entering inline definitions,
3761 ;; since `org-element-map' already traverses
3762 ;; them at the right time.
3763 ((eq (org-element-property :type f
) 'inline
))
3764 (t (funcall search-ref
3765 (org-export-get-footnote-definition f info
)
3768 ;; Don't enter footnote definitions since it will
3769 ;; happen when their first reference is found.
3770 ;; Moreover, if DELAYP is non-nil, make sure we
3771 ;; postpone entering definitions of inline references.
3772 (if delayp
'(footnote-definition footnote-reference
)
3773 'footnote-definition
)))))
3774 (funcall search-ref data body-first
)
3775 (funcall search-ref
(nreverse definitions
) nil
)))
3777 (defun org-export-collect-footnote-definitions (info &optional data body-first
)
3778 "Return an alist between footnote numbers, labels and definitions.
3780 INFO is the current export state, as a plist.
3782 Definitions are collected throughout the whole parse tree, or
3785 Sorting is done by order of references. As soon as a new
3786 reference is encountered, other references are searched within
3787 its definition. However, if BODY-FIRST is non-nil, this step is
3788 delayed after the whole tree is checked. This alters results
3789 when references are found in footnote definitions.
3791 Definitions either appear as Org data or as a secondary string
3792 for inlined footnotes. Unreferenced definitions are ignored."
3793 (let ((n 0) labels alist
)
3794 (org-export--footnote-reference-map
3796 ;; Collect footnote number, label and definition.
3797 (let ((l (org-element-property :label f
)))
3798 (unless (and l
(member l labels
))
3800 (push (list n l
(org-export-get-footnote-definition f info
)) alist
))
3801 (when l
(push l labels
))))
3802 (or data
(plist-get info
:parse-tree
)) info body-first
)
3805 (defun org-export-footnote-first-reference-p
3806 (footnote-reference info
&optional data body-first
)
3807 "Non-nil when a footnote reference is the first one for its label.
3809 FOOTNOTE-REFERENCE is the footnote reference being considered.
3810 INFO is a plist containing current export state.
3812 Search is done throughout the whole parse tree, or DATA when
3815 By default, as soon as a new footnote reference is encountered,
3816 other references are searched within its definition. However, if
3817 BODY-FIRST is non-nil, this step is delayed after the whole tree
3818 is checked. This alters results when references are found in
3819 footnote definitions."
3820 (let ((label (org-element-property :label footnote-reference
)))
3821 ;; Anonymous footnotes are always a first reference.
3824 (org-export--footnote-reference-map
3826 (let ((l (org-element-property :label f
)))
3827 (when (and l label
(string= label l
))
3828 (throw 'exit
(eq footnote-reference f
)))))
3829 (or data
(plist-get info
:parse-tree
)) info body-first
)))))
3831 (defun org-export-get-footnote-number (footnote info
&optional data body-first
)
3832 "Return number associated to a footnote.
3834 FOOTNOTE is either a footnote reference or a footnote definition.
3835 INFO is the plist containing export state.
3837 Number is unique throughout the whole parse tree, or DATA, when
3840 By default, as soon as a new footnote reference is encountered,
3841 counting process moves into its definition. However, if
3842 BODY-FIRST is non-nil, this step is delayed until the end of the
3843 process, leading to a different order when footnotes are nested."
3846 (label (org-element-property :label footnote
)))
3848 (org-export--footnote-reference-map
3850 (let ((l (org-element-property :label f
)))
3852 ;; Anonymous footnote match: return number.
3853 ((and (not l
) (not label
) (eq footnote f
)) (throw 'exit
(1+ count
)))
3854 ;; Labels match: return number.
3855 ((and label l
(string= label l
)) (throw 'exit
(1+ count
)))
3856 ;; Otherwise store label and increase counter if label
3857 ;; wasn't encountered yet.
3858 ((not l
) (cl-incf count
))
3859 ((not (member l seen
)) (push l seen
) (cl-incf count
)))))
3860 (or data
(plist-get info
:parse-tree
)) info body-first
))))
3865 ;; `org-export-get-relative-level' is a shortcut to get headline
3866 ;; level, relatively to the lower headline level in the parsed tree.
3868 ;; `org-export-get-headline-number' returns the section number of an
3869 ;; headline, while `org-export-number-to-roman' allows to convert it
3870 ;; to roman numbers. With an optional argument,
3871 ;; `org-export-get-headline-number' returns a number to unnumbered
3872 ;; headlines (used for internal id).
3874 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
3875 ;; `org-export-last-sibling-p' are three useful predicates when it
3876 ;; comes to fulfill the `:headline-levels' property.
3878 ;; `org-export-get-tags', `org-export-get-category' and
3879 ;; `org-export-get-node-property' extract useful information from an
3880 ;; headline or a parent headline. They all handle inheritance.
3882 ;; `org-export-get-alt-title' tries to retrieve an alternative title,
3883 ;; as a secondary string, suitable for table of contents. It falls
3884 ;; back onto default title.
3886 (defun org-export-get-relative-level (headline info
)
3887 "Return HEADLINE relative level within current parsed tree.
3888 INFO is a plist holding contextual information."
3889 (+ (org-element-property :level headline
)
3890 (or (plist-get info
:headline-offset
) 0)))
3892 (defun org-export-low-level-p (headline info
)
3893 "Non-nil when HEADLINE is considered as low level.
3895 INFO is a plist used as a communication channel.
3897 A low level headlines has a relative level greater than
3898 `:headline-levels' property value.
3900 Return value is the difference between HEADLINE relative level
3901 and the last level being considered as high enough, or nil."
3902 (let ((limit (plist-get info
:headline-levels
)))
3903 (when (wholenump limit
)
3904 (let ((level (org-export-get-relative-level headline info
)))
3905 (and (> level limit
) (- level limit
))))))
3907 (defun org-export-get-headline-number (headline info
)
3908 "Return numbered HEADLINE numbering as a list of numbers.
3909 INFO is a plist holding contextual information."
3910 (and (org-export-numbered-headline-p headline info
)
3911 (cdr (assq headline
(plist-get info
:headline-numbering
)))))
3913 (defun org-export-numbered-headline-p (headline info
)
3914 "Return a non-nil value if HEADLINE element should be numbered.
3915 INFO is a plist used as a communication channel."
3917 (lambda (head) (org-not-nil (org-element-property :UNNUMBERED head
)))
3918 (org-element-lineage headline nil t
))
3919 (let ((sec-num (plist-get info
:section-numbers
))
3920 (level (org-export-get-relative-level headline info
)))
3921 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))))
3923 (defun org-export-number-to-roman (n)
3924 "Convert integer N into a roman numeral."
3925 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
3926 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
3927 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
3931 (number-to-string n
)
3933 (if (>= n
(caar roman
))
3934 (setq n
(- n
(caar roman
))
3935 res
(concat res
(cdar roman
)))
3939 (defun org-export-get-tags (element info
&optional tags inherited
)
3940 "Return list of tags associated to ELEMENT.
3942 ELEMENT has either an `headline' or an `inlinetask' type. INFO
3943 is a plist used as a communication channel.
3945 Select tags (see `org-export-select-tags') and exclude tags (see
3946 `org-export-exclude-tags') are removed from the list.
3948 When non-nil, optional argument TAGS should be a list of strings.
3949 Any tag belonging to this list will also be removed.
3951 When optional argument INHERITED is non-nil, tags can also be
3952 inherited from parent headlines and FILETAGS keywords."
3954 (lambda (tag) (or (member tag
(plist-get info
:select-tags
))
3955 (member tag
(plist-get info
:exclude-tags
))
3957 (if (not inherited
) (org-element-property :tags element
)
3958 ;; Build complete list of inherited tags.
3959 (let ((current-tag-list (org-element-property :tags element
)))
3960 (dolist (parent (org-element-lineage element
))
3961 (dolist (tag (org-element-property :tags parent
))
3962 (when (and (memq (org-element-type parent
) '(headline inlinetask
))
3963 (not (member tag current-tag-list
)))
3964 (push tag current-tag-list
))))
3965 ;; Add FILETAGS keywords and return results.
3966 (org-uniquify (append (plist-get info
:filetags
) current-tag-list
))))))
3968 (defun org-export-get-node-property (property blob
&optional inherited
)
3969 "Return node PROPERTY value for BLOB.
3971 PROPERTY is an upcase symbol (i.e. `:COOKIE_DATA'). BLOB is an
3974 If optional argument INHERITED is non-nil, the value can be
3975 inherited from a parent headline.
3977 Return value is a string or nil."
3978 (let ((headline (if (eq (org-element-type blob
) 'headline
) blob
3979 (org-export-get-parent-headline blob
))))
3980 (if (not inherited
) (org-element-property property blob
)
3981 (let ((parent headline
))
3984 (when (plist-member (nth 1 parent
) property
)
3985 (throw 'found
(org-element-property property parent
)))
3986 (setq parent
(org-element-property :parent parent
))))))))
3988 (defun org-export-get-category (blob info
)
3989 "Return category for element or object BLOB.
3991 INFO is a plist used as a communication channel.
3993 CATEGORY is automatically inherited from a parent headline, from
3994 #+CATEGORY: keyword or created out of original file name. If all
3995 fail, the fall-back value is \"???\"."
3996 (or (org-export-get-node-property :CATEGORY blob t
)
3997 (org-element-map (plist-get info
:parse-tree
) 'keyword
3999 (when (equal (org-element-property :key kwd
) "CATEGORY")
4000 (org-element-property :value kwd
)))
4002 (let ((file (plist-get info
:input-file
)))
4003 (and file
(file-name-sans-extension (file-name-nondirectory file
))))
4006 (defun org-export-get-alt-title (headline _
)
4007 "Return alternative title for HEADLINE, as a secondary string.
4008 If no optional title is defined, fall-back to the regular title."
4009 (let ((alt (org-element-property :ALT_TITLE headline
)))
4010 (if alt
(org-element-parse-secondary-string
4011 alt
(org-element-restriction 'headline
) headline
)
4012 (org-element-property :title headline
))))
4014 (defun org-export-first-sibling-p (blob info
)
4015 "Non-nil when BLOB is the first sibling in its parent.
4016 BLOB is an element or an object. If BLOB is a headline, non-nil
4017 means it is the first sibling in the sub-tree. INFO is a plist
4018 used as a communication channel."
4019 (memq (org-element-type (org-export-get-previous-element blob info
))
4022 (defun org-export-last-sibling-p (blob info
)
4023 "Non-nil when BLOB is the last sibling in its parent.
4024 BLOB is an element or an object. INFO is a plist used as
4025 a communication channel."
4026 (not (org-export-get-next-element blob info
)))
4031 ;; `org-export-get-date' returns a date appropriate for the document
4032 ;; to about to be exported. In particular, it takes care of
4033 ;; `org-export-date-timestamp-format'.
4035 (defun org-export-get-date (info &optional fmt
)
4036 "Return date value for the current document.
4038 INFO is a plist used as a communication channel. FMT, when
4039 non-nil, is a time format string that will be applied on the date
4040 if it consists in a single timestamp object. It defaults to
4041 `org-export-date-timestamp-format' when nil.
4043 A proper date can be a secondary string, a string or nil. It is
4044 meant to be translated with `org-export-data' or alike."
4045 (let ((date (plist-get info
:date
))
4046 (fmt (or fmt org-export-date-timestamp-format
)))
4047 (cond ((not date
) nil
)
4050 (eq (org-element-type (car date
)) 'timestamp
))
4051 (org-timestamp-format (car date
) fmt
))
4057 ;; `org-export-custom-protocol-maybe' handles custom protocol defined
4058 ;; with `org-add-link-type', which see.
4060 ;; `org-export-get-coderef-format' returns an appropriate format
4061 ;; string for coderefs.
4063 ;; `org-export-inline-image-p' returns a non-nil value when the link
4064 ;; provided should be considered as an inline image.
4066 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
4067 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
4068 ;; returns an appropriate unique identifier.
4070 ;; `org-export-resolve-id-link' returns the first headline with
4071 ;; specified id or custom-id in parse tree, the path to the external
4072 ;; file with the id.
4074 ;; `org-export-resolve-coderef' associates a reference to a line
4075 ;; number in the element it belongs, or returns the reference itself
4076 ;; when the element isn't numbered.
4078 ;; `org-export-file-uri' expands a filename as stored in :path value
4079 ;; of a "file" link into a file URI.
4081 ;; Broken links raise a `org-link-broken' error, which is caught by
4082 ;; `org-export-data' for further processing, depending on
4083 ;; `org-export-with-broken-links' value.
4085 (org-define-error 'org-link-broken
"Unable to resolve link; aborting")
4087 (defun org-export-custom-protocol-maybe (link desc backend
)
4088 "Try exporting LINK with a dedicated function.
4090 DESC is its description, as a string, or nil. BACKEND is the
4091 back-end used for export, as a symbol.
4093 Return output as a string, or nil if no protocol handles LINK.
4095 A custom protocol has precedence over regular back-end export.
4096 The function ignores links with an implicit type (e.g.,
4098 (let ((type (org-element-property :type link
)))
4099 (unless (or (member type
'("coderef" "custom-id" "fuzzy" "radio"))
4101 (let ((protocol (nth 2 (assoc type org-link-protocols
))))
4102 (and (functionp protocol
)
4104 (org-link-unescape (org-element-property :path link
))
4108 (defun org-export-get-coderef-format (path desc
)
4109 "Return format string for code reference link.
4110 PATH is the link path. DESC is its description."
4112 (cond ((not desc
) "%s")
4113 ((string-match (regexp-quote (concat "(" path
")")) desc
)
4114 (replace-match "%s" t t desc
))
4117 (defun org-export-inline-image-p (link &optional rules
)
4118 "Non-nil if LINK object points to an inline image.
4120 Optional argument is a set of RULES defining inline images. It
4121 is an alist where associations have the following shape:
4125 Applying a rule means apply REGEXP against LINK's path when its
4126 type is TYPE. The function will return a non-nil value if any of
4127 the provided rules is non-nil. The default rule is
4128 `org-export-default-inline-image-rule'.
4130 This only applies to links without a description."
4131 (and (not (org-element-contents link
))
4132 (let ((case-fold-search t
))
4134 (dolist (rule (or rules org-export-default-inline-image-rule
))
4135 (and (string= (org-element-property :type link
) (car rule
))
4136 (org-string-match-p (cdr rule
)
4137 (org-element-property :path link
))
4138 (throw 'exit t
)))))))
4140 (defun org-export-resolve-coderef (ref info
)
4141 "Resolve a code reference REF.
4143 INFO is a plist used as a communication channel.
4145 Return associated line number in source code, or REF itself,
4146 depending on src-block or example element's switches. Throw an
4147 error if no block contains REF."
4148 (or (org-element-map (plist-get info
:parse-tree
) '(example-block src-block
)
4151 (insert (org-trim (org-element-property :value el
)))
4152 (let* ((label-fmt (regexp-quote
4153 (or (org-element-property :label-fmt el
)
4154 org-coderef-label-format
)))
4156 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
4157 (format label-fmt ref
))))
4158 ;; Element containing REF is found. Resolve it to
4159 ;; either a label or a line number, as needed.
4160 (when (re-search-backward ref-re nil t
)
4162 ((org-element-property :use-labels el
) ref
)
4163 ((eq (org-element-property :number-lines el
) 'continued
)
4164 (+ (org-export-get-loc el info
) (line-number-at-pos)))
4165 (t (line-number-at-pos)))))))
4167 (signal 'org-link-broken
(list ref
))))
4169 (defun org-export-resolve-fuzzy-link (link info
)
4170 "Return LINK destination.
4172 INFO is a plist holding contextual information.
4174 Return value can be an object or an element:
4176 - If LINK path matches a target object (i.e. <<path>>) return it.
4178 - If LINK path exactly matches the name affiliated keyword
4179 (i.e. #+NAME: path) of an element, return that element.
4181 - If LINK path exactly matches any headline name, return that
4184 - Otherwise, throw an error.
4186 Assume LINK type is \"fuzzy\". White spaces are not
4188 (let* ((raw-path (org-link-unescape (org-element-property :path link
)))
4189 (headline-only (eq (string-to-char raw-path
) ?
*))
4190 ;; Split PATH at white spaces so matches are space
4192 (path (org-split-string
4193 (if headline-only
(substring raw-path
1) raw-path
)))
4195 (or (plist-get info
:resolve-fuzzy-link-cache
)
4196 (plist-get (plist-put info
4197 :resolve-fuzzy-link-cache
4198 (make-hash-table :test
#'equal
))
4199 :resolve-fuzzy-link-cache
)))
4200 (cached (gethash path link-cache
'not-found
)))
4201 (if (not (eq cached
'not-found
)) cached
4202 (let ((ast (plist-get info
:parse-tree
)))
4206 ;; First try to find a matching "<<path>>" unless user
4207 ;; specified he was looking for a headline (path starts with
4208 ;; a "*" character).
4209 ((and (not headline-only
)
4210 (org-element-map ast
'target
4212 (and (equal (org-split-string
4213 (org-element-property :value datum
))
4216 info
'first-match
)))
4217 ;; Then try to find an element with a matching "#+NAME: path"
4218 ;; affiliated keyword.
4219 ((and (not headline-only
)
4220 (org-element-map ast org-element-all-elements
4222 (let ((name (org-element-property :name datum
)))
4223 (and name
(equal (org-split-string name
) path
) datum
)))
4224 info
'first-match
)))
4225 ;; Try to find a matching headline.
4226 ((org-element-map ast
'headline
4228 (and (equal (org-split-string
4229 (replace-regexp-in-string
4230 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
4231 (org-element-property :raw-value h
)))
4235 (t (signal 'org-link-broken
(list raw-path
))))
4238 (defun org-export-resolve-id-link (link info
)
4239 "Return headline referenced as LINK destination.
4241 INFO is a plist used as a communication channel.
4243 Return value can be the headline element matched in current parse
4244 tree or a file name. Assume LINK type is either \"id\" or
4245 \"custom-id\". Throw an error if no match is found."
4246 (let ((id (org-element-property :path link
)))
4247 ;; First check if id is within the current parse tree.
4248 (or (org-element-map (plist-get info
:parse-tree
) 'headline
4250 (when (or (equal (org-element-property :ID headline
) id
)
4251 (equal (org-element-property :CUSTOM_ID headline
) id
))
4254 ;; Otherwise, look for external files.
4255 (cdr (assoc id
(plist-get info
:id-alist
)))
4256 (signal 'org-link-broken
(list id
)))))
4258 (defun org-export-resolve-radio-link (link info
)
4259 "Return radio-target object referenced as LINK destination.
4261 INFO is a plist used as a communication channel.
4263 Return value can be a radio-target object or nil. Assume LINK
4264 has type \"radio\"."
4265 (let ((path (replace-regexp-in-string
4266 "[ \r\t\n]+" " " (org-element-property :path link
))))
4267 (org-element-map (plist-get info
:parse-tree
) 'radio-target
4269 (and (eq (compare-strings
4270 (replace-regexp-in-string
4271 "[ \r\t\n]+" " " (org-element-property :value radio
))
4272 nil nil path nil nil t
)
4275 info
'first-match
)))
4277 (defun org-export-file-uri (filename)
4278 "Return file URI associated to FILENAME."
4279 (cond ((org-string-match-p "\\`//" filename
) (concat "file:" filename
))
4280 ((not (file-name-absolute-p filename
)) filename
)
4281 ((org-file-remote-p filename
) (concat "file:/" filename
))
4282 (t (concat "file://" (expand-file-name filename
)))))
4287 ;; `org-export-get-reference' associate a unique reference for any
4288 ;; object or element.
4290 ;; `org-export-get-ordinal' associates a sequence number to any object
4293 (defun org-export-get-reference (datum info
)
4294 "Return a unique reference for DATUM, as a string.
4295 DATUM is either an element or an object. INFO is the current
4296 export state, as a plist. Returned reference consists of
4297 alphanumeric characters only."
4298 (let ((type (org-element-type datum
))
4299 (cache (or (plist-get info
:internal-references
)
4300 (let ((h (make-hash-table :test
#'eq
)))
4301 (plist-put info
:internal-references h
)
4303 (or (gethash datum cache
)
4307 (replace-regexp-in-string "-" "" (symbol-name type
))
4309 (cl-incf (gethash type cache
0)))
4312 (defun org-export-get-ordinal (element info
&optional types predicate
)
4313 "Return ordinal number of an element or object.
4315 ELEMENT is the element or object considered. INFO is the plist
4316 used as a communication channel.
4318 Optional argument TYPES, when non-nil, is a list of element or
4319 object types, as symbols, that should also be counted in.
4320 Otherwise, only provided element's type is considered.
4322 Optional argument PREDICATE is a function returning a non-nil
4323 value if the current element or object should be counted in. It
4324 accepts two arguments: the element or object being considered and
4325 the plist used as a communication channel. This allows to count
4326 only a certain type of objects (i.e. inline images).
4328 Return value is a list of numbers if ELEMENT is a headline or an
4329 item. It is nil for keywords. It represents the footnote number
4330 for footnote definitions and footnote references. If ELEMENT is
4331 a target, return the same value as if ELEMENT was the closest
4332 table, item or headline containing the target. In any other
4333 case, return the sequence number of ELEMENT among elements or
4334 objects of the same type."
4335 ;; Ordinal of a target object refer to the ordinal of the closest
4336 ;; table, item, or headline containing the object.
4337 (when (eq (org-element-type element
) 'target
)
4339 (org-element-lineage
4341 '(footnote-definition footnote-reference headline item table
))))
4342 (cl-case (org-element-type element
)
4343 ;; Special case 1: A headline returns its number as a list.
4344 (headline (org-export-get-headline-number element info
))
4345 ;; Special case 2: An item returns its number as a list.
4346 (item (let ((struct (org-element-property :structure element
)))
4347 (org-list-get-item-number
4348 (org-element-property :begin element
)
4350 (org-list-prevs-alist struct
)
4351 (org-list-parents-alist struct
))))
4352 ((footnote-definition footnote-reference
)
4353 (org-export-get-footnote-number element info
))
4356 ;; Increment counter until ELEMENT is found again.
4357 (org-element-map (plist-get info
:parse-tree
)
4358 (or types
(org-element-type element
))
4361 ((eq element el
) (1+ counter
))
4362 ((not predicate
) (cl-incf counter
) nil
)
4363 ((funcall predicate el info
) (cl-incf counter
) nil
)))
4364 info
'first-match
)))))
4369 ;; `org-export-get-loc' counts number of code lines accumulated in
4370 ;; src-block or example-block elements with a "+n" switch until
4371 ;; a given element, excluded. Note: "-n" switches reset that count.
4373 ;; `org-export-unravel-code' extracts source code (along with a code
4374 ;; references alist) from an `element-block' or `src-block' type
4377 ;; `org-export-format-code' applies a formatting function to each line
4378 ;; of code, providing relative line number and code reference when
4379 ;; appropriate. Since it doesn't access the original element from
4380 ;; which the source code is coming, it expects from the code calling
4381 ;; it to know if lines should be numbered and if code references
4384 ;; Eventually, `org-export-format-code-default' is a higher-level
4385 ;; function (it makes use of the two previous functions) which handles
4386 ;; line numbering and code references inclusion, and returns source
4387 ;; code in a format suitable for plain text or verbatim output.
4389 (defun org-export-get-loc (element info
)
4390 "Return accumulated lines of code up to ELEMENT.
4392 INFO is the plist used as a communication channel.
4394 ELEMENT is excluded from count."
4396 (org-element-map (plist-get info
:parse-tree
)
4397 `(src-block example-block
,(org-element-type element
))
4400 ;; ELEMENT is reached: Quit the loop.
4402 ;; Only count lines from src-block and example-block elements
4403 ;; with a "+n" or "-n" switch. A "-n" switch resets counter.
4404 ((not (memq (org-element-type el
) '(src-block example-block
))) nil
)
4405 ((let ((linums (org-element-property :number-lines el
)))
4407 ;; Accumulate locs or reset them.
4408 (let ((lines (org-count-lines
4409 (org-trim (org-element-property :value el
)))))
4410 (setq loc
(if (eq linums
'new
) lines
(+ loc lines
))))))
4411 ;; Return nil to stay in the loop.
4417 (defun org-export-unravel-code (element)
4418 "Clean source code and extract references out of it.
4420 ELEMENT has either a `src-block' an `example-block' type.
4422 Return a cons cell whose CAR is the source code, cleaned from any
4423 reference, protective commas and spurious indentation, and CDR is
4424 an alist between relative line number (integer) and name of code
4425 reference on that line (string)."
4426 (let* ((line 0) refs
4427 (value (org-element-property :value element
))
4428 ;; Get code and clean it. Remove blank lines at its
4429 ;; beginning and end.
4430 (code (replace-regexp-in-string
4431 "\\`\\([ \t]*\n\\)+" ""
4432 (replace-regexp-in-string
4433 "\\([ \t]*\n\\)*[ \t]*\\'" "\n"
4434 (if (or org-src-preserve-indentation
4435 (org-element-property :preserve-indent element
))
4437 (org-remove-indentation value
)))))
4438 ;; Get format used for references.
4439 (label-fmt (regexp-quote
4440 (or (org-element-property :label-fmt element
)
4441 org-coderef-label-format
)))
4442 ;; Build a regexp matching a loc with a reference.
4444 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)[ \t]*\\)$"
4445 (replace-regexp-in-string
4446 "%s" "\\([-a-zA-Z0-9_ ]+\\)" label-fmt nil t
))))
4449 ;; Code with references removed.
4450 (org-element-normalize-string
4454 (if (not (string-match with-ref-re loc
)) loc
4455 ;; Ref line: remove ref, and signal its position in REFS.
4456 (push (cons line
(match-string 3 loc
)) refs
)
4457 (replace-match "" nil nil loc
1)))
4458 (org-split-string code
"\n") "\n"))
4462 (defun org-export-format-code (code fun
&optional num-lines ref-alist
)
4463 "Format CODE by applying FUN line-wise and return it.
4465 CODE is a string representing the code to format. FUN is
4466 a function. It must accept three arguments: a line of
4467 code (string), the current line number (integer) or nil and the
4468 reference associated to the current line (string) or nil.
4470 Optional argument NUM-LINES can be an integer representing the
4471 number of code lines accumulated until the current code. Line
4472 numbers passed to FUN will take it into account. If it is nil,
4473 FUN's second argument will always be nil. This number can be
4474 obtained with `org-export-get-loc' function.
4476 Optional argument REF-ALIST can be an alist between relative line
4477 number (i.e. ignoring NUM-LINES) and the name of the code
4478 reference on it. If it is nil, FUN's third argument will always
4479 be nil. It can be obtained through the use of
4480 `org-export-unravel-code' function."
4481 (let ((--locs (org-split-string code
"\n"))
4483 (org-element-normalize-string
4487 (let ((--ref (cdr (assq --line ref-alist
))))
4488 (funcall fun --loc
(and num-lines
(+ num-lines --line
)) --ref
)))
4491 (defun org-export-format-code-default (element info
)
4492 "Return source code from ELEMENT, formatted in a standard way.
4494 ELEMENT is either a `src-block' or `example-block' element. INFO
4495 is a plist used as a communication channel.
4497 This function takes care of line numbering and code references
4498 inclusion. Line numbers, when applicable, appear at the
4499 beginning of the line, separated from the code by two white
4500 spaces. Code references, on the other hand, appear flushed to
4501 the right, separated by six white spaces from the widest line of
4503 ;; Extract code and references.
4504 (let* ((code-info (org-export-unravel-code element
))
4505 (code (car code-info
))
4506 (code-lines (org-split-string code
"\n")))
4507 (if (null code-lines
) ""
4508 (let* ((refs (and (org-element-property :retain-labels element
)
4510 ;; Handle line numbering.
4511 (num-start (cl-case (org-element-property :number-lines element
)
4512 (continued (org-export-get-loc element info
))
4517 (length (number-to-string
4518 (+ (length code-lines
) num-start
))))))
4519 ;; Prepare references display, if required. Any reference
4520 ;; should start six columns after the widest line of code,
4521 ;; wrapped with parenthesis.
4523 (+ (apply 'max
(mapcar 'length code-lines
))
4524 (if (not num-start
) 0 (length (format num-fmt num-start
))))))
4525 (org-export-format-code
4527 (lambda (loc line-num ref
)
4528 (let ((number-str (and num-fmt
(format num-fmt line-num
))))
4533 (concat (make-string
4535 (+ (length loc
) (length number-str
))) ?
)
4536 (format "(%s)" ref
))))))
4542 ;; `org-export-table-has-special-column-p' and and
4543 ;; `org-export-table-row-is-special-p' are predicates used to look for
4544 ;; meta-information about the table structure.
4546 ;; `org-table-has-header-p' tells when the rows before the first rule
4547 ;; should be considered as table's header.
4549 ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
4550 ;; and `org-export-table-cell-borders' extract information from
4551 ;; a table-cell element.
4553 ;; `org-export-table-dimensions' gives the number on rows and columns
4554 ;; in the table, ignoring horizontal rules and special columns.
4555 ;; `org-export-table-cell-address', given a table-cell object, returns
4556 ;; the absolute address of a cell. On the other hand,
4557 ;; `org-export-get-table-cell-at' does the contrary.
4559 ;; `org-export-table-cell-starts-colgroup-p',
4560 ;; `org-export-table-cell-ends-colgroup-p',
4561 ;; `org-export-table-row-starts-rowgroup-p',
4562 ;; `org-export-table-row-ends-rowgroup-p',
4563 ;; `org-export-table-row-starts-header-p',
4564 ;; `org-export-table-row-ends-header-p' and
4565 ;; `org-export-table-row-in-header-p' indicate position of current row
4566 ;; or cell within the table.
4568 (defun org-export-table-has-special-column-p (table)
4569 "Non-nil when TABLE has a special column.
4570 All special columns will be ignored during export."
4571 ;; The table has a special column when every first cell of every row
4572 ;; has an empty value or contains a symbol among "/", "#", "!", "$",
4573 ;; "*" "_" and "^". Though, do not consider a first row containing
4574 ;; only empty cells as special.
4575 (let ((special-column-p 'empty
))
4577 (dolist (row (org-element-contents table
))
4578 (when (eq (org-element-property :type row
) 'standard
)
4579 (let ((value (org-element-contents
4580 (car (org-element-contents row
)))))
4581 (cond ((member value
'(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
4582 (setq special-column-p
'special
))
4584 (t (throw 'exit nil
))))))
4585 (eq special-column-p
'special
))))
4587 (defun org-export-table-has-header-p (table info
)
4588 "Non-nil when TABLE has a header.
4590 INFO is a plist used as a communication channel.
4592 A table has a header when it contains at least two row groups."
4593 (let ((cache (or (plist-get info
:table-header-cache
)
4594 (plist-get (setq info
4595 (plist-put info
:table-header-cache
4596 (make-hash-table :test
'eq
)))
4597 :table-header-cache
))))
4598 (or (gethash table cache
)
4599 (let ((rowgroup 1) row-flag
)
4602 (org-element-map table
'table-row
4606 ((and row-flag
(eq (org-element-property :type row
) 'rule
))
4607 (cl-incf rowgroup
) (setq row-flag nil
))
4608 ((and (not row-flag
) (eq (org-element-property :type row
)
4610 (setq row-flag t
) nil
)))
4614 (defun org-export-table-row-is-special-p (table-row _
)
4615 "Non-nil if TABLE-ROW is considered special.
4616 All special rows will be ignored during export."
4617 (when (eq (org-element-property :type table-row
) 'standard
)
4618 (let ((first-cell (org-element-contents
4619 (car (org-element-contents table-row
)))))
4620 ;; A row is special either when...
4622 ;; ... it starts with a field only containing "/",
4623 (equal first-cell
'("/"))
4624 ;; ... the table contains a special column and the row start
4625 ;; with a marking character among, "^", "_", "$" or "!",
4626 (and (org-export-table-has-special-column-p
4627 (org-export-get-parent table-row
))
4628 (member first-cell
'(("^") ("_") ("$") ("!"))))
4629 ;; ... it contains only alignment cookies and empty cells.
4630 (let ((special-row-p 'empty
))
4632 (dolist (cell (org-element-contents table-row
))
4633 (let ((value (org-element-contents cell
)))
4634 ;; Since VALUE is a secondary string, the following
4635 ;; checks avoid expanding it with `org-export-data'.
4637 ((and (not (cdr value
))
4638 (stringp (car value
))
4639 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
4641 (setq special-row-p
'cookie
))
4642 (t (throw 'exit nil
)))))
4643 (eq special-row-p
'cookie
)))))))
4645 (defun org-export-table-row-group (table-row info
)
4646 "Return TABLE-ROW's group number, as an integer.
4648 INFO is a plist used as the communication channel.
4650 Return value is the group number, as an integer, or nil for
4651 special rows and rows separators. First group is also table's
4653 (let ((cache (or (plist-get info
:table-row-group-cache
)
4654 (plist-get (setq info
4655 (plist-put info
:table-row-group-cache
4656 (make-hash-table :test
'eq
)))
4657 :table-row-group-cache
))))
4658 (cond ((gethash table-row cache
))
4659 ((eq (org-element-property :type table-row
) 'rule
) nil
)
4660 (t (let ((group 0) row-flag
)
4661 (org-element-map (org-export-get-parent table-row
) 'table-row
4663 (if (eq (org-element-property :type row
) 'rule
)
4665 (unless row-flag
(cl-incf group
) (setq row-flag t
)))
4666 (when (eq table-row row
) (puthash table-row group cache
)))
4667 info
'first-match
))))))
4669 (defun org-export-table-cell-width (table-cell info
)
4670 "Return TABLE-CELL contents width.
4672 INFO is a plist used as the communication channel.
4674 Return value is the width given by the last width cookie in the
4675 same column as TABLE-CELL, or nil."
4676 (let* ((row (org-export-get-parent table-cell
))
4677 (table (org-export-get-parent row
))
4678 (cells (org-element-contents row
))
4679 (columns (length cells
))
4680 (column (- columns
(length (memq table-cell cells
))))
4681 (cache (or (plist-get info
:table-cell-width-cache
)
4682 (plist-get (setq info
4683 (plist-put info
:table-cell-width-cache
4684 (make-hash-table :test
'eq
)))
4685 :table-cell-width-cache
)))
4686 (width-vector (or (gethash table cache
)
4687 (puthash table
(make-vector columns
'empty
) cache
)))
4688 (value (aref width-vector column
)))
4689 (if (not (eq value
'empty
)) value
4691 (dolist (row (org-element-contents table
)
4692 (aset width-vector column cookie-width
))
4693 (when (org-export-table-row-is-special-p row info
)
4694 ;; In a special row, try to find a width cookie at COLUMN.
4695 (let* ((value (org-element-contents
4696 (elt (org-element-contents row
) column
)))
4697 (cookie (car value
)))
4698 ;; The following checks avoid expanding unnecessarily
4699 ;; the cell with `org-export-data'.
4703 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" cookie
)
4704 (match-string 1 cookie
))
4706 (string-to-number (match-string 1 cookie
)))))))))))
4708 (defun org-export-table-cell-alignment (table-cell info
)
4709 "Return TABLE-CELL contents alignment.
4711 INFO is a plist used as the communication channel.
4713 Return alignment as specified by the last alignment cookie in the
4714 same column as TABLE-CELL. If no such cookie is found, a default
4715 alignment value will be deduced from fraction of numbers in the
4716 column (see `org-table-number-fraction' for more information).
4717 Possible values are `left', `right' and `center'."
4718 ;; Load `org-table-number-fraction' and `org-table-number-regexp'.
4719 (require 'org-table
)
4720 (let* ((row (org-export-get-parent table-cell
))
4721 (table (org-export-get-parent row
))
4722 (cells (org-element-contents row
))
4723 (columns (length cells
))
4724 (column (- columns
(length (memq table-cell cells
))))
4725 (cache (or (plist-get info
:table-cell-alignment-cache
)
4726 (plist-get (setq info
4727 (plist-put info
:table-cell-alignment-cache
4728 (make-hash-table :test
'eq
)))
4729 :table-cell-alignment-cache
)))
4730 (align-vector (or (gethash table cache
)
4731 (puthash table
(make-vector columns nil
) cache
))))
4732 (or (aref align-vector column
)
4733 (let ((number-cells 0)
4736 previous-cell-number-p
)
4737 (dolist (row (org-element-contents (org-export-get-parent row
)))
4739 ;; In a special row, try to find an alignment cookie at
4741 ((org-export-table-row-is-special-p row info
)
4742 (let ((value (org-element-contents
4743 (elt (org-element-contents row
) column
))))
4744 ;; Since VALUE is a secondary string, the following
4745 ;; checks avoid useless expansion through
4746 ;; `org-export-data'.
4749 (stringp (car value
))
4750 (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
4752 (match-string 1 (car value
)))
4753 (setq cookie-align
(match-string 1 (car value
))))))
4754 ;; Ignore table rules.
4755 ((eq (org-element-property :type row
) 'rule
))
4756 ;; In a standard row, check if cell's contents are
4757 ;; expressing some kind of number. Increase NUMBER-CELLS
4758 ;; accordingly. Though, don't bother if an alignment
4759 ;; cookie has already defined cell's alignment.
4761 (let ((value (org-export-data
4762 (org-element-contents
4763 (elt (org-element-contents row
) column
))
4765 (cl-incf total-cells
)
4766 ;; Treat an empty cell as a number if it follows
4768 (if (not (or (string-match org-table-number-regexp value
)
4769 (and (string= value
"") previous-cell-number-p
)))
4770 (setq previous-cell-number-p nil
)
4771 (setq previous-cell-number-p t
)
4772 (cl-incf number-cells
))))))
4773 ;; Return value. Alignment specified by cookies has
4774 ;; precedence over alignment deduced from cell's contents.
4777 (cond ((equal cookie-align
"l") 'left
)
4778 ((equal cookie-align
"r") 'right
)
4779 ((equal cookie-align
"c") 'center
)
4780 ((>= (/ (float number-cells
) total-cells
)
4781 org-table-number-fraction
)
4785 (defun org-export-table-cell-borders (table-cell info
)
4786 "Return TABLE-CELL borders.
4788 INFO is a plist used as a communication channel.
4790 Return value is a list of symbols, or nil. Possible values are:
4791 `top', `bottom', `above', `below', `left' and `right'. Note:
4792 `top' (resp. `bottom') only happen for a cell in the first
4793 row (resp. last row) of the table, ignoring table rules, if any.
4795 Returned borders ignore special rows."
4796 (let* ((row (org-export-get-parent table-cell
))
4797 (table (org-export-get-parent-table table-cell
))
4799 ;; Top/above border? TABLE-CELL has a border above when a rule
4800 ;; used to demarcate row groups can be found above. Hence,
4801 ;; finding a rule isn't sufficient to push `above' in BORDERS:
4802 ;; another regular row has to be found above that rule.
4805 ;; Look at every row before the current one.
4806 (dolist (row (cdr (memq row
(reverse (org-element-contents table
)))))
4807 (cond ((eq (org-element-property :type row
) 'rule
)
4809 ((not (org-export-table-row-is-special-p row info
))
4810 (if rule-flag
(throw 'exit
(push 'above borders
))
4811 (throw 'exit nil
)))))
4812 ;; No rule above, or rule found starts the table (ignoring any
4813 ;; special row): TABLE-CELL is at the top of the table.
4814 (when rule-flag
(push 'above borders
))
4815 (push 'top borders
)))
4816 ;; Bottom/below border? TABLE-CELL has a border below when next
4817 ;; non-regular row below is a rule.
4820 ;; Look at every row after the current one.
4821 (dolist (row (cdr (memq row
(org-element-contents table
))))
4822 (cond ((eq (org-element-property :type row
) 'rule
)
4824 ((not (org-export-table-row-is-special-p row info
))
4825 (if rule-flag
(throw 'exit
(push 'below borders
))
4826 (throw 'exit nil
)))))
4827 ;; No rule below, or rule found ends the table (modulo some
4828 ;; special row): TABLE-CELL is at the bottom of the table.
4829 (when rule-flag
(push 'below borders
))
4830 (push 'bottom borders
)))
4831 ;; Right/left borders? They can only be specified by column
4832 ;; groups. Column groups are defined in a row starting with "/".
4833 ;; Also a column groups row only contains "<", "<>", ">" or blank
4836 (let ((column (let ((cells (org-element-contents row
)))
4837 (- (length cells
) (length (memq table-cell cells
))))))
4838 ;; Table rows are read in reverse order so last column groups
4839 ;; row has precedence over any previous one.
4840 (dolist (row (reverse (org-element-contents table
)))
4841 (unless (eq (org-element-property :type row
) 'rule
)
4842 (when (equal (org-element-contents
4843 (car (org-element-contents row
)))
4845 (let ((column-groups
4848 (let ((value (org-element-contents cell
)))
4849 (when (member value
'(("<") ("<>") (">") nil
))
4851 (org-element-contents row
))))
4852 ;; There's a left border when previous cell, if
4853 ;; any, ends a group, or current one starts one.
4854 (when (or (and (not (zerop column
))
4855 (member (elt column-groups
(1- column
))
4857 (member (elt column-groups column
) '("<" "<>")))
4858 (push 'left borders
))
4859 ;; There's a right border when next cell, if any,
4860 ;; starts a group, or current one ends one.
4861 (when (or (and (/= (1+ column
) (length column-groups
))
4862 (member (elt column-groups
(1+ column
))
4864 (member (elt column-groups column
) '(">" "<>")))
4865 (push 'right borders
))
4866 (throw 'exit nil
)))))))
4870 (defun org-export-table-cell-starts-colgroup-p (table-cell info
)
4871 "Non-nil when TABLE-CELL is at the beginning of a column group.
4872 INFO is a plist used as a communication channel."
4873 ;; A cell starts a column group either when it is at the beginning
4874 ;; of a row (or after the special column, if any) or when it has
4876 (or (eq (org-element-map (org-export-get-parent table-cell
) 'table-cell
4877 'identity info
'first-match
)
4879 (memq 'left
(org-export-table-cell-borders table-cell info
))))
4881 (defun org-export-table-cell-ends-colgroup-p (table-cell info
)
4882 "Non-nil when TABLE-CELL is at the end of a column group.
4883 INFO is a plist used as a communication channel."
4884 ;; A cell ends a column group either when it is at the end of a row
4885 ;; or when it has a right border.
4886 (or (eq (car (last (org-element-contents
4887 (org-export-get-parent table-cell
))))
4889 (memq 'right
(org-export-table-cell-borders table-cell info
))))
4891 (defun org-export-table-row-starts-rowgroup-p (table-row info
)
4892 "Non-nil when TABLE-ROW is at the beginning of a row group.
4893 INFO is a plist used as a communication channel."
4894 (unless (or (eq (org-element-property :type table-row
) 'rule
)
4895 (org-export-table-row-is-special-p table-row info
))
4896 (let ((borders (org-export-table-cell-borders
4897 (car (org-element-contents table-row
)) info
)))
4898 (or (memq 'top borders
) (memq 'above borders
)))))
4900 (defun org-export-table-row-ends-rowgroup-p (table-row info
)
4901 "Non-nil when TABLE-ROW is at the end of a row group.
4902 INFO is a plist used as a communication channel."
4903 (unless (or (eq (org-element-property :type table-row
) 'rule
)
4904 (org-export-table-row-is-special-p table-row info
))
4905 (let ((borders (org-export-table-cell-borders
4906 (car (org-element-contents table-row
)) info
)))
4907 (or (memq 'bottom borders
) (memq 'below borders
)))))
4909 (defun org-export-table-row-in-header-p (table-row info
)
4910 "Non-nil when TABLE-ROW is located within table's header.
4911 INFO is a plist used as a communication channel. Always return
4912 nil for special rows and rows separators."
4913 (and (org-export-table-has-header-p
4914 (org-export-get-parent-table table-row
) info
)
4915 (eql (org-export-table-row-group table-row info
) 1)))
4917 (defun org-export-table-row-starts-header-p (table-row info
)
4918 "Non-nil when TABLE-ROW is the first table header's row.
4919 INFO is a plist used as a communication channel."
4920 (and (org-export-table-row-in-header-p table-row info
)
4921 (org-export-table-row-starts-rowgroup-p table-row info
)))
4923 (defun org-export-table-row-ends-header-p (table-row info
)
4924 "Non-nil when TABLE-ROW is the last table header's row.
4925 INFO is a plist used as a communication channel."
4926 (and (org-export-table-row-in-header-p table-row info
)
4927 (org-export-table-row-ends-rowgroup-p table-row info
)))
4929 (defun org-export-table-row-number (table-row info
)
4930 "Return TABLE-ROW number.
4931 INFO is a plist used as a communication channel. Return value is
4932 zero-based and ignores separators. The function returns nil for
4933 special columns and separators."
4934 (when (and (eq (org-element-property :type table-row
) 'standard
)
4935 (not (org-export-table-row-is-special-p table-row info
)))
4937 (org-element-map (org-export-get-parent-table table-row
) 'table-row
4939 (cond ((eq row table-row
) number
)
4940 ((eq (org-element-property :type row
) 'standard
)
4941 (cl-incf number
) nil
)))
4942 info
'first-match
))))
4944 (defun org-export-table-dimensions (table info
)
4945 "Return TABLE dimensions.
4947 INFO is a plist used as a communication channel.
4949 Return value is a CONS like (ROWS . COLUMNS) where
4950 ROWS (resp. COLUMNS) is the number of exportable
4951 rows (resp. columns)."
4952 (let (first-row (columns 0) (rows 0))
4953 ;; Set number of rows, and extract first one.
4954 (org-element-map table
'table-row
4956 (when (eq (org-element-property :type row
) 'standard
)
4958 (unless first-row
(setq first-row row
)))) info
)
4959 ;; Set number of columns.
4960 (org-element-map first-row
'table-cell
(lambda (_) (cl-incf columns
)) info
)
4962 (cons rows columns
)))
4964 (defun org-export-table-cell-address (table-cell info
)
4965 "Return address of a regular TABLE-CELL object.
4967 TABLE-CELL is the cell considered. INFO is a plist used as
4968 a communication channel.
4970 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4971 zero-based index. Only exportable cells are considered. The
4972 function returns nil for other cells."
4973 (let* ((table-row (org-export-get-parent table-cell
))
4974 (row-number (org-export-table-row-number table-row info
)))
4977 (let ((col-count 0))
4978 (org-element-map table-row
'table-cell
4980 (if (eq cell table-cell
) col-count
(cl-incf col-count
) nil
))
4981 info
'first-match
))))))
4983 (defun org-export-get-table-cell-at (address table info
)
4984 "Return regular table-cell object at ADDRESS in TABLE.
4986 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4987 zero-based index. TABLE is a table type element. INFO is
4988 a plist used as a communication channel.
4990 If no table-cell, among exportable cells, is found at ADDRESS,
4992 (let ((column-pos (cdr address
)) (column-count 0))
4994 ;; Row at (car address) or nil.
4995 (let ((row-pos (car address
)) (row-count 0))
4996 (org-element-map table
'table-row
4998 (cond ((eq (org-element-property :type row
) 'rule
) nil
)
4999 ((= row-count row-pos
) row
)
5000 (t (cl-incf row-count
) nil
)))
5004 (if (= column-count column-pos
) cell
5005 (cl-incf column-count
) nil
))
5006 info
'first-match
)))
5009 ;;;; For Tables Of Contents
5011 ;; `org-export-collect-headlines' builds a list of all exportable
5012 ;; headline elements, maybe limited to a certain depth. One can then
5013 ;; easily parse it and transcode it.
5015 ;; Building lists of tables, figures or listings is quite similar.
5016 ;; Once the generic function `org-export-collect-elements' is defined,
5017 ;; `org-export-collect-tables', `org-export-collect-figures' and
5018 ;; `org-export-collect-listings' can be derived from it.
5020 (defun org-export-collect-headlines (info &optional n scope
)
5021 "Collect headlines in order to build a table of contents.
5023 INFO is a plist used as a communication channel.
5025 When optional argument N is an integer, it specifies the depth of
5026 the table of contents. Otherwise, it is set to the value of the
5027 last headline level. See `org-export-headline-levels' for more
5030 Optional argument SCOPE, when non-nil, is an element. If it is
5031 a headline, only children of SCOPE are collected. Otherwise,
5032 collect children of the headline containing provided element. If
5033 there is no such headline, collect all headlines. In any case,
5034 argument N becomes relative to the level of that headline.
5036 Return a list of all exportable headlines as parsed elements.
5037 Footnote sections are ignored."
5038 (let* ((scope (cond ((not scope
) (plist-get info
:parse-tree
))
5039 ((eq (org-element-type scope
) 'headline
) scope
)
5040 ((org-export-get-parent-headline scope
))
5041 (t (plist-get info
:parse-tree
))))
5042 (limit (plist-get info
:headline-levels
))
5043 (n (if (not (wholenump n
)) limit
5044 (min (if (eq (org-element-type scope
) 'org-data
) n
5045 (+ (org-export-get-relative-level scope info
) n
))
5047 (org-element-map (org-element-contents scope
) 'headline
5049 (unless (org-element-property :footnote-section-p headline
)
5050 (let ((level (org-export-get-relative-level headline info
)))
5051 (and (<= level n
) headline
))))
5054 (defun org-export-collect-elements (type info
&optional predicate
)
5055 "Collect referenceable elements of a determined type.
5057 TYPE can be a symbol or a list of symbols specifying element
5058 types to search. Only elements with a caption are collected.
5060 INFO is a plist used as a communication channel.
5062 When non-nil, optional argument PREDICATE is a function accepting
5063 one argument, an element of type TYPE. It returns a non-nil
5064 value when that element should be collected.
5066 Return a list of all elements found, in order of appearance."
5067 (org-element-map (plist-get info
:parse-tree
) type
5069 (and (org-element-property :caption element
)
5070 (or (not predicate
) (funcall predicate element
))
5074 (defun org-export-collect-tables (info)
5075 "Build a list of tables.
5076 INFO is a plist used as a communication channel.
5078 Return a list of table elements with a caption."
5079 (org-export-collect-elements 'table info
))
5081 (defun org-export-collect-figures (info predicate
)
5082 "Build a list of figures.
5084 INFO is a plist used as a communication channel. PREDICATE is
5085 a function which accepts one argument: a paragraph element and
5086 whose return value is non-nil when that element should be
5089 A figure is a paragraph type element, with a caption, verifying
5090 PREDICATE. The latter has to be provided since a \"figure\" is
5091 a vague concept that may depend on back-end.
5093 Return a list of elements recognized as figures."
5094 (org-export-collect-elements 'paragraph info predicate
))
5096 (defun org-export-collect-listings (info)
5097 "Build a list of src blocks.
5099 INFO is a plist used as a communication channel.
5101 Return a list of src-block elements with a caption."
5102 (org-export-collect-elements 'src-block info
))
5107 ;; The main function for the smart quotes sub-system is
5108 ;; `org-export-activate-smart-quotes', which replaces every quote in
5109 ;; a given string from the parse tree with its "smart" counterpart.
5111 ;; Dictionary for smart quotes is stored in
5112 ;; `org-export-smart-quotes-alist'.
5114 (defconst org-export-smart-quotes-alist
5116 ;; one may use: »...«, "...", ›...‹, or '...'.
5117 ;; http://sproget.dk/raad-og-regler/retskrivningsregler/retskrivningsregler/a7-40-60/a7-58-anforselstegn/
5118 ;; LaTeX quotes require Babel!
5120 :utf-8
"»" :html
"»" :latex
">>" :texinfo
"@guillemetright{}")
5122 :utf-8
"«" :html
"«" :latex
"<<" :texinfo
"@guillemetleft{}")
5124 :utf-8
"›" :html
"›" :latex
"\\frq{}" :texinfo
"@guilsinglright{}")
5126 :utf-8
"‹" :html
"‹" :latex
"\\flq{}" :texinfo
"@guilsingleft{}")
5127 (apostrophe :utf-8
"’" :html
"’"))
5130 :utf-8
"„" :html
"„" :latex
"\"`" :texinfo
"@quotedblbase{}")
5132 :utf-8
"“" :html
"“" :latex
"\"'" :texinfo
"@quotedblleft{}")
5134 :utf-8
"‚" :html
"‚" :latex
"\\glq{}" :texinfo
"@quotesinglbase{}")
5136 :utf-8
"‘" :html
"‘" :latex
"\\grq{}" :texinfo
"@quoteleft{}")
5137 (apostrophe :utf-8
"’" :html
"’"))
5139 (primary-opening :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
5140 (primary-closing :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
5141 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5142 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5143 (apostrophe :utf-8
"’" :html
"’"))
5146 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5147 :texinfo
"@guillemetleft{}")
5149 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5150 :texinfo
"@guillemetright{}")
5151 (secondary-opening :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
5152 (secondary-closing :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
5153 (apostrophe :utf-8
"’" :html
"’"))
5156 :utf-8
"« " :html
"« " :latex
"\\og "
5157 :texinfo
"@guillemetleft{}@tie{}")
5159 :utf-8
" »" :html
" »" :latex
"\\fg{}"
5160 :texinfo
"@tie{}@guillemetright{}")
5162 :utf-8
"« " :html
"« " :latex
"\\og "
5163 :texinfo
"@guillemetleft{}@tie{}")
5164 (secondary-closing :utf-8
" »" :html
" »" :latex
"\\fg{}"
5165 :texinfo
"@tie{}@guillemetright{}")
5166 (apostrophe :utf-8
"’" :html
"’"))
5168 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5170 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5171 :texinfo
"@guillemetleft{}")
5173 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5174 :texinfo
"@guillemetright{}")
5175 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5176 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5177 (apostrophe :utf-8
"’" :html
"’"))
5179 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5181 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5182 :texinfo
"@guillemetleft{}")
5184 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5185 :texinfo
"@guillemetright{}")
5186 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5187 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5188 (apostrophe :utf-8
"’" :html
"’"))
5190 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5192 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5193 :texinfo
"@guillemetleft{}")
5195 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5196 :texinfo
"@guillemetright{}")
5197 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5198 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5199 (apostrophe :utf-8
"’" :html
"’"))
5201 ;; http://ru.wikipedia.org/wiki/%D0%9A%D0%B0%D0%B2%D1%8B%D1%87%D0%BA%D0%B8#.D0.9A.D0.B0.D0.B2.D1.8B.D1.87.D0.BA.D0.B8.2C_.D0.B8.D1.81.D0.BF.D0.BE.D0.BB.D1.8C.D0.B7.D1.83.D0.B5.D0.BC.D1.8B.D0.B5_.D0.B2_.D1.80.D1.83.D1.81.D1.81.D0.BA.D0.BE.D0.BC_.D1.8F.D0.B7.D1.8B.D0.BA.D0.B5
5202 ;; http://www.artlebedev.ru/kovodstvo/sections/104/
5203 (primary-opening :utf-8
"«" :html
"«" :latex
"{}<<"
5204 :texinfo
"@guillemetleft{}")
5205 (primary-closing :utf-8
"»" :html
"»" :latex
">>{}"
5206 :texinfo
"@guillemetright{}")
5208 :utf-8
"„" :html
"„" :latex
"\\glqq{}" :texinfo
"@quotedblbase{}")
5210 :utf-8
"“" :html
"“" :latex
"\\grqq{}" :texinfo
"@quotedblleft{}")
5211 (apostrophe :utf-8
"’" :html
: "'"))
5213 ;; based on https://sv.wikipedia.org/wiki/Citattecken
5214 (primary-opening :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
5215 (primary-closing :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
5216 (secondary-opening :utf-8
"’" :html
"’" :latex
"’" :texinfo
"`")
5217 (secondary-closing :utf-8
"’" :html
"’" :latex
"’" :texinfo
"'")
5218 (apostrophe :utf-8
"’" :html
"’")))
5219 "Smart quotes translations.
5221 Alist whose CAR is a language string and CDR is an alist with
5222 quote type as key and a plist associating various encodings to
5223 their translation as value.
5225 A quote type can be any symbol among `primary-opening',
5226 `primary-closing', `secondary-opening', `secondary-closing' and
5229 Valid encodings include `:utf-8', `:html', `:latex' and
5232 If no translation is found, the quote character is left as-is.")
5234 (defun org-export--smart-quote-status (s info
)
5235 "Return smart quote status at the beginning of string S.
5236 INFO is the current export state, as a plist."
5237 (let* ((parent (org-element-property :parent s
))
5238 (cache (or (plist-get info
:smart-quote-cache
)
5239 (let ((table (make-hash-table :test
#'eq
)))
5240 (plist-put info
:smart-quote-cache table
)
5242 (value (gethash parent cache
'missing-data
)))
5243 (if (not (eq value
'missing-data
)) (cdr (assq s value
))
5244 (let (level1-open full-status
)
5245 (org-element-map parent
'plain-text
5247 (let ((start 0) current-status
)
5248 (while (setq start
(string-match "['\"]" text start
))
5251 ((equal (match-string 0 text
) "\"")
5252 (setf level1-open
(not level1-open
))
5253 (if level1-open
'primary-opening
'primary-closing
))
5254 ;; Not already in a level 1 quote: this is an
5256 ((not level1-open
) 'apostrophe
)
5257 ;; Extract previous char and next char. As
5258 ;; a special case, they can also be set to `blank',
5259 ;; `no-blank' or nil. Then determine if current
5260 ;; match is allowed as an opening quote or a closing
5264 (if (> start
0) (substring text
(1- start
) start
)
5265 (let ((p (org-export-get-previous-element
5268 ((stringp p
) (substring p
(1- (length p
))))
5269 ((memq (org-element-property :post-blank p
)
5274 (if (< (1+ start
) (length text
))
5275 (substring text
(1+ start
) (+ start
2))
5276 (let ((n (org-export-get-next-element text info
)))
5278 ((stringp n
) (substring n
0 1))
5281 (and (if (stringp previous
)
5282 (string-match "\\s\"\\|\\s-\\|\\s("
5284 (memq previous
'(blank nil
)))
5286 (string-match "\\w\\|\\s.\\|\\s_" next
)
5287 (eq next
'no-blank
))))
5289 (and (if (stringp previous
)
5290 (string-match "\\w\\|\\s.\\|\\s_" previous
)
5291 (eq previous
'no-blank
))
5293 (string-match "\\s-\\|\\s)\\|\\s.\\|\\s\""
5295 (memq next
'(blank nil
))))))
5297 ((and allow-open allow-close
) (error "Should not happen"))
5298 (allow-open 'secondary-opening
)
5299 (allow-close 'secondary-closing
)
5303 (when current-status
5304 (push (cons text
(nreverse current-status
)) full-status
))))
5305 info nil org-element-recursive-objects
)
5306 (puthash parent full-status cache
)
5307 (cdr (assq s full-status
))))))
5309 (defun org-export-activate-smart-quotes (s encoding info
&optional original
)
5310 "Replace regular quotes with \"smart\" quotes in string S.
5312 ENCODING is a symbol among `:html', `:latex', `:texinfo' and
5313 `:utf-8'. INFO is a plist used as a communication channel.
5315 The function has to retrieve information about string
5316 surroundings in parse tree. It can only happen with an
5317 unmodified string. Thus, if S has already been through another
5318 process, a non-nil ORIGINAL optional argument will provide that
5321 Return the new string."
5323 (copy-sequence (org-export--smart-quote-status (or original s
) info
))))
5324 (replace-regexp-in-string
5328 (cdr (assq (pop quote-status
)
5329 (cdr (assoc (plist-get info
:language
)
5330 org-export-smart-quotes-alist
))))
5337 ;; Here are various functions to retrieve information about the
5338 ;; neighborhood of a given element or object. Neighbors of interest
5339 ;; are direct parent (`org-export-get-parent'), parent headline
5340 ;; (`org-export-get-parent-headline'), first element containing an
5341 ;; object, (`org-export-get-parent-element'), parent table
5342 ;; (`org-export-get-parent-table'), previous element or object
5343 ;; (`org-export-get-previous-element') and next element or object
5344 ;; (`org-export-get-next-element').
5346 ;; defsubst org-export-get-parent must be defined before first use
5348 (define-obsolete-function-alias
5349 'org-export-get-genealogy
'org-element-lineage
"25.1")
5351 (defun org-export-get-parent-headline (blob)
5352 "Return BLOB parent headline or nil.
5353 BLOB is the element or object being considered."
5354 (org-element-lineage blob
'(headline)))
5356 (defun org-export-get-parent-element (object)
5357 "Return first element containing OBJECT or nil.
5358 OBJECT is the object to consider."
5359 (org-element-lineage object org-element-all-elements
))
5361 (defun org-export-get-parent-table (object)
5362 "Return OBJECT parent table or nil.
5363 OBJECT is either a `table-cell' or `table-element' type object."
5364 (org-element-lineage object
'(table)))
5366 (defun org-export-get-previous-element (blob info
&optional n
)
5367 "Return previous element or object.
5369 BLOB is an element or object. INFO is a plist used as
5370 a communication channel. Return previous exportable element or
5371 object, a string, or nil.
5373 When optional argument N is a positive integer, return a list
5374 containing up to N siblings before BLOB, from farthest to
5375 closest. With any other non-nil value, return a list containing
5377 (let* ((secondary (org-element-secondary-p blob
))
5378 (parent (org-export-get-parent blob
))
5380 (if secondary
(org-element-property secondary parent
)
5381 (org-element-contents parent
)))
5384 (dolist (obj (cdr (memq blob
(reverse siblings
))) prev
)
5385 (cond ((memq obj
(plist-get info
:ignore-list
)))
5386 ((null n
) (throw 'exit obj
))
5387 ((not (wholenump n
)) (push obj prev
))
5388 ((zerop n
) (throw 'exit prev
))
5389 (t (cl-decf n
) (push obj prev
)))))))
5391 (defun org-export-get-next-element (blob info
&optional n
)
5392 "Return next element or object.
5394 BLOB is an element or object. INFO is a plist used as
5395 a communication channel. Return next exportable element or
5396 object, a string, or nil.
5398 When optional argument N is a positive integer, return a list
5399 containing up to N siblings after BLOB, from closest to farthest.
5400 With any other non-nil value, return a list containing all of
5402 (let* ((secondary (org-element-secondary-p blob
))
5403 (parent (org-export-get-parent blob
))
5406 (if secondary
(org-element-property secondary parent
)
5407 (org-element-contents parent
)))))
5410 (dolist (obj siblings
(nreverse next
))
5411 (cond ((memq obj
(plist-get info
:ignore-list
)))
5412 ((null n
) (throw 'exit obj
))
5413 ((not (wholenump n
)) (push obj next
))
5414 ((zerop n
) (throw 'exit
(nreverse next
)))
5415 (t (cl-decf n
) (push obj next
)))))))
5420 ;; `org-export-translate' translates a string according to the language
5421 ;; specified by the LANGUAGE keyword. `org-export-dictionary' contains
5422 ;; the dictionary used for the translation.
5424 (defconst org-export-dictionary
5426 ("fr" :default
"%e %n : %c" :html
"%e %n : %c"))
5428 ("ca" :default
"Autor")
5429 ("cs" :default
"Autor")
5430 ("da" :default
"Forfatter")
5431 ("de" :default
"Autor")
5432 ("eo" :html
"Aŭtoro")
5433 ("es" :default
"Autor")
5434 ("et" :default
"Autor")
5435 ("fi" :html
"Tekijä")
5436 ("fr" :default
"Auteur")
5437 ("hu" :default
"Szerzõ")
5438 ("is" :html
"Höfundur")
5439 ("it" :default
"Autore")
5440 ("ja" :default
"著者" :html
"著者")
5441 ("nl" :default
"Auteur")
5442 ("no" :default
"Forfatter")
5443 ("nb" :default
"Forfatter")
5444 ("nn" :default
"Forfattar")
5445 ("pl" :default
"Autor")
5446 ("pt_BR" :default
"Autor")
5447 ("ru" :html
"Автор" :utf-8
"Автор")
5448 ("sv" :html
"Författare")
5449 ("uk" :html
"Автор" :utf-8
"Автор")
5450 ("zh-CN" :html
"作者" :utf-8
"作者")
5451 ("zh-TW" :html
"作者" :utf-8
"作者"))
5452 ("Continued from previous page"
5453 ("de" :default
"Fortsetzung von vorheriger Seite")
5454 ("es" :html
"Continúa de la página anterior" :ascii
"Continua de la pagina anterior" :default
"Continúa de la página anterior")
5455 ("fr" :default
"Suite de la page précédente")
5456 ("it" :default
"Continua da pagina precedente")
5457 ("ja" :default
"前ページからの続き")
5458 ("nl" :default
"Vervolg van vorige pagina")
5459 ("pt" :default
"Continuação da página anterior")
5460 ("ru" :html
"(Продолжение)"
5461 :utf-8
"(Продолжение)"))
5462 ("Continued on next page"
5463 ("de" :default
"Fortsetzung nächste Seite")
5464 ("es" :html
"Continúa en la siguiente página" :ascii
"Continua en la siguiente pagina" :default
"Continúa en la siguiente página")
5465 ("fr" :default
"Suite page suivante")
5466 ("it" :default
"Continua alla pagina successiva")
5467 ("ja" :default
"次ページに続く")
5468 ("nl" :default
"Vervolg op volgende pagina")
5469 ("pt" :default
"Continua na página seguinte")
5470 ("ru" :html
"(Продолжение следует)"
5471 :utf-8
"(Продолжение следует)"))
5473 ("ca" :default
"Data")
5474 ("cs" :default
"Datum")
5475 ("da" :default
"Dato")
5476 ("de" :default
"Datum")
5477 ("eo" :default
"Dato")
5478 ("es" :default
"Fecha")
5479 ("et" :html
"Kuupäev" :utf-8
"Kuupäev")
5480 ("fi" :html
"Päivämäärä")
5481 ("hu" :html
"Dátum")
5482 ("is" :default
"Dagsetning")
5483 ("it" :default
"Data")
5484 ("ja" :default
"日付" :html
"日付")
5485 ("nl" :default
"Datum")
5486 ("no" :default
"Dato")
5487 ("nb" :default
"Dato")
5488 ("nn" :default
"Dato")
5489 ("pl" :default
"Data")
5490 ("pt_BR" :default
"Data")
5491 ("ru" :html
"Дата" :utf-8
"Дата")
5492 ("sv" :default
"Datum")
5493 ("uk" :html
"Дата" :utf-8
"Дата")
5494 ("zh-CN" :html
"日期" :utf-8
"日期")
5495 ("zh-TW" :html
"日期" :utf-8
"日期"))
5497 ("da" :default
"Ligning")
5498 ("de" :default
"Gleichung")
5499 ("es" :ascii
"Ecuacion" :html
"Ecuación" :default
"Ecuación")
5500 ("et" :html
"Võrrand" :utf-8
"Võrrand")
5501 ("fr" :ascii
"Equation" :default
"Équation")
5502 ("ja" :default
"方程式")
5503 ("no" :default
"Ligning")
5504 ("nb" :default
"Ligning")
5505 ("nn" :default
"Likning")
5506 ("pt_BR" :html
"Equação" :default
"Equação" :ascii
"Equacao")
5507 ("ru" :html
"Уравнение"
5509 ("sv" :default
"Ekvation")
5510 ("zh-CN" :html
"方程" :utf-8
"方程"))
5512 ("da" :default
"Figur")
5513 ("de" :default
"Abbildung")
5514 ("es" :default
"Figura")
5515 ("et" :default
"Joonis")
5516 ("ja" :default
"図" :html
"図")
5517 ("no" :default
"Illustrasjon")
5518 ("nb" :default
"Illustrasjon")
5519 ("nn" :default
"Illustrasjon")
5520 ("pt_BR" :default
"Figura")
5521 ("ru" :html
"Рисунок" :utf-8
"Рисунок")
5522 ("sv" :default
"Illustration")
5523 ("zh-CN" :html
"图" :utf-8
"图"))
5525 ("da" :default
"Figur %d")
5526 ("de" :default
"Abbildung %d:")
5527 ("es" :default
"Figura %d:")
5528 ("et" :default
"Joonis %d:")
5529 ("fr" :default
"Figure %d :" :html
"Figure %d :")
5530 ("ja" :default
"図%d: " :html
"図%d: ")
5531 ("no" :default
"Illustrasjon %d")
5532 ("nb" :default
"Illustrasjon %d")
5533 ("nn" :default
"Illustrasjon %d")
5534 ("pt_BR" :default
"Figura %d:")
5535 ("ru" :html
"Рис. %d.:" :utf-8
"Рис. %d.:")
5536 ("sv" :default
"Illustration %d")
5537 ("zh-CN" :html
"图%d " :utf-8
"图%d "))
5539 ("ca" :html
"Peus de pàgina")
5540 ("cs" :default
"Pozn\xe1mky pod carou")
5541 ("da" :default
"Fodnoter")
5542 ("de" :html
"Fußnoten" :default
"Fußnoten")
5543 ("eo" :default
"Piednotoj")
5544 ("es" :ascii
"Nota al pie de pagina" :html
"Nota al pie de página" :default
"Nota al pie de página")
5545 ("et" :html
"Allmärkused" :utf-8
"Allmärkused")
5546 ("fi" :default
"Alaviitteet")
5547 ("fr" :default
"Notes de bas de page")
5548 ("hu" :html
"Lábjegyzet")
5549 ("is" :html
"Aftanmálsgreinar")
5550 ("it" :html
"Note a piè di pagina")
5551 ("ja" :default
"脚注" :html
"脚注")
5552 ("nl" :default
"Voetnoten")
5553 ("no" :default
"Fotnoter")
5554 ("nb" :default
"Fotnoter")
5555 ("nn" :default
"Fotnotar")
5556 ("pl" :default
"Przypis")
5557 ("pt_BR" :html
"Notas de Rodapé" :default
"Notas de Rodapé" :ascii
"Notas de Rodape")
5558 ("ru" :html
"Сноски" :utf-8
"Сноски")
5559 ("sv" :default
"Fotnoter")
5560 ("uk" :html
"Примітки"
5562 ("zh-CN" :html
"脚注" :utf-8
"脚注")
5563 ("zh-TW" :html
"腳註" :utf-8
"腳註"))
5565 ("da" :default
"Programmer")
5566 ("de" :default
"Programmauflistungsverzeichnis")
5567 ("es" :ascii
"Indice de Listados de programas" :html
"Índice de Listados de programas" :default
"Índice de Listados de programas")
5568 ("et" :default
"Loendite nimekiri")
5569 ("fr" :default
"Liste des programmes")
5570 ("ja" :default
"ソースコード目次")
5571 ("no" :default
"Dataprogrammer")
5572 ("nb" :default
"Dataprogrammer")
5573 ("ru" :html
"Список распечаток"
5574 :utf-8
"Список распечаток")
5575 ("zh-CN" :html
"代码目录" :utf-8
"代码目录"))
5577 ("da" :default
"Tabeller")
5578 ("de" :default
"Tabellenverzeichnis")
5579 ("es" :ascii
"Indice de tablas" :html
"Índice de tablas" :default
"Índice de tablas")
5580 ("et" :default
"Tabelite nimekiri")
5581 ("fr" :default
"Liste des tableaux")
5582 ("ja" :default
"表目次")
5583 ("no" :default
"Tabeller")
5584 ("nb" :default
"Tabeller")
5585 ("nn" :default
"Tabeller")
5586 ("pt_BR" :default
"Índice de Tabelas" :ascii
"Indice de Tabelas")
5587 ("ru" :html
"Список таблиц"
5588 :utf-8
"Список таблиц")
5589 ("sv" :default
"Tabeller")
5590 ("zh-CN" :html
"表格目录" :utf-8
"表格目录"))
5592 ("da" :default
"Program")
5593 ("de" :default
"Programmlisting")
5594 ("es" :default
"Listado de programa")
5595 ("et" :default
"Loend")
5596 ("fr" :default
"Programme" :html
"Programme")
5597 ("ja" :default
"ソースコード")
5598 ("no" :default
"Dataprogram")
5599 ("nb" :default
"Dataprogram")
5600 ("pt_BR" :default
"Listagem")
5601 ("ru" :html
"Распечатка"
5602 :utf-8
"Распечатка")
5603 ("zh-CN" :html
"代码" :utf-8
"代码"))
5605 ("da" :default
"Program %d")
5606 ("de" :default
"Programmlisting %d")
5607 ("es" :default
"Listado de programa %d")
5608 ("et" :default
"Loend %d")
5609 ("fr" :default
"Programme %d :" :html
"Programme %d :")
5610 ("ja" :default
"ソースコード%d:")
5611 ("no" :default
"Dataprogram %d")
5612 ("nb" :default
"Dataprogram %d")
5613 ("pt_BR" :default
"Listagem %d")
5614 ("ru" :html
"Распечатка %d.:"
5615 :utf-8
"Распечатка %d.:")
5616 ("zh-CN" :html
"代码%d " :utf-8
"代码%d "))
5618 ("fr" :ascii
"References" :default
"Références")
5619 ("de" :default
"Quellen")
5620 ("es" :default
"Referencias"))
5622 ("da" :default
"jævnfør afsnit %s")
5623 ("de" :default
"siehe Abschnitt %s")
5624 ("es" :ascii
"Vea seccion %s" :html
"Vea sección %s" :default
"Vea sección %s")
5625 ("et" :html
"Vaata peatükki %s" :utf-8
"Vaata peatükki %s")
5626 ("fr" :default
"cf. section %s")
5627 ("ja" :default
"セクション %s を参照")
5628 ("pt_BR" :html
"Veja a seção %s" :default
"Veja a seção %s"
5629 :ascii
"Veja a secao %s")
5630 ("ru" :html
"См. раздел %s"
5631 :utf-8
"См. раздел %s")
5632 ("zh-CN" :html
"参见第%s节" :utf-8
"参见第%s节"))
5634 ("de" :default
"Tabelle")
5635 ("es" :default
"Tabla")
5636 ("et" :default
"Tabel")
5637 ("fr" :default
"Tableau")
5638 ("ja" :default
"表" :html
"表")
5639 ("pt_BR" :default
"Tabela")
5640 ("ru" :html
"Таблица"
5642 ("zh-CN" :html
"表" :utf-8
"表"))
5644 ("da" :default
"Tabel %d")
5645 ("de" :default
"Tabelle %d")
5646 ("es" :default
"Tabla %d")
5647 ("et" :default
"Tabel %d")
5648 ("fr" :default
"Tableau %d :")
5649 ("ja" :default
"表%d:" :html
"表%d:")
5650 ("no" :default
"Tabell %d")
5651 ("nb" :default
"Tabell %d")
5652 ("nn" :default
"Tabell %d")
5653 ("pt_BR" :default
"Tabela %d")
5654 ("ru" :html
"Таблица %d.:"
5655 :utf-8
"Таблица %d.:")
5656 ("sv" :default
"Tabell %d")
5657 ("zh-CN" :html
"表%d " :utf-8
"表%d "))
5658 ("Table of Contents"
5659 ("ca" :html
"Índex")
5660 ("cs" :default
"Obsah")
5661 ("da" :default
"Indhold")
5662 ("de" :default
"Inhaltsverzeichnis")
5663 ("eo" :default
"Enhavo")
5664 ("es" :ascii
"Indice" :html
"Índice" :default
"Índice")
5665 ("et" :default
"Sisukord")
5666 ("fi" :html
"Sisällysluettelo")
5667 ("fr" :ascii
"Sommaire" :default
"Table des matières")
5668 ("hu" :html
"Tartalomjegyzék")
5669 ("is" :default
"Efnisyfirlit")
5670 ("it" :default
"Indice")
5671 ("ja" :default
"目次" :html
"目次")
5672 ("nl" :default
"Inhoudsopgave")
5673 ("no" :default
"Innhold")
5674 ("nb" :default
"Innhold")
5675 ("nn" :default
"Innhald")
5676 ("pl" :html
"Spis treści")
5677 ("pt_BR" :html
"Índice" :utf8
"Índice" :ascii
"Indice")
5678 ("ru" :html
"Содержание"
5679 :utf-8
"Содержание")
5680 ("sv" :html
"Innehåll")
5681 ("uk" :html
"Зміст" :utf-8
"Зміст")
5682 ("zh-CN" :html
"目录" :utf-8
"目录")
5683 ("zh-TW" :html
"目錄" :utf-8
"目錄"))
5684 ("Unknown reference"
5685 ("da" :default
"ukendt reference")
5686 ("de" :default
"Unbekannter Verweis")
5687 ("es" :default
"Referencia desconocida")
5688 ("et" :default
"Tundmatu viide")
5689 ("fr" :ascii
"Destination inconnue" :default
"Référence inconnue")
5690 ("ja" :default
"不明な参照先")
5691 ("pt_BR" :default
"Referência desconhecida"
5692 :ascii
"Referencia desconhecida")
5693 ("ru" :html
"Неизвестная ссылка"
5694 :utf-8
"Неизвестная ссылка")
5695 ("zh-CN" :html
"未知引用" :utf-8
"未知引用")))
5696 "Dictionary for export engine.
5698 Alist whose car is the string to translate and cdr is an alist
5699 whose car is the language string and cdr is a plist whose
5700 properties are possible charsets and values translated terms.
5702 It is used as a database for `org-export-translate'. Since this
5703 function returns the string as-is if no translation was found,
5704 the variable only needs to record values different from the
5707 (defun org-export-translate (s encoding info
)
5708 "Translate string S according to language specification.
5710 ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
5711 and `:utf-8'. INFO is a plist used as a communication channel.
5713 Translation depends on `:language' property. Return the
5714 translated string. If no translation is found, try to fall back
5715 to `:default' encoding. If it fails, return S."
5716 (let* ((lang (plist-get info
:language
))
5717 (translations (cdr (assoc lang
5718 (cdr (assoc s org-export-dictionary
))))))
5719 (or (plist-get translations encoding
)
5720 (plist-get translations
:default
)
5725 ;;; Asynchronous Export
5727 ;; `org-export-async-start' is the entry point for asynchronous
5728 ;; export. It recreates current buffer (including visibility,
5729 ;; narrowing and visited file) in an external Emacs process, and
5730 ;; evaluates a command there. It then applies a function on the
5731 ;; returned results in the current process.
5733 ;; At a higher level, `org-export-to-buffer' and `org-export-to-file'
5734 ;; allow to export to a buffer or a file, asynchronously or not.
5736 ;; `org-export-output-file-name' is an auxiliary function meant to be
5737 ;; used with `org-export-to-file'. With a given extension, it tries
5738 ;; to provide a canonical file name to write export output to.
5740 ;; Asynchronously generated results are never displayed directly.
5741 ;; Instead, they are stored in `org-export-stack-contents'. They can
5742 ;; then be retrieved by calling `org-export-stack'.
5744 ;; Export Stack is viewed through a dedicated major mode
5745 ;;`org-export-stack-mode' and tools: `org-export-stack-refresh',
5746 ;;`org-export-stack-delete', `org-export-stack-view' and
5747 ;;`org-export-stack-clear'.
5749 ;; For back-ends, `org-export-add-to-stack' add a new source to stack.
5750 ;; It should be used whenever `org-export-async-start' is called.
5752 (defmacro org-export-async-start
(fun &rest body
)
5753 "Call function FUN on the results returned by BODY evaluation.
5755 FUN is an anonymous function of one argument. BODY evaluation
5756 happens in an asynchronous process, from a buffer which is an
5757 exact copy of the current one.
5759 Use `org-export-add-to-stack' in FUN in order to register results
5762 This is a low level function. See also `org-export-to-buffer'
5763 and `org-export-to-file' for more specialized functions."
5764 (declare (indent 1) (debug t
))
5765 (org-with-gensyms (process temp-file copy-fun proc-buffer coding
)
5766 ;; Write the full sexp evaluating BODY in a copy of the current
5767 ;; buffer to a temporary file, as it may be too long for program
5768 ;; args in `start-process'.
5769 `(with-temp-message "Initializing asynchronous export process"
5770 (let ((,copy-fun
(org-export--generate-copy-script (current-buffer)))
5771 (,temp-file
(make-temp-file "org-export-process"))
5772 (,coding buffer-file-coding-system
))
5773 (with-temp-file ,temp-file
5775 ;; Null characters (from variable values) are inserted
5776 ;; within the file. As a consequence, coding system for
5777 ;; buffer contents will not be recognized properly. So,
5778 ;; we make sure it is the same as the one used to display
5779 ;; the original buffer.
5780 (format ";; -*- coding: %s; -*-\n%S"
5783 (when org-export-async-debug
'(setq debug-on-error t
))
5784 ;; Ignore `kill-emacs-hook' and code evaluation
5785 ;; queries from Babel as we need a truly
5786 ;; non-interactive process.
5787 (setq kill-emacs-hook nil
5788 org-babel-confirm-evaluate-answer-no t
)
5789 ;; Initialize export framework.
5791 ;; Re-create current buffer there.
5792 (funcall ,,copy-fun
)
5793 (restore-buffer-modified-p nil
)
5794 ;; Sexp to evaluate in the buffer.
5795 (print (progn ,,@body
))))))
5796 ;; Start external process.
5797 (let* ((process-connection-type nil
)
5798 (,proc-buffer
(generate-new-buffer-name "*Org Export Process*"))
5803 (list "org-export-process"
5805 (expand-file-name invocation-name invocation-directory
)
5807 (if org-export-async-init-file
5808 (list "-Q" "-l" org-export-async-init-file
)
5809 (list "-l" user-init-file
))
5810 (list "-l" ,temp-file
)))))
5811 ;; Register running process in stack.
5812 (org-export-add-to-stack (get-buffer ,proc-buffer
) nil
,process
)
5813 ;; Set-up sentinel in order to catch results.
5814 (let ((handler ,fun
))
5815 (set-process-sentinel
5818 (let ((proc-buffer (process-buffer p
)))
5819 (when (eq (process-status p
) 'exit
)
5821 (if (zerop (process-exit-status p
))
5824 (with-current-buffer proc-buffer
5825 (goto-char (point-max))
5827 (read (current-buffer)))))
5828 (funcall ,handler results
))
5829 (unless org-export-async-debug
5830 (and (get-buffer proc-buffer
)
5831 (kill-buffer proc-buffer
))))
5832 (org-export-add-to-stack proc-buffer nil p
)
5834 (message "Process `%s' exited abnormally" p
))
5835 (unless org-export-async-debug
5836 (delete-file ,,temp-file
)))))))))))))
5839 (defun org-export-to-buffer
5841 &optional async subtreep visible-only body-only ext-plist
5843 "Call `org-export-as' with output to a specified buffer.
5845 BACKEND is either an export back-end, as returned by, e.g.,
5846 `org-export-create-backend', or a symbol referring to
5847 a registered back-end.
5849 BUFFER is the name of the output buffer. If it already exists,
5850 it will be erased first, otherwise, it will be created.
5852 A non-nil optional argument ASYNC means the process should happen
5853 asynchronously. The resulting buffer should then be accessible
5854 through the `org-export-stack' interface. When ASYNC is nil, the
5855 buffer is displayed if `org-export-show-temporary-export-buffer'
5858 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
5859 EXT-PLIST are similar to those used in `org-export-as', which
5862 Optional argument POST-PROCESS is a function which should accept
5863 no argument. It is always called within the current process,
5864 from BUFFER, with point at its beginning. Export back-ends can
5865 use it to set a major mode there, e.g,
5867 (defun org-latex-export-as-latex
5868 (&optional async subtreep visible-only body-only ext-plist)
5870 (org-export-to-buffer \\='latex \"*Org LATEX Export*\"
5871 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
5873 This function returns BUFFER."
5874 (declare (indent 2))
5876 (org-export-async-start
5878 (with-current-buffer (get-buffer-create ,buffer
)
5880 (setq buffer-file-coding-system
',buffer-file-coding-system
)
5882 (goto-char (point-min))
5883 (org-export-add-to-stack (current-buffer) ',backend
)
5884 (ignore-errors (funcall ,post-process
))))
5886 ',backend
,subtreep
,visible-only
,body-only
',ext-plist
))
5888 (org-export-as backend subtreep visible-only body-only ext-plist
))
5889 (buffer (get-buffer-create buffer
))
5890 (encoding buffer-file-coding-system
))
5891 (when (and (org-string-nw-p output
) (org-export--copy-to-kill-ring-p))
5892 (org-kill-new output
))
5893 (with-current-buffer buffer
5895 (setq buffer-file-coding-system encoding
)
5897 (goto-char (point-min))
5898 (and (functionp post-process
) (funcall post-process
)))
5899 (when org-export-show-temporary-export-buffer
5900 (switch-to-buffer-other-window buffer
))
5904 (defun org-export-to-file
5905 (backend file
&optional async subtreep visible-only body-only ext-plist
5907 "Call `org-export-as' with output to a specified file.
5909 BACKEND is either an export back-end, as returned by, e.g.,
5910 `org-export-create-backend', or a symbol referring to
5911 a registered back-end. FILE is the name of the output file, as
5914 A non-nil optional argument ASYNC means the process should happen
5915 asynchronously. The resulting buffer will then be accessible
5916 through the `org-export-stack' interface.
5918 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
5919 EXT-PLIST are similar to those used in `org-export-as', which
5922 Optional argument POST-PROCESS is called with FILE as its
5923 argument and happens asynchronously when ASYNC is non-nil. It
5924 has to return a file name, or nil. Export back-ends can use this
5925 to send the output file through additional processing, e.g,
5927 (defun org-latex-export-to-latex
5928 (&optional async subtreep visible-only body-only ext-plist)
5930 (let ((outfile (org-export-output-file-name \".tex\" subtreep)))
5931 (org-export-to-file \\='latex outfile
5932 async subtreep visible-only body-only ext-plist
5933 (lambda (file) (org-latex-compile file)))
5935 The function returns either a file name returned by POST-PROCESS,
5937 (declare (indent 2))
5938 (if (not (file-writable-p file
)) (error "Output file not writable")
5939 (let ((ext-plist (org-combine-plists `(:output-file
,file
) ext-plist
))
5940 (encoding (or org-export-coding-system buffer-file-coding-system
)))
5942 (org-export-async-start
5944 (org-export-add-to-stack (expand-file-name file
) ',backend
))
5947 ',backend
,subtreep
,visible-only
,body-only
5951 (let ((coding-system-for-write ',encoding
))
5952 (write-file ,file
)))
5953 (or (ignore-errors (funcall ',post-process
,file
)) ,file
)))
5954 (let ((output (org-export-as
5955 backend subtreep visible-only body-only ext-plist
)))
5958 (let ((coding-system-for-write encoding
))
5960 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p output
))
5961 (org-kill-new output
))
5962 ;; Get proper return value.
5963 (or (and (functionp post-process
) (funcall post-process file
))
5966 (defun org-export-output-file-name (extension &optional subtreep pub-dir
)
5967 "Return output file's name according to buffer specifications.
5969 EXTENSION is a string representing the output file extension,
5970 with the leading dot.
5972 With a non-nil optional argument SUBTREEP, try to determine
5973 output file's name by looking for \"EXPORT_FILE_NAME\" property
5974 of subtree at point.
5976 When optional argument PUB-DIR is set, use it as the publishing
5979 Return file name as a string."
5980 (let* ((visited-file (buffer-file-name (buffer-base-buffer)))
5982 ;; File name may come from EXPORT_FILE_NAME subtree
5984 (file-name-sans-extension
5985 (or (and subtreep
(org-entry-get nil
"EXPORT_FILE_NAME" 'selective
))
5986 ;; File name may be extracted from buffer's associated
5988 (and visited-file
(file-name-nondirectory visited-file
))
5989 ;; Can't determine file name on our own: Ask user.
5991 "Output file: " pub-dir nil nil nil
5993 (string= (file-name-extension name t
) extension
))))))
5995 ;; Build file name. Enforce EXTENSION over whatever user
5996 ;; may have come up with. PUB-DIR, if defined, always has
5997 ;; precedence over any provided path.
6000 (concat (file-name-as-directory pub-dir
)
6001 (file-name-nondirectory base-name
)
6003 ((file-name-absolute-p base-name
) (concat base-name extension
))
6004 (t (concat (file-name-as-directory ".") base-name extension
)))))
6005 ;; If writing to OUTPUT-FILE would overwrite original file, append
6006 ;; EXTENSION another time to final name.
6007 (if (and visited-file
(file-equal-p visited-file output-file
))
6008 (concat output-file extension
)
6011 (defun org-export-add-to-stack (source backend
&optional process
)
6012 "Add a new result to export stack if not present already.
6014 SOURCE is a buffer or a file name containing export results.
6015 BACKEND is a symbol representing export back-end used to generate
6018 Entries already pointing to SOURCE and unavailable entries are
6019 removed beforehand. Return the new stack."
6020 (setq org-export-stack-contents
6021 (cons (list source backend
(or process
(current-time)))
6022 (org-export-stack-remove source
))))
6024 (defun org-export-stack ()
6025 "Menu for asynchronous export results and running processes."
6027 (let ((buffer (get-buffer-create "*Org Export Stack*")))
6029 (when (zerop (buffer-size)) (org-export-stack-mode))
6030 (org-export-stack-refresh)
6031 (pop-to-buffer buffer
))
6032 (message "Type \"q\" to quit, \"?\" for help"))
6034 (defun org-export--stack-source-at-point ()
6035 "Return source from export results at point in stack."
6036 (let ((source (car (nth (1- (org-current-line)) org-export-stack-contents
))))
6037 (if (not source
) (error "Source unavailable, please refresh buffer")
6038 (let ((source-name (if (stringp source
) source
(buffer-name source
))))
6041 (looking-at (concat ".* +" (regexp-quote source-name
) "$")))
6043 ;; SOURCE is not consistent with current line. The stack
6044 ;; view is outdated.
6045 (error "Source unavailable; type `g' to update buffer"))))))
6047 (defun org-export-stack-clear ()
6048 "Remove all entries from export stack."
6050 (setq org-export-stack-contents nil
))
6052 (defun org-export-stack-refresh (&rest _
)
6053 "Refresh the asynchronous export stack.
6054 Unavailable sources are removed from the list. Return the new
6056 (let ((inhibit-read-only t
))
6062 (let ((proc-p (processp (nth 2 entry
))))
6065 (format " %-12s " (or (nth 1 entry
) ""))
6067 (let ((data (nth 2 entry
)))
6068 (if proc-p
(format " %6s " (process-status data
))
6069 ;; Compute age of the results.
6072 (float-time (time-since data
)))))
6075 (let ((source (car entry
)))
6076 (if (stringp source
) source
6077 (buffer-name source
)))))))
6078 ;; Clear stack from exited processes, dead buffers or
6079 ;; non-existent files.
6080 (setq org-export-stack-contents
6083 (if (processp (nth 2 el
))
6084 (buffer-live-p (process-buffer (nth 2 el
)))
6085 (let ((source (car el
)))
6086 (if (bufferp source
) (buffer-live-p source
)
6087 (file-exists-p source
)))))
6088 org-export-stack-contents
)) "\n"))))))
6090 (defun org-export-stack-remove (&optional source
)
6091 "Remove export results at point from stack.
6092 If optional argument SOURCE is non-nil, remove it instead."
6094 (let ((source (or source
(org-export--stack-source-at-point))))
6095 (setq org-export-stack-contents
6096 (cl-remove-if (lambda (el) (equal (car el
) source
))
6097 org-export-stack-contents
))))
6099 (defun org-export-stack-view (&optional in-emacs
)
6100 "View export results at point in stack.
6101 With an optional prefix argument IN-EMACS, force viewing files
6104 (let ((source (org-export--stack-source-at-point)))
6105 (cond ((processp source
)
6106 (org-switch-to-buffer-other-window (process-buffer source
)))
6107 ((bufferp source
) (org-switch-to-buffer-other-window source
))
6108 (t (org-open-file source in-emacs
)))))
6110 (defvar org-export-stack-mode-map
6111 (let ((km (make-sparse-keymap)))
6112 (define-key km
" " 'next-line
)
6113 (define-key km
"n" 'next-line
)
6114 (define-key km
"\C-n" 'next-line
)
6115 (define-key km
[down] 'next-line)
6116 (define-key km "p" 'previous-line)
6117 (define-key km "\C-p" 'previous-line)
6118 (define-key km "\C-?" 'previous-line)
6119 (define-key km [up] 'previous-line)
6120 (define-key km "C" 'org-export-stack-clear)
6121 (define-key km "v" 'org-export-stack-view)
6122 (define-key km (kbd "RET") 'org-export-stack-view)
6123 (define-key km "d" 'org-export-stack-remove)
6125 "Keymap for Org Export Stack.")
6127 (define-derived-mode org-export-stack-mode special-mode "Org-Stack"
6128 "Mode for displaying asynchronous export stack.
6130 Type \\[org-export-stack] to visualize the asynchronous export
6133 In an Org Export Stack buffer, use \\<org-export-stack-mode-map>\\[org-export-stack-view] to view export output
6134 on current line, \\[org-export-stack-remove] to remove it from the stack and \\[org-export-stack-clear] to clear
6137 Removing entries in an Org Export Stack buffer doesn't affect
6138 files or buffers, only the display.
6140 \\{org-export-stack-mode-map}"
6143 (setq buffer-read-only t
6148 (format " %-12s | %6s | %s" "Back-End" "Age" "Source")))
6149 (org-add-hook 'post-command-hook 'org-export-stack-refresh nil t)
6150 (setq-local revert-buffer-function
6151 'org-export-stack-refresh))
6157 ;; `org-export-dispatch' is the standard interactive way to start an
6158 ;; export process. It uses `org-export--dispatch-ui' as a subroutine
6159 ;; for its interface, which, in turn, delegates response to key
6160 ;; pressed to `org-export--dispatch-action'.
6163 (defun org-export-dispatch (&optional arg)
6164 "Export dispatcher for Org mode.
6166 It provides an access to common export related tasks in a buffer.
6167 Its interface comes in two flavors: standard and expert.
6169 While both share the same set of bindings, only the former
6170 displays the valid keys associations in a dedicated buffer.
6171 Scrolling (resp. line-wise motion) in this buffer is done with
6172 SPC and DEL (resp. C-n and C-p) keys.
6174 Set variable `org-export-dispatch-use-expert-ui' to switch to one
6175 flavor or the other.
6177 When ARG is \\[universal-argument], repeat the last export action, with the same set
6178 of options used back then, on the current buffer.
6180 When ARG is \\[universal-argument] \\[universal-argument], display the asynchronous export stack."
6183 (cond ((equal arg '(16)) '(stack))
6184 ((and arg org-export-dispatch-last-action))
6185 (t (save-window-excursion
6188 ;; Remember where we are
6189 (move-marker org-export-dispatch-last-position
6191 (org-base-buffer (current-buffer)))
6192 ;; Get and store an export command
6193 (setq org-export-dispatch-last-action
6194 (org-export--dispatch-ui
6195 (list org-export-initial-scope
6196 (and org-export-in-background 'async))
6198 org-export-dispatch-use-expert-ui)))
6199 (and (get-buffer "*Org Export Dispatcher*")
6200 (kill-buffer "*Org Export Dispatcher*")))))))
6201 (action (car input))
6202 (optns (cdr input)))
6203 (unless (memq 'subtree optns)
6204 (move-marker org-export-dispatch-last-position nil))
6206 ;; First handle special hard-coded actions.
6207 (template (org-export-insert-default-template nil optns))
6208 (stack (org-export-stack))
6209 (publish-current-file
6210 (org-publish-current-file (memq 'force optns) (memq 'async optns)))
6211 (publish-current-project
6212 (org-publish-current-project (memq 'force optns) (memq 'async optns)))
6213 (publish-choose-project
6214 (org-publish (assoc (org-icompleting-read
6216 org-publish-project-alist nil t)
6217 org-publish-project-alist)
6219 (memq 'async optns)))
6220 (publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
6224 ;; Repeating command, maybe move cursor to restore subtree
6226 (if (eq (marker-buffer org-export-dispatch-last-position)
6227 (org-base-buffer (current-buffer)))
6228 (goto-char org-export-dispatch-last-position)
6229 ;; We are in a different buffer, forget position.
6230 (move-marker org-export-dispatch-last-position nil)))
6232 ;; Return a symbol instead of a list to ease
6233 ;; asynchronous export macro use.
6234 (and (memq 'async optns) t)
6235 (and (memq 'subtree optns) t)
6236 (and (memq 'visible optns) t)
6237 (and (memq 'body optns) t)))))))
6239 (defun org-export--dispatch-ui (options first-key expertp)
6240 "Handle interface for `org-export-dispatch'.
6242 OPTIONS is a list containing current interactive options set for
6243 export. It can contain any of the following symbols:
6244 `body' toggles a body-only export
6245 `subtree' restricts export to current subtree
6246 `visible' restricts export to visible part of buffer.
6247 `force' force publishing files.
6248 `async' use asynchronous export process
6250 FIRST-KEY is the key pressed to select the first level menu. It
6251 is nil when this menu hasn't been selected yet.
6253 EXPERTP, when non-nil, triggers expert UI. In that case, no help
6254 buffer is provided, but indications about currently active
6255 options are given in the prompt. Moreover, [?] allows to switch
6256 back to standard interface."
6258 (lambda (key &optional access-key)
6259 ;; Fontify KEY string. Optional argument ACCESS-KEY, when
6260 ;; non-nil is the required first-level key to activate
6261 ;; KEY. When its value is t, activate KEY independently
6262 ;; on the first key, if any. A nil value means KEY will
6263 ;; only be activated at first level.
6264 (if (or (eq access-key t) (eq access-key first-key))
6265 (org-propertize key 'face 'org-warning)
6269 ;; Fontify VALUE string.
6270 (org-propertize value 'face 'font-lock-variable-name-face)))
6271 ;; Prepare menu entries by extracting them from registered
6272 ;; back-ends and sorting them by access key and by ordinal,
6275 (sort (sort (delq nil
6276 (mapcar #'org-export-backend-menu
6277 org-export-registered-backends))
6279 (let ((key-a (nth 1 a))
6281 (cond ((and (numberp key-a) (numberp key-b))
6283 ((numberp key-b) t)))))
6284 'car-less-than-car))
6285 ;; Compute a list of allowed keys based on the first key
6286 ;; pressed, if any. Some keys
6287 ;; (?^B, ?^V, ?^S, ?^F, ?^A, ?&, ?# and ?q) are always
6290 (nconc (list 2 22 19 6 1)
6291 (if (not first-key) (org-uniquify (mapcar 'car entries))
6293 (dolist (entry entries (sort (mapcar 'car sub-menu) '<))
6294 (when (eq (car entry) first-key)
6295 (setq sub-menu (append (nth 2 entry) sub-menu))))))
6296 (cond ((eq first-key ?P) (list ?f ?p ?x ?a))
6297 ((not first-key) (list ?P)))
6299 (when expertp (list ??))
6301 ;; Build the help menu for standard UI.
6305 ;; Options are hard-coded.
6306 (format "[%s] Body only: %s [%s] Visible only: %s
6307 \[%s] Export scope: %s [%s] Force publishing: %s
6308 \[%s] Async export: %s\n\n"
6309 (funcall fontify-key "C-b" t)
6310 (funcall fontify-value
6311 (if (memq 'body options) "On " "Off"))
6312 (funcall fontify-key "C-v" t)
6313 (funcall fontify-value
6314 (if (memq 'visible options) "On " "Off"))
6315 (funcall fontify-key "C-s" t)
6316 (funcall fontify-value
6317 (if (memq 'subtree options) "Subtree" "Buffer "))
6318 (funcall fontify-key "C-f" t)
6319 (funcall fontify-value
6320 (if (memq 'force options) "On " "Off"))
6321 (funcall fontify-key "C-a" t)
6322 (funcall fontify-value
6323 (if (memq 'async options) "On " "Off")))
6324 ;; Display registered back-end entries. When a key
6325 ;; appears for the second time, do not create another
6326 ;; entry, but append its sub-menu to existing menu.
6330 (let ((top-key (car entry)))
6332 (unless (eq top-key last-key)
6333 (setq last-key top-key)
6334 (format "\n[%s] %s\n"
6335 (funcall fontify-key (char-to-string top-key))
6337 (let ((sub-menu (nth 2 entry)))
6338 (unless (functionp sub-menu)
6339 ;; Split sub-menu into two columns.
6346 (if (zerop (mod index 2)) " [%s] %-26s"
6348 (funcall fontify-key
6349 (char-to-string (car sub-entry))
6353 (when (zerop (mod index 2)) "\n"))))))))
6355 ;; Publishing menu is hard-coded.
6356 (format "\n[%s] Publish
6357 [%s] Current file [%s] Current project
6358 [%s] Choose project [%s] All projects\n\n\n"
6359 (funcall fontify-key "P")
6360 (funcall fontify-key "f" ?P)
6361 (funcall fontify-key "p" ?P)
6362 (funcall fontify-key "x" ?P)
6363 (funcall fontify-key "a" ?P))
6364 (format "[%s] Export stack [%s] Insert template\n"
6365 (funcall fontify-key "&" t)
6366 (funcall fontify-key "#" t))
6368 (funcall fontify-key "q" t)
6369 (if first-key "Main menu" "Exit")))))
6370 ;; Build prompts for both standard and expert UI.
6371 (standard-prompt (unless expertp "Export command: "))
6375 "Export command (C-%s%s%s%s%s) [%s]: "
6376 (if (memq 'body options) (funcall fontify-key "b" t) "b")
6377 (if (memq 'visible options) (funcall fontify-key "v" t) "v")
6378 (if (memq 'subtree options) (funcall fontify-key "s" t) "s")
6379 (if (memq 'force options) (funcall fontify-key "f" t) "f")
6380 (if (memq 'async options) (funcall fontify-key "a" t) "a")
6381 (mapconcat (lambda (k)
6382 ;; Strip control characters.
6383 (unless (< k 27) (char-to-string k)))
6384 allowed-keys "")))))
6385 ;; With expert UI, just read key with a fancy prompt. In standard
6386 ;; UI, display an intrusive help buffer.
6388 (org-export--dispatch-action
6389 expert-prompt allowed-keys entries options first-key expertp)
6390 ;; At first call, create frame layout in order to display menu.
6391 (unless (get-buffer "*Org Export Dispatcher*")
6392 (delete-other-windows)
6393 (org-switch-to-buffer-other-window
6394 (get-buffer-create "*Org Export Dispatcher*"))
6395 (setq cursor-type nil
6396 header-line-format "Use SPC, DEL, C-n or C-p to navigate.")
6397 ;; Make sure that invisible cursor will not highlight square
6399 (set-syntax-table (copy-syntax-table))
6400 (modify-syntax-entry ?\[ "w"))
6401 ;; At this point, the buffer containing the menu exists and is
6402 ;; visible in the current window. So, refresh it.
6403 (with-current-buffer "*Org Export Dispatcher*"
6404 ;; Refresh help. Maintain display continuity by re-visiting
6405 ;; previous window position.
6406 (let ((pos (window-start)))
6409 (set-window-start nil pos)))
6410 (org-fit-window-to-buffer)
6411 (org-export--dispatch-action
6412 standard-prompt allowed-keys entries options first-key expertp))))
6414 (defun org-export--dispatch-action
6415 (prompt allowed-keys entries options first-key expertp)
6416 "Read a character from command input and act accordingly.
6418 PROMPT is the displayed prompt, as a string. ALLOWED-KEYS is
6419 a list of characters available at a given step in the process.
6420 ENTRIES is a list of menu entries. OPTIONS, FIRST-KEY and
6421 EXPERTP are the same as defined in `org-export--dispatch-ui',
6424 Toggle export options when required. Otherwise, return value is
6425 a list with action as CAR and a list of interactive export
6428 ;; Scrolling: when in non-expert mode, act on motion keys (C-n,
6430 (while (and (setq key (read-char-exclusive prompt))
6432 (memq key '(14 16 ?\s ?\d)))
6434 (14 (if (not (pos-visible-in-window-p (point-max)))
6435 (ignore-errors (scroll-up 1))
6436 (message "End of buffer")
6438 (16 (if (not (pos-visible-in-window-p (point-min)))
6439 (ignore-errors (scroll-down 1))
6440 (message "Beginning of buffer")
6442 (?\s (if (not (pos-visible-in-window-p (point-max)))
6444 (message "End of buffer")
6446 (?\d (if (not (pos-visible-in-window-p (point-min)))
6448 (message "Beginning of buffer")
6451 ;; Ignore undefined associations.
6452 ((not (memq key allowed-keys))
6454 (unless expertp (message "Invalid key") (sit-for 1))
6455 (org-export--dispatch-ui options first-key expertp))
6456 ;; q key at first level aborts export. At second level, cancel
6457 ;; first key instead.
6458 ((eq key ?q) (if (not first-key) (error "Export aborted")
6459 (org-export--dispatch-ui options nil expertp)))
6460 ;; Help key: Switch back to standard interface if expert UI was
6462 ((eq key ??) (org-export--dispatch-ui options first-key nil))
6463 ;; Send request for template insertion along with export scope.
6464 ((eq key ?#) (cons 'template (memq 'subtree options)))
6465 ;; Switch to asynchronous export stack.
6466 ((eq key ?&) '(stack))
6467 ;; Toggle options: C-b (2) C-v (22) C-s (19) C-f (6) C-a (1).
6468 ((memq key '(2 22 19 6 1))
6469 (org-export--dispatch-ui
6470 (let ((option (cl-case key (2 'body) (22 'visible) (19 'subtree)
6471 (6 'force) (1 'async))))
6472 (if (memq option options) (remq option options)
6473 (cons option options)))
6475 ;; Action selected: Send key and options back to
6476 ;; `org-export-dispatch'.
6477 ((or first-key (functionp (nth 2 (assq key entries))))
6479 ((not first-key) (nth 2 (assq key entries)))
6480 ;; Publishing actions are hard-coded. Send a special
6481 ;; signal to `org-export-dispatch'.
6484 (?f 'publish-current-file)
6485 (?p 'publish-current-project)
6486 (?x 'publish-choose-project)
6488 ;; Return first action associated to FIRST-KEY + KEY
6489 ;; path. Indeed, derived backends can share the same
6492 (dolist (entry (member (assq first-key entries) entries))
6493 (let ((match (assq key (nth 2 entry))))
6494 (when match (throw 'found (nth 2 match))))))))
6496 ;; Otherwise, enter sub-menu.
6497 (t (org-export--dispatch-ui options key expertp)))))
6504 ;; generated-autoload-file: "org-loaddefs.el"