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
)
442 (or (cl-every #'stringp x
)
443 (and (eq (nth 0 x
) 'not
)
444 (cl-every #'stringp
(cdr x
))))))))
446 (defcustom org-export-with-email nil
447 "Non-nil means insert author email into the exported file.
448 This option can also be set with the OPTIONS keyword,
450 :group
'org-export-general
454 (defcustom org-export-with-emphasize t
455 "Non-nil means interpret *word*, /word/, _word_ and +word+.
457 If the export target supports emphasizing text, the word will be
458 typeset in bold, italic, with an underline or strike-through,
461 This option can also be set with the OPTIONS keyword,
463 :group
'org-export-general
467 (defcustom org-export-exclude-tags
'("noexport")
468 "Tags that exclude a tree from export.
470 All trees carrying any of these tags will be excluded from
471 export. This is without condition, so even subtrees inside that
472 carry one of the `org-export-select-tags' will be removed.
474 This option can also be set with the EXCLUDE_TAGS keyword."
475 :group
'org-export-general
476 :type
'(repeat (string :tag
"Tag"))
477 :safe
(lambda (x) (and (listp x
) (cl-every #'stringp x
))))
479 (defcustom org-export-with-fixed-width t
480 "Non-nil means export lines starting with \":\".
481 This option can also be set with the OPTIONS keyword,
483 :group
'org-export-general
485 :package-version
'(Org .
"8.0")
489 (defcustom org-export-with-footnotes t
490 "Non-nil means Org footnotes should be exported.
491 This option can also be set with the OPTIONS keyword,
493 :group
'org-export-general
497 (defcustom org-export-with-latex t
498 "Non-nil means process LaTeX environments and fragments.
500 This option can also be set with the OPTIONS line,
501 e.g. \"tex:verbatim\". Allowed values are:
503 nil Ignore math snippets.
504 `verbatim' Keep everything in verbatim.
505 t Allow export of math snippets."
506 :group
'org-export-general
508 :package-version
'(Org .
"8.0")
510 (const :tag
"Do not process math in any way" nil
)
511 (const :tag
"Interpret math snippets" t
)
512 (const :tag
"Leave math verbatim" verbatim
))
513 :safe
(lambda (x) (memq x
'(t nil verbatim
))))
515 (defcustom org-export-headline-levels
3
516 "The last level which is still exported as a headline.
518 Inferior levels will usually produce itemize or enumerate lists
519 when exported, but back-end behavior may differ.
521 This option can also be set with the OPTIONS keyword,
523 :group
'org-export-general
527 (defcustom org-export-default-language
"en"
528 "The default language for export and clocktable translations, as a string.
529 This may have an association in
530 `org-clock-clocktable-language-setup',
531 `org-export-smart-quotes-alist' and `org-export-dictionary'.
532 This option can also be set with the LANGUAGE keyword."
533 :group
'org-export-general
534 :type
'(string :tag
"Language")
537 (defcustom org-export-preserve-breaks nil
538 "Non-nil means preserve all line breaks when exporting.
539 This option can also be set with the OPTIONS keyword,
541 :group
'org-export-general
545 (defcustom org-export-with-entities t
546 "Non-nil means interpret entities when exporting.
548 For example, HTML export converts \\alpha to α and \\AA to
551 For a list of supported names, see the constant `org-entities'
552 and the user option `org-entities-user'.
554 This option can also be set with the OPTIONS keyword,
556 :group
'org-export-general
560 (defcustom org-export-with-inlinetasks t
561 "Non-nil means inlinetasks should be exported.
562 This option can also be set with the OPTIONS keyword,
563 e.g. \"inline:nil\"."
564 :group
'org-export-general
566 :package-version
'(Org .
"8.0")
570 (defcustom org-export-with-planning nil
571 "Non-nil means include planning info in export.
573 Planning info is the line containing either SCHEDULED:,
574 DEADLINE:, CLOSED: time-stamps, or a combination of them.
576 This option can also be set with the OPTIONS keyword,
578 :group
'org-export-general
580 :package-version
'(Org .
"8.0")
584 (defcustom org-export-with-priority nil
585 "Non-nil means include priority cookies in export.
586 This option can also be set with the OPTIONS keyword,
588 :group
'org-export-general
592 (defcustom org-export-with-properties nil
593 "Non-nil means export contents of properties drawers.
595 When t, all properties are exported. This may also be a list of
596 properties to export, as strings.
598 This option can also be set with the OPTIONS keyword,
600 :group
'org-export-general
602 :package-version
'(Org .
"8.3")
604 (const :tag
"All properties" t
)
605 (const :tag
"None" nil
)
606 (repeat :tag
"Selected properties"
607 (string :tag
"Property name")))
608 :safe
(lambda (x) (or (booleanp x
)
609 (and (listp x
) (cl-every #'stringp x
)))))
611 (defcustom org-export-with-section-numbers t
612 "Non-nil means add section numbers to headlines when exporting.
614 When set to an integer n, numbering will only happen for
615 headlines whose relative level is higher or equal to n.
617 This option can also be set with the OPTIONS keyword,
619 :group
'org-export-general
623 (defcustom org-export-select-tags
'("export")
624 "Tags that select a tree for export.
626 If any such tag is found in a buffer, all trees that do not carry
627 one of these tags will be ignored during export. Inside trees
628 that are selected like this, you can still deselect a subtree by
629 tagging it with one of the `org-export-exclude-tags'.
631 This option can also be set with the SELECT_TAGS keyword."
632 :group
'org-export-general
633 :type
'(repeat (string :tag
"Tag"))
634 :safe
(lambda (x) (and (listp x
) (cl-every #'stringp x
))))
636 (defcustom org-export-with-smart-quotes nil
637 "Non-nil means activate smart quotes during export.
638 This option can also be set with the OPTIONS keyword,
641 When setting this to non-nil, you need to take care of
642 using the correct Babel package when exporting to LaTeX.
643 E.g., you can load Babel for french like this:
645 #+LATEX_HEADER: \\usepackage[french]{babel}"
646 :group
'org-export-general
648 :package-version
'(Org .
"8.0")
652 (defcustom org-export-with-special-strings t
653 "Non-nil means interpret \"\\-\", \"--\" and \"---\" for export.
655 When this option is turned on, these strings will be exported as:
658 -----+----------+--------+-------
662 ... … \\ldots …
664 This option can also be set with the OPTIONS keyword,
666 :group
'org-export-general
670 (defcustom org-export-with-statistics-cookies t
671 "Non-nil means include statistics cookies in export.
672 This option can also be set with the OPTIONS keyword,
674 :group
'org-export-general
676 :package-version
'(Org .
"8.0")
680 (defcustom org-export-with-sub-superscripts t
681 "Non-nil means interpret \"_\" and \"^\" for export.
683 If you want to control how Org displays those characters, see
684 `org-use-sub-superscripts'. `org-export-with-sub-superscripts'
685 used to be an alias for `org-use-sub-superscripts' in Org <8.0,
688 When this option is turned on, you can use TeX-like syntax for
689 sub- and superscripts and see them exported correctly.
691 You can also set the option with #+OPTIONS: ^:t
693 Several characters after \"_\" or \"^\" will be considered as a
694 single item - so grouping with {} is normally not needed. For
695 example, the following things will be parsed as single sub- or
698 10^24 or 10^tau several digits will be considered 1 item.
699 10^-12 or 10^-tau a leading sign with digits or a word
700 x^2-y^3 will be read as x^2 - y^3, because items are
701 terminated by almost any nonword/nondigit char.
702 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
704 Still, ambiguity is possible. So when in doubt, use {} to enclose
705 the sub/superscript. If you set this variable to the symbol `{}',
706 the braces are *required* in order to trigger interpretations as
707 sub/superscript. This can be helpful in documents that need \"_\"
708 frequently in plain text."
709 :group
'org-export-general
711 :package-version
'(Org .
"8.0")
713 (const :tag
"Interpret them" t
)
714 (const :tag
"Curly brackets only" {})
715 (const :tag
"Do not interpret them" nil
))
716 :safe
(lambda (x) (memq x
'(t nil
{}))))
718 (defcustom org-export-with-toc t
719 "Non-nil means create a table of contents in exported files.
721 The TOC contains headlines with levels up
722 to`org-export-headline-levels'. When an integer, include levels
723 up to N in the toc, this may then be different from
724 `org-export-headline-levels', but it will not be allowed to be
725 larger than the number of headline levels. When nil, no table of
728 This option can also be set with the OPTIONS keyword,
729 e.g. \"toc:nil\" or \"toc:3\"."
730 :group
'org-export-general
732 (const :tag
"No Table of Contents" nil
)
733 (const :tag
"Full Table of Contents" t
)
734 (integer :tag
"TOC to level"))
735 :safe
(lambda (x) (or (booleanp x
)
738 (defcustom org-export-with-tables t
739 "Non-nil means export tables.
740 This option can also be set with the OPTIONS keyword,
742 :group
'org-export-general
744 :package-version
'(Org .
"8.0")
748 (defcustom org-export-with-tags t
749 "If nil, do not export tags, just remove them from headlines.
751 If this is the symbol `not-in-toc', tags will be removed from
752 table of contents entries, but still be shown in the headlines of
755 This option can also be set with the OPTIONS keyword,
757 :group
'org-export-general
759 (const :tag
"Off" nil
)
760 (const :tag
"Not in TOC" not-in-toc
)
762 :safe
(lambda (x) (memq x
'(t nil not-in-toc
))))
764 (defcustom org-export-with-tasks t
765 "Non-nil means include TODO items for export.
767 This may have the following values:
768 t include tasks independent of state.
769 `todo' include only tasks that are not yet done.
770 `done' include only tasks that are already done.
771 nil ignore all tasks.
772 list of keywords include tasks with these keywords.
774 This option can also be set with the OPTIONS keyword,
776 :group
'org-export-general
778 (const :tag
"All tasks" t
)
779 (const :tag
"No tasks" nil
)
780 (const :tag
"Not-done tasks" todo
)
781 (const :tag
"Only done tasks" done
)
782 (repeat :tag
"Specific TODO keywords"
783 (string :tag
"Keyword")))
784 :safe
(lambda (x) (or (memq x
'(nil t todo done
))
786 (cl-every #'stringp x
)))))
788 (defcustom org-export-with-title t
789 "Non-nil means print title into the exported file.
790 This option can also be set with the OPTIONS keyword,
792 :group
'org-export-general
794 :package-version
'(Org .
"8.3")
798 (defcustom org-export-time-stamp-file t
799 "Non-nil means insert a time stamp into the exported file.
800 The time stamp shows when the file was created. This option can
801 also be set with the OPTIONS keyword, e.g. \"timestamp:nil\"."
802 :group
'org-export-general
806 (defcustom org-export-with-timestamps t
807 "Non nil means allow timestamps in export.
809 It can be set to any of the following values:
810 t export all timestamps.
811 `active' export active timestamps only.
812 `inactive' export inactive timestamps only.
813 nil do not export timestamps
815 This only applies to timestamps isolated in a paragraph
816 containing only timestamps. Other timestamps are always
819 This option can also be set with the OPTIONS keyword, e.g.
821 :group
'org-export-general
823 (const :tag
"All timestamps" t
)
824 (const :tag
"Only active timestamps" active
)
825 (const :tag
"Only inactive timestamps" inactive
)
826 (const :tag
"No timestamp" nil
))
827 :safe
(lambda (x) (memq x
'(t nil active inactive
))))
829 (defcustom org-export-with-todo-keywords t
830 "Non-nil means include TODO keywords in export.
831 When nil, remove all these keywords from the export. This option
832 can also be set with the OPTIONS keyword, e.g. \"todo:nil\"."
833 :group
'org-export-general
836 (defcustom org-export-allow-bind-keywords nil
837 "Non-nil means BIND keywords can define local variable values.
838 This is a potential security risk, which is why the default value
839 is nil. You can also allow them through local buffer variables."
840 :group
'org-export-general
842 :package-version
'(Org .
"8.0")
845 (defcustom org-export-with-broken-links nil
846 "Non-nil means do not raise an error on broken links.
848 When this variable is non-nil, broken links are ignored, without
849 stopping the export process. If it is set to `mark', broken
850 links are marked as such in the output, with a string like
854 where PATH is the un-resolvable reference.
856 This option can also be set with the OPTIONS keyword, e.g.,
857 \"broken-links:mark\"."
858 :group
'org-export-general
860 :package-version
'(Org .
"9.0")
862 (const :tag
"Ignore broken links" t
)
863 (const :tag
"Mark broken links in output" mark
)
864 (const :tag
"Raise an error" nil
)))
866 (defcustom org-export-snippet-translation-alist nil
867 "Alist between export snippets back-ends and exporter back-ends.
869 This variable allows providing shortcuts for export snippets.
871 For example, with a value of \\='((\"h\" . \"html\")), the
872 HTML back-end will recognize the contents of \"@@h:<b>@@\" as
873 HTML code while every other back-end will ignore it."
874 :group
'org-export-general
876 :package-version
'(Org .
"8.0")
878 (cons (string :tag
"Shortcut")
879 (string :tag
"Back-end")))
883 (cl-every #'stringp
(mapcar #'car x
))
884 (cl-every #'stringp
(mapcar #'cdr x
)))))
886 (defcustom org-export-coding-system nil
887 "Coding system for the exported file."
888 :group
'org-export-general
890 :package-version
'(Org .
"8.0")
891 :type
'coding-system
)
893 (defcustom org-export-copy-to-kill-ring nil
894 "Non-nil means pushing export output to the kill ring.
895 This variable is ignored during asynchronous export."
896 :group
'org-export-general
898 :package-version
'(Org .
"8.3")
900 (const :tag
"Always" t
)
901 (const :tag
"When export is done interactively" if-interactive
)
902 (const :tag
"Never" nil
)))
904 (defcustom org-export-initial-scope
'buffer
905 "The initial scope when exporting with `org-export-dispatch'.
906 This variable can be either set to `buffer' or `subtree'."
907 :group
'org-export-general
909 (const :tag
"Export current buffer" buffer
)
910 (const :tag
"Export current subtree" subtree
)))
912 (defcustom org-export-show-temporary-export-buffer t
913 "Non-nil means show buffer after exporting to temp buffer.
914 When Org exports to a file, the buffer visiting that file is never
915 shown, but remains buried. However, when exporting to
916 a temporary buffer, that buffer is popped up in a second window.
917 When this variable is nil, the buffer remains buried also in
919 :group
'org-export-general
922 (defcustom org-export-in-background nil
923 "Non-nil means export and publishing commands will run in background.
924 Results from an asynchronous export are never displayed
925 automatically. But you can retrieve them with `\\[org-export-stack]'."
926 :group
'org-export-general
928 :package-version
'(Org .
"8.0")
931 (defcustom org-export-async-init-file nil
932 "File used to initialize external export process.
934 Value must be either nil or an absolute file name. When nil, the
935 external process is launched like a regular Emacs session,
936 loading user's initialization file and any site specific
937 configuration. If a file is provided, it, and only it, is loaded
940 Therefore, using a specific configuration makes the process to
941 load faster and the export more portable."
942 :group
'org-export-general
944 :package-version
'(Org .
"8.0")
946 (const :tag
"Regular startup" nil
)
947 (file :tag
"Specific start-up file" :must-match t
)))
949 (defcustom org-export-dispatch-use-expert-ui nil
950 "Non-nil means using a non-intrusive `org-export-dispatch'.
951 In that case, no help buffer is displayed. Though, an indicator
952 for current export scope is added to the prompt (\"b\" when
953 output is restricted to body only, \"s\" when it is restricted to
954 the current subtree, \"v\" when only visible elements are
955 considered for export, \"f\" when publishing functions should be
956 passed the FORCE argument and \"a\" when the export should be
957 asynchronous). Also, [?] allows switching back to standard
959 :group
'org-export-general
961 :package-version
'(Org .
"8.0")
966 ;;; Defining Back-ends
968 ;; An export back-end is a structure with `org-export-backend' type
969 ;; and `name', `parent', `transcoders', `options', `filters', `blocks'
972 ;; At the lowest level, a back-end is created with
973 ;; `org-export-create-backend' function.
975 ;; A named back-end can be registered with
976 ;; `org-export-register-backend' function. A registered back-end can
977 ;; later be referred to by its name, with `org-export-get-backend'
978 ;; function. Also, such a back-end can become the parent of a derived
979 ;; back-end from which slot values will be inherited by default.
980 ;; `org-export-derived-backend-p' can check if a given back-end is
981 ;; derived from a list of back-end names.
983 ;; `org-export-get-all-transcoders', `org-export-get-all-options' and
984 ;; `org-export-get-all-filters' return the full alist of transcoders,
985 ;; options and filters, including those inherited from ancestors.
987 ;; At a higher level, `org-export-define-backend' is the standard way
988 ;; to define an export back-end. If the new back-end is similar to
989 ;; a registered back-end, `org-export-define-derived-backend' may be
992 ;; Eventually `org-export-barf-if-invalid-backend' returns an error
993 ;; when a given back-end hasn't been registered yet.
995 (cl-defstruct (org-export-backend (:constructor org-export-create-backend
)
997 name parent transcoders options filters blocks menu
)
1000 (defun org-export-get-backend (name)
1001 "Return export back-end named after NAME.
1002 NAME is a symbol. Return nil if no such back-end is found."
1003 (cl-find-if (lambda (b) (and (eq name
(org-export-backend-name b
))))
1004 org-export-registered-backends
))
1006 (defun org-export-register-backend (backend)
1007 "Register BACKEND as a known export back-end.
1008 BACKEND is a structure with `org-export-backend' type."
1009 ;; Refuse to register an unnamed back-end.
1010 (unless (org-export-backend-name backend
)
1011 (error "Cannot register a unnamed export back-end"))
1012 ;; Refuse to register a back-end with an unknown parent.
1013 (let ((parent (org-export-backend-parent backend
)))
1014 (when (and parent
(not (org-export-get-backend parent
)))
1015 (error "Cannot use unknown \"%s\" back-end as a parent" parent
)))
1016 ;; If a back-end with the same name as BACKEND is already
1017 ;; registered, replace it with BACKEND. Otherwise, simply add
1018 ;; BACKEND to the list of registered back-ends.
1019 (let ((old (org-export-get-backend (org-export-backend-name backend
))))
1020 (if old
(setcar (memq old org-export-registered-backends
) backend
)
1021 (push backend org-export-registered-backends
))))
1023 (defun org-export-barf-if-invalid-backend (backend)
1024 "Signal an error if BACKEND isn't defined."
1025 (unless (org-export-backend-p backend
)
1026 (error "Unknown \"%s\" back-end: Aborting export" backend
)))
1028 (defun org-export-derived-backend-p (backend &rest backends
)
1029 "Non-nil if BACKEND is derived from one of BACKENDS.
1030 BACKEND is an export back-end, as returned by, e.g.,
1031 `org-export-create-backend', or a symbol referring to
1032 a registered back-end. BACKENDS is constituted of symbols."
1033 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1036 (while (org-export-backend-parent backend
)
1037 (when (memq (org-export-backend-name backend
) backends
)
1040 (org-export-get-backend (org-export-backend-parent backend
))))
1041 (memq (org-export-backend-name backend
) backends
))))
1043 (defun org-export-get-all-transcoders (backend)
1044 "Return full translation table for BACKEND.
1046 BACKEND is an export back-end, as return by, e.g,,
1047 `org-export-create-backend'. Return value is an alist where
1048 keys are element or object types, as symbols, and values are
1051 Unlike to `org-export-backend-transcoders', this function
1052 also returns transcoders inherited from parent back-ends,
1054 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1056 (let ((transcoders (org-export-backend-transcoders backend
))
1058 (while (setq parent
(org-export-backend-parent backend
))
1059 (setq backend
(org-export-get-backend parent
))
1061 (append transcoders
(org-export-backend-transcoders backend
))))
1064 (defun org-export-get-all-options (backend)
1065 "Return export options for BACKEND.
1067 BACKEND is an export back-end, as return by, e.g,,
1068 `org-export-create-backend'. See `org-export-options-alist'
1069 for the shape of the return value.
1071 Unlike to `org-export-backend-options', this function also
1072 returns options inherited from parent back-ends, if any.
1074 Return nil if BACKEND is unknown."
1075 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1077 (let ((options (org-export-backend-options backend
))
1079 (while (setq parent
(org-export-backend-parent backend
))
1080 (setq backend
(org-export-get-backend parent
))
1081 (setq options
(append options
(org-export-backend-options backend
))))
1084 (defun org-export-get-all-filters (backend)
1085 "Return complete list of filters for BACKEND.
1087 BACKEND is an export back-end, as return by, e.g,,
1088 `org-export-create-backend'. Return value is an alist where
1089 keys are symbols and values lists of functions.
1091 Unlike to `org-export-backend-filters', this function also
1092 returns filters inherited from parent back-ends, if any."
1093 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1095 (let ((filters (org-export-backend-filters backend
))
1097 (while (setq parent
(org-export-backend-parent backend
))
1098 (setq backend
(org-export-get-backend parent
))
1099 (setq filters
(append filters
(org-export-backend-filters backend
))))
1102 (defun org-export-define-backend (backend transcoders
&rest body
)
1103 "Define a new back-end BACKEND.
1105 TRANSCODERS is an alist between object or element types and
1106 functions handling them.
1108 These functions should return a string without any trailing
1109 space, or nil. They must accept three arguments: the object or
1110 element itself, its contents or nil when it isn't recursive and
1111 the property list used as a communication channel.
1113 Contents, when not nil, are stripped from any global indentation
1114 \(although the relative one is preserved). They also always end
1115 with a single newline character.
1117 If, for a given type, no function is found, that element or
1118 object type will simply be ignored, along with any blank line or
1119 white space at its end. The same will happen if the function
1120 returns the nil value. If that function returns the empty
1121 string, the type will be ignored, but the blank lines or white
1122 spaces will be kept.
1124 In addition to element and object types, one function can be
1125 associated to the `template' (or `inner-template') symbol and
1126 another one to the `plain-text' symbol.
1128 The former returns the final transcoded string, and can be used
1129 to add a preamble and a postamble to document's body. It must
1130 accept two arguments: the transcoded string and the property list
1131 containing export options. A function associated to `template'
1132 will not be applied if export has option \"body-only\".
1133 A function associated to `inner-template' is always applied.
1135 The latter, when defined, is to be called on every text not
1136 recognized as an element or an object. It must accept two
1137 arguments: the text string and the information channel. It is an
1138 appropriate place to protect special chars relative to the
1141 BODY can start with pre-defined keyword arguments. The following
1142 keywords are understood:
1146 Alist between filters and function, or list of functions,
1147 specific to the back-end. See `org-export-filters-alist' for
1148 a list of all allowed filters. Filters defined here
1149 shouldn't make a back-end test, as it may prevent back-ends
1150 derived from this one to behave properly.
1154 Menu entry for the export dispatcher. It should be a list
1157 \\='(KEY DESCRIPTION-OR-ORDINAL ACTION-OR-MENU)
1161 KEY is a free character selecting the back-end.
1163 DESCRIPTION-OR-ORDINAL is either a string or a number.
1165 If it is a string, is will be used to name the back-end in
1166 its menu entry. If it is a number, the following menu will
1167 be displayed as a sub-menu of the back-end with the same
1168 KEY. Also, the number will be used to determine in which
1169 order such sub-menus will appear (lowest first).
1171 ACTION-OR-MENU is either a function or an alist.
1173 If it is an action, it will be called with four
1174 arguments (booleans): ASYNC, SUBTREEP, VISIBLE-ONLY and
1175 BODY-ONLY. See `org-export-as' for further explanations on
1178 If it is an alist, associations should follow the
1181 \\='(KEY DESCRIPTION ACTION)
1183 where KEY, DESCRIPTION and ACTION are described above.
1185 Valid values include:
1187 \\='(?m \"My Special Back-end\" my-special-export-function)
1191 \\='(?l \"Export to LaTeX\"
1192 (?p \"As PDF file\" org-latex-export-to-pdf)
1193 (?o \"As PDF file and open\"
1195 (if a (org-latex-export-to-pdf t s v b)
1197 (org-latex-export-to-pdf nil s v b)))))))
1199 or the following, which will be added to the previous
1203 ((?B \"As TEX buffer (Beamer)\" org-beamer-export-as-latex)
1204 (?P \"As PDF file (Beamer)\" org-beamer-export-to-pdf)))
1208 Alist between back-end specific properties introduced in
1209 communication channel and how their value are acquired. See
1210 `org-export-options-alist' for more information about
1211 structure of the values."
1212 (declare (indent 1))
1213 (let (filters menu-entry options
)
1214 (while (keywordp (car body
))
1215 (let ((keyword (pop body
)))
1217 (:filters-alist
(setq filters
(pop body
)))
1218 (:menu-entry
(setq menu-entry
(pop body
)))
1219 (:options-alist
(setq options
(pop body
)))
1220 (_ (error "Unknown keyword: %s" keyword
)))))
1221 (org-export-register-backend
1222 (org-export-create-backend :name backend
1223 :transcoders transcoders
1226 :menu menu-entry
))))
1228 (defun org-export-define-derived-backend (child parent
&rest body
)
1229 "Create a new back-end as a variant of an existing one.
1231 CHILD is the name of the derived back-end. PARENT is the name of
1232 the parent back-end.
1234 BODY can start with pre-defined keyword arguments. The following
1235 keywords are understood:
1239 Alist of filters that will overwrite or complete filters
1240 defined in PARENT back-end. See `org-export-filters-alist'
1241 for a list of allowed filters.
1245 Menu entry for the export dispatcher. See
1246 `org-export-define-backend' for more information about the
1251 Alist of back-end specific properties that will overwrite or
1252 complete those defined in PARENT back-end. Refer to
1253 `org-export-options-alist' for more information about
1254 structure of the values.
1258 Alist of element and object types and transcoders that will
1259 overwrite or complete transcode table from PARENT back-end.
1260 Refer to `org-export-define-backend' for detailed information
1263 As an example, here is how one could define \"my-latex\" back-end
1264 as a variant of `latex' back-end with a custom template function:
1266 (org-export-define-derived-backend \\='my-latex \\='latex
1267 :translate-alist \\='((template . my-latex-template-fun)))
1269 The back-end could then be called with, for example:
1271 (org-export-to-buffer \\='my-latex \"*Test my-latex*\")"
1272 (declare (indent 2))
1273 (let (filters menu-entry options transcoders
)
1274 (while (keywordp (car body
))
1275 (let ((keyword (pop body
)))
1277 (:filters-alist
(setq filters
(pop body
)))
1278 (:menu-entry
(setq menu-entry
(pop body
)))
1279 (:options-alist
(setq options
(pop body
)))
1280 (:translate-alist
(setq transcoders
(pop body
)))
1281 (_ (error "Unknown keyword: %s" keyword
)))))
1282 (org-export-register-backend
1283 (org-export-create-backend :name child
1285 :transcoders transcoders
1288 :menu menu-entry
))))
1292 ;;; The Communication Channel
1294 ;; During export process, every function has access to a number of
1295 ;; properties. They are of two types:
1297 ;; 1. Environment options are collected once at the very beginning of
1298 ;; the process, out of the original buffer and configuration.
1299 ;; Collecting them is handled by `org-export-get-environment'
1302 ;; Most environment options are defined through the
1303 ;; `org-export-options-alist' variable.
1305 ;; 2. Tree properties are extracted directly from the parsed tree,
1306 ;; just before export, by `org-export--collect-tree-properties'.
1308 ;;;; Environment Options
1310 ;; Environment options encompass all parameters defined outside the
1311 ;; scope of the parsed data. They come from five sources, in
1312 ;; increasing precedence order:
1314 ;; - Global variables,
1315 ;; - Buffer's attributes,
1316 ;; - Options keyword symbols,
1317 ;; - Buffer keywords,
1318 ;; - Subtree properties.
1320 ;; The central internal function with regards to environment options
1321 ;; is `org-export-get-environment'. It updates global variables with
1322 ;; "#+BIND:" keywords, then retrieve and prioritize properties from
1323 ;; the different sources.
1325 ;; The internal functions doing the retrieval are:
1326 ;; `org-export--get-global-options',
1327 ;; `org-export--get-buffer-attributes',
1328 ;; `org-export--parse-option-keyword',
1329 ;; `org-export--get-subtree-options' and
1330 ;; `org-export--get-inbuffer-options'
1332 ;; Also, `org-export--list-bound-variables' collects bound variables
1333 ;; along with their value in order to set them as buffer local
1334 ;; variables later in the process.
1337 (defun org-export-get-environment (&optional backend subtreep ext-plist
)
1338 "Collect export options from the current buffer.
1340 Optional argument BACKEND is an export back-end, as returned by
1341 `org-export-create-backend'.
1343 When optional argument SUBTREEP is non-nil, assume the export is
1344 done against the current sub-tree.
1346 Third optional argument EXT-PLIST is a property list with
1347 external parameters overriding Org default settings, but still
1348 inferior to file-local settings."
1349 ;; First install #+BIND variables since these must be set before
1350 ;; global options are read.
1351 (dolist (pair (org-export--list-bound-variables))
1352 (set (make-local-variable (car pair
)) (nth 1 pair
)))
1353 ;; Get and prioritize export options...
1355 ;; ... from global variables...
1356 (org-export--get-global-options backend
)
1357 ;; ... from an external property list...
1359 ;; ... from in-buffer settings...
1360 (org-export--get-inbuffer-options backend
)
1361 ;; ... and from subtree, when appropriate.
1362 (and subtreep
(org-export--get-subtree-options backend
))))
1364 (defun org-export--parse-option-keyword (options &optional backend
)
1365 "Parse an OPTIONS line and return values as a plist.
1366 Optional argument BACKEND is an export back-end, as returned by,
1367 e.g., `org-export-create-backend'. It specifies which back-end
1368 specific items to read, if any."
1371 (while (string-match "\\(.+?\\):\\((.*?)\\|\\S-*\\)[ \t]*" options s
)
1372 (setq s
(match-end 0))
1373 (push (cons (match-string 1 options
)
1374 (read (match-string 2 options
)))
1377 ;; Priority is given to back-end specific options.
1378 (all (append (org-export-get-all-options backend
)
1379 org-export-options-alist
))
1382 (dolist (entry all plist
)
1383 (let ((item (nth 2 entry
)))
1385 (let ((v (assoc-string item line t
)))
1386 (when v
(setq plist
(plist-put plist
(car entry
) (cdr v
)))))))))))
1388 (defun org-export--get-subtree-options (&optional backend
)
1389 "Get export options in subtree at point.
1390 Optional argument BACKEND is an export back-end, as returned by,
1391 e.g., `org-export-create-backend'. It specifies back-end used
1392 for export. Return options as a plist."
1393 ;; For each buffer keyword, create a headline property setting the
1394 ;; same property in communication channel. The name for the
1395 ;; property is the keyword with "EXPORT_" appended to it.
1396 (org-with-wide-buffer
1397 ;; Make sure point is at a heading.
1398 (if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t
))
1400 ;; EXPORT_OPTIONS are parsed in a non-standard way. Take
1401 ;; care of them right from the start.
1402 (let ((o (org-entry-get (point) "EXPORT_OPTIONS" 'selective
)))
1403 (and o
(org-export--parse-option-keyword o backend
))))
1404 ;; Take care of EXPORT_TITLE. If it isn't defined, use
1405 ;; headline's title (with no todo keyword, priority cookie or
1406 ;; tag) as its fallback value.
1409 (or (org-entry-get (point) "EXPORT_TITLE" 'selective
)
1410 (let ((case-fold-search nil
))
1411 (looking-at org-complex-heading-regexp
)
1412 (match-string-no-properties 4))))))
1413 ;; Look for both general keywords and back-end specific
1414 ;; options, with priority given to the latter.
1415 (options (append (org-export-get-all-options backend
)
1416 org-export-options-alist
)))
1417 ;; Handle other keywords. Then return PLIST.
1418 (dolist (option options plist
)
1419 (let ((property (car option
))
1420 (keyword (nth 1 option
)))
1423 (or (cdr (assoc keyword cache
))
1424 (let ((v (org-entry-get (point)
1425 (concat "EXPORT_" keyword
)
1427 (push (cons keyword v
) cache
) v
))))
1432 (cl-case (nth 4 option
)
1434 (org-element-parse-secondary-string
1435 value
(org-element-restriction 'keyword
)))
1436 (split (org-split-string value
))
1437 (t value
))))))))))))
1439 (defun org-export--get-inbuffer-options (&optional backend
)
1440 "Return current buffer export options, as a plist.
1442 Optional argument BACKEND, when non-nil, is an export back-end,
1443 as returned by, e.g., `org-export-create-backend'. It specifies
1444 which back-end specific options should also be read in the
1447 Assume buffer is in Org mode. Narrowing, if any, is ignored."
1448 (let* ((case-fold-search t
)
1450 ;; Priority is given to back-end specific options.
1451 (org-export-get-all-options backend
)
1452 org-export-options-alist
))
1453 (regexp (format "^[ \t]*#\\+%s:"
1454 (regexp-opt (nconc (delq nil
(mapcar #'cadr options
))
1455 org-export-special-keywords
))))
1457 (letrec ((find-properties
1459 ;; Return all properties associated to KEYWORD.
1461 (dolist (option options properties
)
1462 (when (equal (nth 1 option
) keyword
)
1463 (cl-pushnew (car option
) properties
))))))
1465 (lambda (&optional files
)
1466 ;; Recursively read keywords in buffer. FILES is
1467 ;; a list of files read so far. PLIST is the current
1468 ;; property list obtained.
1469 (org-with-wide-buffer
1470 (goto-char (point-min))
1471 (while (re-search-forward regexp nil t
)
1472 (let ((element (org-element-at-point)))
1473 (when (eq (org-element-type element
) 'keyword
)
1474 (let ((key (org-element-property :key element
))
1475 (val (org-element-property :value element
)))
1477 ;; Options in `org-export-special-keywords'.
1478 ((equal key
"SETUPFILE")
1481 (org-unbracket-string "\"" "\"" (org-trim val
)))))
1482 ;; Avoid circular dependencies.
1483 (unless (member file files
)
1485 (setq default-directory
1486 (file-name-directory file
))
1487 (insert (org-file-contents file
'noerror
))
1488 (let ((org-inhibit-startup t
)) (org-mode))
1489 (funcall get-options
(cons file files
))))))
1490 ((equal key
"OPTIONS")
1494 (org-export--parse-option-keyword
1496 ((equal key
"FILETAGS")
1503 (org-split-string val
":")
1504 (plist-get plist
:filetags
)))))))
1506 ;; Options in `org-export-options-alist'.
1507 (dolist (property (funcall find-properties key
))
1512 ;; Handle value depending on specified
1514 (cl-case (nth 4 (assq property options
))
1516 (unless (memq property to-parse
)
1517 (push property to-parse
))
1518 ;; Even if `parse' implies `space'
1519 ;; behavior, we separate line with
1520 ;; "\n" so as to preserve
1521 ;; line-breaks. However, empty
1522 ;; lines are forbidden since `parse'
1523 ;; doesn't allow more than one
1525 (let ((old (plist-get plist property
)))
1526 (cond ((not (org-string-nw-p val
)) old
)
1527 (old (concat old
"\n" val
))
1530 (if (not (plist-get plist property
))
1532 (concat (plist-get plist property
)
1537 (concat (plist-get plist property
)
1540 (split `(,@(plist-get plist property
)
1541 ,@(org-split-string val
)))
1544 (if (not (plist-member plist property
)) val
1545 (plist-get plist property
)))))))))))))))))
1546 ;; Read options in the current buffer and return value.
1547 (funcall get-options
(and buffer-file-name
(list buffer-file-name
)))
1548 ;; Parse properties in TO-PARSE. Remove newline characters not
1549 ;; involved in line breaks to simulate `space' behavior.
1550 ;; Finally return options.
1551 (dolist (p to-parse plist
)
1552 (let ((value (org-element-parse-secondary-string
1554 (org-element-restriction 'keyword
))))
1555 (org-element-map value
'plain-text
1557 (org-element-set-element
1558 s
(replace-regexp-in-string "\n" " " s
))))
1559 (setq plist
(plist-put plist p value
)))))))
1561 (defun org-export--get-export-attributes
1562 (&optional backend subtreep visible-only body-only
)
1563 "Return properties related to export process, as a plist.
1564 Optional arguments BACKEND, SUBTREEP, VISIBLE-ONLY and BODY-ONLY
1565 are like the arguments with the same names of function
1567 (list :export-options
(delq nil
1568 (list (and subtreep
'subtree
)
1569 (and visible-only
'visible-only
)
1570 (and body-only
'body-only
)))
1572 :translate-alist
(org-export-get-all-transcoders backend
)
1573 :exported-data
(make-hash-table :test
#'eq
:size
4001)))
1575 (defun org-export--get-buffer-attributes ()
1576 "Return properties related to buffer attributes, as a plist."
1577 (list :input-buffer
(buffer-name (buffer-base-buffer))
1578 :input-file
(buffer-file-name (buffer-base-buffer))))
1580 (defun org-export--get-global-options (&optional backend
)
1581 "Return global export options as a plist.
1582 Optional argument BACKEND, if non-nil, is an export back-end, as
1583 returned by, e.g., `org-export-create-backend'. It specifies
1584 which back-end specific export options should also be read in the
1587 ;; Priority is given to back-end specific options.
1588 (all (append (org-export-get-all-options backend
)
1589 org-export-options-alist
)))
1590 (dolist (cell all plist
)
1591 (let ((prop (car cell
)))
1592 (unless (plist-member plist prop
)
1597 ;; Evaluate default value provided.
1598 (let ((value (eval (nth 3 cell
))))
1599 (if (eq (nth 4 cell
) 'parse
)
1600 (org-element-parse-secondary-string
1601 value
(org-element-restriction 'keyword
))
1604 (defun org-export--list-bound-variables ()
1605 "Return variables bound from BIND keywords in current buffer.
1606 Also look for BIND keywords in setup files. The return value is
1607 an alist where associations are (VARIABLE-NAME VALUE)."
1608 (when org-export-allow-bind-keywords
1609 (letrec ((collect-bind
1610 (lambda (files alist
)
1611 ;; Return an alist between variable names and their
1612 ;; value. FILES is a list of setup files names read
1613 ;; so far, used to avoid circular dependencies. ALIST
1614 ;; is the alist collected so far.
1615 (let ((case-fold-search t
))
1616 (org-with-wide-buffer
1617 (goto-char (point-min))
1618 (while (re-search-forward
1619 "^[ \t]*#\\+\\(BIND\\|SETUPFILE\\):" nil t
)
1620 (let ((element (org-element-at-point)))
1621 (when (eq (org-element-type element
) 'keyword
)
1622 (let ((val (org-element-property :value element
)))
1623 (if (equal (org-element-property :key element
)
1625 (push (read (format "(%s)" val
)) alist
)
1626 ;; Enter setup file.
1627 (let ((file (expand-file-name
1628 (org-unbracket-string "\"" "\"" val
))))
1629 (unless (member file files
)
1631 (setq default-directory
1632 (file-name-directory file
))
1633 (let ((org-inhibit-startup t
)) (org-mode))
1634 (insert (org-file-contents file
'noerror
))
1636 (funcall collect-bind
1640 ;; Return value in appropriate order of appearance.
1641 (nreverse (funcall collect-bind nil nil
)))))
1643 ;; defsubst org-export-get-parent must be defined before first use,
1644 ;; was originally defined in the topology section
1646 (defsubst org-export-get-parent
(blob)
1647 "Return BLOB parent or nil.
1648 BLOB is the element or object considered."
1649 (org-element-property :parent blob
))
1651 ;;;; Tree Properties
1653 ;; Tree properties are information extracted from parse tree. They
1654 ;; are initialized at the beginning of the transcoding process by
1655 ;; `org-export--collect-tree-properties'.
1657 ;; Dedicated functions focus on computing the value of specific tree
1658 ;; properties during initialization. Thus,
1659 ;; `org-export--populate-ignore-list' lists elements and objects that
1660 ;; should be skipped during export, `org-export--get-min-level' gets
1661 ;; the minimal exportable level, used as a basis to compute relative
1662 ;; level for headlines. Eventually
1663 ;; `org-export--collect-headline-numbering' builds an alist between
1664 ;; headlines and their numbering.
1666 (defun org-export--collect-tree-properties (data info
)
1667 "Extract tree properties from parse tree.
1669 DATA is the parse tree from which information is retrieved. INFO
1670 is a list holding export options.
1672 Following tree properties are set or updated:
1674 `:headline-offset' Offset between true level of headlines and
1675 local level. An offset of -1 means a headline
1676 of level 2 should be considered as a level
1677 1 headline in the context.
1679 `:headline-numbering' Alist of all headlines as key and the
1680 associated numbering as value.
1682 `:id-alist' Alist of all ID references as key and associated file
1685 Return updated plist."
1686 ;; Install the parse tree in the communication channel.
1687 (setq info
(plist-put info
:parse-tree data
))
1688 ;; Compute `:headline-offset' in order to be able to use
1689 ;; `org-export-get-relative-level'.
1693 (- 1 (org-export--get-min-level data info
))))
1694 ;; From now on, properties order doesn't matter: get the rest of the
1698 (list :headline-numbering
(org-export--collect-headline-numbering data info
)
1700 (org-element-map data
'link
1702 (and (string= (org-element-property :type l
) "id")
1703 (let* ((id (org-element-property :path l
))
1704 (file (car (org-id-find id
))))
1705 (and file
(cons id
(file-relative-name file
))))))))))
1707 (defun org-export--get-min-level (data options
)
1708 "Return minimum exportable headline's level in DATA.
1709 DATA is parsed tree as returned by `org-element-parse-buffer'.
1710 OPTIONS is a plist holding export options."
1712 (let ((min-level 10000))
1713 (dolist (datum (org-element-contents data
))
1714 (when (and (eq (org-element-type datum
) 'headline
)
1715 (not (org-element-property :footnote-section-p datum
))
1716 (not (memq datum
(plist-get options
:ignore-list
))))
1717 (setq min-level
(min (org-element-property :level datum
) min-level
))
1718 (when (= min-level
1) (throw 'exit
1))))
1719 ;; If no headline was found, for the sake of consistency, set
1720 ;; minimum level to 1 nonetheless.
1721 (if (= min-level
10000) 1 min-level
))))
1723 (defun org-export--collect-headline-numbering (data options
)
1724 "Return numbering of all exportable, numbered headlines in a parse tree.
1726 DATA is the parse tree. OPTIONS is the plist holding export
1729 Return an alist whose key is a headline and value is its
1730 associated numbering \(in the shape of a list of numbers) or nil
1731 for a footnotes section."
1732 (let ((numbering (make-vector org-export-max-depth
0)))
1733 (org-element-map data
'headline
1735 (when (and (org-export-numbered-headline-p headline options
)
1736 (not (org-element-property :footnote-section-p headline
)))
1737 (let ((relative-level
1738 (1- (org-export-get-relative-level headline options
))))
1742 for n across numbering
1743 for idx from
0 to org-export-max-depth
1744 when
(< idx relative-level
) collect n
1745 when
(= idx relative-level
) collect
(aset numbering idx
(1+ n
))
1746 when
(> idx relative-level
) do
(aset numbering idx
0))))))
1749 (defun org-export--selected-trees (data info
)
1750 "List headlines and inlinetasks with a select tag in their tree.
1751 DATA is parsed data as returned by `org-element-parse-buffer'.
1752 INFO is a plist holding export options."
1753 (let ((select (plist-get info
:select-tags
)))
1754 (if (cl-some (lambda (tag) (member tag select
)) (plist-get info
:filetags
))
1755 ;; If FILETAGS contains a select tag, every headline or
1756 ;; inlinetask is returned.
1757 (org-element-map data
'(headline inlinetask
) #'identity
)
1758 (letrec ((selected-trees nil
)
1760 (lambda (data genealogy
)
1761 (let ((type (org-element-type data
)))
1763 ((memq type
'(headline inlinetask
))
1764 (let ((tags (org-element-property :tags data
)))
1765 (if (cl-some (lambda (tag) (member tag select
)) tags
)
1766 ;; When a select tag is found, mark full
1767 ;; genealogy and every headline within the
1768 ;; tree as acceptable.
1769 (setq selected-trees
1772 (org-element-map data
'(headline inlinetask
)
1775 ;; If at a headline, continue searching in
1776 ;; tree, recursively.
1777 (when (eq type
'headline
)
1778 (dolist (el (org-element-contents data
))
1779 (funcall walk-data el
(cons data genealogy
)))))))
1780 ((or (eq type
'org-data
)
1781 (memq type org-element-greater-elements
))
1782 (dolist (el (org-element-contents data
))
1783 (funcall walk-data el genealogy
))))))))
1784 (funcall walk-data data nil
)
1787 (defun org-export--skip-p (datum options selected
)
1788 "Non-nil when element or object DATUM should be skipped during export.
1789 OPTIONS is the plist holding export options. SELECTED, when
1790 non-nil, is a list of headlines or inlinetasks belonging to
1791 a tree with a select tag."
1792 (cl-case (org-element-type datum
)
1793 ((comment comment-block
)
1794 ;; Skip all comments and comment blocks. Make to keep maximum
1795 ;; number of blank lines around the comment so as to preserve
1796 ;; local structure of the document upon interpreting it back into
1798 (let* ((previous (org-export-get-previous-element datum options
))
1799 (before (or (org-element-property :post-blank previous
) 0))
1800 (after (or (org-element-property :post-blank datum
) 0)))
1802 (org-element-put-property previous
:post-blank
(max before after
1))))
1804 (clock (not (plist-get options
:with-clocks
)))
1806 (let ((with-drawers-p (plist-get options
:with-drawers
)))
1807 (or (not with-drawers-p
)
1808 (and (consp with-drawers-p
)
1809 ;; If `:with-drawers' value starts with `not', ignore
1810 ;; every drawer whose name belong to that list.
1811 ;; Otherwise, ignore drawers whose name isn't in that
1813 (let ((name (org-element-property :drawer-name datum
)))
1814 (if (eq (car with-drawers-p
) 'not
)
1815 (member-ignore-case name
(cdr with-drawers-p
))
1816 (not (member-ignore-case name with-drawers-p
))))))))
1817 (fixed-width (not (plist-get options
:with-fixed-width
)))
1818 ((footnote-definition footnote-reference
)
1819 (not (plist-get options
:with-footnotes
)))
1820 ((headline inlinetask
)
1821 (let ((with-tasks (plist-get options
:with-tasks
))
1822 (todo (org-element-property :todo-keyword datum
))
1823 (todo-type (org-element-property :todo-type datum
))
1824 (archived (plist-get options
:with-archived-trees
))
1825 (tags (org-export-get-tags datum options nil t
)))
1827 (and (eq (org-element-type datum
) 'inlinetask
)
1828 (not (plist-get options
:with-inlinetasks
)))
1829 ;; Ignore subtrees with an exclude tag.
1830 (cl-loop for k in
(plist-get options
:exclude-tags
)
1831 thereis
(member k tags
))
1832 ;; When a select tag is present in the buffer, ignore any tree
1834 (and selected
(not (memq datum selected
)))
1835 ;; Ignore commented sub-trees.
1836 (org-element-property :commentedp datum
)
1837 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
1838 (and (not archived
) (org-element-property :archivedp datum
))
1839 ;; Ignore tasks, if specified by `:with-tasks' property.
1841 (or (not with-tasks
)
1842 (and (memq with-tasks
'(todo done
))
1843 (not (eq todo-type with-tasks
)))
1844 (and (consp with-tasks
) (not (member todo with-tasks
))))))))
1845 ((latex-environment latex-fragment
) (not (plist-get options
:with-latex
)))
1847 (let ((properties-set (plist-get options
:with-properties
)))
1848 (cond ((null properties-set
) t
)
1849 ((consp properties-set
)
1850 (not (member-ignore-case (org-element-property :key datum
)
1851 properties-set
))))))
1852 (planning (not (plist-get options
:with-planning
)))
1853 (property-drawer (not (plist-get options
:with-properties
)))
1854 (statistics-cookie (not (plist-get options
:with-statistics-cookies
)))
1855 (table (not (plist-get options
:with-tables
)))
1857 (and (org-export-table-has-special-column-p
1858 (org-export-get-parent-table datum
))
1859 (org-export-first-sibling-p datum options
)))
1860 (table-row (org-export-table-row-is-special-p datum options
))
1862 ;; `:with-timestamps' only applies to isolated timestamps
1863 ;; objects, i.e. timestamp objects in a paragraph containing only
1864 ;; timestamps and whitespaces.
1865 (when (let ((parent (org-export-get-parent-element datum
)))
1866 (and (memq (org-element-type parent
) '(paragraph verse-block
))
1867 (not (org-element-map parent
1869 (remq 'timestamp org-element-all-objects
))
1871 (or (not (stringp obj
)) (org-string-nw-p obj
)))
1873 (cl-case (plist-get options
:with-timestamps
)
1876 (not (memq (org-element-property :type datum
) '(active active-range
))))
1878 (not (memq (org-element-property :type datum
)
1879 '(inactive inactive-range
)))))))))
1884 ;; `org-export-data' reads a parse tree (obtained with, i.e.
1885 ;; `org-element-parse-buffer') and transcodes it into a specified
1886 ;; back-end output. It takes care of filtering out elements or
1887 ;; objects according to export options and organizing the output blank
1888 ;; lines and white space are preserved. The function memoizes its
1889 ;; results, so it is cheap to call it within transcoders.
1891 ;; It is possible to modify locally the back-end used by
1892 ;; `org-export-data' or even use a temporary back-end by using
1893 ;; `org-export-data-with-backend'.
1895 ;; `org-export-transcoder' is an accessor returning appropriate
1896 ;; translator function for a given element or object.
1898 (defun org-export-transcoder (blob info
)
1899 "Return appropriate transcoder for BLOB.
1900 INFO is a plist containing export directives."
1901 (let ((type (org-element-type blob
)))
1902 ;; Return contents only for complete parse trees.
1903 (if (eq type
'org-data
) (lambda (_datum contents _info
) contents
)
1904 (let ((transcoder (cdr (assq type
(plist-get info
:translate-alist
)))))
1905 (and (functionp transcoder
) transcoder
)))))
1907 (defun org-export-data (data info
)
1908 "Convert DATA into current back-end format.
1910 DATA is a parse tree, an element or an object or a secondary
1911 string. INFO is a plist holding export options.
1914 (or (gethash data
(plist-get info
:exported-data
))
1915 ;; Handle broken links according to
1916 ;; `org-export-with-broken-links'.
1918 ((broken-link-handler
1920 `(condition-case err
1923 (pcase (plist-get info
:with-broken-links
)
1924 (`nil
(user-error "Unable to resolve link: %S" (nth 1 err
)))
1925 (`mark
(org-export-data
1926 (format "[BROKEN LINK: %s]" (nth 1 err
)) info
))
1928 (let* ((type (org-element-type data
))
1929 (parent (org-export-get-parent data
))
1932 ;; Ignored element/object.
1933 ((memq data
(plist-get info
:ignore-list
)) nil
)
1935 ((eq type
'plain-text
)
1936 (org-export-filter-apply-functions
1937 (plist-get info
:filter-plain-text
)
1938 (let ((transcoder (org-export-transcoder data info
)))
1939 (if transcoder
(funcall transcoder data info
) data
))
1941 ;; Secondary string.
1943 (mapconcat (lambda (obj) (org-export-data obj info
)) data
""))
1944 ;; Element/Object without contents or, as a special
1945 ;; case, headline with archive tag and archived trees
1946 ;; restricted to title only.
1947 ((or (not (org-element-contents data
))
1948 (and (eq type
'headline
)
1949 (eq (plist-get info
:with-archived-trees
) 'headline
)
1950 (org-element-property :archivedp data
)))
1951 (let ((transcoder (org-export-transcoder data info
)))
1952 (or (and (functionp transcoder
)
1953 (broken-link-handler
1954 (funcall transcoder data nil info
)))
1955 ;; Export snippets never return a nil value so
1956 ;; that white spaces following them are never
1958 (and (eq type
'export-snippet
) ""))))
1959 ;; Element/Object with contents.
1961 (let ((transcoder (org-export-transcoder data info
)))
1963 (let* ((greaterp (memq type org-element-greater-elements
))
1966 (memq type org-element-recursive-objects
)))
1969 (lambda (element) (org-export-data element info
))
1970 (org-element-contents
1971 (if (or greaterp objectp
) data
1972 ;; Elements directly containing
1973 ;; objects must have their indentation
1974 ;; normalized first.
1975 (org-element-normalize-contents
1977 ;; When normalizing contents of the
1978 ;; first paragraph in an item or
1979 ;; a footnote definition, ignore
1980 ;; first line's indentation: there is
1981 ;; none and it might be misleading.
1982 (when (eq type
'paragraph
)
1984 (eq (car (org-element-contents parent
))
1986 (memq (org-element-type parent
)
1987 '(footnote-definition item
)))))))
1989 (broken-link-handler
1990 (funcall transcoder data
1991 (if (not greaterp
) contents
1992 (org-element-normalize-string contents
))
1994 ;; Final result will be memoized before being returned.
1999 ((memq type
'(org-data plain-text nil
)) results
)
2000 ;; Append the same white space between elements or objects
2001 ;; as in the original buffer, and call appropriate filters.
2003 (org-export-filter-apply-functions
2004 (plist-get info
(intern (format ":filter-%s" type
)))
2005 (let ((blank (or (org-element-property :post-blank data
) 0)))
2006 (if (eq (org-element-class data parent
) 'object
)
2007 (concat results
(make-string blank ?\s
))
2008 (concat (org-element-normalize-string results
)
2009 (make-string blank ?
\n))))
2011 (plist-get info
:exported-data
))))))
2013 (defun org-export-data-with-backend (data backend info
)
2014 "Convert DATA into BACKEND format.
2016 DATA is an element, an object, a secondary string or a string.
2017 BACKEND is a symbol. INFO is a plist used as a communication
2020 Unlike to `org-export-with-backend', this function will
2021 recursively convert DATA using BACKEND translation table."
2022 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
2023 ;; Set-up a new communication channel with translations defined in
2024 ;; BACKEND as the translate table and a new hash table for
2029 (list :back-end backend
2030 :translate-alist
(org-export-get-all-transcoders backend
)
2031 ;; Size of the hash table is reduced since this
2032 ;; function will probably be used on small trees.
2033 :exported-data
(make-hash-table :test
'eq
:size
401)))))
2034 (prog1 (org-export-data data new-info
)
2035 ;; Preserve `:internal-references', as those do not depend on
2036 ;; the back-end used; we need to make sure that any new
2037 ;; reference when the temporary back-end was active gets through
2039 (plist-put info
:internal-references
2040 (plist-get new-info
:internal-references
)))))
2042 (defun org-export-expand (blob contents
&optional with-affiliated
)
2043 "Expand a parsed element or object to its original state.
2045 BLOB is either an element or an object. CONTENTS is its
2046 contents, as a string or nil.
2048 When optional argument WITH-AFFILIATED is non-nil, add affiliated
2049 keywords before output."
2050 (let ((type (org-element-type blob
)))
2051 (concat (and with-affiliated
2052 (eq (org-element-class blob
) 'element
)
2053 (org-element--interpret-affiliated-keywords blob
))
2054 (funcall (intern (format "org-element-%s-interpreter" type
))
2059 ;;; The Filter System
2061 ;; Filters allow end-users to tweak easily the transcoded output.
2062 ;; They are the functional counterpart of hooks, as every filter in
2063 ;; a set is applied to the return value of the previous one.
2065 ;; Every set is back-end agnostic. Although, a filter is always
2066 ;; called, in addition to the string it applies to, with the back-end
2067 ;; used as argument, so it's easy for the end-user to add back-end
2068 ;; specific filters in the set. The communication channel, as
2069 ;; a plist, is required as the third argument.
2071 ;; From the developer side, filters sets can be installed in the
2072 ;; process with the help of `org-export-define-backend', which
2073 ;; internally stores filters as an alist. Each association has a key
2074 ;; among the following symbols and a function or a list of functions
2077 ;; - `:filter-options' applies to the property list containing export
2078 ;; options. Unlike to other filters, functions in this list accept
2079 ;; two arguments instead of three: the property list containing
2080 ;; export options and the back-end. Users can set its value through
2081 ;; `org-export-filter-options-functions' variable.
2083 ;; - `:filter-parse-tree' applies directly to the complete parsed
2084 ;; tree. Users can set it through
2085 ;; `org-export-filter-parse-tree-functions' variable.
2087 ;; - `:filter-body' applies to the body of the output, before template
2088 ;; translator chimes in. Users can set it through
2089 ;; `org-export-filter-body-functions' variable.
2091 ;; - `:filter-final-output' applies to the final transcoded string.
2092 ;; Users can set it with `org-export-filter-final-output-functions'
2095 ;; - `:filter-plain-text' applies to any string not recognized as Org
2096 ;; syntax. `org-export-filter-plain-text-functions' allows users to
2099 ;; - `:filter-TYPE' applies on the string returned after an element or
2100 ;; object of type TYPE has been transcoded. A user can modify
2101 ;; `org-export-filter-TYPE-functions' to install these filters.
2103 ;; All filters sets are applied with
2104 ;; `org-export-filter-apply-functions' function. Filters in a set are
2105 ;; applied in a LIFO fashion. It allows developers to be sure that
2106 ;; their filters will be applied first.
2108 ;; Filters properties are installed in communication channel with
2109 ;; `org-export-install-filters' function.
2111 ;; Eventually, two hooks (`org-export-before-processing-hook' and
2112 ;; `org-export-before-parsing-hook') are run at the beginning of the
2113 ;; export process and just before parsing to allow for heavy structure
2119 (defvar org-export-before-processing-hook nil
2120 "Hook run at the beginning of the export process.
2122 This is run before include keywords and macros are expanded and
2123 Babel code blocks executed, on a copy of the original buffer
2124 being exported. Visibility and narrowing are preserved. Point
2125 is at the beginning of the buffer.
2127 Every function in this hook will be called with one argument: the
2128 back-end currently used, as a symbol.")
2130 (defvar org-export-before-parsing-hook nil
2131 "Hook run before parsing an export buffer.
2133 This is run after include keywords and macros have been expanded
2134 and Babel code blocks executed, on a copy of the original buffer
2135 being exported. Visibility and narrowing are preserved. Point
2136 is at the beginning of the buffer.
2138 Every function in this hook will be called with one argument: the
2139 back-end currently used, as a symbol.")
2142 ;;;; Special Filters
2144 (defvar org-export-filter-options-functions nil
2145 "List of functions applied to the export options.
2146 Each filter is called with two arguments: the export options, as
2147 a plist, and the back-end, as a symbol. It must return
2148 a property list containing export options.")
2150 (defvar org-export-filter-parse-tree-functions nil
2151 "List of functions applied to the parsed tree.
2152 Each filter is called with three arguments: the parse tree, as
2153 returned by `org-element-parse-buffer', the back-end, as
2154 a symbol, and the communication channel, as a plist. It must
2155 return the modified parse tree to transcode.")
2157 (defvar org-export-filter-plain-text-functions nil
2158 "List of functions applied to plain text.
2159 Each filter is called with three arguments: a string which
2160 contains no Org syntax, the back-end, as a symbol, and the
2161 communication channel, as a plist. It must return a string or
2164 (defvar org-export-filter-body-functions nil
2165 "List of functions applied to transcoded body.
2166 Each filter is called with three arguments: a string which
2167 contains no Org syntax, the back-end, as a symbol, and the
2168 communication channel, as a plist. It must return a string or
2171 (defvar org-export-filter-final-output-functions nil
2172 "List of functions applied to the transcoded string.
2173 Each filter is called with three arguments: the full transcoded
2174 string, the back-end, as a symbol, and the communication channel,
2175 as a plist. It must return a string that will be used as the
2176 final export output.")
2179 ;;;; Elements Filters
2181 (defvar org-export-filter-babel-call-functions nil
2182 "List of functions applied to a transcoded babel-call.
2183 Each filter is called with three arguments: the transcoded data,
2184 as a string, the back-end, as a symbol, and the communication
2185 channel, as a plist. It must return a string or nil.")
2187 (defvar org-export-filter-center-block-functions nil
2188 "List of functions applied to a transcoded center block.
2189 Each filter is called with three arguments: the transcoded data,
2190 as a string, the back-end, as a symbol, and the communication
2191 channel, as a plist. It must return a string or nil.")
2193 (defvar org-export-filter-clock-functions nil
2194 "List of functions applied to a transcoded clock.
2195 Each filter is called with three arguments: the transcoded data,
2196 as a string, the back-end, as a symbol, and the communication
2197 channel, as a plist. It must return a string or nil.")
2199 (defvar org-export-filter-diary-sexp-functions nil
2200 "List of functions applied to a transcoded diary-sexp.
2201 Each filter is called with three arguments: the transcoded data,
2202 as a string, the back-end, as a symbol, and the communication
2203 channel, as a plist. It must return a string or nil.")
2205 (defvar org-export-filter-drawer-functions nil
2206 "List of functions applied to a transcoded drawer.
2207 Each filter is called with three arguments: the transcoded data,
2208 as a string, the back-end, as a symbol, and the communication
2209 channel, as a plist. It must return a string or nil.")
2211 (defvar org-export-filter-dynamic-block-functions nil
2212 "List of functions applied to a transcoded dynamic-block.
2213 Each filter is called with three arguments: the transcoded data,
2214 as a string, the back-end, as a symbol, and the communication
2215 channel, as a plist. It must return a string or nil.")
2217 (defvar org-export-filter-example-block-functions nil
2218 "List of functions applied to a transcoded example-block.
2219 Each filter is called with three arguments: the transcoded data,
2220 as a string, the back-end, as a symbol, and the communication
2221 channel, as a plist. It must return a string or nil.")
2223 (defvar org-export-filter-export-block-functions nil
2224 "List of functions applied to a transcoded export-block.
2225 Each filter is called with three arguments: the transcoded data,
2226 as a string, the back-end, as a symbol, and the communication
2227 channel, as a plist. It must return a string or nil.")
2229 (defvar org-export-filter-fixed-width-functions nil
2230 "List of functions applied to a transcoded fixed-width.
2231 Each filter is called with three arguments: the transcoded data,
2232 as a string, the back-end, as a symbol, and the communication
2233 channel, as a plist. It must return a string or nil.")
2235 (defvar org-export-filter-footnote-definition-functions nil
2236 "List of functions applied to a transcoded footnote-definition.
2237 Each filter is called with three arguments: the transcoded data,
2238 as a string, the back-end, as a symbol, and the communication
2239 channel, as a plist. It must return a string or nil.")
2241 (defvar org-export-filter-headline-functions nil
2242 "List of functions applied to a transcoded headline.
2243 Each filter is called with three arguments: the transcoded data,
2244 as a string, the back-end, as a symbol, and the communication
2245 channel, as a plist. It must return a string or nil.")
2247 (defvar org-export-filter-horizontal-rule-functions nil
2248 "List of functions applied to a transcoded horizontal-rule.
2249 Each filter is called with three arguments: the transcoded data,
2250 as a string, the back-end, as a symbol, and the communication
2251 channel, as a plist. It must return a string or nil.")
2253 (defvar org-export-filter-inlinetask-functions nil
2254 "List of functions applied to a transcoded inlinetask.
2255 Each filter is called with three arguments: the transcoded data,
2256 as a string, the back-end, as a symbol, and the communication
2257 channel, as a plist. It must return a string or nil.")
2259 (defvar org-export-filter-item-functions nil
2260 "List of functions applied to a transcoded item.
2261 Each filter is called with three arguments: the transcoded data,
2262 as a string, the back-end, as a symbol, and the communication
2263 channel, as a plist. It must return a string or nil.")
2265 (defvar org-export-filter-keyword-functions nil
2266 "List of functions applied to a transcoded keyword.
2267 Each filter is called with three arguments: the transcoded data,
2268 as a string, the back-end, as a symbol, and the communication
2269 channel, as a plist. It must return a string or nil.")
2271 (defvar org-export-filter-latex-environment-functions nil
2272 "List of functions applied to a transcoded latex-environment.
2273 Each filter is called with three arguments: the transcoded data,
2274 as a string, the back-end, as a symbol, and the communication
2275 channel, as a plist. It must return a string or nil.")
2277 (defvar org-export-filter-node-property-functions nil
2278 "List of functions applied to a transcoded node-property.
2279 Each filter is called with three arguments: the transcoded data,
2280 as a string, the back-end, as a symbol, and the communication
2281 channel, as a plist. It must return a string or nil.")
2283 (defvar org-export-filter-paragraph-functions nil
2284 "List of functions applied to a transcoded paragraph.
2285 Each filter is called with three arguments: the transcoded data,
2286 as a string, the back-end, as a symbol, and the communication
2287 channel, as a plist. It must return a string or nil.")
2289 (defvar org-export-filter-plain-list-functions nil
2290 "List of functions applied to a transcoded plain-list.
2291 Each filter is called with three arguments: the transcoded data,
2292 as a string, the back-end, as a symbol, and the communication
2293 channel, as a plist. It must return a string or nil.")
2295 (defvar org-export-filter-planning-functions nil
2296 "List of functions applied to a transcoded planning.
2297 Each filter is called with three arguments: the transcoded data,
2298 as a string, the back-end, as a symbol, and the communication
2299 channel, as a plist. It must return a string or nil.")
2301 (defvar org-export-filter-property-drawer-functions nil
2302 "List of functions applied to a transcoded property-drawer.
2303 Each filter is called with three arguments: the transcoded data,
2304 as a string, the back-end, as a symbol, and the communication
2305 channel, as a plist. It must return a string or nil.")
2307 (defvar org-export-filter-quote-block-functions nil
2308 "List of functions applied to a transcoded quote block.
2309 Each filter is called with three arguments: the transcoded quote
2310 data, as a string, the back-end, as a symbol, and the
2311 communication channel, as a plist. It must return a string or
2314 (defvar org-export-filter-section-functions nil
2315 "List of functions applied to a transcoded section.
2316 Each filter is called with three arguments: the transcoded data,
2317 as a string, the back-end, as a symbol, and the communication
2318 channel, as a plist. It must return a string or nil.")
2320 (defvar org-export-filter-special-block-functions nil
2321 "List of functions applied to a transcoded special block.
2322 Each filter is called with three arguments: the transcoded data,
2323 as a string, the back-end, as a symbol, and the communication
2324 channel, as a plist. It must return a string or nil.")
2326 (defvar org-export-filter-src-block-functions nil
2327 "List of functions applied to a transcoded src-block.
2328 Each filter is called with three arguments: the transcoded data,
2329 as a string, the back-end, as a symbol, and the communication
2330 channel, as a plist. It must return a string or nil.")
2332 (defvar org-export-filter-table-functions nil
2333 "List of functions applied to a transcoded table.
2334 Each filter is called with three arguments: the transcoded data,
2335 as a string, the back-end, as a symbol, and the communication
2336 channel, as a plist. It must return a string or nil.")
2338 (defvar org-export-filter-table-cell-functions nil
2339 "List of functions applied to a transcoded table-cell.
2340 Each filter is called with three arguments: the transcoded data,
2341 as a string, the back-end, as a symbol, and the communication
2342 channel, as a plist. It must return a string or nil.")
2344 (defvar org-export-filter-table-row-functions nil
2345 "List of functions applied to a transcoded table-row.
2346 Each filter is called with three arguments: the transcoded data,
2347 as a string, the back-end, as a symbol, and the communication
2348 channel, as a plist. It must return a string or nil.")
2350 (defvar org-export-filter-verse-block-functions nil
2351 "List of functions applied to a transcoded verse block.
2352 Each filter is called with three arguments: the transcoded data,
2353 as a string, the back-end, as a symbol, and the communication
2354 channel, as a plist. It must return a string or nil.")
2357 ;;;; Objects Filters
2359 (defvar org-export-filter-bold-functions nil
2360 "List of functions applied to transcoded bold text.
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-code-functions nil
2366 "List of functions applied to transcoded code text.
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-entity-functions nil
2372 "List of functions applied to a transcoded entity.
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-export-snippet-functions nil
2378 "List of functions applied to a transcoded export-snippet.
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.")
2383 (defvar org-export-filter-footnote-reference-functions nil
2384 "List of functions applied to a transcoded footnote-reference.
2385 Each filter is called with three arguments: the transcoded data,
2386 as a string, the back-end, as a symbol, and the communication
2387 channel, as a plist. It must return a string or nil.")
2389 (defvar org-export-filter-inline-babel-call-functions nil
2390 "List of functions applied to a transcoded inline-babel-call.
2391 Each filter is called with three arguments: the transcoded data,
2392 as a string, the back-end, as a symbol, and the communication
2393 channel, as a plist. It must return a string or nil.")
2395 (defvar org-export-filter-inline-src-block-functions nil
2396 "List of functions applied to a transcoded inline-src-block.
2397 Each filter is called with three arguments: the transcoded data,
2398 as a string, the back-end, as a symbol, and the communication
2399 channel, as a plist. It must return a string or nil.")
2401 (defvar org-export-filter-italic-functions nil
2402 "List of functions applied to transcoded italic text.
2403 Each filter is called with three arguments: the transcoded data,
2404 as a string, the back-end, as a symbol, and the communication
2405 channel, as a plist. It must return a string or nil.")
2407 (defvar org-export-filter-latex-fragment-functions nil
2408 "List of functions applied to a transcoded latex-fragment.
2409 Each filter is called with three arguments: the transcoded data,
2410 as a string, the back-end, as a symbol, and the communication
2411 channel, as a plist. It must return a string or nil.")
2413 (defvar org-export-filter-line-break-functions nil
2414 "List of functions applied to a transcoded line-break.
2415 Each filter is called with three arguments: the transcoded data,
2416 as a string, the back-end, as a symbol, and the communication
2417 channel, as a plist. It must return a string or nil.")
2419 (defvar org-export-filter-link-functions nil
2420 "List of functions applied to a transcoded link.
2421 Each filter is called with three arguments: the transcoded data,
2422 as a string, the back-end, as a symbol, and the communication
2423 channel, as a plist. It must return a string or nil.")
2425 (defvar org-export-filter-radio-target-functions nil
2426 "List of functions applied to a transcoded radio-target.
2427 Each filter is called with three arguments: the transcoded data,
2428 as a string, the back-end, as a symbol, and the communication
2429 channel, as a plist. It must return a string or nil.")
2431 (defvar org-export-filter-statistics-cookie-functions nil
2432 "List of functions applied to a transcoded statistics-cookie.
2433 Each filter is called with three arguments: the transcoded data,
2434 as a string, the back-end, as a symbol, and the communication
2435 channel, as a plist. It must return a string or nil.")
2437 (defvar org-export-filter-strike-through-functions nil
2438 "List of functions applied to transcoded strike-through text.
2439 Each filter is called with three arguments: the transcoded data,
2440 as a string, the back-end, as a symbol, and the communication
2441 channel, as a plist. It must return a string or nil.")
2443 (defvar org-export-filter-subscript-functions nil
2444 "List of functions applied to a transcoded subscript.
2445 Each filter is called with three arguments: the transcoded data,
2446 as a string, the back-end, as a symbol, and the communication
2447 channel, as a plist. It must return a string or nil.")
2449 (defvar org-export-filter-superscript-functions nil
2450 "List of functions applied to a transcoded superscript.
2451 Each filter is called with three arguments: the transcoded data,
2452 as a string, the back-end, as a symbol, and the communication
2453 channel, as a plist. It must return a string or nil.")
2455 (defvar org-export-filter-target-functions nil
2456 "List of functions applied to a transcoded target.
2457 Each filter is called with three arguments: the transcoded data,
2458 as a string, the back-end, as a symbol, and the communication
2459 channel, as a plist. It must return a string or nil.")
2461 (defvar org-export-filter-timestamp-functions nil
2462 "List of functions applied to a transcoded timestamp.
2463 Each filter is called with three arguments: the transcoded data,
2464 as a string, the back-end, as a symbol, and the communication
2465 channel, as a plist. It must return a string or nil.")
2467 (defvar org-export-filter-underline-functions nil
2468 "List of functions applied to transcoded underline text.
2469 Each filter is called with three arguments: the transcoded data,
2470 as a string, the back-end, as a symbol, and the communication
2471 channel, as a plist. It must return a string or nil.")
2473 (defvar org-export-filter-verbatim-functions nil
2474 "List of functions applied to transcoded verbatim text.
2475 Each filter is called with three arguments: the transcoded data,
2476 as a string, the back-end, as a symbol, and the communication
2477 channel, as a plist. It must return a string or nil.")
2482 ;; Internal function `org-export-install-filters' installs filters
2483 ;; hard-coded in back-ends (developer filters) and filters from global
2484 ;; variables (user filters) in the communication channel.
2486 ;; Internal function `org-export-filter-apply-functions' takes care
2487 ;; about applying each filter in order to a given data. It ignores
2488 ;; filters returning a nil value but stops whenever a filter returns
2491 (defun org-export-filter-apply-functions (filters value info
)
2492 "Call every function in FILTERS.
2494 Functions are called with three arguments: a value, the export
2495 back-end name and the communication channel. First function in
2496 FILTERS is called with VALUE as its first argument. Second
2497 function in FILTERS is called with the previous result as its
2500 Functions returning nil are skipped. Any function returning the
2501 empty string ends the process, which returns the empty string.
2503 Call is done in a LIFO fashion, to be sure that developer
2504 specified filters, if any, are called first."
2506 (let* ((backend (plist-get info
:back-end
))
2507 (backend-name (and backend
(org-export-backend-name backend
))))
2508 (dolist (filter filters value
)
2509 (let ((result (funcall filter value backend-name info
)))
2510 (cond ((not result
))
2511 ((equal result
"") (throw :exit
""))
2512 (t (setq value result
))))))))
2514 (defun org-export-install-filters (info)
2515 "Install filters properties in communication channel.
2516 INFO is a plist containing the current communication channel.
2517 Return the updated communication channel."
2519 ;; Install user-defined filters with `org-export-filters-alist'
2520 ;; and filters already in INFO (through ext-plist mechanism).
2521 (dolist (p org-export-filters-alist
)
2522 (let* ((prop (car p
))
2523 (info-value (plist-get info prop
))
2524 (default-value (symbol-value (cdr p
))))
2526 (plist-put plist prop
2527 ;; Filters in INFO will be called
2528 ;; before those user provided.
2529 (append (if (listp info-value
) info-value
2532 ;; Prepend back-end specific filters to that list.
2533 (dolist (p (org-export-get-all-filters (plist-get info
:back-end
)))
2534 ;; Single values get consed, lists are appended.
2535 (let ((key (car p
)) (value (cdr p
)))
2540 (if (atom value
) (cons value
(plist-get plist key
))
2541 (append value
(plist-get plist key
))))))))
2542 ;; Return new communication channel.
2543 (org-combine-plists info plist
)))
2549 ;; This is the room for the main function, `org-export-as', along with
2550 ;; its derivative, `org-export-string-as'.
2551 ;; `org-export--copy-to-kill-ring-p' determines if output of these
2552 ;; function should be added to kill ring.
2554 ;; Note that `org-export-as' doesn't really parse the current buffer,
2555 ;; but a copy of it (with the same buffer-local variables and
2556 ;; visibility), where macros and include keywords are expanded and
2557 ;; Babel blocks are executed, if appropriate.
2558 ;; `org-export-with-buffer-copy' macro prepares that copy.
2560 ;; File inclusion is taken care of by
2561 ;; `org-export-expand-include-keyword' and
2562 ;; `org-export--prepare-file-contents'. Structure wise, including
2563 ;; a whole Org file in a buffer often makes little sense. For
2564 ;; example, if the file contains a headline and the include keyword
2565 ;; was within an item, the item should contain the headline. That's
2566 ;; why file inclusion should be done before any structure can be
2567 ;; associated to the file, that is before parsing.
2569 ;; `org-export-insert-default-template' is a command to insert
2570 ;; a default template (or a back-end specific template) at point or in
2573 (defun org-export-copy-buffer ()
2574 "Return a copy of the current buffer.
2575 The copy preserves Org buffer-local variables, visibility and
2577 (let ((copy-buffer-fun (org-export--generate-copy-script (current-buffer)))
2578 (new-buf (generate-new-buffer (buffer-name))))
2579 (with-current-buffer new-buf
2580 (funcall copy-buffer-fun
)
2581 (set-buffer-modified-p nil
))
2584 (defmacro org-export-with-buffer-copy
(&rest body
)
2585 "Apply BODY in a copy of the current buffer.
2586 The copy preserves local variables, visibility and contents of
2587 the original buffer. Point is at the beginning of the buffer
2588 when BODY is applied."
2590 (org-with-gensyms (buf-copy)
2591 `(let ((,buf-copy
(org-export-copy-buffer)))
2593 (with-current-buffer ,buf-copy
2594 (goto-char (point-min))
2596 (and (buffer-live-p ,buf-copy
)
2597 ;; Kill copy without confirmation.
2598 (progn (with-current-buffer ,buf-copy
2599 (restore-buffer-modified-p nil
))
2600 (kill-buffer ,buf-copy
)))))))
2602 (defun org-export--generate-copy-script (buffer)
2603 "Generate a function duplicating BUFFER.
2605 The copy will preserve local variables, visibility, contents and
2606 narrowing of the original buffer. If a region was active in
2607 BUFFER, contents will be narrowed to that region instead.
2609 The resulting function can be evaluated at a later time, from
2610 another buffer, effectively cloning the original buffer there.
2612 The function assumes BUFFER's major mode is `org-mode'."
2613 (with-current-buffer buffer
2615 (let ((inhibit-modification-hooks t
))
2616 ;; Set major mode. Ignore `org-mode-hook' as it has been run
2617 ;; already in BUFFER.
2618 (let ((org-mode-hook nil
) (org-inhibit-startup t
)) (org-mode))
2619 ;; Copy specific buffer local variables and variables set
2620 ;; through BIND keywords.
2621 ,@(let ((bound-variables (org-export--list-bound-variables))
2623 (dolist (entry (buffer-local-variables (buffer-base-buffer)) vars
)
2625 (let ((var (car entry
))
2627 (and (not (memq var org-export-ignored-local-variables
))
2631 buffer-file-coding-system
))
2632 (assq var bound-variables
)
2633 (string-match "^\\(org-\\|orgtbl-\\)"
2635 ;; Skip unreadable values, as they cannot be
2636 ;; sent to external process.
2637 (or (not val
) (ignore-errors (read (format "%S" val
))))
2638 (push `(set (make-local-variable (quote ,var
))
2641 ;; Whole buffer contents.
2643 ,(org-with-wide-buffer
2644 (buffer-substring-no-properties
2645 (point-min) (point-max))))
2647 ,(if (org-region-active-p)
2648 `(narrow-to-region ,(region-beginning) ,(region-end))
2649 `(narrow-to-region ,(point-min) ,(point-max)))
2650 ;; Current position of point.
2651 (goto-char ,(point))
2652 ;; Overlays with invisible property.
2654 (dolist (ov (overlays-in (point-min) (point-max)) ov-set
)
2655 (let ((invis-prop (overlay-get ov
'invisible
)))
2658 (make-overlay ,(overlay-start ov
)
2660 'invisible
(quote ,invis-prop
))
2663 (defun org-export--delete-comment-trees ()
2664 "Delete commented trees and commented inlinetasks in the buffer.
2665 Narrowing, if any, is ignored."
2666 (org-with-wide-buffer
2667 (goto-char (point-min))
2668 (let* ((case-fold-search t
)
2669 (regexp (concat org-outline-regexp-bol
".*" org-comment-string
)))
2670 (while (re-search-forward regexp nil t
)
2671 (let ((element (org-element-at-point)))
2672 (when (org-element-property :commentedp element
)
2673 (delete-region (org-element-property :begin element
)
2674 (org-element-property :end element
))))))))
2676 (defun org-export--prune-tree (data info
)
2677 "Prune non exportable elements from DATA.
2678 DATA is the parse tree to traverse. INFO is the plist holding
2679 export info. Also set `:ignore-list' in INFO to a list of
2680 objects which should be ignored during export, but not removed
2682 (letrec ((ignore nil
)
2683 ;; First find trees containing a select tag, if any.
2684 (selected (org-export--selected-trees data info
))
2687 ;; Prune non-exportable elements and objects from tree.
2688 ;; As a special case, special rows and cells from tables
2689 ;; are stored in IGNORE, as they still need to be
2690 ;; accessed during export.
2692 (let ((type (org-element-type data
)))
2693 (if (org-export--skip-p data info selected
)
2694 (if (memq type
'(table-cell table-row
)) (push data ignore
)
2695 (org-element-extract-element data
))
2696 (if (and (eq type
'headline
)
2697 (eq (plist-get info
:with-archived-trees
)
2699 (org-element-property :archivedp data
))
2700 ;; If headline is archived but tree below has
2701 ;; to be skipped, remove contents.
2702 (org-element-set-contents data
)
2703 ;; Move into recursive objects/elements.
2704 (mapc walk-data
(org-element-contents data
)))
2705 ;; Move into secondary string, if any.
2706 (dolist (p (cdr (assq type
2707 org-element-secondary-value-alist
)))
2708 (mapc walk-data
(org-element-property p data
))))))))
2710 ;; Collect definitions before possibly pruning them so as
2711 ;; to avoid parsing them again if they are required.
2712 (org-element-map data
'(footnote-definition footnote-reference
)
2715 ((eq 'footnote-definition
(org-element-type f
)) f
)
2716 ((and (eq 'inline
(org-element-property :type f
))
2717 (org-element-property :label f
))
2720 ;; If a select tag is active, also ignore the section before the
2721 ;; first headline, if any.
2723 (let ((first-element (car (org-element-contents data
))))
2724 (when (eq (org-element-type first-element
) 'section
)
2725 (org-element-extract-element first-element
))))
2726 ;; Prune tree and communication channel.
2727 (funcall walk-data data
)
2728 (dolist (entry (append
2729 ;; Priority is given to back-end specific options.
2730 (org-export-get-all-options (plist-get info
:back-end
))
2731 org-export-options-alist
))
2732 (when (eq (nth 4 entry
) 'parse
)
2733 (funcall walk-data
(plist-get info
(car entry
)))))
2734 (let ((missing (org-export--missing-definitions data definitions
)))
2735 (funcall walk-data missing
)
2736 (org-export--install-footnote-definitions missing data
))
2737 ;; Eventually set `:ignore-list'.
2738 (plist-put info
:ignore-list ignore
)))
2740 (defun org-export--missing-definitions (tree definitions
)
2741 "List footnote definitions missing from TREE.
2742 Missing definitions are searched within DEFINITIONS, which is
2743 a list of footnote definitions or in the widened buffer."
2746 ;; List all footnote labels encountered in DATA. Inline
2747 ;; footnote references are ignored.
2748 (org-element-map data
'footnote-reference
2750 (and (eq (org-element-property :type reference
) 'standard
)
2751 (org-element-property :label reference
))))))
2752 defined undefined missing-definitions
)
2753 ;; Partition DIRECT-REFERENCES between DEFINED and UNDEFINED
2755 (let ((known-definitions
2756 (org-element-map tree
'(footnote-reference footnote-definition
)
2758 (and (or (eq (org-element-type f
) 'footnote-definition
)
2759 (eq (org-element-property :type f
) 'inline
))
2760 (org-element-property :label f
)))))
2762 (dolist (l (funcall list-labels tree
))
2763 (cond ((member l seen
))
2764 ((member l known-definitions
) (push l defined
))
2765 (t (push l undefined
)))))
2766 ;; Complete MISSING-DEFINITIONS by finding the definition of every
2767 ;; undefined label, first by looking into DEFINITIONS, then by
2768 ;; searching the widened buffer. This is a recursive process
2769 ;; since definitions found can themselves contain an undefined
2772 (let* ((label (pop undefined
))
2776 (lambda (d) (and (equal (org-element-property :label d
) label
)
2779 ((pcase (org-footnote-get-definition label
)
2781 (org-with-wide-buffer
2783 (let ((datum (org-element-context)))
2784 (if (eq (org-element-type datum
) 'footnote-reference
)
2786 ;; Parse definition with contents.
2789 (org-element-property :begin datum
)
2790 (org-element-property :end datum
))
2791 (org-element-map (org-element-parse-buffer)
2792 'footnote-definition
#'identity nil t
))))))
2794 (t (user-error "Definition not found for footnote %s" label
)))))
2795 (push label defined
)
2796 (push definition missing-definitions
)
2797 ;; Look for footnote references within DEFINITION, since
2798 ;; we may need to also find their definition.
2799 (dolist (l (funcall list-labels definition
))
2800 (unless (or (member l defined
) ;Known label
2801 (member l undefined
)) ;Processed later
2802 (push l undefined
)))))
2803 ;; MISSING-DEFINITIONS may contain footnote references with inline
2804 ;; definitions. Make sure those are changed into real footnote
2807 (if (eq (org-element-type d
) 'footnote-definition
) d
2808 (let ((label (org-element-property :label d
)))
2809 (apply #'org-element-create
2810 'footnote-definition
`(:label
,label
:post-blank
1)
2811 (org-element-contents d
)))))
2812 missing-definitions
)))
2814 (defun org-export--install-footnote-definitions (definitions tree
)
2815 "Install footnote definitions in tree.
2817 DEFINITIONS is the list of footnote definitions to install. TREE
2820 If there is a footnote section in TREE, definitions found are
2821 appended to it. If `org-footnote-section' is non-nil, a new
2822 footnote section containing all definitions is inserted in TREE.
2823 Otherwise, definitions are appended at the end of the section
2824 containing their first reference."
2826 ((null definitions
))
2827 ;; If there is a footnote section, insert definitions there.
2828 ((let ((footnote-section
2829 (org-element-map tree
'headline
2830 (lambda (h) (and (org-element-property :footnote-section-p h
) h
))
2832 (and footnote-section
2833 (apply #'org-element-adopt-elements
2835 (nreverse definitions
)))))
2836 ;; If there should be a footnote section, create one containing all
2837 ;; the definitions at the end of the tree.
2838 (org-footnote-section
2839 (org-element-adopt-elements
2841 (org-element-create 'headline
2842 (list :footnote-section-p t
2844 :title org-footnote-section
2845 :raw-value org-footnote-section
)
2846 (apply #'org-element-create
2849 (nreverse definitions
)))))
2850 ;; Otherwise add each definition at the end of the section where it
2851 ;; is first referenced.
2856 ;; Insert footnote definitions in the same section as
2857 ;; their first reference in DATA.
2858 (org-element-map data
'footnote-reference
2860 (when (eq (org-element-property :type reference
) 'standard
)
2861 (let ((label (org-element-property :label reference
)))
2862 (unless (member label seen
)
2867 (and (equal (org-element-property :label d
)
2871 (org-element-adopt-elements
2872 (org-element-lineage reference
'(section))
2874 ;; Also insert definitions for nested
2875 ;; references, if any.
2876 (funcall insert-definitions definition
))))))))))
2877 (funcall insert-definitions tree
)))))
2879 (defun org-export--remove-uninterpreted-data (data info
)
2880 "Change uninterpreted elements back into Org syntax.
2881 DATA is a parse tree or a secondary string. INFO is a plist
2882 containing export options. It is modified by side effect and
2883 returned by the function."
2884 (org-element-map data
2885 '(entity bold italic latex-environment latex-fragment strike-through
2886 subscript superscript underline
)
2889 (cl-case (org-element-type datum
)
2892 (and (not (plist-get info
:with-entities
))
2894 (org-export-expand datum nil
)
2896 (or (org-element-property :post-blank datum
) 0)
2899 ((bold italic strike-through underline
)
2900 (and (not (plist-get info
:with-emphasize
))
2901 (let ((marker (cl-case (org-element-type datum
)
2904 (strike-through "+")
2908 (org-element-contents datum
)
2912 (or (org-element-property :post-blank datum
)
2915 ;; ... LaTeX environments and fragments...
2916 ((latex-environment latex-fragment
)
2917 (and (eq (plist-get info
:with-latex
) 'verbatim
)
2918 (list (org-export-expand datum nil
))))
2919 ;; ... sub/superscripts...
2920 ((subscript superscript
)
2921 (let ((sub/super-p
(plist-get info
:with-sub-superscript
))
2922 (bracketp (org-element-property :use-brackets-p datum
)))
2923 (and (or (not sub
/super-p
)
2924 (and (eq sub
/super-p
'{}) (not bracketp
)))
2927 (if (eq (org-element-type datum
) 'subscript
)
2930 (and bracketp
"{")))
2931 (org-element-contents datum
)
2934 (and (org-element-property :post-blank datum
)
2936 (org-element-property :post-blank datum
)
2939 ;; Splice NEW at DATUM location in parse tree.
2940 (dolist (e new
(org-element-extract-element datum
))
2941 (unless (equal e
"") (org-element-insert-before e datum
))))))
2943 ;; Return modified parse tree.
2947 (defun org-export-as
2948 (backend &optional subtreep visible-only body-only ext-plist
)
2949 "Transcode current Org buffer into BACKEND code.
2951 BACKEND is either an export back-end, as returned by, e.g.,
2952 `org-export-create-backend', or a symbol referring to
2953 a registered back-end.
2955 If narrowing is active in the current buffer, only transcode its
2958 If a region is active, transcode that region.
2960 When optional argument SUBTREEP is non-nil, transcode the
2961 sub-tree at point, extracting information from the headline
2964 When optional argument VISIBLE-ONLY is non-nil, don't export
2965 contents of hidden elements.
2967 When optional argument BODY-ONLY is non-nil, only return body
2968 code, without surrounding template.
2970 Optional argument EXT-PLIST, when provided, is a property list
2971 with external parameters overriding Org default settings, but
2972 still inferior to file-local settings.
2974 Return code as a string."
2975 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
2976 (org-export-barf-if-invalid-backend backend
)
2979 ;; Narrow buffer to an appropriate region or subtree for
2980 ;; parsing. If parsing subtree, be sure to remove main
2981 ;; headline, planning data and property drawer.
2982 (cond ((org-region-active-p)
2983 (narrow-to-region (region-beginning) (region-end)))
2985 (org-narrow-to-subtree)
2986 (goto-char (point-min))
2987 (org-end-of-meta-data)
2988 (narrow-to-region (point) (point-max))))
2989 ;; Initialize communication channel with original buffer
2990 ;; attributes, unavailable in its copy.
2991 (let* ((org-export-current-backend (org-export-backend-name backend
))
2992 (info (org-combine-plists
2993 (org-export--get-export-attributes
2994 backend subtreep visible-only body-only
)
2995 (org-export--get-buffer-attributes)))
2998 (mapcar (lambda (o) (and (eq (nth 4 o
) 'parse
) (nth 1 o
)))
2999 (append (org-export-get-all-options backend
)
3000 org-export-options-alist
))))
3002 ;; Update communication channel and get parse tree. Buffer
3003 ;; isn't parsed directly. Instead, all buffer modifications
3004 ;; and consequent parsing are undertaken in a temporary copy.
3005 (org-export-with-buffer-copy
3006 ;; Run first hook with current back-end's name as argument.
3007 (run-hook-with-args 'org-export-before-processing-hook
3008 (org-export-backend-name backend
))
3009 ;; Include files, delete comments and expand macros.
3010 (org-export-expand-include-keyword)
3011 (org-export--delete-comment-trees)
3012 (org-macro-initialize-templates)
3013 (org-macro-replace-all org-macro-templates nil parsed-keywords
)
3014 ;; Refresh buffer properties and radio targets after
3015 ;; potentially invasive previous changes. Likewise, do it
3016 ;; again after executing Babel code.
3017 (org-set-regexps-and-options)
3018 (org-update-radio-target-regexp)
3019 (when org-export-babel-evaluate
3020 (org-babel-exp-process-buffer)
3021 (org-set-regexps-and-options)
3022 (org-update-radio-target-regexp))
3023 ;; Run last hook with current back-end's name as argument.
3024 ;; Update buffer properties and radio targets one last time
3026 (goto-char (point-min))
3028 (run-hook-with-args 'org-export-before-parsing-hook
3029 (org-export-backend-name backend
)))
3030 (org-set-regexps-and-options)
3031 (org-update-radio-target-regexp)
3032 ;; Update communication channel with environment.
3035 info
(org-export-get-environment backend subtreep ext-plist
)))
3036 ;; De-activate uninterpreted data from parsed keywords.
3037 (dolist (entry (append (org-export-get-all-options backend
)
3038 org-export-options-alist
))
3040 (`(,p
,_
,_
,_ parse
)
3041 (let ((value (plist-get info p
)))
3044 (org-export--remove-uninterpreted-data value info
))))
3046 ;; Install user's and developer's filters.
3047 (setq info
(org-export-install-filters info
))
3048 ;; Call options filters and update export options. We do not
3049 ;; use `org-export-filter-apply-functions' here since the
3050 ;; arity of such filters is different.
3051 (let ((backend-name (org-export-backend-name backend
)))
3052 (dolist (filter (plist-get info
:filter-options
))
3053 (let ((result (funcall filter info backend-name
)))
3054 (when result
(setq info result
)))))
3055 ;; Expand export-specific set of macros: {{{author}}},
3056 ;; {{{date(FORMAT)}}}, {{{email}}} and {{{title}}}. It must
3057 ;; be done once regular macros have been expanded, since
3058 ;; parsed keywords may contain one of them.
3059 (org-macro-replace-all
3061 (cons "author" (org-element-interpret-data (plist-get info
:author
)))
3063 (let* ((date (plist-get info
:date
))
3064 (value (or (org-element-interpret-data date
) "")))
3065 (if (and (consp date
)
3067 (eq (org-element-type (car date
)) 'timestamp
))
3068 (format "(eval (if (org-string-nw-p \"$1\") %s %S))"
3069 (format "(org-timestamp-format '%S \"$1\")"
3070 (org-element-copy (car date
)))
3073 (cons "email" (org-element-interpret-data (plist-get info
:email
)))
3074 (cons "title" (org-element-interpret-data (plist-get info
:title
)))
3075 (cons "results" "$1"))
3079 (setq tree
(org-element-parse-buffer nil visible-only
))
3080 ;; Prune tree from non-exported elements and transform
3081 ;; uninterpreted elements or objects in both parse tree and
3082 ;; communication channel.
3083 (org-export--prune-tree tree info
)
3084 (org-export--remove-uninterpreted-data tree info
)
3085 ;; Call parse tree filters.
3087 (org-export-filter-apply-functions
3088 (plist-get info
:filter-parse-tree
) tree info
))
3089 ;; Now tree is complete, compute its properties and add them
3090 ;; to communication channel.
3091 (setq info
(org-export--collect-tree-properties tree info
))
3092 ;; Eventually transcode TREE. Wrap the resulting string into
3094 (let* ((body (org-element-normalize-string
3095 (or (org-export-data tree info
) "")))
3096 (inner-template (cdr (assq 'inner-template
3097 (plist-get info
:translate-alist
))))
3098 (full-body (org-export-filter-apply-functions
3099 (plist-get info
:filter-body
)
3100 (if (not (functionp inner-template
)) body
3101 (funcall inner-template body info
))
3103 (template (cdr (assq 'template
3104 (plist-get info
:translate-alist
)))))
3105 ;; Remove all text properties since they cannot be
3106 ;; retrieved from an external process. Finally call
3107 ;; final-output filter and return result.
3109 (org-export-filter-apply-functions
3110 (plist-get info
:filter-final-output
)
3111 (if (or (not (functionp template
)) body-only
) full-body
3112 (funcall template full-body info
))
3116 (defun org-export-string-as (string backend
&optional body-only ext-plist
)
3117 "Transcode STRING into BACKEND code.
3119 BACKEND is either an export back-end, as returned by, e.g.,
3120 `org-export-create-backend', or a symbol referring to
3121 a registered back-end.
3123 When optional argument BODY-ONLY is non-nil, only return body
3124 code, without preamble nor postamble.
3126 Optional argument EXT-PLIST, when provided, is a property list
3127 with external parameters overriding Org default settings, but
3128 still inferior to file-local settings.
3130 Return code as a string."
3133 (let ((org-inhibit-startup t
)) (org-mode))
3134 (org-export-as backend nil nil body-only ext-plist
)))
3137 (defun org-export-replace-region-by (backend)
3138 "Replace the active region by its export to BACKEND.
3139 BACKEND is either an export back-end, as returned by, e.g.,
3140 `org-export-create-backend', or a symbol referring to
3141 a registered back-end."
3142 (unless (org-region-active-p) (user-error "No active region to replace"))
3144 (org-export-string-as
3145 (delete-and-extract-region (region-beginning) (region-end)) backend t
)))
3148 (defun org-export-insert-default-template (&optional backend subtreep
)
3149 "Insert all export keywords with default values at beginning of line.
3151 BACKEND is a symbol referring to the name of a registered export
3152 back-end, for which specific export options should be added to
3153 the template, or `default' for default template. When it is nil,
3154 the user will be prompted for a category.
3156 If SUBTREEP is non-nil, export configuration will be set up
3157 locally for the subtree through node properties."
3159 (unless (derived-mode-p 'org-mode
) (user-error "Not in an Org mode buffer"))
3160 (when (and subtreep
(org-before-first-heading-p))
3161 (user-error "No subtree to set export options for"))
3162 (let ((node (and subtreep
(save-excursion (org-back-to-heading t
) (point))))
3166 (org-completing-read
3167 "Options category: "
3170 (symbol-name (org-export-backend-name b
)))
3171 org-export-registered-backends
))
3174 ;; Populate OPTIONS and KEYWORDS.
3175 (dolist (entry (cond ((eq backend
'default
) org-export-options-alist
)
3176 ((org-export-backend-p backend
)
3177 (org-export-backend-options backend
))
3178 (t (org-export-backend-options
3179 (org-export-get-backend backend
)))))
3180 (let ((keyword (nth 1 entry
))
3181 (option (nth 2 entry
)))
3183 (keyword (unless (assoc keyword keywords
)
3185 (if (eq (nth 4 entry
) 'split
)
3186 (mapconcat #'identity
(eval (nth 3 entry
)) " ")
3187 (eval (nth 3 entry
)))))
3188 (push (cons keyword value
) keywords
))))
3189 (option (unless (assoc option options
)
3190 (push (cons option
(eval (nth 3 entry
))) options
))))))
3191 ;; Move to an appropriate location in order to insert options.
3192 (unless subtreep
(beginning-of-line))
3193 ;; First (multiple) OPTIONS lines. Never go past fill-column.
3197 #'(lambda (opt) (format "%s:%S" (car opt
) (cdr opt
)))
3198 (sort options
(lambda (k1 k2
) (string< (car k1
) (car k2
)))))))
3201 node
"EXPORT_OPTIONS" (mapconcat 'identity items
" "))
3203 (insert "#+OPTIONS:")
3206 (< (+ width
(length (car items
)) 1) fill-column
))
3207 (let ((item (pop items
)))
3209 (cl-incf width
(1+ (length item
))))))
3211 ;; Then the rest of keywords, in the order specified in either
3212 ;; `org-export-options-alist' or respective export back-ends.
3213 (dolist (key (nreverse keywords
))
3214 (let ((val (cond ((equal (car key
) "DATE")
3217 (org-insert-time-stamp (current-time)))))
3218 ((equal (car key
) "TITLE")
3219 (or (let ((visited-file
3220 (buffer-file-name (buffer-base-buffer))))
3222 (file-name-sans-extension
3223 (file-name-nondirectory visited-file
))))
3224 (buffer-name (buffer-base-buffer))))
3226 (if subtreep
(org-entry-put node
(concat "EXPORT_" (car key
)) val
)
3230 (if (org-string-nw-p val
) (format " %s" val
) ""))))))))
3232 (defun org-export-expand-include-keyword (&optional included dir footnotes
)
3233 "Expand every include keyword in buffer.
3234 Optional argument INCLUDED is a list of included file names along
3235 with their line restriction, when appropriate. It is used to
3236 avoid infinite recursion. Optional argument DIR is the current
3237 working directory. It is used to properly resolve relative
3238 paths. Optional argument FOOTNOTES is a hash-table used for
3239 storing and resolving footnotes. It is created automatically."
3240 (let ((case-fold-search t
)
3241 (file-prefix (make-hash-table :test
#'equal
))
3243 (footnotes (or footnotes
(make-hash-table :test
#'equal
)))
3244 (include-re "^[ \t]*#\\+INCLUDE:"))
3245 ;; If :minlevel is not set the text-property
3246 ;; `:org-include-induced-level' will be used to determine the
3247 ;; relative level when expanding INCLUDE.
3248 ;; Only affects included Org documents.
3249 (goto-char (point-min))
3250 (while (re-search-forward include-re nil t
)
3251 (put-text-property (line-beginning-position) (line-end-position)
3252 :org-include-induced-level
3253 (1+ (org-reduced-level (or (org-current-level) 0)))))
3254 ;; Expand INCLUDE keywords.
3255 (goto-char (point-min))
3256 (while (re-search-forward include-re nil t
)
3257 (let ((element (save-match-data (org-element-at-point))))
3258 (when (eq (org-element-type element
) 'keyword
)
3260 ;; Extract arguments from keyword's value.
3261 (let* ((value (org-element-property :value element
))
3262 (ind (org-get-indentation))
3266 "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value
)
3269 (let ((matched (match-string 1 value
)))
3270 (when (string-match "\\(::\\(.*?\\)\\)\"?\\'"
3272 (setq location
(match-string 2 matched
))
3274 (replace-match "" nil nil matched
1)))
3276 (org-unbracket-string "\"" "\"" matched
)
3278 (setq value
(replace-match "" nil nil value
)))))
3280 (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
3282 (prog1 (org-not-nil (match-string 1 value
))
3283 (setq value
(replace-match "" nil nil value
)))))
3286 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
3288 (prog1 (match-string 1 value
)
3289 (setq value
(replace-match "" nil nil value
)))))
3291 ((string-match "\\<example\\>" value
) 'literal
)
3292 ((string-match "\\<export\\(?: +\\(.*\\)\\)?" value
)
3294 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value
)
3296 ;; Minimal level of included file defaults to the child
3297 ;; level of the current headline, if any, or one. It
3298 ;; only applies is the file is meant to be included as
3302 (if (string-match ":minlevel +\\([0-9]+\\)" value
)
3303 (prog1 (string-to-number (match-string 1 value
))
3304 (setq value
(replace-match "" nil nil value
)))
3305 (get-text-property (point)
3306 :org-include-induced-level
))))
3307 (args (and (eq env
'literal
) (match-string 1 value
)))
3308 (block (and (string-match "\\<\\(\\S-+\\)\\>" value
)
3309 (match-string 1 value
))))
3311 (delete-region (point) (line-beginning-position 2))
3314 ((not (file-readable-p file
))
3315 (error "Cannot include file %s" file
))
3316 ;; Check if files has already been parsed. Look after
3317 ;; inclusion lines too, as different parts of the same file
3318 ;; can be included too.
3319 ((member (list file lines
) included
)
3320 (error "Recursive file inclusion: %s" file
))
3325 (let ((ind-str (make-string ind ?\s
))
3326 (arg-str (if (stringp args
) (format " %s" args
) ""))
3328 (org-escape-code-in-string
3329 (org-export--prepare-file-contents file lines
))))
3330 (format "%s#+BEGIN_%s%s\n%s%s#+END_%s\n"
3331 ind-str block arg-str contents ind-str block
))))
3334 (let ((ind-str (make-string ind ?\s
))
3336 (org-export--prepare-file-contents file lines
)))
3337 (format "%s#+BEGIN_%s\n%s%s#+END_%s\n"
3338 ind-str block contents ind-str block
))))
3342 (let ((org-inhibit-startup t
)
3345 (org-export--inclusion-absolute-lines
3346 file location only-contents lines
)
3350 (org-export--prepare-file-contents
3351 file lines ind minlevel
3352 (or (gethash file file-prefix
)
3353 (puthash file
(cl-incf current-prefix
) file-prefix
))
3355 (org-export-expand-include-keyword
3356 (cons (list file lines
) included
)
3357 (file-name-directory file
)
3360 ;; Expand footnotes after all files have been included.
3361 ;; Footnotes are stored at end of buffer.
3363 (org-with-wide-buffer
3364 (goto-char (point-max))
3365 (maphash (lambda (k v
) (insert (format "\n[fn:%s] %s\n" k v
)))
3366 footnotes
)))))))))))
3368 (defun org-export--inclusion-absolute-lines (file location only-contents lines
)
3369 "Resolve absolute lines for an included file with file-link.
3371 FILE is string file-name of the file to include. LOCATION is a
3372 string name within FILE to be included (located via
3373 `org-link-search'). If ONLY-CONTENTS is non-nil only the
3374 contents of the named element will be included, as determined
3375 Org-Element. If LINES is non-nil only those lines are included.
3377 Return a string of lines to be included in the format expected by
3378 `org-export--prepare-file-contents'."
3380 (insert-file-contents file
)
3381 (unless (eq major-mode
'org-mode
)
3382 (let ((org-inhibit-startup t
)) (org-mode)))
3384 ;; Enforce consistent search.
3385 (let ((org-link-search-must-match-exact-headline nil
))
3386 (org-link-search location
))
3388 (error "%s for %s::%s" (error-message-string err
) file location
)))
3389 (let* ((element (org-element-at-point))
3391 (and only-contents
(org-element-property :contents-begin element
))))
3393 (or contents-begin
(org-element-property :begin element
))
3394 (org-element-property (if contents-begin
:contents-end
:end
) element
))
3395 (when (and only-contents
3396 (memq (org-element-type element
) '(headline inlinetask
)))
3397 ;; Skip planning line and property-drawer.
3398 (goto-char (point-min))
3399 (when (looking-at-p org-planning-line-re
) (forward-line))
3400 (when (looking-at org-property-drawer-re
) (goto-char (match-end 0)))
3401 (unless (bolp) (forward-line))
3402 (narrow-to-region (point) (point-max))))
3404 (org-skip-whitespace)
3406 (let* ((lines (split-string lines
"-"))
3407 (lbeg (string-to-number (car lines
)))
3408 (lend (string-to-number (cadr lines
)))
3409 (beg (if (zerop lbeg
) (point-min)
3410 (goto-char (point-min))
3411 (forward-line (1- lbeg
))
3413 (end (if (zerop lend
) (point-max)
3415 (forward-line (1- lend
))
3417 (narrow-to-region beg end
)))
3418 (let ((end (point-max)))
3419 (goto-char (point-min))
3421 (let ((start-line (line-number-at-pos)))
3427 (while (< (point) end
) (cl-incf counter
) (forward-line))
3430 (defun org-export--prepare-file-contents
3431 (file &optional lines ind minlevel id footnotes
)
3432 "Prepare contents of FILE for inclusion and return it as a string.
3434 When optional argument LINES is a string specifying a range of
3435 lines, include only those lines.
3437 Optional argument IND, when non-nil, is an integer specifying the
3438 global indentation of returned contents. Since its purpose is to
3439 allow an included file to stay in the same environment it was
3440 created (e.g., a list item), it doesn't apply past the first
3441 headline encountered.
3443 Optional argument MINLEVEL, when non-nil, is an integer
3444 specifying the level that any top-level headline in the included
3447 Optional argument ID is an integer that will be inserted before
3448 each footnote definition and reference if FILE is an Org file.
3449 This is useful to avoid conflicts when more than one Org file
3450 with footnotes is included in a document.
3452 Optional argument FOOTNOTES is a hash-table to store footnotes in
3453 the included document."
3455 (insert-file-contents file
)
3457 (let* ((lines (split-string lines
"-"))
3458 (lbeg (string-to-number (car lines
)))
3459 (lend (string-to-number (cadr lines
)))
3460 (beg (if (zerop lbeg
) (point-min)
3461 (goto-char (point-min))
3462 (forward-line (1- lbeg
))
3464 (end (if (zerop lend
) (point-max)
3465 (goto-char (point-min))
3466 (forward-line (1- lend
))
3468 (narrow-to-region beg end
)))
3469 ;; Remove blank lines at beginning and end of contents. The logic
3470 ;; behind that removal is that blank lines around include keyword
3471 ;; override blank lines in included file.
3472 (goto-char (point-min))
3473 (org-skip-whitespace)
3475 (delete-region (point-min) (point))
3476 (goto-char (point-max))
3477 (skip-chars-backward " \r\t\n")
3479 (delete-region (point) (point-max))
3480 ;; If IND is set, preserve indentation of include keyword until
3481 ;; the first headline encountered.
3482 (when (and ind
(> ind
0))
3483 (unless (eq major-mode
'org-mode
)
3484 (let ((org-inhibit-startup t
)) (org-mode)))
3485 (goto-char (point-min))
3486 (let ((ind-str (make-string ind ?\s
)))
3487 (while (not (or (eobp) (looking-at org-outline-regexp-bol
)))
3488 ;; Do not move footnote definitions out of column 0.
3489 (unless (and (looking-at org-footnote-definition-re
)
3490 (eq (org-element-type (org-element-at-point))
3491 'footnote-definition
))
3494 ;; When MINLEVEL is specified, compute minimal level for headlines
3495 ;; in the file (CUR-MIN), and remove stars to each headline so
3496 ;; that headlines with minimal level have a level of MINLEVEL.
3498 (unless (eq major-mode
'org-mode
)
3499 (let ((org-inhibit-startup t
)) (org-mode)))
3500 (org-with-limited-levels
3501 (let ((levels (org-map-entries
3502 (lambda () (org-reduced-level (org-current-level))))))
3504 (let ((offset (- minlevel
(apply #'min levels
))))
3505 (unless (zerop offset
)
3506 (when org-odd-levels-only
(setq offset
(* offset
2)))
3507 ;; Only change stars, don't bother moving whole
3511 (if (< offset
0) (delete-char (abs offset
))
3512 (insert (make-string offset ?
*)))))))))))
3513 ;; Append ID to all footnote references and definitions, so they
3514 ;; become file specific and cannot collide with footnotes in other
3515 ;; included files. Further, collect relevant footnote definitions
3516 ;; outside of LINES, in order to reintroduce them later.
3518 (let ((marker-min (point-min-marker))
3519 (marker-max (point-max-marker))
3522 ;; Generate new label from LABEL by prefixing it with
3524 (format "-%d-%s" id label
)))
3527 ;; Replace OLD label with NEW in footnote F.
3529 (goto-char (+ (org-element-property :begin f
) 4))
3530 (looking-at (regexp-quote old
))
3531 (replace-match new
))))
3533 (goto-char (point-min))
3534 (while (re-search-forward org-footnote-re nil t
)
3535 (let ((footnote (save-excursion
3537 (org-element-context))))
3538 (when (memq (org-element-type footnote
)
3539 '(footnote-definition footnote-reference
))
3540 (let* ((label (org-element-property :label footnote
)))
3541 ;; Update the footnote-reference at point and collect
3542 ;; the new label, which is only used for footnotes
3545 (let ((seen (cdr (assoc label seen-alist
))))
3546 (if seen
(funcall set-new-label footnote label seen
)
3547 (let ((new (funcall get-new-label label
)))
3548 (push (cons label new
) seen-alist
)
3549 (org-with-wide-buffer
3550 (let* ((def (org-footnote-get-definition label
))
3553 (or (< beg marker-min
)
3554 (>= beg marker-max
)))
3555 ;; Store since footnote-definition is
3556 ;; outside of LINES.
3558 (org-element-normalize-string (nth 3 def
))
3560 (funcall set-new-label footnote label new
)))))))))
3561 (set-marker marker-min nil
)
3562 (set-marker marker-max nil
)))
3563 (org-element-normalize-string (buffer-string))))
3565 (defun org-export--copy-to-kill-ring-p ()
3566 "Return a non-nil value when output should be added to the kill ring.
3567 See also `org-export-copy-to-kill-ring'."
3568 (if (eq org-export-copy-to-kill-ring
'if-interactive
)
3569 (not (or executing-kbd-macro noninteractive
))
3570 (eq org-export-copy-to-kill-ring t
)))
3574 ;;; Tools For Back-Ends
3576 ;; A whole set of tools is available to help build new exporters. Any
3577 ;; function general enough to have its use across many back-ends
3578 ;; should be added here.
3580 ;;;; For Affiliated Keywords
3582 ;; `org-export-read-attribute' reads a property from a given element
3583 ;; as a plist. It can be used to normalize affiliated keywords'
3586 ;; Since captions can span over multiple lines and accept dual values,
3587 ;; their internal representation is a bit tricky. Therefore,
3588 ;; `org-export-get-caption' transparently returns a given element's
3589 ;; caption as a secondary string.
3591 (defun org-export-read-attribute (attribute element
&optional property
)
3592 "Turn ATTRIBUTE property from ELEMENT into a plist.
3594 When optional argument PROPERTY is non-nil, return the value of
3595 that property within attributes.
3597 This function assumes attributes are defined as \":keyword
3598 value\" pairs. It is appropriate for `:attr_html' like
3601 All values will become strings except the empty string and
3602 \"nil\", which will become nil. Also, values containing only
3603 double quotes will be read as-is, which means that \"\" value
3604 will become the empty string."
3605 (let* ((prepare-value
3608 (cond ((member str
'(nil "" "nil")) nil
)
3609 ((string-match "^\"\\(\"+\\)?\"$" str
)
3610 (or (match-string 1 str
) ""))
3613 (let ((value (org-element-property attribute element
)))
3615 (let ((s (mapconcat 'identity value
" ")) result
)
3616 (while (string-match
3617 "\\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ \t]+\\|$\\)"
3619 (let ((value (substring s
0 (match-beginning 0))))
3620 (push (funcall prepare-value value
) result
))
3621 (push (intern (match-string 1 s
)) result
)
3622 (setq s
(substring s
(match-end 0))))
3623 ;; Ignore any string before first property with `cdr'.
3624 (cdr (nreverse (cons (funcall prepare-value s
) result
))))))))
3625 (if property
(plist-get attributes property
) attributes
)))
3627 (defun org-export-get-caption (element &optional shortp
)
3628 "Return caption from ELEMENT as a secondary string.
3630 When optional argument SHORTP is non-nil, return short caption,
3631 as a secondary string, instead.
3633 Caption lines are separated by a white space."
3634 (let ((full-caption (org-element-property :caption element
)) caption
)
3635 (dolist (line full-caption
(cdr caption
))
3636 (let ((cap (funcall (if shortp
'cdr
'car
) line
)))
3638 (setq caption
(nconc (list " ") (copy-sequence cap
) caption
)))))))
3641 ;;;; For Derived Back-ends
3643 ;; `org-export-with-backend' is a function allowing to locally use
3644 ;; another back-end to transcode some object or element. In a derived
3645 ;; back-end, it may be used as a fall-back function once all specific
3646 ;; cases have been treated.
3648 (defun org-export-with-backend (backend data
&optional contents info
)
3649 "Call a transcoder from BACKEND on DATA.
3650 BACKEND is an export back-end, as returned by, e.g.,
3651 `org-export-create-backend', or a symbol referring to
3652 a registered back-end. DATA is an Org element, object, secondary
3653 string or string. CONTENTS, when non-nil, is the transcoded
3654 contents of DATA element, as a string. INFO, when non-nil, is
3655 the communication channel used for export, as a plist."
3656 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
3657 (org-export-barf-if-invalid-backend backend
)
3658 (let ((type (org-element-type data
)))
3659 (when (memq type
'(nil org-data
)) (error "No foreign transcoder available"))
3660 (let* ((all-transcoders (org-export-get-all-transcoders backend
))
3661 (transcoder (cdr (assq type all-transcoders
))))
3662 (unless (functionp transcoder
) (error "No foreign transcoder available"))
3667 :translate-alist all-transcoders
3668 :exported-data
(make-hash-table :test
#'eq
:size
401)))))
3669 ;; `:internal-references' are shared across back-ends.
3670 (prog1 (funcall transcoder data contents new-info
)
3671 (plist-put info
:internal-references
3672 (plist-get new-info
:internal-references
)))))))
3675 ;;;; For Export Snippets
3677 ;; Every export snippet is transmitted to the back-end. Though, the
3678 ;; latter will only retain one type of export-snippet, ignoring
3679 ;; others, based on the former's target back-end. The function
3680 ;; `org-export-snippet-backend' returns that back-end for a given
3683 (defun org-export-snippet-backend (export-snippet)
3684 "Return EXPORT-SNIPPET targeted back-end as a symbol.
3685 Translation, with `org-export-snippet-translation-alist', is
3687 (let ((back-end (org-element-property :back-end export-snippet
)))
3689 (or (cdr (assoc back-end org-export-snippet-translation-alist
))
3695 ;; `org-export-collect-footnote-definitions' is a tool to list
3696 ;; actually used footnotes definitions in the whole parse tree, or in
3697 ;; a headline, in order to add footnote listings throughout the
3700 ;; `org-export-footnote-first-reference-p' is a predicate used by some
3701 ;; back-ends, when they need to attach the footnote definition only to
3702 ;; the first occurrence of the corresponding label.
3704 ;; `org-export-get-footnote-definition' and
3705 ;; `org-export-get-footnote-number' provide easier access to
3706 ;; additional information relative to a footnote reference.
3708 (defun org-export-get-footnote-definition (footnote-reference info
)
3709 "Return definition of FOOTNOTE-REFERENCE as parsed data.
3710 INFO is the plist used as a communication channel. If no such
3711 definition can be found, raise an error."
3712 (let ((label (org-element-property :label footnote-reference
)))
3713 (if (not label
) (org-element-contents footnote-reference
)
3714 (let ((cache (or (plist-get info
:footnote-definition-cache
)
3715 (let ((hash (make-hash-table :test
#'equal
)))
3716 (plist-put info
:footnote-definition-cache hash
)
3719 (gethash label cache
)
3721 (org-element-map (plist-get info
:parse-tree
)
3722 '(footnote-definition footnote-reference
)
3725 ;; Skip any footnote with a different label.
3726 ;; Also skip any standard footnote reference
3727 ;; with the same label since those cannot
3728 ;; contain a definition.
3729 ((not (equal (org-element-property :label f
) label
)) nil
)
3730 ((eq (org-element-property :type f
) 'standard
) nil
)
3731 ((org-element-contents f
))
3732 ;; Even if the contents are empty, we can not
3733 ;; return nil since that would eventually raise
3734 ;; the error. Instead, return the equivalent
3739 (error "Definition not found for footnote %s" label
))))))
3741 (defun org-export--footnote-reference-map
3742 (function data info
&optional body-first
)
3743 "Apply FUNCTION on every footnote reference in DATA.
3744 INFO is a plist containing export state. By default, as soon as
3745 a new footnote reference is encountered, FUNCTION is called onto
3746 its definition. However, if BODY-FIRST is non-nil, this step is
3747 delayed until the end of the process."
3748 (letrec ((definitions nil
)
3751 (lambda (data delayp
)
3752 ;; Search footnote references through DATA, filling
3753 ;; SEEN-REFS along the way. When DELAYP is non-nil,
3754 ;; store footnote definitions so they can be entered
3756 (org-element-map data
'footnote-reference
3758 (funcall function f
)
3759 (let ((--label (org-element-property :label f
)))
3760 (unless (and --label
(member --label seen-refs
))
3761 (when --label
(push --label seen-refs
))
3762 ;; Search for subsequent references in footnote
3763 ;; definition so numbering follows reading
3764 ;; logic, unless DELAYP in non-nil.
3767 (push (org-export-get-footnote-definition f info
)
3769 ;; Do not force entering inline definitions,
3770 ;; since `org-element-map' already traverses
3771 ;; them at the right time.
3772 ((eq (org-element-property :type f
) 'inline
))
3773 (t (funcall search-ref
3774 (org-export-get-footnote-definition f info
)
3777 ;; Don't enter footnote definitions since it will
3778 ;; happen when their first reference is found.
3779 ;; Moreover, if DELAYP is non-nil, make sure we
3780 ;; postpone entering definitions of inline references.
3781 (if delayp
'(footnote-definition footnote-reference
)
3782 'footnote-definition
)))))
3783 (funcall search-ref data body-first
)
3784 (funcall search-ref
(nreverse definitions
) nil
)))
3786 (defun org-export-collect-footnote-definitions (info &optional data body-first
)
3787 "Return an alist between footnote numbers, labels and definitions.
3789 INFO is the current export state, as a plist.
3791 Definitions are collected throughout the whole parse tree, or
3794 Sorting is done by order of references. As soon as a new
3795 reference is encountered, other references are searched within
3796 its definition. However, if BODY-FIRST is non-nil, this step is
3797 delayed after the whole tree is checked. This alters results
3798 when references are found in footnote definitions.
3800 Definitions either appear as Org data or as a secondary string
3801 for inlined footnotes. Unreferenced definitions are ignored."
3802 (let ((n 0) labels alist
)
3803 (org-export--footnote-reference-map
3805 ;; Collect footnote number, label and definition.
3806 (let ((l (org-element-property :label f
)))
3807 (unless (and l
(member l labels
))
3809 (push (list n l
(org-export-get-footnote-definition f info
)) alist
))
3810 (when l
(push l labels
))))
3811 (or data
(plist-get info
:parse-tree
)) info body-first
)
3814 (defun org-export-footnote-first-reference-p
3815 (footnote-reference info
&optional data body-first
)
3816 "Non-nil when a footnote reference is the first one for its label.
3818 FOOTNOTE-REFERENCE is the footnote reference being considered.
3819 INFO is a plist containing current export state.
3821 Search is done throughout the whole parse tree, or DATA when
3824 By default, as soon as a new footnote reference is encountered,
3825 other references are searched within its definition. However, if
3826 BODY-FIRST is non-nil, this step is delayed after the whole tree
3827 is checked. This alters results when references are found in
3828 footnote definitions."
3829 (let ((label (org-element-property :label footnote-reference
)))
3830 ;; Anonymous footnotes are always a first reference.
3833 (org-export--footnote-reference-map
3835 (let ((l (org-element-property :label f
)))
3836 (when (and l label
(string= label l
))
3837 (throw 'exit
(eq footnote-reference f
)))))
3838 (or data
(plist-get info
:parse-tree
)) info body-first
)))))
3840 (defun org-export-get-footnote-number (footnote info
&optional data body-first
)
3841 "Return number associated to a footnote.
3843 FOOTNOTE is either a footnote reference or a footnote definition.
3844 INFO is the plist containing export state.
3846 Number is unique throughout the whole parse tree, or DATA, when
3849 By default, as soon as a new footnote reference is encountered,
3850 counting process moves into its definition. However, if
3851 BODY-FIRST is non-nil, this step is delayed until the end of the
3852 process, leading to a different order when footnotes are nested."
3855 (label (org-element-property :label footnote
)))
3857 (org-export--footnote-reference-map
3859 (let ((l (org-element-property :label f
)))
3861 ;; Anonymous footnote match: return number.
3862 ((and (not l
) (not label
) (eq footnote f
)) (throw 'exit
(1+ count
)))
3863 ;; Labels match: return number.
3864 ((and label l
(string= label l
)) (throw 'exit
(1+ count
)))
3865 ;; Otherwise store label and increase counter if label
3866 ;; wasn't encountered yet.
3867 ((not l
) (cl-incf count
))
3868 ((not (member l seen
)) (push l seen
) (cl-incf count
)))))
3869 (or data
(plist-get info
:parse-tree
)) info body-first
))))
3874 ;; `org-export-get-relative-level' is a shortcut to get headline
3875 ;; level, relatively to the lower headline level in the parsed tree.
3877 ;; `org-export-get-headline-number' returns the section number of an
3878 ;; headline, while `org-export-number-to-roman' allows it to be
3879 ;; converted to roman numbers. With an optional argument,
3880 ;; `org-export-get-headline-number' returns a number to unnumbered
3881 ;; headlines (used for internal id).
3883 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
3884 ;; `org-export-last-sibling-p' are three useful predicates when it
3885 ;; comes to fulfill the `:headline-levels' property.
3887 ;; `org-export-get-tags', `org-export-get-category' and
3888 ;; `org-export-get-node-property' extract useful information from an
3889 ;; headline or a parent headline. They all handle inheritance.
3891 ;; `org-export-get-alt-title' tries to retrieve an alternative title,
3892 ;; as a secondary string, suitable for table of contents. It falls
3893 ;; back onto default title.
3895 (defun org-export-get-relative-level (headline info
)
3896 "Return HEADLINE relative level within current parsed tree.
3897 INFO is a plist holding contextual information."
3898 (+ (org-element-property :level headline
)
3899 (or (plist-get info
:headline-offset
) 0)))
3901 (defun org-export-low-level-p (headline info
)
3902 "Non-nil when HEADLINE is considered as low level.
3904 INFO is a plist used as a communication channel.
3906 A low level headlines has a relative level greater than
3907 `:headline-levels' property value.
3909 Return value is the difference between HEADLINE relative level
3910 and the last level being considered as high enough, or nil."
3911 (let ((limit (plist-get info
:headline-levels
)))
3912 (when (wholenump limit
)
3913 (let ((level (org-export-get-relative-level headline info
)))
3914 (and (> level limit
) (- level limit
))))))
3916 (defun org-export-get-headline-number (headline info
)
3917 "Return numbered HEADLINE numbering as a list of numbers.
3918 INFO is a plist holding contextual information."
3919 (and (org-export-numbered-headline-p headline info
)
3920 (cdr (assq headline
(plist-get info
:headline-numbering
)))))
3922 (defun org-export-numbered-headline-p (headline info
)
3923 "Return a non-nil value if HEADLINE element should be numbered.
3924 INFO is a plist used as a communication channel."
3926 (lambda (head) (org-not-nil (org-element-property :UNNUMBERED head
)))
3927 (org-element-lineage headline nil t
))
3928 (let ((sec-num (plist-get info
:section-numbers
))
3929 (level (org-export-get-relative-level headline info
)))
3930 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))))
3932 (defun org-export-number-to-roman (n)
3933 "Convert integer N into a roman numeral."
3934 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
3935 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
3936 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
3940 (number-to-string n
)
3942 (if (>= n
(caar roman
))
3943 (setq n
(- n
(caar roman
))
3944 res
(concat res
(cdar roman
)))
3948 (defun org-export-get-tags (element info
&optional tags inherited
)
3949 "Return list of tags associated to ELEMENT.
3951 ELEMENT has either an `headline' or an `inlinetask' type. INFO
3952 is a plist used as a communication channel.
3954 When non-nil, optional argument TAGS should be a list of strings.
3955 Any tag belonging to this list will also be removed.
3957 When optional argument INHERITED is non-nil, tags can also be
3958 inherited from parent headlines and FILETAGS keywords."
3960 (lambda (tag) (member tag tags
))
3961 (if (not inherited
) (org-element-property :tags element
)
3962 ;; Build complete list of inherited tags.
3963 (let ((current-tag-list (org-element-property :tags element
)))
3964 (dolist (parent (org-element-lineage element
))
3965 (dolist (tag (org-element-property :tags parent
))
3966 (when (and (memq (org-element-type parent
) '(headline inlinetask
))
3967 (not (member tag current-tag-list
)))
3968 (push tag current-tag-list
))))
3969 ;; Add FILETAGS keywords and return results.
3970 (org-uniquify (append (plist-get info
:filetags
) current-tag-list
))))))
3972 (defun org-export-get-node-property (property blob
&optional inherited
)
3973 "Return node PROPERTY value for BLOB.
3975 PROPERTY is an upcase symbol (i.e. `:COOKIE_DATA'). BLOB is an
3978 If optional argument INHERITED is non-nil, the value can be
3979 inherited from a parent headline.
3981 Return value is a string or nil."
3982 (let ((headline (if (eq (org-element-type blob
) 'headline
) blob
3983 (org-export-get-parent-headline blob
))))
3984 (if (not inherited
) (org-element-property property blob
)
3985 (let ((parent headline
))
3988 (when (plist-member (nth 1 parent
) property
)
3989 (throw 'found
(org-element-property property parent
)))
3990 (setq parent
(org-element-property :parent parent
))))))))
3992 (defun org-export-get-category (blob info
)
3993 "Return category for element or object BLOB.
3995 INFO is a plist used as a communication channel.
3997 CATEGORY is automatically inherited from a parent headline, from
3998 #+CATEGORY: keyword or created out of original file name. If all
3999 fail, the fall-back value is \"???\"."
4000 (or (org-export-get-node-property :CATEGORY blob t
)
4001 (org-element-map (plist-get info
:parse-tree
) 'keyword
4003 (when (equal (org-element-property :key kwd
) "CATEGORY")
4004 (org-element-property :value kwd
)))
4006 (let ((file (plist-get info
:input-file
)))
4007 (and file
(file-name-sans-extension (file-name-nondirectory file
))))
4010 (defun org-export-get-alt-title (headline _
)
4011 "Return alternative title for HEADLINE, as a secondary string.
4012 If no optional title is defined, fall-back to the regular title."
4013 (let ((alt (org-element-property :ALT_TITLE headline
)))
4014 (if alt
(org-element-parse-secondary-string
4015 alt
(org-element-restriction 'headline
) headline
)
4016 (org-element-property :title headline
))))
4018 (defun org-export-first-sibling-p (blob info
)
4019 "Non-nil when BLOB is the first sibling in its parent.
4020 BLOB is an element or an object. If BLOB is a headline, non-nil
4021 means it is the first sibling in the sub-tree. INFO is a plist
4022 used as a communication channel."
4023 (memq (org-element-type (org-export-get-previous-element blob info
))
4026 (defun org-export-last-sibling-p (blob info
)
4027 "Non-nil when BLOB is the last sibling in its parent.
4028 BLOB is an element or an object. INFO is a plist used as
4029 a communication channel."
4030 (not (org-export-get-next-element blob info
)))
4035 ;; `org-export-get-date' returns a date appropriate for the document
4036 ;; to about to be exported. In particular, it takes care of
4037 ;; `org-export-date-timestamp-format'.
4039 (defun org-export-get-date (info &optional fmt
)
4040 "Return date value for the current document.
4042 INFO is a plist used as a communication channel. FMT, when
4043 non-nil, is a time format string that will be applied on the date
4044 if it consists in a single timestamp object. It defaults to
4045 `org-export-date-timestamp-format' when nil.
4047 A proper date can be a secondary string, a string or nil. It is
4048 meant to be translated with `org-export-data' or alike."
4049 (let ((date (plist-get info
:date
))
4050 (fmt (or fmt org-export-date-timestamp-format
)))
4051 (cond ((not date
) nil
)
4054 (eq (org-element-type (car date
)) 'timestamp
))
4055 (org-timestamp-format (car date
) fmt
))
4061 ;; `org-export-custom-protocol-maybe' handles custom protocol defined
4062 ;; in `org-link-parameters'.
4064 ;; `org-export-get-coderef-format' returns an appropriate format
4065 ;; string for coderefs.
4067 ;; `org-export-inline-image-p' returns a non-nil value when the link
4068 ;; provided should be considered as an inline image.
4070 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
4071 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
4072 ;; returns an appropriate unique identifier.
4074 ;; `org-export-resolve-id-link' returns the first headline with
4075 ;; specified id or custom-id in parse tree, the path to the external
4076 ;; file with the id.
4078 ;; `org-export-resolve-coderef' associates a reference to a line
4079 ;; number in the element it belongs, or returns the reference itself
4080 ;; when the element isn't numbered.
4082 ;; `org-export-file-uri' expands a filename as stored in :path value
4083 ;; of a "file" link into a file URI.
4085 ;; Broken links raise a `org-link-broken' error, which is caught by
4086 ;; `org-export-data' for further processing, depending on
4087 ;; `org-export-with-broken-links' value.
4089 (org-define-error 'org-link-broken
"Unable to resolve link; aborting")
4091 (defun org-export-custom-protocol-maybe (link desc backend
)
4092 "Try exporting LINK with a dedicated function.
4094 DESC is its description, as a string, or nil. BACKEND is the
4095 back-end used for export, as a symbol.
4097 Return output as a string, or nil if no protocol handles LINK.
4099 A custom protocol has precedence over regular back-end export.
4100 The function ignores links with an implicit type (e.g.,
4102 (let ((type (org-element-property :type link
)))
4103 (unless (or (member type
'("coderef" "custom-id" "fuzzy" "radio"))
4105 (let ((protocol (org-link-get-parameter type
:export
)))
4106 (and (functionp protocol
)
4108 (org-link-unescape (org-element-property :path link
))
4112 (defun org-export-get-coderef-format (path desc
)
4113 "Return format string for code reference link.
4114 PATH is the link path. DESC is its description."
4116 (cond ((not desc
) "%s")
4117 ((string-match (regexp-quote (concat "(" path
")")) desc
)
4118 (replace-match "%s" t t desc
))
4121 (defun org-export-inline-image-p (link &optional rules
)
4122 "Non-nil if LINK object points to an inline image.
4124 Optional argument is a set of RULES defining inline images. It
4125 is an alist where associations have the following shape:
4129 Applying a rule means apply REGEXP against LINK's path when its
4130 type is TYPE. The function will return a non-nil value if any of
4131 the provided rules is non-nil. The default rule is
4132 `org-export-default-inline-image-rule'.
4134 This only applies to links without a description."
4135 (and (not (org-element-contents link
))
4136 (let ((case-fold-search t
))
4138 (dolist (rule (or rules org-export-default-inline-image-rule
))
4139 (and (string= (org-element-property :type link
) (car rule
))
4140 (string-match-p (cdr rule
)
4141 (org-element-property :path link
))
4142 (throw 'exit t
)))))))
4144 (defun org-export-resolve-coderef (ref info
)
4145 "Resolve a code reference REF.
4147 INFO is a plist used as a communication channel.
4149 Return associated line number in source code, or REF itself,
4150 depending on src-block or example element's switches. Throw an
4151 error if no block contains REF."
4152 (or (org-element-map (plist-get info
:parse-tree
) '(example-block src-block
)
4155 (insert (org-trim (org-element-property :value el
)))
4156 (let* ((label-fmt (or (org-element-property :label-fmt el
)
4157 org-coderef-label-format
))
4158 (ref-re (org-src-coderef-regexp label-fmt ref
)))
4159 ;; Element containing REF is found. Resolve it to
4160 ;; either a label or a line number, as needed.
4161 (when (re-search-backward ref-re nil t
)
4162 (if (org-element-property :use-labels el
) ref
4163 (+ (or (org-export-get-loc el info
) 0)
4164 (line-number-at-pos)))))))
4166 (signal 'org-link-broken
(list ref
))))
4168 (defun org-export-search-cells (datum)
4169 "List search cells for element or object DATUM.
4171 A search cell follows the pattern (TYPE . SEARCH) where
4173 TYPE is a symbol among `headline', `custom-id', `target' and
4176 SEARCH is the string a link is expected to match. More
4179 - headline's title, as a list of strings, if TYPE is
4182 - CUSTOM_ID value, as a string, if TYPE is `custom-id'.
4184 - target's or radio-target's name as a list of strings if
4187 - NAME affiliated keyword is TYPE is `other'.
4189 A search cell is the internal representation of a fuzzy link. It
4190 ignores white spaces and statistics cookies, if applicable."
4191 (pcase (org-element-type datum
)
4193 (let ((title (split-string
4194 (replace-regexp-in-string
4195 "\\[[0-9]*\\(?:%\\|/[0-9]*\\)\\]" ""
4196 (org-element-property :raw-value datum
)))))
4199 (cons 'headline title
)
4201 (let ((custom-id (org-element-property :custom-id datum
)))
4202 (and custom-id
(cons 'custom-id custom-id
)))))))
4204 (list (cons 'target
(split-string (org-element-property :value datum
)))))
4205 ((and (let name
(org-element-property :name datum
))
4207 (list (cons 'other
(split-string name
))))
4210 (defun org-export-string-to-search-cell (s)
4211 "Return search cells associated to string S.
4212 S is either the path of a fuzzy link or a search option, i.e., it
4213 tries to match either a headline (through custom ID or title),
4214 a target or a named element."
4215 (pcase (string-to-char s
)
4216 (?
* (list (cons 'headline
(split-string (substring s
1)))))
4217 (?
# (list (cons 'custom-id
(substring s
1))))
4218 ((let search
(split-string s
))
4219 (list (cons 'target search
) (cons 'other search
)))))
4221 (defun org-export-match-search-cell-p (datum cells
)
4222 "Non-nil when DATUM matches search cells CELLS.
4223 DATUM is an element or object. CELLS is a list of search cells,
4224 as returned by `org-export-search-cells'."
4225 (let ((targets (org-export-search-cells datum
)))
4226 (and targets
(cl-some (lambda (cell) (member cell targets
)) cells
))))
4228 (defun org-export-resolve-fuzzy-link (link info
)
4229 "Return LINK destination.
4231 INFO is a plist holding contextual information.
4233 Return value can be an object or an element:
4235 - If LINK path matches a target object (i.e. <<path>>) return it.
4237 - If LINK path exactly matches the name affiliated keyword
4238 (i.e. #+NAME: path) of an element, return that element.
4240 - If LINK path exactly matches any headline name, return that
4243 - Otherwise, throw an error.
4245 Assume LINK type is \"fuzzy\". White spaces are not
4247 (let* ((search-cells (org-export-string-to-search-cell
4248 (org-link-unescape (org-element-property :path link
))))
4250 (or (plist-get info
:resolve-fuzzy-link-cache
)
4251 (plist-get (plist-put info
4252 :resolve-fuzzy-link-cache
4253 (make-hash-table :test
#'equal
))
4254 :resolve-fuzzy-link-cache
)))
4255 (cached (gethash search-cells link-cache
'not-found
)))
4256 (if (not (eq cached
'not-found
)) cached
4258 (org-element-map (plist-get info
:parse-tree
)
4259 (cons 'target org-element-all-elements
)
4261 (and (org-export-match-search-cell-p datum search-cells
)
4264 (signal 'org-link-broken
(list (org-element-property :path link
))))
4267 ;; There can be multiple matches for un-typed searches, i.e.,
4268 ;; for searches not starting with # or *. In this case,
4269 ;; prioritize targets and names over headline titles.
4270 ;; Matching both a name and a target is not valid, and
4271 ;; therefore undefined.
4272 (or (cl-some (lambda (datum)
4273 (and (not (eq (org-element-type datum
) 'headline
))
4279 (defun org-export-resolve-id-link (link info
)
4280 "Return headline referenced as LINK destination.
4282 INFO is a plist used as a communication channel.
4284 Return value can be the headline element matched in current parse
4285 tree or a file name. Assume LINK type is either \"id\" or
4286 \"custom-id\". Throw an error if no match is found."
4287 (let ((id (org-element-property :path link
)))
4288 ;; First check if id is within the current parse tree.
4289 (or (org-element-map (plist-get info
:parse-tree
) 'headline
4291 (when (or (equal (org-element-property :ID headline
) id
)
4292 (equal (org-element-property :CUSTOM_ID headline
) id
))
4295 ;; Otherwise, look for external files.
4296 (cdr (assoc id
(plist-get info
:id-alist
)))
4297 (signal 'org-link-broken
(list id
)))))
4299 (defun org-export-resolve-radio-link (link info
)
4300 "Return radio-target object referenced as LINK destination.
4302 INFO is a plist used as a communication channel.
4304 Return value can be a radio-target object or nil. Assume LINK
4305 has type \"radio\"."
4306 (let ((path (replace-regexp-in-string
4307 "[ \r\t\n]+" " " (org-element-property :path link
))))
4308 (org-element-map (plist-get info
:parse-tree
) 'radio-target
4310 (and (eq (compare-strings
4311 (replace-regexp-in-string
4312 "[ \r\t\n]+" " " (org-element-property :value radio
))
4313 nil nil path nil nil t
)
4316 info
'first-match
)))
4318 (defun org-export-file-uri (filename)
4319 "Return file URI associated to FILENAME."
4320 (cond ((string-prefix-p "//" filename
) (concat "file:" filename
))
4321 ((not (file-name-absolute-p filename
)) filename
)
4322 ((org-file-remote-p filename
) (concat "file:/" filename
))
4324 (let ((fullname (expand-file-name filename
)))
4325 (concat (if (string-prefix-p "/" fullname
) "file://" "file:///")
4330 ;; `org-export-get-reference' associate a unique reference for any
4331 ;; object or element. It uses `org-export-new-reference' and
4332 ;; `org-export-format-reference' to, respectively, generate new
4333 ;; internal references and turn them into a string suitable for
4336 ;; `org-export-get-ordinal' associates a sequence number to any object
4339 (defun org-export-new-reference (references)
4340 "Return a unique reference, among REFERENCES.
4341 REFERENCES is an alist whose values are in-use references, as
4342 numbers. Returns a number, which is the internal representation
4343 of a reference. See also `org-export-format-reference'."
4344 ;; Generate random 7 digits hexadecimal numbers. Collisions
4345 ;; increase exponentially with the numbers of references. However,
4346 ;; the odds for encountering at least one collision with 1000 active
4347 ;; references in the same document are roughly 0.2%, so this
4348 ;; shouldn't be the bottleneck.
4349 (let ((new (random #x10000000
)))
4350 (while (rassq new references
) (setq new
(random #x10000000
)))
4353 (defun org-export-format-reference (reference)
4354 "Format REFERENCE into a string.
4355 REFERENCE is a number representing a reference, as returned by
4356 `org-export-new-reference', which see."
4357 (format "org%07x" reference
))
4359 (defun org-export-get-reference (datum info
)
4360 "Return a unique reference for DATUM, as a string.
4362 DATUM is either an element or an object. INFO is the current
4363 export state, as a plist.
4365 This function checks `:crossrefs' property in INFO for search
4366 cells matching DATUM before creating a new reference. Returned
4367 reference consists of alphanumeric characters only."
4368 (let ((cache (plist-get info
:internal-references
)))
4369 (or (car (rassq datum cache
))
4370 (let* ((crossrefs (plist-get info
:crossrefs
))
4371 (cells (org-export-search-cells datum
))
4372 ;; Preserve any pre-existing association between
4373 ;; a search cell and a reference, i.e., when some
4374 ;; previously published document referenced a location
4375 ;; within current file (see
4376 ;; `org-publish-resolve-external-link').
4378 ;; However, there is no guarantee that search cells are
4379 ;; unique, e.g., there might be duplicate custom ID or
4380 ;; two headings with the same title in the file.
4382 ;; As a consequence, before re-using any reference to
4383 ;; an element or object, we check that it doesn't refer
4384 ;; to a previous element or object.
4387 (let ((stored (cdr (assoc cell crossrefs
))))
4389 (let ((old (org-export-format-reference stored
)))
4390 (and (not (assoc old cache
)) stored
)))))
4392 (org-export-new-reference cache
)))
4393 (reference-string (org-export-format-reference new
)))
4394 ;; Cache contains both data already associated to
4395 ;; a reference and in-use internal references, so as to make
4396 ;; unique references.
4397 (dolist (cell cells
) (push (cons cell new
) cache
))
4398 ;; Retain a direct association between reference string and
4399 ;; DATUM since (1) not every object or element can be given
4400 ;; a search cell (2) it permits quick lookup.
4401 (push (cons reference-string datum
) cache
)
4402 (plist-put info
:internal-references cache
)
4403 reference-string
))))
4405 (defun org-export-get-ordinal (element info
&optional types predicate
)
4406 "Return ordinal number of an element or object.
4408 ELEMENT is the element or object considered. INFO is the plist
4409 used as a communication channel.
4411 Optional argument TYPES, when non-nil, is a list of element or
4412 object types, as symbols, that should also be counted in.
4413 Otherwise, only provided element's type is considered.
4415 Optional argument PREDICATE is a function returning a non-nil
4416 value if the current element or object should be counted in. It
4417 accepts two arguments: the element or object being considered and
4418 the plist used as a communication channel. This allows counting
4419 only a certain type of object (i.e. inline images).
4421 Return value is a list of numbers if ELEMENT is a headline or an
4422 item. It is nil for keywords. It represents the footnote number
4423 for footnote definitions and footnote references. If ELEMENT is
4424 a target, return the same value as if ELEMENT was the closest
4425 table, item or headline containing the target. In any other
4426 case, return the sequence number of ELEMENT among elements or
4427 objects of the same type."
4428 ;; Ordinal of a target object refer to the ordinal of the closest
4429 ;; table, item, or headline containing the object.
4430 (when (eq (org-element-type element
) 'target
)
4432 (org-element-lineage
4434 '(footnote-definition footnote-reference headline item table
))))
4435 (cl-case (org-element-type element
)
4436 ;; Special case 1: A headline returns its number as a list.
4437 (headline (org-export-get-headline-number element info
))
4438 ;; Special case 2: An item returns its number as a list.
4439 (item (let ((struct (org-element-property :structure element
)))
4440 (org-list-get-item-number
4441 (org-element-property :begin element
)
4443 (org-list-prevs-alist struct
)
4444 (org-list-parents-alist struct
))))
4445 ((footnote-definition footnote-reference
)
4446 (org-export-get-footnote-number element info
))
4449 ;; Increment counter until ELEMENT is found again.
4450 (org-element-map (plist-get info
:parse-tree
)
4451 (or types
(org-element-type element
))
4454 ((eq element el
) (1+ counter
))
4455 ((not predicate
) (cl-incf counter
) nil
)
4456 ((funcall predicate el info
) (cl-incf counter
) nil
)))
4457 info
'first-match
)))))
4462 ;; `org-export-get-loc' counts number of code lines accumulated in
4463 ;; src-block or example-block elements with a "+n" switch until
4464 ;; a given element, excluded. Note: "-n" switches reset that count.
4466 ;; `org-export-unravel-code' extracts source code (along with a code
4467 ;; references alist) from an `element-block' or `src-block' type
4470 ;; `org-export-format-code' applies a formatting function to each line
4471 ;; of code, providing relative line number and code reference when
4472 ;; appropriate. Since it doesn't access the original element from
4473 ;; which the source code is coming, it expects from the code calling
4474 ;; it to know if lines should be numbered and if code references
4477 ;; Eventually, `org-export-format-code-default' is a higher-level
4478 ;; function (it makes use of the two previous functions) which handles
4479 ;; line numbering and code references inclusion, and returns source
4480 ;; code in a format suitable for plain text or verbatim output.
4482 (defun org-export-get-loc (element info
)
4483 "Return count of lines of code before ELEMENT.
4485 ELEMENT is an example-block or src-block element. INFO is the
4486 plist used as a communication channel.
4488 Count includes every line of code in example-block or src-block
4489 with a \"+n\" or \"-n\" switch before block. Return nil if
4490 ELEMENT doesn't allow line numbering."
4491 (pcase (org-element-property :number-lines element
)
4495 (org-element-map (plist-get info
:parse-tree
) '(src-block example-block
)
4497 ;; ELEMENT is reached: Quit loop and return locs.
4498 (if (eq el element
) (+ loc n
)
4499 ;; Only count lines from src-block and example-block
4500 ;; elements with a "+n" or "-n" switch.
4501 (let ((linum (org-element-property :number-lines el
)))
4503 (let ((lines (org-count-lines
4504 (org-element-property :value el
))))
4505 ;; Accumulate locs or reset them.
4507 (`(new .
,n
) (setq loc
(+ n lines
)))
4508 (`(continued .
,n
) (cl-incf loc
(+ n lines
)))))))
4509 nil
)) ;Return nil to stay in the loop.
4510 info
'first-match
)))))
4512 (defun org-export-unravel-code (element)
4513 "Clean source code and extract references out of it.
4515 ELEMENT has either a `src-block' an `example-block' type.
4517 Return a cons cell whose CAR is the source code, cleaned from any
4518 reference, protective commas and spurious indentation, and CDR is
4519 an alist between relative line number (integer) and name of code
4520 reference on that line (string)."
4521 (let* ((line 0) refs
4522 (value (org-element-property :value element
))
4523 ;; Remove global indentation from code, if necessary. Also
4524 ;; remove final newline character, since it doesn't belongs
4525 ;; to the code proper.
4526 (code (replace-regexp-in-string
4528 (if (or org-src-preserve-indentation
4529 (org-element-property :preserve-indent element
))
4531 (org-remove-indentation value
))))
4532 ;; Build a regexp matching a loc with a reference.
4533 (ref-re (org-src-coderef-regexp (org-src-coderef-format element
))))
4536 ;; Code with references removed.
4540 (if (not (string-match ref-re loc
)) loc
4541 ;; Ref line: remove ref, and add its position in REFS.
4542 (push (cons line
(match-string 3 loc
)) refs
)
4543 (replace-match "" nil nil loc
1)))
4544 (split-string code
"\n") "\n")
4548 (defun org-export-format-code (code fun
&optional num-lines ref-alist
)
4549 "Format CODE by applying FUN line-wise and return it.
4551 CODE is a string representing the code to format. FUN is
4552 a function. It must accept three arguments: a line of
4553 code (string), the current line number (integer) or nil and the
4554 reference associated to the current line (string) or nil.
4556 Optional argument NUM-LINES can be an integer representing the
4557 number of code lines accumulated until the current code. Line
4558 numbers passed to FUN will take it into account. If it is nil,
4559 FUN's second argument will always be nil. This number can be
4560 obtained with `org-export-get-loc' function.
4562 Optional argument REF-ALIST can be an alist between relative line
4563 number (i.e. ignoring NUM-LINES) and the name of the code
4564 reference on it. If it is nil, FUN's third argument will always
4565 be nil. It can be obtained through the use of
4566 `org-export-unravel-code' function."
4567 (let ((--locs (split-string code
"\n"))
4573 (let ((--ref (cdr (assq --line ref-alist
))))
4574 (funcall fun --loc
(and num-lines
(+ num-lines --line
)) --ref
)))
4578 (defun org-export-format-code-default (element info
)
4579 "Return source code from ELEMENT, formatted in a standard way.
4581 ELEMENT is either a `src-block' or `example-block' element. INFO
4582 is a plist used as a communication channel.
4584 This function takes care of line numbering and code references
4585 inclusion. Line numbers, when applicable, appear at the
4586 beginning of the line, separated from the code by two white
4587 spaces. Code references, on the other hand, appear flushed to
4588 the right, separated by six white spaces from the widest line of
4590 ;; Extract code and references.
4591 (let* ((code-info (org-export-unravel-code element
))
4592 (code (car code-info
))
4593 (code-lines (split-string code
"\n")))
4594 (if (null code-lines
) ""
4595 (let* ((refs (and (org-element-property :retain-labels element
)
4597 ;; Handle line numbering.
4598 (num-start (org-export-get-loc element info
))
4602 (length (number-to-string
4603 (+ (length code-lines
) num-start
))))))
4604 ;; Prepare references display, if required. Any reference
4605 ;; should start six columns after the widest line of code,
4606 ;; wrapped with parenthesis.
4608 (+ (apply 'max
(mapcar 'length code-lines
))
4609 (if (not num-start
) 0 (length (format num-fmt num-start
))))))
4610 (org-export-format-code
4612 (lambda (loc line-num ref
)
4613 (let ((number-str (and num-fmt
(format num-fmt line-num
))))
4618 (concat (make-string (- (+ 6 max-width
)
4619 (+ (length loc
) (length number-str
)))
4621 (format "(%s)" ref
))))))
4627 ;; `org-export-table-has-special-column-p' and and
4628 ;; `org-export-table-row-is-special-p' are predicates used to look for
4629 ;; meta-information about the table structure.
4631 ;; `org-table-has-header-p' tells when the rows before the first rule
4632 ;; should be considered as table's header.
4634 ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
4635 ;; and `org-export-table-cell-borders' extract information from
4636 ;; a table-cell element.
4638 ;; `org-export-table-dimensions' gives the number on rows and columns
4639 ;; in the table, ignoring horizontal rules and special columns.
4640 ;; `org-export-table-cell-address', given a table-cell object, returns
4641 ;; the absolute address of a cell. On the other hand,
4642 ;; `org-export-get-table-cell-at' does the contrary.
4644 ;; `org-export-table-cell-starts-colgroup-p',
4645 ;; `org-export-table-cell-ends-colgroup-p',
4646 ;; `org-export-table-row-starts-rowgroup-p',
4647 ;; `org-export-table-row-ends-rowgroup-p',
4648 ;; `org-export-table-row-starts-header-p',
4649 ;; `org-export-table-row-ends-header-p' and
4650 ;; `org-export-table-row-in-header-p' indicate position of current row
4651 ;; or cell within the table.
4653 (defun org-export-table-has-special-column-p (table)
4654 "Non-nil when TABLE has a special column.
4655 All special columns will be ignored during export."
4656 ;; The table has a special column when every first cell of every row
4657 ;; has an empty value or contains a symbol among "/", "#", "!", "$",
4658 ;; "*" "_" and "^". Though, do not consider a first row containing
4659 ;; only empty cells as special.
4660 (let ((special-column-p 'empty
))
4662 (dolist (row (org-element-contents table
))
4663 (when (eq (org-element-property :type row
) 'standard
)
4664 (let ((value (org-element-contents
4665 (car (org-element-contents row
)))))
4666 (cond ((member value
'(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
4667 (setq special-column-p
'special
))
4669 (t (throw 'exit nil
))))))
4670 (eq special-column-p
'special
))))
4672 (defun org-export-table-has-header-p (table info
)
4673 "Non-nil when TABLE has a header.
4675 INFO is a plist used as a communication channel.
4677 A table has a header when it contains at least two row groups."
4678 (let ((cache (or (plist-get info
:table-header-cache
)
4679 (plist-get (setq info
4680 (plist-put info
:table-header-cache
4681 (make-hash-table :test
'eq
)))
4682 :table-header-cache
))))
4683 (or (gethash table cache
)
4684 (let ((rowgroup 1) row-flag
)
4687 (org-element-map table
'table-row
4691 ((and row-flag
(eq (org-element-property :type row
) 'rule
))
4692 (cl-incf rowgroup
) (setq row-flag nil
))
4693 ((and (not row-flag
) (eq (org-element-property :type row
)
4695 (setq row-flag t
) nil
)))
4699 (defun org-export-table-row-is-special-p (table-row _
)
4700 "Non-nil if TABLE-ROW is considered special.
4701 All special rows will be ignored during export."
4702 (when (eq (org-element-property :type table-row
) 'standard
)
4703 (let ((first-cell (org-element-contents
4704 (car (org-element-contents table-row
)))))
4705 ;; A row is special either when...
4707 ;; ... it starts with a field only containing "/",
4708 (equal first-cell
'("/"))
4709 ;; ... the table contains a special column and the row start
4710 ;; with a marking character among, "^", "_", "$" or "!",
4711 (and (org-export-table-has-special-column-p
4712 (org-export-get-parent table-row
))
4713 (member first-cell
'(("^") ("_") ("$") ("!"))))
4714 ;; ... it contains only alignment cookies and empty cells.
4715 (let ((special-row-p 'empty
))
4717 (dolist (cell (org-element-contents table-row
))
4718 (let ((value (org-element-contents cell
)))
4719 ;; Since VALUE is a secondary string, the following
4720 ;; checks avoid expanding it with `org-export-data'.
4722 ((and (not (cdr value
))
4723 (stringp (car value
))
4724 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
4726 (setq special-row-p
'cookie
))
4727 (t (throw 'exit nil
)))))
4728 (eq special-row-p
'cookie
)))))))
4730 (defun org-export-table-row-group (table-row info
)
4731 "Return TABLE-ROW's group number, as an integer.
4733 INFO is a plist used as the communication channel.
4735 Return value is the group number, as an integer, or nil for
4736 special rows and rows separators. First group is also table's
4738 (let ((cache (or (plist-get info
:table-row-group-cache
)
4739 (plist-get (setq info
4740 (plist-put info
:table-row-group-cache
4741 (make-hash-table :test
'eq
)))
4742 :table-row-group-cache
))))
4743 (cond ((gethash table-row cache
))
4744 ((eq (org-element-property :type table-row
) 'rule
) nil
)
4745 (t (let ((group 0) row-flag
)
4746 (org-element-map (org-export-get-parent table-row
) 'table-row
4748 (if (eq (org-element-property :type row
) 'rule
)
4750 (unless row-flag
(cl-incf group
) (setq row-flag t
)))
4751 (when (eq table-row row
) (puthash table-row group cache
)))
4752 info
'first-match
))))))
4754 (defun org-export-table-cell-width (table-cell info
)
4755 "Return TABLE-CELL contents width.
4757 INFO is a plist used as the communication channel.
4759 Return value is the width given by the last width cookie in the
4760 same column as TABLE-CELL, or nil."
4761 (let* ((row (org-export-get-parent table-cell
))
4762 (table (org-export-get-parent row
))
4763 (cells (org-element-contents row
))
4764 (columns (length cells
))
4765 (column (- columns
(length (memq table-cell cells
))))
4766 (cache (or (plist-get info
:table-cell-width-cache
)
4767 (plist-get (setq info
4768 (plist-put info
:table-cell-width-cache
4769 (make-hash-table :test
'eq
)))
4770 :table-cell-width-cache
)))
4771 (width-vector (or (gethash table cache
)
4772 (puthash table
(make-vector columns
'empty
) cache
)))
4773 (value (aref width-vector column
)))
4774 (if (not (eq value
'empty
)) value
4776 (dolist (row (org-element-contents table
)
4777 (aset width-vector column cookie-width
))
4778 (when (org-export-table-row-is-special-p row info
)
4779 ;; In a special row, try to find a width cookie at COLUMN.
4780 (let* ((value (org-element-contents
4781 (elt (org-element-contents row
) column
)))
4782 (cookie (car value
)))
4783 ;; The following checks avoid expanding unnecessarily
4784 ;; the cell with `org-export-data'.
4788 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" cookie
)
4789 (match-string 1 cookie
))
4791 (string-to-number (match-string 1 cookie
)))))))))))
4793 (defun org-export-table-cell-alignment (table-cell info
)
4794 "Return TABLE-CELL contents alignment.
4796 INFO is a plist used as the communication channel.
4798 Return alignment as specified by the last alignment cookie in the
4799 same column as TABLE-CELL. If no such cookie is found, a default
4800 alignment value will be deduced from fraction of numbers in the
4801 column (see `org-table-number-fraction' for more information).
4802 Possible values are `left', `right' and `center'."
4803 ;; Load `org-table-number-fraction' and `org-table-number-regexp'.
4804 (require 'org-table
)
4805 (let* ((row (org-export-get-parent table-cell
))
4806 (table (org-export-get-parent row
))
4807 (cells (org-element-contents row
))
4808 (columns (length cells
))
4809 (column (- columns
(length (memq table-cell cells
))))
4810 (cache (or (plist-get info
:table-cell-alignment-cache
)
4811 (plist-get (setq info
4812 (plist-put info
:table-cell-alignment-cache
4813 (make-hash-table :test
'eq
)))
4814 :table-cell-alignment-cache
)))
4815 (align-vector (or (gethash table cache
)
4816 (puthash table
(make-vector columns nil
) cache
))))
4817 (or (aref align-vector column
)
4818 (let ((number-cells 0)
4821 previous-cell-number-p
)
4822 (dolist (row (org-element-contents (org-export-get-parent row
)))
4824 ;; In a special row, try to find an alignment cookie at
4826 ((org-export-table-row-is-special-p row info
)
4827 (let ((value (org-element-contents
4828 (elt (org-element-contents row
) column
))))
4829 ;; Since VALUE is a secondary string, the following
4830 ;; checks avoid useless expansion through
4831 ;; `org-export-data'.
4834 (stringp (car value
))
4835 (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
4837 (match-string 1 (car value
)))
4838 (setq cookie-align
(match-string 1 (car value
))))))
4839 ;; Ignore table rules.
4840 ((eq (org-element-property :type row
) 'rule
))
4841 ;; In a standard row, check if cell's contents are
4842 ;; expressing some kind of number. Increase NUMBER-CELLS
4843 ;; accordingly. Though, don't bother if an alignment
4844 ;; cookie has already defined cell's alignment.
4846 (let ((value (org-export-data
4847 (org-element-contents
4848 (elt (org-element-contents row
) column
))
4850 (cl-incf total-cells
)
4851 ;; Treat an empty cell as a number if it follows
4853 (if (not (or (string-match org-table-number-regexp value
)
4854 (and (string= value
"") previous-cell-number-p
)))
4855 (setq previous-cell-number-p nil
)
4856 (setq previous-cell-number-p t
)
4857 (cl-incf number-cells
))))))
4858 ;; Return value. Alignment specified by cookies has
4859 ;; precedence over alignment deduced from cell's contents.
4862 (cond ((equal cookie-align
"l") 'left
)
4863 ((equal cookie-align
"r") 'right
)
4864 ((equal cookie-align
"c") 'center
)
4865 ((>= (/ (float number-cells
) total-cells
)
4866 org-table-number-fraction
)
4870 (defun org-export-table-cell-borders (table-cell info
)
4871 "Return TABLE-CELL borders.
4873 INFO is a plist used as a communication channel.
4875 Return value is a list of symbols, or nil. Possible values are:
4876 `top', `bottom', `above', `below', `left' and `right'. Note:
4877 `top' (resp. `bottom') only happen for a cell in the first
4878 row (resp. last row) of the table, ignoring table rules, if any.
4880 Returned borders ignore special rows."
4881 (let* ((row (org-export-get-parent table-cell
))
4882 (table (org-export-get-parent-table table-cell
))
4884 ;; Top/above border? TABLE-CELL has a border above when a rule
4885 ;; used to demarcate row groups can be found above. Hence,
4886 ;; finding a rule isn't sufficient to push `above' in BORDERS:
4887 ;; another regular row has to be found above that rule.
4890 ;; Look at every row before the current one.
4891 (dolist (row (cdr (memq row
(reverse (org-element-contents table
)))))
4892 (cond ((eq (org-element-property :type row
) 'rule
)
4894 ((not (org-export-table-row-is-special-p row info
))
4895 (if rule-flag
(throw 'exit
(push 'above borders
))
4896 (throw 'exit nil
)))))
4897 ;; No rule above, or rule found starts the table (ignoring any
4898 ;; special row): TABLE-CELL is at the top of the table.
4899 (when rule-flag
(push 'above borders
))
4900 (push 'top borders
)))
4901 ;; Bottom/below border? TABLE-CELL has a border below when next
4902 ;; non-regular row below is a rule.
4905 ;; Look at every row after the current one.
4906 (dolist (row (cdr (memq row
(org-element-contents table
))))
4907 (cond ((eq (org-element-property :type row
) 'rule
)
4909 ((not (org-export-table-row-is-special-p row info
))
4910 (if rule-flag
(throw 'exit
(push 'below borders
))
4911 (throw 'exit nil
)))))
4912 ;; No rule below, or rule found ends the table (modulo some
4913 ;; special row): TABLE-CELL is at the bottom of the table.
4914 (when rule-flag
(push 'below borders
))
4915 (push 'bottom borders
)))
4916 ;; Right/left borders? They can only be specified by column
4917 ;; groups. Column groups are defined in a row starting with "/".
4918 ;; Also a column groups row only contains "<", "<>", ">" or blank
4921 (let ((column (let ((cells (org-element-contents row
)))
4922 (- (length cells
) (length (memq table-cell cells
))))))
4923 ;; Table rows are read in reverse order so last column groups
4924 ;; row has precedence over any previous one.
4925 (dolist (row (reverse (org-element-contents table
)))
4926 (unless (eq (org-element-property :type row
) 'rule
)
4927 (when (equal (org-element-contents
4928 (car (org-element-contents row
)))
4930 (let ((column-groups
4933 (let ((value (org-element-contents cell
)))
4934 (when (member value
'(("<") ("<>") (">") nil
))
4936 (org-element-contents row
))))
4937 ;; There's a left border when previous cell, if
4938 ;; any, ends a group, or current one starts one.
4939 (when (or (and (not (zerop column
))
4940 (member (elt column-groups
(1- column
))
4942 (member (elt column-groups column
) '("<" "<>")))
4943 (push 'left borders
))
4944 ;; There's a right border when next cell, if any,
4945 ;; starts a group, or current one ends one.
4946 (when (or (and (/= (1+ column
) (length column-groups
))
4947 (member (elt column-groups
(1+ column
))
4949 (member (elt column-groups column
) '(">" "<>")))
4950 (push 'right borders
))
4951 (throw 'exit nil
)))))))
4955 (defun org-export-table-cell-starts-colgroup-p (table-cell info
)
4956 "Non-nil when TABLE-CELL is at the beginning of a column group.
4957 INFO is a plist used as a communication channel."
4958 ;; A cell starts a column group either when it is at the beginning
4959 ;; of a row (or after the special column, if any) or when it has
4961 (or (eq (org-element-map (org-export-get-parent table-cell
) 'table-cell
4962 'identity info
'first-match
)
4964 (memq 'left
(org-export-table-cell-borders table-cell info
))))
4966 (defun org-export-table-cell-ends-colgroup-p (table-cell info
)
4967 "Non-nil when TABLE-CELL is at the end of a column group.
4968 INFO is a plist used as a communication channel."
4969 ;; A cell ends a column group either when it is at the end of a row
4970 ;; or when it has a right border.
4971 (or (eq (car (last (org-element-contents
4972 (org-export-get-parent table-cell
))))
4974 (memq 'right
(org-export-table-cell-borders table-cell info
))))
4976 (defun org-export-table-row-starts-rowgroup-p (table-row info
)
4977 "Non-nil when TABLE-ROW is at the beginning of a row group.
4978 INFO is a plist used as a communication channel."
4979 (unless (or (eq (org-element-property :type table-row
) 'rule
)
4980 (org-export-table-row-is-special-p table-row info
))
4981 (let ((borders (org-export-table-cell-borders
4982 (car (org-element-contents table-row
)) info
)))
4983 (or (memq 'top borders
) (memq 'above borders
)))))
4985 (defun org-export-table-row-ends-rowgroup-p (table-row info
)
4986 "Non-nil when TABLE-ROW is at the end of a row group.
4987 INFO is a plist used as a communication channel."
4988 (unless (or (eq (org-element-property :type table-row
) 'rule
)
4989 (org-export-table-row-is-special-p table-row info
))
4990 (let ((borders (org-export-table-cell-borders
4991 (car (org-element-contents table-row
)) info
)))
4992 (or (memq 'bottom borders
) (memq 'below borders
)))))
4994 (defun org-export-table-row-in-header-p (table-row info
)
4995 "Non-nil when TABLE-ROW is located within table's header.
4996 INFO is a plist used as a communication channel. Always return
4997 nil for special rows and rows separators."
4998 (and (org-export-table-has-header-p
4999 (org-export-get-parent-table table-row
) info
)
5000 (eql (org-export-table-row-group table-row info
) 1)))
5002 (defun org-export-table-row-starts-header-p (table-row info
)
5003 "Non-nil when TABLE-ROW is the first table header's row.
5004 INFO is a plist used as a communication channel."
5005 (and (org-export-table-row-in-header-p table-row info
)
5006 (org-export-table-row-starts-rowgroup-p table-row info
)))
5008 (defun org-export-table-row-ends-header-p (table-row info
)
5009 "Non-nil when TABLE-ROW is the last table header's row.
5010 INFO is a plist used as a communication channel."
5011 (and (org-export-table-row-in-header-p table-row info
)
5012 (org-export-table-row-ends-rowgroup-p table-row info
)))
5014 (defun org-export-table-row-number (table-row info
)
5015 "Return TABLE-ROW number.
5016 INFO is a plist used as a communication channel. Return value is
5017 zero-based and ignores separators. The function returns nil for
5018 special columns and separators."
5019 (when (and (eq (org-element-property :type table-row
) 'standard
)
5020 (not (org-export-table-row-is-special-p table-row info
)))
5022 (org-element-map (org-export-get-parent-table table-row
) 'table-row
5024 (cond ((eq row table-row
) number
)
5025 ((eq (org-element-property :type row
) 'standard
)
5026 (cl-incf number
) nil
)))
5027 info
'first-match
))))
5029 (defun org-export-table-dimensions (table info
)
5030 "Return TABLE dimensions.
5032 INFO is a plist used as a communication channel.
5034 Return value is a CONS like (ROWS . COLUMNS) where
5035 ROWS (resp. COLUMNS) is the number of exportable
5036 rows (resp. columns)."
5037 (let (first-row (columns 0) (rows 0))
5038 ;; Set number of rows, and extract first one.
5039 (org-element-map table
'table-row
5041 (when (eq (org-element-property :type row
) 'standard
)
5043 (unless first-row
(setq first-row row
)))) info
)
5044 ;; Set number of columns.
5045 (org-element-map first-row
'table-cell
(lambda (_) (cl-incf columns
)) info
)
5047 (cons rows columns
)))
5049 (defun org-export-table-cell-address (table-cell info
)
5050 "Return address of a regular TABLE-CELL object.
5052 TABLE-CELL is the cell considered. INFO is a plist used as
5053 a communication channel.
5055 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
5056 zero-based index. Only exportable cells are considered. The
5057 function returns nil for other cells."
5058 (let* ((table-row (org-export-get-parent table-cell
))
5059 (row-number (org-export-table-row-number table-row info
)))
5062 (let ((col-count 0))
5063 (org-element-map table-row
'table-cell
5065 (if (eq cell table-cell
) col-count
(cl-incf col-count
) nil
))
5066 info
'first-match
))))))
5068 (defun org-export-get-table-cell-at (address table info
)
5069 "Return regular table-cell object at ADDRESS in TABLE.
5071 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
5072 zero-based index. TABLE is a table type element. INFO is
5073 a plist used as a communication channel.
5075 If no table-cell, among exportable cells, is found at ADDRESS,
5077 (let ((column-pos (cdr address
)) (column-count 0))
5079 ;; Row at (car address) or nil.
5080 (let ((row-pos (car address
)) (row-count 0))
5081 (org-element-map table
'table-row
5083 (cond ((eq (org-element-property :type row
) 'rule
) nil
)
5084 ((= row-count row-pos
) row
)
5085 (t (cl-incf row-count
) nil
)))
5089 (if (= column-count column-pos
) cell
5090 (cl-incf column-count
) nil
))
5091 info
'first-match
)))
5094 ;;;; For Tables Of Contents
5096 ;; `org-export-collect-headlines' builds a list of all exportable
5097 ;; headline elements, maybe limited to a certain depth. One can then
5098 ;; easily parse it and transcode it.
5100 ;; Building lists of tables, figures or listings is quite similar.
5101 ;; Once the generic function `org-export-collect-elements' is defined,
5102 ;; `org-export-collect-tables', `org-export-collect-figures' and
5103 ;; `org-export-collect-listings' can be derived from it.
5105 (defun org-export-collect-headlines (info &optional n scope
)
5106 "Collect headlines in order to build a table of contents.
5108 INFO is a plist used as a communication channel.
5110 When optional argument N is an integer, it specifies the depth of
5111 the table of contents. Otherwise, it is set to the value of the
5112 last headline level. See `org-export-headline-levels' for more
5115 Optional argument SCOPE, when non-nil, is an element. If it is
5116 a headline, only children of SCOPE are collected. Otherwise,
5117 collect children of the headline containing provided element. If
5118 there is no such headline, collect all headlines. In any case,
5119 argument N becomes relative to the level of that headline.
5121 Return a list of all exportable headlines as parsed elements.
5122 Footnote sections are ignored."
5123 (let* ((scope (cond ((not scope
) (plist-get info
:parse-tree
))
5124 ((eq (org-element-type scope
) 'headline
) scope
)
5125 ((org-export-get-parent-headline scope
))
5126 (t (plist-get info
:parse-tree
))))
5127 (limit (plist-get info
:headline-levels
))
5128 (n (if (not (wholenump n
)) limit
5129 (min (if (eq (org-element-type scope
) 'org-data
) n
5130 (+ (org-export-get-relative-level scope info
) n
))
5132 (org-element-map (org-element-contents scope
) 'headline
5134 (unless (org-element-property :footnote-section-p headline
)
5135 (let ((level (org-export-get-relative-level headline info
)))
5136 (and (<= level n
) headline
))))
5139 (defun org-export-collect-elements (type info
&optional predicate
)
5140 "Collect referenceable elements of a determined type.
5142 TYPE can be a symbol or a list of symbols specifying element
5143 types to search. Only elements with a caption are collected.
5145 INFO is a plist used as a communication channel.
5147 When non-nil, optional argument PREDICATE is a function accepting
5148 one argument, an element of type TYPE. It returns a non-nil
5149 value when that element should be collected.
5151 Return a list of all elements found, in order of appearance."
5152 (org-element-map (plist-get info
:parse-tree
) type
5154 (and (org-element-property :caption element
)
5155 (or (not predicate
) (funcall predicate element
))
5159 (defun org-export-collect-tables (info)
5160 "Build a list of tables.
5161 INFO is a plist used as a communication channel.
5163 Return a list of table elements with a caption."
5164 (org-export-collect-elements 'table info
))
5166 (defun org-export-collect-figures (info predicate
)
5167 "Build a list of figures.
5169 INFO is a plist used as a communication channel. PREDICATE is
5170 a function which accepts one argument: a paragraph element and
5171 whose return value is non-nil when that element should be
5174 A figure is a paragraph type element, with a caption, verifying
5175 PREDICATE. The latter has to be provided since a \"figure\" is
5176 a vague concept that may depend on back-end.
5178 Return a list of elements recognized as figures."
5179 (org-export-collect-elements 'paragraph info predicate
))
5181 (defun org-export-collect-listings (info)
5182 "Build a list of src blocks.
5184 INFO is a plist used as a communication channel.
5186 Return a list of src-block elements with a caption."
5187 (org-export-collect-elements 'src-block info
))
5192 ;; The main function for the smart quotes sub-system is
5193 ;; `org-export-activate-smart-quotes', which replaces every quote in
5194 ;; a given string from the parse tree with its "smart" counterpart.
5196 ;; Dictionary for smart quotes is stored in
5197 ;; `org-export-smart-quotes-alist'.
5199 (defconst org-export-smart-quotes-alist
5201 ;; one may use: »...«, "...", ›...‹, or '...'.
5202 ;; http://sproget.dk/raad-og-regler/retskrivningsregler/retskrivningsregler/a7-40-60/a7-58-anforselstegn/
5203 ;; LaTeX quotes require Babel!
5205 :utf-8
"»" :html
"»" :latex
">>" :texinfo
"@guillemetright{}")
5207 :utf-8
"«" :html
"«" :latex
"<<" :texinfo
"@guillemetleft{}")
5209 :utf-8
"›" :html
"›" :latex
"\\frq{}" :texinfo
"@guilsinglright{}")
5211 :utf-8
"‹" :html
"‹" :latex
"\\flq{}" :texinfo
"@guilsingleft{}")
5212 (apostrophe :utf-8
"’" :html
"’"))
5215 :utf-8
"„" :html
"„" :latex
"\"`" :texinfo
"@quotedblbase{}")
5217 :utf-8
"“" :html
"“" :latex
"\"'" :texinfo
"@quotedblleft{}")
5219 :utf-8
"‚" :html
"‚" :latex
"\\glq{}" :texinfo
"@quotesinglbase{}")
5221 :utf-8
"‘" :html
"‘" :latex
"\\grq{}" :texinfo
"@quoteleft{}")
5222 (apostrophe :utf-8
"’" :html
"’"))
5224 (primary-opening :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
5225 (primary-closing :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
5226 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5227 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5228 (apostrophe :utf-8
"’" :html
"’"))
5231 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5232 :texinfo
"@guillemetleft{}")
5234 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5235 :texinfo
"@guillemetright{}")
5236 (secondary-opening :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
5237 (secondary-closing :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
5238 (apostrophe :utf-8
"’" :html
"’"))
5241 :utf-8
"« " :html
"« " :latex
"\\og "
5242 :texinfo
"@guillemetleft{}@tie{}")
5244 :utf-8
" »" :html
" »" :latex
"\\fg{}"
5245 :texinfo
"@tie{}@guillemetright{}")
5247 :utf-8
"« " :html
"« " :latex
"\\og "
5248 :texinfo
"@guillemetleft{}@tie{}")
5249 (secondary-closing :utf-8
" »" :html
" »" :latex
"\\fg{}"
5250 :texinfo
"@tie{}@guillemetright{}")
5251 (apostrophe :utf-8
"’" :html
"’"))
5254 :utf-8
"„" :html
"„" :latex
"\"`" :texinfo
"@quotedblbase{}")
5256 :utf-8
"“" :html
"“" :latex
"\"'" :texinfo
"@quotedblleft{}")
5258 :utf-8
"‚" :html
"‚" :latex
"\\glq{}" :texinfo
"@quotesinglbase{}")
5260 :utf-8
"‘" :html
"‘" :latex
"\\grq{}" :texinfo
"@quoteleft{}")
5261 (apostrophe :utf-8
"’" :html
"’"))
5263 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5265 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5266 :texinfo
"@guillemetleft{}")
5268 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5269 :texinfo
"@guillemetright{}")
5270 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5271 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5272 (apostrophe :utf-8
"’" :html
"’"))
5274 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5276 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5277 :texinfo
"@guillemetleft{}")
5279 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5280 :texinfo
"@guillemetright{}")
5281 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5282 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5283 (apostrophe :utf-8
"’" :html
"’"))
5285 ;; https://nn.wikipedia.org/wiki/Sitatteikn
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
"`" :texinfo
"`")
5293 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5294 (apostrophe :utf-8
"’" :html
"’"))
5296 ;; 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
5297 ;; http://www.artlebedev.ru/kovodstvo/sections/104/
5298 (primary-opening :utf-8
"«" :html
"«" :latex
"{}<<"
5299 :texinfo
"@guillemetleft{}")
5300 (primary-closing :utf-8
"»" :html
"»" :latex
">>{}"
5301 :texinfo
"@guillemetright{}")
5303 :utf-8
"„" :html
"„" :latex
"\\glqq{}" :texinfo
"@quotedblbase{}")
5305 :utf-8
"“" :html
"“" :latex
"\\grqq{}" :texinfo
"@quotedblleft{}")
5306 (apostrophe :utf-8
"’" :html
: "'"))
5308 ;; based on https://sv.wikipedia.org/wiki/Citattecken
5309 (primary-opening :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
5310 (primary-closing :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
5311 (secondary-opening :utf-8
"’" :html
"’" :latex
"’" :texinfo
"`")
5312 (secondary-closing :utf-8
"’" :html
"’" :latex
"’" :texinfo
"'")
5313 (apostrophe :utf-8
"’" :html
"’")))
5314 "Smart quotes translations.
5316 Alist whose CAR is a language string and CDR is an alist with
5317 quote type as key and a plist associating various encodings to
5318 their translation as value.
5320 A quote type can be any symbol among `primary-opening',
5321 `primary-closing', `secondary-opening', `secondary-closing' and
5324 Valid encodings include `:utf-8', `:html', `:latex' and
5327 If no translation is found, the quote character is left as-is.")
5329 (defun org-export--smart-quote-status (s info
)
5330 "Return smart quote status at the beginning of string S.
5331 INFO is the current export state, as a plist."
5332 (let* ((parent (org-element-property :parent s
))
5333 (cache (or (plist-get info
:smart-quote-cache
)
5334 (let ((table (make-hash-table :test
#'eq
)))
5335 (plist-put info
:smart-quote-cache table
)
5337 (value (gethash parent cache
'missing-data
)))
5338 (if (not (eq value
'missing-data
)) (cdr (assq s value
))
5339 (let (level1-open full-status
)
5341 (let ((secondary (org-element-secondary-p s
)))
5342 (if secondary
(org-element-property secondary parent
)
5343 (org-element-contents parent
)))
5346 (let ((start 0) current-status
)
5347 (while (setq start
(string-match "['\"]" text start
))
5350 ((equal (match-string 0 text
) "\"")
5351 (setf level1-open
(not level1-open
))
5352 (if level1-open
'primary-opening
'primary-closing
))
5353 ;; Not already in a level 1 quote: this is an
5355 ((not level1-open
) 'apostrophe
)
5356 ;; Extract previous char and next char. As
5357 ;; a special case, they can also be set to `blank',
5358 ;; `no-blank' or nil. Then determine if current
5359 ;; match is allowed as an opening quote or a closing
5363 (if (> start
0) (substring text
(1- start
) start
)
5364 (let ((p (org-export-get-previous-element
5367 ((stringp p
) (substring p -
1))
5368 ((memq (org-element-property :post-blank p
)
5373 (if (< (1+ start
) (length text
))
5374 (substring text
(1+ start
) (+ start
2))
5375 (let ((n (org-export-get-next-element text info
)))
5377 ((stringp n
) (substring n
0 1))
5380 (and (if (stringp previous
)
5381 (string-match "\\s\"\\|\\s-\\|\\s("
5383 (memq previous
'(blank nil
)))
5385 (string-match "\\w\\|\\s.\\|\\s_" next
)
5386 (eq next
'no-blank
))))
5388 (and (if (stringp previous
)
5389 (string-match "\\w\\|\\s.\\|\\s_" previous
)
5390 (eq previous
'no-blank
))
5392 (string-match "\\s-\\|\\s)\\|\\s.\\|\\s\""
5394 (memq next
'(blank nil
))))))
5396 ((and allow-open allow-close
) (error "Should not happen"))
5397 (allow-open 'secondary-opening
)
5398 (allow-close 'secondary-closing
)
5402 (when current-status
5403 (push (cons text
(nreverse current-status
)) full-status
))))
5404 info nil org-element-recursive-objects
)
5405 (puthash parent full-status cache
)
5406 (cdr (assq s full-status
))))))
5408 (defun org-export-activate-smart-quotes (s encoding info
&optional original
)
5409 "Replace regular quotes with \"smart\" quotes in string S.
5411 ENCODING is a symbol among `:html', `:latex', `:texinfo' and
5412 `:utf-8'. INFO is a plist used as a communication channel.
5414 The function has to retrieve information about string
5415 surroundings in parse tree. It can only happen with an
5416 unmodified string. Thus, if S has already been through another
5417 process, a non-nil ORIGINAL optional argument will provide that
5420 Return the new string."
5422 (copy-sequence (org-export--smart-quote-status (or original s
) info
))))
5423 (replace-regexp-in-string
5427 (cdr (assq (pop quote-status
)
5428 (cdr (assoc (plist-get info
:language
)
5429 org-export-smart-quotes-alist
))))
5436 ;; Here are various functions to retrieve information about the
5437 ;; neighborhood of a given element or object. Neighbors of interest
5438 ;; are direct parent (`org-export-get-parent'), parent headline
5439 ;; (`org-export-get-parent-headline'), first element containing an
5440 ;; object, (`org-export-get-parent-element'), parent table
5441 ;; (`org-export-get-parent-table'), previous element or object
5442 ;; (`org-export-get-previous-element') and next element or object
5443 ;; (`org-export-get-next-element').
5445 ;; defsubst org-export-get-parent must be defined before first use
5447 (defun org-export-get-parent-headline (blob)
5448 "Return BLOB parent headline or nil.
5449 BLOB is the element or object being considered."
5450 (org-element-lineage blob
'(headline)))
5452 (defun org-export-get-parent-element (object)
5453 "Return first element containing OBJECT or nil.
5454 OBJECT is the object to consider."
5455 (org-element-lineage object org-element-all-elements
))
5457 (defun org-export-get-parent-table (object)
5458 "Return OBJECT parent table or nil.
5459 OBJECT is either a `table-cell' or `table-element' type object."
5460 (org-element-lineage object
'(table)))
5462 (defun org-export-get-previous-element (blob info
&optional n
)
5463 "Return previous element or object.
5465 BLOB is an element or object. INFO is a plist used as
5466 a communication channel. Return previous exportable element or
5467 object, a string, or nil.
5469 When optional argument N is a positive integer, return a list
5470 containing up to N siblings before BLOB, from farthest to
5471 closest. With any other non-nil value, return a list containing
5473 (let* ((secondary (org-element-secondary-p blob
))
5474 (parent (org-export-get-parent blob
))
5476 (if secondary
(org-element-property secondary parent
)
5477 (org-element-contents parent
)))
5480 (dolist (obj (cdr (memq blob
(reverse siblings
))) prev
)
5481 (cond ((memq obj
(plist-get info
:ignore-list
)))
5482 ((null n
) (throw 'exit obj
))
5483 ((not (wholenump n
)) (push obj prev
))
5484 ((zerop n
) (throw 'exit prev
))
5485 (t (cl-decf n
) (push obj prev
)))))))
5487 (defun org-export-get-next-element (blob info
&optional n
)
5488 "Return next element or object.
5490 BLOB is an element or object. INFO is a plist used as
5491 a communication channel. Return next exportable element or
5492 object, a string, or nil.
5494 When optional argument N is a positive integer, return a list
5495 containing up to N siblings after BLOB, from closest to farthest.
5496 With any other non-nil value, return a list containing all of
5498 (let* ((secondary (org-element-secondary-p blob
))
5499 (parent (org-export-get-parent blob
))
5502 (if secondary
(org-element-property secondary parent
)
5503 (org-element-contents parent
)))))
5506 (dolist (obj siblings
(nreverse next
))
5507 (cond ((memq obj
(plist-get info
:ignore-list
)))
5508 ((null n
) (throw 'exit obj
))
5509 ((not (wholenump n
)) (push obj next
))
5510 ((zerop n
) (throw 'exit
(nreverse next
)))
5511 (t (cl-decf n
) (push obj next
)))))))
5516 ;; `org-export-translate' translates a string according to the language
5517 ;; specified by the LANGUAGE keyword. `org-export-dictionary' contains
5518 ;; the dictionary used for the translation.
5520 (defconst org-export-dictionary
5522 ("fr" :default
"%e %n : %c" :html
"%e %n : %c"))
5524 ("ca" :default
"Autor")
5525 ("cs" :default
"Autor")
5526 ("da" :default
"Forfatter")
5527 ("de" :default
"Autor")
5528 ("eo" :html
"Aŭtoro")
5529 ("es" :default
"Autor")
5530 ("et" :default
"Autor")
5531 ("fi" :html
"Tekijä")
5532 ("fr" :default
"Auteur")
5533 ("hu" :default
"Szerzõ")
5534 ("is" :html
"Höfundur")
5535 ("it" :default
"Autore")
5536 ("ja" :default
"著者" :html
"著者")
5537 ("nl" :default
"Auteur")
5538 ("no" :default
"Forfatter")
5539 ("nb" :default
"Forfatter")
5540 ("nn" :default
"Forfattar")
5541 ("pl" :default
"Autor")
5542 ("pt_BR" :default
"Autor")
5543 ("ru" :html
"Автор" :utf-8
"Автор")
5544 ("sv" :html
"Författare")
5545 ("uk" :html
"Автор" :utf-8
"Автор")
5546 ("zh-CN" :html
"作者" :utf-8
"作者")
5547 ("zh-TW" :html
"作者" :utf-8
"作者"))
5548 ("Continued from previous page"
5549 ("de" :default
"Fortsetzung von vorheriger Seite")
5550 ("es" :html
"Continúa de la página anterior" :ascii
"Continua de la pagina anterior" :default
"Continúa de la página anterior")
5551 ("fr" :default
"Suite de la page précédente")
5552 ("it" :default
"Continua da pagina precedente")
5553 ("ja" :default
"前ページからの続き")
5554 ("nl" :default
"Vervolg van vorige pagina")
5555 ("pt" :default
"Continuação da página anterior")
5556 ("ru" :html
"(Продолжение)"
5557 :utf-8
"(Продолжение)"))
5558 ("Continued on next page"
5559 ("de" :default
"Fortsetzung nächste Seite")
5560 ("es" :html
"Continúa en la siguiente página" :ascii
"Continua en la siguiente pagina" :default
"Continúa en la siguiente página")
5561 ("fr" :default
"Suite page suivante")
5562 ("it" :default
"Continua alla pagina successiva")
5563 ("ja" :default
"次ページに続く")
5564 ("nl" :default
"Vervolg op volgende pagina")
5565 ("pt" :default
"Continua na página seguinte")
5566 ("ru" :html
"(Продолжение следует)"
5567 :utf-8
"(Продолжение следует)"))
5569 ("ca" :default
"Data")
5570 ("cs" :default
"Datum")
5571 ("da" :default
"Dato")
5572 ("de" :default
"Datum")
5573 ("eo" :default
"Dato")
5574 ("es" :default
"Fecha")
5575 ("et" :html
"Kuupäev" :utf-8
"Kuupäev")
5576 ("fi" :html
"Päivämäärä")
5577 ("hu" :html
"Dátum")
5578 ("is" :default
"Dagsetning")
5579 ("it" :default
"Data")
5580 ("ja" :default
"日付" :html
"日付")
5581 ("nl" :default
"Datum")
5582 ("no" :default
"Dato")
5583 ("nb" :default
"Dato")
5584 ("nn" :default
"Dato")
5585 ("pl" :default
"Data")
5586 ("pt_BR" :default
"Data")
5587 ("ru" :html
"Дата" :utf-8
"Дата")
5588 ("sv" :default
"Datum")
5589 ("uk" :html
"Дата" :utf-8
"Дата")
5590 ("zh-CN" :html
"日期" :utf-8
"日期")
5591 ("zh-TW" :html
"日期" :utf-8
"日期"))
5593 ("da" :default
"Ligning")
5594 ("de" :default
"Gleichung")
5595 ("es" :ascii
"Ecuacion" :html
"Ecuación" :default
"Ecuación")
5596 ("et" :html
"Võrrand" :utf-8
"Võrrand")
5597 ("fr" :ascii
"Equation" :default
"Équation")
5598 ("is" :default
"Jafna")
5599 ("ja" :default
"方程式")
5600 ("no" :default
"Ligning")
5601 ("nb" :default
"Ligning")
5602 ("nn" :default
"Likning")
5603 ("pt_BR" :html
"Equação" :default
"Equação" :ascii
"Equacao")
5604 ("ru" :html
"Уравнение"
5606 ("sv" :default
"Ekvation")
5607 ("zh-CN" :html
"方程" :utf-8
"方程"))
5609 ("da" :default
"Figur")
5610 ("de" :default
"Abbildung")
5611 ("es" :default
"Figura")
5612 ("et" :default
"Joonis")
5613 ("is" :default
"Mynd")
5614 ("ja" :default
"図" :html
"図")
5615 ("no" :default
"Illustrasjon")
5616 ("nb" :default
"Illustrasjon")
5617 ("nn" :default
"Illustrasjon")
5618 ("pt_BR" :default
"Figura")
5619 ("ru" :html
"Рисунок" :utf-8
"Рисунок")
5620 ("sv" :default
"Illustration")
5621 ("zh-CN" :html
"图" :utf-8
"图"))
5623 ("da" :default
"Figur %d")
5624 ("de" :default
"Abbildung %d:")
5625 ("es" :default
"Figura %d:")
5626 ("et" :default
"Joonis %d:")
5627 ("fr" :default
"Figure %d :" :html
"Figure %d :")
5628 ("is" :default
"Mynd %d")
5629 ("ja" :default
"図%d: " :html
"図%d: ")
5630 ("no" :default
"Illustrasjon %d")
5631 ("nb" :default
"Illustrasjon %d")
5632 ("nn" :default
"Illustrasjon %d")
5633 ("pt_BR" :default
"Figura %d:")
5634 ("ru" :html
"Рис. %d.:" :utf-8
"Рис. %d.:")
5635 ("sv" :default
"Illustration %d")
5636 ("zh-CN" :html
"图%d " :utf-8
"图%d "))
5638 ("ca" :html
"Peus de pàgina")
5639 ("cs" :default
"Pozn\xe1mky pod carou")
5640 ("da" :default
"Fodnoter")
5641 ("de" :html
"Fußnoten" :default
"Fußnoten")
5642 ("eo" :default
"Piednotoj")
5643 ("es" :ascii
"Nota al pie de pagina" :html
"Nota al pie de página" :default
"Nota al pie de página")
5644 ("et" :html
"Allmärkused" :utf-8
"Allmärkused")
5645 ("fi" :default
"Alaviitteet")
5646 ("fr" :default
"Notes de bas de page")
5647 ("hu" :html
"Lábjegyzet")
5648 ("is" :html
"Aftanmálsgreinar")
5649 ("it" :html
"Note a piè di pagina")
5650 ("ja" :default
"脚注" :html
"脚注")
5651 ("nl" :default
"Voetnoten")
5652 ("no" :default
"Fotnoter")
5653 ("nb" :default
"Fotnoter")
5654 ("nn" :default
"Fotnotar")
5655 ("pl" :default
"Przypis")
5656 ("pt_BR" :html
"Notas de Rodapé" :default
"Notas de Rodapé" :ascii
"Notas de Rodape")
5657 ("ru" :html
"Сноски" :utf-8
"Сноски")
5658 ("sv" :default
"Fotnoter")
5659 ("uk" :html
"Примітки"
5661 ("zh-CN" :html
"脚注" :utf-8
"脚注")
5662 ("zh-TW" :html
"腳註" :utf-8
"腳註"))
5664 ("da" :default
"Programmer")
5665 ("de" :default
"Programmauflistungsverzeichnis")
5666 ("es" :ascii
"Indice de Listados de programas" :html
"Índice de Listados de programas" :default
"Índice de Listados de programas")
5667 ("et" :default
"Loendite nimekiri")
5668 ("fr" :default
"Liste des programmes")
5669 ("ja" :default
"ソースコード目次")
5670 ("no" :default
"Dataprogrammer")
5671 ("nb" :default
"Dataprogrammer")
5672 ("ru" :html
"Список распечаток"
5673 :utf-8
"Список распечаток")
5674 ("zh-CN" :html
"代码目录" :utf-8
"代码目录"))
5676 ("da" :default
"Tabeller")
5677 ("de" :default
"Tabellenverzeichnis")
5678 ("es" :ascii
"Indice de tablas" :html
"Índice de tablas" :default
"Índice de tablas")
5679 ("et" :default
"Tabelite nimekiri")
5680 ("fr" :default
"Liste des tableaux")
5681 ("is" :default
"Töfluskrá" :html
"Töfluskrá")
5682 ("ja" :default
"表目次")
5683 ("no" :default
"Tabeller")
5684 ("nb" :default
"Tabeller")
5685 ("nn" :default
"Tabeller")
5686 ("pt_BR" :default
"Índice de Tabelas" :ascii
"Indice de Tabelas")
5687 ("ru" :html
"Список таблиц"
5688 :utf-8
"Список таблиц")
5689 ("sv" :default
"Tabeller")
5690 ("zh-CN" :html
"表格目录" :utf-8
"表格目录"))
5692 ("da" :default
"Program")
5693 ("de" :default
"Programmlisting")
5694 ("es" :default
"Listado de programa")
5695 ("et" :default
"Loend")
5696 ("fr" :default
"Programme" :html
"Programme")
5697 ("ja" :default
"ソースコード")
5698 ("no" :default
"Dataprogram")
5699 ("nb" :default
"Dataprogram")
5700 ("pt_BR" :default
"Listagem")
5701 ("ru" :html
"Распечатка"
5702 :utf-8
"Распечатка")
5703 ("zh-CN" :html
"代码" :utf-8
"代码"))
5705 ("da" :default
"Program %d")
5706 ("de" :default
"Programmlisting %d")
5707 ("es" :default
"Listado de programa %d")
5708 ("et" :default
"Loend %d")
5709 ("fr" :default
"Programme %d :" :html
"Programme %d :")
5710 ("ja" :default
"ソースコード%d:")
5711 ("no" :default
"Dataprogram %d")
5712 ("nb" :default
"Dataprogram %d")
5713 ("pt_BR" :default
"Listagem %d")
5714 ("ru" :html
"Распечатка %d.:"
5715 :utf-8
"Распечатка %d.:")
5716 ("zh-CN" :html
"代码%d " :utf-8
"代码%d "))
5718 ("fr" :ascii
"References" :default
"Références")
5719 ("de" :default
"Quellen")
5720 ("es" :default
"Referencias"))
5722 ("fr" :default
"cf. figure %s"
5723 :html
"cf. figure %s" :latex
"cf.~figure~%s"))
5725 ("fr" :default
"cf. programme %s"
5726 :html
"cf. programme %s" :latex
"cf.~programme~%s"))
5728 ("da" :default
"jævnfør afsnit %s")
5729 ("de" :default
"siehe Abschnitt %s")
5730 ("es" :ascii
"Vea seccion %s" :html
"Vea sección %s" :default
"Vea sección %s")
5731 ("et" :html
"Vaata peatükki %s" :utf-8
"Vaata peatükki %s")
5732 ("fr" :default
"cf. section %s")
5733 ("ja" :default
"セクション %s を参照")
5734 ("pt_BR" :html
"Veja a seção %s" :default
"Veja a seção %s"
5735 :ascii
"Veja a secao %s")
5736 ("ru" :html
"См. раздел %s"
5737 :utf-8
"См. раздел %s")
5738 ("zh-CN" :html
"参见第%s节" :utf-8
"参见第%s节"))
5740 ("fr" :default
"cf. tableau %s"
5741 :html
"cf. tableau %s" :latex
"cf.~tableau~%s"))
5743 ("de" :default
"Tabelle")
5744 ("es" :default
"Tabla")
5745 ("et" :default
"Tabel")
5746 ("fr" :default
"Tableau")
5747 ("is" :default
"Tafla")
5748 ("ja" :default
"表" :html
"表")
5749 ("pt_BR" :default
"Tabela")
5750 ("ru" :html
"Таблица"
5752 ("zh-CN" :html
"表" :utf-8
"表"))
5754 ("da" :default
"Tabel %d")
5755 ("de" :default
"Tabelle %d")
5756 ("es" :default
"Tabla %d")
5757 ("et" :default
"Tabel %d")
5758 ("fr" :default
"Tableau %d :")
5759 ("is" :default
"Tafla %d")
5760 ("ja" :default
"表%d:" :html
"表%d:")
5761 ("no" :default
"Tabell %d")
5762 ("nb" :default
"Tabell %d")
5763 ("nn" :default
"Tabell %d")
5764 ("pt_BR" :default
"Tabela %d")
5765 ("ru" :html
"Таблица %d.:"
5766 :utf-8
"Таблица %d.:")
5767 ("sv" :default
"Tabell %d")
5768 ("zh-CN" :html
"表%d " :utf-8
"表%d "))
5769 ("Table of Contents"
5770 ("ca" :html
"Índex")
5771 ("cs" :default
"Obsah")
5772 ("da" :default
"Indhold")
5773 ("de" :default
"Inhaltsverzeichnis")
5774 ("eo" :default
"Enhavo")
5775 ("es" :ascii
"Indice" :html
"Índice" :default
"Índice")
5776 ("et" :default
"Sisukord")
5777 ("fi" :html
"Sisällysluettelo")
5778 ("fr" :ascii
"Sommaire" :default
"Table des matières")
5779 ("hu" :html
"Tartalomjegyzék")
5780 ("is" :default
"Efnisyfirlit")
5781 ("it" :default
"Indice")
5782 ("ja" :default
"目次" :html
"目次")
5783 ("nl" :default
"Inhoudsopgave")
5784 ("no" :default
"Innhold")
5785 ("nb" :default
"Innhold")
5786 ("nn" :default
"Innhald")
5787 ("pl" :html
"Spis treści")
5788 ("pt_BR" :html
"Índice" :utf8
"Índice" :ascii
"Indice")
5789 ("ru" :html
"Содержание"
5790 :utf-8
"Содержание")
5791 ("sv" :html
"Innehåll")
5792 ("uk" :html
"Зміст" :utf-8
"Зміст")
5793 ("zh-CN" :html
"目录" :utf-8
"目录")
5794 ("zh-TW" :html
"目錄" :utf-8
"目錄"))
5795 ("Unknown reference"
5796 ("da" :default
"ukendt reference")
5797 ("de" :default
"Unbekannter Verweis")
5798 ("es" :default
"Referencia desconocida")
5799 ("et" :default
"Tundmatu viide")
5800 ("fr" :ascii
"Destination inconnue" :default
"Référence inconnue")
5801 ("ja" :default
"不明な参照先")
5802 ("pt_BR" :default
"Referência desconhecida"
5803 :ascii
"Referencia desconhecida")
5804 ("ru" :html
"Неизвестная ссылка"
5805 :utf-8
"Неизвестная ссылка")
5806 ("zh-CN" :html
"未知引用" :utf-8
"未知引用")))
5807 "Dictionary for export engine.
5809 Alist whose car is the string to translate and cdr is an alist
5810 whose car is the language string and cdr is a plist whose
5811 properties are possible charsets and values translated terms.
5813 It is used as a database for `org-export-translate'. Since this
5814 function returns the string as-is if no translation was found,
5815 the variable only needs to record values different from the
5818 (defun org-export-translate (s encoding info
)
5819 "Translate string S according to language specification.
5821 ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
5822 and `:utf-8'. INFO is a plist used as a communication channel.
5824 Translation depends on `:language' property. Return the
5825 translated string. If no translation is found, try to fall back
5826 to `:default' encoding. If it fails, return S."
5827 (let* ((lang (plist-get info
:language
))
5828 (translations (cdr (assoc lang
5829 (cdr (assoc s org-export-dictionary
))))))
5830 (or (plist-get translations encoding
)
5831 (plist-get translations
:default
)
5836 ;;; Asynchronous Export
5838 ;; `org-export-async-start' is the entry point for asynchronous
5839 ;; export. It recreates current buffer (including visibility,
5840 ;; narrowing and visited file) in an external Emacs process, and
5841 ;; evaluates a command there. It then applies a function on the
5842 ;; returned results in the current process.
5844 ;; At a higher level, `org-export-to-buffer' and `org-export-to-file'
5845 ;; allow exporting to a buffer or a file, asynchronously or not.
5847 ;; `org-export-output-file-name' is an auxiliary function meant to be
5848 ;; used with `org-export-to-file'. With a given extension, it tries
5849 ;; to provide a canonical file name to write export output to.
5851 ;; Asynchronously generated results are never displayed directly.
5852 ;; Instead, they are stored in `org-export-stack-contents'. They can
5853 ;; then be retrieved by calling `org-export-stack'.
5855 ;; Export Stack is viewed through a dedicated major mode
5856 ;;`org-export-stack-mode' and tools: `org-export-stack-refresh',
5857 ;;`org-export-stack-delete', `org-export-stack-view' and
5858 ;;`org-export-stack-clear'.
5860 ;; For back-ends, `org-export-add-to-stack' add a new source to stack.
5861 ;; It should be used whenever `org-export-async-start' is called.
5863 (defmacro org-export-async-start
(fun &rest body
)
5864 "Call function FUN on the results returned by BODY evaluation.
5866 FUN is an anonymous function of one argument. BODY evaluation
5867 happens in an asynchronous process, from a buffer which is an
5868 exact copy of the current one.
5870 Use `org-export-add-to-stack' in FUN in order to register results
5873 This is a low level function. See also `org-export-to-buffer'
5874 and `org-export-to-file' for more specialized functions."
5875 (declare (indent 1) (debug t
))
5876 (org-with-gensyms (process temp-file copy-fun proc-buffer coding
)
5877 ;; Write the full sexp evaluating BODY in a copy of the current
5878 ;; buffer to a temporary file, as it may be too long for program
5879 ;; args in `start-process'.
5880 `(with-temp-message "Initializing asynchronous export process"
5881 (let ((,copy-fun
(org-export--generate-copy-script (current-buffer)))
5882 (,temp-file
(make-temp-file "org-export-process"))
5883 (,coding buffer-file-coding-system
))
5884 (with-temp-file ,temp-file
5886 ;; Null characters (from variable values) are inserted
5887 ;; within the file. As a consequence, coding system for
5888 ;; buffer contents will not be recognized properly. So,
5889 ;; we make sure it is the same as the one used to display
5890 ;; the original buffer.
5891 (format ";; -*- coding: %s; -*-\n%S"
5894 (when org-export-async-debug
'(setq debug-on-error t
))
5895 ;; Ignore `kill-emacs-hook' and code evaluation
5896 ;; queries from Babel as we need a truly
5897 ;; non-interactive process.
5898 (setq kill-emacs-hook nil
5899 org-babel-confirm-evaluate-answer-no t
)
5900 ;; Initialize export framework.
5902 ;; Re-create current buffer there.
5903 (funcall ,,copy-fun
)
5904 (restore-buffer-modified-p nil
)
5905 ;; Sexp to evaluate in the buffer.
5906 (print (progn ,,@body
))))))
5907 ;; Start external process.
5908 (let* ((process-connection-type nil
)
5909 (,proc-buffer
(generate-new-buffer-name "*Org Export Process*"))
5914 (list "org-export-process"
5916 (expand-file-name invocation-name invocation-directory
)
5918 (if org-export-async-init-file
5919 (list "-Q" "-l" org-export-async-init-file
)
5920 (list "-l" user-init-file
))
5921 (list "-l" ,temp-file
)))))
5922 ;; Register running process in stack.
5923 (org-export-add-to-stack (get-buffer ,proc-buffer
) nil
,process
)
5924 ;; Set-up sentinel in order to catch results.
5925 (let ((handler ,fun
))
5926 (set-process-sentinel
5929 (let ((proc-buffer (process-buffer p
)))
5930 (when (eq (process-status p
) 'exit
)
5932 (if (zerop (process-exit-status p
))
5935 (with-current-buffer proc-buffer
5936 (goto-char (point-max))
5938 (read (current-buffer)))))
5939 (funcall ,handler results
))
5940 (unless org-export-async-debug
5941 (and (get-buffer proc-buffer
)
5942 (kill-buffer proc-buffer
))))
5943 (org-export-add-to-stack proc-buffer nil p
)
5945 (message "Process `%s' exited abnormally" p
))
5946 (unless org-export-async-debug
5947 (delete-file ,,temp-file
)))))))))))))
5950 (defun org-export-to-buffer
5952 &optional async subtreep visible-only body-only ext-plist
5954 "Call `org-export-as' with output to a specified buffer.
5956 BACKEND is either an export back-end, as returned by, e.g.,
5957 `org-export-create-backend', or a symbol referring to
5958 a registered back-end.
5960 BUFFER is the name of the output buffer. If it already exists,
5961 it will be erased first, otherwise, it will be created.
5963 A non-nil optional argument ASYNC means the process should happen
5964 asynchronously. The resulting buffer should then be accessible
5965 through the `org-export-stack' interface. When ASYNC is nil, the
5966 buffer is displayed if `org-export-show-temporary-export-buffer'
5969 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
5970 EXT-PLIST are similar to those used in `org-export-as', which
5973 Optional argument POST-PROCESS is a function which should accept
5974 no argument. It is always called within the current process,
5975 from BUFFER, with point at its beginning. Export back-ends can
5976 use it to set a major mode there, e.g,
5978 (defun org-latex-export-as-latex
5979 (&optional async subtreep visible-only body-only ext-plist)
5981 (org-export-to-buffer \\='latex \"*Org LATEX Export*\"
5982 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
5984 This function returns BUFFER."
5985 (declare (indent 2))
5987 (org-export-async-start
5989 (with-current-buffer (get-buffer-create ,buffer
)
5991 (setq buffer-file-coding-system
',buffer-file-coding-system
)
5993 (goto-char (point-min))
5994 (org-export-add-to-stack (current-buffer) ',backend
)
5995 (ignore-errors (funcall ,post-process
))))
5997 ',backend
,subtreep
,visible-only
,body-only
',ext-plist
))
5999 (org-export-as backend subtreep visible-only body-only ext-plist
))
6000 (buffer (get-buffer-create buffer
))
6001 (encoding buffer-file-coding-system
))
6002 (when (and (org-string-nw-p output
) (org-export--copy-to-kill-ring-p))
6003 (org-kill-new output
))
6004 (with-current-buffer buffer
6006 (setq buffer-file-coding-system encoding
)
6008 (goto-char (point-min))
6009 (and (functionp post-process
) (funcall post-process
)))
6010 (when org-export-show-temporary-export-buffer
6011 (switch-to-buffer-other-window buffer
))
6015 (defun org-export-to-file
6016 (backend file
&optional async subtreep visible-only body-only ext-plist
6018 "Call `org-export-as' with output to a specified file.
6020 BACKEND is either an export back-end, as returned by, e.g.,
6021 `org-export-create-backend', or a symbol referring to
6022 a registered back-end. FILE is the name of the output file, as
6025 A non-nil optional argument ASYNC means the process should happen
6026 asynchronously. The resulting buffer will then be accessible
6027 through the `org-export-stack' interface.
6029 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
6030 EXT-PLIST are similar to those used in `org-export-as', which
6033 Optional argument POST-PROCESS is called with FILE as its
6034 argument and happens asynchronously when ASYNC is non-nil. It
6035 has to return a file name, or nil. Export back-ends can use this
6036 to send the output file through additional processing, e.g,
6038 (defun org-latex-export-to-latex
6039 (&optional async subtreep visible-only body-only ext-plist)
6041 (let ((outfile (org-export-output-file-name \".tex\" subtreep)))
6042 (org-export-to-file \\='latex outfile
6043 async subtreep visible-only body-only ext-plist
6044 (lambda (file) (org-latex-compile file)))
6046 The function returns either a file name returned by POST-PROCESS,
6048 (declare (indent 2))
6049 (if (not (file-writable-p file
)) (error "Output file not writable")
6050 (let ((ext-plist (org-combine-plists `(:output-file
,file
) ext-plist
))
6051 (encoding (or org-export-coding-system buffer-file-coding-system
)))
6053 (org-export-async-start
6055 (org-export-add-to-stack (expand-file-name file
) ',backend
))
6058 ',backend
,subtreep
,visible-only
,body-only
6062 (let ((coding-system-for-write ',encoding
))
6063 (write-file ,file
)))
6064 (or (ignore-errors (funcall ',post-process
,file
)) ,file
)))
6065 (let ((output (org-export-as
6066 backend subtreep visible-only body-only ext-plist
)))
6069 (let ((coding-system-for-write encoding
))
6071 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p output
))
6072 (org-kill-new output
))
6073 ;; Get proper return value.
6074 (or (and (functionp post-process
) (funcall post-process file
))
6077 (defun org-export-output-file-name (extension &optional subtreep pub-dir
)
6078 "Return output file's name according to buffer specifications.
6080 EXTENSION is a string representing the output file extension,
6081 with the leading dot.
6083 With a non-nil optional argument SUBTREEP, try to determine
6084 output file's name by looking for \"EXPORT_FILE_NAME\" property
6085 of subtree at point.
6087 When optional argument PUB-DIR is set, use it as the publishing
6090 Return file name as a string."
6091 (let* ((visited-file (buffer-file-name (buffer-base-buffer)))
6093 ;; File name may come from EXPORT_FILE_NAME subtree
6095 (file-name-sans-extension
6096 (or (and subtreep
(org-entry-get nil
"EXPORT_FILE_NAME" 'selective
))
6097 ;; File name may be extracted from buffer's associated
6099 (and visited-file
(file-name-nondirectory visited-file
))
6100 ;; Can't determine file name on our own: Ask user.
6102 "Output file: " pub-dir nil nil nil
6104 (string= (file-name-extension name t
) extension
))))))
6106 ;; Build file name. Enforce EXTENSION over whatever user
6107 ;; may have come up with. PUB-DIR, if defined, always has
6108 ;; precedence over any provided path.
6111 (concat (file-name-as-directory pub-dir
)
6112 (file-name-nondirectory base-name
)
6114 ((file-name-absolute-p base-name
) (concat base-name extension
))
6115 (t (concat (file-name-as-directory ".") base-name extension
)))))
6116 ;; If writing to OUTPUT-FILE would overwrite original file, append
6117 ;; EXTENSION another time to final name.
6118 (if (and visited-file
(file-equal-p visited-file output-file
))
6119 (concat output-file extension
)
6122 (defun org-export-add-to-stack (source backend
&optional process
)
6123 "Add a new result to export stack if not present already.
6125 SOURCE is a buffer or a file name containing export results.
6126 BACKEND is a symbol representing export back-end used to generate
6129 Entries already pointing to SOURCE and unavailable entries are
6130 removed beforehand. Return the new stack."
6131 (setq org-export-stack-contents
6132 (cons (list source backend
(or process
(current-time)))
6133 (org-export-stack-remove source
))))
6135 (defun org-export-stack ()
6136 "Menu for asynchronous export results and running processes."
6138 (let ((buffer (get-buffer-create "*Org Export Stack*")))
6139 (with-current-buffer buffer
6140 (org-export-stack-mode)
6141 (tabulated-list-print t
))
6142 (pop-to-buffer buffer
))
6143 (message "Type \"q\" to quit, \"?\" for help"))
6145 (defun org-export-stack-clear ()
6146 "Remove all entries from export stack."
6148 (setq org-export-stack-contents nil
))
6150 (defun org-export-stack-refresh ()
6151 "Refresh the export stack."
6153 (tabulated-list-print t
))
6155 (defun org-export-stack-remove (&optional source
)
6156 "Remove export results at point from stack.
6157 If optional argument SOURCE is non-nil, remove it instead."
6159 (let ((source (or source
(org-export--stack-source-at-point))))
6160 (setq org-export-stack-contents
6161 (cl-remove-if (lambda (el) (equal (car el
) source
))
6162 org-export-stack-contents
))))
6164 (defun org-export-stack-view (&optional in-emacs
)
6165 "View export results at point in stack.
6166 With an optional prefix argument IN-EMACS, force viewing files
6169 (let ((source (org-export--stack-source-at-point)))
6170 (cond ((processp source
)
6171 (org-switch-to-buffer-other-window (process-buffer source
)))
6172 ((bufferp source
) (org-switch-to-buffer-other-window source
))
6173 (t (org-open-file source in-emacs
)))))
6175 (defvar org-export-stack-mode-map
6176 (let ((km (make-sparse-keymap)))
6177 (set-keymap-parent km tabulated-list-mode-map
)
6178 (define-key km
" " 'next-line
)
6179 (define-key km
"\C-n" 'next-line
)
6180 (define-key km
[down] 'next-line)
6181 (define-key km "\C-p" 'previous-line)
6182 (define-key km "\C-?" 'previous-line)
6183 (define-key km [up] 'previous-line)
6184 (define-key km "C" 'org-export-stack-clear)
6185 (define-key km "v" 'org-export-stack-view)
6186 (define-key km (kbd "RET") 'org-export-stack-view)
6187 (define-key km "d" 'org-export-stack-remove)
6189 "Keymap for Org Export Stack.")
6191 (define-derived-mode org-export-stack-mode tabulated-list-mode "Org-Stack"
6192 "Mode for displaying asynchronous export stack.
6194 Type `\\[org-export-stack]' to visualize the asynchronous export
6197 In an Org Export Stack buffer, use \
6198 \\<org-export-stack-mode-map>`\\[org-export-stack-view]' to view export output
6199 on current line, `\\[org-export-stack-remove]' to remove it from the stack and \
6200 `\\[org-export-stack-clear]' to clear
6203 Removing entries in a stack buffer does not affect files
6204 or buffers, only display.
6206 \\{org-export-stack-mode-map}"
6207 (setq tabulated-list-format
6208 (vector (list "#" 4 #'org-export--stack-num-predicate)
6209 (list "Back-End" 12 t)
6211 (list "Source" 0 nil)))
6212 (setq tabulated-list-sort-key (cons "#" nil))
6213 (setq tabulated-list-entries #'org-export--stack-generate)
6214 (add-hook 'tabulated-list-revert-hook #'org-export--stack-generate nil t)
6215 (add-hook 'post-command-hook #'org-export-stack-refresh nil t)
6216 (tabulated-list-init-header))
6218 (defun org-export--stack-generate ()
6219 "Generate the asynchronous export stack for display.
6220 Unavailable sources are removed from the list. Return a list
6221 appropriate for `tabulated-list-print'."
6222 ;; Clear stack from exited processes, dead buffers or non-existent
6224 (setq org-export-stack-contents
6227 (if (processp (nth 2 el))
6228 (buffer-live-p (process-buffer (nth 2 el)))
6229 (let ((source (car el)))
6230 (if (bufferp source) (buffer-live-p source)
6231 (file-exists-p source)))))
6232 org-export-stack-contents))
6233 ;; Update `tabulated-list-entries'.
6237 (let ((source (car entry)))
6241 (number-to-string (cl-incf counter))
6243 (if (nth 1 entry) (symbol-name (nth 1 entry)) "")
6245 (let ((info (nth 2 entry)))
6246 (if (processp info) (symbol-name (process-status info))
6247 (format-seconds "%h:%.2m" (float-time (time-since info)))))
6249 (if (stringp source) source (buffer-name source))))))
6250 org-export-stack-contents)))
6252 (defun org-export--stack-num-predicate (a b)
6253 (< (string-to-number (aref (nth 1 a) 0))
6254 (string-to-number (aref (nth 1 b) 0))))
6256 (defun org-export--stack-source-at-point ()
6257 "Return source from export results at point in stack."
6258 (let ((source (car (nth (1- (org-current-line)) org-export-stack-contents))))
6259 (if (not source) (error "Source unavailable, please refresh buffer")
6260 (let ((source-name (if (stringp source) source (buffer-name source))))
6263 (looking-at-p (concat ".* +" (regexp-quote source-name) "$")))
6265 ;; SOURCE is not consistent with current line. The stack
6266 ;; view is outdated.
6267 (error (substitute-command-keys
6268 "Source unavailable; type `\\[org-export-stack-refresh]' \
6269 to refresh buffer")))))))
6275 ;; `org-export-dispatch' is the standard interactive way to start an
6276 ;; export process. It uses `org-export--dispatch-ui' as a subroutine
6277 ;; for its interface, which, in turn, delegates response to key
6278 ;; pressed to `org-export--dispatch-action'.
6281 (defun org-export-dispatch (&optional arg)
6282 "Export dispatcher for Org mode.
6284 It provides an access to common export related tasks in a buffer.
6285 Its interface comes in two flavors: standard and expert.
6287 While both share the same set of bindings, only the former
6288 displays the valid keys associations in a dedicated buffer.
6289 Scrolling (resp. line-wise motion) in this buffer is done with
6290 SPC and DEL (resp. C-n and C-p) keys.
6292 Set variable `org-export-dispatch-use-expert-ui' to switch to one
6293 flavor or the other.
6295 When ARG is `\\[universal-argument]', repeat the last export action, with the\
6297 set of options used back then, on the current buffer.
6299 When ARG is `\\[universal-argument] \\[universal-argument]', display the \
6300 asynchronous export stack."
6303 (cond ((equal arg '(16)) '(stack))
6304 ((and arg org-export-dispatch-last-action))
6305 (t (save-window-excursion
6308 ;; Remember where we are
6309 (move-marker org-export-dispatch-last-position
6311 (org-base-buffer (current-buffer)))
6312 ;; Get and store an export command
6313 (setq org-export-dispatch-last-action
6314 (org-export--dispatch-ui
6315 (list org-export-initial-scope
6316 (and org-export-in-background 'async))
6318 org-export-dispatch-use-expert-ui)))
6319 (and (get-buffer "*Org Export Dispatcher*")
6320 (kill-buffer "*Org Export Dispatcher*")))))))
6321 (action (car input))
6322 (optns (cdr input)))
6323 (unless (memq 'subtree optns)
6324 (move-marker org-export-dispatch-last-position nil))
6326 ;; First handle special hard-coded actions.
6327 (template (org-export-insert-default-template nil optns))
6328 (stack (org-export-stack))
6329 (publish-current-file
6330 (org-publish-current-file (memq 'force optns) (memq 'async optns)))
6331 (publish-current-project
6332 (org-publish-current-project (memq 'force optns) (memq 'async optns)))
6333 (publish-choose-project
6334 (org-publish (assoc (completing-read
6336 org-publish-project-alist nil t)
6337 org-publish-project-alist)
6339 (memq 'async optns)))
6340 (publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
6344 ;; Repeating command, maybe move cursor to restore subtree
6346 (if (eq (marker-buffer org-export-dispatch-last-position)
6347 (org-base-buffer (current-buffer)))
6348 (goto-char org-export-dispatch-last-position)
6349 ;; We are in a different buffer, forget position.
6350 (move-marker org-export-dispatch-last-position nil)))
6352 ;; Return a symbol instead of a list to ease
6353 ;; asynchronous export macro use.
6354 (and (memq 'async optns) t)
6355 (and (memq 'subtree optns) t)
6356 (and (memq 'visible optns) t)
6357 (and (memq 'body optns) t)))))))
6359 (defun org-export--dispatch-ui (options first-key expertp)
6360 "Handle interface for `org-export-dispatch'.
6362 OPTIONS is a list containing current interactive options set for
6363 export. It can contain any of the following symbols:
6364 `body' toggles a body-only export
6365 `subtree' restricts export to current subtree
6366 `visible' restricts export to visible part of buffer.
6367 `force' force publishing files.
6368 `async' use asynchronous export process
6370 FIRST-KEY is the key pressed to select the first level menu. It
6371 is nil when this menu hasn't been selected yet.
6373 EXPERTP, when non-nil, triggers expert UI. In that case, no help
6374 buffer is provided, but indications about currently active
6375 options are given in the prompt. Moreover, [?] allows switching
6376 back to standard interface."
6378 (lambda (key &optional access-key)
6379 ;; Fontify KEY string. Optional argument ACCESS-KEY, when
6380 ;; non-nil is the required first-level key to activate
6381 ;; KEY. When its value is t, activate KEY independently
6382 ;; on the first key, if any. A nil value means KEY will
6383 ;; only be activated at first level.
6384 (if (or (eq access-key t) (eq access-key first-key))
6385 (propertize key 'face 'org-warning)
6389 ;; Fontify VALUE string.
6390 (propertize value 'face 'font-lock-variable-name-face)))
6391 ;; Prepare menu entries by extracting them from registered
6392 ;; back-ends and sorting them by access key and by ordinal,
6395 (sort (sort (delq nil
6396 (mapcar #'org-export-backend-menu
6397 org-export-registered-backends))
6399 (let ((key-a (nth 1 a))
6401 (cond ((and (numberp key-a) (numberp key-b))
6403 ((numberp key-b) t)))))
6404 'car-less-than-car))
6405 ;; Compute a list of allowed keys based on the first key
6406 ;; pressed, if any. Some keys
6407 ;; (?^B, ?^V, ?^S, ?^F, ?^A, ?&, ?# and ?q) are always
6410 (nconc (list 2 22 19 6 1)
6411 (if (not first-key) (org-uniquify (mapcar 'car entries))
6413 (dolist (entry entries (sort (mapcar 'car sub-menu) '<))
6414 (when (eq (car entry) first-key)
6415 (setq sub-menu (append (nth 2 entry) sub-menu))))))
6416 (cond ((eq first-key ?P) (list ?f ?p ?x ?a))
6417 ((not first-key) (list ?P)))
6419 (when expertp (list ??))
6421 ;; Build the help menu for standard UI.
6425 ;; Options are hard-coded.
6426 (format "[%s] Body only: %s [%s] Visible only: %s
6427 \[%s] Export scope: %s [%s] Force publishing: %s
6428 \[%s] Async export: %s\n\n"
6429 (funcall fontify-key "C-b" t)
6430 (funcall fontify-value
6431 (if (memq 'body options) "On " "Off"))
6432 (funcall fontify-key "C-v" t)
6433 (funcall fontify-value
6434 (if (memq 'visible options) "On " "Off"))
6435 (funcall fontify-key "C-s" t)
6436 (funcall fontify-value
6437 (if (memq 'subtree options) "Subtree" "Buffer "))
6438 (funcall fontify-key "C-f" t)
6439 (funcall fontify-value
6440 (if (memq 'force options) "On " "Off"))
6441 (funcall fontify-key "C-a" t)
6442 (funcall fontify-value
6443 (if (memq 'async options) "On " "Off")))
6444 ;; Display registered back-end entries. When a key
6445 ;; appears for the second time, do not create another
6446 ;; entry, but append its sub-menu to existing menu.
6450 (let ((top-key (car entry)))
6452 (unless (eq top-key last-key)
6453 (setq last-key top-key)
6454 (format "\n[%s] %s\n"
6455 (funcall fontify-key (char-to-string top-key))
6457 (let ((sub-menu (nth 2 entry)))
6458 (unless (functionp sub-menu)
6459 ;; Split sub-menu into two columns.
6466 (if (zerop (mod index 2)) " [%s] %-26s"
6468 (funcall fontify-key
6469 (char-to-string (car sub-entry))
6473 (when (zerop (mod index 2)) "\n"))))))))
6475 ;; Publishing menu is hard-coded.
6476 (format "\n[%s] Publish
6477 [%s] Current file [%s] Current project
6478 [%s] Choose project [%s] All projects\n\n\n"
6479 (funcall fontify-key "P")
6480 (funcall fontify-key "f" ?P)
6481 (funcall fontify-key "p" ?P)
6482 (funcall fontify-key "x" ?P)
6483 (funcall fontify-key "a" ?P))
6484 (format "[%s] Export stack [%s] Insert template\n"
6485 (funcall fontify-key "&" t)
6486 (funcall fontify-key "#" t))
6488 (funcall fontify-key "q" t)
6489 (if first-key "Main menu" "Exit")))))
6490 ;; Build prompts for both standard and expert UI.
6491 (standard-prompt (unless expertp "Export command: "))
6495 "Export command (C-%s%s%s%s%s) [%s]: "
6496 (if (memq 'body options) (funcall fontify-key "b" t) "b")
6497 (if (memq 'visible options) (funcall fontify-key "v" t) "v")
6498 (if (memq 'subtree options) (funcall fontify-key "s" t) "s")
6499 (if (memq 'force options) (funcall fontify-key "f" t) "f")
6500 (if (memq 'async options) (funcall fontify-key "a" t) "a")
6501 (mapconcat (lambda (k)
6502 ;; Strip control characters.
6503 (unless (< k 27) (char-to-string k)))
6504 allowed-keys "")))))
6505 ;; With expert UI, just read key with a fancy prompt. In standard
6506 ;; UI, display an intrusive help buffer.
6508 (org-export--dispatch-action
6509 expert-prompt allowed-keys entries options first-key expertp)
6510 ;; At first call, create frame layout in order to display menu.
6511 (unless (get-buffer "*Org Export Dispatcher*")
6512 (delete-other-windows)
6513 (org-switch-to-buffer-other-window
6514 (get-buffer-create "*Org Export Dispatcher*"))
6515 (setq cursor-type nil
6516 header-line-format "Use SPC, DEL, C-n or C-p to navigate.")
6517 ;; Make sure that invisible cursor will not highlight square
6519 (set-syntax-table (copy-syntax-table))
6520 (modify-syntax-entry ?\[ "w"))
6521 ;; At this point, the buffer containing the menu exists and is
6522 ;; visible in the current window. So, refresh it.
6523 (with-current-buffer "*Org Export Dispatcher*"
6524 ;; Refresh help. Maintain display continuity by re-visiting
6525 ;; previous window position.
6526 (let ((pos (window-start)))
6529 (set-window-start nil pos)))
6530 (org-fit-window-to-buffer)
6531 (org-export--dispatch-action
6532 standard-prompt allowed-keys entries options first-key expertp))))
6534 (defun org-export--dispatch-action
6535 (prompt allowed-keys entries options first-key expertp)
6536 "Read a character from command input and act accordingly.
6538 PROMPT is the displayed prompt, as a string. ALLOWED-KEYS is
6539 a list of characters available at a given step in the process.
6540 ENTRIES is a list of menu entries. OPTIONS, FIRST-KEY and
6541 EXPERTP are the same as defined in `org-export--dispatch-ui',
6544 Toggle export options when required. Otherwise, return value is
6545 a list with action as CAR and a list of interactive export
6548 ;; Scrolling: when in non-expert mode, act on motion keys (C-n,
6550 (while (and (setq key (read-char-exclusive prompt))
6552 (memq key '(14 16 ?\s ?\d)))
6554 (14 (if (not (pos-visible-in-window-p (point-max)))
6555 (ignore-errors (scroll-up 1))
6556 (message "End of buffer")
6558 (16 (if (not (pos-visible-in-window-p (point-min)))
6559 (ignore-errors (scroll-down 1))
6560 (message "Beginning of buffer")
6562 (?\s (if (not (pos-visible-in-window-p (point-max)))
6564 (message "End of buffer")
6566 (?\d (if (not (pos-visible-in-window-p (point-min)))
6568 (message "Beginning of buffer")
6571 ;; Ignore undefined associations.
6572 ((not (memq key allowed-keys))
6574 (unless expertp (message "Invalid key") (sit-for 1))
6575 (org-export--dispatch-ui options first-key expertp))
6576 ;; q key at first level aborts export. At second level, cancel
6577 ;; first key instead.
6578 ((eq key ?q) (if (not first-key) (error "Export aborted")
6579 (org-export--dispatch-ui options nil expertp)))
6580 ;; Help key: Switch back to standard interface if expert UI was
6582 ((eq key ??) (org-export--dispatch-ui options first-key nil))
6583 ;; Send request for template insertion along with export scope.
6584 ((eq key ?#) (cons 'template (memq 'subtree options)))
6585 ;; Switch to asynchronous export stack.
6586 ((eq key ?&) '(stack))
6587 ;; Toggle options: C-b (2) C-v (22) C-s (19) C-f (6) C-a (1).
6588 ((memq key '(2 22 19 6 1))
6589 (org-export--dispatch-ui
6590 (let ((option (cl-case key (2 'body) (22 'visible) (19 'subtree)
6591 (6 'force) (1 'async))))
6592 (if (memq option options) (remq option options)
6593 (cons option options)))
6595 ;; Action selected: Send key and options back to
6596 ;; `org-export-dispatch'.
6597 ((or first-key (functionp (nth 2 (assq key entries))))
6599 ((not first-key) (nth 2 (assq key entries)))
6600 ;; Publishing actions are hard-coded. Send a special
6601 ;; signal to `org-export-dispatch'.
6604 (?f 'publish-current-file)
6605 (?p 'publish-current-project)
6606 (?x 'publish-choose-project)
6608 ;; Return first action associated to FIRST-KEY + KEY
6609 ;; path. Indeed, derived backends can share the same
6612 (dolist (entry (member (assq first-key entries) entries))
6613 (let ((match (assq key (nth 2 entry))))
6614 (when match (throw 'found (nth 2 match))))))))
6616 ;; Otherwise, enter sub-menu.
6617 (t (org-export--dispatch-ui options key expertp)))))
6624 ;; generated-autoload-file: "org-loaddefs.el"