Merge branch 'maint'
[org-mode.git] / lisp / ox.el
blob0a212eb109dbe09b351e14060a350ad393244951
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/>.
23 ;;; Commentary:
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
29 ;; parts:
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
54 ;; more information.
56 ;; If the new back-end shares most properties with another one,
57 ;; `org-export-define-derived-backend' can be used to simplify the
58 ;; process.
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
67 ;; last one.
69 ;; See <http://orgmode.org/worg/dev/org-export-reference.html> for
70 ;; more information.
72 ;;; Code:
74 (require 'cl-lib)
75 (require 'org-element)
76 (require 'org-macro)
77 (require 'ob-exp)
79 (declare-function org-publish "ox-publish" (project &optional force async))
80 (declare-function org-publish-all "ox-publish" (&optional force async))
81 (declare-function
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
150 property).
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
159 a newline.
160 `split' Split values at white spaces, and cons them to the
161 previous list.
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
167 DEFAULT.
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
244 first.")
246 (defconst org-export-default-inline-image-rule
247 `(("file" .
248 ,(format "\\.%s\\'"
249 (regexp-opt
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
258 rules.")
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."
327 :tag "Org Export"
328 :group 'org)
330 (defgroup org-export-general nil
331 "General options for export engine."
332 :tag "Org Export General"
333 :group 'org-export)
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,
344 e.g. \"arch:nil\"."
345 :group 'org-export-general
346 :type '(choice
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
357 :type 'boolean
358 :safe #'booleanp)
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,
363 e.g. \"c:t\"."
364 :group 'org-export-general
365 :type 'boolean
366 :safe #'booleanp)
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
372 see.
374 This option can also be set with the OPTIONS keyword, e.g.,
375 \"creator:t\"."
376 :group 'org-export-general
377 :version "25.1"
378 :package-version '(Org . "8.3")
379 :type 'boolean
380 :safe #'booleanp)
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,
385 e.g. \"date:nil\"."
386 :group 'org-export-general
387 :type 'boolean
388 :safe #'booleanp)
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
397 string."
398 :group 'org-export-general
399 :type '(choice
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)"
406 emacs-version
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")
412 :safe #'stringp)
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,
425 e.g. \"d:nil\"."
426 :group 'org-export-general
427 :version "24.4"
428 :package-version '(Org . "8.0")
429 :type '(choice
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"
437 :inline t
438 (string :tag "Drawer name"))))
439 :safe (lambda (x) (or (booleanp x)
440 (and (listp 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,
448 e.g. \"email:t\"."
449 :group 'org-export-general
450 :type 'boolean
451 :safe #'booleanp)
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,
458 respectively.
460 This option can also be set with the OPTIONS keyword,
461 e.g. \"*:nil\"."
462 :group 'org-export-general
463 :type 'boolean
464 :safe #'booleanp)
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,
481 e.g. \"::nil\"."
482 :group 'org-export-general
483 :version "24.4"
484 :package-version '(Org . "8.0")
485 :type 'boolean
486 :safe #'booleanp)
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,
491 e.g. \"f:nil\"."
492 :group 'org-export-general
493 :type 'boolean
494 :safe #'booleanp)
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
506 :version "24.4"
507 :package-version '(Org . "8.0")
508 :type '(choice
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,
521 e.g. \"H:2\"."
522 :group 'org-export-general
523 :type 'integer
524 :safe #'integerp)
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")
534 :safe #'stringp)
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,
539 e.g. \"\\n:t\"."
540 :group 'org-export-general
541 :type 'boolean
542 :safe #'booleanp)
544 (defcustom org-export-with-entities t
545 "Non-nil means interpret entities when exporting.
547 For example, HTML export converts \\alpha to &alpha; and \\AA to
548 &Aring;.
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,
554 e.g. \"e:nil\"."
555 :group 'org-export-general
556 :type 'boolean
557 :safe #'booleanp)
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
564 :version "24.4"
565 :package-version '(Org . "8.0")
566 :type 'boolean
567 :safe #'booleanp)
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,
576 e.g. \"p:t\"."
577 :group 'org-export-general
578 :version "24.4"
579 :package-version '(Org . "8.0")
580 :type 'boolean
581 :safe #'booleanp)
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,
586 e.g. \"pri:t\"."
587 :group 'org-export-general
588 :type 'boolean
589 :safe #'booleanp)
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,
598 e.g. \"prop:t\"."
599 :group 'org-export-general
600 :version "24.4"
601 :package-version '(Org . "8.3")
602 :type '(choice
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,
617 e.g. \"num:t\"."
618 :group 'org-export-general
619 :type 'boolean
620 :safe #'booleanp)
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,
638 e.g., \"':t\".
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
646 :version "24.4"
647 :package-version '(Org . "8.0")
648 :type 'boolean
649 :safe #'booleanp)
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:
656 Org HTML LaTeX UTF-8
657 -----+----------+--------+-------
658 \\- &shy; \\-
659 -- &ndash; -- –
660 --- &mdash; --- —
661 ... &hellip; \\ldots …
663 This option can also be set with the OPTIONS keyword,
664 e.g. \"-:nil\"."
665 :group 'org-export-general
666 :type 'boolean
667 :safe #'booleanp)
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,
672 e.g. \"stat:nil\""
673 :group 'org-export-general
674 :version "24.4"
675 :package-version '(Org . "8.0")
676 :type 'boolean
677 :safe #'booleanp)
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,
685 it is not anymore.
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
695 superscripts:
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
709 :version "24.4"
710 :package-version '(Org . "8.0")
711 :type '(choice
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
725 contents is made.
727 This option can also be set with the OPTIONS keyword,
728 e.g. \"toc:nil\" or \"toc:3\"."
729 :group 'org-export-general
730 :type '(choice
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)
735 (integerp 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,
740 e.g. \"|:nil\"."
741 :group 'org-export-general
742 :version "24.4"
743 :package-version '(Org . "8.0")
744 :type 'boolean
745 :safe #'booleanp)
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
752 the document.
754 This option can also be set with the OPTIONS keyword,
755 e.g. \"tags:nil\"."
756 :group 'org-export-general
757 :type '(choice
758 (const :tag "Off" nil)
759 (const :tag "Not in TOC" not-in-toc)
760 (const :tag "On" t))
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,
774 e.g. \"tasks:nil\"."
775 :group 'org-export-general
776 :type '(choice
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))
784 (and (listp x)
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,
790 e.g. \"title:nil\"."
791 :group 'org-export-general
792 :version "25.1"
793 :package-version '(Org . "8.3")
794 :type 'boolean
795 :safe #'booleanp)
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
802 :type 'boolean
803 :safe #'booleanp)
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
816 exported.
818 This option can also be set with the OPTIONS keyword, e.g.
819 \"<:nil\"."
820 :group 'org-export-general
821 :type '(choice
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
833 :type 'boolean)
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
840 :version "24.4"
841 :package-version '(Org . "8.0")
842 :type 'boolean)
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
851 [BROKEN LINK: path]
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
858 :version "25.1"
859 :package-version '(Org . "9.0")
860 :type '(choice
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
874 :version "24.4"
875 :package-version '(Org . "8.0")
876 :type '(repeat
877 (cons (string :tag "Shortcut")
878 (string :tag "Back-end")))
879 :safe (lambda (x)
880 (and (listp x)
881 (cl-every #'consp x)
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
888 :version "24.4"
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
896 :version "25.1"
897 :package-version '(Org . "8.3")
898 :type '(choice
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
907 :type '(choice
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
917 these cases."
918 :group 'org-export-general
919 :type 'boolean)
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
926 :version "24.4"
927 :package-version '(Org . "8.0")
928 :type 'boolean)
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
937 at start-up.
939 Therefore, using a specific configuration makes the process to
940 load faster and the export more portable."
941 :group 'org-export-general
942 :version "24.4"
943 :package-version '(Org . "8.0")
944 :type '(choice
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
957 mode."
958 :group 'org-export-general
959 :version "24.4"
960 :package-version '(Org . "8.0")
961 :type 'boolean)
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'
969 ;; and `menu' slots.
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
989 ;; used instead.
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)
995 (:copier nil))
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."
1001 (catch '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)))
1038 (when backend
1039 (catch 'exit
1040 (while (org-export-backend-parent backend)
1041 (when (memq (org-export-backend-name backend) backends)
1042 (throw 'exit t))
1043 (setq backend
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
1053 transcoders.
1055 Unlike to `org-export-backend-transcoders', this function
1056 also returns transcoders inherited from parent back-ends,
1057 if any."
1058 (when (symbolp backend) (setq backend (org-export-get-backend backend)))
1059 (when backend
1060 (let ((transcoders (org-export-backend-transcoders backend))
1061 parent)
1062 (while (setq parent (org-export-backend-parent backend))
1063 (setq backend (org-export-get-backend parent))
1064 (setq transcoders
1065 (append transcoders (org-export-backend-transcoders backend))))
1066 transcoders)))
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)))
1078 (when backend
1079 (let ((options (org-export-backend-options backend))
1080 parent)
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))))
1084 options)))
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)))
1096 (when backend
1097 (let ((filters (org-export-backend-filters backend))
1098 parent)
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))))
1102 filters)))
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
1141 back-end.
1143 BODY can start with pre-defined keyword arguments. The following
1144 keywords are understood:
1146 :export-block
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
1152 translator.
1154 :filters-alist
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.
1162 :menu-entry
1164 Menu entry for the export dispatcher. It should be a list
1165 like:
1167 \\='(KEY DESCRIPTION-OR-ORDINAL ACTION-OR-MENU)
1169 where :
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
1186 some of them.
1188 If it is an alist, associations should follow the
1189 pattern:
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\"
1204 (lambda (a s v b)
1205 (if a (org-latex-export-to-pdf t s v b)
1206 (org-open-file
1207 (org-latex-export-to-pdf nil s v b)))))))
1209 or the following, which will be added to the previous
1210 sub-menu,
1212 \\='(?l 1
1213 ((?B \"As TEX buffer (Beamer)\" org-beamer-export-as-latex)
1214 (?P \"As PDF file (Beamer)\" org-beamer-export-to-pdf)))
1216 :options-alist
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)))
1226 (cl-case keyword
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
1237 :options options
1238 :filters filters
1239 :blocks blocks
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:
1251 :export-block
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
1257 translator.
1259 :filters-alist
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.
1265 :menu-entry
1267 Menu entry for the export dispatcher. See
1268 `org-export-define-backend' for more information about the
1269 expected value.
1271 :options-alist
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.
1278 :translate-alist
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
1283 about transcoders.
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)))
1298 (cl-case keyword
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
1309 :parent parent
1310 :transcoders transcoders
1311 :options options
1312 :filters filters
1313 :blocks blocks
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'
1326 ;; function.
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...
1379 (org-combine-plists
1380 ;; ... from global variables...
1381 (org-export--get-global-options backend)
1382 ;; ... from an external property list...
1383 ext-plist
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."
1394 (let ((line
1395 (let ((s 0) alist)
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)))
1400 alist))
1401 alist))
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))
1405 (plist))
1406 (when line
1407 (dolist (entry all plist)
1408 (let ((item (nth 2 entry)))
1409 (when item
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))
1424 (let ((plist
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.
1432 (cache (list
1433 (cons "TITLE"
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)))
1445 (when keyword
1446 (let ((value
1447 (or (cdr (assoc keyword cache))
1448 (let ((v (org-entry-get (point)
1449 (concat "EXPORT_" keyword)
1450 'selective)))
1451 (push (cons keyword v) cache) v))))
1452 (when value
1453 (setq plist
1454 (plist-put plist
1455 property
1456 (cl-case (nth 4 option)
1457 (parse
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
1469 process.
1471 Assume buffer is in Org mode. Narrowing, if any, is ignored."
1472 (let* ((case-fold-search t)
1473 (options (append
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))))
1480 plist to-parse)
1481 (letrec ((find-properties
1482 (lambda (keyword)
1483 ;; Return all properties associated to KEYWORD.
1484 (let (properties)
1485 (dolist (option options properties)
1486 (when (equal (nth 1 option) keyword)
1487 (cl-pushnew (car option) properties))))))
1488 (get-options
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)))
1500 (cond
1501 ;; Options in `org-export-special-keywords'.
1502 ((equal key "SETUPFILE")
1503 (let ((file
1504 (expand-file-name
1505 (org-remove-double-quotes (org-trim val)))))
1506 ;; Avoid circular dependencies.
1507 (unless (member file files)
1508 (with-temp-buffer
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")
1515 (setq plist
1516 (org-combine-plists
1517 plist
1518 (org-export--parse-option-keyword
1519 val backend))))
1520 ((equal key "FILETAGS")
1521 (setq plist
1522 (org-combine-plists
1523 plist
1524 (list :filetags
1525 (org-uniquify
1526 (append
1527 (org-split-string val ":")
1528 (plist-get plist :filetags)))))))
1530 ;; Options in `org-export-options-alist'.
1531 (dolist (property (funcall find-properties key))
1532 (setq
1533 plist
1534 (plist-put
1535 plist property
1536 ;; Handle value depending on specified
1537 ;; BEHAVIOR.
1538 (cl-case (nth 4 (assq property options))
1539 (parse
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
1548 ;; paragraph.
1549 (let ((old (plist-get plist property)))
1550 (cond ((not (org-string-nw-p val)) old)
1551 (old (concat old "\n" val))
1552 (t val))))
1553 (space
1554 (if (not (plist-get plist property))
1555 (org-trim val)
1556 (concat (plist-get plist property)
1558 (org-trim val))))
1559 (newline
1560 (org-trim
1561 (concat (plist-get plist property)
1562 "\n"
1563 (org-trim val))))
1564 (split `(,@(plist-get plist property)
1565 ,@(org-split-string val)))
1566 ((t) val)
1567 (otherwise
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
1577 (plist-get plist p)
1578 (org-element-restriction 'keyword))))
1579 (org-element-map value 'plain-text
1580 (lambda (s)
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
1590 `org-export-as'."
1591 (list :export-options (delq nil
1592 (list (and subtreep 'subtree)
1593 (and visible-only 'visible-only)
1594 (and body-only 'body-only)))
1595 :back-end backend
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
1609 process."
1610 (let (plist
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)
1617 (setq plist
1618 (plist-put
1619 plist
1620 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))
1626 value)))))))))
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)
1648 "BIND")
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)
1654 (with-temp-buffer
1655 (setq default-directory
1656 (file-name-directory file))
1657 (let ((org-inhibit-startup t)) (org-mode))
1658 (insert (org-file-contents file 'noerror))
1659 (setq alist
1660 (funcall collect-bind
1661 (cons file files)
1662 alist))))))))))
1663 alist)))))
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
1707 as value.
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'.
1714 (setq info
1715 (plist-put info
1716 :headline-offset
1717 (- 1 (org-export--get-min-level data info))))
1718 ;; From now on, properties order doesn't matter: get the rest of the
1719 ;; tree properties.
1720 (org-combine-plists
1721 info
1722 (list :headline-numbering (org-export--collect-headline-numbering data info)
1723 :id-alist
1724 (org-element-map data 'link
1725 (lambda (l)
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."
1735 (catch 'exit
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
1751 options.
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
1758 (lambda (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))))
1763 (cons
1764 headline
1765 (cl-loop
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))))))
1771 options)))
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 (let ((select (plist-get info :select-tags)))
1778 (if (cl-some (lambda (tag) (member tag select)) (plist-get info :filetags))
1779 ;; If FILETAGS contains a select tag, every headline or
1780 ;; inlinetask is returned.
1781 (org-element-map data '(headline inlinetask) #'identity)
1782 (letrec ((selected-trees)
1783 (walk-data
1784 (lambda (data genealogy)
1785 (let ((type (org-element-type data)))
1786 (cond
1787 ((memq type '(headline inlinetask))
1788 (let ((tags (org-element-property :tags data)))
1789 (if (cl-some (lambda (tag) (member tag select)) tags)
1790 ;; When a select tag is found, mark full
1791 ;; genealogy and every headline within the
1792 ;; tree as acceptable.
1793 (setq selected-trees
1794 (append
1795 genealogy
1796 (org-element-map data '(headline inlinetask)
1797 #'identity)
1798 selected-trees))
1799 ;; If at a headline, continue searching in
1800 ;; tree, recursively.
1801 (when (eq type 'headline)
1802 (dolist (el (org-element-contents data))
1803 (funcall walk-data el (cons data genealogy)))))))
1804 ((or (eq type 'org-data)
1805 (memq type org-element-greater-elements))
1806 (dolist (el (org-element-contents data))
1807 (funcall walk-data el genealogy))))))))
1808 (funcall walk-data data nil)
1809 selected-trees))))
1811 (defun org-export--skip-p (blob options selected)
1812 "Non-nil when element or object BLOB should be skipped during export.
1813 OPTIONS is the plist holding export options. SELECTED, when
1814 non-nil, is a list of headlines or inlinetasks belonging to
1815 a tree with a select tag."
1816 (cl-case (org-element-type blob)
1817 (clock (not (plist-get options :with-clocks)))
1818 (drawer
1819 (let ((with-drawers-p (plist-get options :with-drawers)))
1820 (or (not with-drawers-p)
1821 (and (consp with-drawers-p)
1822 ;; If `:with-drawers' value starts with `not', ignore
1823 ;; every drawer whose name belong to that list.
1824 ;; Otherwise, ignore drawers whose name isn't in that
1825 ;; list.
1826 (let ((name (org-element-property :drawer-name blob)))
1827 (if (eq (car with-drawers-p) 'not)
1828 (member-ignore-case name (cdr with-drawers-p))
1829 (not (member-ignore-case name with-drawers-p))))))))
1830 (fixed-width (not (plist-get options :with-fixed-width)))
1831 ((footnote-definition footnote-reference)
1832 (not (plist-get options :with-footnotes)))
1833 ((headline inlinetask)
1834 (let ((with-tasks (plist-get options :with-tasks))
1835 (todo (org-element-property :todo-keyword blob))
1836 (todo-type (org-element-property :todo-type blob))
1837 (archived (plist-get options :with-archived-trees))
1838 (tags (org-export-get-tags blob options nil t)))
1840 (and (eq (org-element-type blob) 'inlinetask)
1841 (not (plist-get options :with-inlinetasks)))
1842 ;; Ignore subtrees with an exclude tag.
1843 (cl-loop for k in (plist-get options :exclude-tags)
1844 thereis (member k tags))
1845 ;; When a select tag is present in the buffer, ignore any tree
1846 ;; without it.
1847 (and selected (not (memq blob selected)))
1848 ;; Ignore commented sub-trees.
1849 (org-element-property :commentedp blob)
1850 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
1851 (and (not archived) (org-element-property :archivedp blob))
1852 ;; Ignore tasks, if specified by `:with-tasks' property.
1853 (and todo
1854 (or (not with-tasks)
1855 (and (memq with-tasks '(todo done))
1856 (not (eq todo-type with-tasks)))
1857 (and (consp with-tasks) (not (member todo with-tasks))))))))
1858 ((latex-environment latex-fragment) (not (plist-get options :with-latex)))
1859 (node-property
1860 (let ((properties-set (plist-get options :with-properties)))
1861 (cond ((null properties-set) t)
1862 ((consp properties-set)
1863 (not (member-ignore-case (org-element-property :key blob)
1864 properties-set))))))
1865 (planning (not (plist-get options :with-planning)))
1866 (property-drawer (not (plist-get options :with-properties)))
1867 (statistics-cookie (not (plist-get options :with-statistics-cookies)))
1868 (table (not (plist-get options :with-tables)))
1869 (table-cell
1870 (and (org-export-table-has-special-column-p
1871 (org-export-get-parent-table blob))
1872 (org-export-first-sibling-p blob options)))
1873 (table-row (org-export-table-row-is-special-p blob options))
1874 (timestamp
1875 ;; `:with-timestamps' only applies to isolated timestamps
1876 ;; objects, i.e. timestamp objects in a paragraph containing only
1877 ;; timestamps and whitespaces.
1878 (when (let ((parent (org-export-get-parent-element blob)))
1879 (and (memq (org-element-type parent) '(paragraph verse-block))
1880 (not (org-element-map parent
1881 (cons 'plain-text
1882 (remq 'timestamp org-element-all-objects))
1883 (lambda (obj)
1884 (or (not (stringp obj)) (org-string-nw-p obj)))
1885 options t))))
1886 (cl-case (plist-get options :with-timestamps)
1887 ((nil) t)
1888 (active
1889 (not (memq (org-element-property :type blob) '(active active-range))))
1890 (inactive
1891 (not (memq (org-element-property :type blob)
1892 '(inactive inactive-range)))))))))
1895 ;;; The Transcoder
1897 ;; `org-export-data' reads a parse tree (obtained with, i.e.
1898 ;; `org-element-parse-buffer') and transcodes it into a specified
1899 ;; back-end output. It takes care of filtering out elements or
1900 ;; objects according to export options and organizing the output blank
1901 ;; lines and white space are preserved. The function memoizes its
1902 ;; results, so it is cheap to call it within transcoders.
1904 ;; It is possible to modify locally the back-end used by
1905 ;; `org-export-data' or even use a temporary back-end by using
1906 ;; `org-export-data-with-backend'.
1908 ;; `org-export-transcoder' is an accessor returning appropriate
1909 ;; translator function for a given element or object.
1911 (defun org-export-transcoder (blob info)
1912 "Return appropriate transcoder for BLOB.
1913 INFO is a plist containing export directives."
1914 (let ((type (org-element-type blob)))
1915 ;; Return contents only for complete parse trees.
1916 (if (eq type 'org-data) (lambda (_datum contents _info) contents)
1917 (let ((transcoder (cdr (assq type (plist-get info :translate-alist)))))
1918 (and (functionp transcoder) transcoder)))))
1920 (defun org-export-data (data info)
1921 "Convert DATA into current back-end format.
1923 DATA is a parse tree, an element or an object or a secondary
1924 string. INFO is a plist holding export options.
1926 Return a string."
1927 (or (gethash data (plist-get info :exported-data))
1928 ;; Handle broken links according to
1929 ;; `org-export-with-broken-links'.
1930 (cl-macrolet
1931 ((broken-link-handler
1932 (&rest body)
1933 `(condition-case err
1934 (progn ,@body)
1935 (org-link-broken
1936 (pcase (plist-get info :with-broken-links)
1937 (`nil (user-error "Unable to resolve link: %S" (nth 1 err)))
1938 (`mark (org-export-data
1939 (format "[BROKEN LINK: %s]" (nth 1 err)) info))
1940 (_ nil))))))
1941 (let* ((type (org-element-type data))
1942 (results
1943 (cond
1944 ;; Ignored element/object.
1945 ((memq data (plist-get info :ignore-list)) nil)
1946 ;; Plain text.
1947 ((eq type 'plain-text)
1948 (org-export-filter-apply-functions
1949 (plist-get info :filter-plain-text)
1950 (let ((transcoder (org-export-transcoder data info)))
1951 (if transcoder (funcall transcoder data info) data))
1952 info))
1953 ;; Secondary string.
1954 ((not type)
1955 (mapconcat (lambda (obj) (org-export-data obj info)) data ""))
1956 ;; Element/Object without contents or, as a special
1957 ;; case, headline with archive tag and archived trees
1958 ;; restricted to title only.
1959 ((or (not (org-element-contents data))
1960 (and (eq type 'headline)
1961 (eq (plist-get info :with-archived-trees) 'headline)
1962 (org-element-property :archivedp data)))
1963 (let ((transcoder (org-export-transcoder data info)))
1964 (or (and (functionp transcoder)
1965 (broken-link-handler
1966 (funcall transcoder data nil info)))
1967 ;; Export snippets never return a nil value so
1968 ;; that white spaces following them are never
1969 ;; ignored.
1970 (and (eq type 'export-snippet) ""))))
1971 ;; Element/Object with contents.
1973 (let ((transcoder (org-export-transcoder data info)))
1974 (when transcoder
1975 (let* ((greaterp (memq type org-element-greater-elements))
1976 (objectp
1977 (and (not greaterp)
1978 (memq type org-element-recursive-objects)))
1979 (contents
1980 (mapconcat
1981 (lambda (element) (org-export-data element info))
1982 (org-element-contents
1983 (if (or greaterp objectp) data
1984 ;; Elements directly containing
1985 ;; objects must have their indentation
1986 ;; normalized first.
1987 (org-element-normalize-contents
1988 data
1989 ;; When normalizing contents of the
1990 ;; first paragraph in an item or
1991 ;; a footnote definition, ignore
1992 ;; first line's indentation: there is
1993 ;; none and it might be misleading.
1994 (when (eq type 'paragraph)
1995 (let ((parent (org-export-get-parent data)))
1996 (and
1997 (eq (car (org-element-contents parent))
1998 data)
1999 (memq (org-element-type parent)
2000 '(footnote-definition item))))))))
2001 "")))
2002 (broken-link-handler
2003 (funcall transcoder data
2004 (if (not greaterp) contents
2005 (org-element-normalize-string contents))
2006 info)))))))))
2007 ;; Final result will be memoized before being returned.
2008 (puthash
2009 data
2010 (cond
2011 ((not results) "")
2012 ((memq type '(org-data plain-text nil)) results)
2013 ;; Append the same white space between elements or objects
2014 ;; as in the original buffer, and call appropriate filters.
2016 (let ((results
2017 (org-export-filter-apply-functions
2018 (plist-get info (intern (format ":filter-%s" type)))
2019 (let ((post-blank (or (org-element-property :post-blank data)
2020 0)))
2021 (if (memq type org-element-all-elements)
2022 (concat (org-element-normalize-string results)
2023 (make-string post-blank ?\n))
2024 (concat results (make-string post-blank ?\s))))
2025 info)))
2026 results)))
2027 (plist-get info :exported-data))))))
2029 (defun org-export-data-with-backend (data backend info)
2030 "Convert DATA into BACKEND format.
2032 DATA is an element, an object, a secondary string or a string.
2033 BACKEND is a symbol. INFO is a plist used as a communication
2034 channel.
2036 Unlike to `org-export-with-backend', this function will
2037 recursively convert DATA using BACKEND translation table."
2038 (when (symbolp backend) (setq backend (org-export-get-backend backend)))
2039 (org-export-data
2040 data
2041 ;; Set-up a new communication channel with translations defined in
2042 ;; BACKEND as the translate table and a new hash table for
2043 ;; memoization.
2044 (org-combine-plists
2045 info
2046 (list :back-end backend
2047 :translate-alist (org-export-get-all-transcoders backend)
2048 ;; Size of the hash table is reduced since this function
2049 ;; will probably be used on small trees.
2050 :exported-data (make-hash-table :test 'eq :size 401)))))
2052 (defun org-export-expand (blob contents &optional with-affiliated)
2053 "Expand a parsed element or object to its original state.
2055 BLOB is either an element or an object. CONTENTS is its
2056 contents, as a string or nil.
2058 When optional argument WITH-AFFILIATED is non-nil, add affiliated
2059 keywords before output."
2060 (let ((type (org-element-type blob)))
2061 (concat (and with-affiliated (memq type org-element-all-elements)
2062 (org-element--interpret-affiliated-keywords blob))
2063 (funcall (intern (format "org-element-%s-interpreter" type))
2064 blob contents))))
2068 ;;; The Filter System
2070 ;; Filters allow end-users to tweak easily the transcoded output.
2071 ;; They are the functional counterpart of hooks, as every filter in
2072 ;; a set is applied to the return value of the previous one.
2074 ;; Every set is back-end agnostic. Although, a filter is always
2075 ;; called, in addition to the string it applies to, with the back-end
2076 ;; used as argument, so it's easy for the end-user to add back-end
2077 ;; specific filters in the set. The communication channel, as
2078 ;; a plist, is required as the third argument.
2080 ;; From the developer side, filters sets can be installed in the
2081 ;; process with the help of `org-export-define-backend', which
2082 ;; internally stores filters as an alist. Each association has a key
2083 ;; among the following symbols and a function or a list of functions
2084 ;; as value.
2086 ;; - `:filter-options' applies to the property list containing export
2087 ;; options. Unlike to other filters, functions in this list accept
2088 ;; two arguments instead of three: the property list containing
2089 ;; export options and the back-end. Users can set its value through
2090 ;; `org-export-filter-options-functions' variable.
2092 ;; - `:filter-parse-tree' applies directly to the complete parsed
2093 ;; tree. Users can set it through
2094 ;; `org-export-filter-parse-tree-functions' variable.
2096 ;; - `:filter-body' applies to the body of the output, before template
2097 ;; translator chimes in. Users can set it through
2098 ;; `org-export-filter-body-functions' variable.
2100 ;; - `:filter-final-output' applies to the final transcoded string.
2101 ;; Users can set it with `org-export-filter-final-output-functions'
2102 ;; variable.
2104 ;; - `:filter-plain-text' applies to any string not recognized as Org
2105 ;; syntax. `org-export-filter-plain-text-functions' allows users to
2106 ;; configure it.
2108 ;; - `:filter-TYPE' applies on the string returned after an element or
2109 ;; object of type TYPE has been transcoded. A user can modify
2110 ;; `org-export-filter-TYPE-functions' to install these filters.
2112 ;; All filters sets are applied with
2113 ;; `org-export-filter-apply-functions' function. Filters in a set are
2114 ;; applied in a LIFO fashion. It allows developers to be sure that
2115 ;; their filters will be applied first.
2117 ;; Filters properties are installed in communication channel with
2118 ;; `org-export-install-filters' function.
2120 ;; Eventually, two hooks (`org-export-before-processing-hook' and
2121 ;; `org-export-before-parsing-hook') are run at the beginning of the
2122 ;; export process and just before parsing to allow for heavy structure
2123 ;; modifications.
2126 ;;;; Hooks
2128 (defvar org-export-before-processing-hook nil
2129 "Hook run at the beginning of the export process.
2131 This is run before include keywords and macros are expanded and
2132 Babel code blocks executed, on a copy of the original buffer
2133 being exported. Visibility and narrowing are preserved. Point
2134 is at the beginning of the buffer.
2136 Every function in this hook will be called with one argument: the
2137 back-end currently used, as a symbol.")
2139 (defvar org-export-before-parsing-hook nil
2140 "Hook run before parsing an export buffer.
2142 This is run after include keywords and macros have been expanded
2143 and Babel code blocks executed, on a copy of the original buffer
2144 being exported. Visibility and narrowing are preserved. Point
2145 is at the beginning of the buffer.
2147 Every function in this hook will be called with one argument: the
2148 back-end currently used, as a symbol.")
2151 ;;;; Special Filters
2153 (defvar org-export-filter-options-functions nil
2154 "List of functions applied to the export options.
2155 Each filter is called with two arguments: the export options, as
2156 a plist, and the back-end, as a symbol. It must return
2157 a property list containing export options.")
2159 (defvar org-export-filter-parse-tree-functions nil
2160 "List of functions applied to the parsed tree.
2161 Each filter is called with three arguments: the parse tree, as
2162 returned by `org-element-parse-buffer', the back-end, as
2163 a symbol, and the communication channel, as a plist. It must
2164 return the modified parse tree to transcode.")
2166 (defvar org-export-filter-plain-text-functions nil
2167 "List of functions applied to plain text.
2168 Each filter is called with three arguments: a string which
2169 contains no Org syntax, the back-end, as a symbol, and the
2170 communication channel, as a plist. It must return a string or
2171 nil.")
2173 (defvar org-export-filter-body-functions nil
2174 "List of functions applied to transcoded body.
2175 Each filter is called with three arguments: a string which
2176 contains no Org syntax, the back-end, as a symbol, and the
2177 communication channel, as a plist. It must return a string or
2178 nil.")
2180 (defvar org-export-filter-final-output-functions nil
2181 "List of functions applied to the transcoded string.
2182 Each filter is called with three arguments: the full transcoded
2183 string, the back-end, as a symbol, and the communication channel,
2184 as a plist. It must return a string that will be used as the
2185 final export output.")
2188 ;;;; Elements Filters
2190 (defvar org-export-filter-babel-call-functions nil
2191 "List of functions applied to a transcoded babel-call.
2192 Each filter is called with three arguments: the transcoded data,
2193 as a string, the back-end, as a symbol, and the communication
2194 channel, as a plist. It must return a string or nil.")
2196 (defvar org-export-filter-center-block-functions nil
2197 "List of functions applied to a transcoded center block.
2198 Each filter is called with three arguments: the transcoded data,
2199 as a string, the back-end, as a symbol, and the communication
2200 channel, as a plist. It must return a string or nil.")
2202 (defvar org-export-filter-clock-functions nil
2203 "List of functions applied to a transcoded clock.
2204 Each filter is called with three arguments: the transcoded data,
2205 as a string, the back-end, as a symbol, and the communication
2206 channel, as a plist. It must return a string or nil.")
2208 (defvar org-export-filter-diary-sexp-functions nil
2209 "List of functions applied to a transcoded diary-sexp.
2210 Each filter is called with three arguments: the transcoded data,
2211 as a string, the back-end, as a symbol, and the communication
2212 channel, as a plist. It must return a string or nil.")
2214 (defvar org-export-filter-drawer-functions nil
2215 "List of functions applied to a transcoded drawer.
2216 Each filter is called with three arguments: the transcoded data,
2217 as a string, the back-end, as a symbol, and the communication
2218 channel, as a plist. It must return a string or nil.")
2220 (defvar org-export-filter-dynamic-block-functions nil
2221 "List of functions applied to a transcoded dynamic-block.
2222 Each filter is called with three arguments: the transcoded data,
2223 as a string, the back-end, as a symbol, and the communication
2224 channel, as a plist. It must return a string or nil.")
2226 (defvar org-export-filter-example-block-functions nil
2227 "List of functions applied to a transcoded example-block.
2228 Each filter is called with three arguments: the transcoded data,
2229 as a string, the back-end, as a symbol, and the communication
2230 channel, as a plist. It must return a string or nil.")
2232 (defvar org-export-filter-export-block-functions nil
2233 "List of functions applied to a transcoded export-block.
2234 Each filter is called with three arguments: the transcoded data,
2235 as a string, the back-end, as a symbol, and the communication
2236 channel, as a plist. It must return a string or nil.")
2238 (defvar org-export-filter-fixed-width-functions nil
2239 "List of functions applied to a transcoded fixed-width.
2240 Each filter is called with three arguments: the transcoded data,
2241 as a string, the back-end, as a symbol, and the communication
2242 channel, as a plist. It must return a string or nil.")
2244 (defvar org-export-filter-footnote-definition-functions nil
2245 "List of functions applied to a transcoded footnote-definition.
2246 Each filter is called with three arguments: the transcoded data,
2247 as a string, the back-end, as a symbol, and the communication
2248 channel, as a plist. It must return a string or nil.")
2250 (defvar org-export-filter-headline-functions nil
2251 "List of functions applied to a transcoded headline.
2252 Each filter is called with three arguments: the transcoded data,
2253 as a string, the back-end, as a symbol, and the communication
2254 channel, as a plist. It must return a string or nil.")
2256 (defvar org-export-filter-horizontal-rule-functions nil
2257 "List of functions applied to a transcoded horizontal-rule.
2258 Each filter is called with three arguments: the transcoded data,
2259 as a string, the back-end, as a symbol, and the communication
2260 channel, as a plist. It must return a string or nil.")
2262 (defvar org-export-filter-inlinetask-functions nil
2263 "List of functions applied to a transcoded inlinetask.
2264 Each filter is called with three arguments: the transcoded data,
2265 as a string, the back-end, as a symbol, and the communication
2266 channel, as a plist. It must return a string or nil.")
2268 (defvar org-export-filter-item-functions nil
2269 "List of functions applied to a transcoded item.
2270 Each filter is called with three arguments: the transcoded data,
2271 as a string, the back-end, as a symbol, and the communication
2272 channel, as a plist. It must return a string or nil.")
2274 (defvar org-export-filter-keyword-functions nil
2275 "List of functions applied to a transcoded keyword.
2276 Each filter is called with three arguments: the transcoded data,
2277 as a string, the back-end, as a symbol, and the communication
2278 channel, as a plist. It must return a string or nil.")
2280 (defvar org-export-filter-latex-environment-functions nil
2281 "List of functions applied to a transcoded latex-environment.
2282 Each filter is called with three arguments: the transcoded data,
2283 as a string, the back-end, as a symbol, and the communication
2284 channel, as a plist. It must return a string or nil.")
2286 (defvar org-export-filter-node-property-functions nil
2287 "List of functions applied to a transcoded node-property.
2288 Each filter is called with three arguments: the transcoded data,
2289 as a string, the back-end, as a symbol, and the communication
2290 channel, as a plist. It must return a string or nil.")
2292 (defvar org-export-filter-paragraph-functions nil
2293 "List of functions applied to a transcoded paragraph.
2294 Each filter is called with three arguments: the transcoded data,
2295 as a string, the back-end, as a symbol, and the communication
2296 channel, as a plist. It must return a string or nil.")
2298 (defvar org-export-filter-plain-list-functions nil
2299 "List of functions applied to a transcoded plain-list.
2300 Each filter is called with three arguments: the transcoded data,
2301 as a string, the back-end, as a symbol, and the communication
2302 channel, as a plist. It must return a string or nil.")
2304 (defvar org-export-filter-planning-functions nil
2305 "List of functions applied to a transcoded planning.
2306 Each filter is called with three arguments: the transcoded data,
2307 as a string, the back-end, as a symbol, and the communication
2308 channel, as a plist. It must return a string or nil.")
2310 (defvar org-export-filter-property-drawer-functions nil
2311 "List of functions applied to a transcoded property-drawer.
2312 Each filter is called with three arguments: the transcoded data,
2313 as a string, the back-end, as a symbol, and the communication
2314 channel, as a plist. It must return a string or nil.")
2316 (defvar org-export-filter-quote-block-functions nil
2317 "List of functions applied to a transcoded quote block.
2318 Each filter is called with three arguments: the transcoded quote
2319 data, as a string, the back-end, as a symbol, and the
2320 communication channel, as a plist. It must return a string or
2321 nil.")
2323 (defvar org-export-filter-section-functions nil
2324 "List of functions applied to a transcoded section.
2325 Each filter is called with three arguments: the transcoded data,
2326 as a string, the back-end, as a symbol, and the communication
2327 channel, as a plist. It must return a string or nil.")
2329 (defvar org-export-filter-special-block-functions nil
2330 "List of functions applied to a transcoded special block.
2331 Each filter is called with three arguments: the transcoded data,
2332 as a string, the back-end, as a symbol, and the communication
2333 channel, as a plist. It must return a string or nil.")
2335 (defvar org-export-filter-src-block-functions nil
2336 "List of functions applied to a transcoded src-block.
2337 Each filter is called with three arguments: the transcoded data,
2338 as a string, the back-end, as a symbol, and the communication
2339 channel, as a plist. It must return a string or nil.")
2341 (defvar org-export-filter-table-functions nil
2342 "List of functions applied to a transcoded table.
2343 Each filter is called with three arguments: the transcoded data,
2344 as a string, the back-end, as a symbol, and the communication
2345 channel, as a plist. It must return a string or nil.")
2347 (defvar org-export-filter-table-cell-functions nil
2348 "List of functions applied to a transcoded table-cell.
2349 Each filter is called with three arguments: the transcoded data,
2350 as a string, the back-end, as a symbol, and the communication
2351 channel, as a plist. It must return a string or nil.")
2353 (defvar org-export-filter-table-row-functions nil
2354 "List of functions applied to a transcoded table-row.
2355 Each filter is called with three arguments: the transcoded data,
2356 as a string, the back-end, as a symbol, and the communication
2357 channel, as a plist. It must return a string or nil.")
2359 (defvar org-export-filter-verse-block-functions nil
2360 "List of functions applied to a transcoded verse block.
2361 Each filter is called with three arguments: the transcoded data,
2362 as a string, the back-end, as a symbol, and the communication
2363 channel, as a plist. It must return a string or nil.")
2366 ;;;; Objects Filters
2368 (defvar org-export-filter-bold-functions nil
2369 "List of functions applied to transcoded bold text.
2370 Each filter is called with three arguments: the transcoded data,
2371 as a string, the back-end, as a symbol, and the communication
2372 channel, as a plist. It must return a string or nil.")
2374 (defvar org-export-filter-code-functions nil
2375 "List of functions applied to transcoded code text.
2376 Each filter is called with three arguments: the transcoded data,
2377 as a string, the back-end, as a symbol, and the communication
2378 channel, as a plist. It must return a string or nil.")
2380 (defvar org-export-filter-entity-functions nil
2381 "List of functions applied to a transcoded entity.
2382 Each filter is called with three arguments: the transcoded data,
2383 as a string, the back-end, as a symbol, and the communication
2384 channel, as a plist. It must return a string or nil.")
2386 (defvar org-export-filter-export-snippet-functions nil
2387 "List of functions applied to a transcoded export-snippet.
2388 Each filter is called with three arguments: the transcoded data,
2389 as a string, the back-end, as a symbol, and the communication
2390 channel, as a plist. It must return a string or nil.")
2392 (defvar org-export-filter-footnote-reference-functions nil
2393 "List of functions applied to a transcoded footnote-reference.
2394 Each filter is called with three arguments: the transcoded data,
2395 as a string, the back-end, as a symbol, and the communication
2396 channel, as a plist. It must return a string or nil.")
2398 (defvar org-export-filter-inline-babel-call-functions nil
2399 "List of functions applied to a transcoded inline-babel-call.
2400 Each filter is called with three arguments: the transcoded data,
2401 as a string, the back-end, as a symbol, and the communication
2402 channel, as a plist. It must return a string or nil.")
2404 (defvar org-export-filter-inline-src-block-functions nil
2405 "List of functions applied to a transcoded inline-src-block.
2406 Each filter is called with three arguments: the transcoded data,
2407 as a string, the back-end, as a symbol, and the communication
2408 channel, as a plist. It must return a string or nil.")
2410 (defvar org-export-filter-italic-functions nil
2411 "List of functions applied to transcoded italic text.
2412 Each filter is called with three arguments: the transcoded data,
2413 as a string, the back-end, as a symbol, and the communication
2414 channel, as a plist. It must return a string or nil.")
2416 (defvar org-export-filter-latex-fragment-functions nil
2417 "List of functions applied to a transcoded latex-fragment.
2418 Each filter is called with three arguments: the transcoded data,
2419 as a string, the back-end, as a symbol, and the communication
2420 channel, as a plist. It must return a string or nil.")
2422 (defvar org-export-filter-line-break-functions nil
2423 "List of functions applied to a transcoded line-break.
2424 Each filter is called with three arguments: the transcoded data,
2425 as a string, the back-end, as a symbol, and the communication
2426 channel, as a plist. It must return a string or nil.")
2428 (defvar org-export-filter-link-functions nil
2429 "List of functions applied to a transcoded link.
2430 Each filter is called with three arguments: the transcoded data,
2431 as a string, the back-end, as a symbol, and the communication
2432 channel, as a plist. It must return a string or nil.")
2434 (defvar org-export-filter-radio-target-functions nil
2435 "List of functions applied to a transcoded radio-target.
2436 Each filter is called with three arguments: the transcoded data,
2437 as a string, the back-end, as a symbol, and the communication
2438 channel, as a plist. It must return a string or nil.")
2440 (defvar org-export-filter-statistics-cookie-functions nil
2441 "List of functions applied to a transcoded statistics-cookie.
2442 Each filter is called with three arguments: the transcoded data,
2443 as a string, the back-end, as a symbol, and the communication
2444 channel, as a plist. It must return a string or nil.")
2446 (defvar org-export-filter-strike-through-functions nil
2447 "List of functions applied to transcoded strike-through text.
2448 Each filter is called with three arguments: the transcoded data,
2449 as a string, the back-end, as a symbol, and the communication
2450 channel, as a plist. It must return a string or nil.")
2452 (defvar org-export-filter-subscript-functions nil
2453 "List of functions applied to a transcoded subscript.
2454 Each filter is called with three arguments: the transcoded data,
2455 as a string, the back-end, as a symbol, and the communication
2456 channel, as a plist. It must return a string or nil.")
2458 (defvar org-export-filter-superscript-functions nil
2459 "List of functions applied to a transcoded superscript.
2460 Each filter is called with three arguments: the transcoded data,
2461 as a string, the back-end, as a symbol, and the communication
2462 channel, as a plist. It must return a string or nil.")
2464 (defvar org-export-filter-target-functions nil
2465 "List of functions applied to a transcoded target.
2466 Each filter is called with three arguments: the transcoded data,
2467 as a string, the back-end, as a symbol, and the communication
2468 channel, as a plist. It must return a string or nil.")
2470 (defvar org-export-filter-timestamp-functions nil
2471 "List of functions applied to a transcoded timestamp.
2472 Each filter is called with three arguments: the transcoded data,
2473 as a string, the back-end, as a symbol, and the communication
2474 channel, as a plist. It must return a string or nil.")
2476 (defvar org-export-filter-underline-functions nil
2477 "List of functions applied to transcoded underline text.
2478 Each filter is called with three arguments: the transcoded data,
2479 as a string, the back-end, as a symbol, and the communication
2480 channel, as a plist. It must return a string or nil.")
2482 (defvar org-export-filter-verbatim-functions nil
2483 "List of functions applied to transcoded verbatim text.
2484 Each filter is called with three arguments: the transcoded data,
2485 as a string, the back-end, as a symbol, and the communication
2486 channel, as a plist. It must return a string or nil.")
2489 ;;;; Filters Tools
2491 ;; Internal function `org-export-install-filters' installs filters
2492 ;; hard-coded in back-ends (developer filters) and filters from global
2493 ;; variables (user filters) in the communication channel.
2495 ;; Internal function `org-export-filter-apply-functions' takes care
2496 ;; about applying each filter in order to a given data. It ignores
2497 ;; filters returning a nil value but stops whenever a filter returns
2498 ;; an empty string.
2500 (defun org-export-filter-apply-functions (filters value info)
2501 "Call every function in FILTERS.
2503 Functions are called with arguments VALUE, current export
2504 back-end's name and INFO. A function returning a nil value will
2505 be skipped. If it returns the empty string, the process ends and
2506 VALUE is ignored.
2508 Call is done in a LIFO fashion, to be sure that developer
2509 specified filters, if any, are called first."
2510 (catch 'exit
2511 (let* ((backend (plist-get info :back-end))
2512 (backend-name (and backend (org-export-backend-name backend))))
2513 (dolist (filter filters value)
2514 (let ((result (funcall filter value backend-name info)))
2515 (cond ((not result) value)
2516 ((equal value "") (throw 'exit nil))
2517 (t (setq value result))))))))
2519 (defun org-export-install-filters (info)
2520 "Install filters properties in communication channel.
2521 INFO is a plist containing the current communication channel.
2522 Return the updated communication channel."
2523 (let (plist)
2524 ;; Install user-defined filters with `org-export-filters-alist'
2525 ;; and filters already in INFO (through ext-plist mechanism).
2526 (dolist (p org-export-filters-alist)
2527 (let* ((prop (car p))
2528 (info-value (plist-get info prop))
2529 (default-value (symbol-value (cdr p))))
2530 (setq plist
2531 (plist-put plist prop
2532 ;; Filters in INFO will be called
2533 ;; before those user provided.
2534 (append (if (listp info-value) info-value
2535 (list info-value))
2536 default-value)))))
2537 ;; Prepend back-end specific filters to that list.
2538 (dolist (p (org-export-get-all-filters (plist-get info :back-end)))
2539 ;; Single values get consed, lists are appended.
2540 (let ((key (car p)) (value (cdr p)))
2541 (when value
2542 (setq plist
2543 (plist-put
2544 plist key
2545 (if (atom value) (cons value (plist-get plist key))
2546 (append value (plist-get plist key))))))))
2547 ;; Return new communication channel.
2548 (org-combine-plists info plist)))
2552 ;;; Core functions
2554 ;; This is the room for the main function, `org-export-as', along with
2555 ;; its derivative, `org-export-string-as'.
2556 ;; `org-export--copy-to-kill-ring-p' determines if output of these
2557 ;; function should be added to kill ring.
2559 ;; Note that `org-export-as' doesn't really parse the current buffer,
2560 ;; but a copy of it (with the same buffer-local variables and
2561 ;; visibility), where macros and include keywords are expanded and
2562 ;; Babel blocks are executed, if appropriate.
2563 ;; `org-export-with-buffer-copy' macro prepares that copy.
2565 ;; File inclusion is taken care of by
2566 ;; `org-export-expand-include-keyword' and
2567 ;; `org-export--prepare-file-contents'. Structure wise, including
2568 ;; a whole Org file in a buffer often makes little sense. For
2569 ;; example, if the file contains a headline and the include keyword
2570 ;; was within an item, the item should contain the headline. That's
2571 ;; why file inclusion should be done before any structure can be
2572 ;; associated to the file, that is before parsing.
2574 ;; `org-export-insert-default-template' is a command to insert
2575 ;; a default template (or a back-end specific template) at point or in
2576 ;; current subtree.
2578 (defun org-export-copy-buffer ()
2579 "Return a copy of the current buffer.
2580 The copy preserves Org buffer-local variables, visibility and
2581 narrowing."
2582 (let ((copy-buffer-fun (org-export--generate-copy-script (current-buffer)))
2583 (new-buf (generate-new-buffer (buffer-name))))
2584 (with-current-buffer new-buf
2585 (funcall copy-buffer-fun)
2586 (set-buffer-modified-p nil))
2587 new-buf))
2589 (defmacro org-export-with-buffer-copy (&rest body)
2590 "Apply BODY in a copy of the current buffer.
2591 The copy preserves local variables, visibility and contents of
2592 the original buffer. Point is at the beginning of the buffer
2593 when BODY is applied."
2594 (declare (debug t))
2595 (org-with-gensyms (buf-copy)
2596 `(let ((,buf-copy (org-export-copy-buffer)))
2597 (unwind-protect
2598 (with-current-buffer ,buf-copy
2599 (goto-char (point-min))
2600 (progn ,@body))
2601 (and (buffer-live-p ,buf-copy)
2602 ;; Kill copy without confirmation.
2603 (progn (with-current-buffer ,buf-copy
2604 (restore-buffer-modified-p nil))
2605 (kill-buffer ,buf-copy)))))))
2607 (defun org-export--generate-copy-script (buffer)
2608 "Generate a function duplicating BUFFER.
2610 The copy will preserve local variables, visibility, contents and
2611 narrowing of the original buffer. If a region was active in
2612 BUFFER, contents will be narrowed to that region instead.
2614 The resulting function can be evaluated at a later time, from
2615 another buffer, effectively cloning the original buffer there.
2617 The function assumes BUFFER's major mode is `org-mode'."
2618 (with-current-buffer buffer
2619 `(lambda ()
2620 (let ((inhibit-modification-hooks t))
2621 ;; Set major mode. Ignore `org-mode-hook' as it has been run
2622 ;; already in BUFFER.
2623 (let ((org-mode-hook nil) (org-inhibit-startup t)) (org-mode))
2624 ;; Copy specific buffer local variables and variables set
2625 ;; through BIND keywords.
2626 ,@(let ((bound-variables (org-export--list-bound-variables))
2627 vars)
2628 (dolist (entry (buffer-local-variables (buffer-base-buffer)) vars)
2629 (when (consp entry)
2630 (let ((var (car entry))
2631 (val (cdr entry)))
2632 (and (not (memq var org-export-ignored-local-variables))
2633 (or (memq var
2634 '(default-directory
2635 buffer-file-name
2636 buffer-file-coding-system))
2637 (assq var bound-variables)
2638 (string-match "^\\(org-\\|orgtbl-\\)"
2639 (symbol-name var)))
2640 ;; Skip unreadable values, as they cannot be
2641 ;; sent to external process.
2642 (or (not val) (ignore-errors (read (format "%S" val))))
2643 (push `(set (make-local-variable (quote ,var))
2644 (quote ,val))
2645 vars))))))
2646 ;; Whole buffer contents.
2647 (insert
2648 ,(org-with-wide-buffer
2649 (buffer-substring-no-properties
2650 (point-min) (point-max))))
2651 ;; Narrowing.
2652 ,(if (org-region-active-p)
2653 `(narrow-to-region ,(region-beginning) ,(region-end))
2654 `(narrow-to-region ,(point-min) ,(point-max)))
2655 ;; Current position of point.
2656 (goto-char ,(point))
2657 ;; Overlays with invisible property.
2658 ,@(let (ov-set)
2659 (dolist (ov (overlays-in (point-min) (point-max)) ov-set)
2660 (let ((invis-prop (overlay-get ov 'invisible)))
2661 (when invis-prop
2662 (push `(overlay-put
2663 (make-overlay ,(overlay-start ov)
2664 ,(overlay-end ov))
2665 'invisible (quote ,invis-prop))
2666 ov-set)))))))))
2668 (defun org-export--delete-comments ()
2669 "Delete commented areas in the buffer.
2670 Commented areas are comments, comment blocks, commented trees and
2671 inlinetasks. Trailing blank lines after a comment or a comment
2672 block are preserved. Narrowing, if any, is ignored."
2673 (org-with-wide-buffer
2674 (goto-char (point-min))
2675 (let ((regexp (concat org-outline-regexp-bol ".*" org-comment-string
2676 "\\|"
2677 "^[ \t]*#\\(?: \\|$\\|\\+begin_comment\\)"))
2678 (case-fold-search t))
2679 (while (re-search-forward regexp nil t)
2680 (let ((e (org-element-at-point)))
2681 (cl-case (org-element-type e)
2682 ((comment comment-block)
2683 (delete-region (org-element-property :begin e)
2684 (progn (goto-char (org-element-property :end e))
2685 (skip-chars-backward " \r\t\n")
2686 (line-beginning-position 2))))
2687 ((headline inlinetask)
2688 (when (org-element-property :commentedp e)
2689 (delete-region (org-element-property :begin e)
2690 (org-element-property :end e))))))))))
2692 (defun org-export--prune-tree (data info)
2693 "Prune non exportable elements from DATA.
2694 DATA is the parse tree to traverse. INFO is the plist holding
2695 export info. Also set `:ignore-list' in INFO to a list of
2696 objects which should be ignored during export, but not removed
2697 from tree."
2698 (letrec ((ignore)
2699 ;; First find trees containing a select tag, if any.
2700 (selected (org-export--selected-trees data info))
2701 (walk-data
2702 (lambda (data)
2703 ;; Prune non-exportable elements and objects from tree.
2704 ;; As a special case, special rows and cells from tables
2705 ;; are stored in IGNORE, as they still need to be
2706 ;; accessed during export.
2707 (when data
2708 (let ((type (org-element-type data)))
2709 (if (org-export--skip-p data info selected)
2710 (if (memq type '(table-cell table-row)) (push data ignore)
2711 (org-element-extract-element data))
2712 (if (and (eq type 'headline)
2713 (eq (plist-get info :with-archived-trees)
2714 'headline)
2715 (org-element-property :archivedp data))
2716 ;; If headline is archived but tree below has
2717 ;; to be skipped, remove contents.
2718 (org-element-set-contents data)
2719 ;; Move into recursive objects/elements.
2720 (mapc walk-data (org-element-contents data)))
2721 ;; Move into secondary string, if any.
2722 (dolist (p (cdr (assq type
2723 org-element-secondary-value-alist)))
2724 (mapc walk-data (org-element-property p data)))))))))
2725 ;; If a select tag is active, also ignore the section before the
2726 ;; first headline, if any.
2727 (when selected
2728 (let ((first-element (car (org-element-contents data))))
2729 (when (eq (org-element-type first-element) 'section)
2730 (org-element-extract-element first-element))))
2731 ;; Prune tree and communication channel.
2732 (funcall walk-data data)
2733 (dolist (entry
2734 (append
2735 ;; Priority is given to back-end specific options.
2736 (org-export-get-all-options (plist-get info :back-end))
2737 org-export-options-alist))
2738 (when (eq (nth 4 entry) 'parse)
2739 (funcall walk-data (plist-get info (car entry)))))
2740 ;; Eventually set `:ignore-list'.
2741 (plist-put info :ignore-list ignore)))
2743 (defun org-export--remove-uninterpreted-data (data info)
2744 "Change uninterpreted elements back into Org syntax.
2745 DATA is the parse tree. INFO is a plist containing export
2746 options. Each uninterpreted element or object is changed back
2747 into a string. Contents, if any, are not modified. The parse
2748 tree is modified by side effect."
2749 (org-export--remove-uninterpreted-data-1 data info)
2750 (dolist (entry org-export-options-alist)
2751 (when (eq (nth 4 entry) 'parse)
2752 (let ((p (car entry)))
2753 (plist-put info
2755 (org-export--remove-uninterpreted-data-1
2756 (plist-get info p)
2757 info))))))
2759 (defun org-export--remove-uninterpreted-data-1 (data info)
2760 "Change uninterpreted elements back into Org syntax.
2761 DATA is a parse tree or a secondary string. INFO is a plist
2762 containing export options. It is modified by side effect and
2763 returned by the function."
2764 (org-element-map data
2765 '(entity bold italic latex-environment latex-fragment strike-through
2766 subscript superscript underline)
2767 (lambda (blob)
2768 (let ((new
2769 (cl-case (org-element-type blob)
2770 ;; ... entities...
2771 (entity
2772 (and (not (plist-get info :with-entities))
2773 (list (concat
2774 (org-export-expand blob nil)
2775 (make-string
2776 (or (org-element-property :post-blank blob) 0)
2777 ?\s)))))
2778 ;; ... emphasis...
2779 ((bold italic strike-through underline)
2780 (and (not (plist-get info :with-emphasize))
2781 (let ((marker (cl-case (org-element-type blob)
2782 (bold "*")
2783 (italic "/")
2784 (strike-through "+")
2785 (underline "_"))))
2786 (append
2787 (list marker)
2788 (org-element-contents blob)
2789 (list (concat
2790 marker
2791 (make-string
2792 (or (org-element-property :post-blank blob)
2794 ?\s)))))))
2795 ;; ... LaTeX environments and fragments...
2796 ((latex-environment latex-fragment)
2797 (and (eq (plist-get info :with-latex) 'verbatim)
2798 (list (org-export-expand blob nil))))
2799 ;; ... sub/superscripts...
2800 ((subscript superscript)
2801 (let ((sub/super-p (plist-get info :with-sub-superscript))
2802 (bracketp (org-element-property :use-brackets-p blob)))
2803 (and (or (not sub/super-p)
2804 (and (eq sub/super-p '{}) (not bracketp)))
2805 (append
2806 (list (concat
2807 (if (eq (org-element-type blob) 'subscript)
2809 "^")
2810 (and bracketp "{")))
2811 (org-element-contents blob)
2812 (list (concat
2813 (and bracketp "}")
2814 (and (org-element-property :post-blank blob)
2815 (make-string
2816 (org-element-property :post-blank blob)
2817 ?\s)))))))))))
2818 (when new
2819 ;; Splice NEW at BLOB location in parse tree.
2820 (dolist (e new (org-element-extract-element blob))
2821 (unless (string= e "") (org-element-insert-before e blob))))))
2822 info nil nil t)
2823 ;; Return modified parse tree.
2824 data)
2826 (defun org-export--merge-external-footnote-definitions (tree)
2827 "Insert footnote definitions outside parsing scope in TREE.
2829 If there is a footnote section in TREE, definitions found are
2830 appended to it. If `org-footnote-section' is non-nil, a new
2831 footnote section containing all definitions is inserted in TREE.
2832 Otherwise, definitions are appended at the end of the section
2833 containing their first reference.
2835 Only definitions actually referred to within TREE, directly or
2836 not, are considered."
2837 (let* ((collect-labels
2838 (lambda (data)
2839 (org-element-map data 'footnote-reference
2840 (lambda (f)
2841 (and (eq (org-element-property :type f) 'standard)
2842 (org-element-property :label f))))))
2843 (referenced-labels (funcall collect-labels tree)))
2844 (when referenced-labels
2845 (let* ((definitions)
2846 (push-definition
2847 (lambda (datum)
2848 (cl-case (org-element-type datum)
2849 (footnote-definition
2850 (push (save-restriction
2851 (narrow-to-region (org-element-property :begin datum)
2852 (org-element-property :end datum))
2853 (org-element-map (org-element-parse-buffer)
2854 'footnote-definition #'identity nil t))
2855 definitions))
2856 (footnote-reference
2857 (let ((label (org-element-property :label datum))
2858 (cbeg (org-element-property :contents-begin datum)))
2859 (when (and label cbeg
2860 (eq (org-element-property :type datum) 'inline))
2861 (push
2862 (apply #'org-element-create
2863 'footnote-definition
2864 (list :label label :post-blank 1)
2865 (org-element-parse-secondary-string
2866 (buffer-substring
2867 cbeg (org-element-property :contents-end datum))
2868 (org-element-restriction 'footnote-reference)))
2869 definitions))))))))
2870 ;; Collect all out of scope definitions.
2871 (save-excursion
2872 (goto-char (point-min))
2873 (org-with-wide-buffer
2874 (while (re-search-backward org-footnote-re nil t)
2875 (funcall push-definition (org-element-context))))
2876 (goto-char (point-max))
2877 (org-with-wide-buffer
2878 (while (re-search-forward org-footnote-re nil t)
2879 (funcall push-definition (org-element-context)))))
2880 ;; Filter out definitions referenced neither in the original
2881 ;; tree nor in the external definitions.
2882 (let* ((directly-referenced
2883 (cl-remove-if-not
2884 (lambda (d)
2885 (member (org-element-property :label d) referenced-labels))
2886 definitions))
2887 (all-labels
2888 (append (funcall collect-labels directly-referenced)
2889 referenced-labels)))
2890 (setq definitions
2891 (cl-remove-if-not
2892 (lambda (d)
2893 (member (org-element-property :label d) all-labels))
2894 definitions)))
2895 ;; Install definitions in subtree.
2896 (cond
2897 ((null definitions))
2898 ;; If there is a footnote section, insert them here.
2899 ((let ((footnote-section
2900 (org-element-map tree 'headline
2901 (lambda (h)
2902 (and (org-element-property :footnote-section-p h) h))
2903 nil t)))
2904 (and footnote-section
2905 (apply #'org-element-adopt-elements (nreverse definitions)))))
2906 ;; If there should be a footnote section, create one containing
2907 ;; all the definitions at the end of the tree.
2908 (org-footnote-section
2909 (org-element-adopt-elements
2910 tree
2911 (org-element-create 'headline
2912 (list :footnote-section-p t
2913 :level 1
2914 :title org-footnote-section)
2915 (apply #'org-element-create
2916 'section
2918 (nreverse definitions)))))
2919 ;; Otherwise add each definition at the end of the section where
2920 ;; it is first referenced.
2922 (letrec ((seen)
2923 (insert-definitions
2924 (lambda (data)
2925 ;; Insert definitions in the same section as
2926 ;; their first reference in DATA.
2927 (org-element-map data 'footnote-reference
2928 (lambda (f)
2929 (when (eq (org-element-property :type f) 'standard)
2930 (let ((label (org-element-property :label f)))
2931 (unless (member label seen)
2932 (push label seen)
2933 (let ((definition
2934 (catch 'found
2935 (dolist (d definitions)
2936 (when (equal
2937 (org-element-property :label
2939 label)
2940 (setq definitions
2941 (delete d definitions))
2942 (throw 'found d))))))
2943 (when definition
2944 (org-element-adopt-elements
2945 (org-element-lineage f '(section))
2946 definition)
2947 (funcall insert-definitions
2948 definition)))))))))))
2949 (funcall insert-definitions tree))))))))
2951 ;;;###autoload
2952 (defun org-export-as
2953 (backend &optional subtreep visible-only body-only ext-plist)
2954 "Transcode current Org buffer into BACKEND code.
2956 BACKEND is either an export back-end, as returned by, e.g.,
2957 `org-export-create-backend', or a symbol referring to
2958 a registered back-end.
2960 If narrowing is active in the current buffer, only transcode its
2961 narrowed part.
2963 If a region is active, transcode that region.
2965 When optional argument SUBTREEP is non-nil, transcode the
2966 sub-tree at point, extracting information from the headline
2967 properties first.
2969 When optional argument VISIBLE-ONLY is non-nil, don't export
2970 contents of hidden elements.
2972 When optional argument BODY-ONLY is non-nil, only return body
2973 code, without surrounding template.
2975 Optional argument EXT-PLIST, when provided, is a property list
2976 with external parameters overriding Org default settings, but
2977 still inferior to file-local settings.
2979 Return code as a string."
2980 (when (symbolp backend) (setq backend (org-export-get-backend backend)))
2981 (org-export-barf-if-invalid-backend backend)
2982 (save-excursion
2983 (save-restriction
2984 ;; Narrow buffer to an appropriate region or subtree for
2985 ;; parsing. If parsing subtree, be sure to remove main headline
2986 ;; too.
2987 (cond ((org-region-active-p)
2988 (narrow-to-region (region-beginning) (region-end)))
2989 (subtreep
2990 (org-narrow-to-subtree)
2991 (goto-char (point-min))
2992 (forward-line)
2993 (narrow-to-region (point) (point-max))))
2994 ;; Initialize communication channel with original buffer
2995 ;; attributes, unavailable in its copy.
2996 (let* ((org-export-current-backend (org-export-backend-name backend))
2997 (info (org-combine-plists
2998 (org-export--get-export-attributes
2999 backend subtreep visible-only body-only)
3000 (org-export--get-buffer-attributes)))
3001 (parsed-keywords
3002 (delq nil
3003 (mapcar (lambda (o) (and (eq (nth 4 o) 'parse) (nth 1 o)))
3004 (append (org-export-get-all-options backend)
3005 org-export-options-alist))))
3006 tree)
3007 ;; Update communication channel and get parse tree. Buffer
3008 ;; isn't parsed directly. Instead, all buffer modifications
3009 ;; and consequent parsing are undertaken in a temporary copy.
3010 (org-export-with-buffer-copy
3011 ;; Run first hook with current back-end's name as argument.
3012 (run-hook-with-args 'org-export-before-processing-hook
3013 (org-export-backend-name backend))
3014 ;; Include files, delete comments and expand macros.
3015 (org-export-expand-include-keyword)
3016 (org-export--delete-comments)
3017 (org-macro-initialize-templates)
3018 (org-macro-replace-all org-macro-templates nil parsed-keywords)
3019 ;; Refresh buffer properties and radio targets after
3020 ;; potentially invasive previous changes. Likewise, do it
3021 ;; again after executing Babel code.
3022 (org-set-regexps-and-options)
3023 (org-update-radio-target-regexp)
3024 (org-export-execute-babel-code)
3025 (org-set-regexps-and-options)
3026 (org-update-radio-target-regexp)
3027 ;; Run last hook with current back-end's name as argument.
3028 ;; Update buffer properties and radio targets one last time
3029 ;; before parsing.
3030 (goto-char (point-min))
3031 (save-excursion
3032 (run-hook-with-args 'org-export-before-parsing-hook
3033 (org-export-backend-name backend)))
3034 (org-set-regexps-and-options)
3035 (org-update-radio-target-regexp)
3036 ;; Update communication channel with environment. Also
3037 ;; install user's and developer's filters.
3038 (setq info
3039 (org-export-install-filters
3040 (org-combine-plists
3041 info (org-export-get-environment backend subtreep ext-plist))))
3042 ;; Call options filters and update export options. We do not
3043 ;; use `org-export-filter-apply-functions' here since the
3044 ;; arity of such filters is different.
3045 (let ((backend-name (org-export-backend-name backend)))
3046 (dolist (filter (plist-get info :filter-options))
3047 (let ((result (funcall filter info backend-name)))
3048 (when result (setq info result)))))
3049 ;; Expand export-specific set of macros: {{{author}}},
3050 ;; {{{date(FORMAT)}}}, {{{email}}} and {{{title}}}. It must
3051 ;; be done once regular macros have been expanded, since
3052 ;; parsed keywords may contain one of them.
3053 (org-macro-replace-all
3054 (list
3055 (cons "author" (org-element-interpret-data (plist-get info :author)))
3056 (cons "date"
3057 (let* ((date (plist-get info :date))
3058 (value (or (org-element-interpret-data date) "")))
3059 (if (and (consp date)
3060 (not (cdr date))
3061 (eq (org-element-type (car date)) 'timestamp))
3062 (format "(eval (if (org-string-nw-p \"$1\") %s %S))"
3063 (format "(org-timestamp-format '%S \"$1\")"
3064 (org-element-copy (car date)))
3065 value)
3066 value)))
3067 (cons "email" (org-element-interpret-data (plist-get info :email)))
3068 (cons "title" (org-element-interpret-data (plist-get info :title)))
3069 (cons "results" "$1"))
3070 'finalize
3071 parsed-keywords)
3072 ;; Parse buffer.
3073 (setq tree (org-element-parse-buffer nil visible-only))
3074 ;; Merge footnote definitions outside scope into parse tree.
3075 (org-export--merge-external-footnote-definitions tree)
3076 ;; Prune tree from non-exported elements and transform
3077 ;; uninterpreted elements or objects in both parse tree and
3078 ;; communication channel.
3079 (org-export--prune-tree tree info)
3080 (org-export--remove-uninterpreted-data tree info)
3081 ;; Call parse tree filters.
3082 (setq tree
3083 (org-export-filter-apply-functions
3084 (plist-get info :filter-parse-tree) tree info))
3085 ;; Now tree is complete, compute its properties and add them
3086 ;; to communication channel.
3087 (setq info (org-export--collect-tree-properties tree info))
3088 ;; Eventually transcode TREE. Wrap the resulting string into
3089 ;; a template.
3090 (let* ((body (org-element-normalize-string
3091 (or (org-export-data tree info) "")))
3092 (inner-template (cdr (assq 'inner-template
3093 (plist-get info :translate-alist))))
3094 (full-body (org-export-filter-apply-functions
3095 (plist-get info :filter-body)
3096 (if (not (functionp inner-template)) body
3097 (funcall inner-template body info))
3098 info))
3099 (template (cdr (assq 'template
3100 (plist-get info :translate-alist)))))
3101 ;; Remove all text properties since they cannot be
3102 ;; retrieved from an external process. Finally call
3103 ;; final-output filter and return result.
3104 (org-no-properties
3105 (org-export-filter-apply-functions
3106 (plist-get info :filter-final-output)
3107 (if (or (not (functionp template)) body-only) full-body
3108 (funcall template full-body info))
3109 info))))))))
3111 ;;;###autoload
3112 (defun org-export-string-as (string backend &optional body-only ext-plist)
3113 "Transcode STRING into BACKEND code.
3115 BACKEND is either an export back-end, as returned by, e.g.,
3116 `org-export-create-backend', or a symbol referring to
3117 a registered back-end.
3119 When optional argument BODY-ONLY is non-nil, only return body
3120 code, without preamble nor postamble.
3122 Optional argument EXT-PLIST, when provided, is a property list
3123 with external parameters overriding Org default settings, but
3124 still inferior to file-local settings.
3126 Return code as a string."
3127 (with-temp-buffer
3128 (insert string)
3129 (let ((org-inhibit-startup t)) (org-mode))
3130 (org-export-as backend nil nil body-only ext-plist)))
3132 ;;;###autoload
3133 (defun org-export-replace-region-by (backend)
3134 "Replace the active region by its export to BACKEND.
3135 BACKEND is either an export back-end, as returned by, e.g.,
3136 `org-export-create-backend', or a symbol referring to
3137 a registered back-end."
3138 (unless (org-region-active-p) (user-error "No active region to replace"))
3139 (insert
3140 (org-export-string-as
3141 (delete-and-extract-region (region-beginning) (region-end)) backend t)))
3143 ;;;###autoload
3144 (defun org-export-insert-default-template (&optional backend subtreep)
3145 "Insert all export keywords with default values at beginning of line.
3147 BACKEND is a symbol referring to the name of a registered export
3148 back-end, for which specific export options should be added to
3149 the template, or `default' for default template. When it is nil,
3150 the user will be prompted for a category.
3152 If SUBTREEP is non-nil, export configuration will be set up
3153 locally for the subtree through node properties."
3154 (interactive)
3155 (unless (derived-mode-p 'org-mode) (user-error "Not in an Org mode buffer"))
3156 (when (and subtreep (org-before-first-heading-p))
3157 (user-error "No subtree to set export options for"))
3158 (let ((node (and subtreep (save-excursion (org-back-to-heading t) (point))))
3159 (backend
3160 (or backend
3161 (intern
3162 (org-completing-read
3163 "Options category: "
3164 (cons "default"
3165 (mapcar (lambda (b)
3166 (symbol-name (org-export-backend-name b)))
3167 org-export-registered-backends))
3168 nil t))))
3169 options keywords)
3170 ;; Populate OPTIONS and KEYWORDS.
3171 (dolist (entry (cond ((eq backend 'default) org-export-options-alist)
3172 ((org-export-backend-p backend)
3173 (org-export-backend-options backend))
3174 (t (org-export-backend-options
3175 (org-export-get-backend backend)))))
3176 (let ((keyword (nth 1 entry))
3177 (option (nth 2 entry)))
3178 (cond
3179 (keyword (unless (assoc keyword keywords)
3180 (let ((value
3181 (if (eq (nth 4 entry) 'split)
3182 (mapconcat #'identity (eval (nth 3 entry)) " ")
3183 (eval (nth 3 entry)))))
3184 (push (cons keyword value) keywords))))
3185 (option (unless (assoc option options)
3186 (push (cons option (eval (nth 3 entry))) options))))))
3187 ;; Move to an appropriate location in order to insert options.
3188 (unless subtreep (beginning-of-line))
3189 ;; First (multiple) OPTIONS lines. Never go past fill-column.
3190 (when options
3191 (let ((items
3192 (mapcar
3193 #'(lambda (opt) (format "%s:%S" (car opt) (cdr opt)))
3194 (sort options (lambda (k1 k2) (string< (car k1) (car k2)))))))
3195 (if subtreep
3196 (org-entry-put
3197 node "EXPORT_OPTIONS" (mapconcat 'identity items " "))
3198 (while items
3199 (insert "#+OPTIONS:")
3200 (let ((width 10))
3201 (while (and items
3202 (< (+ width (length (car items)) 1) fill-column))
3203 (let ((item (pop items)))
3204 (insert " " item)
3205 (cl-incf width (1+ (length item))))))
3206 (insert "\n")))))
3207 ;; Then the rest of keywords, in the order specified in either
3208 ;; `org-export-options-alist' or respective export back-ends.
3209 (dolist (key (nreverse keywords))
3210 (let ((val (cond ((equal (car key) "DATE")
3211 (or (cdr key)
3212 (with-temp-buffer
3213 (org-insert-time-stamp (current-time)))))
3214 ((equal (car key) "TITLE")
3215 (or (let ((visited-file
3216 (buffer-file-name (buffer-base-buffer))))
3217 (and visited-file
3218 (file-name-sans-extension
3219 (file-name-nondirectory visited-file))))
3220 (buffer-name (buffer-base-buffer))))
3221 (t (cdr key)))))
3222 (if subtreep (org-entry-put node (concat "EXPORT_" (car key)) val)
3223 (insert
3224 (format "#+%s:%s\n"
3225 (car key)
3226 (if (org-string-nw-p val) (format " %s" val) ""))))))))
3228 (defun org-export-expand-include-keyword (&optional included dir footnotes)
3229 "Expand every include keyword in buffer.
3230 Optional argument INCLUDED is a list of included file names along
3231 with their line restriction, when appropriate. It is used to
3232 avoid infinite recursion. Optional argument DIR is the current
3233 working directory. It is used to properly resolve relative
3234 paths. Optional argument FOOTNOTES is a hash-table used for
3235 storing and resolving footnotes. It is created automatically."
3236 (let ((case-fold-search t)
3237 (file-prefix (make-hash-table :test #'equal))
3238 (current-prefix 0)
3239 (footnotes (or footnotes (make-hash-table :test #'equal)))
3240 (include-re "^[ \t]*#\\+INCLUDE:"))
3241 ;; If :minlevel is not set the text-property
3242 ;; `:org-include-induced-level' will be used to determine the
3243 ;; relative level when expanding INCLUDE.
3244 ;; Only affects included Org documents.
3245 (goto-char (point-min))
3246 (while (re-search-forward include-re nil t)
3247 (put-text-property (line-beginning-position) (line-end-position)
3248 :org-include-induced-level
3249 (1+ (org-reduced-level (or (org-current-level) 0)))))
3250 ;; Expand INCLUDE keywords.
3251 (goto-char (point-min))
3252 (while (re-search-forward include-re nil t)
3253 (let ((element (save-match-data (org-element-at-point))))
3254 (when (eq (org-element-type element) 'keyword)
3255 (beginning-of-line)
3256 ;; Extract arguments from keyword's value.
3257 (let* ((value (org-element-property :value element))
3258 (ind (org-get-indentation))
3259 location
3260 (file
3261 (and (string-match
3262 "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value)
3263 (prog1
3264 (save-match-data
3265 (let ((matched (match-string 1 value)))
3266 (when (string-match "\\(::\\(.*?\\)\\)\"?\\'"
3267 matched)
3268 (setq location (match-string 2 matched))
3269 (setq matched
3270 (replace-match "" nil nil matched 1)))
3271 (expand-file-name
3272 (org-remove-double-quotes
3273 matched)
3274 dir)))
3275 (setq value (replace-match "" nil nil value)))))
3276 (only-contents
3277 (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
3278 value)
3279 (prog1 (org-not-nil (match-string 1 value))
3280 (setq value (replace-match "" nil nil value)))))
3281 (lines
3282 (and (string-match
3283 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
3284 value)
3285 (prog1 (match-string 1 value)
3286 (setq value (replace-match "" nil nil value)))))
3287 (env (cond ((string-match "\\<example\\>" value)
3288 'literal)
3289 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
3290 'literal)))
3291 ;; Minimal level of included file defaults to the child
3292 ;; level of the current headline, if any, or one. It
3293 ;; only applies is the file is meant to be included as
3294 ;; an Org one.
3295 (minlevel
3296 (and (not env)
3297 (if (string-match ":minlevel +\\([0-9]+\\)" value)
3298 (prog1 (string-to-number (match-string 1 value))
3299 (setq value (replace-match "" nil nil value)))
3300 (get-text-property (point)
3301 :org-include-induced-level))))
3302 (src-args (and (eq env 'literal)
3303 (match-string 1 value)))
3304 (block (and (string-match "\\<\\(\\S-+\\)\\>" value)
3305 (match-string 1 value))))
3306 ;; Remove keyword.
3307 (delete-region (point) (progn (forward-line) (point)))
3308 (cond
3309 ((not file) nil)
3310 ((not (file-readable-p file))
3311 (error "Cannot include file %s" file))
3312 ;; Check if files has already been parsed. Look after
3313 ;; inclusion lines too, as different parts of the same file
3314 ;; can be included too.
3315 ((member (list file lines) included)
3316 (error "Recursive file inclusion: %s" file))
3318 (cond
3319 ((eq env 'literal)
3320 (insert
3321 (let ((ind-str (make-string ind ? ))
3322 (arg-str (if (stringp src-args)
3323 (format " %s" src-args)
3324 ""))
3325 (contents
3326 (org-escape-code-in-string
3327 (org-export--prepare-file-contents file lines))))
3328 (format "%s#+BEGIN_%s%s\n%s%s#+END_%s\n"
3329 ind-str block arg-str contents ind-str block))))
3330 ((stringp block)
3331 (insert
3332 (let ((ind-str (make-string ind ? ))
3333 (contents
3334 (org-export--prepare-file-contents file lines)))
3335 (format "%s#+BEGIN_%s\n%s%s#+END_%s\n"
3336 ind-str block contents ind-str block))))
3338 (insert
3339 (with-temp-buffer
3340 (let ((org-inhibit-startup t)
3341 (lines
3342 (if location
3343 (org-export--inclusion-absolute-lines
3344 file location only-contents lines)
3345 lines)))
3346 (org-mode)
3347 (insert
3348 (org-export--prepare-file-contents
3349 file lines ind minlevel
3350 (or (gethash file file-prefix)
3351 (puthash file (cl-incf current-prefix) file-prefix))
3352 footnotes)))
3353 (org-export-expand-include-keyword
3354 (cons (list file lines) included)
3355 (file-name-directory file)
3356 footnotes)
3357 (buffer-string)))))
3358 ;; Expand footnotes after all files have been included.
3359 ;; Footnotes are stored at end of buffer.
3360 (unless included
3361 (org-with-wide-buffer
3362 (goto-char (point-max))
3363 (maphash (lambda (k v) (insert (format "\n[%s] %s\n" k v)))
3364 footnotes)))))))))))
3366 (defun org-export--inclusion-absolute-lines (file location only-contents lines)
3367 "Resolve absolute lines for an included file with file-link.
3369 FILE is string file-name of the file to include. LOCATION is a
3370 string name within FILE to be included (located via
3371 `org-link-search'). If ONLY-CONTENTS is non-nil only the
3372 contents of the named element will be included, as determined
3373 Org-Element. If LINES is non-nil only those lines are included.
3375 Return a string of lines to be included in the format expected by
3376 `org-export--prepare-file-contents'."
3377 (with-temp-buffer
3378 (insert-file-contents file)
3379 (unless (eq major-mode 'org-mode)
3380 (let ((org-inhibit-startup t)) (org-mode)))
3381 (condition-case err
3382 ;; Enforce consistent search.
3383 (let ((org-link-search-must-match-exact-headline nil))
3384 (org-link-search location))
3385 (error
3386 (error "%s for %s::%s" (error-message-string err) file location)))
3387 (let* ((element (org-element-at-point))
3388 (contents-begin
3389 (and only-contents (org-element-property :contents-begin element))))
3390 (narrow-to-region
3391 (or contents-begin (org-element-property :begin element))
3392 (org-element-property (if contents-begin :contents-end :end) element))
3393 (when (and only-contents
3394 (memq (org-element-type element) '(headline inlinetask)))
3395 ;; Skip planning line and property-drawer.
3396 (goto-char (point-min))
3397 (when (org-looking-at-p org-planning-line-re) (forward-line))
3398 (when (looking-at org-property-drawer-re) (goto-char (match-end 0)))
3399 (unless (bolp) (forward-line))
3400 (narrow-to-region (point) (point-max))))
3401 (when lines
3402 (org-skip-whitespace)
3403 (beginning-of-line)
3404 (let* ((lines (split-string lines "-"))
3405 (lbeg (string-to-number (car lines)))
3406 (lend (string-to-number (cadr lines)))
3407 (beg (if (zerop lbeg) (point-min)
3408 (goto-char (point-min))
3409 (forward-line (1- lbeg))
3410 (point)))
3411 (end (if (zerop lend) (point-max)
3412 (goto-char beg)
3413 (forward-line (1- lend))
3414 (point))))
3415 (narrow-to-region beg end)))
3416 (let ((end (point-max)))
3417 (goto-char (point-min))
3418 (widen)
3419 (let ((start-line (line-number-at-pos)))
3420 (format "%d-%d"
3421 start-line
3422 (save-excursion
3423 (+ start-line
3424 (let ((counter 0))
3425 (while (< (point) end) (cl-incf counter) (forward-line))
3426 counter))))))))
3428 (defun org-export--prepare-file-contents
3429 (file &optional lines ind minlevel id footnotes)
3430 "Prepare contents of FILE for inclusion and return it as a string.
3432 When optional argument LINES is a string specifying a range of
3433 lines, include only those lines.
3435 Optional argument IND, when non-nil, is an integer specifying the
3436 global indentation of returned contents. Since its purpose is to
3437 allow an included file to stay in the same environment it was
3438 created (e.g., a list item), it doesn't apply past the first
3439 headline encountered.
3441 Optional argument MINLEVEL, when non-nil, is an integer
3442 specifying the level that any top-level headline in the included
3443 file should have.
3445 Optional argument ID is an integer that will be inserted before
3446 each footnote definition and reference if FILE is an Org file.
3447 This is useful to avoid conflicts when more than one Org file
3448 with footnotes is included in a document.
3450 Optional argument FOOTNOTES is a hash-table to store footnotes in
3451 the included document."
3452 (with-temp-buffer
3453 (insert-file-contents file)
3454 (when lines
3455 (let* ((lines (split-string lines "-"))
3456 (lbeg (string-to-number (car lines)))
3457 (lend (string-to-number (cadr lines)))
3458 (beg (if (zerop lbeg) (point-min)
3459 (goto-char (point-min))
3460 (forward-line (1- lbeg))
3461 (point)))
3462 (end (if (zerop lend) (point-max)
3463 (goto-char (point-min))
3464 (forward-line (1- lend))
3465 (point))))
3466 (narrow-to-region beg end)))
3467 ;; Remove blank lines at beginning and end of contents. The logic
3468 ;; behind that removal is that blank lines around include keyword
3469 ;; override blank lines in included file.
3470 (goto-char (point-min))
3471 (org-skip-whitespace)
3472 (beginning-of-line)
3473 (delete-region (point-min) (point))
3474 (goto-char (point-max))
3475 (skip-chars-backward " \r\t\n")
3476 (forward-line)
3477 (delete-region (point) (point-max))
3478 ;; If IND is set, preserve indentation of include keyword until
3479 ;; the first headline encountered.
3480 (when (and ind (> ind 0))
3481 (unless (eq major-mode 'org-mode)
3482 (let ((org-inhibit-startup t)) (org-mode)))
3483 (goto-char (point-min))
3484 (let ((ind-str (make-string ind ? )))
3485 (while (not (or (eobp) (looking-at org-outline-regexp-bol)))
3486 ;; Do not move footnote definitions out of column 0.
3487 (unless (and (looking-at org-footnote-definition-re)
3488 (eq (org-element-type (org-element-at-point))
3489 'footnote-definition))
3490 (insert ind-str))
3491 (forward-line))))
3492 ;; When MINLEVEL is specified, compute minimal level for headlines
3493 ;; in the file (CUR-MIN), and remove stars to each headline so
3494 ;; that headlines with minimal level have a level of MINLEVEL.
3495 (when minlevel
3496 (unless (eq major-mode 'org-mode)
3497 (let ((org-inhibit-startup t)) (org-mode)))
3498 (org-with-limited-levels
3499 (let ((levels (org-map-entries
3500 (lambda () (org-reduced-level (org-current-level))))))
3501 (when levels
3502 (let ((offset (- minlevel (apply #'min levels))))
3503 (unless (zerop offset)
3504 (when org-odd-levels-only (setq offset (* offset 2)))
3505 ;; Only change stars, don't bother moving whole
3506 ;; sections.
3507 (org-map-entries
3508 (lambda ()
3509 (if (< offset 0) (delete-char (abs offset))
3510 (insert (make-string offset ?*)))))))))))
3511 ;; Append ID to all footnote references and definitions, so they
3512 ;; become file specific and cannot collide with footnotes in other
3513 ;; included files. Further, collect relevant footnote definitions
3514 ;; outside of LINES, in order to reintroduce them later.
3515 (when id
3516 (let ((marker-min (point-min-marker))
3517 (marker-max (point-max-marker))
3518 (get-new-label
3519 (lambda (label)
3520 ;; Generate new label from LABEL. If LABEL is akin to
3521 ;; [1] convert it to [fn:--ID-1]. Otherwise add "-ID-"
3522 ;; after "fn:".
3523 (if (org-string-match-p "\\`[0-9]+\\'" label)
3524 (format "fn:--%d-%s" id label)
3525 (format "fn:-%d-%s" id (substring label 3)))))
3526 (set-new-label
3527 (lambda (f old new)
3528 ;; Replace OLD label with NEW in footnote F.
3529 (save-excursion
3530 (goto-char (1+ (org-element-property :begin f)))
3531 (looking-at (regexp-quote old))
3532 (replace-match new))))
3533 (seen-alist))
3534 (goto-char (point-min))
3535 (while (re-search-forward org-footnote-re nil t)
3536 (let ((footnote (save-excursion
3537 (backward-char)
3538 (org-element-context))))
3539 (when (memq (org-element-type footnote)
3540 '(footnote-definition footnote-reference))
3541 (let* ((label (org-element-property :label footnote)))
3542 ;; Update the footnote-reference at point and collect
3543 ;; the new label, which is only used for footnotes
3544 ;; outsides LINES.
3545 (when label
3546 (let ((seen (cdr (assoc label seen-alist))))
3547 (if seen (funcall set-new-label footnote label seen)
3548 (let ((new (funcall get-new-label label)))
3549 (push (cons label new) seen-alist)
3550 (org-with-wide-buffer
3551 (let* ((def (org-footnote-get-definition label))
3552 (beg (nth 1 def)))
3553 (when (and def
3554 (or (< beg marker-min)
3555 (>= beg marker-max)))
3556 ;; Store since footnote-definition is
3557 ;; outside of LINES.
3558 (puthash new
3559 (org-element-normalize-string (nth 3 def))
3560 footnotes))))
3561 (funcall set-new-label footnote label new)))))))))
3562 (set-marker marker-min nil)
3563 (set-marker marker-max nil)))
3564 (org-element-normalize-string (buffer-string))))
3566 (defun org-export-execute-babel-code ()
3567 "Execute every Babel code in the visible part of current buffer."
3568 ;; Get a pristine copy of current buffer so Babel references can be
3569 ;; properly resolved.
3570 (let ((reference (org-export-copy-buffer)))
3571 (unwind-protect (org-babel-exp-process-buffer reference)
3572 (kill-buffer reference))))
3574 (defun org-export--copy-to-kill-ring-p ()
3575 "Return a non-nil value when output should be added to the kill ring.
3576 See also `org-export-copy-to-kill-ring'."
3577 (if (eq org-export-copy-to-kill-ring 'if-interactive)
3578 (not (or executing-kbd-macro noninteractive))
3579 (eq org-export-copy-to-kill-ring t)))
3583 ;;; Tools For Back-Ends
3585 ;; A whole set of tools is available to help build new exporters. Any
3586 ;; function general enough to have its use across many back-ends
3587 ;; should be added here.
3589 ;;;; For Affiliated Keywords
3591 ;; `org-export-read-attribute' reads a property from a given element
3592 ;; as a plist. It can be used to normalize affiliated keywords'
3593 ;; syntax.
3595 ;; Since captions can span over multiple lines and accept dual values,
3596 ;; their internal representation is a bit tricky. Therefore,
3597 ;; `org-export-get-caption' transparently returns a given element's
3598 ;; caption as a secondary string.
3600 (defun org-export-read-attribute (attribute element &optional property)
3601 "Turn ATTRIBUTE property from ELEMENT into a plist.
3603 When optional argument PROPERTY is non-nil, return the value of
3604 that property within attributes.
3606 This function assumes attributes are defined as \":keyword
3607 value\" pairs. It is appropriate for `:attr_html' like
3608 properties.
3610 All values will become strings except the empty string and
3611 \"nil\", which will become nil. Also, values containing only
3612 double quotes will be read as-is, which means that \"\" value
3613 will become the empty string."
3614 (let* ((prepare-value
3615 (lambda (str)
3616 (save-match-data
3617 (cond ((member str '(nil "" "nil")) nil)
3618 ((string-match "^\"\\(\"+\\)?\"$" str)
3619 (or (match-string 1 str) ""))
3620 (t str)))))
3621 (attributes
3622 (let ((value (org-element-property attribute element)))
3623 (when value
3624 (let ((s (mapconcat 'identity value " ")) result)
3625 (while (string-match
3626 "\\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ \t]+\\|$\\)"
3628 (let ((value (substring s 0 (match-beginning 0))))
3629 (push (funcall prepare-value value) result))
3630 (push (intern (match-string 1 s)) result)
3631 (setq s (substring s (match-end 0))))
3632 ;; Ignore any string before first property with `cdr'.
3633 (cdr (nreverse (cons (funcall prepare-value s) result))))))))
3634 (if property (plist-get attributes property) attributes)))
3636 (defun org-export-get-caption (element &optional shortp)
3637 "Return caption from ELEMENT as a secondary string.
3639 When optional argument SHORTP is non-nil, return short caption,
3640 as a secondary string, instead.
3642 Caption lines are separated by a white space."
3643 (let ((full-caption (org-element-property :caption element)) caption)
3644 (dolist (line full-caption (cdr caption))
3645 (let ((cap (funcall (if shortp 'cdr 'car) line)))
3646 (when cap
3647 (setq caption (nconc (list " ") (copy-sequence cap) caption)))))))
3650 ;;;; For Derived Back-ends
3652 ;; `org-export-with-backend' is a function allowing to locally use
3653 ;; another back-end to transcode some object or element. In a derived
3654 ;; back-end, it may be used as a fall-back function once all specific
3655 ;; cases have been treated.
3657 (defun org-export-with-backend (backend data &optional contents info)
3658 "Call a transcoder from BACKEND on DATA.
3659 BACKEND is an export back-end, as returned by, e.g.,
3660 `org-export-create-backend', or a symbol referring to
3661 a registered back-end. DATA is an Org element, object, secondary
3662 string or string. CONTENTS, when non-nil, is the transcoded
3663 contents of DATA element, as a string. INFO, when non-nil, is
3664 the communication channel used for export, as a plist."
3665 (when (symbolp backend) (setq backend (org-export-get-backend backend)))
3666 (org-export-barf-if-invalid-backend backend)
3667 (let ((type (org-element-type data)))
3668 (if (memq type '(nil org-data)) (error "No foreign transcoder available")
3669 (let* ((all-transcoders (org-export-get-all-transcoders backend))
3670 (transcoder (cdr (assq type all-transcoders))))
3671 (if (not (functionp transcoder))
3672 (error "No foreign transcoder available")
3673 (funcall
3674 transcoder data contents
3675 (org-combine-plists
3676 info (list
3677 :back-end backend
3678 :translate-alist all-transcoders
3679 :exported-data (make-hash-table :test #'eq :size 401)))))))))
3682 ;;;; For Export Snippets
3684 ;; Every export snippet is transmitted to the back-end. Though, the
3685 ;; latter will only retain one type of export-snippet, ignoring
3686 ;; others, based on the former's target back-end. The function
3687 ;; `org-export-snippet-backend' returns that back-end for a given
3688 ;; export-snippet.
3690 (defun org-export-snippet-backend (export-snippet)
3691 "Return EXPORT-SNIPPET targeted back-end as a symbol.
3692 Translation, with `org-export-snippet-translation-alist', is
3693 applied."
3694 (let ((back-end (org-element-property :back-end export-snippet)))
3695 (intern
3696 (or (cdr (assoc back-end org-export-snippet-translation-alist))
3697 back-end))))
3700 ;;;; For Footnotes
3702 ;; `org-export-collect-footnote-definitions' is a tool to list
3703 ;; actually used footnotes definitions in the whole parse tree, or in
3704 ;; a headline, in order to add footnote listings throughout the
3705 ;; transcoded data.
3707 ;; `org-export-footnote-first-reference-p' is a predicate used by some
3708 ;; back-ends, when they need to attach the footnote definition only to
3709 ;; the first occurrence of the corresponding label.
3711 ;; `org-export-get-footnote-definition' and
3712 ;; `org-export-get-footnote-number' provide easier access to
3713 ;; additional information relative to a footnote reference.
3715 (defun org-export-get-footnote-definition (footnote-reference info)
3716 "Return definition of FOOTNOTE-REFERENCE as parsed data.
3717 INFO is the plist used as a communication channel. If no such
3718 definition can be found, raise an error."
3719 (let ((label (org-element-property :label footnote-reference)))
3720 (if (not label) (org-element-contents footnote-reference)
3721 (let ((cache (or (plist-get info :footnote-definition-cache)
3722 (let ((hash (make-hash-table :test #'equal)))
3723 (plist-put info :footnote-definition-cache hash)
3724 hash))))
3725 (or (gethash label cache)
3726 (puthash label
3727 (org-element-map (plist-get info :parse-tree)
3728 '(footnote-definition footnote-reference)
3729 (lambda (f)
3730 (and (equal (org-element-property :label f) label)
3731 (org-element-contents f)))
3732 info t)
3733 cache)
3734 (error "Definition not found for footnote %s" label))))))
3736 (defun org-export--footnote-reference-map
3737 (function data info &optional body-first)
3738 "Apply FUNCTION on every footnote reference in DATA.
3739 INFO is a plist containing export state. By default, as soon as
3740 a new footnote reference is encountered, FUNCTION is called onto
3741 its definition. However, if BODY-FIRST is non-nil, this step is
3742 delayed until the end of the process."
3743 (letrec ((definitions)
3744 (seen-refs)
3745 (search-ref
3746 (lambda (data delayp)
3747 ;; Search footnote references through DATA, filling
3748 ;; SEEN-REFS along the way. When DELAYP is non-nil,
3749 ;; store footnote definitions so they can be entered
3750 ;; later.
3751 (org-element-map data 'footnote-reference
3752 (lambda (f)
3753 (funcall function f)
3754 (let ((--label (org-element-property :label f)))
3755 (unless (and --label (member --label seen-refs))
3756 (when --label (push --label seen-refs))
3757 ;; Search for subsequent references in footnote
3758 ;; definition so numbering follows reading
3759 ;; logic, unless DELAYP in non-nil.
3760 (cond
3761 (delayp
3762 (push (org-export-get-footnote-definition f info)
3763 definitions))
3764 ;; Do not force entering inline definitions,
3765 ;; since `org-element-map' already traverses
3766 ;; them at the right time.
3767 ((eq (org-element-property :type f) 'inline))
3768 (t (funcall search-ref
3769 (org-export-get-footnote-definition f info)
3770 nil))))))
3771 info nil
3772 ;; Don't enter footnote definitions since it will
3773 ;; happen when their first reference is found.
3774 ;; Moreover, if DELAYP is non-nil, make sure we
3775 ;; postpone entering definitions of inline references.
3776 (if delayp '(footnote-definition footnote-reference)
3777 'footnote-definition)))))
3778 (funcall search-ref data body-first)
3779 (funcall search-ref (nreverse definitions) nil)))
3781 (defun org-export-collect-footnote-definitions (info &optional data body-first)
3782 "Return an alist between footnote numbers, labels and definitions.
3784 INFO is the current export state, as a plist.
3786 Definitions are collected throughout the whole parse tree, or
3787 DATA when non-nil.
3789 Sorting is done by order of references. As soon as a new
3790 reference is encountered, other references are searched within
3791 its definition. However, if BODY-FIRST is non-nil, this step is
3792 delayed after the whole tree is checked. This alters results
3793 when references are found in footnote definitions.
3795 Definitions either appear as Org data or as a secondary string
3796 for inlined footnotes. Unreferenced definitions are ignored."
3797 (let ((n 0) labels alist)
3798 (org-export--footnote-reference-map
3799 (lambda (f)
3800 ;; Collect footnote number, label and definition.
3801 (let ((l (org-element-property :label f)))
3802 (unless (and l (member l labels))
3803 (cl-incf n)
3804 (push (list n l (org-export-get-footnote-definition f info)) alist))
3805 (when l (push l labels))))
3806 (or data (plist-get info :parse-tree)) info body-first)
3807 (nreverse alist)))
3809 (defun org-export-footnote-first-reference-p
3810 (footnote-reference info &optional data body-first)
3811 "Non-nil when a footnote reference is the first one for its label.
3813 FOOTNOTE-REFERENCE is the footnote reference being considered.
3814 INFO is a plist containing current export state.
3816 Search is done throughout the whole parse tree, or DATA when
3817 non-nil.
3819 By default, as soon as a new footnote reference is encountered,
3820 other references are searched within its definition. However, if
3821 BODY-FIRST is non-nil, this step is delayed after the whole tree
3822 is checked. This alters results when references are found in
3823 footnote definitions."
3824 (let ((label (org-element-property :label footnote-reference)))
3825 ;; Anonymous footnotes are always a first reference.
3826 (or (not label)
3827 (catch 'exit
3828 (org-export--footnote-reference-map
3829 (lambda (f)
3830 (let ((l (org-element-property :label f)))
3831 (when (and l label (string= label l))
3832 (throw 'exit (eq footnote-reference f)))))
3833 (or data (plist-get info :parse-tree)) info body-first)))))
3835 (defun org-export-get-footnote-number (footnote info &optional data body-first)
3836 "Return number associated to a footnote.
3838 FOOTNOTE is either a footnote reference or a footnote definition.
3839 INFO is the plist containing export state.
3841 Number is unique throughout the whole parse tree, or DATA, when
3842 non-nil.
3844 By default, as soon as a new footnote reference is encountered,
3845 counting process moves into its definition. However, if
3846 BODY-FIRST is non-nil, this step is delayed until the end of the
3847 process, leading to a different order when footnotes are nested."
3848 (let ((count 0)
3849 (seen)
3850 (label (org-element-property :label footnote)))
3851 (catch 'exit
3852 (org-export--footnote-reference-map
3853 (lambda (f)
3854 (let ((l (org-element-property :label f)))
3855 (cond
3856 ;; Anonymous footnote match: return number.
3857 ((and (not l) (not label) (eq footnote f)) (throw 'exit (1+ count)))
3858 ;; Labels match: return number.
3859 ((and label l (string= label l)) (throw 'exit (1+ count)))
3860 ;; Otherwise store label and increase counter if label
3861 ;; wasn't encountered yet.
3862 ((not l) (cl-incf count))
3863 ((not (member l seen)) (push l seen) (cl-incf count)))))
3864 (or data (plist-get info :parse-tree)) info body-first))))
3867 ;;;; For Headlines
3869 ;; `org-export-get-relative-level' is a shortcut to get headline
3870 ;; level, relatively to the lower headline level in the parsed tree.
3872 ;; `org-export-get-headline-number' returns the section number of an
3873 ;; headline, while `org-export-number-to-roman' allows to convert it
3874 ;; to roman numbers. With an optional argument,
3875 ;; `org-export-get-headline-number' returns a number to unnumbered
3876 ;; headlines (used for internal id).
3878 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
3879 ;; `org-export-last-sibling-p' are three useful predicates when it
3880 ;; comes to fulfill the `:headline-levels' property.
3882 ;; `org-export-get-tags', `org-export-get-category' and
3883 ;; `org-export-get-node-property' extract useful information from an
3884 ;; headline or a parent headline. They all handle inheritance.
3886 ;; `org-export-get-alt-title' tries to retrieve an alternative title,
3887 ;; as a secondary string, suitable for table of contents. It falls
3888 ;; back onto default title.
3890 (defun org-export-get-relative-level (headline info)
3891 "Return HEADLINE relative level within current parsed tree.
3892 INFO is a plist holding contextual information."
3893 (+ (org-element-property :level headline)
3894 (or (plist-get info :headline-offset) 0)))
3896 (defun org-export-low-level-p (headline info)
3897 "Non-nil when HEADLINE is considered as low level.
3899 INFO is a plist used as a communication channel.
3901 A low level headlines has a relative level greater than
3902 `:headline-levels' property value.
3904 Return value is the difference between HEADLINE relative level
3905 and the last level being considered as high enough, or nil."
3906 (let ((limit (plist-get info :headline-levels)))
3907 (when (wholenump limit)
3908 (let ((level (org-export-get-relative-level headline info)))
3909 (and (> level limit) (- level limit))))))
3911 (defun org-export-get-headline-number (headline info)
3912 "Return numbered HEADLINE numbering as a list of numbers.
3913 INFO is a plist holding contextual information."
3914 (and (org-export-numbered-headline-p headline info)
3915 (cdr (assq headline (plist-get info :headline-numbering)))))
3917 (defun org-export-numbered-headline-p (headline info)
3918 "Return a non-nil value if HEADLINE element should be numbered.
3919 INFO is a plist used as a communication channel."
3920 (unless (cl-some
3921 (lambda (head) (org-not-nil (org-element-property :UNNUMBERED head)))
3922 (org-element-lineage headline nil t))
3923 (let ((sec-num (plist-get info :section-numbers))
3924 (level (org-export-get-relative-level headline info)))
3925 (if (wholenump sec-num) (<= level sec-num) sec-num))))
3927 (defun org-export-number-to-roman (n)
3928 "Convert integer N into a roman numeral."
3929 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
3930 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
3931 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
3932 ( 1 . "I")))
3933 (res ""))
3934 (if (<= n 0)
3935 (number-to-string n)
3936 (while roman
3937 (if (>= n (caar roman))
3938 (setq n (- n (caar roman))
3939 res (concat res (cdar roman)))
3940 (pop roman)))
3941 res)))
3943 (defun org-export-get-tags (element info &optional tags inherited)
3944 "Return list of tags associated to ELEMENT.
3946 ELEMENT has either an `headline' or an `inlinetask' type. INFO
3947 is a plist used as a communication channel.
3949 When non-nil, optional argument TAGS should be a list of strings.
3950 Any tag belonging to this list will also be removed.
3952 When optional argument INHERITED is non-nil, tags can also be
3953 inherited from parent headlines and FILETAGS keywords."
3954 (cl-remove-if
3955 (lambda (tag) (member tag tags))
3956 (if (not inherited) (org-element-property :tags element)
3957 ;; Build complete list of inherited tags.
3958 (let ((current-tag-list (org-element-property :tags element)))
3959 (dolist (parent (org-element-lineage element))
3960 (dolist (tag (org-element-property :tags parent))
3961 (when (and (memq (org-element-type parent) '(headline inlinetask))
3962 (not (member tag current-tag-list)))
3963 (push tag current-tag-list))))
3964 ;; Add FILETAGS keywords and return results.
3965 (org-uniquify (append (plist-get info :filetags) current-tag-list))))))
3967 (defun org-export-get-node-property (property blob &optional inherited)
3968 "Return node PROPERTY value for BLOB.
3970 PROPERTY is an upcase symbol (i.e. `:COOKIE_DATA'). BLOB is an
3971 element or object.
3973 If optional argument INHERITED is non-nil, the value can be
3974 inherited from a parent headline.
3976 Return value is a string or nil."
3977 (let ((headline (if (eq (org-element-type blob) 'headline) blob
3978 (org-export-get-parent-headline blob))))
3979 (if (not inherited) (org-element-property property blob)
3980 (let ((parent headline))
3981 (catch 'found
3982 (while parent
3983 (when (plist-member (nth 1 parent) property)
3984 (throw 'found (org-element-property property parent)))
3985 (setq parent (org-element-property :parent parent))))))))
3987 (defun org-export-get-category (blob info)
3988 "Return category for element or object BLOB.
3990 INFO is a plist used as a communication channel.
3992 CATEGORY is automatically inherited from a parent headline, from
3993 #+CATEGORY: keyword or created out of original file name. If all
3994 fail, the fall-back value is \"???\"."
3995 (or (org-export-get-node-property :CATEGORY blob t)
3996 (org-element-map (plist-get info :parse-tree) 'keyword
3997 (lambda (kwd)
3998 (when (equal (org-element-property :key kwd) "CATEGORY")
3999 (org-element-property :value kwd)))
4000 info 'first-match)
4001 (let ((file (plist-get info :input-file)))
4002 (and file (file-name-sans-extension (file-name-nondirectory file))))
4003 "???"))
4005 (defun org-export-get-alt-title (headline _)
4006 "Return alternative title for HEADLINE, as a secondary string.
4007 If no optional title is defined, fall-back to the regular title."
4008 (let ((alt (org-element-property :ALT_TITLE headline)))
4009 (if alt (org-element-parse-secondary-string
4010 alt (org-element-restriction 'headline) headline)
4011 (org-element-property :title headline))))
4013 (defun org-export-first-sibling-p (blob info)
4014 "Non-nil when BLOB is the first sibling in its parent.
4015 BLOB is an element or an object. If BLOB is a headline, non-nil
4016 means it is the first sibling in the sub-tree. INFO is a plist
4017 used as a communication channel."
4018 (memq (org-element-type (org-export-get-previous-element blob info))
4019 '(nil section)))
4021 (defun org-export-last-sibling-p (blob info)
4022 "Non-nil when BLOB is the last sibling in its parent.
4023 BLOB is an element or an object. INFO is a plist used as
4024 a communication channel."
4025 (not (org-export-get-next-element blob info)))
4028 ;;;; For Keywords
4030 ;; `org-export-get-date' returns a date appropriate for the document
4031 ;; to about to be exported. In particular, it takes care of
4032 ;; `org-export-date-timestamp-format'.
4034 (defun org-export-get-date (info &optional fmt)
4035 "Return date value for the current document.
4037 INFO is a plist used as a communication channel. FMT, when
4038 non-nil, is a time format string that will be applied on the date
4039 if it consists in a single timestamp object. It defaults to
4040 `org-export-date-timestamp-format' when nil.
4042 A proper date can be a secondary string, a string or nil. It is
4043 meant to be translated with `org-export-data' or alike."
4044 (let ((date (plist-get info :date))
4045 (fmt (or fmt org-export-date-timestamp-format)))
4046 (cond ((not date) nil)
4047 ((and fmt
4048 (not (cdr date))
4049 (eq (org-element-type (car date)) 'timestamp))
4050 (org-timestamp-format (car date) fmt))
4051 (t date))))
4054 ;;;; For Links
4056 ;; `org-export-custom-protocol-maybe' handles custom protocol defined
4057 ;; with `org-add-link-type', which see.
4059 ;; `org-export-get-coderef-format' returns an appropriate format
4060 ;; string for coderefs.
4062 ;; `org-export-inline-image-p' returns a non-nil value when the link
4063 ;; provided should be considered as an inline image.
4065 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
4066 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
4067 ;; returns an appropriate unique identifier.
4069 ;; `org-export-resolve-id-link' returns the first headline with
4070 ;; specified id or custom-id in parse tree, the path to the external
4071 ;; file with the id.
4073 ;; `org-export-resolve-coderef' associates a reference to a line
4074 ;; number in the element it belongs, or returns the reference itself
4075 ;; when the element isn't numbered.
4077 ;; `org-export-file-uri' expands a filename as stored in :path value
4078 ;; of a "file" link into a file URI.
4080 ;; Broken links raise a `org-link-broken' error, which is caught by
4081 ;; `org-export-data' for further processing, depending on
4082 ;; `org-export-with-broken-links' value.
4084 (org-define-error 'org-link-broken "Unable to resolve link; aborting")
4086 (defun org-export-custom-protocol-maybe (link desc backend)
4087 "Try exporting LINK with a dedicated function.
4089 DESC is its description, as a string, or nil. BACKEND is the
4090 back-end used for export, as a symbol.
4092 Return output as a string, or nil if no protocol handles LINK.
4094 A custom protocol has precedence over regular back-end export.
4095 The function ignores links with an implicit type (e.g.,
4096 \"custom-id\")."
4097 (let ((type (org-element-property :type link)))
4098 (unless (or (member type '("coderef" "custom-id" "fuzzy" "radio"))
4099 (not backend))
4100 (let ((protocol (nth 2 (assoc type org-link-protocols))))
4101 (and (functionp protocol)
4102 (funcall protocol
4103 (org-link-unescape (org-element-property :path link))
4104 desc
4105 backend))))))
4107 (defun org-export-get-coderef-format (path desc)
4108 "Return format string for code reference link.
4109 PATH is the link path. DESC is its description."
4110 (save-match-data
4111 (cond ((not desc) "%s")
4112 ((string-match (regexp-quote (concat "(" path ")")) desc)
4113 (replace-match "%s" t t desc))
4114 (t desc))))
4116 (defun org-export-inline-image-p (link &optional rules)
4117 "Non-nil if LINK object points to an inline image.
4119 Optional argument is a set of RULES defining inline images. It
4120 is an alist where associations have the following shape:
4122 (TYPE . REGEXP)
4124 Applying a rule means apply REGEXP against LINK's path when its
4125 type is TYPE. The function will return a non-nil value if any of
4126 the provided rules is non-nil. The default rule is
4127 `org-export-default-inline-image-rule'.
4129 This only applies to links without a description."
4130 (and (not (org-element-contents link))
4131 (let ((case-fold-search t))
4132 (catch 'exit
4133 (dolist (rule (or rules org-export-default-inline-image-rule))
4134 (and (string= (org-element-property :type link) (car rule))
4135 (org-string-match-p (cdr rule)
4136 (org-element-property :path link))
4137 (throw 'exit t)))))))
4139 (defun org-export-resolve-coderef (ref info)
4140 "Resolve a code reference REF.
4142 INFO is a plist used as a communication channel.
4144 Return associated line number in source code, or REF itself,
4145 depending on src-block or example element's switches. Throw an
4146 error if no block contains REF."
4147 (or (org-element-map (plist-get info :parse-tree) '(example-block src-block)
4148 (lambda (el)
4149 (with-temp-buffer
4150 (insert (org-trim (org-element-property :value el)))
4151 (let* ((label-fmt (regexp-quote
4152 (or (org-element-property :label-fmt el)
4153 org-coderef-label-format)))
4154 (ref-re
4155 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
4156 (format label-fmt ref))))
4157 ;; Element containing REF is found. Resolve it to
4158 ;; either a label or a line number, as needed.
4159 (when (re-search-backward ref-re nil t)
4160 (cond
4161 ((org-element-property :use-labels el) ref)
4162 ((eq (org-element-property :number-lines el) 'continued)
4163 (+ (org-export-get-loc el info) (line-number-at-pos)))
4164 (t (line-number-at-pos)))))))
4165 info 'first-match)
4166 (signal 'org-link-broken (list ref))))
4168 (defun org-export-resolve-fuzzy-link (link info)
4169 "Return LINK destination.
4171 INFO is a plist holding contextual information.
4173 Return value can be an object or an element:
4175 - If LINK path matches a target object (i.e. <<path>>) return it.
4177 - If LINK path exactly matches the name affiliated keyword
4178 (i.e. #+NAME: path) of an element, return that element.
4180 - If LINK path exactly matches any headline name, return that
4181 element.
4183 - Otherwise, throw an error.
4185 Assume LINK type is \"fuzzy\". White spaces are not
4186 significant."
4187 (let* ((raw-path (org-link-unescape (org-element-property :path link)))
4188 (headline-only (eq (string-to-char raw-path) ?*))
4189 ;; Split PATH at white spaces so matches are space
4190 ;; insensitive.
4191 (path (org-split-string
4192 (if headline-only (substring raw-path 1) raw-path)))
4193 (link-cache
4194 (or (plist-get info :resolve-fuzzy-link-cache)
4195 (plist-get (plist-put info
4196 :resolve-fuzzy-link-cache
4197 (make-hash-table :test #'equal))
4198 :resolve-fuzzy-link-cache)))
4199 (cached (gethash path link-cache 'not-found)))
4200 (if (not (eq cached 'not-found)) cached
4201 (let ((ast (plist-get info :parse-tree)))
4202 (puthash
4203 path
4204 (cond
4205 ;; First try to find a matching "<<path>>" unless user
4206 ;; specified he was looking for a headline (path starts with
4207 ;; a "*" character).
4208 ((and (not headline-only)
4209 (org-element-map ast 'target
4210 (lambda (datum)
4211 (and (equal (org-split-string
4212 (org-element-property :value datum))
4213 path)
4214 datum))
4215 info 'first-match)))
4216 ;; Then try to find an element with a matching "#+NAME: path"
4217 ;; affiliated keyword.
4218 ((and (not headline-only)
4219 (org-element-map ast org-element-all-elements
4220 (lambda (datum)
4221 (let ((name (org-element-property :name datum)))
4222 (and name (equal (org-split-string name) path) datum)))
4223 info 'first-match)))
4224 ;; Try to find a matching headline.
4225 ((org-element-map ast 'headline
4226 (lambda (h)
4227 (and (equal (org-split-string
4228 (replace-regexp-in-string
4229 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
4230 (org-element-property :raw-value h)))
4231 path)
4233 info 'first-match))
4234 (t (signal 'org-link-broken (list raw-path))))
4235 link-cache)))))
4237 (defun org-export-resolve-id-link (link info)
4238 "Return headline referenced as LINK destination.
4240 INFO is a plist used as a communication channel.
4242 Return value can be the headline element matched in current parse
4243 tree or a file name. Assume LINK type is either \"id\" or
4244 \"custom-id\". Throw an error if no match is found."
4245 (let ((id (org-element-property :path link)))
4246 ;; First check if id is within the current parse tree.
4247 (or (org-element-map (plist-get info :parse-tree) 'headline
4248 (lambda (headline)
4249 (when (or (equal (org-element-property :ID headline) id)
4250 (equal (org-element-property :CUSTOM_ID headline) id))
4251 headline))
4252 info 'first-match)
4253 ;; Otherwise, look for external files.
4254 (cdr (assoc id (plist-get info :id-alist)))
4255 (signal 'org-link-broken (list id)))))
4257 (defun org-export-resolve-radio-link (link info)
4258 "Return radio-target object referenced as LINK destination.
4260 INFO is a plist used as a communication channel.
4262 Return value can be a radio-target object or nil. Assume LINK
4263 has type \"radio\"."
4264 (let ((path (replace-regexp-in-string
4265 "[ \r\t\n]+" " " (org-element-property :path link))))
4266 (org-element-map (plist-get info :parse-tree) 'radio-target
4267 (lambda (radio)
4268 (and (eq (compare-strings
4269 (replace-regexp-in-string
4270 "[ \r\t\n]+" " " (org-element-property :value radio))
4271 nil nil path nil nil t)
4273 radio))
4274 info 'first-match)))
4276 (defun org-export-file-uri (filename)
4277 "Return file URI associated to FILENAME."
4278 (cond ((org-string-match-p "\\`//" filename) (concat "file:" filename))
4279 ((not (file-name-absolute-p filename)) filename)
4280 ((org-file-remote-p filename) (concat "file:/" filename))
4281 (t (concat "file://" (expand-file-name filename)))))
4284 ;;;; For References
4286 ;; `org-export-get-reference' associate a unique reference for any
4287 ;; object or element.
4289 ;; `org-export-get-ordinal' associates a sequence number to any object
4290 ;; or element.
4292 (defun org-export-get-reference (datum info)
4293 "Return a unique reference for DATUM, as a string.
4294 DATUM is either an element or an object. INFO is the current
4295 export state, as a plist. Returned reference consists of
4296 alphanumeric characters only."
4297 (let ((type (org-element-type datum))
4298 (cache (or (plist-get info :internal-references)
4299 (let ((h (make-hash-table :test #'eq)))
4300 (plist-put info :internal-references h)
4301 h))))
4302 (or (gethash datum cache)
4303 (puthash datum
4304 (format "org%s%d"
4305 (if type
4306 (replace-regexp-in-string "-" "" (symbol-name type))
4307 "secondarystring")
4308 (cl-incf (gethash type cache 0)))
4309 cache))))
4311 (defun org-export-get-ordinal (element info &optional types predicate)
4312 "Return ordinal number of an element or object.
4314 ELEMENT is the element or object considered. INFO is the plist
4315 used as a communication channel.
4317 Optional argument TYPES, when non-nil, is a list of element or
4318 object types, as symbols, that should also be counted in.
4319 Otherwise, only provided element's type is considered.
4321 Optional argument PREDICATE is a function returning a non-nil
4322 value if the current element or object should be counted in. It
4323 accepts two arguments: the element or object being considered and
4324 the plist used as a communication channel. This allows to count
4325 only a certain type of objects (i.e. inline images).
4327 Return value is a list of numbers if ELEMENT is a headline or an
4328 item. It is nil for keywords. It represents the footnote number
4329 for footnote definitions and footnote references. If ELEMENT is
4330 a target, return the same value as if ELEMENT was the closest
4331 table, item or headline containing the target. In any other
4332 case, return the sequence number of ELEMENT among elements or
4333 objects of the same type."
4334 ;; Ordinal of a target object refer to the ordinal of the closest
4335 ;; table, item, or headline containing the object.
4336 (when (eq (org-element-type element) 'target)
4337 (setq element
4338 (org-element-lineage
4339 element
4340 '(footnote-definition footnote-reference headline item table))))
4341 (cl-case (org-element-type element)
4342 ;; Special case 1: A headline returns its number as a list.
4343 (headline (org-export-get-headline-number element info))
4344 ;; Special case 2: An item returns its number as a list.
4345 (item (let ((struct (org-element-property :structure element)))
4346 (org-list-get-item-number
4347 (org-element-property :begin element)
4348 struct
4349 (org-list-prevs-alist struct)
4350 (org-list-parents-alist struct))))
4351 ((footnote-definition footnote-reference)
4352 (org-export-get-footnote-number element info))
4353 (otherwise
4354 (let ((counter 0))
4355 ;; Increment counter until ELEMENT is found again.
4356 (org-element-map (plist-get info :parse-tree)
4357 (or types (org-element-type element))
4358 (lambda (el)
4359 (cond
4360 ((eq element el) (1+ counter))
4361 ((not predicate) (cl-incf counter) nil)
4362 ((funcall predicate el info) (cl-incf counter) nil)))
4363 info 'first-match)))))
4366 ;;;; For Src-Blocks
4368 ;; `org-export-get-loc' counts number of code lines accumulated in
4369 ;; src-block or example-block elements with a "+n" switch until
4370 ;; a given element, excluded. Note: "-n" switches reset that count.
4372 ;; `org-export-unravel-code' extracts source code (along with a code
4373 ;; references alist) from an `element-block' or `src-block' type
4374 ;; element.
4376 ;; `org-export-format-code' applies a formatting function to each line
4377 ;; of code, providing relative line number and code reference when
4378 ;; appropriate. Since it doesn't access the original element from
4379 ;; which the source code is coming, it expects from the code calling
4380 ;; it to know if lines should be numbered and if code references
4381 ;; should appear.
4383 ;; Eventually, `org-export-format-code-default' is a higher-level
4384 ;; function (it makes use of the two previous functions) which handles
4385 ;; line numbering and code references inclusion, and returns source
4386 ;; code in a format suitable for plain text or verbatim output.
4388 (defun org-export-get-loc (element info)
4389 "Return accumulated lines of code up to ELEMENT.
4391 INFO is the plist used as a communication channel.
4393 ELEMENT is excluded from count."
4394 (let ((loc 0))
4395 (org-element-map (plist-get info :parse-tree)
4396 `(src-block example-block ,(org-element-type element))
4397 (lambda (el)
4398 (cond
4399 ;; ELEMENT is reached: Quit the loop.
4400 ((eq el element))
4401 ;; Only count lines from src-block and example-block elements
4402 ;; with a "+n" or "-n" switch. A "-n" switch resets counter.
4403 ((not (memq (org-element-type el) '(src-block example-block))) nil)
4404 ((let ((linums (org-element-property :number-lines el)))
4405 (when linums
4406 ;; Accumulate locs or reset them.
4407 (let ((lines (org-count-lines
4408 (org-trim (org-element-property :value el)))))
4409 (setq loc (if (eq linums 'new) lines (+ loc lines))))))
4410 ;; Return nil to stay in the loop.
4411 nil)))
4412 info 'first-match)
4413 ;; Return value.
4414 loc))
4416 (defun org-export-unravel-code (element)
4417 "Clean source code and extract references out of it.
4419 ELEMENT has either a `src-block' an `example-block' type.
4421 Return a cons cell whose CAR is the source code, cleaned from any
4422 reference, protective commas and spurious indentation, and CDR is
4423 an alist between relative line number (integer) and name of code
4424 reference on that line (string)."
4425 (let* ((line 0) refs
4426 (value (org-element-property :value element))
4427 ;; Get code and clean it. Remove blank lines at its
4428 ;; beginning and end.
4429 (code (replace-regexp-in-string
4430 "\\`\\([ \t]*\n\\)+" ""
4431 (replace-regexp-in-string
4432 "\\([ \t]*\n\\)*[ \t]*\\'" "\n"
4433 (if (or org-src-preserve-indentation
4434 (org-element-property :preserve-indent element))
4435 value
4436 (org-remove-indentation value)))))
4437 ;; Get format used for references.
4438 (label-fmt (regexp-quote
4439 (or (org-element-property :label-fmt element)
4440 org-coderef-label-format)))
4441 ;; Build a regexp matching a loc with a reference.
4442 (with-ref-re
4443 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)[ \t]*\\)$"
4444 (replace-regexp-in-string
4445 "%s" "\\([-a-zA-Z0-9_ ]+\\)" label-fmt nil t))))
4446 ;; Return value.
4447 (cons
4448 ;; Code with references removed.
4449 (org-element-normalize-string
4450 (mapconcat
4451 (lambda (loc)
4452 (cl-incf line)
4453 (if (not (string-match with-ref-re loc)) loc
4454 ;; Ref line: remove ref, and signal its position in REFS.
4455 (push (cons line (match-string 3 loc)) refs)
4456 (replace-match "" nil nil loc 1)))
4457 (org-split-string code "\n") "\n"))
4458 ;; Reference alist.
4459 refs)))
4461 (defun org-export-format-code (code fun &optional num-lines ref-alist)
4462 "Format CODE by applying FUN line-wise and return it.
4464 CODE is a string representing the code to format. FUN is
4465 a function. It must accept three arguments: a line of
4466 code (string), the current line number (integer) or nil and the
4467 reference associated to the current line (string) or nil.
4469 Optional argument NUM-LINES can be an integer representing the
4470 number of code lines accumulated until the current code. Line
4471 numbers passed to FUN will take it into account. If it is nil,
4472 FUN's second argument will always be nil. This number can be
4473 obtained with `org-export-get-loc' function.
4475 Optional argument REF-ALIST can be an alist between relative line
4476 number (i.e. ignoring NUM-LINES) and the name of the code
4477 reference on it. If it is nil, FUN's third argument will always
4478 be nil. It can be obtained through the use of
4479 `org-export-unravel-code' function."
4480 (let ((--locs (org-split-string code "\n"))
4481 (--line 0))
4482 (org-element-normalize-string
4483 (mapconcat
4484 (lambda (--loc)
4485 (cl-incf --line)
4486 (let ((--ref (cdr (assq --line ref-alist))))
4487 (funcall fun --loc (and num-lines (+ num-lines --line)) --ref)))
4488 --locs "\n"))))
4490 (defun org-export-format-code-default (element info)
4491 "Return source code from ELEMENT, formatted in a standard way.
4493 ELEMENT is either a `src-block' or `example-block' element. INFO
4494 is a plist used as a communication channel.
4496 This function takes care of line numbering and code references
4497 inclusion. Line numbers, when applicable, appear at the
4498 beginning of the line, separated from the code by two white
4499 spaces. Code references, on the other hand, appear flushed to
4500 the right, separated by six white spaces from the widest line of
4501 code."
4502 ;; Extract code and references.
4503 (let* ((code-info (org-export-unravel-code element))
4504 (code (car code-info))
4505 (code-lines (org-split-string code "\n")))
4506 (if (null code-lines) ""
4507 (let* ((refs (and (org-element-property :retain-labels element)
4508 (cdr code-info)))
4509 ;; Handle line numbering.
4510 (num-start (cl-case (org-element-property :number-lines element)
4511 (continued (org-export-get-loc element info))
4512 (new 0)))
4513 (num-fmt
4514 (and num-start
4515 (format "%%%ds "
4516 (length (number-to-string
4517 (+ (length code-lines) num-start))))))
4518 ;; Prepare references display, if required. Any reference
4519 ;; should start six columns after the widest line of code,
4520 ;; wrapped with parenthesis.
4521 (max-width
4522 (+ (apply 'max (mapcar 'length code-lines))
4523 (if (not num-start) 0 (length (format num-fmt num-start))))))
4524 (org-export-format-code
4525 code
4526 (lambda (loc line-num ref)
4527 (let ((number-str (and num-fmt (format num-fmt line-num))))
4528 (concat
4529 number-str
4531 (and ref
4532 (concat (make-string
4533 (- (+ 6 max-width)
4534 (+ (length loc) (length number-str))) ? )
4535 (format "(%s)" ref))))))
4536 num-start refs)))))
4539 ;;;; For Tables
4541 ;; `org-export-table-has-special-column-p' and and
4542 ;; `org-export-table-row-is-special-p' are predicates used to look for
4543 ;; meta-information about the table structure.
4545 ;; `org-table-has-header-p' tells when the rows before the first rule
4546 ;; should be considered as table's header.
4548 ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
4549 ;; and `org-export-table-cell-borders' extract information from
4550 ;; a table-cell element.
4552 ;; `org-export-table-dimensions' gives the number on rows and columns
4553 ;; in the table, ignoring horizontal rules and special columns.
4554 ;; `org-export-table-cell-address', given a table-cell object, returns
4555 ;; the absolute address of a cell. On the other hand,
4556 ;; `org-export-get-table-cell-at' does the contrary.
4558 ;; `org-export-table-cell-starts-colgroup-p',
4559 ;; `org-export-table-cell-ends-colgroup-p',
4560 ;; `org-export-table-row-starts-rowgroup-p',
4561 ;; `org-export-table-row-ends-rowgroup-p',
4562 ;; `org-export-table-row-starts-header-p',
4563 ;; `org-export-table-row-ends-header-p' and
4564 ;; `org-export-table-row-in-header-p' indicate position of current row
4565 ;; or cell within the table.
4567 (defun org-export-table-has-special-column-p (table)
4568 "Non-nil when TABLE has a special column.
4569 All special columns will be ignored during export."
4570 ;; The table has a special column when every first cell of every row
4571 ;; has an empty value or contains a symbol among "/", "#", "!", "$",
4572 ;; "*" "_" and "^". Though, do not consider a first row containing
4573 ;; only empty cells as special.
4574 (let ((special-column-p 'empty))
4575 (catch 'exit
4576 (dolist (row (org-element-contents table))
4577 (when (eq (org-element-property :type row) 'standard)
4578 (let ((value (org-element-contents
4579 (car (org-element-contents row)))))
4580 (cond ((member value '(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
4581 (setq special-column-p 'special))
4582 ((not value))
4583 (t (throw 'exit nil))))))
4584 (eq special-column-p 'special))))
4586 (defun org-export-table-has-header-p (table info)
4587 "Non-nil when TABLE has a header.
4589 INFO is a plist used as a communication channel.
4591 A table has a header when it contains at least two row groups."
4592 (let ((cache (or (plist-get info :table-header-cache)
4593 (plist-get (setq info
4594 (plist-put info :table-header-cache
4595 (make-hash-table :test 'eq)))
4596 :table-header-cache))))
4597 (or (gethash table cache)
4598 (let ((rowgroup 1) row-flag)
4599 (puthash
4600 table
4601 (org-element-map table 'table-row
4602 (lambda (row)
4603 (cond
4604 ((> rowgroup 1) t)
4605 ((and row-flag (eq (org-element-property :type row) 'rule))
4606 (cl-incf rowgroup) (setq row-flag nil))
4607 ((and (not row-flag) (eq (org-element-property :type row)
4608 'standard))
4609 (setq row-flag t) nil)))
4610 info 'first-match)
4611 cache)))))
4613 (defun org-export-table-row-is-special-p (table-row _)
4614 "Non-nil if TABLE-ROW is considered special.
4615 All special rows will be ignored during export."
4616 (when (eq (org-element-property :type table-row) 'standard)
4617 (let ((first-cell (org-element-contents
4618 (car (org-element-contents table-row)))))
4619 ;; A row is special either when...
4621 ;; ... it starts with a field only containing "/",
4622 (equal first-cell '("/"))
4623 ;; ... the table contains a special column and the row start
4624 ;; with a marking character among, "^", "_", "$" or "!",
4625 (and (org-export-table-has-special-column-p
4626 (org-export-get-parent table-row))
4627 (member first-cell '(("^") ("_") ("$") ("!"))))
4628 ;; ... it contains only alignment cookies and empty cells.
4629 (let ((special-row-p 'empty))
4630 (catch 'exit
4631 (dolist (cell (org-element-contents table-row))
4632 (let ((value (org-element-contents cell)))
4633 ;; Since VALUE is a secondary string, the following
4634 ;; checks avoid expanding it with `org-export-data'.
4635 (cond ((not value))
4636 ((and (not (cdr value))
4637 (stringp (car value))
4638 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
4639 (car value)))
4640 (setq special-row-p 'cookie))
4641 (t (throw 'exit nil)))))
4642 (eq special-row-p 'cookie)))))))
4644 (defun org-export-table-row-group (table-row info)
4645 "Return TABLE-ROW's group number, as an integer.
4647 INFO is a plist used as the communication channel.
4649 Return value is the group number, as an integer, or nil for
4650 special rows and rows separators. First group is also table's
4651 header."
4652 (let ((cache (or (plist-get info :table-row-group-cache)
4653 (plist-get (setq info
4654 (plist-put info :table-row-group-cache
4655 (make-hash-table :test 'eq)))
4656 :table-row-group-cache))))
4657 (cond ((gethash table-row cache))
4658 ((eq (org-element-property :type table-row) 'rule) nil)
4659 (t (let ((group 0) row-flag)
4660 (org-element-map (org-export-get-parent table-row) 'table-row
4661 (lambda (row)
4662 (if (eq (org-element-property :type row) 'rule)
4663 (setq row-flag nil)
4664 (unless row-flag (cl-incf group) (setq row-flag t)))
4665 (when (eq table-row row) (puthash table-row group cache)))
4666 info 'first-match))))))
4668 (defun org-export-table-cell-width (table-cell info)
4669 "Return TABLE-CELL contents width.
4671 INFO is a plist used as the communication channel.
4673 Return value is the width given by the last width cookie in the
4674 same column as TABLE-CELL, or nil."
4675 (let* ((row (org-export-get-parent table-cell))
4676 (table (org-export-get-parent row))
4677 (cells (org-element-contents row))
4678 (columns (length cells))
4679 (column (- columns (length (memq table-cell cells))))
4680 (cache (or (plist-get info :table-cell-width-cache)
4681 (plist-get (setq info
4682 (plist-put info :table-cell-width-cache
4683 (make-hash-table :test 'eq)))
4684 :table-cell-width-cache)))
4685 (width-vector (or (gethash table cache)
4686 (puthash table (make-vector columns 'empty) cache)))
4687 (value (aref width-vector column)))
4688 (if (not (eq value 'empty)) value
4689 (let (cookie-width)
4690 (dolist (row (org-element-contents table)
4691 (aset width-vector column cookie-width))
4692 (when (org-export-table-row-is-special-p row info)
4693 ;; In a special row, try to find a width cookie at COLUMN.
4694 (let* ((value (org-element-contents
4695 (elt (org-element-contents row) column)))
4696 (cookie (car value)))
4697 ;; The following checks avoid expanding unnecessarily
4698 ;; the cell with `org-export-data'.
4699 (when (and value
4700 (not (cdr value))
4701 (stringp cookie)
4702 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" cookie)
4703 (match-string 1 cookie))
4704 (setq cookie-width
4705 (string-to-number (match-string 1 cookie)))))))))))
4707 (defun org-export-table-cell-alignment (table-cell info)
4708 "Return TABLE-CELL contents alignment.
4710 INFO is a plist used as the communication channel.
4712 Return alignment as specified by the last alignment cookie in the
4713 same column as TABLE-CELL. If no such cookie is found, a default
4714 alignment value will be deduced from fraction of numbers in the
4715 column (see `org-table-number-fraction' for more information).
4716 Possible values are `left', `right' and `center'."
4717 ;; Load `org-table-number-fraction' and `org-table-number-regexp'.
4718 (require 'org-table)
4719 (let* ((row (org-export-get-parent table-cell))
4720 (table (org-export-get-parent row))
4721 (cells (org-element-contents row))
4722 (columns (length cells))
4723 (column (- columns (length (memq table-cell cells))))
4724 (cache (or (plist-get info :table-cell-alignment-cache)
4725 (plist-get (setq info
4726 (plist-put info :table-cell-alignment-cache
4727 (make-hash-table :test 'eq)))
4728 :table-cell-alignment-cache)))
4729 (align-vector (or (gethash table cache)
4730 (puthash table (make-vector columns nil) cache))))
4731 (or (aref align-vector column)
4732 (let ((number-cells 0)
4733 (total-cells 0)
4734 cookie-align
4735 previous-cell-number-p)
4736 (dolist (row (org-element-contents (org-export-get-parent row)))
4737 (cond
4738 ;; In a special row, try to find an alignment cookie at
4739 ;; COLUMN.
4740 ((org-export-table-row-is-special-p row info)
4741 (let ((value (org-element-contents
4742 (elt (org-element-contents row) column))))
4743 ;; Since VALUE is a secondary string, the following
4744 ;; checks avoid useless expansion through
4745 ;; `org-export-data'.
4746 (when (and value
4747 (not (cdr value))
4748 (stringp (car value))
4749 (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
4750 (car value))
4751 (match-string 1 (car value)))
4752 (setq cookie-align (match-string 1 (car value))))))
4753 ;; Ignore table rules.
4754 ((eq (org-element-property :type row) 'rule))
4755 ;; In a standard row, check if cell's contents are
4756 ;; expressing some kind of number. Increase NUMBER-CELLS
4757 ;; accordingly. Though, don't bother if an alignment
4758 ;; cookie has already defined cell's alignment.
4759 ((not cookie-align)
4760 (let ((value (org-export-data
4761 (org-element-contents
4762 (elt (org-element-contents row) column))
4763 info)))
4764 (cl-incf total-cells)
4765 ;; Treat an empty cell as a number if it follows
4766 ;; a number.
4767 (if (not (or (string-match org-table-number-regexp value)
4768 (and (string= value "") previous-cell-number-p)))
4769 (setq previous-cell-number-p nil)
4770 (setq previous-cell-number-p t)
4771 (cl-incf number-cells))))))
4772 ;; Return value. Alignment specified by cookies has
4773 ;; precedence over alignment deduced from cell's contents.
4774 (aset align-vector
4775 column
4776 (cond ((equal cookie-align "l") 'left)
4777 ((equal cookie-align "r") 'right)
4778 ((equal cookie-align "c") 'center)
4779 ((>= (/ (float number-cells) total-cells)
4780 org-table-number-fraction)
4781 'right)
4782 (t 'left)))))))
4784 (defun org-export-table-cell-borders (table-cell info)
4785 "Return TABLE-CELL borders.
4787 INFO is a plist used as a communication channel.
4789 Return value is a list of symbols, or nil. Possible values are:
4790 `top', `bottom', `above', `below', `left' and `right'. Note:
4791 `top' (resp. `bottom') only happen for a cell in the first
4792 row (resp. last row) of the table, ignoring table rules, if any.
4794 Returned borders ignore special rows."
4795 (let* ((row (org-export-get-parent table-cell))
4796 (table (org-export-get-parent-table table-cell))
4797 borders)
4798 ;; Top/above border? TABLE-CELL has a border above when a rule
4799 ;; used to demarcate row groups can be found above. Hence,
4800 ;; finding a rule isn't sufficient to push `above' in BORDERS:
4801 ;; another regular row has to be found above that rule.
4802 (let (rule-flag)
4803 (catch 'exit
4804 ;; Look at every row before the current one.
4805 (dolist (row (cdr (memq row (reverse (org-element-contents table)))))
4806 (cond ((eq (org-element-property :type row) 'rule)
4807 (setq rule-flag t))
4808 ((not (org-export-table-row-is-special-p row info))
4809 (if rule-flag (throw 'exit (push 'above borders))
4810 (throw 'exit nil)))))
4811 ;; No rule above, or rule found starts the table (ignoring any
4812 ;; special row): TABLE-CELL is at the top of the table.
4813 (when rule-flag (push 'above borders))
4814 (push 'top borders)))
4815 ;; Bottom/below border? TABLE-CELL has a border below when next
4816 ;; non-regular row below is a rule.
4817 (let (rule-flag)
4818 (catch 'exit
4819 ;; Look at every row after the current one.
4820 (dolist (row (cdr (memq row (org-element-contents table))))
4821 (cond ((eq (org-element-property :type row) 'rule)
4822 (setq rule-flag t))
4823 ((not (org-export-table-row-is-special-p row info))
4824 (if rule-flag (throw 'exit (push 'below borders))
4825 (throw 'exit nil)))))
4826 ;; No rule below, or rule found ends the table (modulo some
4827 ;; special row): TABLE-CELL is at the bottom of the table.
4828 (when rule-flag (push 'below borders))
4829 (push 'bottom borders)))
4830 ;; Right/left borders? They can only be specified by column
4831 ;; groups. Column groups are defined in a row starting with "/".
4832 ;; Also a column groups row only contains "<", "<>", ">" or blank
4833 ;; cells.
4834 (catch 'exit
4835 (let ((column (let ((cells (org-element-contents row)))
4836 (- (length cells) (length (memq table-cell cells))))))
4837 ;; Table rows are read in reverse order so last column groups
4838 ;; row has precedence over any previous one.
4839 (dolist (row (reverse (org-element-contents table)))
4840 (unless (eq (org-element-property :type row) 'rule)
4841 (when (equal (org-element-contents
4842 (car (org-element-contents row)))
4843 '("/"))
4844 (let ((column-groups
4845 (mapcar
4846 (lambda (cell)
4847 (let ((value (org-element-contents cell)))
4848 (when (member value '(("<") ("<>") (">") nil))
4849 (car value))))
4850 (org-element-contents row))))
4851 ;; There's a left border when previous cell, if
4852 ;; any, ends a group, or current one starts one.
4853 (when (or (and (not (zerop column))
4854 (member (elt column-groups (1- column))
4855 '(">" "<>")))
4856 (member (elt column-groups column) '("<" "<>")))
4857 (push 'left borders))
4858 ;; There's a right border when next cell, if any,
4859 ;; starts a group, or current one ends one.
4860 (when (or (and (/= (1+ column) (length column-groups))
4861 (member (elt column-groups (1+ column))
4862 '("<" "<>")))
4863 (member (elt column-groups column) '(">" "<>")))
4864 (push 'right borders))
4865 (throw 'exit nil)))))))
4866 ;; Return value.
4867 borders))
4869 (defun org-export-table-cell-starts-colgroup-p (table-cell info)
4870 "Non-nil when TABLE-CELL is at the beginning of a column group.
4871 INFO is a plist used as a communication channel."
4872 ;; A cell starts a column group either when it is at the beginning
4873 ;; of a row (or after the special column, if any) or when it has
4874 ;; a left border.
4875 (or (eq (org-element-map (org-export-get-parent table-cell) 'table-cell
4876 'identity info 'first-match)
4877 table-cell)
4878 (memq 'left (org-export-table-cell-borders table-cell info))))
4880 (defun org-export-table-cell-ends-colgroup-p (table-cell info)
4881 "Non-nil when TABLE-CELL is at the end of a column group.
4882 INFO is a plist used as a communication channel."
4883 ;; A cell ends a column group either when it is at the end of a row
4884 ;; or when it has a right border.
4885 (or (eq (car (last (org-element-contents
4886 (org-export-get-parent table-cell))))
4887 table-cell)
4888 (memq 'right (org-export-table-cell-borders table-cell info))))
4890 (defun org-export-table-row-starts-rowgroup-p (table-row info)
4891 "Non-nil when TABLE-ROW is at the beginning of a row group.
4892 INFO is a plist used as a communication channel."
4893 (unless (or (eq (org-element-property :type table-row) 'rule)
4894 (org-export-table-row-is-special-p table-row info))
4895 (let ((borders (org-export-table-cell-borders
4896 (car (org-element-contents table-row)) info)))
4897 (or (memq 'top borders) (memq 'above borders)))))
4899 (defun org-export-table-row-ends-rowgroup-p (table-row info)
4900 "Non-nil when TABLE-ROW is at the end of a row group.
4901 INFO is a plist used as a communication channel."
4902 (unless (or (eq (org-element-property :type table-row) 'rule)
4903 (org-export-table-row-is-special-p table-row info))
4904 (let ((borders (org-export-table-cell-borders
4905 (car (org-element-contents table-row)) info)))
4906 (or (memq 'bottom borders) (memq 'below borders)))))
4908 (defun org-export-table-row-in-header-p (table-row info)
4909 "Non-nil when TABLE-ROW is located within table's header.
4910 INFO is a plist used as a communication channel. Always return
4911 nil for special rows and rows separators."
4912 (and (org-export-table-has-header-p
4913 (org-export-get-parent-table table-row) info)
4914 (eql (org-export-table-row-group table-row info) 1)))
4916 (defun org-export-table-row-starts-header-p (table-row info)
4917 "Non-nil when TABLE-ROW is the first table header's row.
4918 INFO is a plist used as a communication channel."
4919 (and (org-export-table-row-in-header-p table-row info)
4920 (org-export-table-row-starts-rowgroup-p table-row info)))
4922 (defun org-export-table-row-ends-header-p (table-row info)
4923 "Non-nil when TABLE-ROW is the last table header's row.
4924 INFO is a plist used as a communication channel."
4925 (and (org-export-table-row-in-header-p table-row info)
4926 (org-export-table-row-ends-rowgroup-p table-row info)))
4928 (defun org-export-table-row-number (table-row info)
4929 "Return TABLE-ROW number.
4930 INFO is a plist used as a communication channel. Return value is
4931 zero-based and ignores separators. The function returns nil for
4932 special columns and separators."
4933 (when (and (eq (org-element-property :type table-row) 'standard)
4934 (not (org-export-table-row-is-special-p table-row info)))
4935 (let ((number 0))
4936 (org-element-map (org-export-get-parent-table table-row) 'table-row
4937 (lambda (row)
4938 (cond ((eq row table-row) number)
4939 ((eq (org-element-property :type row) 'standard)
4940 (cl-incf number) nil)))
4941 info 'first-match))))
4943 (defun org-export-table-dimensions (table info)
4944 "Return TABLE dimensions.
4946 INFO is a plist used as a communication channel.
4948 Return value is a CONS like (ROWS . COLUMNS) where
4949 ROWS (resp. COLUMNS) is the number of exportable
4950 rows (resp. columns)."
4951 (let (first-row (columns 0) (rows 0))
4952 ;; Set number of rows, and extract first one.
4953 (org-element-map table 'table-row
4954 (lambda (row)
4955 (when (eq (org-element-property :type row) 'standard)
4956 (cl-incf rows)
4957 (unless first-row (setq first-row row)))) info)
4958 ;; Set number of columns.
4959 (org-element-map first-row 'table-cell (lambda (_) (cl-incf columns)) info)
4960 ;; Return value.
4961 (cons rows columns)))
4963 (defun org-export-table-cell-address (table-cell info)
4964 "Return address of a regular TABLE-CELL object.
4966 TABLE-CELL is the cell considered. INFO is a plist used as
4967 a communication channel.
4969 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4970 zero-based index. Only exportable cells are considered. The
4971 function returns nil for other cells."
4972 (let* ((table-row (org-export-get-parent table-cell))
4973 (row-number (org-export-table-row-number table-row info)))
4974 (when row-number
4975 (cons row-number
4976 (let ((col-count 0))
4977 (org-element-map table-row 'table-cell
4978 (lambda (cell)
4979 (if (eq cell table-cell) col-count (cl-incf col-count) nil))
4980 info 'first-match))))))
4982 (defun org-export-get-table-cell-at (address table info)
4983 "Return regular table-cell object at ADDRESS in TABLE.
4985 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4986 zero-based index. TABLE is a table type element. INFO is
4987 a plist used as a communication channel.
4989 If no table-cell, among exportable cells, is found at ADDRESS,
4990 return nil."
4991 (let ((column-pos (cdr address)) (column-count 0))
4992 (org-element-map
4993 ;; Row at (car address) or nil.
4994 (let ((row-pos (car address)) (row-count 0))
4995 (org-element-map table 'table-row
4996 (lambda (row)
4997 (cond ((eq (org-element-property :type row) 'rule) nil)
4998 ((= row-count row-pos) row)
4999 (t (cl-incf row-count) nil)))
5000 info 'first-match))
5001 'table-cell
5002 (lambda (cell)
5003 (if (= column-count column-pos) cell
5004 (cl-incf column-count) nil))
5005 info 'first-match)))
5008 ;;;; For Tables Of Contents
5010 ;; `org-export-collect-headlines' builds a list of all exportable
5011 ;; headline elements, maybe limited to a certain depth. One can then
5012 ;; easily parse it and transcode it.
5014 ;; Building lists of tables, figures or listings is quite similar.
5015 ;; Once the generic function `org-export-collect-elements' is defined,
5016 ;; `org-export-collect-tables', `org-export-collect-figures' and
5017 ;; `org-export-collect-listings' can be derived from it.
5019 (defun org-export-collect-headlines (info &optional n scope)
5020 "Collect headlines in order to build a table of contents.
5022 INFO is a plist used as a communication channel.
5024 When optional argument N is an integer, it specifies the depth of
5025 the table of contents. Otherwise, it is set to the value of the
5026 last headline level. See `org-export-headline-levels' for more
5027 information.
5029 Optional argument SCOPE, when non-nil, is an element. If it is
5030 a headline, only children of SCOPE are collected. Otherwise,
5031 collect children of the headline containing provided element. If
5032 there is no such headline, collect all headlines. In any case,
5033 argument N becomes relative to the level of that headline.
5035 Return a list of all exportable headlines as parsed elements.
5036 Footnote sections are ignored."
5037 (let* ((scope (cond ((not scope) (plist-get info :parse-tree))
5038 ((eq (org-element-type scope) 'headline) scope)
5039 ((org-export-get-parent-headline scope))
5040 (t (plist-get info :parse-tree))))
5041 (limit (plist-get info :headline-levels))
5042 (n (if (not (wholenump n)) limit
5043 (min (if (eq (org-element-type scope) 'org-data) n
5044 (+ (org-export-get-relative-level scope info) n))
5045 limit))))
5046 (org-element-map (org-element-contents scope) 'headline
5047 (lambda (headline)
5048 (unless (org-element-property :footnote-section-p headline)
5049 (let ((level (org-export-get-relative-level headline info)))
5050 (and (<= level n) headline))))
5051 info)))
5053 (defun org-export-collect-elements (type info &optional predicate)
5054 "Collect referenceable elements of a determined type.
5056 TYPE can be a symbol or a list of symbols specifying element
5057 types to search. Only elements with a caption are collected.
5059 INFO is a plist used as a communication channel.
5061 When non-nil, optional argument PREDICATE is a function accepting
5062 one argument, an element of type TYPE. It returns a non-nil
5063 value when that element should be collected.
5065 Return a list of all elements found, in order of appearance."
5066 (org-element-map (plist-get info :parse-tree) type
5067 (lambda (element)
5068 (and (org-element-property :caption element)
5069 (or (not predicate) (funcall predicate element))
5070 element))
5071 info))
5073 (defun org-export-collect-tables (info)
5074 "Build a list of tables.
5075 INFO is a plist used as a communication channel.
5077 Return a list of table elements with a caption."
5078 (org-export-collect-elements 'table info))
5080 (defun org-export-collect-figures (info predicate)
5081 "Build a list of figures.
5083 INFO is a plist used as a communication channel. PREDICATE is
5084 a function which accepts one argument: a paragraph element and
5085 whose return value is non-nil when that element should be
5086 collected.
5088 A figure is a paragraph type element, with a caption, verifying
5089 PREDICATE. The latter has to be provided since a \"figure\" is
5090 a vague concept that may depend on back-end.
5092 Return a list of elements recognized as figures."
5093 (org-export-collect-elements 'paragraph info predicate))
5095 (defun org-export-collect-listings (info)
5096 "Build a list of src blocks.
5098 INFO is a plist used as a communication channel.
5100 Return a list of src-block elements with a caption."
5101 (org-export-collect-elements 'src-block info))
5104 ;;;; Smart Quotes
5106 ;; The main function for the smart quotes sub-system is
5107 ;; `org-export-activate-smart-quotes', which replaces every quote in
5108 ;; a given string from the parse tree with its "smart" counterpart.
5110 ;; Dictionary for smart quotes is stored in
5111 ;; `org-export-smart-quotes-alist'.
5113 (defconst org-export-smart-quotes-alist
5114 '(("da"
5115 ;; one may use: »...«, "...", ›...‹, or '...'.
5116 ;; http://sproget.dk/raad-og-regler/retskrivningsregler/retskrivningsregler/a7-40-60/a7-58-anforselstegn/
5117 ;; LaTeX quotes require Babel!
5118 (primary-opening
5119 :utf-8 "»" :html "&raquo;" :latex ">>" :texinfo "@guillemetright{}")
5120 (primary-closing
5121 :utf-8 "«" :html "&laquo;" :latex "<<" :texinfo "@guillemetleft{}")
5122 (secondary-opening
5123 :utf-8 "›" :html "&rsaquo;" :latex "\\frq{}" :texinfo "@guilsinglright{}")
5124 (secondary-closing
5125 :utf-8 "‹" :html "&lsaquo;" :latex "\\flq{}" :texinfo "@guilsingleft{}")
5126 (apostrophe :utf-8 "’" :html "&rsquo;"))
5127 ("de"
5128 (primary-opening
5129 :utf-8 "„" :html "&bdquo;" :latex "\"`" :texinfo "@quotedblbase{}")
5130 (primary-closing
5131 :utf-8 "“" :html "&ldquo;" :latex "\"'" :texinfo "@quotedblleft{}")
5132 (secondary-opening
5133 :utf-8 "‚" :html "&sbquo;" :latex "\\glq{}" :texinfo "@quotesinglbase{}")
5134 (secondary-closing
5135 :utf-8 "‘" :html "&lsquo;" :latex "\\grq{}" :texinfo "@quoteleft{}")
5136 (apostrophe :utf-8 "’" :html "&rsquo;"))
5137 ("en"
5138 (primary-opening :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
5139 (primary-closing :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
5140 (secondary-opening :utf-8 "‘" :html "&lsquo;" :latex "`" :texinfo "`")
5141 (secondary-closing :utf-8 "’" :html "&rsquo;" :latex "'" :texinfo "'")
5142 (apostrophe :utf-8 "’" :html "&rsquo;"))
5143 ("es"
5144 (primary-opening
5145 :utf-8 "«" :html "&laquo;" :latex "\\guillemotleft{}"
5146 :texinfo "@guillemetleft{}")
5147 (primary-closing
5148 :utf-8 "»" :html "&raquo;" :latex "\\guillemotright{}"
5149 :texinfo "@guillemetright{}")
5150 (secondary-opening :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
5151 (secondary-closing :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
5152 (apostrophe :utf-8 "’" :html "&rsquo;"))
5153 ("fr"
5154 (primary-opening
5155 :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
5156 :texinfo "@guillemetleft{}@tie{}")
5157 (primary-closing
5158 :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
5159 :texinfo "@tie{}@guillemetright{}")
5160 (secondary-opening
5161 :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
5162 :texinfo "@guillemetleft{}@tie{}")
5163 (secondary-closing :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
5164 :texinfo "@tie{}@guillemetright{}")
5165 (apostrophe :utf-8 "’" :html "&rsquo;"))
5166 ("no"
5167 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5168 (primary-opening
5169 :utf-8 "«" :html "&laquo;" :latex "\\guillemotleft{}"
5170 :texinfo "@guillemetleft{}")
5171 (primary-closing
5172 :utf-8 "»" :html "&raquo;" :latex "\\guillemotright{}"
5173 :texinfo "@guillemetright{}")
5174 (secondary-opening :utf-8 "‘" :html "&lsquo;" :latex "`" :texinfo "`")
5175 (secondary-closing :utf-8 "’" :html "&rsquo;" :latex "'" :texinfo "'")
5176 (apostrophe :utf-8 "’" :html "&rsquo;"))
5177 ("nb"
5178 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5179 (primary-opening
5180 :utf-8 "«" :html "&laquo;" :latex "\\guillemotleft{}"
5181 :texinfo "@guillemetleft{}")
5182 (primary-closing
5183 :utf-8 "»" :html "&raquo;" :latex "\\guillemotright{}"
5184 :texinfo "@guillemetright{}")
5185 (secondary-opening :utf-8 "‘" :html "&lsquo;" :latex "`" :texinfo "`")
5186 (secondary-closing :utf-8 "’" :html "&rsquo;" :latex "'" :texinfo "'")
5187 (apostrophe :utf-8 "’" :html "&rsquo;"))
5188 ("nn"
5189 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5190 (primary-opening
5191 :utf-8 "«" :html "&laquo;" :latex "\\guillemotleft{}"
5192 :texinfo "@guillemetleft{}")
5193 (primary-closing
5194 :utf-8 "»" :html "&raquo;" :latex "\\guillemotright{}"
5195 :texinfo "@guillemetright{}")
5196 (secondary-opening :utf-8 "‘" :html "&lsquo;" :latex "`" :texinfo "`")
5197 (secondary-closing :utf-8 "’" :html "&rsquo;" :latex "'" :texinfo "'")
5198 (apostrophe :utf-8 "’" :html "&rsquo;"))
5199 ("ru"
5200 ;; 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
5201 ;; http://www.artlebedev.ru/kovodstvo/sections/104/
5202 (primary-opening :utf-8 "«" :html "&laquo;" :latex "{}<<"
5203 :texinfo "@guillemetleft{}")
5204 (primary-closing :utf-8 "»" :html "&raquo;" :latex ">>{}"
5205 :texinfo "@guillemetright{}")
5206 (secondary-opening
5207 :utf-8 "„" :html "&bdquo;" :latex "\\glqq{}" :texinfo "@quotedblbase{}")
5208 (secondary-closing
5209 :utf-8 "“" :html "&ldquo;" :latex "\\grqq{}" :texinfo "@quotedblleft{}")
5210 (apostrophe :utf-8 "’" :html: "&#39;"))
5211 ("sv"
5212 ;; based on https://sv.wikipedia.org/wiki/Citattecken
5213 (primary-opening :utf-8 "”" :html "&rdquo;" :latex "’’" :texinfo "’’")
5214 (primary-closing :utf-8 "”" :html "&rdquo;" :latex "’’" :texinfo "’’")
5215 (secondary-opening :utf-8 "’" :html "&rsquo;" :latex "’" :texinfo "`")
5216 (secondary-closing :utf-8 "’" :html "&rsquo;" :latex "’" :texinfo "'")
5217 (apostrophe :utf-8 "’" :html "&rsquo;")))
5218 "Smart quotes translations.
5220 Alist whose CAR is a language string and CDR is an alist with
5221 quote type as key and a plist associating various encodings to
5222 their translation as value.
5224 A quote type can be any symbol among `primary-opening',
5225 `primary-closing', `secondary-opening', `secondary-closing' and
5226 `apostrophe'.
5228 Valid encodings include `:utf-8', `:html', `:latex' and
5229 `:texinfo'.
5231 If no translation is found, the quote character is left as-is.")
5233 (defun org-export--smart-quote-status (s info)
5234 "Return smart quote status at the beginning of string S.
5235 INFO is the current export state, as a plist."
5236 (let* ((parent (org-element-property :parent s))
5237 (cache (or (plist-get info :smart-quote-cache)
5238 (let ((table (make-hash-table :test #'eq)))
5239 (plist-put info :smart-quote-cache table)
5240 table)))
5241 (value (gethash parent cache 'missing-data)))
5242 (if (not (eq value 'missing-data)) (cdr (assq s value))
5243 (let (level1-open full-status)
5244 (org-element-map parent 'plain-text
5245 (lambda (text)
5246 (let ((start 0) current-status)
5247 (while (setq start (string-match "['\"]" text start))
5248 (push
5249 (cond
5250 ((equal (match-string 0 text) "\"")
5251 (setf level1-open (not level1-open))
5252 (if level1-open 'primary-opening 'primary-closing))
5253 ;; Not already in a level 1 quote: this is an
5254 ;; apostrophe.
5255 ((not level1-open) 'apostrophe)
5256 ;; Extract previous char and next char. As
5257 ;; a special case, they can also be set to `blank',
5258 ;; `no-blank' or nil. Then determine if current
5259 ;; match is allowed as an opening quote or a closing
5260 ;; quote.
5262 (let* ((previous
5263 (if (> start 0) (substring text (1- start) start)
5264 (let ((p (org-export-get-previous-element
5265 text info)))
5266 (cond ((not p) nil)
5267 ((stringp p) (substring p (1- (length p))))
5268 ((memq (org-element-property :post-blank p)
5269 '(0 nil))
5270 'no-blank)
5271 (t 'blank)))))
5272 (next
5273 (if (< (1+ start) (length text))
5274 (substring text (1+ start) (+ start 2))
5275 (let ((n (org-export-get-next-element text info)))
5276 (cond ((not n) nil)
5277 ((stringp n) (substring n 0 1))
5278 (t 'no-blank)))))
5279 (allow-open
5280 (and (if (stringp previous)
5281 (string-match "\\s\"\\|\\s-\\|\\s("
5282 previous)
5283 (memq previous '(blank nil)))
5284 (if (stringp next)
5285 (string-match "\\w\\|\\s.\\|\\s_" next)
5286 (eq next 'no-blank))))
5287 (allow-close
5288 (and (if (stringp previous)
5289 (string-match "\\w\\|\\s.\\|\\s_" previous)
5290 (eq previous 'no-blank))
5291 (if (stringp next)
5292 (string-match "\\s-\\|\\s)\\|\\s.\\|\\s\""
5293 next)
5294 (memq next '(blank nil))))))
5295 (cond
5296 ((and allow-open allow-close) (error "Should not happen"))
5297 (allow-open 'secondary-opening)
5298 (allow-close 'secondary-closing)
5299 (t 'apostrophe)))))
5300 current-status)
5301 (cl-incf start))
5302 (when current-status
5303 (push (cons text (nreverse current-status)) full-status))))
5304 info nil org-element-recursive-objects)
5305 (puthash parent full-status cache)
5306 (cdr (assq s full-status))))))
5308 (defun org-export-activate-smart-quotes (s encoding info &optional original)
5309 "Replace regular quotes with \"smart\" quotes in string S.
5311 ENCODING is a symbol among `:html', `:latex', `:texinfo' and
5312 `:utf-8'. INFO is a plist used as a communication channel.
5314 The function has to retrieve information about string
5315 surroundings in parse tree. It can only happen with an
5316 unmodified string. Thus, if S has already been through another
5317 process, a non-nil ORIGINAL optional argument will provide that
5318 original string.
5320 Return the new string."
5321 (let ((quote-status
5322 (copy-sequence (org-export--smart-quote-status (or original s) info))))
5323 (replace-regexp-in-string
5324 "['\"]"
5325 (lambda (match)
5326 (or (plist-get
5327 (cdr (assq (pop quote-status)
5328 (cdr (assoc (plist-get info :language)
5329 org-export-smart-quotes-alist))))
5330 encoding)
5331 match))
5332 s nil t)))
5334 ;;;; Topology
5336 ;; Here are various functions to retrieve information about the
5337 ;; neighborhood of a given element or object. Neighbors of interest
5338 ;; are direct parent (`org-export-get-parent'), parent headline
5339 ;; (`org-export-get-parent-headline'), first element containing an
5340 ;; object, (`org-export-get-parent-element'), parent table
5341 ;; (`org-export-get-parent-table'), previous element or object
5342 ;; (`org-export-get-previous-element') and next element or object
5343 ;; (`org-export-get-next-element').
5345 ;; defsubst org-export-get-parent must be defined before first use
5347 (define-obsolete-function-alias
5348 'org-export-get-genealogy 'org-element-lineage "25.1")
5350 (defun org-export-get-parent-headline (blob)
5351 "Return BLOB parent headline or nil.
5352 BLOB is the element or object being considered."
5353 (org-element-lineage blob '(headline)))
5355 (defun org-export-get-parent-element (object)
5356 "Return first element containing OBJECT or nil.
5357 OBJECT is the object to consider."
5358 (org-element-lineage object org-element-all-elements))
5360 (defun org-export-get-parent-table (object)
5361 "Return OBJECT parent table or nil.
5362 OBJECT is either a `table-cell' or `table-element' type object."
5363 (org-element-lineage object '(table)))
5365 (defun org-export-get-previous-element (blob info &optional n)
5366 "Return previous element or object.
5368 BLOB is an element or object. INFO is a plist used as
5369 a communication channel. Return previous exportable element or
5370 object, a string, or nil.
5372 When optional argument N is a positive integer, return a list
5373 containing up to N siblings before BLOB, from farthest to
5374 closest. With any other non-nil value, return a list containing
5375 all of them."
5376 (let* ((secondary (org-element-secondary-p blob))
5377 (parent (org-export-get-parent blob))
5378 (siblings
5379 (if secondary (org-element-property secondary parent)
5380 (org-element-contents parent)))
5381 prev)
5382 (catch 'exit
5383 (dolist (obj (cdr (memq blob (reverse siblings))) prev)
5384 (cond ((memq obj (plist-get info :ignore-list)))
5385 ((null n) (throw 'exit obj))
5386 ((not (wholenump n)) (push obj prev))
5387 ((zerop n) (throw 'exit prev))
5388 (t (cl-decf n) (push obj prev)))))))
5390 (defun org-export-get-next-element (blob info &optional n)
5391 "Return next element or object.
5393 BLOB is an element or object. INFO is a plist used as
5394 a communication channel. Return next exportable element or
5395 object, a string, or nil.
5397 When optional argument N is a positive integer, return a list
5398 containing up to N siblings after BLOB, from closest to farthest.
5399 With any other non-nil value, return a list containing all of
5400 them."
5401 (let* ((secondary (org-element-secondary-p blob))
5402 (parent (org-export-get-parent blob))
5403 (siblings
5404 (cdr (memq blob
5405 (if secondary (org-element-property secondary parent)
5406 (org-element-contents parent)))))
5407 next)
5408 (catch 'exit
5409 (dolist (obj siblings (nreverse next))
5410 (cond ((memq obj (plist-get info :ignore-list)))
5411 ((null n) (throw 'exit obj))
5412 ((not (wholenump n)) (push obj next))
5413 ((zerop n) (throw 'exit (nreverse next)))
5414 (t (cl-decf n) (push obj next)))))))
5417 ;;;; Translation
5419 ;; `org-export-translate' translates a string according to the language
5420 ;; specified by the LANGUAGE keyword. `org-export-dictionary' contains
5421 ;; the dictionary used for the translation.
5423 (defconst org-export-dictionary
5424 '(("%e %n: %c"
5425 ("fr" :default "%e %n : %c" :html "%e&nbsp;%n&nbsp;: %c"))
5426 ("Author"
5427 ("ca" :default "Autor")
5428 ("cs" :default "Autor")
5429 ("da" :default "Forfatter")
5430 ("de" :default "Autor")
5431 ("eo" :html "A&#365;toro")
5432 ("es" :default "Autor")
5433 ("et" :default "Autor")
5434 ("fi" :html "Tekij&auml;")
5435 ("fr" :default "Auteur")
5436 ("hu" :default "Szerz&otilde;")
5437 ("is" :html "H&ouml;fundur")
5438 ("it" :default "Autore")
5439 ("ja" :default "著者" :html "&#33879;&#32773;")
5440 ("nl" :default "Auteur")
5441 ("no" :default "Forfatter")
5442 ("nb" :default "Forfatter")
5443 ("nn" :default "Forfattar")
5444 ("pl" :default "Autor")
5445 ("pt_BR" :default "Autor")
5446 ("ru" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
5447 ("sv" :html "F&ouml;rfattare")
5448 ("uk" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
5449 ("zh-CN" :html "&#20316;&#32773;" :utf-8 "作者")
5450 ("zh-TW" :html "&#20316;&#32773;" :utf-8 "作者"))
5451 ("Continued from previous page"
5452 ("de" :default "Fortsetzung von vorheriger Seite")
5453 ("es" :html "Contin&uacute;a de la p&aacute;gina anterior" :ascii "Continua de la pagina anterior" :default "Continúa de la página anterior")
5454 ("fr" :default "Suite de la page précédente")
5455 ("it" :default "Continua da pagina precedente")
5456 ("ja" :default "前ページからの続き")
5457 ("nl" :default "Vervolg van vorige pagina")
5458 ("pt" :default "Continuação da página anterior")
5459 ("ru" :html "(&#1055;&#1088;&#1086;&#1076;&#1086;&#1083;&#1078;&#1077;&#1085;&#1080;&#1077;)"
5460 :utf-8 "(Продолжение)"))
5461 ("Continued on next page"
5462 ("de" :default "Fortsetzung nächste Seite")
5463 ("es" :html "Contin&uacute;a en la siguiente p&aacute;gina" :ascii "Continua en la siguiente pagina" :default "Continúa en la siguiente página")
5464 ("fr" :default "Suite page suivante")
5465 ("it" :default "Continua alla pagina successiva")
5466 ("ja" :default "次ページに続く")
5467 ("nl" :default "Vervolg op volgende pagina")
5468 ("pt" :default "Continua na página seguinte")
5469 ("ru" :html "(&#1055;&#1088;&#1086;&#1076;&#1086;&#1083;&#1078;&#1077;&#1085;&#1080;&#1077; &#1089;&#1083;&#1077;&#1076;&#1091;&#1077;&#1090;)"
5470 :utf-8 "(Продолжение следует)"))
5471 ("Date"
5472 ("ca" :default "Data")
5473 ("cs" :default "Datum")
5474 ("da" :default "Dato")
5475 ("de" :default "Datum")
5476 ("eo" :default "Dato")
5477 ("es" :default "Fecha")
5478 ("et" :html "Kuup&#228;ev" :utf-8 "Kuupäev")
5479 ("fi" :html "P&auml;iv&auml;m&auml;&auml;r&auml;")
5480 ("hu" :html "D&aacute;tum")
5481 ("is" :default "Dagsetning")
5482 ("it" :default "Data")
5483 ("ja" :default "日付" :html "&#26085;&#20184;")
5484 ("nl" :default "Datum")
5485 ("no" :default "Dato")
5486 ("nb" :default "Dato")
5487 ("nn" :default "Dato")
5488 ("pl" :default "Data")
5489 ("pt_BR" :default "Data")
5490 ("ru" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
5491 ("sv" :default "Datum")
5492 ("uk" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
5493 ("zh-CN" :html "&#26085;&#26399;" :utf-8 "日期")
5494 ("zh-TW" :html "&#26085;&#26399;" :utf-8 "日期"))
5495 ("Equation"
5496 ("da" :default "Ligning")
5497 ("de" :default "Gleichung")
5498 ("es" :ascii "Ecuacion" :html "Ecuaci&oacute;n" :default "Ecuación")
5499 ("et" :html "V&#245;rrand" :utf-8 "Võrrand")
5500 ("fr" :ascii "Equation" :default "Équation")
5501 ("ja" :default "方程式")
5502 ("no" :default "Ligning")
5503 ("nb" :default "Ligning")
5504 ("nn" :default "Likning")
5505 ("pt_BR" :html "Equa&ccedil;&atilde;o" :default "Equação" :ascii "Equacao")
5506 ("ru" :html "&#1059;&#1088;&#1072;&#1074;&#1085;&#1077;&#1085;&#1080;&#1077;"
5507 :utf-8 "Уравнение")
5508 ("sv" :default "Ekvation")
5509 ("zh-CN" :html "&#26041;&#31243;" :utf-8 "方程"))
5510 ("Figure"
5511 ("da" :default "Figur")
5512 ("de" :default "Abbildung")
5513 ("es" :default "Figura")
5514 ("et" :default "Joonis")
5515 ("ja" :default "図" :html "&#22259;")
5516 ("no" :default "Illustrasjon")
5517 ("nb" :default "Illustrasjon")
5518 ("nn" :default "Illustrasjon")
5519 ("pt_BR" :default "Figura")
5520 ("ru" :html "&#1056;&#1080;&#1089;&#1091;&#1085;&#1086;&#1082;" :utf-8 "Рисунок")
5521 ("sv" :default "Illustration")
5522 ("zh-CN" :html "&#22270;" :utf-8 "图"))
5523 ("Figure %d:"
5524 ("da" :default "Figur %d")
5525 ("de" :default "Abbildung %d:")
5526 ("es" :default "Figura %d:")
5527 ("et" :default "Joonis %d:")
5528 ("fr" :default "Figure %d :" :html "Figure&nbsp;%d&nbsp;:")
5529 ("ja" :default "図%d: " :html "&#22259;%d: ")
5530 ("no" :default "Illustrasjon %d")
5531 ("nb" :default "Illustrasjon %d")
5532 ("nn" :default "Illustrasjon %d")
5533 ("pt_BR" :default "Figura %d:")
5534 ("ru" :html "&#1056;&#1080;&#1089;. %d.:" :utf-8 "Рис. %d.:")
5535 ("sv" :default "Illustration %d")
5536 ("zh-CN" :html "&#22270;%d&nbsp;" :utf-8 "图%d "))
5537 ("Footnotes"
5538 ("ca" :html "Peus de p&agrave;gina")
5539 ("cs" :default "Pozn\xe1mky pod carou")
5540 ("da" :default "Fodnoter")
5541 ("de" :html "Fu&szlig;noten" :default "Fußnoten")
5542 ("eo" :default "Piednotoj")
5543 ("es" :ascii "Nota al pie de pagina" :html "Nota al pie de p&aacute;gina" :default "Nota al pie de página")
5544 ("et" :html "Allm&#228;rkused" :utf-8 "Allmärkused")
5545 ("fi" :default "Alaviitteet")
5546 ("fr" :default "Notes de bas de page")
5547 ("hu" :html "L&aacute;bjegyzet")
5548 ("is" :html "Aftanm&aacute;lsgreinar")
5549 ("it" :html "Note a pi&egrave; di pagina")
5550 ("ja" :default "脚注" :html "&#33050;&#27880;")
5551 ("nl" :default "Voetnoten")
5552 ("no" :default "Fotnoter")
5553 ("nb" :default "Fotnoter")
5554 ("nn" :default "Fotnotar")
5555 ("pl" :default "Przypis")
5556 ("pt_BR" :html "Notas de Rodap&eacute;" :default "Notas de Rodapé" :ascii "Notas de Rodape")
5557 ("ru" :html "&#1057;&#1085;&#1086;&#1089;&#1082;&#1080;" :utf-8 "Сноски")
5558 ("sv" :default "Fotnoter")
5559 ("uk" :html "&#1055;&#1088;&#1080;&#1084;&#1110;&#1090;&#1082;&#1080;"
5560 :utf-8 "Примітки")
5561 ("zh-CN" :html "&#33050;&#27880;" :utf-8 "脚注")
5562 ("zh-TW" :html "&#33139;&#35387;" :utf-8 "腳註"))
5563 ("List of Listings"
5564 ("da" :default "Programmer")
5565 ("de" :default "Programmauflistungsverzeichnis")
5566 ("es" :ascii "Indice de Listados de programas" :html "&Iacute;ndice de Listados de programas" :default "Índice de Listados de programas")
5567 ("et" :default "Loendite nimekiri")
5568 ("fr" :default "Liste des programmes")
5569 ("ja" :default "ソースコード目次")
5570 ("no" :default "Dataprogrammer")
5571 ("nb" :default "Dataprogrammer")
5572 ("ru" :html "&#1057;&#1087;&#1080;&#1089;&#1086;&#1082; &#1088;&#1072;&#1089;&#1087;&#1077;&#1095;&#1072;&#1090;&#1086;&#1082;"
5573 :utf-8 "Список распечаток")
5574 ("zh-CN" :html "&#20195;&#30721;&#30446;&#24405;" :utf-8 "代码目录"))
5575 ("List of Tables"
5576 ("da" :default "Tabeller")
5577 ("de" :default "Tabellenverzeichnis")
5578 ("es" :ascii "Indice de tablas" :html "&Iacute;ndice de tablas" :default "Índice de tablas")
5579 ("et" :default "Tabelite nimekiri")
5580 ("fr" :default "Liste des tableaux")
5581 ("ja" :default "表目次")
5582 ("no" :default "Tabeller")
5583 ("nb" :default "Tabeller")
5584 ("nn" :default "Tabeller")
5585 ("pt_BR" :default "Índice de Tabelas" :ascii "Indice de Tabelas")
5586 ("ru" :html "&#1057;&#1087;&#1080;&#1089;&#1086;&#1082; &#1090;&#1072;&#1073;&#1083;&#1080;&#1094;"
5587 :utf-8 "Список таблиц")
5588 ("sv" :default "Tabeller")
5589 ("zh-CN" :html "&#34920;&#26684;&#30446;&#24405;" :utf-8 "表格目录"))
5590 ("Listing"
5591 ("da" :default "Program")
5592 ("de" :default "Programmlisting")
5593 ("es" :default "Listado de programa")
5594 ("et" :default "Loend")
5595 ("fr" :default "Programme" :html "Programme")
5596 ("ja" :default "ソースコード")
5597 ("no" :default "Dataprogram")
5598 ("nb" :default "Dataprogram")
5599 ("pt_BR" :default "Listagem")
5600 ("ru" :html "&#1056;&#1072;&#1089;&#1087;&#1077;&#1095;&#1072;&#1090;&#1082;&#1072;"
5601 :utf-8 "Распечатка")
5602 ("zh-CN" :html "&#20195;&#30721;" :utf-8 "代码"))
5603 ("Listing %d:"
5604 ("da" :default "Program %d")
5605 ("de" :default "Programmlisting %d")
5606 ("es" :default "Listado de programa %d")
5607 ("et" :default "Loend %d")
5608 ("fr" :default "Programme %d :" :html "Programme&nbsp;%d&nbsp;:")
5609 ("ja" :default "ソースコード%d:")
5610 ("no" :default "Dataprogram %d")
5611 ("nb" :default "Dataprogram %d")
5612 ("pt_BR" :default "Listagem %d")
5613 ("ru" :html "&#1056;&#1072;&#1089;&#1087;&#1077;&#1095;&#1072;&#1090;&#1082;&#1072; %d.:"
5614 :utf-8 "Распечатка %d.:")
5615 ("zh-CN" :html "&#20195;&#30721;%d&nbsp;" :utf-8 "代码%d "))
5616 ("References"
5617 ("fr" :ascii "References" :default "Références")
5618 ("de" :default "Quellen")
5619 ("es" :default "Referencias"))
5620 ("See section %s"
5621 ("da" :default "jævnfør afsnit %s")
5622 ("de" :default "siehe Abschnitt %s")
5623 ("es" :ascii "Vea seccion %s" :html "Vea secci&oacute;n %s" :default "Vea sección %s")
5624 ("et" :html "Vaata peat&#252;kki %s" :utf-8 "Vaata peatükki %s")
5625 ("fr" :default "cf. section %s")
5626 ("ja" :default "セクション %s を参照")
5627 ("pt_BR" :html "Veja a se&ccedil;&atilde;o %s" :default "Veja a seção %s"
5628 :ascii "Veja a secao %s")
5629 ("ru" :html "&#1057;&#1084;. &#1088;&#1072;&#1079;&#1076;&#1077;&#1083; %s"
5630 :utf-8 "См. раздел %s")
5631 ("zh-CN" :html "&#21442;&#35265;&#31532;%s&#33410;" :utf-8 "参见第%s节"))
5632 ("Table"
5633 ("de" :default "Tabelle")
5634 ("es" :default "Tabla")
5635 ("et" :default "Tabel")
5636 ("fr" :default "Tableau")
5637 ("ja" :default "表" :html "&#34920;")
5638 ("pt_BR" :default "Tabela")
5639 ("ru" :html "&#1058;&#1072;&#1073;&#1083;&#1080;&#1094;&#1072;"
5640 :utf-8 "Таблица")
5641 ("zh-CN" :html "&#34920;" :utf-8 "表"))
5642 ("Table %d:"
5643 ("da" :default "Tabel %d")
5644 ("de" :default "Tabelle %d")
5645 ("es" :default "Tabla %d")
5646 ("et" :default "Tabel %d")
5647 ("fr" :default "Tableau %d :")
5648 ("ja" :default "表%d:" :html "&#34920;%d:")
5649 ("no" :default "Tabell %d")
5650 ("nb" :default "Tabell %d")
5651 ("nn" :default "Tabell %d")
5652 ("pt_BR" :default "Tabela %d")
5653 ("ru" :html "&#1058;&#1072;&#1073;&#1083;&#1080;&#1094;&#1072; %d.:"
5654 :utf-8 "Таблица %d.:")
5655 ("sv" :default "Tabell %d")
5656 ("zh-CN" :html "&#34920;%d&nbsp;" :utf-8 "表%d "))
5657 ("Table of Contents"
5658 ("ca" :html "&Iacute;ndex")
5659 ("cs" :default "Obsah")
5660 ("da" :default "Indhold")
5661 ("de" :default "Inhaltsverzeichnis")
5662 ("eo" :default "Enhavo")
5663 ("es" :ascii "Indice" :html "&Iacute;ndice" :default "Índice")
5664 ("et" :default "Sisukord")
5665 ("fi" :html "Sis&auml;llysluettelo")
5666 ("fr" :ascii "Sommaire" :default "Table des matières")
5667 ("hu" :html "Tartalomjegyz&eacute;k")
5668 ("is" :default "Efnisyfirlit")
5669 ("it" :default "Indice")
5670 ("ja" :default "目次" :html "&#30446;&#27425;")
5671 ("nl" :default "Inhoudsopgave")
5672 ("no" :default "Innhold")
5673 ("nb" :default "Innhold")
5674 ("nn" :default "Innhald")
5675 ("pl" :html "Spis tre&#x015b;ci")
5676 ("pt_BR" :html "&Iacute;ndice" :utf8 "Índice" :ascii "Indice")
5677 ("ru" :html "&#1057;&#1086;&#1076;&#1077;&#1088;&#1078;&#1072;&#1085;&#1080;&#1077;"
5678 :utf-8 "Содержание")
5679 ("sv" :html "Inneh&aring;ll")
5680 ("uk" :html "&#1047;&#1084;&#1110;&#1089;&#1090;" :utf-8 "Зміст")
5681 ("zh-CN" :html "&#30446;&#24405;" :utf-8 "目录")
5682 ("zh-TW" :html "&#30446;&#37636;" :utf-8 "目錄"))
5683 ("Unknown reference"
5684 ("da" :default "ukendt reference")
5685 ("de" :default "Unbekannter Verweis")
5686 ("es" :default "Referencia desconocida")
5687 ("et" :default "Tundmatu viide")
5688 ("fr" :ascii "Destination inconnue" :default "Référence inconnue")
5689 ("ja" :default "不明な参照先")
5690 ("pt_BR" :default "Referência desconhecida"
5691 :ascii "Referencia desconhecida")
5692 ("ru" :html "&#1053;&#1077;&#1080;&#1079;&#1074;&#1077;&#1089;&#1090;&#1085;&#1072;&#1103; &#1089;&#1089;&#1099;&#1083;&#1082;&#1072;"
5693 :utf-8 "Неизвестная ссылка")
5694 ("zh-CN" :html "&#26410;&#30693;&#24341;&#29992;" :utf-8 "未知引用")))
5695 "Dictionary for export engine.
5697 Alist whose car is the string to translate and cdr is an alist
5698 whose car is the language string and cdr is a plist whose
5699 properties are possible charsets and values translated terms.
5701 It is used as a database for `org-export-translate'. Since this
5702 function returns the string as-is if no translation was found,
5703 the variable only needs to record values different from the
5704 entry.")
5706 (defun org-export-translate (s encoding info)
5707 "Translate string S according to language specification.
5709 ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
5710 and `:utf-8'. INFO is a plist used as a communication channel.
5712 Translation depends on `:language' property. Return the
5713 translated string. If no translation is found, try to fall back
5714 to `:default' encoding. If it fails, return S."
5715 (let* ((lang (plist-get info :language))
5716 (translations (cdr (assoc lang
5717 (cdr (assoc s org-export-dictionary))))))
5718 (or (plist-get translations encoding)
5719 (plist-get translations :default)
5720 s)))
5724 ;;; Asynchronous Export
5726 ;; `org-export-async-start' is the entry point for asynchronous
5727 ;; export. It recreates current buffer (including visibility,
5728 ;; narrowing and visited file) in an external Emacs process, and
5729 ;; evaluates a command there. It then applies a function on the
5730 ;; returned results in the current process.
5732 ;; At a higher level, `org-export-to-buffer' and `org-export-to-file'
5733 ;; allow to export to a buffer or a file, asynchronously or not.
5735 ;; `org-export-output-file-name' is an auxiliary function meant to be
5736 ;; used with `org-export-to-file'. With a given extension, it tries
5737 ;; to provide a canonical file name to write export output to.
5739 ;; Asynchronously generated results are never displayed directly.
5740 ;; Instead, they are stored in `org-export-stack-contents'. They can
5741 ;; then be retrieved by calling `org-export-stack'.
5743 ;; Export Stack is viewed through a dedicated major mode
5744 ;;`org-export-stack-mode' and tools: `org-export-stack-refresh',
5745 ;;`org-export-stack-delete', `org-export-stack-view' and
5746 ;;`org-export-stack-clear'.
5748 ;; For back-ends, `org-export-add-to-stack' add a new source to stack.
5749 ;; It should be used whenever `org-export-async-start' is called.
5751 (defmacro org-export-async-start (fun &rest body)
5752 "Call function FUN on the results returned by BODY evaluation.
5754 FUN is an anonymous function of one argument. BODY evaluation
5755 happens in an asynchronous process, from a buffer which is an
5756 exact copy of the current one.
5758 Use `org-export-add-to-stack' in FUN in order to register results
5759 in the stack.
5761 This is a low level function. See also `org-export-to-buffer'
5762 and `org-export-to-file' for more specialized functions."
5763 (declare (indent 1) (debug t))
5764 (org-with-gensyms (process temp-file copy-fun proc-buffer coding)
5765 ;; Write the full sexp evaluating BODY in a copy of the current
5766 ;; buffer to a temporary file, as it may be too long for program
5767 ;; args in `start-process'.
5768 `(with-temp-message "Initializing asynchronous export process"
5769 (let ((,copy-fun (org-export--generate-copy-script (current-buffer)))
5770 (,temp-file (make-temp-file "org-export-process"))
5771 (,coding buffer-file-coding-system))
5772 (with-temp-file ,temp-file
5773 (insert
5774 ;; Null characters (from variable values) are inserted
5775 ;; within the file. As a consequence, coding system for
5776 ;; buffer contents will not be recognized properly. So,
5777 ;; we make sure it is the same as the one used to display
5778 ;; the original buffer.
5779 (format ";; -*- coding: %s; -*-\n%S"
5780 ,coding
5781 `(with-temp-buffer
5782 (when org-export-async-debug '(setq debug-on-error t))
5783 ;; Ignore `kill-emacs-hook' and code evaluation
5784 ;; queries from Babel as we need a truly
5785 ;; non-interactive process.
5786 (setq kill-emacs-hook nil
5787 org-babel-confirm-evaluate-answer-no t)
5788 ;; Initialize export framework.
5789 (require 'ox)
5790 ;; Re-create current buffer there.
5791 (funcall ,,copy-fun)
5792 (restore-buffer-modified-p nil)
5793 ;; Sexp to evaluate in the buffer.
5794 (print (progn ,,@body))))))
5795 ;; Start external process.
5796 (let* ((process-connection-type nil)
5797 (,proc-buffer (generate-new-buffer-name "*Org Export Process*"))
5798 (,process
5799 (apply
5800 #'start-process
5801 (append
5802 (list "org-export-process"
5803 ,proc-buffer
5804 (expand-file-name invocation-name invocation-directory)
5805 "--batch")
5806 (if org-export-async-init-file
5807 (list "-Q" "-l" org-export-async-init-file)
5808 (list "-l" user-init-file))
5809 (list "-l" ,temp-file)))))
5810 ;; Register running process in stack.
5811 (org-export-add-to-stack (get-buffer ,proc-buffer) nil ,process)
5812 ;; Set-up sentinel in order to catch results.
5813 (let ((handler ,fun))
5814 (set-process-sentinel
5815 ,process
5816 `(lambda (p status)
5817 (let ((proc-buffer (process-buffer p)))
5818 (when (eq (process-status p) 'exit)
5819 (unwind-protect
5820 (if (zerop (process-exit-status p))
5821 (unwind-protect
5822 (let ((results
5823 (with-current-buffer proc-buffer
5824 (goto-char (point-max))
5825 (backward-sexp)
5826 (read (current-buffer)))))
5827 (funcall ,handler results))
5828 (unless org-export-async-debug
5829 (and (get-buffer proc-buffer)
5830 (kill-buffer proc-buffer))))
5831 (org-export-add-to-stack proc-buffer nil p)
5832 (ding)
5833 (message "Process `%s' exited abnormally" p))
5834 (unless org-export-async-debug
5835 (delete-file ,,temp-file)))))))))))))
5837 ;;;###autoload
5838 (defun org-export-to-buffer
5839 (backend buffer
5840 &optional async subtreep visible-only body-only ext-plist
5841 post-process)
5842 "Call `org-export-as' with output to a specified buffer.
5844 BACKEND is either an export back-end, as returned by, e.g.,
5845 `org-export-create-backend', or a symbol referring to
5846 a registered back-end.
5848 BUFFER is the name of the output buffer. If it already exists,
5849 it will be erased first, otherwise, it will be created.
5851 A non-nil optional argument ASYNC means the process should happen
5852 asynchronously. The resulting buffer should then be accessible
5853 through the `org-export-stack' interface. When ASYNC is nil, the
5854 buffer is displayed if `org-export-show-temporary-export-buffer'
5855 is non-nil.
5857 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
5858 EXT-PLIST are similar to those used in `org-export-as', which
5859 see.
5861 Optional argument POST-PROCESS is a function which should accept
5862 no argument. It is always called within the current process,
5863 from BUFFER, with point at its beginning. Export back-ends can
5864 use it to set a major mode there, e.g,
5866 (defun org-latex-export-as-latex
5867 (&optional async subtreep visible-only body-only ext-plist)
5868 (interactive)
5869 (org-export-to-buffer \\='latex \"*Org LATEX Export*\"
5870 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
5872 This function returns BUFFER."
5873 (declare (indent 2))
5874 (if async
5875 (org-export-async-start
5876 `(lambda (output)
5877 (with-current-buffer (get-buffer-create ,buffer)
5878 (erase-buffer)
5879 (setq buffer-file-coding-system ',buffer-file-coding-system)
5880 (insert output)
5881 (goto-char (point-min))
5882 (org-export-add-to-stack (current-buffer) ',backend)
5883 (ignore-errors (funcall ,post-process))))
5884 `(org-export-as
5885 ',backend ,subtreep ,visible-only ,body-only ',ext-plist))
5886 (let ((output
5887 (org-export-as backend subtreep visible-only body-only ext-plist))
5888 (buffer (get-buffer-create buffer))
5889 (encoding buffer-file-coding-system))
5890 (when (and (org-string-nw-p output) (org-export--copy-to-kill-ring-p))
5891 (org-kill-new output))
5892 (with-current-buffer buffer
5893 (erase-buffer)
5894 (setq buffer-file-coding-system encoding)
5895 (insert output)
5896 (goto-char (point-min))
5897 (and (functionp post-process) (funcall post-process)))
5898 (when org-export-show-temporary-export-buffer
5899 (switch-to-buffer-other-window buffer))
5900 buffer)))
5902 ;;;###autoload
5903 (defun org-export-to-file
5904 (backend file &optional async subtreep visible-only body-only ext-plist
5905 post-process)
5906 "Call `org-export-as' with output to a specified file.
5908 BACKEND is either an export back-end, as returned by, e.g.,
5909 `org-export-create-backend', or a symbol referring to
5910 a registered back-end. FILE is the name of the output file, as
5911 a string.
5913 A non-nil optional argument ASYNC means the process should happen
5914 asynchronously. The resulting buffer will then be accessible
5915 through the `org-export-stack' interface.
5917 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
5918 EXT-PLIST are similar to those used in `org-export-as', which
5919 see.
5921 Optional argument POST-PROCESS is called with FILE as its
5922 argument and happens asynchronously when ASYNC is non-nil. It
5923 has to return a file name, or nil. Export back-ends can use this
5924 to send the output file through additional processing, e.g,
5926 (defun org-latex-export-to-latex
5927 (&optional async subtreep visible-only body-only ext-plist)
5928 (interactive)
5929 (let ((outfile (org-export-output-file-name \".tex\" subtreep)))
5930 (org-export-to-file \\='latex outfile
5931 async subtreep visible-only body-only ext-plist
5932 (lambda (file) (org-latex-compile file)))
5934 The function returns either a file name returned by POST-PROCESS,
5935 or FILE."
5936 (declare (indent 2))
5937 (if (not (file-writable-p file)) (error "Output file not writable")
5938 (let ((ext-plist (org-combine-plists `(:output-file ,file) ext-plist))
5939 (encoding (or org-export-coding-system buffer-file-coding-system)))
5940 (if async
5941 (org-export-async-start
5942 `(lambda (file)
5943 (org-export-add-to-stack (expand-file-name file) ',backend))
5944 `(let ((output
5945 (org-export-as
5946 ',backend ,subtreep ,visible-only ,body-only
5947 ',ext-plist)))
5948 (with-temp-buffer
5949 (insert output)
5950 (let ((coding-system-for-write ',encoding))
5951 (write-file ,file)))
5952 (or (ignore-errors (funcall ',post-process ,file)) ,file)))
5953 (let ((output (org-export-as
5954 backend subtreep visible-only body-only ext-plist)))
5955 (with-temp-buffer
5956 (insert output)
5957 (let ((coding-system-for-write encoding))
5958 (write-file file)))
5959 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p output))
5960 (org-kill-new output))
5961 ;; Get proper return value.
5962 (or (and (functionp post-process) (funcall post-process file))
5963 file))))))
5965 (defun org-export-output-file-name (extension &optional subtreep pub-dir)
5966 "Return output file's name according to buffer specifications.
5968 EXTENSION is a string representing the output file extension,
5969 with the leading dot.
5971 With a non-nil optional argument SUBTREEP, try to determine
5972 output file's name by looking for \"EXPORT_FILE_NAME\" property
5973 of subtree at point.
5975 When optional argument PUB-DIR is set, use it as the publishing
5976 directory.
5978 Return file name as a string."
5979 (let* ((visited-file (buffer-file-name (buffer-base-buffer)))
5980 (base-name
5981 ;; File name may come from EXPORT_FILE_NAME subtree
5982 ;; property.
5983 (file-name-sans-extension
5984 (or (and subtreep (org-entry-get nil "EXPORT_FILE_NAME" 'selective))
5985 ;; File name may be extracted from buffer's associated
5986 ;; file, if any.
5987 (and visited-file (file-name-nondirectory visited-file))
5988 ;; Can't determine file name on our own: Ask user.
5989 (read-file-name
5990 "Output file: " pub-dir nil nil nil
5991 (lambda (name)
5992 (string= (file-name-extension name t) extension))))))
5993 (output-file
5994 ;; Build file name. Enforce EXTENSION over whatever user
5995 ;; may have come up with. PUB-DIR, if defined, always has
5996 ;; precedence over any provided path.
5997 (cond
5998 (pub-dir
5999 (concat (file-name-as-directory pub-dir)
6000 (file-name-nondirectory base-name)
6001 extension))
6002 ((file-name-absolute-p base-name) (concat base-name extension))
6003 (t (concat (file-name-as-directory ".") base-name extension)))))
6004 ;; If writing to OUTPUT-FILE would overwrite original file, append
6005 ;; EXTENSION another time to final name.
6006 (if (and visited-file (file-equal-p visited-file output-file))
6007 (concat output-file extension)
6008 output-file)))
6010 (defun org-export-add-to-stack (source backend &optional process)
6011 "Add a new result to export stack if not present already.
6013 SOURCE is a buffer or a file name containing export results.
6014 BACKEND is a symbol representing export back-end used to generate
6017 Entries already pointing to SOURCE and unavailable entries are
6018 removed beforehand. Return the new stack."
6019 (setq org-export-stack-contents
6020 (cons (list source backend (or process (current-time)))
6021 (org-export-stack-remove source))))
6023 (defun org-export-stack ()
6024 "Menu for asynchronous export results and running processes."
6025 (interactive)
6026 (let ((buffer (get-buffer-create "*Org Export Stack*")))
6027 (set-buffer buffer)
6028 (when (zerop (buffer-size)) (org-export-stack-mode))
6029 (org-export-stack-refresh)
6030 (pop-to-buffer buffer))
6031 (message "Type \"q\" to quit, \"?\" for help"))
6033 (defun org-export--stack-source-at-point ()
6034 "Return source from export results at point in stack."
6035 (let ((source (car (nth (1- (org-current-line)) org-export-stack-contents))))
6036 (if (not source) (error "Source unavailable, please refresh buffer")
6037 (let ((source-name (if (stringp source) source (buffer-name source))))
6038 (if (save-excursion
6039 (beginning-of-line)
6040 (looking-at (concat ".* +" (regexp-quote source-name) "$")))
6041 source
6042 ;; SOURCE is not consistent with current line. The stack
6043 ;; view is outdated.
6044 (error "Source unavailable; type `g' to update buffer"))))))
6046 (defun org-export-stack-clear ()
6047 "Remove all entries from export stack."
6048 (interactive)
6049 (setq org-export-stack-contents nil))
6051 (defun org-export-stack-refresh (&rest _)
6052 "Refresh the asynchronous export stack.
6053 Unavailable sources are removed from the list. Return the new
6054 stack."
6055 (let ((inhibit-read-only t))
6056 (org-preserve-lc
6057 (erase-buffer)
6058 (insert (concat
6059 (mapconcat
6060 (lambda (entry)
6061 (let ((proc-p (processp (nth 2 entry))))
6062 (concat
6063 ;; Back-end.
6064 (format " %-12s " (or (nth 1 entry) ""))
6065 ;; Age.
6066 (let ((data (nth 2 entry)))
6067 (if proc-p (format " %6s " (process-status data))
6068 ;; Compute age of the results.
6069 (org-format-seconds
6070 "%4h:%.2m "
6071 (float-time (time-since data)))))
6072 ;; Source.
6073 (format " %s"
6074 (let ((source (car entry)))
6075 (if (stringp source) source
6076 (buffer-name source)))))))
6077 ;; Clear stack from exited processes, dead buffers or
6078 ;; non-existent files.
6079 (setq org-export-stack-contents
6080 (cl-remove-if-not
6081 (lambda (el)
6082 (if (processp (nth 2 el))
6083 (buffer-live-p (process-buffer (nth 2 el)))
6084 (let ((source (car el)))
6085 (if (bufferp source) (buffer-live-p source)
6086 (file-exists-p source)))))
6087 org-export-stack-contents)) "\n"))))))
6089 (defun org-export-stack-remove (&optional source)
6090 "Remove export results at point from stack.
6091 If optional argument SOURCE is non-nil, remove it instead."
6092 (interactive)
6093 (let ((source (or source (org-export--stack-source-at-point))))
6094 (setq org-export-stack-contents
6095 (cl-remove-if (lambda (el) (equal (car el) source))
6096 org-export-stack-contents))))
6098 (defun org-export-stack-view (&optional in-emacs)
6099 "View export results at point in stack.
6100 With an optional prefix argument IN-EMACS, force viewing files
6101 within Emacs."
6102 (interactive "P")
6103 (let ((source (org-export--stack-source-at-point)))
6104 (cond ((processp source)
6105 (org-switch-to-buffer-other-window (process-buffer source)))
6106 ((bufferp source) (org-switch-to-buffer-other-window source))
6107 (t (org-open-file source in-emacs)))))
6109 (defvar org-export-stack-mode-map
6110 (let ((km (make-sparse-keymap)))
6111 (define-key km " " 'next-line)
6112 (define-key km "n" 'next-line)
6113 (define-key km "\C-n" 'next-line)
6114 (define-key km [down] 'next-line)
6115 (define-key km "p" 'previous-line)
6116 (define-key km "\C-p" 'previous-line)
6117 (define-key km "\C-?" 'previous-line)
6118 (define-key km [up] 'previous-line)
6119 (define-key km "C" 'org-export-stack-clear)
6120 (define-key km "v" 'org-export-stack-view)
6121 (define-key km (kbd "RET") 'org-export-stack-view)
6122 (define-key km "d" 'org-export-stack-remove)
6124 "Keymap for Org Export Stack.")
6126 (define-derived-mode org-export-stack-mode special-mode "Org-Stack"
6127 "Mode for displaying asynchronous export stack.
6129 Type \\[org-export-stack] to visualize the asynchronous export
6130 stack.
6132 In an Org Export Stack buffer, use \\<org-export-stack-mode-map>\\[org-export-stack-view] to view export output
6133 on current line, \\[org-export-stack-remove] to remove it from the stack and \\[org-export-stack-clear] to clear
6134 stack completely.
6136 Removing entries in an Org Export Stack buffer doesn't affect
6137 files or buffers, only the display.
6139 \\{org-export-stack-mode-map}"
6140 (abbrev-mode 0)
6141 (auto-fill-mode 0)
6142 (setq buffer-read-only t
6143 buffer-undo-list t
6144 truncate-lines t
6145 header-line-format
6146 '(:eval
6147 (format " %-12s | %6s | %s" "Back-End" "Age" "Source")))
6148 (org-add-hook 'post-command-hook 'org-export-stack-refresh nil t)
6149 (setq-local revert-buffer-function
6150 'org-export-stack-refresh))
6154 ;;; The Dispatcher
6156 ;; `org-export-dispatch' is the standard interactive way to start an
6157 ;; export process. It uses `org-export--dispatch-ui' as a subroutine
6158 ;; for its interface, which, in turn, delegates response to key
6159 ;; pressed to `org-export--dispatch-action'.
6161 ;;;###autoload
6162 (defun org-export-dispatch (&optional arg)
6163 "Export dispatcher for Org mode.
6165 It provides an access to common export related tasks in a buffer.
6166 Its interface comes in two flavors: standard and expert.
6168 While both share the same set of bindings, only the former
6169 displays the valid keys associations in a dedicated buffer.
6170 Scrolling (resp. line-wise motion) in this buffer is done with
6171 SPC and DEL (resp. C-n and C-p) keys.
6173 Set variable `org-export-dispatch-use-expert-ui' to switch to one
6174 flavor or the other.
6176 When ARG is \\[universal-argument], repeat the last export action, with the same set
6177 of options used back then, on the current buffer.
6179 When ARG is \\[universal-argument] \\[universal-argument], display the asynchronous export stack."
6180 (interactive "P")
6181 (let* ((input
6182 (cond ((equal arg '(16)) '(stack))
6183 ((and arg org-export-dispatch-last-action))
6184 (t (save-window-excursion
6185 (unwind-protect
6186 (progn
6187 ;; Remember where we are
6188 (move-marker org-export-dispatch-last-position
6189 (point)
6190 (org-base-buffer (current-buffer)))
6191 ;; Get and store an export command
6192 (setq org-export-dispatch-last-action
6193 (org-export--dispatch-ui
6194 (list org-export-initial-scope
6195 (and org-export-in-background 'async))
6197 org-export-dispatch-use-expert-ui)))
6198 (and (get-buffer "*Org Export Dispatcher*")
6199 (kill-buffer "*Org Export Dispatcher*")))))))
6200 (action (car input))
6201 (optns (cdr input)))
6202 (unless (memq 'subtree optns)
6203 (move-marker org-export-dispatch-last-position nil))
6204 (cl-case action
6205 ;; First handle special hard-coded actions.
6206 (template (org-export-insert-default-template nil optns))
6207 (stack (org-export-stack))
6208 (publish-current-file
6209 (org-publish-current-file (memq 'force optns) (memq 'async optns)))
6210 (publish-current-project
6211 (org-publish-current-project (memq 'force optns) (memq 'async optns)))
6212 (publish-choose-project
6213 (org-publish (assoc (org-icompleting-read
6214 "Publish project: "
6215 org-publish-project-alist nil t)
6216 org-publish-project-alist)
6217 (memq 'force optns)
6218 (memq 'async optns)))
6219 (publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
6220 (otherwise
6221 (save-excursion
6222 (when arg
6223 ;; Repeating command, maybe move cursor to restore subtree
6224 ;; context.
6225 (if (eq (marker-buffer org-export-dispatch-last-position)
6226 (org-base-buffer (current-buffer)))
6227 (goto-char org-export-dispatch-last-position)
6228 ;; We are in a different buffer, forget position.
6229 (move-marker org-export-dispatch-last-position nil)))
6230 (funcall action
6231 ;; Return a symbol instead of a list to ease
6232 ;; asynchronous export macro use.
6233 (and (memq 'async optns) t)
6234 (and (memq 'subtree optns) t)
6235 (and (memq 'visible optns) t)
6236 (and (memq 'body optns) t)))))))
6238 (defun org-export--dispatch-ui (options first-key expertp)
6239 "Handle interface for `org-export-dispatch'.
6241 OPTIONS is a list containing current interactive options set for
6242 export. It can contain any of the following symbols:
6243 `body' toggles a body-only export
6244 `subtree' restricts export to current subtree
6245 `visible' restricts export to visible part of buffer.
6246 `force' force publishing files.
6247 `async' use asynchronous export process
6249 FIRST-KEY is the key pressed to select the first level menu. It
6250 is nil when this menu hasn't been selected yet.
6252 EXPERTP, when non-nil, triggers expert UI. In that case, no help
6253 buffer is provided, but indications about currently active
6254 options are given in the prompt. Moreover, [?] allows to switch
6255 back to standard interface."
6256 (let* ((fontify-key
6257 (lambda (key &optional access-key)
6258 ;; Fontify KEY string. Optional argument ACCESS-KEY, when
6259 ;; non-nil is the required first-level key to activate
6260 ;; KEY. When its value is t, activate KEY independently
6261 ;; on the first key, if any. A nil value means KEY will
6262 ;; only be activated at first level.
6263 (if (or (eq access-key t) (eq access-key first-key))
6264 (org-propertize key 'face 'org-warning)
6265 key)))
6266 (fontify-value
6267 (lambda (value)
6268 ;; Fontify VALUE string.
6269 (org-propertize value 'face 'font-lock-variable-name-face)))
6270 ;; Prepare menu entries by extracting them from registered
6271 ;; back-ends and sorting them by access key and by ordinal,
6272 ;; if any.
6273 (entries
6274 (sort (sort (delq nil
6275 (mapcar #'org-export-backend-menu
6276 org-export-registered-backends))
6277 (lambda (a b)
6278 (let ((key-a (nth 1 a))
6279 (key-b (nth 1 b)))
6280 (cond ((and (numberp key-a) (numberp key-b))
6281 (< key-a key-b))
6282 ((numberp key-b) t)))))
6283 'car-less-than-car))
6284 ;; Compute a list of allowed keys based on the first key
6285 ;; pressed, if any. Some keys
6286 ;; (?^B, ?^V, ?^S, ?^F, ?^A, ?&, ?# and ?q) are always
6287 ;; available.
6288 (allowed-keys
6289 (nconc (list 2 22 19 6 1)
6290 (if (not first-key) (org-uniquify (mapcar 'car entries))
6291 (let (sub-menu)
6292 (dolist (entry entries (sort (mapcar 'car sub-menu) '<))
6293 (when (eq (car entry) first-key)
6294 (setq sub-menu (append (nth 2 entry) sub-menu))))))
6295 (cond ((eq first-key ?P) (list ?f ?p ?x ?a))
6296 ((not first-key) (list ?P)))
6297 (list ?& ?#)
6298 (when expertp (list ??))
6299 (list ?q)))
6300 ;; Build the help menu for standard UI.
6301 (help
6302 (unless expertp
6303 (concat
6304 ;; Options are hard-coded.
6305 (format "[%s] Body only: %s [%s] Visible only: %s
6306 \[%s] Export scope: %s [%s] Force publishing: %s
6307 \[%s] Async export: %s\n\n"
6308 (funcall fontify-key "C-b" t)
6309 (funcall fontify-value
6310 (if (memq 'body options) "On " "Off"))
6311 (funcall fontify-key "C-v" t)
6312 (funcall fontify-value
6313 (if (memq 'visible options) "On " "Off"))
6314 (funcall fontify-key "C-s" t)
6315 (funcall fontify-value
6316 (if (memq 'subtree options) "Subtree" "Buffer "))
6317 (funcall fontify-key "C-f" t)
6318 (funcall fontify-value
6319 (if (memq 'force options) "On " "Off"))
6320 (funcall fontify-key "C-a" t)
6321 (funcall fontify-value
6322 (if (memq 'async options) "On " "Off")))
6323 ;; Display registered back-end entries. When a key
6324 ;; appears for the second time, do not create another
6325 ;; entry, but append its sub-menu to existing menu.
6326 (let (last-key)
6327 (mapconcat
6328 (lambda (entry)
6329 (let ((top-key (car entry)))
6330 (concat
6331 (unless (eq top-key last-key)
6332 (setq last-key top-key)
6333 (format "\n[%s] %s\n"
6334 (funcall fontify-key (char-to-string top-key))
6335 (nth 1 entry)))
6336 (let ((sub-menu (nth 2 entry)))
6337 (unless (functionp sub-menu)
6338 ;; Split sub-menu into two columns.
6339 (let ((index -1))
6340 (concat
6341 (mapconcat
6342 (lambda (sub-entry)
6343 (cl-incf index)
6344 (format
6345 (if (zerop (mod index 2)) " [%s] %-26s"
6346 "[%s] %s\n")
6347 (funcall fontify-key
6348 (char-to-string (car sub-entry))
6349 top-key)
6350 (nth 1 sub-entry)))
6351 sub-menu "")
6352 (when (zerop (mod index 2)) "\n"))))))))
6353 entries ""))
6354 ;; Publishing menu is hard-coded.
6355 (format "\n[%s] Publish
6356 [%s] Current file [%s] Current project
6357 [%s] Choose project [%s] All projects\n\n\n"
6358 (funcall fontify-key "P")
6359 (funcall fontify-key "f" ?P)
6360 (funcall fontify-key "p" ?P)
6361 (funcall fontify-key "x" ?P)
6362 (funcall fontify-key "a" ?P))
6363 (format "[%s] Export stack [%s] Insert template\n"
6364 (funcall fontify-key "&" t)
6365 (funcall fontify-key "#" t))
6366 (format "[%s] %s"
6367 (funcall fontify-key "q" t)
6368 (if first-key "Main menu" "Exit")))))
6369 ;; Build prompts for both standard and expert UI.
6370 (standard-prompt (unless expertp "Export command: "))
6371 (expert-prompt
6372 (when expertp
6373 (format
6374 "Export command (C-%s%s%s%s%s) [%s]: "
6375 (if (memq 'body options) (funcall fontify-key "b" t) "b")
6376 (if (memq 'visible options) (funcall fontify-key "v" t) "v")
6377 (if (memq 'subtree options) (funcall fontify-key "s" t) "s")
6378 (if (memq 'force options) (funcall fontify-key "f" t) "f")
6379 (if (memq 'async options) (funcall fontify-key "a" t) "a")
6380 (mapconcat (lambda (k)
6381 ;; Strip control characters.
6382 (unless (< k 27) (char-to-string k)))
6383 allowed-keys "")))))
6384 ;; With expert UI, just read key with a fancy prompt. In standard
6385 ;; UI, display an intrusive help buffer.
6386 (if expertp
6387 (org-export--dispatch-action
6388 expert-prompt allowed-keys entries options first-key expertp)
6389 ;; At first call, create frame layout in order to display menu.
6390 (unless (get-buffer "*Org Export Dispatcher*")
6391 (delete-other-windows)
6392 (org-switch-to-buffer-other-window
6393 (get-buffer-create "*Org Export Dispatcher*"))
6394 (setq cursor-type nil
6395 header-line-format "Use SPC, DEL, C-n or C-p to navigate.")
6396 ;; Make sure that invisible cursor will not highlight square
6397 ;; brackets.
6398 (set-syntax-table (copy-syntax-table))
6399 (modify-syntax-entry ?\[ "w"))
6400 ;; At this point, the buffer containing the menu exists and is
6401 ;; visible in the current window. So, refresh it.
6402 (with-current-buffer "*Org Export Dispatcher*"
6403 ;; Refresh help. Maintain display continuity by re-visiting
6404 ;; previous window position.
6405 (let ((pos (window-start)))
6406 (erase-buffer)
6407 (insert help)
6408 (set-window-start nil pos)))
6409 (org-fit-window-to-buffer)
6410 (org-export--dispatch-action
6411 standard-prompt allowed-keys entries options first-key expertp))))
6413 (defun org-export--dispatch-action
6414 (prompt allowed-keys entries options first-key expertp)
6415 "Read a character from command input and act accordingly.
6417 PROMPT is the displayed prompt, as a string. ALLOWED-KEYS is
6418 a list of characters available at a given step in the process.
6419 ENTRIES is a list of menu entries. OPTIONS, FIRST-KEY and
6420 EXPERTP are the same as defined in `org-export--dispatch-ui',
6421 which see.
6423 Toggle export options when required. Otherwise, return value is
6424 a list with action as CAR and a list of interactive export
6425 options as CDR."
6426 (let (key)
6427 ;; Scrolling: when in non-expert mode, act on motion keys (C-n,
6428 ;; C-p, SPC, DEL).
6429 (while (and (setq key (read-char-exclusive prompt))
6430 (not expertp)
6431 (memq key '(14 16 ?\s ?\d)))
6432 (cl-case key
6433 (14 (if (not (pos-visible-in-window-p (point-max)))
6434 (ignore-errors (scroll-up 1))
6435 (message "End of buffer")
6436 (sit-for 1)))
6437 (16 (if (not (pos-visible-in-window-p (point-min)))
6438 (ignore-errors (scroll-down 1))
6439 (message "Beginning of buffer")
6440 (sit-for 1)))
6441 (?\s (if (not (pos-visible-in-window-p (point-max)))
6442 (scroll-up nil)
6443 (message "End of buffer")
6444 (sit-for 1)))
6445 (?\d (if (not (pos-visible-in-window-p (point-min)))
6446 (scroll-down nil)
6447 (message "Beginning of buffer")
6448 (sit-for 1)))))
6449 (cond
6450 ;; Ignore undefined associations.
6451 ((not (memq key allowed-keys))
6452 (ding)
6453 (unless expertp (message "Invalid key") (sit-for 1))
6454 (org-export--dispatch-ui options first-key expertp))
6455 ;; q key at first level aborts export. At second level, cancel
6456 ;; first key instead.
6457 ((eq key ?q) (if (not first-key) (error "Export aborted")
6458 (org-export--dispatch-ui options nil expertp)))
6459 ;; Help key: Switch back to standard interface if expert UI was
6460 ;; active.
6461 ((eq key ??) (org-export--dispatch-ui options first-key nil))
6462 ;; Send request for template insertion along with export scope.
6463 ((eq key ?#) (cons 'template (memq 'subtree options)))
6464 ;; Switch to asynchronous export stack.
6465 ((eq key ?&) '(stack))
6466 ;; Toggle options: C-b (2) C-v (22) C-s (19) C-f (6) C-a (1).
6467 ((memq key '(2 22 19 6 1))
6468 (org-export--dispatch-ui
6469 (let ((option (cl-case key (2 'body) (22 'visible) (19 'subtree)
6470 (6 'force) (1 'async))))
6471 (if (memq option options) (remq option options)
6472 (cons option options)))
6473 first-key expertp))
6474 ;; Action selected: Send key and options back to
6475 ;; `org-export-dispatch'.
6476 ((or first-key (functionp (nth 2 (assq key entries))))
6477 (cons (cond
6478 ((not first-key) (nth 2 (assq key entries)))
6479 ;; Publishing actions are hard-coded. Send a special
6480 ;; signal to `org-export-dispatch'.
6481 ((eq first-key ?P)
6482 (cl-case key
6483 (?f 'publish-current-file)
6484 (?p 'publish-current-project)
6485 (?x 'publish-choose-project)
6486 (?a 'publish-all)))
6487 ;; Return first action associated to FIRST-KEY + KEY
6488 ;; path. Indeed, derived backends can share the same
6489 ;; FIRST-KEY.
6490 (t (catch 'found
6491 (dolist (entry (member (assq first-key entries) entries))
6492 (let ((match (assq key (nth 2 entry))))
6493 (when match (throw 'found (nth 2 match))))))))
6494 options))
6495 ;; Otherwise, enter sub-menu.
6496 (t (org-export--dispatch-ui options key expertp)))))
6500 (provide 'ox)
6502 ;; Local variables:
6503 ;; generated-autoload-file: "org-loaddefs.el"
6504 ;; End:
6506 ;;; ox.el ends here