1 ;;; ox.el --- Export Framework for Org Mode -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This library implements a generic export engine for Org, built on
26 ;; its syntactical parser: Org Elements.
28 ;; Besides that parser, the generic exporter is made of three distinct
31 ;; - The communication channel consists of a property list, which is
32 ;; created and updated during the process. Its use is to offer
33 ;; every piece of information, would it be about initial environment
34 ;; or contextual data, all in a single place.
36 ;; - The transcoder walks the parse tree, ignores or treat as plain
37 ;; text elements and objects according to export options, and
38 ;; eventually calls back-end specific functions to do the real
39 ;; transcoding, concatenating their return value along the way.
41 ;; - The filter system is activated at the very beginning and the very
42 ;; end of the export process, and each time an element or an object
43 ;; has been converted. It is the entry point to fine-tune standard
44 ;; output from back-end transcoders. See "The Filter System"
45 ;; section for more information.
47 ;; The core functions is `org-export-as'. It returns the transcoded
48 ;; buffer as a string. Its derivatives are `org-export-to-buffer' and
49 ;; `org-export-to-file'.
51 ;; An export back-end is defined with `org-export-define-backend'.
52 ;; This function can also support specific buffer keywords, OPTION
53 ;; keyword's items and filters. Refer to function's documentation for
56 ;; If the new back-end shares most properties with another one,
57 ;; `org-export-define-derived-backend' can be used to simplify the
60 ;; Any back-end can define its own variables. Among them, those
61 ;; customizable should belong to the `org-export-BACKEND' group.
63 ;; Tools for common tasks across back-ends are implemented in the
64 ;; following part of the file.
66 ;; Eventually, a dispatcher (`org-export-dispatch') is provided in the
69 ;; See <http://orgmode.org/worg/dev/org-export-reference.html> for
76 (require 'org-element
)
78 (require 'tabulated-list
)
80 (declare-function org-src-coderef-format
"org-src" (&optional element
))
81 (declare-function org-src-coderef-regexp
"org-src" (fmt &optional label
))
82 (declare-function org-publish
"ox-publish" (project &optional force async
))
83 (declare-function org-publish-all
"ox-publish" (&optional force async
))
84 (declare-function org-publish-current-file
"ox-publish" (&optional force async
))
85 (declare-function org-publish-current-project
"ox-publish" (&optional force async
))
87 (defvar org-publish-project-alist
)
88 (defvar org-table-number-fraction
)
89 (defvar org-table-number-regexp
)
92 ;;; Internal Variables
94 ;; Among internal variables, the most important is
95 ;; `org-export-options-alist'. This variable define the global export
96 ;; options, shared between every exporter, and how they are acquired.
98 (defconst org-export-max-depth
19
99 "Maximum nesting depth for headlines, counting from 0.")
101 (defconst org-export-options-alist
102 '((:title
"TITLE" nil nil parse
)
103 (:date
"DATE" nil nil parse
)
104 (:author
"AUTHOR" nil user-full-name parse
)
105 (:email
"EMAIL" nil user-mail-address t
)
106 (:language
"LANGUAGE" nil org-export-default-language t
)
107 (:select-tags
"SELECT_TAGS" nil org-export-select-tags split
)
108 (:exclude-tags
"EXCLUDE_TAGS" nil org-export-exclude-tags split
)
109 (:creator
"CREATOR" nil org-export-creator-string
)
110 (:headline-levels nil
"H" org-export-headline-levels
)
111 (:preserve-breaks nil
"\\n" org-export-preserve-breaks
)
112 (:section-numbers nil
"num" org-export-with-section-numbers
)
113 (:time-stamp-file nil
"timestamp" org-export-time-stamp-file
)
114 (:with-archived-trees nil
"arch" org-export-with-archived-trees
)
115 (:with-author nil
"author" org-export-with-author
)
116 (:with-broken-links nil
"broken-links" org-export-with-broken-links
)
117 (:with-clocks nil
"c" org-export-with-clocks
)
118 (:with-creator nil
"creator" org-export-with-creator
)
119 (:with-date nil
"date" org-export-with-date
)
120 (:with-drawers nil
"d" org-export-with-drawers
)
121 (:with-email nil
"email" org-export-with-email
)
122 (:with-emphasize nil
"*" org-export-with-emphasize
)
123 (:with-entities nil
"e" org-export-with-entities
)
124 (:with-fixed-width nil
":" org-export-with-fixed-width
)
125 (:with-footnotes nil
"f" org-export-with-footnotes
)
126 (:with-inlinetasks nil
"inline" org-export-with-inlinetasks
)
127 (:with-latex nil
"tex" org-export-with-latex
)
128 (:with-planning nil
"p" org-export-with-planning
)
129 (:with-priority nil
"pri" org-export-with-priority
)
130 (:with-properties nil
"prop" org-export-with-properties
)
131 (:with-smart-quotes nil
"'" org-export-with-smart-quotes
)
132 (:with-special-strings nil
"-" org-export-with-special-strings
)
133 (:with-statistics-cookies nil
"stat" org-export-with-statistics-cookies
)
134 (:with-sub-superscript nil
"^" org-export-with-sub-superscripts
)
135 (:with-toc nil
"toc" org-export-with-toc
)
136 (:with-tables nil
"|" org-export-with-tables
)
137 (:with-tags nil
"tags" org-export-with-tags
)
138 (:with-tasks nil
"tasks" org-export-with-tasks
)
139 (:with-timestamps nil
"<" org-export-with-timestamps
)
140 (:with-title nil
"title" org-export-with-title
)
141 (:with-todo-keywords nil
"todo" org-export-with-todo-keywords
))
142 "Alist between export properties and ways to set them.
144 The key of the alist is the property name, and the value is a list
145 like (KEYWORD OPTION DEFAULT BEHAVIOR) where:
147 KEYWORD is a string representing a buffer keyword, or nil. Each
148 property defined this way can also be set, during subtree
149 export, through a headline property named after the keyword
150 with the \"EXPORT_\" prefix (i.e. DATE keyword and EXPORT_DATE
152 OPTION is a string that could be found in an #+OPTIONS: line.
153 DEFAULT is the default value for the property.
154 BEHAVIOR determines how Org should handle multiple keywords for
155 the same property. It is a symbol among:
156 nil Keep old value and discard the new one.
157 t Replace old value with the new one.
158 `space' Concatenate the values, separating them with a space.
159 `newline' Concatenate the values, separating them with
161 `split' Split values at white spaces, and cons them to the
163 `parse' Parse value as a list of strings and Org objects,
164 which can then be transcoded with, e.g.,
165 `org-export-data'. It implies `space' behavior.
167 Values set through KEYWORD and OPTION have precedence over
170 All these properties should be back-end agnostic. Back-end
171 specific properties are set through `org-export-define-backend'.
172 Properties redefined there have precedence over these.")
174 (defconst org-export-special-keywords
'("FILETAGS" "SETUPFILE" "OPTIONS")
175 "List of in-buffer keywords that require special treatment.
176 These keywords are not directly associated to a property. The
177 way they are handled must be hard-coded into
178 `org-export--get-inbuffer-options' function.")
180 (defconst org-export-filters-alist
181 '((:filter-body . org-export-filter-body-functions
)
182 (:filter-bold . org-export-filter-bold-functions
)
183 (:filter-babel-call . org-export-filter-babel-call-functions
)
184 (:filter-center-block . org-export-filter-center-block-functions
)
185 (:filter-clock . org-export-filter-clock-functions
)
186 (:filter-code . org-export-filter-code-functions
)
187 (:filter-diary-sexp . org-export-filter-diary-sexp-functions
)
188 (:filter-drawer . org-export-filter-drawer-functions
)
189 (:filter-dynamic-block . org-export-filter-dynamic-block-functions
)
190 (:filter-entity . org-export-filter-entity-functions
)
191 (:filter-example-block . org-export-filter-example-block-functions
)
192 (:filter-export-block . org-export-filter-export-block-functions
)
193 (:filter-export-snippet . org-export-filter-export-snippet-functions
)
194 (:filter-final-output . org-export-filter-final-output-functions
)
195 (:filter-fixed-width . org-export-filter-fixed-width-functions
)
196 (:filter-footnote-definition . org-export-filter-footnote-definition-functions
)
197 (:filter-footnote-reference . org-export-filter-footnote-reference-functions
)
198 (:filter-headline . org-export-filter-headline-functions
)
199 (:filter-horizontal-rule . org-export-filter-horizontal-rule-functions
)
200 (:filter-inline-babel-call . org-export-filter-inline-babel-call-functions
)
201 (:filter-inline-src-block . org-export-filter-inline-src-block-functions
)
202 (:filter-inlinetask . org-export-filter-inlinetask-functions
)
203 (:filter-italic . org-export-filter-italic-functions
)
204 (:filter-item . org-export-filter-item-functions
)
205 (:filter-keyword . org-export-filter-keyword-functions
)
206 (:filter-latex-environment . org-export-filter-latex-environment-functions
)
207 (:filter-latex-fragment . org-export-filter-latex-fragment-functions
)
208 (:filter-line-break . org-export-filter-line-break-functions
)
209 (:filter-link . org-export-filter-link-functions
)
210 (:filter-node-property . org-export-filter-node-property-functions
)
211 (:filter-options . org-export-filter-options-functions
)
212 (:filter-paragraph . org-export-filter-paragraph-functions
)
213 (:filter-parse-tree . org-export-filter-parse-tree-functions
)
214 (:filter-plain-list . org-export-filter-plain-list-functions
)
215 (:filter-plain-text . org-export-filter-plain-text-functions
)
216 (:filter-planning . org-export-filter-planning-functions
)
217 (:filter-property-drawer . org-export-filter-property-drawer-functions
)
218 (:filter-quote-block . org-export-filter-quote-block-functions
)
219 (:filter-radio-target . org-export-filter-radio-target-functions
)
220 (:filter-section . org-export-filter-section-functions
)
221 (:filter-special-block . org-export-filter-special-block-functions
)
222 (:filter-src-block . org-export-filter-src-block-functions
)
223 (:filter-statistics-cookie . org-export-filter-statistics-cookie-functions
)
224 (:filter-strike-through . org-export-filter-strike-through-functions
)
225 (:filter-subscript . org-export-filter-subscript-functions
)
226 (:filter-superscript . org-export-filter-superscript-functions
)
227 (:filter-table . org-export-filter-table-functions
)
228 (:filter-table-cell . org-export-filter-table-cell-functions
)
229 (:filter-table-row . org-export-filter-table-row-functions
)
230 (:filter-target . org-export-filter-target-functions
)
231 (:filter-timestamp . org-export-filter-timestamp-functions
)
232 (:filter-underline . org-export-filter-underline-functions
)
233 (:filter-verbatim . org-export-filter-verbatim-functions
)
234 (:filter-verse-block . org-export-filter-verse-block-functions
))
235 "Alist between filters properties and initial values.
237 The key of each association is a property name accessible through
238 the communication channel. Its value is a configurable global
239 variable defining initial filters.
241 This list is meant to install user specified filters. Back-end
242 developers may install their own filters using
243 `org-export-define-backend'. Filters defined there will always
244 be prepended to the current list, so they always get applied
247 (defconst org-export-default-inline-image-rule
251 '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
252 "xpm" "pbm" "pgm" "ppm") t
))))
253 "Default rule for link matching an inline image.
254 This rule applies to links with no description. By default, it
255 will be considered as an inline image if it targets a local file
256 whose extension is either \"png\", \"jpeg\", \"jpg\", \"gif\",
257 \"tiff\", \"tif\", \"xbm\", \"xpm\", \"pbm\", \"pgm\" or \"ppm\".
258 See `org-export-inline-image-p' for more information about
261 (defconst org-export-ignored-local-variables
262 '(org-font-lock-keywords
263 org-element--cache org-element--cache-objects org-element--cache-sync-keys
264 org-element--cache-sync-requests org-element--cache-sync-timer
)
265 "List of variables not copied through upon buffer duplication.
266 Export process takes place on a copy of the original buffer.
267 When this copy is created, all Org related local variables not in
268 this list are copied to the new buffer. Variables with an
269 unreadable value are also ignored.")
271 (defvar org-export-async-debug nil
272 "Non-nil means asynchronous export process should leave data behind.
274 This data is found in the appropriate \"*Org Export Process*\"
275 buffer, and in files prefixed with \"org-export-process\" and
276 located in `temporary-file-directory'.
278 When non-nil, it will also set `debug-on-error' to a non-nil
279 value in the external process.")
281 (defvar org-export-stack-contents nil
282 "Record asynchronously generated export results and processes.
283 This is an alist: its CAR is the source of the
284 result (destination file or buffer for a finished process,
285 original buffer for a running one) and its CDR is a list
286 containing the back-end used, as a symbol, and either a process
287 or the time at which it finished. It is used to build the menu
288 from `org-export-stack'.")
290 (defvar org-export-registered-backends nil
291 "List of backends currently available in the exporter.
292 This variable is set with `org-export-define-backend' and
293 `org-export-define-derived-backend' functions.")
295 (defvar org-export-dispatch-last-action nil
296 "Last command called from the dispatcher.
297 The value should be a list. Its CAR is the action, as a symbol,
298 and its CDR is a list of export options.")
300 (defvar org-export-dispatch-last-position
(make-marker)
301 "The position where the last export command was created using the dispatcher.
302 This marker will be used with `C-u C-c C-e' to make sure export repetition
303 uses the same subtree if the previous command was restricted to a subtree.")
305 ;; For compatibility with Org < 8
306 (defvar org-export-current-backend nil
307 "Name, if any, of the back-end used during an export process.
309 Its value is a symbol such as `html', `latex', `ascii', or nil if
310 the back-end is anonymous (see `org-export-create-backend') or if
311 there is no export process in progress.
313 It can be used to teach Babel blocks how to act differently
314 according to the back-end used.")
318 ;;; User-configurable Variables
320 ;; Configuration for the masses.
322 ;; They should never be accessed directly, as their value is to be
323 ;; stored in a property list (cf. `org-export-options-alist').
324 ;; Back-ends will read their value from there instead.
326 (defgroup org-export nil
327 "Options for exporting Org mode files."
331 (defgroup org-export-general nil
332 "General options for export engine."
333 :tag
"Org Export General"
336 (defcustom org-export-with-archived-trees
'headline
337 "Whether sub-trees with the ARCHIVE tag should be exported.
339 This can have three different values:
340 nil Do not export, pretend this tree is not present.
341 t Do export the entire tree.
342 `headline' Only export the headline, but skip the tree below it.
344 This option can also be set with the OPTIONS keyword,
346 :group
'org-export-general
348 (const :tag
"Not at all" nil
)
349 (const :tag
"Headline only" headline
)
350 (const :tag
"Entirely" t
))
351 :safe
(lambda (x) (memq x
'(t nil headline
))))
353 (defcustom org-export-with-author t
354 "Non-nil means insert author name into the exported file.
355 This option can also be set with the OPTIONS keyword,
356 e.g. \"author:nil\"."
357 :group
'org-export-general
361 (defcustom org-export-with-clocks nil
362 "Non-nil means export CLOCK keywords.
363 This option can also be set with the OPTIONS keyword,
365 :group
'org-export-general
369 (defcustom org-export-with-creator nil
370 "Non-nil means the postamble should contain a creator sentence.
372 The sentence can be set in `org-export-creator-string', which
375 This option can also be set with the OPTIONS keyword, e.g.,
377 :group
'org-export-general
379 :package-version
'(Org .
"8.3")
383 (defcustom org-export-with-date t
384 "Non-nil means insert date in the exported document.
385 This option can also be set with the OPTIONS keyword,
387 :group
'org-export-general
391 (defcustom org-export-date-timestamp-format nil
392 "Time-stamp format string to use for DATE keyword.
394 The format string, when specified, only applies if date consists
395 in a single time-stamp. Otherwise its value will be ignored.
397 See `format-time-string' for details on how to build this
399 :group
'org-export-general
401 (string :tag
"Time-stamp format string")
402 (const :tag
"No format string" nil
))
403 :safe
(lambda (x) (or (null x
) (stringp x
))))
405 (defcustom org-export-creator-string
406 (format "Emacs %s (Org mode %s)"
408 (if (fboundp 'org-version
) (org-version) "unknown version"))
409 "Information about the creator of the document.
410 This option can also be set on with the CREATOR keyword."
411 :group
'org-export-general
412 :type
'(string :tag
"Creator string")
415 (defcustom org-export-with-drawers
'(not "LOGBOOK")
416 "Non-nil means export contents of standard drawers.
418 When t, all drawers are exported. This may also be a list of
419 drawer names to export, as strings. If that list starts with
420 `not', only drawers with such names will be ignored.
422 This variable doesn't apply to properties drawers. See
423 `org-export-with-properties' instead.
425 This option can also be set with the OPTIONS keyword,
427 :group
'org-export-general
429 :package-version
'(Org .
"8.0")
431 (const :tag
"All drawers" t
)
432 (const :tag
"None" nil
)
433 (repeat :tag
"Selected drawers"
434 (string :tag
"Drawer name"))
435 (list :tag
"Ignored drawers"
436 (const :format
"" not
)
437 (repeat :tag
"Specify names of drawers to ignore during export"
439 (string :tag
"Drawer name"))))
440 :safe
(lambda (x) (or (booleanp x
) (consp x
))))
442 (defcustom org-export-with-email nil
443 "Non-nil means insert author email into the exported file.
444 This option can also be set with the OPTIONS keyword,
446 :group
'org-export-general
450 (defcustom org-export-with-emphasize t
451 "Non-nil means interpret *word*, /word/, _word_ and +word+.
453 If the export target supports emphasizing text, the word will be
454 typeset in bold, italic, with an underline or strike-through,
457 This option can also be set with the OPTIONS keyword,
459 :group
'org-export-general
463 (defcustom org-export-exclude-tags
'("noexport")
464 "Tags that exclude a tree from export.
466 All trees carrying any of these tags will be excluded from
467 export. This is without condition, so even subtrees inside that
468 carry one of the `org-export-select-tags' will be removed.
470 This option can also be set with the EXCLUDE_TAGS keyword."
471 :group
'org-export-general
472 :type
'(repeat (string :tag
"Tag"))
473 :safe
(lambda (x) (and (listp x
) (cl-every #'stringp x
))))
475 (defcustom org-export-with-fixed-width t
476 "Non-nil means export lines starting with \":\".
477 This option can also be set with the OPTIONS keyword,
479 :group
'org-export-general
481 :package-version
'(Org .
"8.0")
485 (defcustom org-export-with-footnotes t
486 "Non-nil means Org footnotes should be exported.
487 This option can also be set with the OPTIONS keyword,
489 :group
'org-export-general
493 (defcustom org-export-with-latex t
494 "Non-nil means process LaTeX environments and fragments.
496 This option can also be set with the OPTIONS line,
497 e.g. \"tex:verbatim\". Allowed values are:
499 nil Ignore math snippets.
500 `verbatim' Keep everything in verbatim.
501 t Allow export of math snippets."
502 :group
'org-export-general
504 :package-version
'(Org .
"8.0")
506 (const :tag
"Do not process math in any way" nil
)
507 (const :tag
"Interpret math snippets" t
)
508 (const :tag
"Leave math verbatim" verbatim
))
509 :safe
(lambda (x) (memq x
'(t nil verbatim
))))
511 (defcustom org-export-headline-levels
3
512 "The last level which is still exported as a headline.
514 Inferior levels will usually produce itemize or enumerate lists
515 when exported, but back-end behavior may differ.
517 This option can also be set with the OPTIONS keyword,
519 :group
'org-export-general
523 (defcustom org-export-default-language
"en"
524 "The default language for export and clocktable translations, as a string.
525 This may have an association in
526 `org-clock-clocktable-language-setup',
527 `org-export-smart-quotes-alist' and `org-export-dictionary'.
528 This option can also be set with the LANGUAGE keyword."
529 :group
'org-export-general
530 :type
'(string :tag
"Language")
533 (defcustom org-export-preserve-breaks nil
534 "Non-nil means preserve all line breaks when exporting.
535 This option can also be set with the OPTIONS keyword,
537 :group
'org-export-general
541 (defcustom org-export-with-entities t
542 "Non-nil means interpret entities when exporting.
544 For example, HTML export converts \\alpha to α and \\AA to
547 For a list of supported names, see the constant `org-entities'
548 and the user option `org-entities-user'.
550 This option can also be set with the OPTIONS keyword,
552 :group
'org-export-general
556 (defcustom org-export-with-inlinetasks t
557 "Non-nil means inlinetasks should be exported.
558 This option can also be set with the OPTIONS keyword,
559 e.g. \"inline:nil\"."
560 :group
'org-export-general
562 :package-version
'(Org .
"8.0")
566 (defcustom org-export-with-planning nil
567 "Non-nil means include planning info in export.
569 Planning info is the line containing either SCHEDULED:,
570 DEADLINE:, CLOSED: time-stamps, or a combination of them.
572 This option can also be set with the OPTIONS keyword,
574 :group
'org-export-general
576 :package-version
'(Org .
"8.0")
580 (defcustom org-export-with-priority nil
581 "Non-nil means include priority cookies in export.
582 This option can also be set with the OPTIONS keyword,
584 :group
'org-export-general
588 (defcustom org-export-with-properties nil
589 "Non-nil means export contents of properties drawers.
591 When t, all properties are exported. This may also be a list of
592 properties to export, as strings.
594 This option can also be set with the OPTIONS keyword,
596 :group
'org-export-general
598 :package-version
'(Org .
"8.3")
600 (const :tag
"All properties" t
)
601 (const :tag
"None" nil
)
602 (repeat :tag
"Selected properties"
603 (string :tag
"Property name")))
604 :safe
(lambda (x) (or (booleanp x
)
605 (and (listp x
) (cl-every #'stringp x
)))))
607 (defcustom org-export-with-section-numbers t
608 "Non-nil means add section numbers to headlines when exporting.
610 When set to an integer n, numbering will only happen for
611 headlines whose relative level is higher or equal to n.
613 This option can also be set with the OPTIONS keyword,
615 :group
'org-export-general
619 (defcustom org-export-select-tags
'("export")
620 "Tags that select a tree for export.
622 If any such tag is found in a buffer, all trees that do not carry
623 one of these tags will be ignored during export. Inside trees
624 that are selected like this, you can still deselect a subtree by
625 tagging it with one of the `org-export-exclude-tags'.
627 This option can also be set with the SELECT_TAGS keyword."
628 :group
'org-export-general
629 :type
'(repeat (string :tag
"Tag"))
630 :safe
(lambda (x) (and (listp x
) (cl-every #'stringp x
))))
632 (defcustom org-export-with-smart-quotes nil
633 "Non-nil means activate smart quotes during export.
634 This option can also be set with the OPTIONS keyword,
637 When setting this to non-nil, you need to take care of
638 using the correct Babel package when exporting to LaTeX.
639 E.g., you can load Babel for french like this:
641 #+LATEX_HEADER: \\usepackage[french]{babel}"
642 :group
'org-export-general
644 :package-version
'(Org .
"8.0")
648 (defcustom org-export-with-special-strings t
649 "Non-nil means interpret \"\\-\", \"--\" and \"---\" for export.
651 When this option is turned on, these strings will be exported as:
654 -----+----------+--------+-------
658 ... … \\ldots …
660 This option can also be set with the OPTIONS keyword,
662 :group
'org-export-general
666 (defcustom org-export-with-statistics-cookies t
667 "Non-nil means include statistics cookies in export.
668 This option can also be set with the OPTIONS keyword,
670 :group
'org-export-general
672 :package-version
'(Org .
"8.0")
676 (defcustom org-export-with-sub-superscripts t
677 "Non-nil means interpret \"_\" and \"^\" for export.
679 If you want to control how Org displays those characters, see
680 `org-use-sub-superscripts'. `org-export-with-sub-superscripts'
681 used to be an alias for `org-use-sub-superscripts' in Org <8.0,
684 When this option is turned on, you can use TeX-like syntax for
685 sub- and superscripts and see them exported correctly.
687 You can also set the option with #+OPTIONS: ^:t
689 Several characters after \"_\" or \"^\" will be considered as a
690 single item - so grouping with {} is normally not needed. For
691 example, the following things will be parsed as single sub- or
694 10^24 or 10^tau several digits will be considered 1 item.
695 10^-12 or 10^-tau a leading sign with digits or a word
696 x^2-y^3 will be read as x^2 - y^3, because items are
697 terminated by almost any nonword/nondigit char.
698 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
700 Still, ambiguity is possible. So when in doubt, use {} to enclose
701 the sub/superscript. If you set this variable to the symbol `{}',
702 the braces are *required* in order to trigger interpretations as
703 sub/superscript. This can be helpful in documents that need \"_\"
704 frequently in plain text."
705 :group
'org-export-general
707 :package-version
'(Org .
"8.0")
709 (const :tag
"Interpret them" t
)
710 (const :tag
"Curly brackets only" {})
711 (const :tag
"Do not interpret them" nil
))
712 :safe
(lambda (x) (memq x
'(t nil
{}))))
714 (defcustom org-export-with-toc t
715 "Non-nil means create a table of contents in exported files.
717 The TOC contains headlines with levels up
718 to`org-export-headline-levels'. When an integer, include levels
719 up to N in the toc, this may then be different from
720 `org-export-headline-levels', but it will not be allowed to be
721 larger than the number of headline levels. When nil, no table of
724 This option can also be set with the OPTIONS keyword,
725 e.g. \"toc:nil\" or \"toc:3\"."
726 :group
'org-export-general
728 (const :tag
"No Table of Contents" nil
)
729 (const :tag
"Full Table of Contents" t
)
730 (integer :tag
"TOC to level"))
731 :safe
(lambda (x) (or (booleanp x
)
734 (defcustom org-export-with-tables t
735 "Non-nil means export tables.
736 This option can also be set with the OPTIONS keyword,
738 :group
'org-export-general
740 :package-version
'(Org .
"8.0")
744 (defcustom org-export-with-tags t
745 "If nil, do not export tags, just remove them from headlines.
747 If this is the symbol `not-in-toc', tags will be removed from
748 table of contents entries, but still be shown in the headlines of
751 This option can also be set with the OPTIONS keyword,
753 :group
'org-export-general
755 (const :tag
"Off" nil
)
756 (const :tag
"Not in TOC" not-in-toc
)
758 :safe
(lambda (x) (memq x
'(t nil not-in-toc
))))
760 (defcustom org-export-with-tasks t
761 "Non-nil means include TODO items for export.
763 This may have the following values:
764 t include tasks independent of state.
765 `todo' include only tasks that are not yet done.
766 `done' include only tasks that are already done.
767 nil ignore all tasks.
768 list of keywords include tasks with these keywords.
770 This option can also be set with the OPTIONS keyword,
772 :group
'org-export-general
774 (const :tag
"All tasks" t
)
775 (const :tag
"No tasks" nil
)
776 (const :tag
"Not-done tasks" todo
)
777 (const :tag
"Only done tasks" done
)
778 (repeat :tag
"Specific TODO keywords"
779 (string :tag
"Keyword")))
780 :safe
(lambda (x) (or (memq x
'(nil t todo done
))
782 (cl-every #'stringp x
)))))
784 (defcustom org-export-with-title t
785 "Non-nil means print title into the exported file.
786 This option can also be set with the OPTIONS keyword,
788 :group
'org-export-general
790 :package-version
'(Org .
"8.3")
794 (defcustom org-export-time-stamp-file t
795 "Non-nil means insert a time stamp into the exported file.
796 The time stamp shows when the file was created. This option can
797 also be set with the OPTIONS keyword, e.g. \"timestamp:nil\"."
798 :group
'org-export-general
802 (defcustom org-export-with-timestamps t
803 "Non nil means allow timestamps in export.
805 It can be set to any of the following values:
806 t export all timestamps.
807 `active' export active timestamps only.
808 `inactive' export inactive timestamps only.
809 nil do not export timestamps
811 This only applies to timestamps isolated in a paragraph
812 containing only timestamps. Other timestamps are always
815 This option can also be set with the OPTIONS keyword, e.g.
817 :group
'org-export-general
819 (const :tag
"All timestamps" t
)
820 (const :tag
"Only active timestamps" active
)
821 (const :tag
"Only inactive timestamps" inactive
)
822 (const :tag
"No timestamp" nil
))
823 :safe
(lambda (x) (memq x
'(t nil active inactive
))))
825 (defcustom org-export-with-todo-keywords t
826 "Non-nil means include TODO keywords in export.
827 When nil, remove all these keywords from the export. This option
828 can also be set with the OPTIONS keyword, e.g. \"todo:nil\"."
829 :group
'org-export-general
832 (defcustom org-export-allow-bind-keywords nil
833 "Non-nil means BIND keywords can define local variable values.
834 This is a potential security risk, which is why the default value
835 is nil. You can also allow them through local buffer variables."
836 :group
'org-export-general
838 :package-version
'(Org .
"8.0")
841 (defcustom org-export-with-broken-links nil
842 "Non-nil means do not raise an error on broken links.
844 When this variable is non-nil, broken links are ignored, without
845 stopping the export process. If it is set to `mark', broken
846 links are marked as such in the output, with a string like
850 where PATH is the un-resolvable reference.
852 This option can also be set with the OPTIONS keyword, e.g.,
853 \"broken-links:mark\"."
854 :group
'org-export-general
856 :package-version
'(Org .
"9.0")
858 (const :tag
"Ignore broken links" t
)
859 (const :tag
"Mark broken links in output" mark
)
860 (const :tag
"Raise an error" nil
)))
862 (defcustom org-export-snippet-translation-alist nil
863 "Alist between export snippets back-ends and exporter back-ends.
865 This variable allows providing shortcuts for export snippets.
867 For example, with a value of \\='((\"h\" . \"html\")), the
868 HTML back-end will recognize the contents of \"@@h:<b>@@\" as
869 HTML code while every other back-end will ignore it."
870 :group
'org-export-general
872 :package-version
'(Org .
"8.0")
874 (cons (string :tag
"Shortcut")
875 (string :tag
"Back-end")))
879 (cl-every #'stringp
(mapcar #'car x
))
880 (cl-every #'stringp
(mapcar #'cdr x
)))))
882 (defcustom org-export-global-macros nil
883 "Alist between macro names and expansion templates.
885 This variable defines macro expansion templates available
886 globally. Associations follow the pattern
890 where NAME is a string beginning with a letter and consisting of
891 alphanumeric characters only.
893 TEMPLATE is the string to which the macro is going to be
894 expanded. Inside, \"$1\", \"$2\"... are place-holders for
895 macro's arguments. Moreover, if the template starts with
896 \"(eval\", it will be parsed as an Elisp expression and evaluated
898 :group
'org-export-general
900 :package-version
'(Org .
"9.1")
902 (cons (string :tag
"Name")
903 (string :tag
"Template"))))
905 (defcustom org-export-coding-system nil
906 "Coding system for the exported file."
907 :group
'org-export-general
909 :package-version
'(Org .
"8.0")
910 :type
'coding-system
)
912 (defcustom org-export-copy-to-kill-ring nil
913 "Non-nil means pushing export output to the kill ring.
914 This variable is ignored during asynchronous export."
915 :group
'org-export-general
917 :package-version
'(Org .
"8.3")
919 (const :tag
"Always" t
)
920 (const :tag
"When export is done interactively" if-interactive
)
921 (const :tag
"Never" nil
)))
923 (defcustom org-export-initial-scope
'buffer
924 "The initial scope when exporting with `org-export-dispatch'.
925 This variable can be either set to `buffer' or `subtree'."
926 :group
'org-export-general
928 (const :tag
"Export current buffer" buffer
)
929 (const :tag
"Export current subtree" subtree
)))
931 (defcustom org-export-show-temporary-export-buffer t
932 "Non-nil means show buffer after exporting to temp buffer.
933 When Org exports to a file, the buffer visiting that file is never
934 shown, but remains buried. However, when exporting to
935 a temporary buffer, that buffer is popped up in a second window.
936 When this variable is nil, the buffer remains buried also in
938 :group
'org-export-general
941 (defcustom org-export-in-background nil
942 "Non-nil means export and publishing commands will run in background.
943 Results from an asynchronous export are never displayed
944 automatically. But you can retrieve them with `\\[org-export-stack]'."
945 :group
'org-export-general
947 :package-version
'(Org .
"8.0")
950 (defcustom org-export-async-init-file nil
951 "File used to initialize external export process.
953 Value must be either nil or an absolute file name. When nil, the
954 external process is launched like a regular Emacs session,
955 loading user's initialization file and any site specific
956 configuration. If a file is provided, it, and only it, is loaded
959 Therefore, using a specific configuration makes the process to
960 load faster and the export more portable."
961 :group
'org-export-general
963 :package-version
'(Org .
"8.0")
965 (const :tag
"Regular startup" nil
)
966 (file :tag
"Specific start-up file" :must-match t
)))
968 (defcustom org-export-dispatch-use-expert-ui nil
969 "Non-nil means using a non-intrusive `org-export-dispatch'.
970 In that case, no help buffer is displayed. Though, an indicator
971 for current export scope is added to the prompt (\"b\" when
972 output is restricted to body only, \"s\" when it is restricted to
973 the current subtree, \"v\" when only visible elements are
974 considered for export, \"f\" when publishing functions should be
975 passed the FORCE argument and \"a\" when the export should be
976 asynchronous). Also, [?] allows switching back to standard
978 :group
'org-export-general
980 :package-version
'(Org .
"8.0")
985 ;;; Defining Back-ends
987 ;; An export back-end is a structure with `org-export-backend' type
988 ;; and `name', `parent', `transcoders', `options', `filters', `blocks'
991 ;; At the lowest level, a back-end is created with
992 ;; `org-export-create-backend' function.
994 ;; A named back-end can be registered with
995 ;; `org-export-register-backend' function. A registered back-end can
996 ;; later be referred to by its name, with `org-export-get-backend'
997 ;; function. Also, such a back-end can become the parent of a derived
998 ;; back-end from which slot values will be inherited by default.
999 ;; `org-export-derived-backend-p' can check if a given back-end is
1000 ;; derived from a list of back-end names.
1002 ;; `org-export-get-all-transcoders', `org-export-get-all-options' and
1003 ;; `org-export-get-all-filters' return the full alist of transcoders,
1004 ;; options and filters, including those inherited from ancestors.
1006 ;; At a higher level, `org-export-define-backend' is the standard way
1007 ;; to define an export back-end. If the new back-end is similar to
1008 ;; a registered back-end, `org-export-define-derived-backend' may be
1011 ;; Eventually `org-export-barf-if-invalid-backend' returns an error
1012 ;; when a given back-end hasn't been registered yet.
1014 (cl-defstruct (org-export-backend (:constructor org-export-create-backend
)
1016 name parent transcoders options filters blocks menu
)
1019 (defun org-export-get-backend (name)
1020 "Return export back-end named after NAME.
1021 NAME is a symbol. Return nil if no such back-end is found."
1022 (cl-find-if (lambda (b) (and (eq name
(org-export-backend-name b
))))
1023 org-export-registered-backends
))
1025 (defun org-export-register-backend (backend)
1026 "Register BACKEND as a known export back-end.
1027 BACKEND is a structure with `org-export-backend' type."
1028 ;; Refuse to register an unnamed back-end.
1029 (unless (org-export-backend-name backend
)
1030 (error "Cannot register a unnamed export back-end"))
1031 ;; Refuse to register a back-end with an unknown parent.
1032 (let ((parent (org-export-backend-parent backend
)))
1033 (when (and parent
(not (org-export-get-backend parent
)))
1034 (error "Cannot use unknown \"%s\" back-end as a parent" parent
)))
1035 ;; If a back-end with the same name as BACKEND is already
1036 ;; registered, replace it with BACKEND. Otherwise, simply add
1037 ;; BACKEND to the list of registered back-ends.
1038 (let ((old (org-export-get-backend (org-export-backend-name backend
))))
1039 (if old
(setcar (memq old org-export-registered-backends
) backend
)
1040 (push backend org-export-registered-backends
))))
1042 (defun org-export-barf-if-invalid-backend (backend)
1043 "Signal an error if BACKEND isn't defined."
1044 (unless (org-export-backend-p backend
)
1045 (error "Unknown \"%s\" back-end: Aborting export" backend
)))
1047 (defun org-export-derived-backend-p (backend &rest backends
)
1048 "Non-nil if BACKEND is derived from one of BACKENDS.
1049 BACKEND is an export back-end, as returned by, e.g.,
1050 `org-export-create-backend', or a symbol referring to
1051 a registered back-end. BACKENDS is constituted of symbols."
1052 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1055 (while (org-export-backend-parent backend
)
1056 (when (memq (org-export-backend-name backend
) backends
)
1059 (org-export-get-backend (org-export-backend-parent backend
))))
1060 (memq (org-export-backend-name backend
) backends
))))
1062 (defun org-export-get-all-transcoders (backend)
1063 "Return full translation table for BACKEND.
1065 BACKEND is an export back-end, as return by, e.g,,
1066 `org-export-create-backend'. Return value is an alist where
1067 keys are element or object types, as symbols, and values are
1070 Unlike to `org-export-backend-transcoders', this function
1071 also returns transcoders inherited from parent back-ends,
1073 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1075 (let ((transcoders (org-export-backend-transcoders backend
))
1077 (while (setq parent
(org-export-backend-parent backend
))
1078 (setq backend
(org-export-get-backend parent
))
1080 (append transcoders
(org-export-backend-transcoders backend
))))
1083 (defun org-export-get-all-options (backend)
1084 "Return export options for BACKEND.
1086 BACKEND is an export back-end, as return by, e.g,,
1087 `org-export-create-backend'. See `org-export-options-alist'
1088 for the shape of the return value.
1090 Unlike to `org-export-backend-options', this function also
1091 returns options inherited from parent back-ends, if any.
1093 Return nil if BACKEND is unknown."
1094 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1096 (let ((options (org-export-backend-options backend
))
1098 (while (setq parent
(org-export-backend-parent backend
))
1099 (setq backend
(org-export-get-backend parent
))
1100 (setq options
(append options
(org-export-backend-options backend
))))
1103 (defun org-export-get-all-filters (backend)
1104 "Return complete list of filters for BACKEND.
1106 BACKEND is an export back-end, as return by, e.g,,
1107 `org-export-create-backend'. Return value is an alist where
1108 keys are symbols and values lists of functions.
1110 Unlike to `org-export-backend-filters', this function also
1111 returns filters inherited from parent back-ends, if any."
1112 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1114 (let ((filters (org-export-backend-filters backend
))
1116 (while (setq parent
(org-export-backend-parent backend
))
1117 (setq backend
(org-export-get-backend parent
))
1118 (setq filters
(append filters
(org-export-backend-filters backend
))))
1121 (defun org-export-define-backend (backend transcoders
&rest body
)
1122 "Define a new back-end BACKEND.
1124 TRANSCODERS is an alist between object or element types and
1125 functions handling them.
1127 These functions should return a string without any trailing
1128 space, or nil. They must accept three arguments: the object or
1129 element itself, its contents or nil when it isn't recursive and
1130 the property list used as a communication channel.
1132 Contents, when not nil, are stripped from any global indentation
1133 \(although the relative one is preserved). They also always end
1134 with a single newline character.
1136 If, for a given type, no function is found, that element or
1137 object type will simply be ignored, along with any blank line or
1138 white space at its end. The same will happen if the function
1139 returns the nil value. If that function returns the empty
1140 string, the type will be ignored, but the blank lines or white
1141 spaces will be kept.
1143 In addition to element and object types, one function can be
1144 associated to the `template' (or `inner-template') symbol and
1145 another one to the `plain-text' symbol.
1147 The former returns the final transcoded string, and can be used
1148 to add a preamble and a postamble to document's body. It must
1149 accept two arguments: the transcoded string and the property list
1150 containing export options. A function associated to `template'
1151 will not be applied if export has option \"body-only\".
1152 A function associated to `inner-template' is always applied.
1154 The latter, when defined, is to be called on every text not
1155 recognized as an element or an object. It must accept two
1156 arguments: the text string and the information channel. It is an
1157 appropriate place to protect special chars relative to the
1160 BODY can start with pre-defined keyword arguments. The following
1161 keywords are understood:
1165 Alist between filters and function, or list of functions,
1166 specific to the back-end. See `org-export-filters-alist' for
1167 a list of all allowed filters. Filters defined here
1168 shouldn't make a back-end test, as it may prevent back-ends
1169 derived from this one to behave properly.
1173 Menu entry for the export dispatcher. It should be a list
1176 \\='(KEY DESCRIPTION-OR-ORDINAL ACTION-OR-MENU)
1180 KEY is a free character selecting the back-end.
1182 DESCRIPTION-OR-ORDINAL is either a string or a number.
1184 If it is a string, is will be used to name the back-end in
1185 its menu entry. If it is a number, the following menu will
1186 be displayed as a sub-menu of the back-end with the same
1187 KEY. Also, the number will be used to determine in which
1188 order such sub-menus will appear (lowest first).
1190 ACTION-OR-MENU is either a function or an alist.
1192 If it is an action, it will be called with four
1193 arguments (booleans): ASYNC, SUBTREEP, VISIBLE-ONLY and
1194 BODY-ONLY. See `org-export-as' for further explanations on
1197 If it is an alist, associations should follow the
1200 \\='(KEY DESCRIPTION ACTION)
1202 where KEY, DESCRIPTION and ACTION are described above.
1204 Valid values include:
1206 \\='(?m \"My Special Back-end\" my-special-export-function)
1210 \\='(?l \"Export to LaTeX\"
1211 (?p \"As PDF file\" org-latex-export-to-pdf)
1212 (?o \"As PDF file and open\"
1214 (if a (org-latex-export-to-pdf t s v b)
1216 (org-latex-export-to-pdf nil s v b)))))))
1218 or the following, which will be added to the previous
1222 ((?B \"As TEX buffer (Beamer)\" org-beamer-export-as-latex)
1223 (?P \"As PDF file (Beamer)\" org-beamer-export-to-pdf)))
1227 Alist between back-end specific properties introduced in
1228 communication channel and how their value are acquired. See
1229 `org-export-options-alist' for more information about
1230 structure of the values."
1231 (declare (indent 1))
1232 (let (filters menu-entry options
)
1233 (while (keywordp (car body
))
1234 (let ((keyword (pop body
)))
1236 (:filters-alist
(setq filters
(pop body
)))
1237 (:menu-entry
(setq menu-entry
(pop body
)))
1238 (:options-alist
(setq options
(pop body
)))
1239 (_ (error "Unknown keyword: %s" keyword
)))))
1240 (org-export-register-backend
1241 (org-export-create-backend :name backend
1242 :transcoders transcoders
1245 :menu menu-entry
))))
1247 (defun org-export-define-derived-backend (child parent
&rest body
)
1248 "Create a new back-end as a variant of an existing one.
1250 CHILD is the name of the derived back-end. PARENT is the name of
1251 the parent back-end.
1253 BODY can start with pre-defined keyword arguments. The following
1254 keywords are understood:
1258 Alist of filters that will overwrite or complete filters
1259 defined in PARENT back-end. See `org-export-filters-alist'
1260 for a list of allowed filters.
1264 Menu entry for the export dispatcher. See
1265 `org-export-define-backend' for more information about the
1270 Alist of back-end specific properties that will overwrite or
1271 complete those defined in PARENT back-end. Refer to
1272 `org-export-options-alist' for more information about
1273 structure of the values.
1277 Alist of element and object types and transcoders that will
1278 overwrite or complete transcode table from PARENT back-end.
1279 Refer to `org-export-define-backend' for detailed information
1282 As an example, here is how one could define \"my-latex\" back-end
1283 as a variant of `latex' back-end with a custom template function:
1285 (org-export-define-derived-backend \\='my-latex \\='latex
1286 :translate-alist \\='((template . my-latex-template-fun)))
1288 The back-end could then be called with, for example:
1290 (org-export-to-buffer \\='my-latex \"*Test my-latex*\")"
1291 (declare (indent 2))
1292 (let (filters menu-entry options transcoders
)
1293 (while (keywordp (car body
))
1294 (let ((keyword (pop body
)))
1296 (:filters-alist
(setq filters
(pop body
)))
1297 (:menu-entry
(setq menu-entry
(pop body
)))
1298 (:options-alist
(setq options
(pop body
)))
1299 (:translate-alist
(setq transcoders
(pop body
)))
1300 (_ (error "Unknown keyword: %s" keyword
)))))
1301 (org-export-register-backend
1302 (org-export-create-backend :name child
1304 :transcoders transcoders
1307 :menu menu-entry
))))
1311 ;;; The Communication Channel
1313 ;; During export process, every function has access to a number of
1314 ;; properties. They are of two types:
1316 ;; 1. Environment options are collected once at the very beginning of
1317 ;; the process, out of the original buffer and configuration.
1318 ;; Collecting them is handled by `org-export-get-environment'
1321 ;; Most environment options are defined through the
1322 ;; `org-export-options-alist' variable.
1324 ;; 2. Tree properties are extracted directly from the parsed tree,
1325 ;; just before export, by `org-export--collect-tree-properties'.
1327 ;;;; Environment Options
1329 ;; Environment options encompass all parameters defined outside the
1330 ;; scope of the parsed data. They come from five sources, in
1331 ;; increasing precedence order:
1333 ;; - Global variables,
1334 ;; - Buffer's attributes,
1335 ;; - Options keyword symbols,
1336 ;; - Buffer keywords,
1337 ;; - Subtree properties.
1339 ;; The central internal function with regards to environment options
1340 ;; is `org-export-get-environment'. It updates global variables with
1341 ;; "#+BIND:" keywords, then retrieve and prioritize properties from
1342 ;; the different sources.
1344 ;; The internal functions doing the retrieval are:
1345 ;; `org-export--get-global-options',
1346 ;; `org-export--get-buffer-attributes',
1347 ;; `org-export--parse-option-keyword',
1348 ;; `org-export--get-subtree-options' and
1349 ;; `org-export--get-inbuffer-options'
1351 ;; Also, `org-export--list-bound-variables' collects bound variables
1352 ;; along with their value in order to set them as buffer local
1353 ;; variables later in the process.
1356 (defun org-export-get-environment (&optional backend subtreep ext-plist
)
1357 "Collect export options from the current buffer.
1359 Optional argument BACKEND is an export back-end, as returned by
1360 `org-export-create-backend'.
1362 When optional argument SUBTREEP is non-nil, assume the export is
1363 done against the current sub-tree.
1365 Third optional argument EXT-PLIST is a property list with
1366 external parameters overriding Org default settings, but still
1367 inferior to file-local settings."
1368 ;; First install #+BIND variables since these must be set before
1369 ;; global options are read.
1370 (dolist (pair (org-export--list-bound-variables))
1371 (set (make-local-variable (car pair
)) (nth 1 pair
)))
1372 ;; Get and prioritize export options...
1374 ;; ... from global variables...
1375 (org-export--get-global-options backend
)
1376 ;; ... from an external property list...
1378 ;; ... from in-buffer settings...
1379 (org-export--get-inbuffer-options backend
)
1380 ;; ... and from subtree, when appropriate.
1381 (and subtreep
(org-export--get-subtree-options backend
))))
1383 (defun org-export--parse-option-keyword (options &optional backend
)
1384 "Parse an OPTIONS line and return values as a plist.
1385 Optional argument BACKEND is an export back-end, as returned by,
1386 e.g., `org-export-create-backend'. It specifies which back-end
1387 specific items to read, if any."
1390 (while (string-match "\\(.+?\\):\\((.*?)\\|\\S-*\\)[ \t]*" options s
)
1391 (setq s
(match-end 0))
1392 (push (cons (match-string 1 options
)
1393 (read (match-string 2 options
)))
1396 ;; Priority is given to back-end specific options.
1397 (all (append (org-export-get-all-options backend
)
1398 org-export-options-alist
))
1401 (dolist (entry all plist
)
1402 (let ((item (nth 2 entry
)))
1404 (let ((v (assoc-string item line t
)))
1405 (when v
(setq plist
(plist-put plist
(car entry
) (cdr v
)))))))))))
1407 (defun org-export--get-subtree-options (&optional backend
)
1408 "Get export options in subtree at point.
1409 Optional argument BACKEND is an export back-end, as returned by,
1410 e.g., `org-export-create-backend'. It specifies back-end used
1411 for export. Return options as a plist."
1412 ;; For each buffer keyword, create a headline property setting the
1413 ;; same property in communication channel. The name for the
1414 ;; property is the keyword with "EXPORT_" appended to it.
1415 (org-with-wide-buffer
1416 ;; Make sure point is at a heading.
1417 (if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t
))
1419 ;; EXPORT_OPTIONS are parsed in a non-standard way. Take
1420 ;; care of them right from the start.
1421 (let ((o (org-entry-get (point) "EXPORT_OPTIONS" 'selective
)))
1422 (and o
(org-export--parse-option-keyword o backend
))))
1423 ;; Take care of EXPORT_TITLE. If it isn't defined, use
1424 ;; headline's title (with no todo keyword, priority cookie or
1425 ;; tag) as its fallback value.
1428 (or (org-entry-get (point) "EXPORT_TITLE" 'selective
)
1429 (let ((case-fold-search nil
))
1430 (looking-at org-complex-heading-regexp
)
1431 (match-string-no-properties 4))))))
1432 ;; Look for both general keywords and back-end specific
1433 ;; options, with priority given to the latter.
1434 (options (append (org-export-get-all-options backend
)
1435 org-export-options-alist
)))
1436 ;; Handle other keywords. Then return PLIST.
1437 (dolist (option options plist
)
1438 (let ((property (car option
))
1439 (keyword (nth 1 option
)))
1442 (or (cdr (assoc keyword cache
))
1443 (let ((v (org-entry-get (point)
1444 (concat "EXPORT_" keyword
)
1446 (push (cons keyword v
) cache
) v
))))
1451 (cl-case (nth 4 option
)
1453 (org-element-parse-secondary-string
1454 value
(org-element-restriction 'keyword
)))
1455 (split (org-split-string value
))
1456 (t value
))))))))))))
1458 (defun org-export--get-inbuffer-options (&optional backend
)
1459 "Return current buffer export options, as a plist.
1461 Optional argument BACKEND, when non-nil, is an export back-end,
1462 as returned by, e.g., `org-export-create-backend'. It specifies
1463 which back-end specific options should also be read in the
1466 Assume buffer is in Org mode. Narrowing, if any, is ignored."
1467 (let* ((case-fold-search t
)
1469 ;; Priority is given to back-end specific options.
1470 (org-export-get-all-options backend
)
1471 org-export-options-alist
))
1472 (regexp (format "^[ \t]*#\\+%s:"
1473 (regexp-opt (nconc (delq nil
(mapcar #'cadr options
))
1474 org-export-special-keywords
))))
1476 (letrec ((find-properties
1478 ;; Return all properties associated to KEYWORD.
1480 (dolist (option options properties
)
1481 (when (equal (nth 1 option
) keyword
)
1482 (cl-pushnew (car option
) properties
))))))
1484 (lambda (&optional files
)
1485 ;; Recursively read keywords in buffer. FILES is
1486 ;; a list of files read so far. PLIST is the current
1487 ;; property list obtained.
1488 (org-with-wide-buffer
1489 (goto-char (point-min))
1490 (while (re-search-forward regexp nil t
)
1491 (let ((element (org-element-at-point)))
1492 (when (eq (org-element-type element
) 'keyword
)
1493 (let ((key (org-element-property :key element
))
1494 (val (org-element-property :value element
)))
1496 ;; Options in `org-export-special-keywords'.
1497 ((equal key
"SETUPFILE")
1498 (let* ((uri (org-unbracket-string "\"" "\"" (org-trim val
)))
1499 (uri-is-url (org-file-url-p uri
))
1502 (expand-file-name uri
))))
1503 ;; Avoid circular dependencies.
1504 (unless (member uri files
)
1507 (setq default-directory
1508 (file-name-directory uri
)))
1509 (insert (org-file-contents uri
'noerror
))
1510 (let ((org-inhibit-startup t
)) (org-mode))
1511 (funcall get-options
(cons uri files
))))))
1512 ((equal key
"OPTIONS")
1516 (org-export--parse-option-keyword
1518 ((equal key
"FILETAGS")
1525 (org-split-string val
":")
1526 (plist-get plist
:filetags
)))))))
1528 ;; Options in `org-export-options-alist'.
1529 (dolist (property (funcall find-properties key
))
1534 ;; Handle value depending on specified
1536 (cl-case (nth 4 (assq property options
))
1538 (unless (memq property to-parse
)
1539 (push property to-parse
))
1540 ;; Even if `parse' implies `space'
1541 ;; behavior, we separate line with
1542 ;; "\n" so as to preserve
1543 ;; line-breaks. However, empty
1544 ;; lines are forbidden since `parse'
1545 ;; doesn't allow more than one
1547 (let ((old (plist-get plist property
)))
1548 (cond ((not (org-string-nw-p val
)) old
)
1549 (old (concat old
"\n" val
))
1552 (if (not (plist-get plist property
))
1554 (concat (plist-get plist property
)
1559 (concat (plist-get plist property
)
1562 (split `(,@(plist-get plist property
)
1563 ,@(org-split-string val
)))
1566 (if (not (plist-member plist property
)) val
1567 (plist-get plist property
)))))))))))))))))
1568 ;; Read options in the current buffer and return value.
1569 (funcall get-options
(and buffer-file-name
(list buffer-file-name
)))
1570 ;; Parse properties in TO-PARSE. Remove newline characters not
1571 ;; involved in line breaks to simulate `space' behavior.
1572 ;; Finally return options.
1573 (dolist (p to-parse plist
)
1574 (let ((value (org-element-parse-secondary-string
1576 (org-element-restriction 'keyword
))))
1577 (org-element-map value
'plain-text
1579 (org-element-set-element
1580 s
(replace-regexp-in-string "\n" " " s
))))
1581 (setq plist
(plist-put plist p value
)))))))
1583 (defun org-export--get-export-attributes
1584 (&optional backend subtreep visible-only body-only
)
1585 "Return properties related to export process, as a plist.
1586 Optional arguments BACKEND, SUBTREEP, VISIBLE-ONLY and BODY-ONLY
1587 are like the arguments with the same names of function
1589 (list :export-options
(delq nil
1590 (list (and subtreep
'subtree
)
1591 (and visible-only
'visible-only
)
1592 (and body-only
'body-only
)))
1594 :translate-alist
(org-export-get-all-transcoders backend
)
1595 :exported-data
(make-hash-table :test
#'eq
:size
4001)))
1597 (defun org-export--get-buffer-attributes ()
1598 "Return properties related to buffer attributes, as a plist."
1599 (list :input-buffer
(buffer-name (buffer-base-buffer))
1600 :input-file
(buffer-file-name (buffer-base-buffer))))
1602 (defun org-export--get-global-options (&optional backend
)
1603 "Return global export options as a plist.
1604 Optional argument BACKEND, if non-nil, is an export back-end, as
1605 returned by, e.g., `org-export-create-backend'. It specifies
1606 which back-end specific export options should also be read in the
1609 ;; Priority is given to back-end specific options.
1610 (all (append (org-export-get-all-options backend
)
1611 org-export-options-alist
)))
1612 (dolist (cell all plist
)
1613 (let ((prop (car cell
)))
1614 (unless (plist-member plist prop
)
1619 ;; Evaluate default value provided.
1620 (let ((value (eval (nth 3 cell
))))
1621 (if (eq (nth 4 cell
) 'parse
)
1622 (org-element-parse-secondary-string
1623 value
(org-element-restriction 'keyword
))
1626 (defun org-export--list-bound-variables ()
1627 "Return variables bound from BIND keywords in current buffer.
1628 Also look for BIND keywords in setup files. The return value is
1629 an alist where associations are (VARIABLE-NAME VALUE)."
1630 (when org-export-allow-bind-keywords
1631 (letrec ((collect-bind
1632 (lambda (files alist
)
1633 ;; Return an alist between variable names and their
1634 ;; value. FILES is a list of setup files names read
1635 ;; so far, used to avoid circular dependencies. ALIST
1636 ;; is the alist collected so far.
1637 (let ((case-fold-search t
))
1638 (org-with-wide-buffer
1639 (goto-char (point-min))
1640 (while (re-search-forward
1641 "^[ \t]*#\\+\\(BIND\\|SETUPFILE\\):" nil t
)
1642 (let ((element (org-element-at-point)))
1643 (when (eq (org-element-type element
) 'keyword
)
1644 (let ((val (org-element-property :value element
)))
1645 (if (equal (org-element-property :key element
)
1647 (push (read (format "(%s)" val
)) alist
)
1648 ;; Enter setup file.
1649 (let* ((uri (org-unbracket-string "\"" "\"" val
))
1650 (uri-is-url (org-file-url-p uri
))
1653 (expand-file-name uri
))))
1654 ;; Avoid circular dependencies.
1655 (unless (member uri files
)
1658 (setq default-directory
1659 (file-name-directory uri
)))
1660 (let ((org-inhibit-startup t
)) (org-mode))
1661 (insert (org-file-contents uri
'noerror
))
1663 (funcall collect-bind
1667 ;; Return value in appropriate order of appearance.
1668 (nreverse (funcall collect-bind nil nil
)))))
1670 ;; defsubst org-export-get-parent must be defined before first use,
1671 ;; was originally defined in the topology section
1673 (defsubst org-export-get-parent
(blob)
1674 "Return BLOB parent or nil.
1675 BLOB is the element or object considered."
1676 (org-element-property :parent blob
))
1678 ;;;; Tree Properties
1680 ;; Tree properties are information extracted from parse tree. They
1681 ;; are initialized at the beginning of the transcoding process by
1682 ;; `org-export--collect-tree-properties'.
1684 ;; Dedicated functions focus on computing the value of specific tree
1685 ;; properties during initialization. Thus,
1686 ;; `org-export--populate-ignore-list' lists elements and objects that
1687 ;; should be skipped during export, `org-export--get-min-level' gets
1688 ;; the minimal exportable level, used as a basis to compute relative
1689 ;; level for headlines. Eventually
1690 ;; `org-export--collect-headline-numbering' builds an alist between
1691 ;; headlines and their numbering.
1693 (defun org-export--collect-tree-properties (data info
)
1694 "Extract tree properties from parse tree.
1696 DATA is the parse tree from which information is retrieved. INFO
1697 is a list holding export options.
1699 Following tree properties are set or updated:
1701 `:headline-offset' Offset between true level of headlines and
1702 local level. An offset of -1 means a headline
1703 of level 2 should be considered as a level
1704 1 headline in the context.
1706 `:headline-numbering' Alist of all headlines as key and the
1707 associated numbering as value.
1709 `:id-alist' Alist of all ID references as key and associated file
1712 Return updated plist."
1713 ;; Install the parse tree in the communication channel.
1714 (setq info
(plist-put info
:parse-tree data
))
1715 ;; Compute `:headline-offset' in order to be able to use
1716 ;; `org-export-get-relative-level'.
1720 (- 1 (org-export--get-min-level data info
))))
1721 ;; From now on, properties order doesn't matter: get the rest of the
1725 (list :headline-numbering
(org-export--collect-headline-numbering data info
)
1727 (org-element-map data
'link
1729 (and (string= (org-element-property :type l
) "id")
1730 (let* ((id (org-element-property :path l
))
1731 (file (car (org-id-find id
))))
1732 (and file
(cons id
(file-relative-name file
))))))))))
1734 (defun org-export--get-min-level (data options
)
1735 "Return minimum exportable headline's level in DATA.
1736 DATA is parsed tree as returned by `org-element-parse-buffer'.
1737 OPTIONS is a plist holding export options."
1739 (let ((min-level 10000))
1740 (dolist (datum (org-element-contents data
))
1741 (when (and (eq (org-element-type datum
) 'headline
)
1742 (not (org-element-property :footnote-section-p datum
))
1743 (not (memq datum
(plist-get options
:ignore-list
))))
1744 (setq min-level
(min (org-element-property :level datum
) min-level
))
1745 (when (= min-level
1) (throw 'exit
1))))
1746 ;; If no headline was found, for the sake of consistency, set
1747 ;; minimum level to 1 nonetheless.
1748 (if (= min-level
10000) 1 min-level
))))
1750 (defun org-export--collect-headline-numbering (data options
)
1751 "Return numbering of all exportable, numbered headlines in a parse tree.
1753 DATA is the parse tree. OPTIONS is the plist holding export
1756 Return an alist whose key is a headline and value is its
1757 associated numbering \(in the shape of a list of numbers) or nil
1758 for a footnotes section."
1759 (let ((numbering (make-vector org-export-max-depth
0)))
1760 (org-element-map data
'headline
1762 (when (and (org-export-numbered-headline-p headline options
)
1763 (not (org-element-property :footnote-section-p headline
)))
1764 (let ((relative-level
1765 (1- (org-export-get-relative-level headline options
))))
1769 for n across numbering
1770 for idx from
0 to org-export-max-depth
1771 when
(< idx relative-level
) collect n
1772 when
(= idx relative-level
) collect
(aset numbering idx
(1+ n
))
1773 when
(> idx relative-level
) do
(aset numbering idx
0))))))
1776 (defun org-export--selected-trees (data info
)
1777 "List headlines and inlinetasks with a select tag in their tree.
1778 DATA is parsed data as returned by `org-element-parse-buffer'.
1779 INFO is a plist holding export options."
1780 (let ((select (plist-get info
:select-tags
)))
1781 (if (cl-some (lambda (tag) (member tag select
)) (plist-get info
:filetags
))
1782 ;; If FILETAGS contains a select tag, every headline or
1783 ;; inlinetask is returned.
1784 (org-element-map data
'(headline inlinetask
) #'identity
)
1785 (letrec ((selected-trees nil
)
1787 (lambda (data genealogy
)
1788 (let ((type (org-element-type data
)))
1790 ((memq type
'(headline inlinetask
))
1791 (let ((tags (org-element-property :tags data
)))
1792 (if (cl-some (lambda (tag) (member tag select
)) tags
)
1793 ;; When a select tag is found, mark full
1794 ;; genealogy and every headline within the
1795 ;; tree as acceptable.
1796 (setq selected-trees
1799 (org-element-map data
'(headline inlinetask
)
1802 ;; If at a headline, continue searching in
1803 ;; tree, recursively.
1804 (when (eq type
'headline
)
1805 (dolist (el (org-element-contents data
))
1806 (funcall walk-data el
(cons data genealogy
)))))))
1807 ((or (eq type
'org-data
)
1808 (memq type org-element-greater-elements
))
1809 (dolist (el (org-element-contents data
))
1810 (funcall walk-data el genealogy
))))))))
1811 (funcall walk-data data nil
)
1814 (defun org-export--skip-p (datum options selected
)
1815 "Non-nil when element or object DATUM should be skipped during export.
1816 OPTIONS is the plist holding export options. SELECTED, when
1817 non-nil, is a list of headlines or inlinetasks belonging to
1818 a tree with a select tag."
1819 (cl-case (org-element-type datum
)
1820 ((comment comment-block
)
1821 ;; Skip all comments and comment blocks. Make to keep maximum
1822 ;; number of blank lines around the comment so as to preserve
1823 ;; local structure of the document upon interpreting it back into
1825 (let* ((previous (org-export-get-previous-element datum options
))
1826 (before (or (org-element-property :post-blank previous
) 0))
1827 (after (or (org-element-property :post-blank datum
) 0)))
1829 (org-element-put-property previous
:post-blank
(max before after
1))))
1831 (clock (not (plist-get options
:with-clocks
)))
1833 (let ((with-drawers-p (plist-get options
:with-drawers
)))
1834 (or (not with-drawers-p
)
1835 (and (consp with-drawers-p
)
1836 ;; If `:with-drawers' value starts with `not', ignore
1837 ;; every drawer whose name belong to that list.
1838 ;; Otherwise, ignore drawers whose name isn't in that
1840 (let ((name (org-element-property :drawer-name datum
)))
1841 (if (eq (car with-drawers-p
) 'not
)
1842 (member-ignore-case name
(cdr with-drawers-p
))
1843 (not (member-ignore-case name with-drawers-p
))))))))
1844 (fixed-width (not (plist-get options
:with-fixed-width
)))
1845 ((footnote-definition footnote-reference
)
1846 (not (plist-get options
:with-footnotes
)))
1847 ((headline inlinetask
)
1848 (let ((with-tasks (plist-get options
:with-tasks
))
1849 (todo (org-element-property :todo-keyword datum
))
1850 (todo-type (org-element-property :todo-type datum
))
1851 (archived (plist-get options
:with-archived-trees
))
1852 (tags (org-export-get-tags datum options nil t
)))
1854 (and (eq (org-element-type datum
) 'inlinetask
)
1855 (not (plist-get options
:with-inlinetasks
)))
1856 ;; Ignore subtrees with an exclude tag.
1857 (cl-loop for k in
(plist-get options
:exclude-tags
)
1858 thereis
(member k tags
))
1859 ;; When a select tag is present in the buffer, ignore any tree
1861 (and selected
(not (memq datum selected
)))
1862 ;; Ignore commented sub-trees.
1863 (org-element-property :commentedp datum
)
1864 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
1865 (and (not archived
) (org-element-property :archivedp datum
))
1866 ;; Ignore tasks, if specified by `:with-tasks' property.
1868 (or (not with-tasks
)
1869 (and (memq with-tasks
'(todo done
))
1870 (not (eq todo-type with-tasks
)))
1871 (and (consp with-tasks
) (not (member todo with-tasks
))))))))
1872 ((latex-environment latex-fragment
) (not (plist-get options
:with-latex
)))
1874 (let ((properties-set (plist-get options
:with-properties
)))
1875 (cond ((null properties-set
) t
)
1876 ((consp properties-set
)
1877 (not (member-ignore-case (org-element-property :key datum
)
1878 properties-set
))))))
1879 (planning (not (plist-get options
:with-planning
)))
1880 (property-drawer (not (plist-get options
:with-properties
)))
1881 (statistics-cookie (not (plist-get options
:with-statistics-cookies
)))
1882 (table (not (plist-get options
:with-tables
)))
1884 (and (org-export-table-has-special-column-p
1885 (org-export-get-parent-table datum
))
1886 (org-export-first-sibling-p datum options
)))
1887 (table-row (org-export-table-row-is-special-p datum options
))
1889 ;; `:with-timestamps' only applies to isolated timestamps
1890 ;; objects, i.e. timestamp objects in a paragraph containing only
1891 ;; timestamps and whitespaces.
1892 (when (let ((parent (org-export-get-parent-element datum
)))
1893 (and (memq (org-element-type parent
) '(paragraph verse-block
))
1894 (not (org-element-map parent
1896 (remq 'timestamp org-element-all-objects
))
1898 (or (not (stringp obj
)) (org-string-nw-p obj
)))
1900 (cl-case (plist-get options
:with-timestamps
)
1903 (not (memq (org-element-property :type datum
) '(active active-range
))))
1905 (not (memq (org-element-property :type datum
)
1906 '(inactive inactive-range
)))))))))
1911 ;; `org-export-data' reads a parse tree (obtained with, i.e.
1912 ;; `org-element-parse-buffer') and transcodes it into a specified
1913 ;; back-end output. It takes care of filtering out elements or
1914 ;; objects according to export options and organizing the output blank
1915 ;; lines and white space are preserved. The function memoizes its
1916 ;; results, so it is cheap to call it within transcoders.
1918 ;; It is possible to modify locally the back-end used by
1919 ;; `org-export-data' or even use a temporary back-end by using
1920 ;; `org-export-data-with-backend'.
1922 ;; `org-export-transcoder' is an accessor returning appropriate
1923 ;; translator function for a given element or object.
1925 (defun org-export-transcoder (blob info
)
1926 "Return appropriate transcoder for BLOB.
1927 INFO is a plist containing export directives."
1928 (let ((type (org-element-type blob
)))
1929 ;; Return contents only for complete parse trees.
1930 (if (eq type
'org-data
) (lambda (_datum contents _info
) contents
)
1931 (let ((transcoder (cdr (assq type
(plist-get info
:translate-alist
)))))
1932 (and (functionp transcoder
) transcoder
)))))
1934 (defun org-export-data (data info
)
1935 "Convert DATA into current back-end format.
1937 DATA is a parse tree, an element or an object or a secondary
1938 string. INFO is a plist holding export options.
1941 (or (gethash data
(plist-get info
:exported-data
))
1942 ;; Handle broken links according to
1943 ;; `org-export-with-broken-links'.
1945 ((broken-link-handler
1947 `(condition-case err
1950 (pcase (plist-get info
:with-broken-links
)
1951 (`nil
(user-error "Unable to resolve link: %S" (nth 1 err
)))
1952 (`mark
(org-export-data
1953 (format "[BROKEN LINK: %s]" (nth 1 err
)) info
))
1955 (let* ((type (org-element-type data
))
1956 (parent (org-export-get-parent data
))
1959 ;; Ignored element/object.
1960 ((memq data
(plist-get info
:ignore-list
)) nil
)
1962 ((eq type
'plain-text
)
1963 (org-export-filter-apply-functions
1964 (plist-get info
:filter-plain-text
)
1965 (let ((transcoder (org-export-transcoder data info
)))
1966 (if transcoder
(funcall transcoder data info
) data
))
1968 ;; Secondary string.
1970 (mapconcat (lambda (obj) (org-export-data obj info
)) data
""))
1971 ;; Element/Object without contents or, as a special
1972 ;; case, headline with archive tag and archived trees
1973 ;; restricted to title only.
1974 ((or (not (org-element-contents data
))
1975 (and (eq type
'headline
)
1976 (eq (plist-get info
:with-archived-trees
) 'headline
)
1977 (org-element-property :archivedp data
)))
1978 (let ((transcoder (org-export-transcoder data info
)))
1979 (or (and (functionp transcoder
)
1980 (broken-link-handler
1981 (funcall transcoder data nil info
)))
1982 ;; Export snippets never return a nil value so
1983 ;; that white spaces following them are never
1985 (and (eq type
'export-snippet
) ""))))
1986 ;; Element/Object with contents.
1988 (let ((transcoder (org-export-transcoder data info
)))
1990 (let* ((greaterp (memq type org-element-greater-elements
))
1993 (memq type org-element-recursive-objects
)))
1996 (lambda (element) (org-export-data element info
))
1997 (org-element-contents
1998 (if (or greaterp objectp
) data
1999 ;; Elements directly containing
2000 ;; objects must have their indentation
2001 ;; normalized first.
2002 (org-element-normalize-contents
2004 ;; When normalizing contents of the
2005 ;; first paragraph in an item or
2006 ;; a footnote definition, ignore
2007 ;; first line's indentation: there is
2008 ;; none and it might be misleading.
2009 (when (eq type
'paragraph
)
2011 (eq (car (org-element-contents parent
))
2013 (memq (org-element-type parent
)
2014 '(footnote-definition item
)))))))
2016 (broken-link-handler
2017 (funcall transcoder data
2018 (if (not greaterp
) contents
2019 (org-element-normalize-string contents
))
2021 ;; Final result will be memoized before being returned.
2026 ((memq type
'(org-data plain-text nil
)) results
)
2027 ;; Append the same white space between elements or objects
2028 ;; as in the original buffer, and call appropriate filters.
2030 (org-export-filter-apply-functions
2031 (plist-get info
(intern (format ":filter-%s" type
)))
2032 (let ((blank (or (org-element-property :post-blank data
) 0)))
2033 (if (eq (org-element-class data parent
) 'object
)
2034 (concat results
(make-string blank ?\s
))
2035 (concat (org-element-normalize-string results
)
2036 (make-string blank ?
\n))))
2038 (plist-get info
:exported-data
))))))
2040 (defun org-export-data-with-backend (data backend info
)
2041 "Convert DATA into BACKEND format.
2043 DATA is an element, an object, a secondary string or a string.
2044 BACKEND is a symbol. INFO is a plist used as a communication
2047 Unlike to `org-export-with-backend', this function will
2048 recursively convert DATA using BACKEND translation table."
2049 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
2050 ;; Set-up a new communication channel with translations defined in
2051 ;; BACKEND as the translate table and a new hash table for
2056 (list :back-end backend
2057 :translate-alist
(org-export-get-all-transcoders backend
)
2058 ;; Size of the hash table is reduced since this
2059 ;; function will probably be used on small trees.
2060 :exported-data
(make-hash-table :test
'eq
:size
401)))))
2061 (prog1 (org-export-data data new-info
)
2062 ;; Preserve `:internal-references', as those do not depend on
2063 ;; the back-end used; we need to make sure that any new
2064 ;; reference when the temporary back-end was active gets through
2066 (plist-put info
:internal-references
2067 (plist-get new-info
:internal-references
)))))
2069 (defun org-export-expand (blob contents
&optional with-affiliated
)
2070 "Expand a parsed element or object to its original state.
2072 BLOB is either an element or an object. CONTENTS is its
2073 contents, as a string or nil.
2075 When optional argument WITH-AFFILIATED is non-nil, add affiliated
2076 keywords before output."
2077 (let ((type (org-element-type blob
)))
2078 (concat (and with-affiliated
2079 (eq (org-element-class blob
) 'element
)
2080 (org-element--interpret-affiliated-keywords blob
))
2081 (funcall (intern (format "org-element-%s-interpreter" type
))
2086 ;;; The Filter System
2088 ;; Filters allow end-users to tweak easily the transcoded output.
2089 ;; They are the functional counterpart of hooks, as every filter in
2090 ;; a set is applied to the return value of the previous one.
2092 ;; Every set is back-end agnostic. Although, a filter is always
2093 ;; called, in addition to the string it applies to, with the back-end
2094 ;; used as argument, so it's easy for the end-user to add back-end
2095 ;; specific filters in the set. The communication channel, as
2096 ;; a plist, is required as the third argument.
2098 ;; From the developer side, filters sets can be installed in the
2099 ;; process with the help of `org-export-define-backend', which
2100 ;; internally stores filters as an alist. Each association has a key
2101 ;; among the following symbols and a function or a list of functions
2104 ;; - `:filter-options' applies to the property list containing export
2105 ;; options. Unlike to other filters, functions in this list accept
2106 ;; two arguments instead of three: the property list containing
2107 ;; export options and the back-end. Users can set its value through
2108 ;; `org-export-filter-options-functions' variable.
2110 ;; - `:filter-parse-tree' applies directly to the complete parsed
2111 ;; tree. Users can set it through
2112 ;; `org-export-filter-parse-tree-functions' variable.
2114 ;; - `:filter-body' applies to the body of the output, before template
2115 ;; translator chimes in. Users can set it through
2116 ;; `org-export-filter-body-functions' variable.
2118 ;; - `:filter-final-output' applies to the final transcoded string.
2119 ;; Users can set it with `org-export-filter-final-output-functions'
2122 ;; - `:filter-plain-text' applies to any string not recognized as Org
2123 ;; syntax. `org-export-filter-plain-text-functions' allows users to
2126 ;; - `:filter-TYPE' applies on the string returned after an element or
2127 ;; object of type TYPE has been transcoded. A user can modify
2128 ;; `org-export-filter-TYPE-functions' to install these filters.
2130 ;; All filters sets are applied with
2131 ;; `org-export-filter-apply-functions' function. Filters in a set are
2132 ;; applied in a LIFO fashion. It allows developers to be sure that
2133 ;; their filters will be applied first.
2135 ;; Filters properties are installed in communication channel with
2136 ;; `org-export-install-filters' function.
2138 ;; Eventually, two hooks (`org-export-before-processing-hook' and
2139 ;; `org-export-before-parsing-hook') are run at the beginning of the
2140 ;; export process and just before parsing to allow for heavy structure
2146 (defvar org-export-before-processing-hook nil
2147 "Hook run at the beginning of the export process.
2149 This is run before include keywords and macros are expanded and
2150 Babel code blocks executed, on a copy of the original buffer
2151 being exported. Visibility and narrowing are preserved. Point
2152 is at the beginning of the buffer.
2154 Every function in this hook will be called with one argument: the
2155 back-end currently used, as a symbol.")
2157 (defvar org-export-before-parsing-hook nil
2158 "Hook run before parsing an export buffer.
2160 This is run after include keywords and macros have been expanded
2161 and Babel code blocks executed, on a copy of the original buffer
2162 being exported. Visibility and narrowing are preserved. Point
2163 is at the beginning of the buffer.
2165 Every function in this hook will be called with one argument: the
2166 back-end currently used, as a symbol.")
2169 ;;;; Special Filters
2171 (defvar org-export-filter-options-functions nil
2172 "List of functions applied to the export options.
2173 Each filter is called with two arguments: the export options, as
2174 a plist, and the back-end, as a symbol. It must return
2175 a property list containing export options.")
2177 (defvar org-export-filter-parse-tree-functions nil
2178 "List of functions applied to the parsed tree.
2179 Each filter is called with three arguments: the parse tree, as
2180 returned by `org-element-parse-buffer', the back-end, as
2181 a symbol, and the communication channel, as a plist. It must
2182 return the modified parse tree to transcode.")
2184 (defvar org-export-filter-plain-text-functions nil
2185 "List of functions applied to plain text.
2186 Each filter is called with three arguments: a string which
2187 contains no Org syntax, the back-end, as a symbol, and the
2188 communication channel, as a plist. It must return a string or
2191 (defvar org-export-filter-body-functions nil
2192 "List of functions applied to transcoded body.
2193 Each filter is called with three arguments: a string which
2194 contains no Org syntax, the back-end, as a symbol, and the
2195 communication channel, as a plist. It must return a string or
2198 (defvar org-export-filter-final-output-functions nil
2199 "List of functions applied to the transcoded string.
2200 Each filter is called with three arguments: the full transcoded
2201 string, the back-end, as a symbol, and the communication channel,
2202 as a plist. It must return a string that will be used as the
2203 final export output.")
2206 ;;;; Elements Filters
2208 (defvar org-export-filter-babel-call-functions nil
2209 "List of functions applied to a transcoded babel-call.
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-center-block-functions nil
2215 "List of functions applied to a transcoded center block.
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-clock-functions nil
2221 "List of functions applied to a transcoded clock.
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-diary-sexp-functions nil
2227 "List of functions applied to a transcoded diary-sexp.
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-drawer-functions nil
2233 "List of functions applied to a transcoded drawer.
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-dynamic-block-functions nil
2239 "List of functions applied to a transcoded dynamic-block.
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-example-block-functions nil
2245 "List of functions applied to a transcoded example-block.
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-export-block-functions nil
2251 "List of functions applied to a transcoded export-block.
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-fixed-width-functions nil
2257 "List of functions applied to a transcoded fixed-width.
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-footnote-definition-functions nil
2263 "List of functions applied to a transcoded footnote-definition.
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-headline-functions nil
2269 "List of functions applied to a transcoded headline.
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-horizontal-rule-functions nil
2275 "List of functions applied to a transcoded horizontal-rule.
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-inlinetask-functions nil
2281 "List of functions applied to a transcoded inlinetask.
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-item-functions nil
2287 "List of functions applied to a transcoded item.
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-keyword-functions nil
2293 "List of functions applied to a transcoded keyword.
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-latex-environment-functions nil
2299 "List of functions applied to a transcoded latex-environment.
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-node-property-functions nil
2305 "List of functions applied to a transcoded node-property.
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-paragraph-functions nil
2311 "List of functions applied to a transcoded paragraph.
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-plain-list-functions nil
2317 "List of functions applied to a transcoded plain-list.
2318 Each filter is called with three arguments: the transcoded data,
2319 as a string, the back-end, as a symbol, and the communication
2320 channel, as a plist. It must return a string or nil.")
2322 (defvar org-export-filter-planning-functions nil
2323 "List of functions applied to a transcoded planning.
2324 Each filter is called with three arguments: the transcoded data,
2325 as a string, the back-end, as a symbol, and the communication
2326 channel, as a plist. It must return a string or nil.")
2328 (defvar org-export-filter-property-drawer-functions nil
2329 "List of functions applied to a transcoded property-drawer.
2330 Each filter is called with three arguments: the transcoded data,
2331 as a string, the back-end, as a symbol, and the communication
2332 channel, as a plist. It must return a string or nil.")
2334 (defvar org-export-filter-quote-block-functions nil
2335 "List of functions applied to a transcoded quote block.
2336 Each filter is called with three arguments: the transcoded quote
2337 data, as a string, the back-end, as a symbol, and the
2338 communication channel, as a plist. It must return a string or
2341 (defvar org-export-filter-section-functions nil
2342 "List of functions applied to a transcoded section.
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-special-block-functions nil
2348 "List of functions applied to a transcoded special block.
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-src-block-functions nil
2354 "List of functions applied to a transcoded src-block.
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-table-functions nil
2360 "List of functions applied to a transcoded table.
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.")
2365 (defvar org-export-filter-table-cell-functions nil
2366 "List of functions applied to a transcoded table-cell.
2367 Each filter is called with three arguments: the transcoded data,
2368 as a string, the back-end, as a symbol, and the communication
2369 channel, as a plist. It must return a string or nil.")
2371 (defvar org-export-filter-table-row-functions nil
2372 "List of functions applied to a transcoded table-row.
2373 Each filter is called with three arguments: the transcoded data,
2374 as a string, the back-end, as a symbol, and the communication
2375 channel, as a plist. It must return a string or nil.")
2377 (defvar org-export-filter-verse-block-functions nil
2378 "List of functions applied to a transcoded verse block.
2379 Each filter is called with three arguments: the transcoded data,
2380 as a string, the back-end, as a symbol, and the communication
2381 channel, as a plist. It must return a string or nil.")
2384 ;;;; Objects Filters
2386 (defvar org-export-filter-bold-functions nil
2387 "List of functions applied to transcoded bold text.
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-code-functions nil
2393 "List of functions applied to transcoded code text.
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-entity-functions nil
2399 "List of functions applied to a transcoded entity.
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-export-snippet-functions nil
2405 "List of functions applied to a transcoded export-snippet.
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-footnote-reference-functions nil
2411 "List of functions applied to a transcoded footnote-reference.
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-inline-babel-call-functions nil
2417 "List of functions applied to a transcoded inline-babel-call.
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-inline-src-block-functions nil
2423 "List of functions applied to a transcoded inline-src-block.
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-italic-functions nil
2429 "List of functions applied to transcoded italic text.
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-latex-fragment-functions nil
2435 "List of functions applied to a transcoded latex-fragment.
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-line-break-functions nil
2441 "List of functions applied to a transcoded line-break.
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-link-functions nil
2447 "List of functions applied to a transcoded link.
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-radio-target-functions nil
2453 "List of functions applied to a transcoded radio-target.
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-statistics-cookie-functions nil
2459 "List of functions applied to a transcoded statistics-cookie.
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-strike-through-functions nil
2465 "List of functions applied to transcoded strike-through text.
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-subscript-functions nil
2471 "List of functions applied to a transcoded subscript.
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-superscript-functions nil
2477 "List of functions applied to a transcoded superscript.
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-target-functions nil
2483 "List of functions applied to a transcoded target.
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.")
2488 (defvar org-export-filter-timestamp-functions nil
2489 "List of functions applied to a transcoded timestamp.
2490 Each filter is called with three arguments: the transcoded data,
2491 as a string, the back-end, as a symbol, and the communication
2492 channel, as a plist. It must return a string or nil.")
2494 (defvar org-export-filter-underline-functions nil
2495 "List of functions applied to transcoded underline text.
2496 Each filter is called with three arguments: the transcoded data,
2497 as a string, the back-end, as a symbol, and the communication
2498 channel, as a plist. It must return a string or nil.")
2500 (defvar org-export-filter-verbatim-functions nil
2501 "List of functions applied to transcoded verbatim text.
2502 Each filter is called with three arguments: the transcoded data,
2503 as a string, the back-end, as a symbol, and the communication
2504 channel, as a plist. It must return a string or nil.")
2509 ;; Internal function `org-export-install-filters' installs filters
2510 ;; hard-coded in back-ends (developer filters) and filters from global
2511 ;; variables (user filters) in the communication channel.
2513 ;; Internal function `org-export-filter-apply-functions' takes care
2514 ;; about applying each filter in order to a given data. It ignores
2515 ;; filters returning a nil value but stops whenever a filter returns
2518 (defun org-export-filter-apply-functions (filters value info
)
2519 "Call every function in FILTERS.
2521 Functions are called with three arguments: a value, the export
2522 back-end name and the communication channel. First function in
2523 FILTERS is called with VALUE as its first argument. Second
2524 function in FILTERS is called with the previous result as its
2527 Functions returning nil are skipped. Any function returning the
2528 empty string ends the process, which returns the empty string.
2530 Call is done in a LIFO fashion, to be sure that developer
2531 specified filters, if any, are called first."
2533 (let* ((backend (plist-get info
:back-end
))
2534 (backend-name (and backend
(org-export-backend-name backend
))))
2535 (dolist (filter filters value
)
2536 (let ((result (funcall filter value backend-name info
)))
2537 (cond ((not result
))
2538 ((equal result
"") (throw :exit
""))
2539 (t (setq value result
))))))))
2541 (defun org-export-install-filters (info)
2542 "Install filters properties in communication channel.
2543 INFO is a plist containing the current communication channel.
2544 Return the updated communication channel."
2546 ;; Install user-defined filters with `org-export-filters-alist'
2547 ;; and filters already in INFO (through ext-plist mechanism).
2548 (dolist (p org-export-filters-alist
)
2549 (let* ((prop (car p
))
2550 (info-value (plist-get info prop
))
2551 (default-value (symbol-value (cdr p
))))
2553 (plist-put plist prop
2554 ;; Filters in INFO will be called
2555 ;; before those user provided.
2556 (append (if (listp info-value
) info-value
2559 ;; Prepend back-end specific filters to that list.
2560 (dolist (p (org-export-get-all-filters (plist-get info
:back-end
)))
2561 ;; Single values get consed, lists are appended.
2562 (let ((key (car p
)) (value (cdr p
)))
2567 (if (atom value
) (cons value
(plist-get plist key
))
2568 (append value
(plist-get plist key
))))))))
2569 ;; Return new communication channel.
2570 (org-combine-plists info plist
)))
2576 ;; This is the room for the main function, `org-export-as', along with
2577 ;; its derivative, `org-export-string-as'.
2578 ;; `org-export--copy-to-kill-ring-p' determines if output of these
2579 ;; function should be added to kill ring.
2581 ;; Note that `org-export-as' doesn't really parse the current buffer,
2582 ;; but a copy of it (with the same buffer-local variables and
2583 ;; visibility), where macros and include keywords are expanded and
2584 ;; Babel blocks are executed, if appropriate.
2585 ;; `org-export-with-buffer-copy' macro prepares that copy.
2587 ;; File inclusion is taken care of by
2588 ;; `org-export-expand-include-keyword' and
2589 ;; `org-export--prepare-file-contents'. Structure wise, including
2590 ;; a whole Org file in a buffer often makes little sense. For
2591 ;; example, if the file contains a headline and the include keyword
2592 ;; was within an item, the item should contain the headline. That's
2593 ;; why file inclusion should be done before any structure can be
2594 ;; associated to the file, that is before parsing.
2596 ;; `org-export-insert-default-template' is a command to insert
2597 ;; a default template (or a back-end specific template) at point or in
2600 (defun org-export-copy-buffer ()
2601 "Return a copy of the current buffer.
2602 The copy preserves Org buffer-local variables, visibility and
2604 (let ((copy-buffer-fun (org-export--generate-copy-script (current-buffer)))
2605 (new-buf (generate-new-buffer (buffer-name))))
2606 (with-current-buffer new-buf
2607 (funcall copy-buffer-fun
)
2608 (set-buffer-modified-p nil
))
2611 (defmacro org-export-with-buffer-copy
(&rest body
)
2612 "Apply BODY in a copy of the current buffer.
2613 The copy preserves local variables, visibility and contents of
2614 the original buffer. Point is at the beginning of the buffer
2615 when BODY is applied."
2617 (org-with-gensyms (buf-copy)
2618 `(let ((,buf-copy
(org-export-copy-buffer)))
2620 (with-current-buffer ,buf-copy
2621 (goto-char (point-min))
2623 (and (buffer-live-p ,buf-copy
)
2624 ;; Kill copy without confirmation.
2625 (progn (with-current-buffer ,buf-copy
2626 (restore-buffer-modified-p nil
))
2627 (kill-buffer ,buf-copy
)))))))
2629 (defun org-export--generate-copy-script (buffer)
2630 "Generate a function duplicating BUFFER.
2632 The copy will preserve local variables, visibility, contents and
2633 narrowing of the original buffer. If a region was active in
2634 BUFFER, contents will be narrowed to that region instead.
2636 The resulting function can be evaluated at a later time, from
2637 another buffer, effectively cloning the original buffer there.
2639 The function assumes BUFFER's major mode is `org-mode'."
2640 (with-current-buffer buffer
2642 (let ((inhibit-modification-hooks t
))
2643 ;; Set major mode. Ignore `org-mode-hook' as it has been run
2644 ;; already in BUFFER.
2645 (let ((org-mode-hook nil
) (org-inhibit-startup t
)) (org-mode))
2646 ;; Copy specific buffer local variables and variables set
2647 ;; through BIND keywords.
2648 ,@(let ((bound-variables (org-export--list-bound-variables))
2650 (dolist (entry (buffer-local-variables (buffer-base-buffer)) vars
)
2652 (let ((var (car entry
))
2654 (and (not (memq var org-export-ignored-local-variables
))
2658 buffer-file-coding-system
))
2659 (assq var bound-variables
)
2660 (string-match "^\\(org-\\|orgtbl-\\)"
2662 ;; Skip unreadable values, as they cannot be
2663 ;; sent to external process.
2664 (or (not val
) (ignore-errors (read (format "%S" val
))))
2665 (push `(set (make-local-variable (quote ,var
))
2668 ;; Whole buffer contents.
2670 ,(org-with-wide-buffer
2671 (buffer-substring-no-properties
2672 (point-min) (point-max))))
2674 ,(if (org-region-active-p)
2675 `(narrow-to-region ,(region-beginning) ,(region-end))
2676 `(narrow-to-region ,(point-min) ,(point-max)))
2677 ;; Current position of point.
2678 (goto-char ,(point))
2679 ;; Overlays with invisible property.
2681 (dolist (ov (overlays-in (point-min) (point-max)) ov-set
)
2682 (let ((invis-prop (overlay-get ov
'invisible
)))
2685 (make-overlay ,(overlay-start ov
)
2687 'invisible
(quote ,invis-prop
))
2690 (defun org-export--delete-comment-trees ()
2691 "Delete commented trees and commented inlinetasks in the buffer.
2692 Narrowing, if any, is ignored."
2693 (org-with-wide-buffer
2694 (goto-char (point-min))
2695 (let* ((case-fold-search t
)
2696 (regexp (concat org-outline-regexp-bol
".*" org-comment-string
)))
2697 (while (re-search-forward regexp nil t
)
2698 (let ((element (org-element-at-point)))
2699 (when (org-element-property :commentedp element
)
2700 (delete-region (org-element-property :begin element
)
2701 (org-element-property :end element
))))))))
2703 (defun org-export--prune-tree (data info
)
2704 "Prune non exportable elements from DATA.
2705 DATA is the parse tree to traverse. INFO is the plist holding
2706 export info. Also set `:ignore-list' in INFO to a list of
2707 objects which should be ignored during export, but not removed
2709 (letrec ((ignore nil
)
2710 ;; First find trees containing a select tag, if any.
2711 (selected (org-export--selected-trees data info
))
2714 ;; Prune non-exportable elements and objects from tree.
2715 ;; As a special case, special rows and cells from tables
2716 ;; are stored in IGNORE, as they still need to be
2717 ;; accessed during export.
2719 (let ((type (org-element-type data
)))
2720 (if (org-export--skip-p data info selected
)
2721 (if (memq type
'(table-cell table-row
)) (push data ignore
)
2722 (org-element-extract-element data
))
2723 (if (and (eq type
'headline
)
2724 (eq (plist-get info
:with-archived-trees
)
2726 (org-element-property :archivedp data
))
2727 ;; If headline is archived but tree below has
2728 ;; to be skipped, remove contents.
2729 (org-element-set-contents data
)
2730 ;; Move into recursive objects/elements.
2731 (mapc walk-data
(org-element-contents data
)))
2732 ;; Move into secondary string, if any.
2733 (dolist (p (cdr (assq type
2734 org-element-secondary-value-alist
)))
2735 (mapc walk-data
(org-element-property p data
))))))))
2737 ;; Collect definitions before possibly pruning them so as
2738 ;; to avoid parsing them again if they are required.
2739 (org-element-map data
'(footnote-definition footnote-reference
)
2742 ((eq 'footnote-definition
(org-element-type f
)) f
)
2743 ((and (eq 'inline
(org-element-property :type f
))
2744 (org-element-property :label f
))
2747 ;; If a select tag is active, also ignore the section before the
2748 ;; first headline, if any.
2750 (let ((first-element (car (org-element-contents data
))))
2751 (when (eq (org-element-type first-element
) 'section
)
2752 (org-element-extract-element first-element
))))
2753 ;; Prune tree and communication channel.
2754 (funcall walk-data data
)
2755 (dolist (entry (append
2756 ;; Priority is given to back-end specific options.
2757 (org-export-get-all-options (plist-get info
:back-end
))
2758 org-export-options-alist
))
2759 (when (eq (nth 4 entry
) 'parse
)
2760 (funcall walk-data
(plist-get info
(car entry
)))))
2761 (let ((missing (org-export--missing-definitions data definitions
)))
2762 (funcall walk-data missing
)
2763 (org-export--install-footnote-definitions missing data
))
2764 ;; Eventually set `:ignore-list'.
2765 (plist-put info
:ignore-list ignore
)))
2767 (defun org-export--missing-definitions (tree definitions
)
2768 "List footnote definitions missing from TREE.
2769 Missing definitions are searched within DEFINITIONS, which is
2770 a list of footnote definitions or in the widened buffer."
2773 ;; List all footnote labels encountered in DATA. Inline
2774 ;; footnote references are ignored.
2775 (org-element-map data
'footnote-reference
2777 (and (eq (org-element-property :type reference
) 'standard
)
2778 (org-element-property :label reference
))))))
2779 defined undefined missing-definitions
)
2780 ;; Partition DIRECT-REFERENCES between DEFINED and UNDEFINED
2782 (let ((known-definitions
2783 (org-element-map tree
'(footnote-reference footnote-definition
)
2785 (and (or (eq (org-element-type f
) 'footnote-definition
)
2786 (eq (org-element-property :type f
) 'inline
))
2787 (org-element-property :label f
)))))
2789 (dolist (l (funcall list-labels tree
))
2790 (cond ((member l seen
))
2791 ((member l known-definitions
) (push l defined
))
2792 (t (push l undefined
)))))
2793 ;; Complete MISSING-DEFINITIONS by finding the definition of every
2794 ;; undefined label, first by looking into DEFINITIONS, then by
2795 ;; searching the widened buffer. This is a recursive process
2796 ;; since definitions found can themselves contain an undefined
2799 (let* ((label (pop undefined
))
2803 (lambda (d) (and (equal (org-element-property :label d
) label
)
2806 ((pcase (org-footnote-get-definition label
)
2808 (org-with-wide-buffer
2810 (let ((datum (org-element-context)))
2811 (if (eq (org-element-type datum
) 'footnote-reference
)
2813 ;; Parse definition with contents.
2816 (org-element-property :begin datum
)
2817 (org-element-property :end datum
))
2818 (org-element-map (org-element-parse-buffer)
2819 'footnote-definition
#'identity nil t
))))))
2821 (t (user-error "Definition not found for footnote %s" label
)))))
2822 (push label defined
)
2823 (push definition missing-definitions
)
2824 ;; Look for footnote references within DEFINITION, since
2825 ;; we may need to also find their definition.
2826 (dolist (l (funcall list-labels definition
))
2827 (unless (or (member l defined
) ;Known label
2828 (member l undefined
)) ;Processed later
2829 (push l undefined
)))))
2830 ;; MISSING-DEFINITIONS may contain footnote references with inline
2831 ;; definitions. Make sure those are changed into real footnote
2834 (if (eq (org-element-type d
) 'footnote-definition
) d
2835 (let ((label (org-element-property :label d
)))
2836 (apply #'org-element-create
2837 'footnote-definition
`(:label
,label
:post-blank
1)
2838 (org-element-contents d
)))))
2839 missing-definitions
)))
2841 (defun org-export--install-footnote-definitions (definitions tree
)
2842 "Install footnote definitions in tree.
2844 DEFINITIONS is the list of footnote definitions to install. TREE
2847 If there is a footnote section in TREE, definitions found are
2848 appended to it. If `org-footnote-section' is non-nil, a new
2849 footnote section containing all definitions is inserted in TREE.
2850 Otherwise, definitions are appended at the end of the section
2851 containing their first reference."
2853 ((null definitions
))
2854 ;; If there is a footnote section, insert definitions there.
2855 ((let ((footnote-section
2856 (org-element-map tree
'headline
2857 (lambda (h) (and (org-element-property :footnote-section-p h
) h
))
2859 (and footnote-section
2860 (apply #'org-element-adopt-elements
2862 (nreverse definitions
)))))
2863 ;; If there should be a footnote section, create one containing all
2864 ;; the definitions at the end of the tree.
2865 (org-footnote-section
2866 (org-element-adopt-elements
2868 (org-element-create 'headline
2869 (list :footnote-section-p t
2871 :title org-footnote-section
2872 :raw-value org-footnote-section
)
2873 (apply #'org-element-create
2876 (nreverse definitions
)))))
2877 ;; Otherwise add each definition at the end of the section where it
2878 ;; is first referenced.
2883 ;; Insert footnote definitions in the same section as
2884 ;; their first reference in DATA.
2885 (org-element-map data
'footnote-reference
2887 (when (eq (org-element-property :type reference
) 'standard
)
2888 (let ((label (org-element-property :label reference
)))
2889 (unless (member label seen
)
2894 (and (equal (org-element-property :label d
)
2898 (org-element-adopt-elements
2899 (org-element-lineage reference
'(section))
2901 ;; Also insert definitions for nested
2902 ;; references, if any.
2903 (funcall insert-definitions definition
))))))))))
2904 (funcall insert-definitions tree
)))))
2906 (defun org-export--remove-uninterpreted-data (data info
)
2907 "Change uninterpreted elements back into Org syntax.
2908 DATA is a parse tree or a secondary string. INFO is a plist
2909 containing export options. It is modified by side effect and
2910 returned by the function."
2911 (org-element-map data
2912 '(entity bold italic latex-environment latex-fragment strike-through
2913 subscript superscript underline
)
2916 (cl-case (org-element-type datum
)
2919 (and (not (plist-get info
:with-entities
))
2921 (org-export-expand datum nil
)
2923 (or (org-element-property :post-blank datum
) 0)
2926 ((bold italic strike-through underline
)
2927 (and (not (plist-get info
:with-emphasize
))
2928 (let ((marker (cl-case (org-element-type datum
)
2931 (strike-through "+")
2935 (org-element-contents datum
)
2939 (or (org-element-property :post-blank datum
)
2942 ;; ... LaTeX environments and fragments...
2943 ((latex-environment latex-fragment
)
2944 (and (eq (plist-get info
:with-latex
) 'verbatim
)
2945 (list (org-export-expand datum nil
))))
2946 ;; ... sub/superscripts...
2947 ((subscript superscript
)
2948 (let ((sub/super-p
(plist-get info
:with-sub-superscript
))
2949 (bracketp (org-element-property :use-brackets-p datum
)))
2950 (and (or (not sub
/super-p
)
2951 (and (eq sub
/super-p
'{}) (not bracketp
)))
2954 (if (eq (org-element-type datum
) 'subscript
)
2957 (and bracketp
"{")))
2958 (org-element-contents datum
)
2961 (and (org-element-property :post-blank datum
)
2963 (org-element-property :post-blank datum
)
2966 ;; Splice NEW at DATUM location in parse tree.
2967 (dolist (e new
(org-element-extract-element datum
))
2968 (unless (equal e
"") (org-element-insert-before e datum
))))))
2970 ;; Return modified parse tree.
2974 (defun org-export-as
2975 (backend &optional subtreep visible-only body-only ext-plist
)
2976 "Transcode current Org buffer into BACKEND code.
2978 BACKEND is either an export back-end, as returned by, e.g.,
2979 `org-export-create-backend', or a symbol referring to
2980 a registered back-end.
2982 If narrowing is active in the current buffer, only transcode its
2985 If a region is active, transcode that region.
2987 When optional argument SUBTREEP is non-nil, transcode the
2988 sub-tree at point, extracting information from the headline
2991 When optional argument VISIBLE-ONLY is non-nil, don't export
2992 contents of hidden elements.
2994 When optional argument BODY-ONLY is non-nil, only return body
2995 code, without surrounding template.
2997 Optional argument EXT-PLIST, when provided, is a property list
2998 with external parameters overriding Org default settings, but
2999 still inferior to file-local settings.
3001 Return code as a string."
3002 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
3003 (org-export-barf-if-invalid-backend backend
)
3006 ;; Narrow buffer to an appropriate region or subtree for
3007 ;; parsing. If parsing subtree, be sure to remove main
3008 ;; headline, planning data and property drawer.
3009 (cond ((org-region-active-p)
3010 (narrow-to-region (region-beginning) (region-end)))
3012 (org-narrow-to-subtree)
3013 (goto-char (point-min))
3014 (org-end-of-meta-data)
3015 (narrow-to-region (point) (point-max))))
3016 ;; Initialize communication channel with original buffer
3017 ;; attributes, unavailable in its copy.
3018 (let* ((org-export-current-backend (org-export-backend-name backend
))
3019 (info (org-combine-plists
3020 (org-export--get-export-attributes
3021 backend subtreep visible-only body-only
)
3022 (org-export--get-buffer-attributes)))
3025 (mapcar (lambda (o) (and (eq (nth 4 o
) 'parse
) (nth 1 o
)))
3026 (append (org-export-get-all-options backend
)
3027 org-export-options-alist
))))
3029 ;; Update communication channel and get parse tree. Buffer
3030 ;; isn't parsed directly. Instead, all buffer modifications
3031 ;; and consequent parsing are undertaken in a temporary copy.
3032 (org-export-with-buffer-copy
3033 ;; Run first hook with current back-end's name as argument.
3034 (run-hook-with-args 'org-export-before-processing-hook
3035 (org-export-backend-name backend
))
3036 ;; Include files, delete comments and expand macros.
3037 (org-export-expand-include-keyword)
3038 (org-export--delete-comment-trees)
3039 (org-macro-initialize-templates)
3040 (org-macro-replace-all
3041 (append org-macro-templates org-export-global-macros
)
3042 nil parsed-keywords
)
3043 ;; Refresh buffer properties and radio targets after
3044 ;; potentially invasive previous changes. Likewise, do it
3045 ;; again after executing Babel code.
3046 (org-set-regexps-and-options)
3047 (org-update-radio-target-regexp)
3048 (when org-export-use-babel
3049 (org-babel-exp-process-buffer)
3050 (org-set-regexps-and-options)
3051 (org-update-radio-target-regexp))
3052 ;; Run last hook with current back-end's name as argument.
3053 ;; Update buffer properties and radio targets one last time
3055 (goto-char (point-min))
3057 (run-hook-with-args 'org-export-before-parsing-hook
3058 (org-export-backend-name backend
)))
3059 (org-set-regexps-and-options)
3060 (org-update-radio-target-regexp)
3061 ;; Update communication channel with environment.
3064 info
(org-export-get-environment backend subtreep ext-plist
)))
3065 ;; De-activate uninterpreted data from parsed keywords.
3066 (dolist (entry (append (org-export-get-all-options backend
)
3067 org-export-options-alist
))
3069 (`(,p
,_
,_
,_ parse
)
3070 (let ((value (plist-get info p
)))
3073 (org-export--remove-uninterpreted-data value info
))))
3075 ;; Install user's and developer's filters.
3076 (setq info
(org-export-install-filters info
))
3077 ;; Call options filters and update export options. We do not
3078 ;; use `org-export-filter-apply-functions' here since the
3079 ;; arity of such filters is different.
3080 (let ((backend-name (org-export-backend-name backend
)))
3081 (dolist (filter (plist-get info
:filter-options
))
3082 (let ((result (funcall filter info backend-name
)))
3083 (when result
(setq info result
)))))
3084 ;; Expand export-specific set of macros: {{{author}}},
3085 ;; {{{date(FORMAT)}}}, {{{email}}} and {{{title}}}. It must
3086 ;; be done once regular macros have been expanded, since
3087 ;; parsed keywords may contain one of them.
3088 (org-macro-replace-all
3090 (cons "author" (org-element-interpret-data (plist-get info
:author
)))
3092 (let* ((date (plist-get info
:date
))
3093 (value (or (org-element-interpret-data date
) "")))
3094 (if (and (consp date
)
3096 (eq (org-element-type (car date
)) 'timestamp
))
3097 (format "(eval (if (org-string-nw-p \"$1\") %s %S))"
3098 (format "(org-timestamp-format '%S \"$1\")"
3099 (org-element-copy (car date
)))
3102 (cons "email" (org-element-interpret-data (plist-get info
:email
)))
3103 (cons "title" (org-element-interpret-data (plist-get info
:title
)))
3104 (cons "results" "$1"))
3108 (setq tree
(org-element-parse-buffer nil visible-only
))
3109 ;; Prune tree from non-exported elements and transform
3110 ;; uninterpreted elements or objects in both parse tree and
3111 ;; communication channel.
3112 (org-export--prune-tree tree info
)
3113 (org-export--remove-uninterpreted-data tree info
)
3114 ;; Call parse tree filters.
3116 (org-export-filter-apply-functions
3117 (plist-get info
:filter-parse-tree
) tree info
))
3118 ;; Now tree is complete, compute its properties and add them
3119 ;; to communication channel.
3120 (setq info
(org-export--collect-tree-properties tree info
))
3121 ;; Eventually transcode TREE. Wrap the resulting string into
3123 (let* ((body (org-element-normalize-string
3124 (or (org-export-data tree info
) "")))
3125 (inner-template (cdr (assq 'inner-template
3126 (plist-get info
:translate-alist
))))
3127 (full-body (org-export-filter-apply-functions
3128 (plist-get info
:filter-body
)
3129 (if (not (functionp inner-template
)) body
3130 (funcall inner-template body info
))
3132 (template (cdr (assq 'template
3133 (plist-get info
:translate-alist
)))))
3134 ;; Remove all text properties since they cannot be
3135 ;; retrieved from an external process. Finally call
3136 ;; final-output filter and return result.
3138 (org-export-filter-apply-functions
3139 (plist-get info
:filter-final-output
)
3140 (if (or (not (functionp template
)) body-only
) full-body
3141 (funcall template full-body info
))
3145 (defun org-export-string-as (string backend
&optional body-only ext-plist
)
3146 "Transcode STRING into BACKEND code.
3148 BACKEND is either an export back-end, as returned by, e.g.,
3149 `org-export-create-backend', or a symbol referring to
3150 a registered back-end.
3152 When optional argument BODY-ONLY is non-nil, only return body
3153 code, without preamble nor postamble.
3155 Optional argument EXT-PLIST, when provided, is a property list
3156 with external parameters overriding Org default settings, but
3157 still inferior to file-local settings.
3159 Return code as a string."
3162 (let ((org-inhibit-startup t
)) (org-mode))
3163 (org-export-as backend nil nil body-only ext-plist
)))
3166 (defun org-export-replace-region-by (backend)
3167 "Replace the active region by its export to BACKEND.
3168 BACKEND is either an export back-end, as returned by, e.g.,
3169 `org-export-create-backend', or a symbol referring to
3170 a registered back-end."
3171 (unless (org-region-active-p) (user-error "No active region to replace"))
3173 (org-export-string-as
3174 (delete-and-extract-region (region-beginning) (region-end)) backend t
)))
3177 (defun org-export-insert-default-template (&optional backend subtreep
)
3178 "Insert all export keywords with default values at beginning of line.
3180 BACKEND is a symbol referring to the name of a registered export
3181 back-end, for which specific export options should be added to
3182 the template, or `default' for default template. When it is nil,
3183 the user will be prompted for a category.
3185 If SUBTREEP is non-nil, export configuration will be set up
3186 locally for the subtree through node properties."
3188 (unless (derived-mode-p 'org-mode
) (user-error "Not in an Org mode buffer"))
3189 (when (and subtreep
(org-before-first-heading-p))
3190 (user-error "No subtree to set export options for"))
3191 (let ((node (and subtreep
(save-excursion (org-back-to-heading t
) (point))))
3195 (org-completing-read
3196 "Options category: "
3199 (symbol-name (org-export-backend-name b
)))
3200 org-export-registered-backends
))
3203 ;; Populate OPTIONS and KEYWORDS.
3204 (dolist (entry (cond ((eq backend
'default
) org-export-options-alist
)
3205 ((org-export-backend-p backend
)
3206 (org-export-backend-options backend
))
3207 (t (org-export-backend-options
3208 (org-export-get-backend backend
)))))
3209 (let ((keyword (nth 1 entry
))
3210 (option (nth 2 entry
)))
3212 (keyword (unless (assoc keyword keywords
)
3214 (if (eq (nth 4 entry
) 'split
)
3215 (mapconcat #'identity
(eval (nth 3 entry
)) " ")
3216 (eval (nth 3 entry
)))))
3217 (push (cons keyword value
) keywords
))))
3218 (option (unless (assoc option options
)
3219 (push (cons option
(eval (nth 3 entry
))) options
))))))
3220 ;; Move to an appropriate location in order to insert options.
3221 (unless subtreep
(beginning-of-line))
3222 ;; First (multiple) OPTIONS lines. Never go past fill-column.
3226 #'(lambda (opt) (format "%s:%S" (car opt
) (cdr opt
)))
3227 (sort options
(lambda (k1 k2
) (string< (car k1
) (car k2
)))))))
3230 node
"EXPORT_OPTIONS" (mapconcat 'identity items
" "))
3232 (insert "#+OPTIONS:")
3235 (< (+ width
(length (car items
)) 1) fill-column
))
3236 (let ((item (pop items
)))
3238 (cl-incf width
(1+ (length item
))))))
3240 ;; Then the rest of keywords, in the order specified in either
3241 ;; `org-export-options-alist' or respective export back-ends.
3242 (dolist (key (nreverse keywords
))
3243 (let ((val (cond ((equal (car key
) "DATE")
3246 (org-insert-time-stamp (current-time)))))
3247 ((equal (car key
) "TITLE")
3248 (or (let ((visited-file
3249 (buffer-file-name (buffer-base-buffer))))
3251 (file-name-sans-extension
3252 (file-name-nondirectory visited-file
))))
3253 (buffer-name (buffer-base-buffer))))
3255 (if subtreep
(org-entry-put node
(concat "EXPORT_" (car key
)) val
)
3259 (if (org-string-nw-p val
) (format " %s" val
) ""))))))))
3261 (defun org-export-expand-include-keyword (&optional included dir footnotes
)
3262 "Expand every include keyword in buffer.
3263 Optional argument INCLUDED is a list of included file names along
3264 with their line restriction, when appropriate. It is used to
3265 avoid infinite recursion. Optional argument DIR is the current
3266 working directory. It is used to properly resolve relative
3267 paths. Optional argument FOOTNOTES is a hash-table used for
3268 storing and resolving footnotes. It is created automatically."
3269 (let ((case-fold-search t
)
3270 (file-prefix (make-hash-table :test
#'equal
))
3272 (footnotes (or footnotes
(make-hash-table :test
#'equal
)))
3273 (include-re "^[ \t]*#\\+INCLUDE:"))
3274 ;; If :minlevel is not set the text-property
3275 ;; `:org-include-induced-level' will be used to determine the
3276 ;; relative level when expanding INCLUDE.
3277 ;; Only affects included Org documents.
3278 (goto-char (point-min))
3279 (while (re-search-forward include-re nil t
)
3280 (put-text-property (line-beginning-position) (line-end-position)
3281 :org-include-induced-level
3282 (1+ (org-reduced-level (or (org-current-level) 0)))))
3283 ;; Expand INCLUDE keywords.
3284 (goto-char (point-min))
3285 (while (re-search-forward include-re nil t
)
3286 (unless (org-in-commented-heading-p)
3287 (let ((element (save-match-data (org-element-at-point))))
3288 (when (eq (org-element-type element
) 'keyword
)
3290 ;; Extract arguments from keyword's value.
3291 (let* ((value (org-element-property :value element
))
3292 (ind (org-get-indentation))
3296 "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value
)
3299 (let ((matched (match-string 1 value
)))
3300 (when (string-match "\\(::\\(.*?\\)\\)\"?\\'"
3302 (setq location
(match-string 2 matched
))
3304 (replace-match "" nil nil matched
1)))
3306 (org-unbracket-string "\"" "\"" matched
)
3308 (setq value
(replace-match "" nil nil value
)))))
3310 (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
3312 (prog1 (org-not-nil (match-string 1 value
))
3313 (setq value
(replace-match "" nil nil value
)))))
3316 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
3318 (prog1 (match-string 1 value
)
3319 (setq value
(replace-match "" nil nil value
)))))
3321 ((string-match "\\<example\\>" value
) 'literal
)
3322 ((string-match "\\<export\\(?: +\\(.*\\)\\)?" value
)
3324 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value
)
3326 ;; Minimal level of included file defaults to the
3327 ;; child level of the current headline, if any, or
3328 ;; one. It only applies is the file is meant to be
3329 ;; included as an Org one.
3332 (if (string-match ":minlevel +\\([0-9]+\\)" value
)
3333 (prog1 (string-to-number (match-string 1 value
))
3334 (setq value
(replace-match "" nil nil value
)))
3335 (get-text-property (point)
3336 :org-include-induced-level
))))
3337 (args (and (eq env
'literal
) (match-string 1 value
)))
3338 (block (and (string-match "\\<\\(\\S-+\\)\\>" value
)
3339 (match-string 1 value
))))
3341 (delete-region (point) (line-beginning-position 2))
3344 ((not (file-readable-p file
))
3345 (error "Cannot include file %s" file
))
3346 ;; Check if files has already been parsed. Look after
3347 ;; inclusion lines too, as different parts of the same
3348 ;; file can be included too.
3349 ((member (list file lines
) included
)
3350 (error "Recursive file inclusion: %s" file
))
3355 (let ((ind-str (make-string ind ?\s
))
3356 (arg-str (if (stringp args
) (format " %s" args
) ""))
3358 (org-escape-code-in-string
3359 (org-export--prepare-file-contents file lines
))))
3360 (format "%s#+BEGIN_%s%s\n%s%s#+END_%s\n"
3361 ind-str block arg-str contents ind-str block
))))
3364 (let ((ind-str (make-string ind ?\s
))
3366 (org-export--prepare-file-contents file lines
)))
3367 (format "%s#+BEGIN_%s\n%s%s#+END_%s\n"
3368 ind-str block contents ind-str block
))))
3372 (let ((org-inhibit-startup t
)
3375 (org-export--inclusion-absolute-lines
3376 file location only-contents lines
)
3380 (org-export--prepare-file-contents
3381 file lines ind minlevel
3383 (gethash file file-prefix
)
3384 (puthash file
(cl-incf current-prefix
) file-prefix
))
3386 (org-export-expand-include-keyword
3387 (cons (list file lines
) included
)
3388 (file-name-directory file
)
3391 ;; Expand footnotes after all files have been
3392 ;; included. Footnotes are stored at end of buffer.
3394 (org-with-wide-buffer
3395 (goto-char (point-max))
3396 (maphash (lambda (k v
)
3397 (insert (format "\n[fn:%s] %s\n" k v
)))
3398 footnotes
))))))))))))
3400 (defun org-export--inclusion-absolute-lines (file location only-contents lines
)
3401 "Resolve absolute lines for an included file with file-link.
3403 FILE is string file-name of the file to include. LOCATION is a
3404 string name within FILE to be included (located via
3405 `org-link-search'). If ONLY-CONTENTS is non-nil only the
3406 contents of the named element will be included, as determined
3407 Org-Element. If LINES is non-nil only those lines are included.
3409 Return a string of lines to be included in the format expected by
3410 `org-export--prepare-file-contents'."
3412 (insert-file-contents file
)
3413 (unless (eq major-mode
'org-mode
)
3414 (let ((org-inhibit-startup t
)) (org-mode)))
3416 ;; Enforce consistent search.
3417 (let ((org-link-search-must-match-exact-headline nil
))
3418 (org-link-search location
))
3420 (error "%s for %s::%s" (error-message-string err
) file location
)))
3421 (let* ((element (org-element-at-point))
3423 (and only-contents
(org-element-property :contents-begin element
))))
3425 (or contents-begin
(org-element-property :begin element
))
3426 (org-element-property (if contents-begin
:contents-end
:end
) element
))
3427 (when (and only-contents
3428 (memq (org-element-type element
) '(headline inlinetask
)))
3429 ;; Skip planning line and property-drawer.
3430 (goto-char (point-min))
3431 (when (looking-at-p org-planning-line-re
) (forward-line))
3432 (when (looking-at org-property-drawer-re
) (goto-char (match-end 0)))
3433 (unless (bolp) (forward-line))
3434 (narrow-to-region (point) (point-max))))
3436 (org-skip-whitespace)
3438 (let* ((lines (split-string lines
"-"))
3439 (lbeg (string-to-number (car lines
)))
3440 (lend (string-to-number (cadr lines
)))
3441 (beg (if (zerop lbeg
) (point-min)
3442 (goto-char (point-min))
3443 (forward-line (1- lbeg
))
3445 (end (if (zerop lend
) (point-max)
3447 (forward-line (1- lend
))
3449 (narrow-to-region beg end
)))
3450 (let ((end (point-max)))
3451 (goto-char (point-min))
3453 (let ((start-line (line-number-at-pos)))
3459 (while (< (point) end
) (cl-incf counter
) (forward-line))
3462 (defun org-export--prepare-file-contents
3463 (file &optional lines ind minlevel id footnotes
)
3464 "Prepare contents of FILE for inclusion and return it as a string.
3466 When optional argument LINES is a string specifying a range of
3467 lines, include only those lines.
3469 Optional argument IND, when non-nil, is an integer specifying the
3470 global indentation of returned contents. Since its purpose is to
3471 allow an included file to stay in the same environment it was
3472 created (e.g., a list item), it doesn't apply past the first
3473 headline encountered.
3475 Optional argument MINLEVEL, when non-nil, is an integer
3476 specifying the level that any top-level headline in the included
3479 Optional argument ID is an integer that will be inserted before
3480 each footnote definition and reference if FILE is an Org file.
3481 This is useful to avoid conflicts when more than one Org file
3482 with footnotes is included in a document.
3484 Optional argument FOOTNOTES is a hash-table to store footnotes in
3485 the included document."
3487 (insert-file-contents file
)
3489 (let* ((lines (split-string lines
"-"))
3490 (lbeg (string-to-number (car lines
)))
3491 (lend (string-to-number (cadr lines
)))
3492 (beg (if (zerop lbeg
) (point-min)
3493 (goto-char (point-min))
3494 (forward-line (1- lbeg
))
3496 (end (if (zerop lend
) (point-max)
3497 (goto-char (point-min))
3498 (forward-line (1- lend
))
3500 (narrow-to-region beg end
)))
3501 ;; Remove blank lines at beginning and end of contents. The logic
3502 ;; behind that removal is that blank lines around include keyword
3503 ;; override blank lines in included file.
3504 (goto-char (point-min))
3505 (org-skip-whitespace)
3507 (delete-region (point-min) (point))
3508 (goto-char (point-max))
3509 (skip-chars-backward " \r\t\n")
3511 (delete-region (point) (point-max))
3512 ;; If IND is set, preserve indentation of include keyword until
3513 ;; the first headline encountered.
3514 (when (and ind
(> ind
0))
3515 (unless (eq major-mode
'org-mode
)
3516 (let ((org-inhibit-startup t
)) (org-mode)))
3517 (goto-char (point-min))
3518 (let ((ind-str (make-string ind ?\s
)))
3519 (while (not (or (eobp) (looking-at org-outline-regexp-bol
)))
3520 ;; Do not move footnote definitions out of column 0.
3521 (unless (and (looking-at org-footnote-definition-re
)
3522 (eq (org-element-type (org-element-at-point))
3523 'footnote-definition
))
3526 ;; When MINLEVEL is specified, compute minimal level for headlines
3527 ;; in the file (CUR-MIN), and remove stars to each headline so
3528 ;; that headlines with minimal level have a level of MINLEVEL.
3530 (unless (eq major-mode
'org-mode
)
3531 (let ((org-inhibit-startup t
)) (org-mode)))
3532 (org-with-limited-levels
3533 (let ((levels (org-map-entries
3534 (lambda () (org-reduced-level (org-current-level))))))
3536 (let ((offset (- minlevel
(apply #'min levels
))))
3537 (unless (zerop offset
)
3538 (when org-odd-levels-only
(setq offset
(* offset
2)))
3539 ;; Only change stars, don't bother moving whole
3543 (if (< offset
0) (delete-char (abs offset
))
3544 (insert (make-string offset ?
*)))))))))))
3545 ;; Append ID to all footnote references and definitions, so they
3546 ;; become file specific and cannot collide with footnotes in other
3547 ;; included files. Further, collect relevant footnote definitions
3548 ;; outside of LINES, in order to reintroduce them later.
3550 (let ((marker-min (point-min-marker))
3551 (marker-max (point-max-marker))
3554 ;; Generate new label from LABEL by prefixing it with
3556 (format "-%d-%s" id label
)))
3559 ;; Replace OLD label with NEW in footnote F.
3561 (goto-char (+ (org-element-property :begin f
) 4))
3562 (looking-at (regexp-quote old
))
3563 (replace-match new
))))
3565 (goto-char (point-min))
3566 (while (re-search-forward org-footnote-re nil t
)
3567 (let ((footnote (save-excursion
3569 (org-element-context))))
3570 (when (memq (org-element-type footnote
)
3571 '(footnote-definition footnote-reference
))
3572 (let* ((label (org-element-property :label footnote
)))
3573 ;; Update the footnote-reference at point and collect
3574 ;; the new label, which is only used for footnotes
3577 (let ((seen (cdr (assoc label seen-alist
))))
3578 (if seen
(funcall set-new-label footnote label seen
)
3579 (let ((new (funcall get-new-label label
)))
3580 (push (cons label new
) seen-alist
)
3581 (org-with-wide-buffer
3582 (let* ((def (org-footnote-get-definition label
))
3585 (or (< beg marker-min
)
3586 (>= beg marker-max
)))
3587 ;; Store since footnote-definition is
3588 ;; outside of LINES.
3590 (org-element-normalize-string (nth 3 def
))
3592 (funcall set-new-label footnote label new
)))))))))
3593 (set-marker marker-min nil
)
3594 (set-marker marker-max nil
)))
3595 (org-element-normalize-string (buffer-string))))
3597 (defun org-export--copy-to-kill-ring-p ()
3598 "Return a non-nil value when output should be added to the kill ring.
3599 See also `org-export-copy-to-kill-ring'."
3600 (if (eq org-export-copy-to-kill-ring
'if-interactive
)
3601 (not (or executing-kbd-macro noninteractive
))
3602 (eq org-export-copy-to-kill-ring t
)))
3606 ;;; Tools For Back-Ends
3608 ;; A whole set of tools is available to help build new exporters. Any
3609 ;; function general enough to have its use across many back-ends
3610 ;; should be added here.
3612 ;;;; For Affiliated Keywords
3614 ;; `org-export-read-attribute' reads a property from a given element
3615 ;; as a plist. It can be used to normalize affiliated keywords'
3618 ;; Since captions can span over multiple lines and accept dual values,
3619 ;; their internal representation is a bit tricky. Therefore,
3620 ;; `org-export-get-caption' transparently returns a given element's
3621 ;; caption as a secondary string.
3623 (defun org-export-read-attribute (attribute element
&optional property
)
3624 "Turn ATTRIBUTE property from ELEMENT into a plist.
3626 When optional argument PROPERTY is non-nil, return the value of
3627 that property within attributes.
3629 This function assumes attributes are defined as \":keyword
3630 value\" pairs. It is appropriate for `:attr_html' like
3633 All values will become strings except the empty string and
3634 \"nil\", which will become nil. Also, values containing only
3635 double quotes will be read as-is, which means that \"\" value
3636 will become the empty string."
3637 (let* ((prepare-value
3640 (cond ((member str
'(nil "" "nil")) nil
)
3641 ((string-match "^\"\\(\"+\\)?\"$" str
)
3642 (or (match-string 1 str
) ""))
3645 (let ((value (org-element-property attribute element
)))
3647 (let ((s (mapconcat 'identity value
" ")) result
)
3648 (while (string-match
3649 "\\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ \t]+\\|$\\)"
3651 (let ((value (substring s
0 (match-beginning 0))))
3652 (push (funcall prepare-value value
) result
))
3653 (push (intern (match-string 1 s
)) result
)
3654 (setq s
(substring s
(match-end 0))))
3655 ;; Ignore any string before first property with `cdr'.
3656 (cdr (nreverse (cons (funcall prepare-value s
) result
))))))))
3657 (if property
(plist-get attributes property
) attributes
)))
3659 (defun org-export-get-caption (element &optional shortp
)
3660 "Return caption from ELEMENT as a secondary string.
3662 When optional argument SHORTP is non-nil, return short caption,
3663 as a secondary string, instead.
3665 Caption lines are separated by a white space."
3666 (let ((full-caption (org-element-property :caption element
)) caption
)
3667 (dolist (line full-caption
(cdr caption
))
3668 (let ((cap (funcall (if shortp
'cdr
'car
) line
)))
3670 (setq caption
(nconc (list " ") (copy-sequence cap
) caption
)))))))
3673 ;;;; For Derived Back-ends
3675 ;; `org-export-with-backend' is a function allowing to locally use
3676 ;; another back-end to transcode some object or element. In a derived
3677 ;; back-end, it may be used as a fall-back function once all specific
3678 ;; cases have been treated.
3680 (defun org-export-with-backend (backend data
&optional contents info
)
3681 "Call a transcoder from BACKEND on DATA.
3682 BACKEND is an export back-end, as returned by, e.g.,
3683 `org-export-create-backend', or a symbol referring to
3684 a registered back-end. DATA is an Org element, object, secondary
3685 string or string. CONTENTS, when non-nil, is the transcoded
3686 contents of DATA element, as a string. INFO, when non-nil, is
3687 the communication channel used for export, as a plist."
3688 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
3689 (org-export-barf-if-invalid-backend backend
)
3690 (let ((type (org-element-type data
)))
3691 (when (memq type
'(nil org-data
)) (error "No foreign transcoder available"))
3692 (let* ((all-transcoders (org-export-get-all-transcoders backend
))
3693 (transcoder (cdr (assq type all-transcoders
))))
3694 (unless (functionp transcoder
) (error "No foreign transcoder available"))
3699 :translate-alist all-transcoders
3700 :exported-data
(make-hash-table :test
#'eq
:size
401)))))
3701 ;; `:internal-references' are shared across back-ends.
3702 (prog1 (funcall transcoder data contents new-info
)
3703 (plist-put info
:internal-references
3704 (plist-get new-info
:internal-references
)))))))
3707 ;;;; For Export Snippets
3709 ;; Every export snippet is transmitted to the back-end. Though, the
3710 ;; latter will only retain one type of export-snippet, ignoring
3711 ;; others, based on the former's target back-end. The function
3712 ;; `org-export-snippet-backend' returns that back-end for a given
3715 (defun org-export-snippet-backend (export-snippet)
3716 "Return EXPORT-SNIPPET targeted back-end as a symbol.
3717 Translation, with `org-export-snippet-translation-alist', is
3719 (let ((back-end (org-element-property :back-end export-snippet
)))
3721 (or (cdr (assoc back-end org-export-snippet-translation-alist
))
3727 ;; `org-export-collect-footnote-definitions' is a tool to list
3728 ;; actually used footnotes definitions in the whole parse tree, or in
3729 ;; a headline, in order to add footnote listings throughout the
3732 ;; `org-export-footnote-first-reference-p' is a predicate used by some
3733 ;; back-ends, when they need to attach the footnote definition only to
3734 ;; the first occurrence of the corresponding label.
3736 ;; `org-export-get-footnote-definition' and
3737 ;; `org-export-get-footnote-number' provide easier access to
3738 ;; additional information relative to a footnote reference.
3740 (defun org-export-get-footnote-definition (footnote-reference info
)
3741 "Return definition of FOOTNOTE-REFERENCE as parsed data.
3742 INFO is the plist used as a communication channel. If no such
3743 definition can be found, raise an error."
3744 (let ((label (org-element-property :label footnote-reference
)))
3745 (if (not label
) (org-element-contents footnote-reference
)
3746 (let ((cache (or (plist-get info
:footnote-definition-cache
)
3747 (let ((hash (make-hash-table :test
#'equal
)))
3748 (plist-put info
:footnote-definition-cache hash
)
3751 (gethash label cache
)
3753 (org-element-map (plist-get info
:parse-tree
)
3754 '(footnote-definition footnote-reference
)
3757 ;; Skip any footnote with a different label.
3758 ;; Also skip any standard footnote reference
3759 ;; with the same label since those cannot
3760 ;; contain a definition.
3761 ((not (equal (org-element-property :label f
) label
)) nil
)
3762 ((eq (org-element-property :type f
) 'standard
) nil
)
3763 ((org-element-contents f
))
3764 ;; Even if the contents are empty, we can not
3765 ;; return nil since that would eventually raise
3766 ;; the error. Instead, return the equivalent
3771 (error "Definition not found for footnote %s" label
))))))
3773 (defun org-export--footnote-reference-map
3774 (function data info
&optional body-first
)
3775 "Apply FUNCTION on every footnote reference in DATA.
3776 INFO is a plist containing export state. By default, as soon as
3777 a new footnote reference is encountered, FUNCTION is called onto
3778 its definition. However, if BODY-FIRST is non-nil, this step is
3779 delayed until the end of the process."
3780 (letrec ((definitions nil
)
3783 (lambda (data delayp
)
3784 ;; Search footnote references through DATA, filling
3785 ;; SEEN-REFS along the way. When DELAYP is non-nil,
3786 ;; store footnote definitions so they can be entered
3788 (org-element-map data
'footnote-reference
3790 (funcall function f
)
3791 (let ((--label (org-element-property :label f
)))
3792 (unless (and --label
(member --label seen-refs
))
3793 (when --label
(push --label seen-refs
))
3794 ;; Search for subsequent references in footnote
3795 ;; definition so numbering follows reading
3796 ;; logic, unless DELAYP in non-nil.
3799 (push (org-export-get-footnote-definition f info
)
3801 ;; Do not force entering inline definitions,
3802 ;; since `org-element-map' already traverses
3803 ;; them at the right time.
3804 ((eq (org-element-property :type f
) 'inline
))
3805 (t (funcall search-ref
3806 (org-export-get-footnote-definition f info
)
3809 ;; Don't enter footnote definitions since it will
3810 ;; happen when their first reference is found.
3811 ;; Moreover, if DELAYP is non-nil, make sure we
3812 ;; postpone entering definitions of inline references.
3813 (if delayp
'(footnote-definition footnote-reference
)
3814 'footnote-definition
)))))
3815 (funcall search-ref data body-first
)
3816 (funcall search-ref
(nreverse definitions
) nil
)))
3818 (defun org-export-collect-footnote-definitions (info &optional data body-first
)
3819 "Return an alist between footnote numbers, labels and definitions.
3821 INFO is the current export state, as a plist.
3823 Definitions are collected throughout the whole parse tree, or
3826 Sorting is done by order of references. As soon as a new
3827 reference is encountered, other references are searched within
3828 its definition. However, if BODY-FIRST is non-nil, this step is
3829 delayed after the whole tree is checked. This alters results
3830 when references are found in footnote definitions.
3832 Definitions either appear as Org data or as a secondary string
3833 for inlined footnotes. Unreferenced definitions are ignored."
3834 (let ((n 0) labels alist
)
3835 (org-export--footnote-reference-map
3837 ;; Collect footnote number, label and definition.
3838 (let ((l (org-element-property :label f
)))
3839 (unless (and l
(member l labels
))
3841 (push (list n l
(org-export-get-footnote-definition f info
)) alist
))
3842 (when l
(push l labels
))))
3843 (or data
(plist-get info
:parse-tree
)) info body-first
)
3846 (defun org-export-footnote-first-reference-p
3847 (footnote-reference info
&optional data body-first
)
3848 "Non-nil when a footnote reference is the first one for its label.
3850 FOOTNOTE-REFERENCE is the footnote reference being considered.
3851 INFO is a plist containing current export state.
3853 Search is done throughout the whole parse tree, or DATA when
3856 By default, as soon as a new footnote reference is encountered,
3857 other references are searched within its definition. However, if
3858 BODY-FIRST is non-nil, this step is delayed after the whole tree
3859 is checked. This alters results when references are found in
3860 footnote definitions."
3861 (let ((label (org-element-property :label footnote-reference
)))
3862 ;; Anonymous footnotes are always a first reference.
3865 (org-export--footnote-reference-map
3867 (let ((l (org-element-property :label f
)))
3868 (when (and l label
(string= label l
))
3869 (throw 'exit
(eq footnote-reference f
)))))
3870 (or data
(plist-get info
:parse-tree
)) info body-first
)))))
3872 (defun org-export-get-footnote-number (footnote info
&optional data body-first
)
3873 "Return number associated to a footnote.
3875 FOOTNOTE is either a footnote reference or a footnote definition.
3876 INFO is the plist containing export state.
3878 Number is unique throughout the whole parse tree, or DATA, when
3881 By default, as soon as a new footnote reference is encountered,
3882 counting process moves into its definition. However, if
3883 BODY-FIRST is non-nil, this step is delayed until the end of the
3884 process, leading to a different order when footnotes are nested."
3887 (label (org-element-property :label footnote
)))
3889 (org-export--footnote-reference-map
3891 (let ((l (org-element-property :label f
)))
3893 ;; Anonymous footnote match: return number.
3894 ((and (not l
) (not label
) (eq footnote f
)) (throw 'exit
(1+ count
)))
3895 ;; Labels match: return number.
3896 ((and label l
(string= label l
)) (throw 'exit
(1+ count
)))
3897 ;; Otherwise store label and increase counter if label
3898 ;; wasn't encountered yet.
3899 ((not l
) (cl-incf count
))
3900 ((not (member l seen
)) (push l seen
) (cl-incf count
)))))
3901 (or data
(plist-get info
:parse-tree
)) info body-first
))))
3906 ;; `org-export-get-relative-level' is a shortcut to get headline
3907 ;; level, relatively to the lower headline level in the parsed tree.
3909 ;; `org-export-get-headline-number' returns the section number of an
3910 ;; headline, while `org-export-number-to-roman' allows it to be
3911 ;; converted to roman numbers. With an optional argument,
3912 ;; `org-export-get-headline-number' returns a number to unnumbered
3913 ;; headlines (used for internal id).
3915 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
3916 ;; `org-export-last-sibling-p' are three useful predicates when it
3917 ;; comes to fulfill the `:headline-levels' property.
3919 ;; `org-export-get-tags', `org-export-get-category' and
3920 ;; `org-export-get-node-property' extract useful information from an
3921 ;; headline or a parent headline. They all handle inheritance.
3923 ;; `org-export-get-alt-title' tries to retrieve an alternative title,
3924 ;; as a secondary string, suitable for table of contents. It falls
3925 ;; back onto default title.
3927 (defun org-export-get-relative-level (headline info
)
3928 "Return HEADLINE relative level within current parsed tree.
3929 INFO is a plist holding contextual information."
3930 (+ (org-element-property :level headline
)
3931 (or (plist-get info
:headline-offset
) 0)))
3933 (defun org-export-low-level-p (headline info
)
3934 "Non-nil when HEADLINE is considered as low level.
3936 INFO is a plist used as a communication channel.
3938 A low level headlines has a relative level greater than
3939 `:headline-levels' property value.
3941 Return value is the difference between HEADLINE relative level
3942 and the last level being considered as high enough, or nil."
3943 (let ((limit (plist-get info
:headline-levels
)))
3944 (when (wholenump limit
)
3945 (let ((level (org-export-get-relative-level headline info
)))
3946 (and (> level limit
) (- level limit
))))))
3948 (defun org-export-get-headline-number (headline info
)
3949 "Return numbered HEADLINE numbering as a list of numbers.
3950 INFO is a plist holding contextual information."
3951 (and (org-export-numbered-headline-p headline info
)
3952 (cdr (assq headline
(plist-get info
:headline-numbering
)))))
3954 (defun org-export-numbered-headline-p (headline info
)
3955 "Return a non-nil value if HEADLINE element should be numbered.
3956 INFO is a plist used as a communication channel."
3958 (lambda (head) (org-not-nil (org-element-property :UNNUMBERED head
)))
3959 (org-element-lineage headline nil t
))
3960 (let ((sec-num (plist-get info
:section-numbers
))
3961 (level (org-export-get-relative-level headline info
)))
3962 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))))
3964 (defun org-export-number-to-roman (n)
3965 "Convert integer N into a roman numeral."
3966 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
3967 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
3968 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
3972 (number-to-string n
)
3974 (if (>= n
(caar roman
))
3975 (setq n
(- n
(caar roman
))
3976 res
(concat res
(cdar roman
)))
3980 (defun org-export-get-tags (element info
&optional tags inherited
)
3981 "Return list of tags associated to ELEMENT.
3983 ELEMENT has either an `headline' or an `inlinetask' type. INFO
3984 is a plist used as a communication channel.
3986 When non-nil, optional argument TAGS should be a list of strings.
3987 Any tag belonging to this list will also be removed.
3989 When optional argument INHERITED is non-nil, tags can also be
3990 inherited from parent headlines and FILETAGS keywords."
3992 (lambda (tag) (member tag tags
))
3993 (if (not inherited
) (org-element-property :tags element
)
3994 ;; Build complete list of inherited tags.
3995 (let ((current-tag-list (org-element-property :tags element
)))
3996 (dolist (parent (org-element-lineage element
))
3997 (dolist (tag (org-element-property :tags parent
))
3998 (when (and (memq (org-element-type parent
) '(headline inlinetask
))
3999 (not (member tag current-tag-list
)))
4000 (push tag current-tag-list
))))
4001 ;; Add FILETAGS keywords and return results.
4002 (org-uniquify (append (plist-get info
:filetags
) current-tag-list
))))))
4004 (defun org-export-get-node-property (property blob
&optional inherited
)
4005 "Return node PROPERTY value for BLOB.
4007 PROPERTY is an upcase symbol (i.e. `:COOKIE_DATA'). BLOB is an
4010 If optional argument INHERITED is non-nil, the value can be
4011 inherited from a parent headline.
4013 Return value is a string or nil."
4014 (let ((headline (if (eq (org-element-type blob
) 'headline
) blob
4015 (org-export-get-parent-headline blob
))))
4016 (if (not inherited
) (org-element-property property blob
)
4017 (let ((parent headline
))
4020 (when (plist-member (nth 1 parent
) property
)
4021 (throw 'found
(org-element-property property parent
)))
4022 (setq parent
(org-element-property :parent parent
))))))))
4024 (defun org-export-get-category (blob info
)
4025 "Return category for element or object BLOB.
4027 INFO is a plist used as a communication channel.
4029 CATEGORY is automatically inherited from a parent headline, from
4030 #+CATEGORY: keyword or created out of original file name. If all
4031 fail, the fall-back value is \"???\"."
4032 (or (org-export-get-node-property :CATEGORY blob t
)
4033 (org-element-map (plist-get info
:parse-tree
) 'keyword
4035 (when (equal (org-element-property :key kwd
) "CATEGORY")
4036 (org-element-property :value kwd
)))
4038 (let ((file (plist-get info
:input-file
)))
4039 (and file
(file-name-sans-extension (file-name-nondirectory file
))))
4042 (defun org-export-get-alt-title (headline _
)
4043 "Return alternative title for HEADLINE, as a secondary string.
4044 If no optional title is defined, fall-back to the regular title."
4045 (let ((alt (org-element-property :ALT_TITLE headline
)))
4046 (if alt
(org-element-parse-secondary-string
4047 alt
(org-element-restriction 'headline
) headline
)
4048 (org-element-property :title headline
))))
4050 (defun org-export-first-sibling-p (blob info
)
4051 "Non-nil when BLOB is the first sibling in its parent.
4052 BLOB is an element or an object. If BLOB is a headline, non-nil
4053 means it is the first sibling in the sub-tree. INFO is a plist
4054 used as a communication channel."
4055 (memq (org-element-type (org-export-get-previous-element blob info
))
4058 (defun org-export-last-sibling-p (blob info
)
4059 "Non-nil when BLOB is the last sibling in its parent.
4060 BLOB is an element or an object. INFO is a plist used as
4061 a communication channel."
4062 (not (org-export-get-next-element blob info
)))
4067 ;; `org-export-get-date' returns a date appropriate for the document
4068 ;; to about to be exported. In particular, it takes care of
4069 ;; `org-export-date-timestamp-format'.
4071 (defun org-export-get-date (info &optional fmt
)
4072 "Return date value for the current document.
4074 INFO is a plist used as a communication channel. FMT, when
4075 non-nil, is a time format string that will be applied on the date
4076 if it consists in a single timestamp object. It defaults to
4077 `org-export-date-timestamp-format' when nil.
4079 A proper date can be a secondary string, a string or nil. It is
4080 meant to be translated with `org-export-data' or alike."
4081 (let ((date (plist-get info
:date
))
4082 (fmt (or fmt org-export-date-timestamp-format
)))
4083 (cond ((not date
) nil
)
4086 (eq (org-element-type (car date
)) 'timestamp
))
4087 (org-timestamp-format (car date
) fmt
))
4093 ;; `org-export-custom-protocol-maybe' handles custom protocol defined
4094 ;; in `org-link-parameters'.
4096 ;; `org-export-get-coderef-format' returns an appropriate format
4097 ;; string for coderefs.
4099 ;; `org-export-inline-image-p' returns a non-nil value when the link
4100 ;; provided should be considered as an inline image.
4102 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
4103 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
4104 ;; returns an appropriate unique identifier.
4106 ;; `org-export-resolve-id-link' returns the first headline with
4107 ;; specified id or custom-id in parse tree, the path to the external
4108 ;; file with the id.
4110 ;; `org-export-resolve-coderef' associates a reference to a line
4111 ;; number in the element it belongs, or returns the reference itself
4112 ;; when the element isn't numbered.
4114 ;; `org-export-file-uri' expands a filename as stored in :path value
4115 ;; of a "file" link into a file URI.
4117 ;; Broken links raise a `org-link-broken' error, which is caught by
4118 ;; `org-export-data' for further processing, depending on
4119 ;; `org-export-with-broken-links' value.
4121 (org-define-error 'org-link-broken
"Unable to resolve link; aborting")
4123 (defun org-export-custom-protocol-maybe (link desc backend
)
4124 "Try exporting LINK with a dedicated function.
4126 DESC is its description, as a string, or nil. BACKEND is the
4127 back-end used for export, as a symbol.
4129 Return output as a string, or nil if no protocol handles LINK.
4131 A custom protocol has precedence over regular back-end export.
4132 The function ignores links with an implicit type (e.g.,
4134 (let ((type (org-element-property :type link
)))
4135 (unless (or (member type
'("coderef" "custom-id" "fuzzy" "radio"))
4137 (let ((protocol (org-link-get-parameter type
:export
)))
4138 (and (functionp protocol
)
4140 (org-link-unescape (org-element-property :path link
))
4144 (defun org-export-get-coderef-format (path desc
)
4145 "Return format string for code reference link.
4146 PATH is the link path. DESC is its description."
4148 (cond ((not desc
) "%s")
4149 ((string-match (regexp-quote (concat "(" path
")")) desc
)
4150 (replace-match "%s" t t desc
))
4153 (defun org-export-inline-image-p (link &optional rules
)
4154 "Non-nil if LINK object points to an inline image.
4156 Optional argument is a set of RULES defining inline images. It
4157 is an alist where associations have the following shape:
4161 Applying a rule means apply REGEXP against LINK's path when its
4162 type is TYPE. The function will return a non-nil value if any of
4163 the provided rules is non-nil. The default rule is
4164 `org-export-default-inline-image-rule'.
4166 This only applies to links without a description."
4167 (and (not (org-element-contents link
))
4168 (let ((case-fold-search t
))
4169 (cl-some (lambda (rule)
4170 (and (string= (org-element-property :type link
) (car rule
))
4171 (string-match-p (cdr rule
)
4172 (org-element-property :path link
))))
4173 (or rules org-export-default-inline-image-rule
)))))
4175 (defun org-export-insert-image-links (data info
&optional rules
)
4176 "Insert image links in DATA.
4178 Org syntax does not support nested links. Nevertheless, some
4179 export back-ends support images as descriptions of links. Since
4180 images are really links to image files, we need to make an
4181 exception about links nesting.
4183 This function recognizes links whose contents are really images
4184 and turn them into proper nested links. It is meant to be used
4185 as a parse tree filter in back-ends supporting such constructs.
4187 DATA is a parse tree. INFO is the current state of the export
4188 process, as a plist.
4190 A description is a valid images if it matches any rule in RULES,
4191 if non-nil, or `org-export-default-inline-image-rule' otherwise.
4192 See `org-export-inline-image-p' for more information about the
4195 Return modified DATA."
4196 (let ((link-re (format "\\`\\(?:%s\\|%s\\)\\'"
4199 (case-fold-search t
))
4200 (org-element-map data
'link
4202 (let ((contents (org-element-interpret-data (org-element-contents l
))))
4203 (when (and (org-string-nw-p contents
)
4204 (string-match link-re contents
))
4205 (let ((type (match-string 1 contents
))
4206 (path (match-string 2 contents
)))
4207 (when (cl-some (lambda (rule)
4208 (and (string= type
(car rule
))
4209 (string-match-p (cdr rule
) path
)))
4210 (or rules org-export-default-inline-image-rule
))
4211 ;; Replace contents with image link.
4212 (org-element-adopt-elements
4213 (org-element-set-contents l nil
)
4215 (save-excursion (insert contents
))
4216 (org-element-link-parser))))))))
4220 (defun org-export-resolve-coderef (ref info
)
4221 "Resolve a code reference REF.
4223 INFO is a plist used as a communication channel.
4225 Return associated line number in source code, or REF itself,
4226 depending on src-block or example element's switches. Throw an
4227 error if no block contains REF."
4228 (or (org-element-map (plist-get info
:parse-tree
) '(example-block src-block
)
4231 (insert (org-trim (org-element-property :value el
)))
4232 (let* ((label-fmt (or (org-element-property :label-fmt el
)
4233 org-coderef-label-format
))
4234 (ref-re (org-src-coderef-regexp label-fmt ref
)))
4235 ;; Element containing REF is found. Resolve it to
4236 ;; either a label or a line number, as needed.
4237 (when (re-search-backward ref-re nil t
)
4238 (if (org-element-property :use-labels el
) ref
4239 (+ (or (org-export-get-loc el info
) 0)
4240 (line-number-at-pos)))))))
4242 (signal 'org-link-broken
(list ref
))))
4244 (defun org-export-search-cells (datum)
4245 "List search cells for element or object DATUM.
4247 A search cell follows the pattern (TYPE . SEARCH) where
4249 TYPE is a symbol among `headline', `custom-id', `target' and
4252 SEARCH is the string a link is expected to match. More
4255 - headline's title, as a list of strings, if TYPE is
4258 - CUSTOM_ID value, as a string, if TYPE is `custom-id'.
4260 - target's or radio-target's name as a list of strings if
4263 - NAME affiliated keyword is TYPE is `other'.
4265 A search cell is the internal representation of a fuzzy link. It
4266 ignores white spaces and statistics cookies, if applicable."
4267 (pcase (org-element-type datum
)
4269 (let ((title (split-string
4270 (replace-regexp-in-string
4271 "\\[[0-9]*\\(?:%\\|/[0-9]*\\)\\]" ""
4272 (org-element-property :raw-value datum
)))))
4275 (cons 'headline title
)
4277 (let ((custom-id (org-element-property :custom-id datum
)))
4278 (and custom-id
(cons 'custom-id custom-id
)))))))
4280 (list (cons 'target
(split-string (org-element-property :value datum
)))))
4281 ((and (let name
(org-element-property :name datum
))
4283 (list (cons 'other
(split-string name
))))
4286 (defun org-export-string-to-search-cell (s)
4287 "Return search cells associated to string S.
4288 S is either the path of a fuzzy link or a search option, i.e., it
4289 tries to match either a headline (through custom ID or title),
4290 a target or a named element."
4291 (pcase (string-to-char s
)
4292 (?
* (list (cons 'headline
(split-string (substring s
1)))))
4293 (?
# (list (cons 'custom-id
(substring s
1))))
4294 ((let search
(split-string s
))
4295 (list (cons 'target search
) (cons 'other search
)))))
4297 (defun org-export-match-search-cell-p (datum cells
)
4298 "Non-nil when DATUM matches search cells CELLS.
4299 DATUM is an element or object. CELLS is a list of search cells,
4300 as returned by `org-export-search-cells'."
4301 (let ((targets (org-export-search-cells datum
)))
4302 (and targets
(cl-some (lambda (cell) (member cell targets
)) cells
))))
4304 (defun org-export-resolve-fuzzy-link (link info
)
4305 "Return LINK destination.
4307 INFO is a plist holding contextual information.
4309 Return value can be an object or an element:
4311 - If LINK path matches a target object (i.e. <<path>>) return it.
4313 - If LINK path exactly matches the name affiliated keyword
4314 (i.e. #+NAME: path) of an element, return that element.
4316 - If LINK path exactly matches any headline name, return that
4319 - Otherwise, throw an error.
4321 Assume LINK type is \"fuzzy\". White spaces are not
4323 (let* ((search-cells (org-export-string-to-search-cell
4324 (org-link-unescape (org-element-property :path link
))))
4325 (link-cache (or (plist-get info
:resolve-fuzzy-link-cache
)
4326 (let ((table (make-hash-table :test
#'eq
)))
4327 (plist-put info
:resolve-fuzzy-link-cache table
)
4329 (cached (gethash search-cells link-cache
'not-found
)))
4330 (if (not (eq cached
'not-found
)) cached
4332 (org-element-map (plist-get info
:parse-tree
)
4333 (cons 'target org-element-all-elements
)
4335 (and (org-export-match-search-cell-p datum search-cells
)
4338 (signal 'org-link-broken
(list (org-element-property :path link
))))
4341 ;; There can be multiple matches for un-typed searches, i.e.,
4342 ;; for searches not starting with # or *. In this case,
4343 ;; prioritize targets and names over headline titles.
4344 ;; Matching both a name and a target is not valid, and
4345 ;; therefore undefined.
4346 (or (cl-some (lambda (datum)
4347 (and (not (eq (org-element-type datum
) 'headline
))
4353 (defun org-export-resolve-id-link (link info
)
4354 "Return headline referenced as LINK destination.
4356 INFO is a plist used as a communication channel.
4358 Return value can be the headline element matched in current parse
4359 tree or a file name. Assume LINK type is either \"id\" or
4360 \"custom-id\". Throw an error if no match is found."
4361 (let ((id (org-element-property :path link
)))
4362 ;; First check if id is within the current parse tree.
4363 (or (org-element-map (plist-get info
:parse-tree
) 'headline
4365 (when (or (equal (org-element-property :ID headline
) id
)
4366 (equal (org-element-property :CUSTOM_ID headline
) id
))
4369 ;; Otherwise, look for external files.
4370 (cdr (assoc id
(plist-get info
:id-alist
)))
4371 (signal 'org-link-broken
(list id
)))))
4373 (defun org-export-resolve-radio-link (link info
)
4374 "Return radio-target object referenced as LINK destination.
4376 INFO is a plist used as a communication channel.
4378 Return value can be a radio-target object or nil. Assume LINK
4379 has type \"radio\"."
4380 (let ((path (replace-regexp-in-string
4381 "[ \r\t\n]+" " " (org-element-property :path link
))))
4382 (org-element-map (plist-get info
:parse-tree
) 'radio-target
4384 (and (eq (compare-strings
4385 (replace-regexp-in-string
4386 "[ \r\t\n]+" " " (org-element-property :value radio
))
4387 nil nil path nil nil t
)
4390 info
'first-match
)))
4392 (defun org-export-file-uri (filename)
4393 "Return file URI associated to FILENAME."
4394 (cond ((string-prefix-p "//" filename
) (concat "file:" filename
))
4395 ((not (file-name-absolute-p filename
)) filename
)
4396 ((org-file-remote-p filename
) (concat "file:/" filename
))
4398 (let ((fullname (expand-file-name filename
)))
4399 (concat (if (string-prefix-p "/" fullname
) "file://" "file:///")
4404 ;; `org-export-get-reference' associate a unique reference for any
4405 ;; object or element. It uses `org-export-new-reference' and
4406 ;; `org-export-format-reference' to, respectively, generate new
4407 ;; internal references and turn them into a string suitable for
4410 ;; `org-export-get-ordinal' associates a sequence number to any object
4413 (defun org-export-new-reference (references)
4414 "Return a unique reference, among REFERENCES.
4415 REFERENCES is an alist whose values are in-use references, as
4416 numbers. Returns a number, which is the internal representation
4417 of a reference. See also `org-export-format-reference'."
4418 ;; Generate random 7 digits hexadecimal numbers. Collisions
4419 ;; increase exponentially with the numbers of references. However,
4420 ;; the odds for encountering at least one collision with 1000 active
4421 ;; references in the same document are roughly 0.2%, so this
4422 ;; shouldn't be the bottleneck.
4423 (let ((new (random #x10000000
)))
4424 (while (rassq new references
) (setq new
(random #x10000000
)))
4427 (defun org-export-format-reference (reference)
4428 "Format REFERENCE into a string.
4429 REFERENCE is a number representing a reference, as returned by
4430 `org-export-new-reference', which see."
4431 (format "org%07x" reference
))
4433 (defun org-export-get-reference (datum info
)
4434 "Return a unique reference for DATUM, as a string.
4436 DATUM is either an element or an object. INFO is the current
4437 export state, as a plist.
4439 This function checks `:crossrefs' property in INFO for search
4440 cells matching DATUM before creating a new reference. Returned
4441 reference consists of alphanumeric characters only."
4442 (let ((cache (plist-get info
:internal-references
)))
4443 (or (car (rassq datum cache
))
4444 (let* ((crossrefs (plist-get info
:crossrefs
))
4445 (cells (org-export-search-cells datum
))
4446 ;; Preserve any pre-existing association between
4447 ;; a search cell and a reference, i.e., when some
4448 ;; previously published document referenced a location
4449 ;; within current file (see
4450 ;; `org-publish-resolve-external-link').
4452 ;; However, there is no guarantee that search cells are
4453 ;; unique, e.g., there might be duplicate custom ID or
4454 ;; two headings with the same title in the file.
4456 ;; As a consequence, before re-using any reference to
4457 ;; an element or object, we check that it doesn't refer
4458 ;; to a previous element or object.
4461 (let ((stored (cdr (assoc cell crossrefs
))))
4463 (let ((old (org-export-format-reference stored
)))
4464 (and (not (assoc old cache
)) stored
)))))
4466 (org-export-new-reference cache
)))
4467 (reference-string (org-export-format-reference new
)))
4468 ;; Cache contains both data already associated to
4469 ;; a reference and in-use internal references, so as to make
4470 ;; unique references.
4471 (dolist (cell cells
) (push (cons cell new
) cache
))
4472 ;; Retain a direct association between reference string and
4473 ;; DATUM since (1) not every object or element can be given
4474 ;; a search cell (2) it permits quick lookup.
4475 (push (cons reference-string datum
) cache
)
4476 (plist-put info
:internal-references cache
)
4477 reference-string
))))
4479 (defun org-export-get-ordinal (element info
&optional types predicate
)
4480 "Return ordinal number of an element or object.
4482 ELEMENT is the element or object considered. INFO is the plist
4483 used as a communication channel.
4485 Optional argument TYPES, when non-nil, is a list of element or
4486 object types, as symbols, that should also be counted in.
4487 Otherwise, only provided element's type is considered.
4489 Optional argument PREDICATE is a function returning a non-nil
4490 value if the current element or object should be counted in. It
4491 accepts two arguments: the element or object being considered and
4492 the plist used as a communication channel. This allows counting
4493 only a certain type of object (i.e. inline images).
4495 Return value is a list of numbers if ELEMENT is a headline or an
4496 item. It is nil for keywords. It represents the footnote number
4497 for footnote definitions and footnote references. If ELEMENT is
4498 a target, return the same value as if ELEMENT was the closest
4499 table, item or headline containing the target. In any other
4500 case, return the sequence number of ELEMENT among elements or
4501 objects of the same type."
4502 ;; Ordinal of a target object refer to the ordinal of the closest
4503 ;; table, item, or headline containing the object.
4504 (when (eq (org-element-type element
) 'target
)
4506 (org-element-lineage
4508 '(footnote-definition footnote-reference headline item table
))))
4509 (cl-case (org-element-type element
)
4510 ;; Special case 1: A headline returns its number as a list.
4511 (headline (org-export-get-headline-number element info
))
4512 ;; Special case 2: An item returns its number as a list.
4513 (item (let ((struct (org-element-property :structure element
)))
4514 (org-list-get-item-number
4515 (org-element-property :begin element
)
4517 (org-list-prevs-alist struct
)
4518 (org-list-parents-alist struct
))))
4519 ((footnote-definition footnote-reference
)
4520 (org-export-get-footnote-number element info
))
4523 ;; Increment counter until ELEMENT is found again.
4524 (org-element-map (plist-get info
:parse-tree
)
4525 (or types
(org-element-type element
))
4528 ((eq element el
) (1+ counter
))
4529 ((not predicate
) (cl-incf counter
) nil
)
4530 ((funcall predicate el info
) (cl-incf counter
) nil
)))
4531 info
'first-match
)))))
4536 ;; `org-export-get-loc' counts number of code lines accumulated in
4537 ;; src-block or example-block elements with a "+n" switch until
4538 ;; a given element, excluded. Note: "-n" switches reset that count.
4540 ;; `org-export-unravel-code' extracts source code (along with a code
4541 ;; references alist) from an `element-block' or `src-block' type
4544 ;; `org-export-format-code' applies a formatting function to each line
4545 ;; of code, providing relative line number and code reference when
4546 ;; appropriate. Since it doesn't access the original element from
4547 ;; which the source code is coming, it expects from the code calling
4548 ;; it to know if lines should be numbered and if code references
4551 ;; Eventually, `org-export-format-code-default' is a higher-level
4552 ;; function (it makes use of the two previous functions) which handles
4553 ;; line numbering and code references inclusion, and returns source
4554 ;; code in a format suitable for plain text or verbatim output.
4556 (defun org-export-get-loc (element info
)
4557 "Return count of lines of code before ELEMENT.
4559 ELEMENT is an example-block or src-block element. INFO is the
4560 plist used as a communication channel.
4562 Count includes every line of code in example-block or src-block
4563 with a \"+n\" or \"-n\" switch before block. Return nil if
4564 ELEMENT doesn't allow line numbering."
4565 (pcase (org-element-property :number-lines element
)
4569 (org-element-map (plist-get info
:parse-tree
) '(src-block example-block
)
4571 ;; ELEMENT is reached: Quit loop and return locs.
4572 (if (eq el element
) (+ loc n
)
4573 ;; Only count lines from src-block and example-block
4574 ;; elements with a "+n" or "-n" switch.
4575 (let ((linum (org-element-property :number-lines el
)))
4577 (let ((lines (org-count-lines
4578 (org-element-property :value el
))))
4579 ;; Accumulate locs or reset them.
4581 (`(new .
,n
) (setq loc
(+ n lines
)))
4582 (`(continued .
,n
) (cl-incf loc
(+ n lines
)))))))
4583 nil
)) ;Return nil to stay in the loop.
4584 info
'first-match
)))))
4586 (defun org-export-unravel-code (element)
4587 "Clean source code and extract references out of it.
4589 ELEMENT has either a `src-block' an `example-block' type.
4591 Return a cons cell whose CAR is the source code, cleaned from any
4592 reference, protective commas and spurious indentation, and CDR is
4593 an alist between relative line number (integer) and name of code
4594 reference on that line (string)."
4595 (let* ((line 0) refs
4596 (value (org-element-property :value element
))
4597 ;; Remove global indentation from code, if necessary. Also
4598 ;; remove final newline character, since it doesn't belongs
4599 ;; to the code proper.
4600 (code (replace-regexp-in-string
4602 (if (or org-src-preserve-indentation
4603 (org-element-property :preserve-indent element
))
4605 (org-remove-indentation value
))))
4606 ;; Build a regexp matching a loc with a reference.
4607 (ref-re (org-src-coderef-regexp (org-src-coderef-format element
))))
4610 ;; Code with references removed.
4614 (if (not (string-match ref-re loc
)) loc
4615 ;; Ref line: remove ref, and add its position in REFS.
4616 (push (cons line
(match-string 3 loc
)) refs
)
4617 (replace-match "" nil nil loc
1)))
4618 (split-string code
"\n") "\n")
4622 (defun org-export-format-code (code fun
&optional num-lines ref-alist
)
4623 "Format CODE by applying FUN line-wise and return it.
4625 CODE is a string representing the code to format. FUN is
4626 a function. It must accept three arguments: a line of
4627 code (string), the current line number (integer) or nil and the
4628 reference associated to the current line (string) or nil.
4630 Optional argument NUM-LINES can be an integer representing the
4631 number of code lines accumulated until the current code. Line
4632 numbers passed to FUN will take it into account. If it is nil,
4633 FUN's second argument will always be nil. This number can be
4634 obtained with `org-export-get-loc' function.
4636 Optional argument REF-ALIST can be an alist between relative line
4637 number (i.e. ignoring NUM-LINES) and the name of the code
4638 reference on it. If it is nil, FUN's third argument will always
4639 be nil. It can be obtained through the use of
4640 `org-export-unravel-code' function."
4641 (let ((--locs (split-string code
"\n"))
4647 (let ((--ref (cdr (assq --line ref-alist
))))
4648 (funcall fun --loc
(and num-lines
(+ num-lines --line
)) --ref
)))
4652 (defun org-export-format-code-default (element info
)
4653 "Return source code from ELEMENT, formatted in a standard way.
4655 ELEMENT is either a `src-block' or `example-block' element. INFO
4656 is a plist used as a communication channel.
4658 This function takes care of line numbering and code references
4659 inclusion. Line numbers, when applicable, appear at the
4660 beginning of the line, separated from the code by two white
4661 spaces. Code references, on the other hand, appear flushed to
4662 the right, separated by six white spaces from the widest line of
4664 ;; Extract code and references.
4665 (let* ((code-info (org-export-unravel-code element
))
4666 (code (car code-info
))
4667 (code-lines (split-string code
"\n")))
4668 (if (null code-lines
) ""
4669 (let* ((refs (and (org-element-property :retain-labels element
)
4671 ;; Handle line numbering.
4672 (num-start (org-export-get-loc element info
))
4676 (length (number-to-string
4677 (+ (length code-lines
) num-start
))))))
4678 ;; Prepare references display, if required. Any reference
4679 ;; should start six columns after the widest line of code,
4680 ;; wrapped with parenthesis.
4682 (+ (apply 'max
(mapcar 'length code-lines
))
4683 (if (not num-start
) 0 (length (format num-fmt num-start
))))))
4684 (org-export-format-code
4686 (lambda (loc line-num ref
)
4687 (let ((number-str (and num-fmt
(format num-fmt line-num
))))
4692 (concat (make-string (- (+ 6 max-width
)
4693 (+ (length loc
) (length number-str
)))
4695 (format "(%s)" ref
))))))
4701 ;; `org-export-table-has-special-column-p' and and
4702 ;; `org-export-table-row-is-special-p' are predicates used to look for
4703 ;; meta-information about the table structure.
4705 ;; `org-table-has-header-p' tells when the rows before the first rule
4706 ;; should be considered as table's header.
4708 ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
4709 ;; and `org-export-table-cell-borders' extract information from
4710 ;; a table-cell element.
4712 ;; `org-export-table-dimensions' gives the number on rows and columns
4713 ;; in the table, ignoring horizontal rules and special columns.
4714 ;; `org-export-table-cell-address', given a table-cell object, returns
4715 ;; the absolute address of a cell. On the other hand,
4716 ;; `org-export-get-table-cell-at' does the contrary.
4718 ;; `org-export-table-cell-starts-colgroup-p',
4719 ;; `org-export-table-cell-ends-colgroup-p',
4720 ;; `org-export-table-row-starts-rowgroup-p',
4721 ;; `org-export-table-row-ends-rowgroup-p',
4722 ;; `org-export-table-row-starts-header-p',
4723 ;; `org-export-table-row-ends-header-p' and
4724 ;; `org-export-table-row-in-header-p' indicate position of current row
4725 ;; or cell within the table.
4727 (defun org-export-table-has-special-column-p (table)
4728 "Non-nil when TABLE has a special column.
4729 All special columns will be ignored during export."
4730 ;; The table has a special column when every first cell of every row
4731 ;; has an empty value or contains a symbol among "/", "#", "!", "$",
4732 ;; "*" "_" and "^". Though, do not consider a first column
4733 ;; containing only empty cells as special.
4734 (let ((special-column?
'empty
))
4736 (dolist (row (org-element-contents table
))
4737 (when (eq (org-element-property :type row
) 'standard
)
4738 (let ((value (org-element-contents
4739 (car (org-element-contents row
)))))
4740 (cond ((member value
4741 '(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
4742 (setq special-column?
'special
))
4744 (t (throw 'exit nil
))))))
4745 (eq special-column?
'special
))))
4747 (defun org-export-table-has-header-p (table info
)
4748 "Non-nil when TABLE has a header.
4750 INFO is a plist used as a communication channel.
4752 A table has a header when it contains at least two row groups."
4753 (let* ((cache (or (plist-get info
:table-header-cache
)
4754 (let ((table (make-hash-table :test
#'eq
)))
4755 (plist-put info
:table-header-cache table
)
4757 (cached (gethash table cache
'no-cache
)))
4758 (if (not (eq cached
'no-cache
)) cached
4759 (let ((rowgroup 1) row-flag
)
4761 (org-element-map table
'table-row
4766 (eq (org-element-property :type row
) 'rule
))
4768 (setq row-flag nil
))
4769 ((and (not row-flag
)
4770 (eq (org-element-property :type row
) 'standard
))
4776 (defun org-export-table-row-is-special-p (table-row _
)
4777 "Non-nil if TABLE-ROW is considered special.
4778 All special rows will be ignored during export."
4779 (when (eq (org-element-property :type table-row
) 'standard
)
4780 (let ((first-cell (org-element-contents
4781 (car (org-element-contents table-row
)))))
4782 ;; A row is special either when...
4784 ;; ... it starts with a field only containing "/",
4785 (equal first-cell
'("/"))
4786 ;; ... the table contains a special column and the row start
4787 ;; with a marking character among, "^", "_", "$" or "!",
4788 (and (org-export-table-has-special-column-p
4789 (org-export-get-parent table-row
))
4790 (member first-cell
'(("^") ("_") ("$") ("!"))))
4791 ;; ... it contains only alignment cookies and empty cells.
4792 (let ((special-row-p 'empty
))
4794 (dolist (cell (org-element-contents table-row
))
4795 (let ((value (org-element-contents cell
)))
4796 ;; Since VALUE is a secondary string, the following
4797 ;; checks avoid expanding it with `org-export-data'.
4799 ((and (not (cdr value
))
4800 (stringp (car value
))
4801 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
4803 (setq special-row-p
'cookie
))
4804 (t (throw 'exit nil
)))))
4805 (eq special-row-p
'cookie
)))))))
4807 (defun org-export-table-row-group (table-row info
)
4808 "Return TABLE-ROW's group number, as an integer.
4810 INFO is a plist used as the communication channel.
4812 Return value is the group number, as an integer, or nil for
4813 special rows and rows separators. First group is also table's
4815 (when (eq (org-element-property :type table-row
) 'standard
)
4816 (let* ((cache (or (plist-get info
:table-row-group-cache
)
4817 (let ((table (make-hash-table :test
#'eq
)))
4818 (plist-put info
:table-row-group-cache table
)
4820 (cached (gethash table-row cache
'no-cache
)))
4821 (if (not (eq cached
'no-cache
)) cached
4822 ;; First time a row is queried, populate cache with all the
4823 ;; rows from the table.
4824 (let ((group 0) row-flag
)
4825 (org-element-map (org-export-get-parent table-row
) 'table-row
4827 (if (eq (org-element-property :type row
) 'rule
)
4829 (unless row-flag
(cl-incf group
) (setq row-flag t
))
4830 (puthash row group cache
)))
4832 (gethash table-row cache
)))))
4834 (defun org-export-table-cell-width (table-cell info
)
4835 "Return TABLE-CELL contents width.
4837 INFO is a plist used as the communication channel.
4839 Return value is the width given by the last width cookie in the
4840 same column as TABLE-CELL, or nil."
4841 (let* ((row (org-export-get-parent table-cell
))
4842 (table (org-export-get-parent row
))
4843 (cells (org-element-contents row
))
4844 (columns (length cells
))
4845 (column (- columns
(length (memq table-cell cells
))))
4846 (cache (or (plist-get info
:table-cell-width-cache
)
4847 (let ((table (make-hash-table :test
#'eq
)))
4848 (plist-put info
:table-cell-width-cache table
)
4850 (width-vector (or (gethash table cache
)
4851 (puthash table
(make-vector columns
'empty
) cache
)))
4852 (value (aref width-vector column
)))
4853 (if (not (eq value
'empty
)) value
4855 (dolist (row (org-element-contents table
)
4856 (aset width-vector column cookie-width
))
4857 (when (org-export-table-row-is-special-p row info
)
4858 ;; In a special row, try to find a width cookie at COLUMN.
4859 (let* ((value (org-element-contents
4860 (elt (org-element-contents row
) column
)))
4861 (cookie (car value
)))
4862 ;; The following checks avoid expanding unnecessarily
4863 ;; the cell with `org-export-data'.
4867 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" cookie
)
4868 (match-string 1 cookie
))
4870 (string-to-number (match-string 1 cookie
)))))))))))
4872 (defun org-export-table-cell-alignment (table-cell info
)
4873 "Return TABLE-CELL contents alignment.
4875 INFO is a plist used as the communication channel.
4877 Return alignment as specified by the last alignment cookie in the
4878 same column as TABLE-CELL. If no such cookie is found, a default
4879 alignment value will be deduced from fraction of numbers in the
4880 column (see `org-table-number-fraction' for more information).
4881 Possible values are `left', `right' and `center'."
4882 ;; Load `org-table-number-fraction' and `org-table-number-regexp'.
4883 (require 'org-table
)
4884 (let* ((row (org-export-get-parent table-cell
))
4885 (table (org-export-get-parent row
))
4886 (cells (org-element-contents row
))
4887 (columns (length cells
))
4888 (column (- columns
(length (memq table-cell cells
))))
4889 (cache (or (plist-get info
:table-cell-alignment-cache
)
4890 (let ((table (make-hash-table :test
#'eq
)))
4891 (plist-put info
:table-cell-alignment-cache table
)
4893 (align-vector (or (gethash table cache
)
4894 (puthash table
(make-vector columns nil
) cache
))))
4895 (or (aref align-vector column
)
4896 (let ((number-cells 0)
4899 previous-cell-number-p
)
4900 (dolist (row (org-element-contents (org-export-get-parent row
)))
4902 ;; In a special row, try to find an alignment cookie at
4904 ((org-export-table-row-is-special-p row info
)
4905 (let ((value (org-element-contents
4906 (elt (org-element-contents row
) column
))))
4907 ;; Since VALUE is a secondary string, the following
4908 ;; checks avoid useless expansion through
4909 ;; `org-export-data'.
4912 (stringp (car value
))
4913 (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
4915 (match-string 1 (car value
)))
4916 (setq cookie-align
(match-string 1 (car value
))))))
4917 ;; Ignore table rules.
4918 ((eq (org-element-property :type row
) 'rule
))
4919 ;; In a standard row, check if cell's contents are
4920 ;; expressing some kind of number. Increase NUMBER-CELLS
4921 ;; accordingly. Though, don't bother if an alignment
4922 ;; cookie has already defined cell's alignment.
4924 (let ((value (org-export-data
4925 (org-element-contents
4926 (elt (org-element-contents row
) column
))
4928 (cl-incf total-cells
)
4929 ;; Treat an empty cell as a number if it follows
4931 (if (not (or (string-match org-table-number-regexp value
)
4932 (and (string= value
"") previous-cell-number-p
)))
4933 (setq previous-cell-number-p nil
)
4934 (setq previous-cell-number-p t
)
4935 (cl-incf number-cells
))))))
4936 ;; Return value. Alignment specified by cookies has
4937 ;; precedence over alignment deduced from cell's contents.
4940 (cond ((equal cookie-align
"l") 'left
)
4941 ((equal cookie-align
"r") 'right
)
4942 ((equal cookie-align
"c") 'center
)
4943 ((>= (/ (float number-cells
) total-cells
)
4944 org-table-number-fraction
)
4948 (defun org-export-table-cell-borders (table-cell info
)
4949 "Return TABLE-CELL borders.
4951 INFO is a plist used as a communication channel.
4953 Return value is a list of symbols, or nil. Possible values are:
4954 `top', `bottom', `above', `below', `left' and `right'. Note:
4955 `top' (resp. `bottom') only happen for a cell in the first
4956 row (resp. last row) of the table, ignoring table rules, if any.
4958 Returned borders ignore special rows."
4959 (let* ((row (org-export-get-parent table-cell
))
4960 (table (org-export-get-parent-table table-cell
))
4962 ;; Top/above border? TABLE-CELL has a border above when a rule
4963 ;; used to demarcate row groups can be found above. Hence,
4964 ;; finding a rule isn't sufficient to push `above' in BORDERS:
4965 ;; another regular row has to be found above that rule.
4968 ;; Look at every row before the current one.
4969 (dolist (row (cdr (memq row
(reverse (org-element-contents table
)))))
4970 (cond ((eq (org-element-property :type row
) 'rule
)
4972 ((not (org-export-table-row-is-special-p row info
))
4973 (if rule-flag
(throw 'exit
(push 'above borders
))
4974 (throw 'exit nil
)))))
4975 ;; No rule above, or rule found starts the table (ignoring any
4976 ;; special row): TABLE-CELL is at the top of the table.
4977 (when rule-flag
(push 'above borders
))
4978 (push 'top borders
)))
4979 ;; Bottom/below border? TABLE-CELL has a border below when next
4980 ;; non-regular row below is a rule.
4983 ;; Look at every row after the current one.
4984 (dolist (row (cdr (memq row
(org-element-contents table
))))
4985 (cond ((eq (org-element-property :type row
) 'rule
)
4987 ((not (org-export-table-row-is-special-p row info
))
4988 (if rule-flag
(throw 'exit
(push 'below borders
))
4989 (throw 'exit nil
)))))
4990 ;; No rule below, or rule found ends the table (modulo some
4991 ;; special row): TABLE-CELL is at the bottom of the table.
4992 (when rule-flag
(push 'below borders
))
4993 (push 'bottom borders
)))
4994 ;; Right/left borders? They can only be specified by column
4995 ;; groups. Column groups are defined in a row starting with "/".
4996 ;; Also a column groups row only contains "<", "<>", ">" or blank
4999 (let ((column (let ((cells (org-element-contents row
)))
5000 (- (length cells
) (length (memq table-cell cells
))))))
5001 ;; Table rows are read in reverse order so last column groups
5002 ;; row has precedence over any previous one.
5003 (dolist (row (reverse (org-element-contents table
)))
5004 (unless (eq (org-element-property :type row
) 'rule
)
5005 (when (equal (org-element-contents
5006 (car (org-element-contents row
)))
5008 (let ((column-groups
5011 (let ((value (org-element-contents cell
)))
5012 (when (member value
'(("<") ("<>") (">") nil
))
5014 (org-element-contents row
))))
5015 ;; There's a left border when previous cell, if
5016 ;; any, ends a group, or current one starts one.
5017 (when (or (and (not (zerop column
))
5018 (member (elt column-groups
(1- column
))
5020 (member (elt column-groups column
) '("<" "<>")))
5021 (push 'left borders
))
5022 ;; There's a right border when next cell, if any,
5023 ;; starts a group, or current one ends one.
5024 (when (or (and (/= (1+ column
) (length column-groups
))
5025 (member (elt column-groups
(1+ column
))
5027 (member (elt column-groups column
) '(">" "<>")))
5028 (push 'right borders
))
5029 (throw 'exit nil
)))))))
5033 (defun org-export-table-cell-starts-colgroup-p (table-cell info
)
5034 "Non-nil when TABLE-CELL is at the beginning of a column group.
5035 INFO is a plist used as a communication channel."
5036 ;; A cell starts a column group either when it is at the beginning
5037 ;; of a row (or after the special column, if any) or when it has
5039 (or (eq (org-element-map (org-export-get-parent table-cell
) 'table-cell
5040 'identity info
'first-match
)
5042 (memq 'left
(org-export-table-cell-borders table-cell info
))))
5044 (defun org-export-table-cell-ends-colgroup-p (table-cell info
)
5045 "Non-nil when TABLE-CELL is at the end of a column group.
5046 INFO is a plist used as a communication channel."
5047 ;; A cell ends a column group either when it is at the end of a row
5048 ;; or when it has a right border.
5049 (or (eq (car (last (org-element-contents
5050 (org-export-get-parent table-cell
))))
5052 (memq 'right
(org-export-table-cell-borders table-cell info
))))
5054 (defun org-export-table-row-starts-rowgroup-p (table-row info
)
5055 "Non-nil when TABLE-ROW is at the beginning of a row group.
5056 INFO is a plist used as a communication channel."
5057 (unless (or (eq (org-element-property :type table-row
) 'rule
)
5058 (org-export-table-row-is-special-p table-row info
))
5059 (let ((borders (org-export-table-cell-borders
5060 (car (org-element-contents table-row
)) info
)))
5061 (or (memq 'top borders
) (memq 'above borders
)))))
5063 (defun org-export-table-row-ends-rowgroup-p (table-row info
)
5064 "Non-nil when TABLE-ROW is at the end of a row group.
5065 INFO is a plist used as a communication channel."
5066 (unless (or (eq (org-element-property :type table-row
) 'rule
)
5067 (org-export-table-row-is-special-p table-row info
))
5068 (let ((borders (org-export-table-cell-borders
5069 (car (org-element-contents table-row
)) info
)))
5070 (or (memq 'bottom borders
) (memq 'below borders
)))))
5072 (defun org-export-table-row-in-header-p (table-row info
)
5073 "Non-nil when TABLE-ROW is located within table's header.
5074 INFO is a plist used as a communication channel. Always return
5075 nil for special rows and rows separators."
5076 (and (org-export-table-has-header-p
5077 (org-export-get-parent-table table-row
) info
)
5078 (eql (org-export-table-row-group table-row info
) 1)))
5080 (defun org-export-table-row-starts-header-p (table-row info
)
5081 "Non-nil when TABLE-ROW is the first table header's row.
5082 INFO is a plist used as a communication channel."
5083 (and (org-export-table-row-in-header-p table-row info
)
5084 (org-export-table-row-starts-rowgroup-p table-row info
)))
5086 (defun org-export-table-row-ends-header-p (table-row info
)
5087 "Non-nil when TABLE-ROW is the last table header's row.
5088 INFO is a plist used as a communication channel."
5089 (and (org-export-table-row-in-header-p table-row info
)
5090 (org-export-table-row-ends-rowgroup-p table-row info
)))
5092 (defun org-export-table-row-number (table-row info
)
5093 "Return TABLE-ROW number.
5094 INFO is a plist used as a communication channel. Return value is
5095 zero-indexed and ignores separators. The function returns nil
5096 for special rows and separators."
5097 (when (eq (org-element-property :type table-row
) 'standard
)
5098 (let* ((cache (or (plist-get info
:table-row-number-cache
)
5099 (let ((table (make-hash-table :test
#'eq
)))
5100 (plist-put info
:table-row-number-cache table
)
5102 (cached (gethash table-row cache
'no-cache
)))
5103 (if (not (eq cached
'no-cache
)) cached
5104 ;; First time a row is queried, populate cache with all the
5105 ;; rows from the table.
5107 (org-element-map (org-export-get-parent-table table-row
) 'table-row
5109 (when (eq (org-element-property :type row
) 'standard
)
5110 (puthash row
(cl-incf number
) cache
)))
5112 (gethash table-row cache
)))))
5114 (defun org-export-table-dimensions (table info
)
5115 "Return TABLE dimensions.
5117 INFO is a plist used as a communication channel.
5119 Return value is a CONS like (ROWS . COLUMNS) where
5120 ROWS (resp. COLUMNS) is the number of exportable
5121 rows (resp. columns)."
5122 (let (first-row (columns 0) (rows 0))
5123 ;; Set number of rows, and extract first one.
5124 (org-element-map table
'table-row
5126 (when (eq (org-element-property :type row
) 'standard
)
5128 (unless first-row
(setq first-row row
)))) info
)
5129 ;; Set number of columns.
5130 (org-element-map first-row
'table-cell
(lambda (_) (cl-incf columns
)) info
)
5132 (cons rows columns
)))
5134 (defun org-export-table-cell-address (table-cell info
)
5135 "Return address of a regular TABLE-CELL object.
5137 TABLE-CELL is the cell considered. INFO is a plist used as
5138 a communication channel.
5140 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
5141 zero-based index. Only exportable cells are considered. The
5142 function returns nil for other cells."
5143 (let* ((table-row (org-export-get-parent table-cell
))
5144 (row-number (org-export-table-row-number table-row info
)))
5147 (let ((col-count 0))
5148 (org-element-map table-row
'table-cell
5150 (if (eq cell table-cell
) col-count
(cl-incf col-count
) nil
))
5151 info
'first-match
))))))
5153 (defun org-export-get-table-cell-at (address table info
)
5154 "Return regular table-cell object at ADDRESS in TABLE.
5156 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
5157 zero-based index. TABLE is a table type element. INFO is
5158 a plist used as a communication channel.
5160 If no table-cell, among exportable cells, is found at ADDRESS,
5162 (let ((column-pos (cdr address
)) (column-count 0))
5164 ;; Row at (car address) or nil.
5165 (let ((row-pos (car address
)) (row-count 0))
5166 (org-element-map table
'table-row
5168 (cond ((eq (org-element-property :type row
) 'rule
) nil
)
5169 ((= row-count row-pos
) row
)
5170 (t (cl-incf row-count
) nil
)))
5174 (if (= column-count column-pos
) cell
5175 (cl-incf column-count
) nil
))
5176 info
'first-match
)))
5179 ;;;; For Tables Of Contents
5181 ;; `org-export-collect-headlines' builds a list of all exportable
5182 ;; headline elements, maybe limited to a certain depth. One can then
5183 ;; easily parse it and transcode it.
5185 ;; Building lists of tables, figures or listings is quite similar.
5186 ;; Once the generic function `org-export-collect-elements' is defined,
5187 ;; `org-export-collect-tables', `org-export-collect-figures' and
5188 ;; `org-export-collect-listings' can be derived from it.
5190 (defun org-export-collect-headlines (info &optional n scope
)
5191 "Collect headlines in order to build a table of contents.
5193 INFO is a plist used as a communication channel.
5195 When optional argument N is an integer, it specifies the depth of
5196 the table of contents. Otherwise, it is set to the value of the
5197 last headline level. See `org-export-headline-levels' for more
5200 Optional argument SCOPE, when non-nil, is an element. If it is
5201 a headline, only children of SCOPE are collected. Otherwise,
5202 collect children of the headline containing provided element. If
5203 there is no such headline, collect all headlines. In any case,
5204 argument N becomes relative to the level of that headline.
5206 Return a list of all exportable headlines as parsed elements.
5207 Footnote sections are ignored."
5208 (let* ((scope (cond ((not scope
) (plist-get info
:parse-tree
))
5209 ((eq (org-element-type scope
) 'headline
) scope
)
5210 ((org-export-get-parent-headline scope
))
5211 (t (plist-get info
:parse-tree
))))
5212 (limit (plist-get info
:headline-levels
))
5213 (n (if (not (wholenump n
)) limit
5214 (min (if (eq (org-element-type scope
) 'org-data
) n
5215 (+ (org-export-get-relative-level scope info
) n
))
5217 (org-element-map (org-element-contents scope
) 'headline
5219 (unless (org-element-property :footnote-section-p headline
)
5220 (let ((level (org-export-get-relative-level headline info
)))
5221 (and (<= level n
) headline
))))
5224 (defun org-export-collect-elements (type info
&optional predicate
)
5225 "Collect referenceable elements of a determined type.
5227 TYPE can be a symbol or a list of symbols specifying element
5228 types to search. Only elements with a caption are collected.
5230 INFO is a plist used as a communication channel.
5232 When non-nil, optional argument PREDICATE is a function accepting
5233 one argument, an element of type TYPE. It returns a non-nil
5234 value when that element should be collected.
5236 Return a list of all elements found, in order of appearance."
5237 (org-element-map (plist-get info
:parse-tree
) type
5239 (and (org-element-property :caption element
)
5240 (or (not predicate
) (funcall predicate element
))
5244 (defun org-export-collect-tables (info)
5245 "Build a list of tables.
5246 INFO is a plist used as a communication channel.
5248 Return a list of table elements with a caption."
5249 (org-export-collect-elements 'table info
))
5251 (defun org-export-collect-figures (info predicate
)
5252 "Build a list of figures.
5254 INFO is a plist used as a communication channel. PREDICATE is
5255 a function which accepts one argument: a paragraph element and
5256 whose return value is non-nil when that element should be
5259 A figure is a paragraph type element, with a caption, verifying
5260 PREDICATE. The latter has to be provided since a \"figure\" is
5261 a vague concept that may depend on back-end.
5263 Return a list of elements recognized as figures."
5264 (org-export-collect-elements 'paragraph info predicate
))
5266 (defun org-export-collect-listings (info)
5267 "Build a list of src blocks.
5269 INFO is a plist used as a communication channel.
5271 Return a list of src-block elements with a caption."
5272 (org-export-collect-elements 'src-block info
))
5277 ;; The main function for the smart quotes sub-system is
5278 ;; `org-export-activate-smart-quotes', which replaces every quote in
5279 ;; a given string from the parse tree with its "smart" counterpart.
5281 ;; Dictionary for smart quotes is stored in
5282 ;; `org-export-smart-quotes-alist'.
5284 (defconst org-export-smart-quotes-alist
5287 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5288 :texinfo
"@guillemetleft{}")
5290 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5291 :texinfo
"@guillemetright{}")
5292 (secondary-opening :utf-8
"‹" :html
"‹" :latex
"\\guilsinglleft{}"
5293 :texinfo
"@guilsinglleft{}")
5294 (secondary-closing :utf-8
"›" :html
"›" :latex
"\\guilsinglright{}"
5295 :texinfo
"@guilsinglright{}")
5296 (apostrophe :utf-8
"’" :html
"’"))
5298 ;; one may use: »...«, "...", ›...‹, or '...'.
5299 ;; http://sproget.dk/raad-og-regler/retskrivningsregler/retskrivningsregler/a7-40-60/a7-58-anforselstegn/
5300 ;; LaTeX quotes require Babel!
5302 :utf-8
"»" :html
"»" :latex
">>" :texinfo
"@guillemetright{}")
5304 :utf-8
"«" :html
"«" :latex
"<<" :texinfo
"@guillemetleft{}")
5306 :utf-8
"›" :html
"›" :latex
"\\frq{}" :texinfo
"@guilsinglright{}")
5308 :utf-8
"‹" :html
"‹" :latex
"\\flq{}" :texinfo
"@guilsingleft{}")
5309 (apostrophe :utf-8
"’" :html
"’"))
5312 :utf-8
"„" :html
"„" :latex
"\"`" :texinfo
"@quotedblbase{}")
5314 :utf-8
"“" :html
"“" :latex
"\"'" :texinfo
"@quotedblleft{}")
5316 :utf-8
"‚" :html
"‚" :latex
"\\glq{}" :texinfo
"@quotesinglbase{}")
5318 :utf-8
"‘" :html
"‘" :latex
"\\grq{}" :texinfo
"@quoteleft{}")
5319 (apostrophe :utf-8
"’" :html
"’"))
5321 (primary-opening :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
5322 (primary-closing :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
5323 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5324 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5325 (apostrophe :utf-8
"’" :html
"’"))
5328 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5329 :texinfo
"@guillemetleft{}")
5331 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5332 :texinfo
"@guillemetright{}")
5333 (secondary-opening :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
5334 (secondary-closing :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
5335 (apostrophe :utf-8
"’" :html
"’"))
5338 :utf-8
"« " :html
"« " :latex
"\\og "
5339 :texinfo
"@guillemetleft{}@tie{}")
5341 :utf-8
" »" :html
" »" :latex
"\\fg{}"
5342 :texinfo
"@tie{}@guillemetright{}")
5344 :utf-8
"« " :html
"« " :latex
"\\og "
5345 :texinfo
"@guillemetleft{}@tie{}")
5346 (secondary-closing :utf-8
" »" :html
" »" :latex
"\\fg{}"
5347 :texinfo
"@tie{}@guillemetright{}")
5348 (apostrophe :utf-8
"’" :html
"’"))
5351 :utf-8
"„" :html
"„" :latex
"\"`" :texinfo
"@quotedblbase{}")
5353 :utf-8
"“" :html
"“" :latex
"\"'" :texinfo
"@quotedblleft{}")
5355 :utf-8
"‚" :html
"‚" :latex
"\\glq{}" :texinfo
"@quotesinglbase{}")
5357 :utf-8
"‘" :html
"‘" :latex
"\\grq{}" :texinfo
"@quoteleft{}")
5358 (apostrophe :utf-8
"’" :html
"’"))
5360 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5362 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5363 :texinfo
"@guillemetleft{}")
5365 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5366 :texinfo
"@guillemetright{}")
5367 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5368 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5369 (apostrophe :utf-8
"’" :html
"’"))
5371 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5373 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5374 :texinfo
"@guillemetleft{}")
5376 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5377 :texinfo
"@guillemetright{}")
5378 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5379 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5380 (apostrophe :utf-8
"’" :html
"’"))
5382 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5384 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5385 :texinfo
"@guillemetleft{}")
5387 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5388 :texinfo
"@guillemetright{}")
5389 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5390 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5391 (apostrophe :utf-8
"’" :html
"’"))
5393 ;; 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
5394 ;; http://www.artlebedev.ru/kovodstvo/sections/104/
5395 (primary-opening :utf-8
"«" :html
"«" :latex
"{}<<"
5396 :texinfo
"@guillemetleft{}")
5397 (primary-closing :utf-8
"»" :html
"»" :latex
">>{}"
5398 :texinfo
"@guillemetright{}")
5400 :utf-8
"„" :html
"„" :latex
"\\glqq{}" :texinfo
"@quotedblbase{}")
5402 :utf-8
"“" :html
"“" :latex
"\\grqq{}" :texinfo
"@quotedblleft{}")
5403 (apostrophe :utf-8
"’" :html
: "'"))
5405 ;; Based on https://sl.wikipedia.org/wiki/Narekovaj
5406 (primary-opening :utf-8
"«" :html
"«" :latex
"{}<<"
5407 :texinfo
"@guillemetleft{}")
5408 (primary-closing :utf-8
"»" :html
"»" :latex
">>{}"
5409 :texinfo
"@guillemetright{}")
5411 :utf-8
"„" :html
"„" :latex
"\\glqq{}" :texinfo
"@quotedblbase{}")
5413 :utf-8
"“" :html
"“" :latex
"\\grqq{}" :texinfo
"@quotedblleft{}")
5414 (apostrophe :utf-8
"’" :html
"’"))
5416 ;; Based on https://sv.wikipedia.org/wiki/Citattecken
5417 (primary-opening :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
5418 (primary-closing :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
5419 (secondary-opening :utf-8
"’" :html
"’" :latex
"’" :texinfo
"`")
5420 (secondary-closing :utf-8
"’" :html
"’" :latex
"’" :texinfo
"'")
5421 (apostrophe :utf-8
"’" :html
"’")))
5422 "Smart quotes translations.
5424 Alist whose CAR is a language string and CDR is an alist with
5425 quote type as key and a plist associating various encodings to
5426 their translation as value.
5428 A quote type can be any symbol among `primary-opening',
5429 `primary-closing', `secondary-opening', `secondary-closing' and
5432 Valid encodings include `:utf-8', `:html', `:latex' and
5435 If no translation is found, the quote character is left as-is.")
5437 (defun org-export--smart-quote-status (s info
)
5438 "Return smart quote status at the beginning of string S.
5439 INFO is the current export state, as a plist."
5440 (let* ((parent (org-element-property :parent s
))
5441 (cache (or (plist-get info
:smart-quote-cache
)
5442 (let ((table (make-hash-table :test
#'eq
)))
5443 (plist-put info
:smart-quote-cache table
)
5445 (value (gethash parent cache
'missing-data
)))
5446 (if (not (eq value
'missing-data
)) (cdr (assq s value
))
5447 (let (level1-open full-status
)
5449 (let ((secondary (org-element-secondary-p s
)))
5450 (if secondary
(org-element-property secondary parent
)
5451 (org-element-contents parent
)))
5454 (let ((start 0) current-status
)
5455 (while (setq start
(string-match "['\"]" text start
))
5458 ((equal (match-string 0 text
) "\"")
5459 (setf level1-open
(not level1-open
))
5460 (if level1-open
'primary-opening
'primary-closing
))
5461 ;; Not already in a level 1 quote: this is an
5463 ((not level1-open
) 'apostrophe
)
5464 ;; Extract previous char and next char. As
5465 ;; a special case, they can also be set to `blank',
5466 ;; `no-blank' or nil. Then determine if current
5467 ;; match is allowed as an opening quote or a closing
5471 (if (> start
0) (substring text
(1- start
) start
)
5472 (let ((p (org-export-get-previous-element
5475 ((stringp p
) (substring p -
1))
5476 ((memq (org-element-property :post-blank p
)
5481 (if (< (1+ start
) (length text
))
5482 (substring text
(1+ start
) (+ start
2))
5483 (let ((n (org-export-get-next-element text info
)))
5485 ((stringp n
) (substring n
0 1))
5488 (and (if (stringp previous
)
5489 (string-match "\\s\"\\|\\s-\\|\\s("
5491 (memq previous
'(blank nil
)))
5493 (string-match "\\w\\|\\s.\\|\\s_" next
)
5494 (eq next
'no-blank
))))
5496 (and (if (stringp previous
)
5497 (string-match "\\w\\|\\s.\\|\\s_" previous
)
5498 (eq previous
'no-blank
))
5500 (string-match "\\s-\\|\\s)\\|\\s.\\|\\s\""
5502 (memq next
'(blank nil
))))))
5504 ((and allow-open allow-close
) (error "Should not happen"))
5505 (allow-open 'secondary-opening
)
5506 (allow-close 'secondary-closing
)
5510 (when current-status
5511 (push (cons text
(nreverse current-status
)) full-status
))))
5512 info nil org-element-recursive-objects
)
5513 (puthash parent full-status cache
)
5514 (cdr (assq s full-status
))))))
5516 (defun org-export-activate-smart-quotes (s encoding info
&optional original
)
5517 "Replace regular quotes with \"smart\" quotes in string S.
5519 ENCODING is a symbol among `:html', `:latex', `:texinfo' and
5520 `:utf-8'. INFO is a plist used as a communication channel.
5522 The function has to retrieve information about string
5523 surroundings in parse tree. It can only happen with an
5524 unmodified string. Thus, if S has already been through another
5525 process, a non-nil ORIGINAL optional argument will provide that
5528 Return the new string."
5530 (copy-sequence (org-export--smart-quote-status (or original s
) info
))))
5531 (replace-regexp-in-string
5535 (cdr (assq (pop quote-status
)
5536 (cdr (assoc (plist-get info
:language
)
5537 org-export-smart-quotes-alist
))))
5544 ;; Here are various functions to retrieve information about the
5545 ;; neighborhood of a given element or object. Neighbors of interest
5546 ;; are direct parent (`org-export-get-parent'), parent headline
5547 ;; (`org-export-get-parent-headline'), first element containing an
5548 ;; object, (`org-export-get-parent-element'), parent table
5549 ;; (`org-export-get-parent-table'), previous element or object
5550 ;; (`org-export-get-previous-element') and next element or object
5551 ;; (`org-export-get-next-element').
5553 ;; defsubst org-export-get-parent must be defined before first use
5555 (defun org-export-get-parent-headline (blob)
5556 "Return BLOB parent headline or nil.
5557 BLOB is the element or object being considered."
5558 (org-element-lineage blob
'(headline)))
5560 (defun org-export-get-parent-element (object)
5561 "Return first element containing OBJECT or nil.
5562 OBJECT is the object to consider."
5563 (org-element-lineage object org-element-all-elements
))
5565 (defun org-export-get-parent-table (object)
5566 "Return OBJECT parent table or nil.
5567 OBJECT is either a `table-cell' or `table-element' type object."
5568 (org-element-lineage object
'(table)))
5570 (defun org-export-get-previous-element (blob info
&optional n
)
5571 "Return previous element or object.
5573 BLOB is an element or object. INFO is a plist used as
5574 a communication channel. Return previous exportable element or
5575 object, a string, or nil.
5577 When optional argument N is a positive integer, return a list
5578 containing up to N siblings before BLOB, from farthest to
5579 closest. With any other non-nil value, return a list containing
5581 (let* ((secondary (org-element-secondary-p blob
))
5582 (parent (org-export-get-parent blob
))
5584 (if secondary
(org-element-property secondary parent
)
5585 (org-element-contents parent
)))
5588 (dolist (obj (cdr (memq blob
(reverse siblings
))) prev
)
5589 (cond ((memq obj
(plist-get info
:ignore-list
)))
5590 ((null n
) (throw 'exit obj
))
5591 ((not (wholenump n
)) (push obj prev
))
5592 ((zerop n
) (throw 'exit prev
))
5593 (t (cl-decf n
) (push obj prev
)))))))
5595 (defun org-export-get-next-element (blob info
&optional n
)
5596 "Return next element or object.
5598 BLOB is an element or object. INFO is a plist used as
5599 a communication channel. Return next exportable element or
5600 object, a string, or nil.
5602 When optional argument N is a positive integer, return a list
5603 containing up to N siblings after BLOB, from closest to farthest.
5604 With any other non-nil value, return a list containing all of
5606 (let* ((secondary (org-element-secondary-p blob
))
5607 (parent (org-export-get-parent blob
))
5610 (if secondary
(org-element-property secondary parent
)
5611 (org-element-contents parent
)))))
5614 (dolist (obj siblings
(nreverse next
))
5615 (cond ((memq obj
(plist-get info
:ignore-list
)))
5616 ((null n
) (throw 'exit obj
))
5617 ((not (wholenump n
)) (push obj next
))
5618 ((zerop n
) (throw 'exit
(nreverse next
)))
5619 (t (cl-decf n
) (push obj next
)))))))
5624 ;; `org-export-translate' translates a string according to the language
5625 ;; specified by the LANGUAGE keyword. `org-export-dictionary' contains
5626 ;; the dictionary used for the translation.
5628 (defconst org-export-dictionary
5630 ("fr" :default
"%e %n : %c" :html
"%e %n : %c"))
5632 ("ar" :default
"تأليف")
5633 ("ca" :default
"Autor")
5634 ("cs" :default
"Autor")
5635 ("da" :default
"Forfatter")
5636 ("de" :default
"Autor")
5637 ("eo" :html
"Aŭtoro")
5638 ("es" :default
"Autor")
5639 ("et" :default
"Autor")
5640 ("fi" :html
"Tekijä")
5641 ("fr" :default
"Auteur")
5642 ("hu" :default
"Szerzõ")
5643 ("is" :html
"Höfundur")
5644 ("it" :default
"Autore")
5645 ("ja" :default
"著者" :html
"著者")
5646 ("nl" :default
"Auteur")
5647 ("no" :default
"Forfatter")
5648 ("nb" :default
"Forfatter")
5649 ("nn" :default
"Forfattar")
5650 ("pl" :default
"Autor")
5651 ("pt_BR" :default
"Autor")
5652 ("ru" :html
"Автор" :utf-8
"Автор")
5653 ("sl" :default
"Avtor")
5654 ("sv" :html
"Författare")
5655 ("uk" :html
"Автор" :utf-8
"Автор")
5656 ("zh-CN" :html
"作者" :utf-8
"作者")
5657 ("zh-TW" :html
"作者" :utf-8
"作者"))
5658 ("Continued from previous page"
5659 ("ar" :default
"تتمة الصفحة السابقة")
5660 ("de" :default
"Fortsetzung von vorheriger Seite")
5661 ("es" :html
"Continúa de la página anterior" :ascii
"Continua de la pagina anterior" :default
"Continúa de la página anterior")
5662 ("fr" :default
"Suite de la page précédente")
5663 ("it" :default
"Continua da pagina precedente")
5664 ("ja" :default
"前ページからの続き")
5665 ("nl" :default
"Vervolg van vorige pagina")
5666 ("pt" :default
"Continuação da página anterior")
5667 ("ru" :html
"(Продолжение)"
5668 :utf-8
"(Продолжение)")
5669 ("sl" :default
"Nadaljevanje s prejšnje strani"))
5670 ("Continued on next page"
5671 ("ar" :default
"التتمة في الصفحة التالية")
5672 ("de" :default
"Fortsetzung nächste Seite")
5673 ("es" :html
"Continúa en la siguiente página" :ascii
"Continua en la siguiente pagina" :default
"Continúa en la siguiente página")
5674 ("fr" :default
"Suite page suivante")
5675 ("it" :default
"Continua alla pagina successiva")
5676 ("ja" :default
"次ページに続く")
5677 ("nl" :default
"Vervolg op volgende pagina")
5678 ("pt" :default
"Continua na página seguinte")
5679 ("ru" :html
"(Продолжение следует)"
5680 :utf-8
"(Продолжение следует)")
5681 ("sl" :default
"Nadaljevanje na naslednji strani"))
5683 ("sl" :default
"Ustvarjeno"))
5685 ("ar" :default
"بتاريخ")
5686 ("ca" :default
"Data")
5687 ("cs" :default
"Datum")
5688 ("da" :default
"Dato")
5689 ("de" :default
"Datum")
5690 ("eo" :default
"Dato")
5691 ("es" :default
"Fecha")
5692 ("et" :html
"Kuupäev" :utf-8
"Kuupäev")
5693 ("fi" :html
"Päivämäärä")
5694 ("hu" :html
"Dátum")
5695 ("is" :default
"Dagsetning")
5696 ("it" :default
"Data")
5697 ("ja" :default
"日付" :html
"日付")
5698 ("nl" :default
"Datum")
5699 ("no" :default
"Dato")
5700 ("nb" :default
"Dato")
5701 ("nn" :default
"Dato")
5702 ("pl" :default
"Data")
5703 ("pt_BR" :default
"Data")
5704 ("ru" :html
"Дата" :utf-8
"Дата")
5705 ("sl" :default
"Datum")
5706 ("sv" :default
"Datum")
5707 ("uk" :html
"Дата" :utf-8
"Дата")
5708 ("zh-CN" :html
"日期" :utf-8
"日期")
5709 ("zh-TW" :html
"日期" :utf-8
"日期"))
5711 ("ar" :default
"معادلة")
5712 ("da" :default
"Ligning")
5713 ("de" :default
"Gleichung")
5714 ("es" :ascii
"Ecuacion" :html
"Ecuación" :default
"Ecuación")
5715 ("et" :html
"Võrrand" :utf-8
"Võrrand")
5716 ("fr" :ascii
"Equation" :default
"Équation")
5717 ("is" :default
"Jafna")
5718 ("ja" :default
"方程式")
5719 ("no" :default
"Ligning")
5720 ("nb" :default
"Ligning")
5721 ("nn" :default
"Likning")
5722 ("pt_BR" :html
"Equação" :default
"Equação" :ascii
"Equacao")
5723 ("ru" :html
"Уравнение"
5725 ("sl" :default
"Enačba")
5726 ("sv" :default
"Ekvation")
5727 ("zh-CN" :html
"方程" :utf-8
"方程"))
5729 ("ar" :default
"شكل")
5730 ("da" :default
"Figur")
5731 ("de" :default
"Abbildung")
5732 ("es" :default
"Figura")
5733 ("et" :default
"Joonis")
5734 ("is" :default
"Mynd")
5735 ("ja" :default
"図" :html
"図")
5736 ("no" :default
"Illustrasjon")
5737 ("nb" :default
"Illustrasjon")
5738 ("nn" :default
"Illustrasjon")
5739 ("pt_BR" :default
"Figura")
5740 ("ru" :html
"Рисунок" :utf-8
"Рисунок")
5741 ("sv" :default
"Illustration")
5742 ("zh-CN" :html
"图" :utf-8
"图"))
5744 ("ar" :default
"شكل %d:")
5745 ("da" :default
"Figur %d")
5746 ("de" :default
"Abbildung %d:")
5747 ("es" :default
"Figura %d:")
5748 ("et" :default
"Joonis %d:")
5749 ("fr" :default
"Figure %d :" :html
"Figure %d :")
5750 ("is" :default
"Mynd %d")
5751 ("ja" :default
"図%d: " :html
"図%d: ")
5752 ("no" :default
"Illustrasjon %d")
5753 ("nb" :default
"Illustrasjon %d")
5754 ("nn" :default
"Illustrasjon %d")
5755 ("pt_BR" :default
"Figura %d:")
5756 ("ru" :html
"Рис. %d.:" :utf-8
"Рис. %d.:")
5757 ("sl" :default
"Slika %d")
5758 ("sv" :default
"Illustration %d")
5759 ("zh-CN" :html
"图%d " :utf-8
"图%d "))
5761 ("ar" :default
"الهوامش")
5762 ("ca" :html
"Peus de pàgina")
5763 ("cs" :default
"Pozn\xe1mky pod carou")
5764 ("da" :default
"Fodnoter")
5765 ("de" :html
"Fußnoten" :default
"Fußnoten")
5766 ("eo" :default
"Piednotoj")
5767 ("es" :ascii
"Nota al pie de pagina" :html
"Nota al pie de página" :default
"Nota al pie de página")
5768 ("et" :html
"Allmärkused" :utf-8
"Allmärkused")
5769 ("fi" :default
"Alaviitteet")
5770 ("fr" :default
"Notes de bas de page")
5771 ("hu" :html
"Lábjegyzet")
5772 ("is" :html
"Aftanmálsgreinar")
5773 ("it" :html
"Note a piè di pagina")
5774 ("ja" :default
"脚注" :html
"脚注")
5775 ("nl" :default
"Voetnoten")
5776 ("no" :default
"Fotnoter")
5777 ("nb" :default
"Fotnoter")
5778 ("nn" :default
"Fotnotar")
5779 ("pl" :default
"Przypis")
5780 ("pt_BR" :html
"Notas de Rodapé" :default
"Notas de Rodapé" :ascii
"Notas de Rodape")
5781 ("ru" :html
"Сноски" :utf-8
"Сноски")
5782 ("sl" :default
"Opombe")
5783 ("sv" :default
"Fotnoter")
5784 ("uk" :html
"Примітки"
5786 ("zh-CN" :html
"脚注" :utf-8
"脚注")
5787 ("zh-TW" :html
"腳註" :utf-8
"腳註"))
5789 ("ar" :default
"قائمة بالبرامج")
5790 ("da" :default
"Programmer")
5791 ("de" :default
"Programmauflistungsverzeichnis")
5792 ("es" :ascii
"Indice de Listados de programas" :html
"Índice de Listados de programas" :default
"Índice de Listados de programas")
5793 ("et" :default
"Loendite nimekiri")
5794 ("fr" :default
"Liste des programmes")
5795 ("ja" :default
"ソースコード目次")
5796 ("no" :default
"Dataprogrammer")
5797 ("nb" :default
"Dataprogrammer")
5798 ("ru" :html
"Список распечаток"
5799 :utf-8
"Список распечаток")
5800 ("sl" :default
"Seznam programskih izpisov")
5801 ("zh-CN" :html
"代码目录" :utf-8
"代码目录"))
5803 ("ar" :default
"قائمة بالجداول")
5804 ("da" :default
"Tabeller")
5805 ("de" :default
"Tabellenverzeichnis")
5806 ("es" :ascii
"Indice de tablas" :html
"Índice de tablas" :default
"Índice de tablas")
5807 ("et" :default
"Tabelite nimekiri")
5808 ("fr" :default
"Liste des tableaux")
5809 ("is" :default
"Töfluskrá" :html
"Töfluskrá")
5810 ("ja" :default
"表目次")
5811 ("no" :default
"Tabeller")
5812 ("nb" :default
"Tabeller")
5813 ("nn" :default
"Tabeller")
5814 ("pt_BR" :default
"Índice de Tabelas" :ascii
"Indice de Tabelas")
5815 ("ru" :html
"Список таблиц"
5816 :utf-8
"Список таблиц")
5817 ("sl" :default
"Seznam tabel")
5818 ("sv" :default
"Tabeller")
5819 ("zh-CN" :html
"表格目录" :utf-8
"表格目录"))
5821 ("ar" :default
"برنامج")
5822 ("da" :default
"Program")
5823 ("de" :default
"Programmlisting")
5824 ("es" :default
"Listado de programa")
5825 ("et" :default
"Loend")
5826 ("fr" :default
"Programme" :html
"Programme")
5827 ("ja" :default
"ソースコード")
5828 ("no" :default
"Dataprogram")
5829 ("nb" :default
"Dataprogram")
5830 ("pt_BR" :default
"Listagem")
5831 ("ru" :html
"Распечатка"
5832 :utf-8
"Распечатка")
5833 ("sl" :default
"Izpis programa")
5834 ("zh-CN" :html
"代码" :utf-8
"代码"))
5836 ("ar" :default
"برنامج %d:")
5837 ("da" :default
"Program %d")
5838 ("de" :default
"Programmlisting %d")
5839 ("es" :default
"Listado de programa %d")
5840 ("et" :default
"Loend %d")
5841 ("fr" :default
"Programme %d :" :html
"Programme %d :")
5842 ("ja" :default
"ソースコード%d:")
5843 ("no" :default
"Dataprogram %d")
5844 ("nb" :default
"Dataprogram %d")
5845 ("pt_BR" :default
"Listagem %d")
5846 ("ru" :html
"Распечатка %d.:"
5847 :utf-8
"Распечатка %d.:")
5848 ("sl" :default
"Izpis programa %d")
5849 ("zh-CN" :html
"代码%d " :utf-8
"代码%d "))
5851 ("ar" :default
"المراجع")
5852 ("fr" :ascii
"References" :default
"Références")
5853 ("de" :default
"Quellen")
5854 ("es" :default
"Referencias")
5855 ("sl" :default
"Reference"))
5857 ("fr" :default
"cf. figure %s"
5858 :html
"cf. figure %s" :latex
"cf.~figure~%s")
5859 ("sl" :default
"Glej sliko %s"))
5861 ("fr" :default
"cf. programme %s"
5862 :html
"cf. programme %s" :latex
"cf.~programme~%s")
5863 ("sl" :default
"Glej izpis programa %s"))
5865 ("ar" :default
"انظر قسم %s")
5866 ("da" :default
"jævnfør afsnit %s")
5867 ("de" :default
"siehe Abschnitt %s")
5868 ("es" :ascii
"Vea seccion %s" :html
"Vea sección %s" :default
"Vea sección %s")
5869 ("et" :html
"Vaata peatükki %s" :utf-8
"Vaata peatükki %s")
5870 ("fr" :default
"cf. section %s")
5871 ("ja" :default
"セクション %s を参照")
5872 ("pt_BR" :html
"Veja a seção %s" :default
"Veja a seção %s"
5873 :ascii
"Veja a secao %s")
5874 ("ru" :html
"См. раздел %s"
5875 :utf-8
"См. раздел %s")
5876 ("sl" :default
"Glej poglavje %d")
5877 ("zh-CN" :html
"参见第%s节" :utf-8
"参见第%s节"))
5879 ("fr" :default
"cf. tableau %s"
5880 :html
"cf. tableau %s" :latex
"cf.~tableau~%s")
5881 ("sl" :default
"Glej tabelo %s"))
5883 ("ar" :default
"جدول")
5884 ("de" :default
"Tabelle")
5885 ("es" :default
"Tabla")
5886 ("et" :default
"Tabel")
5887 ("fr" :default
"Tableau")
5888 ("is" :default
"Tafla")
5889 ("ja" :default
"表" :html
"表")
5890 ("pt_BR" :default
"Tabela")
5891 ("ru" :html
"Таблица"
5893 ("zh-CN" :html
"表" :utf-8
"表"))
5895 ("ar" :default
"جدول %d:")
5896 ("da" :default
"Tabel %d")
5897 ("de" :default
"Tabelle %d")
5898 ("es" :default
"Tabla %d")
5899 ("et" :default
"Tabel %d")
5900 ("fr" :default
"Tableau %d :")
5901 ("is" :default
"Tafla %d")
5902 ("ja" :default
"表%d:" :html
"表%d:")
5903 ("no" :default
"Tabell %d")
5904 ("nb" :default
"Tabell %d")
5905 ("nn" :default
"Tabell %d")
5906 ("pt_BR" :default
"Tabela %d")
5907 ("ru" :html
"Таблица %d.:"
5908 :utf-8
"Таблица %d.:")
5909 ("sl" :default
"Tabela %d")
5910 ("sv" :default
"Tabell %d")
5911 ("zh-CN" :html
"表%d " :utf-8
"表%d "))
5912 ("Table of Contents"
5913 ("ar" :default
"قائمة المحتويات")
5914 ("ca" :html
"Índex")
5915 ("cs" :default
"Obsah")
5916 ("da" :default
"Indhold")
5917 ("de" :default
"Inhaltsverzeichnis")
5918 ("eo" :default
"Enhavo")
5919 ("es" :ascii
"Indice" :html
"Índice" :default
"Índice")
5920 ("et" :default
"Sisukord")
5921 ("fi" :html
"Sisällysluettelo")
5922 ("fr" :ascii
"Sommaire" :default
"Table des matières")
5923 ("hu" :html
"Tartalomjegyzék")
5924 ("is" :default
"Efnisyfirlit")
5925 ("it" :default
"Indice")
5926 ("ja" :default
"目次" :html
"目次")
5927 ("nl" :default
"Inhoudsopgave")
5928 ("no" :default
"Innhold")
5929 ("nb" :default
"Innhold")
5930 ("nn" :default
"Innhald")
5931 ("pl" :html
"Spis treści")
5932 ("pt_BR" :html
"Índice" :utf8
"Índice" :ascii
"Indice")
5933 ("ru" :html
"Содержание"
5934 :utf-8
"Содержание")
5935 ("sl" :default
"Kazalo")
5936 ("sv" :html
"Innehåll")
5937 ("uk" :html
"Зміст" :utf-8
"Зміст")
5938 ("zh-CN" :html
"目录" :utf-8
"目录")
5939 ("zh-TW" :html
"目錄" :utf-8
"目錄"))
5940 ("Unknown reference"
5941 ("ar" :default
"مرجع غير معرّف")
5942 ("da" :default
"ukendt reference")
5943 ("de" :default
"Unbekannter Verweis")
5944 ("es" :default
"Referencia desconocida")
5945 ("et" :default
"Tundmatu viide")
5946 ("fr" :ascii
"Destination inconnue" :default
"Référence inconnue")
5947 ("ja" :default
"不明な参照先")
5948 ("pt_BR" :default
"Referência desconhecida"
5949 :ascii
"Referencia desconhecida")
5950 ("ru" :html
"Неизвестная ссылка"
5951 :utf-8
"Неизвестная ссылка")
5952 ("sl" :default
"Neznana referenca")
5953 ("zh-CN" :html
"未知引用" :utf-8
"未知引用")))
5954 "Dictionary for export engine.
5956 Alist whose car is the string to translate and cdr is an alist
5957 whose car is the language string and cdr is a plist whose
5958 properties are possible charsets and values translated terms.
5960 It is used as a database for `org-export-translate'. Since this
5961 function returns the string as-is if no translation was found,
5962 the variable only needs to record values different from the
5965 (defun org-export-translate (s encoding info
)
5966 "Translate string S according to language specification.
5968 ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
5969 and `:utf-8'. INFO is a plist used as a communication channel.
5971 Translation depends on `:language' property. Return the
5972 translated string. If no translation is found, try to fall back
5973 to `:default' encoding. If it fails, return S."
5974 (let* ((lang (plist-get info
:language
))
5975 (translations (cdr (assoc lang
5976 (cdr (assoc s org-export-dictionary
))))))
5977 (or (plist-get translations encoding
)
5978 (plist-get translations
:default
)
5983 ;;; Asynchronous Export
5985 ;; `org-export-async-start' is the entry point for asynchronous
5986 ;; export. It recreates current buffer (including visibility,
5987 ;; narrowing and visited file) in an external Emacs process, and
5988 ;; evaluates a command there. It then applies a function on the
5989 ;; returned results in the current process.
5991 ;; At a higher level, `org-export-to-buffer' and `org-export-to-file'
5992 ;; allow exporting to a buffer or a file, asynchronously or not.
5994 ;; `org-export-output-file-name' is an auxiliary function meant to be
5995 ;; used with `org-export-to-file'. With a given extension, it tries
5996 ;; to provide a canonical file name to write export output to.
5998 ;; Asynchronously generated results are never displayed directly.
5999 ;; Instead, they are stored in `org-export-stack-contents'. They can
6000 ;; then be retrieved by calling `org-export-stack'.
6002 ;; Export Stack is viewed through a dedicated major mode
6003 ;;`org-export-stack-mode' and tools: `org-export-stack-refresh',
6004 ;;`org-export-stack-delete', `org-export-stack-view' and
6005 ;;`org-export-stack-clear'.
6007 ;; For back-ends, `org-export-add-to-stack' add a new source to stack.
6008 ;; It should be used whenever `org-export-async-start' is called.
6010 (defmacro org-export-async-start
(fun &rest body
)
6011 "Call function FUN on the results returned by BODY evaluation.
6013 FUN is an anonymous function of one argument. BODY evaluation
6014 happens in an asynchronous process, from a buffer which is an
6015 exact copy of the current one.
6017 Use `org-export-add-to-stack' in FUN in order to register results
6020 This is a low level function. See also `org-export-to-buffer'
6021 and `org-export-to-file' for more specialized functions."
6022 (declare (indent 1) (debug t
))
6023 (org-with-gensyms (process temp-file copy-fun proc-buffer coding
)
6024 ;; Write the full sexp evaluating BODY in a copy of the current
6025 ;; buffer to a temporary file, as it may be too long for program
6026 ;; args in `start-process'.
6027 `(with-temp-message "Initializing asynchronous export process"
6028 (let ((,copy-fun
(org-export--generate-copy-script (current-buffer)))
6029 (,temp-file
(make-temp-file "org-export-process"))
6030 (,coding buffer-file-coding-system
))
6031 (with-temp-file ,temp-file
6033 ;; Null characters (from variable values) are inserted
6034 ;; within the file. As a consequence, coding system for
6035 ;; buffer contents will not be recognized properly. So,
6036 ;; we make sure it is the same as the one used to display
6037 ;; the original buffer.
6038 (format ";; -*- coding: %s; -*-\n%S"
6041 (when org-export-async-debug
'(setq debug-on-error t
))
6042 ;; Ignore `kill-emacs-hook' and code evaluation
6043 ;; queries from Babel as we need a truly
6044 ;; non-interactive process.
6045 (setq kill-emacs-hook nil
6046 org-babel-confirm-evaluate-answer-no t
)
6047 ;; Initialize export framework.
6049 ;; Re-create current buffer there.
6050 (funcall ,,copy-fun
)
6051 (restore-buffer-modified-p nil
)
6052 ;; Sexp to evaluate in the buffer.
6053 (print (progn ,,@body
))))))
6054 ;; Start external process.
6055 (let* ((process-connection-type nil
)
6056 (,proc-buffer
(generate-new-buffer-name "*Org Export Process*"))
6061 (list "org-export-process"
6063 (expand-file-name invocation-name invocation-directory
)
6065 (if org-export-async-init-file
6066 (list "-Q" "-l" org-export-async-init-file
)
6067 (list "-l" user-init-file
))
6068 (list "-l" ,temp-file
)))))
6069 ;; Register running process in stack.
6070 (org-export-add-to-stack (get-buffer ,proc-buffer
) nil
,process
)
6071 ;; Set-up sentinel in order to catch results.
6072 (let ((handler ,fun
))
6073 (set-process-sentinel
6076 (let ((proc-buffer (process-buffer p
)))
6077 (when (eq (process-status p
) 'exit
)
6079 (if (zerop (process-exit-status p
))
6082 (with-current-buffer proc-buffer
6083 (goto-char (point-max))
6085 (read (current-buffer)))))
6086 (funcall ,handler results
))
6087 (unless org-export-async-debug
6088 (and (get-buffer proc-buffer
)
6089 (kill-buffer proc-buffer
))))
6090 (org-export-add-to-stack proc-buffer nil p
)
6092 (message "Process `%s' exited abnormally" p
))
6093 (unless org-export-async-debug
6094 (delete-file ,,temp-file
)))))))))))))
6097 (defun org-export-to-buffer
6099 &optional async subtreep visible-only body-only ext-plist
6101 "Call `org-export-as' with output to a specified buffer.
6103 BACKEND is either an export back-end, as returned by, e.g.,
6104 `org-export-create-backend', or a symbol referring to
6105 a registered back-end.
6107 BUFFER is the name of the output buffer. If it already exists,
6108 it will be erased first, otherwise, it will be created.
6110 A non-nil optional argument ASYNC means the process should happen
6111 asynchronously. The resulting buffer should then be accessible
6112 through the `org-export-stack' interface. When ASYNC is nil, the
6113 buffer is displayed if `org-export-show-temporary-export-buffer'
6116 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
6117 EXT-PLIST are similar to those used in `org-export-as', which
6120 Optional argument POST-PROCESS is a function which should accept
6121 no argument. It is always called within the current process,
6122 from BUFFER, with point at its beginning. Export back-ends can
6123 use it to set a major mode there, e.g,
6125 (defun org-latex-export-as-latex
6126 (&optional async subtreep visible-only body-only ext-plist)
6128 (org-export-to-buffer \\='latex \"*Org LATEX Export*\"
6129 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
6131 This function returns BUFFER."
6132 (declare (indent 2))
6134 (org-export-async-start
6136 (with-current-buffer (get-buffer-create ,buffer
)
6138 (setq buffer-file-coding-system
',buffer-file-coding-system
)
6140 (goto-char (point-min))
6141 (org-export-add-to-stack (current-buffer) ',backend
)
6142 (ignore-errors (funcall ,post-process
))))
6144 ',backend
,subtreep
,visible-only
,body-only
',ext-plist
))
6146 (org-export-as backend subtreep visible-only body-only ext-plist
))
6147 (buffer (get-buffer-create buffer
))
6148 (encoding buffer-file-coding-system
))
6149 (when (and (org-string-nw-p output
) (org-export--copy-to-kill-ring-p))
6150 (org-kill-new output
))
6151 (with-current-buffer buffer
6153 (setq buffer-file-coding-system encoding
)
6155 (goto-char (point-min))
6156 (and (functionp post-process
) (funcall post-process
)))
6157 (when org-export-show-temporary-export-buffer
6158 (switch-to-buffer-other-window buffer
))
6162 (defun org-export-to-file
6163 (backend file
&optional async subtreep visible-only body-only ext-plist
6165 "Call `org-export-as' with output to a specified file.
6167 BACKEND is either an export back-end, as returned by, e.g.,
6168 `org-export-create-backend', or a symbol referring to
6169 a registered back-end. FILE is the name of the output file, as
6172 A non-nil optional argument ASYNC means the process should happen
6173 asynchronously. The resulting buffer will then be accessible
6174 through the `org-export-stack' interface.
6176 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
6177 EXT-PLIST are similar to those used in `org-export-as', which
6180 Optional argument POST-PROCESS is called with FILE as its
6181 argument and happens asynchronously when ASYNC is non-nil. It
6182 has to return a file name, or nil. Export back-ends can use this
6183 to send the output file through additional processing, e.g,
6185 (defun org-latex-export-to-latex
6186 (&optional async subtreep visible-only body-only ext-plist)
6188 (let ((outfile (org-export-output-file-name \".tex\" subtreep)))
6189 (org-export-to-file \\='latex outfile
6190 async subtreep visible-only body-only ext-plist
6191 (lambda (file) (org-latex-compile file)))
6193 The function returns either a file name returned by POST-PROCESS,
6195 (declare (indent 2))
6196 (if (not (file-writable-p file
)) (error "Output file not writable")
6197 (let ((ext-plist (org-combine-plists `(:output-file
,file
) ext-plist
))
6198 (encoding (or org-export-coding-system buffer-file-coding-system
)))
6200 (org-export-async-start
6202 (org-export-add-to-stack (expand-file-name file
) ',backend
))
6205 ',backend
,subtreep
,visible-only
,body-only
6209 (let ((coding-system-for-write ',encoding
))
6210 (write-file ,file
)))
6211 (or (ignore-errors (funcall ',post-process
,file
)) ,file
)))
6212 (let ((output (org-export-as
6213 backend subtreep visible-only body-only ext-plist
)))
6216 (let ((coding-system-for-write encoding
))
6218 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p output
))
6219 (org-kill-new output
))
6220 ;; Get proper return value.
6221 (or (and (functionp post-process
) (funcall post-process file
))
6224 (defun org-export-output-file-name (extension &optional subtreep pub-dir
)
6225 "Return output file's name according to buffer specifications.
6227 EXTENSION is a string representing the output file extension,
6228 with the leading dot.
6230 With a non-nil optional argument SUBTREEP, try to determine
6231 output file's name by looking for \"EXPORT_FILE_NAME\" property
6232 of subtree at point.
6234 When optional argument PUB-DIR is set, use it as the publishing
6237 Return file name as a string."
6238 (let* ((visited-file (buffer-file-name (buffer-base-buffer)))
6241 (file-name-sans-extension
6243 ;; Check EXPORT_FILE_NAME subtree property.
6244 (and subtreep
(org-entry-get nil
"EXPORT_FILE_NAME" 'selective
))
6245 ;; Check #+EXPORT_FILE_NAME keyword.
6246 (org-with-point-at (point-min)
6248 (let ((case-fold-search t
))
6249 (while (re-search-forward
6250 "^[ \t]*#\\+EXPORT_FILE_NAME:[ \t]+\\S-" nil t
)
6251 (let ((element (org-element-at-point)))
6252 (when (eq 'keyword
(org-element-type element
))
6254 (org-element-property :value element
))))))))
6255 ;; Extract from buffer's associated file, if any.
6256 (and visited-file
(file-name-nondirectory visited-file
))
6257 ;; Can't determine file name on our own: ask user.
6259 "Output file: " pub-dir nil nil nil
6260 (lambda (n) (string= extension
(file-name-extension n t
))))))
6263 ;; Build file name. Enforce EXTENSION over whatever user
6264 ;; may have come up with. PUB-DIR, if defined, always has
6265 ;; precedence over any provided path.
6267 (pub-dir (concat (file-name-as-directory pub-dir
)
6268 (file-name-nondirectory base-name
)))
6269 ((file-name-absolute-p base-name
) base-name
)
6271 ;; If writing to OUTPUT-FILE would overwrite original file, append
6272 ;; EXTENSION another time to final name.
6273 (if (and visited-file
(file-equal-p visited-file output-file
))
6274 (concat output-file extension
)
6277 (defun org-export-add-to-stack (source backend
&optional process
)
6278 "Add a new result to export stack if not present already.
6280 SOURCE is a buffer or a file name containing export results.
6281 BACKEND is a symbol representing export back-end used to generate
6284 Entries already pointing to SOURCE and unavailable entries are
6285 removed beforehand. Return the new stack."
6286 (setq org-export-stack-contents
6287 (cons (list source backend
(or process
(current-time)))
6288 (org-export-stack-remove source
))))
6290 (defun org-export-stack ()
6291 "Menu for asynchronous export results and running processes."
6293 (let ((buffer (get-buffer-create "*Org Export Stack*")))
6294 (with-current-buffer buffer
6295 (org-export-stack-mode)
6296 (tabulated-list-print t
))
6297 (pop-to-buffer buffer
))
6298 (message "Type \"q\" to quit, \"?\" for help"))
6300 (defun org-export-stack-clear ()
6301 "Remove all entries from export stack."
6303 (setq org-export-stack-contents nil
))
6305 (defun org-export-stack-refresh ()
6306 "Refresh the export stack."
6308 (tabulated-list-print t
))
6310 (defun org-export-stack-remove (&optional source
)
6311 "Remove export results at point from stack.
6312 If optional argument SOURCE is non-nil, remove it instead."
6314 (let ((source (or source
(org-export--stack-source-at-point))))
6315 (setq org-export-stack-contents
6316 (cl-remove-if (lambda (el) (equal (car el
) source
))
6317 org-export-stack-contents
))))
6319 (defun org-export-stack-view (&optional in-emacs
)
6320 "View export results at point in stack.
6321 With an optional prefix argument IN-EMACS, force viewing files
6324 (let ((source (org-export--stack-source-at-point)))
6325 (cond ((processp source
)
6326 (org-switch-to-buffer-other-window (process-buffer source
)))
6327 ((bufferp source
) (org-switch-to-buffer-other-window source
))
6328 (t (org-open-file source in-emacs
)))))
6330 (defvar org-export-stack-mode-map
6331 (let ((km (make-sparse-keymap)))
6332 (set-keymap-parent km tabulated-list-mode-map
)
6333 (define-key km
" " 'next-line
)
6334 (define-key km
"\C-n" 'next-line
)
6335 (define-key km
[down] 'next-line)
6336 (define-key km "\C-p" 'previous-line)
6337 (define-key km "\C-?" 'previous-line)
6338 (define-key km [up] 'previous-line)
6339 (define-key km "C" 'org-export-stack-clear)
6340 (define-key km "v" 'org-export-stack-view)
6341 (define-key km (kbd "RET") 'org-export-stack-view)
6342 (define-key km "d" 'org-export-stack-remove)
6344 "Keymap for Org Export Stack.")
6346 (define-derived-mode org-export-stack-mode tabulated-list-mode "Org-Stack"
6347 "Mode for displaying asynchronous export stack.
6349 Type `\\[org-export-stack]' to visualize the asynchronous export
6352 In an Org Export Stack buffer, use \
6353 \\<org-export-stack-mode-map>`\\[org-export-stack-view]' to view export output
6354 on current line, `\\[org-export-stack-remove]' to remove it from the stack and \
6355 `\\[org-export-stack-clear]' to clear
6358 Removing entries in a stack buffer does not affect files
6359 or buffers, only display.
6361 \\{org-export-stack-mode-map}"
6362 (setq tabulated-list-format
6363 (vector (list "#" 4 #'org-export--stack-num-predicate)
6364 (list "Back-End" 12 t)
6366 (list "Source" 0 nil)))
6367 (setq tabulated-list-sort-key (cons "#" nil))
6368 (setq tabulated-list-entries #'org-export--stack-generate)
6369 (add-hook 'tabulated-list-revert-hook #'org-export--stack-generate nil t)
6370 (add-hook 'post-command-hook #'org-export-stack-refresh nil t)
6371 (tabulated-list-init-header))
6373 (defun org-export--stack-generate ()
6374 "Generate the asynchronous export stack for display.
6375 Unavailable sources are removed from the list. Return a list
6376 appropriate for `tabulated-list-print'."
6377 ;; Clear stack from exited processes, dead buffers or non-existent
6379 (setq org-export-stack-contents
6382 (if (processp (nth 2 el))
6383 (buffer-live-p (process-buffer (nth 2 el)))
6384 (let ((source (car el)))
6385 (if (bufferp source) (buffer-live-p source)
6386 (file-exists-p source)))))
6387 org-export-stack-contents))
6388 ;; Update `tabulated-list-entries'.
6392 (let ((source (car entry)))
6396 (number-to-string (cl-incf counter))
6398 (if (nth 1 entry) (symbol-name (nth 1 entry)) "")
6400 (let ((info (nth 2 entry)))
6401 (if (processp info) (symbol-name (process-status info))
6402 (format-seconds "%h:%.2m" (float-time (time-since info)))))
6404 (if (stringp source) source (buffer-name source))))))
6405 org-export-stack-contents)))
6407 (defun org-export--stack-num-predicate (a b)
6408 (< (string-to-number (aref (nth 1 a) 0))
6409 (string-to-number (aref (nth 1 b) 0))))
6411 (defun org-export--stack-source-at-point ()
6412 "Return source from export results at point in stack."
6413 (let ((source (car (nth (1- (org-current-line)) org-export-stack-contents))))
6414 (if (not source) (error "Source unavailable, please refresh buffer")
6415 (let ((source-name (if (stringp source) source (buffer-name source))))
6418 (looking-at-p (concat ".* +" (regexp-quote source-name) "$")))
6420 ;; SOURCE is not consistent with current line. The stack
6421 ;; view is outdated.
6422 (error (substitute-command-keys
6423 "Source unavailable; type `\\[org-export-stack-refresh]' \
6424 to refresh buffer")))))))
6430 ;; `org-export-dispatch' is the standard interactive way to start an
6431 ;; export process. It uses `org-export--dispatch-ui' as a subroutine
6432 ;; for its interface, which, in turn, delegates response to key
6433 ;; pressed to `org-export--dispatch-action'.
6436 (defun org-export-dispatch (&optional arg)
6437 "Export dispatcher for Org mode.
6439 It provides an access to common export related tasks in a buffer.
6440 Its interface comes in two flavors: standard and expert.
6442 While both share the same set of bindings, only the former
6443 displays the valid keys associations in a dedicated buffer.
6444 Scrolling (resp. line-wise motion) in this buffer is done with
6445 SPC and DEL (resp. C-n and C-p) keys.
6447 Set variable `org-export-dispatch-use-expert-ui' to switch to one
6448 flavor or the other.
6450 When ARG is `\\[universal-argument]', repeat the last export action, with the\
6452 set of options used back then, on the current buffer.
6454 When ARG is `\\[universal-argument] \\[universal-argument]', display the \
6455 asynchronous export stack."
6458 (cond ((equal arg '(16)) '(stack))
6459 ((and arg org-export-dispatch-last-action))
6460 (t (save-window-excursion
6463 ;; Remember where we are
6464 (move-marker org-export-dispatch-last-position
6466 (org-base-buffer (current-buffer)))
6467 ;; Get and store an export command
6468 (setq org-export-dispatch-last-action
6469 (org-export--dispatch-ui
6470 (list org-export-initial-scope
6471 (and org-export-in-background 'async))
6473 org-export-dispatch-use-expert-ui)))
6474 (and (get-buffer "*Org Export Dispatcher*")
6475 (kill-buffer "*Org Export Dispatcher*")))))))
6476 (action (car input))
6477 (optns (cdr input)))
6478 (unless (memq 'subtree optns)
6479 (move-marker org-export-dispatch-last-position nil))
6481 ;; First handle special hard-coded actions.
6482 (template (org-export-insert-default-template nil optns))
6483 (stack (org-export-stack))
6484 (publish-current-file
6485 (org-publish-current-file (memq 'force optns) (memq 'async optns)))
6486 (publish-current-project
6487 (org-publish-current-project (memq 'force optns) (memq 'async optns)))
6488 (publish-choose-project
6489 (org-publish (assoc (completing-read
6491 org-publish-project-alist nil t)
6492 org-publish-project-alist)
6494 (memq 'async optns)))
6495 (publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
6499 ;; Repeating command, maybe move cursor to restore subtree
6501 (if (eq (marker-buffer org-export-dispatch-last-position)
6502 (org-base-buffer (current-buffer)))
6503 (goto-char org-export-dispatch-last-position)
6504 ;; We are in a different buffer, forget position.
6505 (move-marker org-export-dispatch-last-position nil)))
6507 ;; Return a symbol instead of a list to ease
6508 ;; asynchronous export macro use.
6509 (and (memq 'async optns) t)
6510 (and (memq 'subtree optns) t)
6511 (and (memq 'visible optns) t)
6512 (and (memq 'body optns) t)))))))
6514 (defun org-export--dispatch-ui (options first-key expertp)
6515 "Handle interface for `org-export-dispatch'.
6517 OPTIONS is a list containing current interactive options set for
6518 export. It can contain any of the following symbols:
6519 `body' toggles a body-only export
6520 `subtree' restricts export to current subtree
6521 `visible' restricts export to visible part of buffer.
6522 `force' force publishing files.
6523 `async' use asynchronous export process
6525 FIRST-KEY is the key pressed to select the first level menu. It
6526 is nil when this menu hasn't been selected yet.
6528 EXPERTP, when non-nil, triggers expert UI. In that case, no help
6529 buffer is provided, but indications about currently active
6530 options are given in the prompt. Moreover, [?] allows switching
6531 back to standard interface."
6533 (lambda (key &optional access-key)
6534 ;; Fontify KEY string. Optional argument ACCESS-KEY, when
6535 ;; non-nil is the required first-level key to activate
6536 ;; KEY. When its value is t, activate KEY independently
6537 ;; on the first key, if any. A nil value means KEY will
6538 ;; only be activated at first level.
6539 (if (or (eq access-key t) (eq access-key first-key))
6540 (propertize key 'face 'org-warning)
6544 ;; Fontify VALUE string.
6545 (propertize value 'face 'font-lock-variable-name-face)))
6546 ;; Prepare menu entries by extracting them from registered
6547 ;; back-ends and sorting them by access key and by ordinal,
6550 (sort (sort (delq nil
6551 (mapcar #'org-export-backend-menu
6552 org-export-registered-backends))
6554 (let ((key-a (nth 1 a))
6556 (cond ((and (numberp key-a) (numberp key-b))
6558 ((numberp key-b) t)))))
6559 'car-less-than-car))
6560 ;; Compute a list of allowed keys based on the first key
6561 ;; pressed, if any. Some keys
6562 ;; (?^B, ?^V, ?^S, ?^F, ?^A, ?&, ?# and ?q) are always
6565 (nconc (list 2 22 19 6 1)
6566 (if (not first-key) (org-uniquify (mapcar 'car entries))
6568 (dolist (entry entries (sort (mapcar 'car sub-menu) '<))
6569 (when (eq (car entry) first-key)
6570 (setq sub-menu (append (nth 2 entry) sub-menu))))))
6571 (cond ((eq first-key ?P) (list ?f ?p ?x ?a))
6572 ((not first-key) (list ?P)))
6574 (when expertp (list ??))
6576 ;; Build the help menu for standard UI.
6580 ;; Options are hard-coded.
6581 (format "[%s] Body only: %s [%s] Visible only: %s
6582 \[%s] Export scope: %s [%s] Force publishing: %s
6583 \[%s] Async export: %s\n\n"
6584 (funcall fontify-key "C-b" t)
6585 (funcall fontify-value
6586 (if (memq 'body options) "On " "Off"))
6587 (funcall fontify-key "C-v" t)
6588 (funcall fontify-value
6589 (if (memq 'visible options) "On " "Off"))
6590 (funcall fontify-key "C-s" t)
6591 (funcall fontify-value
6592 (if (memq 'subtree options) "Subtree" "Buffer "))
6593 (funcall fontify-key "C-f" t)
6594 (funcall fontify-value
6595 (if (memq 'force options) "On " "Off"))
6596 (funcall fontify-key "C-a" t)
6597 (funcall fontify-value
6598 (if (memq 'async options) "On " "Off")))
6599 ;; Display registered back-end entries. When a key
6600 ;; appears for the second time, do not create another
6601 ;; entry, but append its sub-menu to existing menu.
6605 (let ((top-key (car entry)))
6607 (unless (eq top-key last-key)
6608 (setq last-key top-key)
6609 (format "\n[%s] %s\n"
6610 (funcall fontify-key (char-to-string top-key))
6612 (let ((sub-menu (nth 2 entry)))
6613 (unless (functionp sub-menu)
6614 ;; Split sub-menu into two columns.
6621 (if (zerop (mod index 2)) " [%s] %-26s"
6623 (funcall fontify-key
6624 (char-to-string (car sub-entry))
6628 (when (zerop (mod index 2)) "\n"))))))))
6630 ;; Publishing menu is hard-coded.
6631 (format "\n[%s] Publish
6632 [%s] Current file [%s] Current project
6633 [%s] Choose project [%s] All projects\n\n\n"
6634 (funcall fontify-key "P")
6635 (funcall fontify-key "f" ?P)
6636 (funcall fontify-key "p" ?P)
6637 (funcall fontify-key "x" ?P)
6638 (funcall fontify-key "a" ?P))
6639 (format "[%s] Export stack [%s] Insert template\n"
6640 (funcall fontify-key "&" t)
6641 (funcall fontify-key "#" t))
6643 (funcall fontify-key "q" t)
6644 (if first-key "Main menu" "Exit")))))
6645 ;; Build prompts for both standard and expert UI.
6646 (standard-prompt (unless expertp "Export command: "))
6650 "Export command (C-%s%s%s%s%s) [%s]: "
6651 (if (memq 'body options) (funcall fontify-key "b" t) "b")
6652 (if (memq 'visible options) (funcall fontify-key "v" t) "v")
6653 (if (memq 'subtree options) (funcall fontify-key "s" t) "s")
6654 (if (memq 'force options) (funcall fontify-key "f" t) "f")
6655 (if (memq 'async options) (funcall fontify-key "a" t) "a")
6656 (mapconcat (lambda (k)
6657 ;; Strip control characters.
6658 (unless (< k 27) (char-to-string k)))
6659 allowed-keys "")))))
6660 ;; With expert UI, just read key with a fancy prompt. In standard
6661 ;; UI, display an intrusive help buffer.
6663 (org-export--dispatch-action
6664 expert-prompt allowed-keys entries options first-key expertp)
6665 ;; At first call, create frame layout in order to display menu.
6666 (unless (get-buffer "*Org Export Dispatcher*")
6667 (delete-other-windows)
6668 (org-switch-to-buffer-other-window
6669 (get-buffer-create "*Org Export Dispatcher*"))
6670 (setq cursor-type nil
6671 header-line-format "Use SPC, DEL, C-n or C-p to navigate.")
6672 ;; Make sure that invisible cursor will not highlight square
6674 (set-syntax-table (copy-syntax-table))
6675 (modify-syntax-entry ?\[ "w"))
6676 ;; At this point, the buffer containing the menu exists and is
6677 ;; visible in the current window. So, refresh it.
6678 (with-current-buffer "*Org Export Dispatcher*"
6679 ;; Refresh help. Maintain display continuity by re-visiting
6680 ;; previous window position.
6681 (let ((pos (window-start)))
6684 (set-window-start nil pos)))
6685 (org-fit-window-to-buffer)
6686 (org-export--dispatch-action
6687 standard-prompt allowed-keys entries options first-key expertp))))
6689 (defun org-export--dispatch-action
6690 (prompt allowed-keys entries options first-key expertp)
6691 "Read a character from command input and act accordingly.
6693 PROMPT is the displayed prompt, as a string. ALLOWED-KEYS is
6694 a list of characters available at a given step in the process.
6695 ENTRIES is a list of menu entries. OPTIONS, FIRST-KEY and
6696 EXPERTP are the same as defined in `org-export--dispatch-ui',
6699 Toggle export options when required. Otherwise, return value is
6700 a list with action as CAR and a list of interactive export
6703 ;; Scrolling: when in non-expert mode, act on motion keys (C-n,
6705 (while (and (setq key (read-char-exclusive prompt))
6707 (memq key '(14 16 ?\s ?\d)))
6709 (14 (if (not (pos-visible-in-window-p (point-max)))
6710 (ignore-errors (scroll-up 1))
6711 (message "End of buffer")
6713 (16 (if (not (pos-visible-in-window-p (point-min)))
6714 (ignore-errors (scroll-down 1))
6715 (message "Beginning of buffer")
6717 (?\s (if (not (pos-visible-in-window-p (point-max)))
6719 (message "End of buffer")
6721 (?\d (if (not (pos-visible-in-window-p (point-min)))
6723 (message "Beginning of buffer")
6726 ;; Ignore undefined associations.
6727 ((not (memq key allowed-keys))
6729 (unless expertp (message "Invalid key") (sit-for 1))
6730 (org-export--dispatch-ui options first-key expertp))
6731 ;; q key at first level aborts export. At second level, cancel
6732 ;; first key instead.
6733 ((eq key ?q) (if (not first-key) (error "Export aborted")
6734 (org-export--dispatch-ui options nil expertp)))
6735 ;; Help key: Switch back to standard interface if expert UI was
6737 ((eq key ??) (org-export--dispatch-ui options first-key nil))
6738 ;; Send request for template insertion along with export scope.
6739 ((eq key ?#) (cons 'template (memq 'subtree options)))
6740 ;; Switch to asynchronous export stack.
6741 ((eq key ?&) '(stack))
6742 ;; Toggle options: C-b (2) C-v (22) C-s (19) C-f (6) C-a (1).
6743 ((memq key '(2 22 19 6 1))
6744 (org-export--dispatch-ui
6745 (let ((option (cl-case key (2 'body) (22 'visible) (19 'subtree)
6746 (6 'force) (1 'async))))
6747 (if (memq option options) (remq option options)
6748 (cons option options)))
6750 ;; Action selected: Send key and options back to
6751 ;; `org-export-dispatch'.
6752 ((or first-key (functionp (nth 2 (assq key entries))))
6754 ((not first-key) (nth 2 (assq key entries)))
6755 ;; Publishing actions are hard-coded. Send a special
6756 ;; signal to `org-export-dispatch'.
6759 (?f 'publish-current-file)
6760 (?p 'publish-current-project)
6761 (?x 'publish-choose-project)
6763 ;; Return first action associated to FIRST-KEY + KEY
6764 ;; path. Indeed, derived backends can share the same
6767 (dolist (entry (member (assq first-key entries) entries))
6768 (let ((match (assq key (nth 2 entry))))
6769 (when match (throw 'found (nth 2 match))))))))
6771 ;; Otherwise, enter sub-menu.
6772 (t (org-export--dispatch-ui options key expertp)))))
6779 ;; generated-autoload-file: "org-loaddefs.el"