1 ;;; ox.el --- Export Framework for Org Mode -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2016 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-publish
"ox-publish" (project &optional force async
))
81 (declare-function org-publish-all
"ox-publish" (&optional force async
))
82 (declare-function org-publish-current-file
"ox-publish" (&optional force async
))
83 (declare-function org-publish-current-project
"ox-publish" (&optional force async
))
84 (declare-function org-src-coderef-format
"org-src" (&optional element
))
85 (declare-function org-src-coderef-regexp
"org-src" (fmt &optional label
))
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
)
999 (defun org-export-get-backend (name)
1000 "Return export back-end named after NAME.
1001 NAME is a symbol. Return nil if no such back-end is found."
1003 (dolist (b org-export-registered-backends
)
1004 (when (eq (org-export-backend-name b
) name
)
1005 (throw 'found b
)))))
1007 (defun org-export-register-backend (backend)
1008 "Register BACKEND as a known export back-end.
1009 BACKEND is a structure with `org-export-backend' type."
1010 ;; Refuse to register an unnamed back-end.
1011 (unless (org-export-backend-name backend
)
1012 (error "Cannot register a unnamed export back-end"))
1013 ;; Refuse to register a back-end with an unknown parent.
1014 (let ((parent (org-export-backend-parent backend
)))
1015 (when (and parent
(not (org-export-get-backend parent
)))
1016 (error "Cannot use unknown \"%s\" back-end as a parent" parent
)))
1017 ;; If a back-end with the same name as BACKEND is already
1018 ;; registered, replace it with BACKEND. Otherwise, simply add
1019 ;; BACKEND to the list of registered back-ends.
1020 (let ((old (org-export-get-backend (org-export-backend-name backend
))))
1021 (if old
(setcar (memq old org-export-registered-backends
) backend
)
1022 (push backend org-export-registered-backends
))))
1024 (defun org-export-barf-if-invalid-backend (backend)
1025 "Signal an error if BACKEND isn't defined."
1026 (unless (org-export-backend-p backend
)
1027 (error "Unknown \"%s\" back-end: Aborting export" backend
)))
1029 (defun org-export-derived-backend-p (backend &rest backends
)
1030 "Non-nil if BACKEND is derived from one of BACKENDS.
1031 BACKEND is an export back-end, as returned by, e.g.,
1032 `org-export-create-backend', or a symbol referring to
1033 a registered back-end. BACKENDS is constituted of symbols."
1034 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1037 (while (org-export-backend-parent backend
)
1038 (when (memq (org-export-backend-name backend
) backends
)
1041 (org-export-get-backend (org-export-backend-parent backend
))))
1042 (memq (org-export-backend-name backend
) backends
))))
1044 (defun org-export-get-all-transcoders (backend)
1045 "Return full translation table for BACKEND.
1047 BACKEND is an export back-end, as return by, e.g,,
1048 `org-export-create-backend'. Return value is an alist where
1049 keys are element or object types, as symbols, and values are
1052 Unlike to `org-export-backend-transcoders', this function
1053 also returns transcoders inherited from parent back-ends,
1055 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1057 (let ((transcoders (org-export-backend-transcoders backend
))
1059 (while (setq parent
(org-export-backend-parent backend
))
1060 (setq backend
(org-export-get-backend parent
))
1062 (append transcoders
(org-export-backend-transcoders backend
))))
1065 (defun org-export-get-all-options (backend)
1066 "Return export options for BACKEND.
1068 BACKEND is an export back-end, as return by, e.g,,
1069 `org-export-create-backend'. See `org-export-options-alist'
1070 for the shape of the return value.
1072 Unlike to `org-export-backend-options', this function also
1073 returns options inherited from parent back-ends, if any."
1074 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1076 (let ((options (org-export-backend-options backend
))
1078 (while (setq parent
(org-export-backend-parent backend
))
1079 (setq backend
(org-export-get-backend parent
))
1080 (setq options
(append options
(org-export-backend-options backend
))))
1083 (defun org-export-get-all-filters (backend)
1084 "Return complete list of filters for BACKEND.
1086 BACKEND is an export back-end, as return by, e.g,,
1087 `org-export-create-backend'. Return value is an alist where
1088 keys are symbols and values lists of functions.
1090 Unlike to `org-export-backend-filters', this function also
1091 returns filters inherited from parent back-ends, if any."
1092 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
1094 (let ((filters (org-export-backend-filters backend
))
1096 (while (setq parent
(org-export-backend-parent backend
))
1097 (setq backend
(org-export-get-backend parent
))
1098 (setq filters
(append filters
(org-export-backend-filters backend
))))
1101 (defun org-export-define-backend (backend transcoders
&rest body
)
1102 "Define a new back-end BACKEND.
1104 TRANSCODERS is an alist between object or element types and
1105 functions handling them.
1107 These functions should return a string without any trailing
1108 space, or nil. They must accept three arguments: the object or
1109 element itself, its contents or nil when it isn't recursive and
1110 the property list used as a communication channel.
1112 Contents, when not nil, are stripped from any global indentation
1113 \(although the relative one is preserved). They also always end
1114 with a single newline character.
1116 If, for a given type, no function is found, that element or
1117 object type will simply be ignored, along with any blank line or
1118 white space at its end. The same will happen if the function
1119 returns the nil value. If that function returns the empty
1120 string, the type will be ignored, but the blank lines or white
1121 spaces will be kept.
1123 In addition to element and object types, one function can be
1124 associated to the `template' (or `inner-template') symbol and
1125 another one to the `plain-text' symbol.
1127 The former returns the final transcoded string, and can be used
1128 to add a preamble and a postamble to document's body. It must
1129 accept two arguments: the transcoded string and the property list
1130 containing export options. A function associated to `template'
1131 will not be applied if export has option \"body-only\".
1132 A function associated to `inner-template' is always applied.
1134 The latter, when defined, is to be called on every text not
1135 recognized as an element or an object. It must accept two
1136 arguments: the text string and the information channel. It is an
1137 appropriate place to protect special chars relative to the
1140 BODY can start with pre-defined keyword arguments. The following
1141 keywords are understood:
1145 Alist between filters and function, or list of functions,
1146 specific to the back-end. See `org-export-filters-alist' for
1147 a list of all allowed filters. Filters defined here
1148 shouldn't make a back-end test, as it may prevent back-ends
1149 derived from this one to behave properly.
1153 Menu entry for the export dispatcher. It should be a list
1156 \\='(KEY DESCRIPTION-OR-ORDINAL ACTION-OR-MENU)
1160 KEY is a free character selecting the back-end.
1162 DESCRIPTION-OR-ORDINAL is either a string or a number.
1164 If it is a string, is will be used to name the back-end in
1165 its menu entry. If it is a number, the following menu will
1166 be displayed as a sub-menu of the back-end with the same
1167 KEY. Also, the number will be used to determine in which
1168 order such sub-menus will appear (lowest first).
1170 ACTION-OR-MENU is either a function or an alist.
1172 If it is an action, it will be called with four
1173 arguments (booleans): ASYNC, SUBTREEP, VISIBLE-ONLY and
1174 BODY-ONLY. See `org-export-as' for further explanations on
1177 If it is an alist, associations should follow the
1180 \\='(KEY DESCRIPTION ACTION)
1182 where KEY, DESCRIPTION and ACTION are described above.
1184 Valid values include:
1186 \\='(?m \"My Special Back-end\" my-special-export-function)
1190 \\='(?l \"Export to LaTeX\"
1191 (?p \"As PDF file\" org-latex-export-to-pdf)
1192 (?o \"As PDF file and open\"
1194 (if a (org-latex-export-to-pdf t s v b)
1196 (org-latex-export-to-pdf nil s v b)))))))
1198 or the following, which will be added to the previous
1202 ((?B \"As TEX buffer (Beamer)\" org-beamer-export-as-latex)
1203 (?P \"As PDF file (Beamer)\" org-beamer-export-to-pdf)))
1207 Alist between back-end specific properties introduced in
1208 communication channel and how their value are acquired. See
1209 `org-export-options-alist' for more information about
1210 structure of the values."
1211 (declare (indent 1))
1212 (let (filters menu-entry options
)
1213 (while (keywordp (car body
))
1214 (let ((keyword (pop body
)))
1216 (:filters-alist
(setq filters
(pop body
)))
1217 (:menu-entry
(setq menu-entry
(pop body
)))
1218 (:options-alist
(setq options
(pop body
)))
1219 (_ (error "Unknown keyword: %s" keyword
)))))
1220 (org-export-register-backend
1221 (org-export-create-backend :name backend
1222 :transcoders transcoders
1225 :menu menu-entry
))))
1227 (defun org-export-define-derived-backend (child parent
&rest body
)
1228 "Create a new back-end as a variant of an existing one.
1230 CHILD is the name of the derived back-end. PARENT is the name of
1231 the parent back-end.
1233 BODY can start with pre-defined keyword arguments. The following
1234 keywords are understood:
1238 Alist of filters that will overwrite or complete filters
1239 defined in PARENT back-end. See `org-export-filters-alist'
1240 for a list of allowed filters.
1244 Menu entry for the export dispatcher. See
1245 `org-export-define-backend' for more information about the
1250 Alist of back-end specific properties that will overwrite or
1251 complete those defined in PARENT back-end. Refer to
1252 `org-export-options-alist' for more information about
1253 structure of the values.
1257 Alist of element and object types and transcoders that will
1258 overwrite or complete transcode table from PARENT back-end.
1259 Refer to `org-export-define-backend' for detailed information
1262 As an example, here is how one could define \"my-latex\" back-end
1263 as a variant of `latex' back-end with a custom template function:
1265 (org-export-define-derived-backend \\='my-latex \\='latex
1266 :translate-alist \\='((template . my-latex-template-fun)))
1268 The back-end could then be called with, for example:
1270 (org-export-to-buffer \\='my-latex \"*Test my-latex*\")"
1271 (declare (indent 2))
1272 (let (filters menu-entry options transcoders
)
1273 (while (keywordp (car body
))
1274 (let ((keyword (pop body
)))
1276 (:filters-alist
(setq filters
(pop body
)))
1277 (:menu-entry
(setq menu-entry
(pop body
)))
1278 (:options-alist
(setq options
(pop body
)))
1279 (:translate-alist
(setq transcoders
(pop body
)))
1280 (_ (error "Unknown keyword: %s" keyword
)))))
1281 (org-export-register-backend
1282 (org-export-create-backend :name child
1284 :transcoders transcoders
1287 :menu menu-entry
))))
1291 ;;; The Communication Channel
1293 ;; During export process, every function has access to a number of
1294 ;; properties. They are of two types:
1296 ;; 1. Environment options are collected once at the very beginning of
1297 ;; the process, out of the original buffer and configuration.
1298 ;; Collecting them is handled by `org-export-get-environment'
1301 ;; Most environment options are defined through the
1302 ;; `org-export-options-alist' variable.
1304 ;; 2. Tree properties are extracted directly from the parsed tree,
1305 ;; just before export, by `org-export--collect-tree-properties'.
1307 ;;;; Environment Options
1309 ;; Environment options encompass all parameters defined outside the
1310 ;; scope of the parsed data. They come from five sources, in
1311 ;; increasing precedence order:
1313 ;; - Global variables,
1314 ;; - Buffer's attributes,
1315 ;; - Options keyword symbols,
1316 ;; - Buffer keywords,
1317 ;; - Subtree properties.
1319 ;; The central internal function with regards to environment options
1320 ;; is `org-export-get-environment'. It updates global variables with
1321 ;; "#+BIND:" keywords, then retrieve and prioritize properties from
1322 ;; the different sources.
1324 ;; The internal functions doing the retrieval are:
1325 ;; `org-export--get-global-options',
1326 ;; `org-export--get-buffer-attributes',
1327 ;; `org-export--parse-option-keyword',
1328 ;; `org-export--get-subtree-options' and
1329 ;; `org-export--get-inbuffer-options'
1331 ;; Also, `org-export--list-bound-variables' collects bound variables
1332 ;; along with their value in order to set them as buffer local
1333 ;; variables later in the process.
1335 (defun org-export-get-environment (&optional backend subtreep ext-plist
)
1336 "Collect export options from the current buffer.
1338 Optional argument BACKEND is an export back-end, as returned by
1339 `org-export-create-backend'.
1341 When optional argument SUBTREEP is non-nil, assume the export is
1342 done against the current sub-tree.
1344 Third optional argument EXT-PLIST is a property list with
1345 external parameters overriding Org default settings, but still
1346 inferior to file-local settings."
1347 ;; First install #+BIND variables since these must be set before
1348 ;; global options are read.
1349 (dolist (pair (org-export--list-bound-variables))
1350 (set (make-local-variable (car pair
)) (nth 1 pair
)))
1351 ;; Get and prioritize export options...
1353 ;; ... from global variables...
1354 (org-export--get-global-options backend
)
1355 ;; ... from an external property list...
1357 ;; ... from in-buffer settings...
1358 (org-export--get-inbuffer-options backend
)
1359 ;; ... and from subtree, when appropriate.
1360 (and subtreep
(org-export--get-subtree-options backend
))))
1362 (defun org-export--parse-option-keyword (options &optional backend
)
1363 "Parse an OPTIONS line and return values as a plist.
1364 Optional argument BACKEND is an export back-end, as returned by,
1365 e.g., `org-export-create-backend'. It specifies which back-end
1366 specific items to read, if any."
1369 (while (string-match "\\(.+?\\):\\((.*?)\\|\\S-*\\)[ \t]*" options s
)
1370 (setq s
(match-end 0))
1371 (push (cons (match-string 1 options
)
1372 (read (match-string 2 options
)))
1375 ;; Priority is given to back-end specific options.
1376 (all (append (and backend
(org-export-get-all-options backend
))
1377 org-export-options-alist
))
1380 (dolist (entry all plist
)
1381 (let ((item (nth 2 entry
)))
1383 (let ((v (assoc-string item line t
)))
1384 (when v
(setq plist
(plist-put plist
(car entry
) (cdr v
)))))))))))
1386 (defun org-export--get-subtree-options (&optional backend
)
1387 "Get export options in subtree at point.
1388 Optional argument BACKEND is an export back-end, as returned by,
1389 e.g., `org-export-create-backend'. It specifies back-end used
1390 for export. Return options as a plist."
1391 ;; For each buffer keyword, create a headline property setting the
1392 ;; same property in communication channel. The name for the
1393 ;; property is the keyword with "EXPORT_" appended to it.
1394 (org-with-wide-buffer
1395 ;; Make sure point is at a heading.
1396 (if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t
))
1398 ;; EXPORT_OPTIONS are parsed in a non-standard way. Take
1399 ;; care of them right from the start.
1400 (let ((o (org-entry-get (point) "EXPORT_OPTIONS" 'selective
)))
1401 (and o
(org-export--parse-option-keyword o backend
))))
1402 ;; Take care of EXPORT_TITLE. If it isn't defined, use
1403 ;; headline's title (with no todo keyword, priority cookie or
1404 ;; tag) as its fallback value.
1407 (or (org-entry-get (point) "EXPORT_TITLE" 'selective
)
1408 (let ((case-fold-search nil
))
1409 (looking-at org-complex-heading-regexp
)
1410 (match-string-no-properties 4))))))
1411 ;; Look for both general keywords and back-end specific
1412 ;; options, with priority given to the latter.
1413 (options (append (and backend
(org-export-get-all-options backend
))
1414 org-export-options-alist
)))
1415 ;; Handle other keywords. Then return PLIST.
1416 (dolist (option options plist
)
1417 (let ((property (car option
))
1418 (keyword (nth 1 option
)))
1421 (or (cdr (assoc keyword cache
))
1422 (let ((v (org-entry-get (point)
1423 (concat "EXPORT_" keyword
)
1425 (push (cons keyword v
) cache
) v
))))
1430 (cl-case (nth 4 option
)
1432 (org-element-parse-secondary-string
1433 value
(org-element-restriction 'keyword
)))
1434 (split (org-split-string value
))
1435 (t value
))))))))))))
1437 (defun org-export--get-inbuffer-options (&optional backend
)
1438 "Return current buffer export options, as a plist.
1440 Optional argument BACKEND, when non-nil, is an export back-end,
1441 as returned by, e.g., `org-export-create-backend'. It specifies
1442 which back-end specific options should also be read in the
1445 Assume buffer is in Org mode. Narrowing, if any, is ignored."
1446 (let* ((case-fold-search t
)
1448 ;; Priority is given to back-end specific options.
1449 (and backend
(org-export-get-all-options backend
))
1450 org-export-options-alist
))
1451 (regexp (format "^[ \t]*#\\+%s:"
1452 (regexp-opt (nconc (delq nil
(mapcar #'cadr options
))
1453 org-export-special-keywords
))))
1455 (letrec ((find-properties
1457 ;; Return all properties associated to KEYWORD.
1459 (dolist (option options properties
)
1460 (when (equal (nth 1 option
) keyword
)
1461 (cl-pushnew (car option
) properties
))))))
1463 (lambda (&optional files
)
1464 ;; Recursively read keywords in buffer. FILES is
1465 ;; a list of files read so far. PLIST is the current
1466 ;; property list obtained.
1467 (org-with-wide-buffer
1468 (goto-char (point-min))
1469 (while (re-search-forward regexp nil t
)
1470 (let ((element (org-element-at-point)))
1471 (when (eq (org-element-type element
) 'keyword
)
1472 (let ((key (org-element-property :key element
))
1473 (val (org-element-property :value element
)))
1475 ;; Options in `org-export-special-keywords'.
1476 ((equal key
"SETUPFILE")
1479 (org-unbracket-string "\"" "\"" (org-trim val
)))))
1480 ;; Avoid circular dependencies.
1481 (unless (member file files
)
1483 (setq default-directory
1484 (file-name-directory file
))
1485 (insert (org-file-contents file
'noerror
))
1486 (let ((org-inhibit-startup t
)) (org-mode))
1487 (funcall get-options
(cons file files
))))))
1488 ((equal key
"OPTIONS")
1492 (org-export--parse-option-keyword
1494 ((equal key
"FILETAGS")
1501 (org-split-string val
":")
1502 (plist-get plist
:filetags
)))))))
1504 ;; Options in `org-export-options-alist'.
1505 (dolist (property (funcall find-properties key
))
1510 ;; Handle value depending on specified
1512 (cl-case (nth 4 (assq property options
))
1514 (unless (memq property to-parse
)
1515 (push property to-parse
))
1516 ;; Even if `parse' implies `space'
1517 ;; behavior, we separate line with
1518 ;; "\n" so as to preserve
1519 ;; line-breaks. However, empty
1520 ;; lines are forbidden since `parse'
1521 ;; doesn't allow more than one
1523 (let ((old (plist-get plist property
)))
1524 (cond ((not (org-string-nw-p val
)) old
)
1525 (old (concat old
"\n" val
))
1528 (if (not (plist-get plist property
))
1530 (concat (plist-get plist property
)
1535 (concat (plist-get plist property
)
1538 (split `(,@(plist-get plist property
)
1539 ,@(org-split-string val
)))
1542 (if (not (plist-member plist property
)) val
1543 (plist-get plist property
)))))))))))))))))
1544 ;; Read options in the current buffer and return value.
1545 (funcall get-options
(and buffer-file-name
(list buffer-file-name
)))
1546 ;; Parse properties in TO-PARSE. Remove newline characters not
1547 ;; involved in line breaks to simulate `space' behavior.
1548 ;; Finally return options.
1549 (dolist (p to-parse plist
)
1550 (let ((value (org-element-parse-secondary-string
1552 (org-element-restriction 'keyword
))))
1553 (org-element-map value
'plain-text
1555 (org-element-set-element
1556 s
(replace-regexp-in-string "\n" " " s
))))
1557 (setq plist
(plist-put plist p value
)))))))
1559 (defun org-export--get-export-attributes
1560 (&optional backend subtreep visible-only body-only
)
1561 "Return properties related to export process, as a plist.
1562 Optional arguments BACKEND, SUBTREEP, VISIBLE-ONLY and BODY-ONLY
1563 are like the arguments with the same names of function
1565 (list :export-options
(delq nil
1566 (list (and subtreep
'subtree
)
1567 (and visible-only
'visible-only
)
1568 (and body-only
'body-only
)))
1570 :translate-alist
(org-export-get-all-transcoders backend
)
1571 :exported-data
(make-hash-table :test
#'eq
:size
4001)))
1573 (defun org-export--get-buffer-attributes ()
1574 "Return properties related to buffer attributes, as a plist."
1575 (list :input-buffer
(buffer-name (buffer-base-buffer))
1576 :input-file
(buffer-file-name (buffer-base-buffer))))
1578 (defun org-export--get-global-options (&optional backend
)
1579 "Return global export options as a plist.
1580 Optional argument BACKEND, if non-nil, is an export back-end, as
1581 returned by, e.g., `org-export-create-backend'. It specifies
1582 which back-end specific export options should also be read in the
1585 ;; Priority is given to back-end specific options.
1586 (all (append (and backend
(org-export-get-all-options backend
))
1587 org-export-options-alist
)))
1588 (dolist (cell all plist
)
1589 (let ((prop (car cell
)))
1590 (unless (plist-member plist prop
)
1595 ;; Evaluate default value provided.
1596 (let ((value (eval (nth 3 cell
))))
1597 (if (eq (nth 4 cell
) 'parse
)
1598 (org-element-parse-secondary-string
1599 value
(org-element-restriction 'keyword
))
1602 (defun org-export--list-bound-variables ()
1603 "Return variables bound from BIND keywords in current buffer.
1604 Also look for BIND keywords in setup files. The return value is
1605 an alist where associations are (VARIABLE-NAME VALUE)."
1606 (when org-export-allow-bind-keywords
1607 (letrec ((collect-bind
1608 (lambda (files alist
)
1609 ;; Return an alist between variable names and their
1610 ;; value. FILES is a list of setup files names read
1611 ;; so far, used to avoid circular dependencies. ALIST
1612 ;; is the alist collected so far.
1613 (let ((case-fold-search t
))
1614 (org-with-wide-buffer
1615 (goto-char (point-min))
1616 (while (re-search-forward
1617 "^[ \t]*#\\+\\(BIND\\|SETUPFILE\\):" nil t
)
1618 (let ((element (org-element-at-point)))
1619 (when (eq (org-element-type element
) 'keyword
)
1620 (let ((val (org-element-property :value element
)))
1621 (if (equal (org-element-property :key element
)
1623 (push (read (format "(%s)" val
)) alist
)
1624 ;; Enter setup file.
1625 (let ((file (expand-file-name
1626 (org-unbracket-string "\"" "\"" val
))))
1627 (unless (member file files
)
1629 (setq default-directory
1630 (file-name-directory file
))
1631 (let ((org-inhibit-startup t
)) (org-mode))
1632 (insert (org-file-contents file
'noerror
))
1634 (funcall collect-bind
1638 ;; Return value in appropriate order of appearance.
1639 (nreverse (funcall collect-bind nil nil
)))))
1641 ;; defsubst org-export-get-parent must be defined before first use,
1642 ;; was originally defined in the topology section
1644 (defsubst org-export-get-parent
(blob)
1645 "Return BLOB parent or nil.
1646 BLOB is the element or object considered."
1647 (org-element-property :parent blob
))
1649 ;;;; Tree Properties
1651 ;; Tree properties are information extracted from parse tree. They
1652 ;; are initialized at the beginning of the transcoding process by
1653 ;; `org-export--collect-tree-properties'.
1655 ;; Dedicated functions focus on computing the value of specific tree
1656 ;; properties during initialization. Thus,
1657 ;; `org-export--populate-ignore-list' lists elements and objects that
1658 ;; should be skipped during export, `org-export--get-min-level' gets
1659 ;; the minimal exportable level, used as a basis to compute relative
1660 ;; level for headlines. Eventually
1661 ;; `org-export--collect-headline-numbering' builds an alist between
1662 ;; headlines and their numbering.
1664 (defun org-export--collect-tree-properties (data info
)
1665 "Extract tree properties from parse tree.
1667 DATA is the parse tree from which information is retrieved. INFO
1668 is a list holding export options.
1670 Following tree properties are set or updated:
1672 `:headline-offset' Offset between true level of headlines and
1673 local level. An offset of -1 means a headline
1674 of level 2 should be considered as a level
1675 1 headline in the context.
1677 `:headline-numbering' Alist of all headlines as key and the
1678 associated numbering as value.
1680 `:id-alist' Alist of all ID references as key and associated file
1683 Return updated plist."
1684 ;; Install the parse tree in the communication channel.
1685 (setq info
(plist-put info
:parse-tree data
))
1686 ;; Compute `:headline-offset' in order to be able to use
1687 ;; `org-export-get-relative-level'.
1691 (- 1 (org-export--get-min-level data info
))))
1692 ;; From now on, properties order doesn't matter: get the rest of the
1696 (list :headline-numbering
(org-export--collect-headline-numbering data info
)
1698 (org-element-map data
'link
1700 (and (string= (org-element-property :type l
) "id")
1701 (let* ((id (org-element-property :path l
))
1702 (file (car (org-id-find id
))))
1703 (and file
(cons id
(file-relative-name file
))))))))))
1705 (defun org-export--get-min-level (data options
)
1706 "Return minimum exportable headline's level in DATA.
1707 DATA is parsed tree as returned by `org-element-parse-buffer'.
1708 OPTIONS is a plist holding export options."
1710 (let ((min-level 10000))
1711 (dolist (datum (org-element-contents data
))
1712 (when (and (eq (org-element-type datum
) 'headline
)
1713 (not (org-element-property :footnote-section-p datum
))
1714 (not (memq datum
(plist-get options
:ignore-list
))))
1715 (setq min-level
(min (org-element-property :level datum
) min-level
))
1716 (when (= min-level
1) (throw 'exit
1))))
1717 ;; If no headline was found, for the sake of consistency, set
1718 ;; minimum level to 1 nonetheless.
1719 (if (= min-level
10000) 1 min-level
))))
1721 (defun org-export--collect-headline-numbering (data options
)
1722 "Return numbering of all exportable, numbered headlines in a parse tree.
1724 DATA is the parse tree. OPTIONS is the plist holding export
1727 Return an alist whose key is a headline and value is its
1728 associated numbering \(in the shape of a list of numbers) or nil
1729 for a footnotes section."
1730 (let ((numbering (make-vector org-export-max-depth
0)))
1731 (org-element-map data
'headline
1733 (when (and (org-export-numbered-headline-p headline options
)
1734 (not (org-element-property :footnote-section-p headline
)))
1735 (let ((relative-level
1736 (1- (org-export-get-relative-level headline options
))))
1740 for n across numbering
1741 for idx from
0 to org-export-max-depth
1742 when
(< idx relative-level
) collect n
1743 when
(= idx relative-level
) collect
(aset numbering idx
(1+ n
))
1744 when
(> idx relative-level
) do
(aset numbering idx
0))))))
1747 (defun org-export--selected-trees (data info
)
1748 "List headlines and inlinetasks with a select tag in their tree.
1749 DATA is parsed data as returned by `org-element-parse-buffer'.
1750 INFO is a plist holding export options."
1751 (let ((select (plist-get info
:select-tags
)))
1752 (if (cl-some (lambda (tag) (member tag select
)) (plist-get info
:filetags
))
1753 ;; If FILETAGS contains a select tag, every headline or
1754 ;; inlinetask is returned.
1755 (org-element-map data
'(headline inlinetask
) #'identity
)
1756 (letrec ((selected-trees nil
)
1758 (lambda (data genealogy
)
1759 (let ((type (org-element-type data
)))
1761 ((memq type
'(headline inlinetask
))
1762 (let ((tags (org-element-property :tags data
)))
1763 (if (cl-some (lambda (tag) (member tag select
)) tags
)
1764 ;; When a select tag is found, mark full
1765 ;; genealogy and every headline within the
1766 ;; tree as acceptable.
1767 (setq selected-trees
1770 (org-element-map data
'(headline inlinetask
)
1773 ;; If at a headline, continue searching in
1774 ;; tree, recursively.
1775 (when (eq type
'headline
)
1776 (dolist (el (org-element-contents data
))
1777 (funcall walk-data el
(cons data genealogy
)))))))
1778 ((or (eq type
'org-data
)
1779 (memq type org-element-greater-elements
))
1780 (dolist (el (org-element-contents data
))
1781 (funcall walk-data el genealogy
))))))))
1782 (funcall walk-data data nil
)
1785 (defun org-export--skip-p (blob options selected
)
1786 "Non-nil when element or object BLOB should be skipped during export.
1787 OPTIONS is the plist holding export options. SELECTED, when
1788 non-nil, is a list of headlines or inlinetasks belonging to
1789 a tree with a select tag."
1790 (cl-case (org-element-type blob
)
1791 (clock (not (plist-get options
:with-clocks
)))
1793 (let ((with-drawers-p (plist-get options
:with-drawers
)))
1794 (or (not with-drawers-p
)
1795 (and (consp with-drawers-p
)
1796 ;; If `:with-drawers' value starts with `not', ignore
1797 ;; every drawer whose name belong to that list.
1798 ;; Otherwise, ignore drawers whose name isn't in that
1800 (let ((name (org-element-property :drawer-name blob
)))
1801 (if (eq (car with-drawers-p
) 'not
)
1802 (member-ignore-case name
(cdr with-drawers-p
))
1803 (not (member-ignore-case name with-drawers-p
))))))))
1804 (fixed-width (not (plist-get options
:with-fixed-width
)))
1805 ((footnote-definition footnote-reference
)
1806 (not (plist-get options
:with-footnotes
)))
1807 ((headline inlinetask
)
1808 (let ((with-tasks (plist-get options
:with-tasks
))
1809 (todo (org-element-property :todo-keyword blob
))
1810 (todo-type (org-element-property :todo-type blob
))
1811 (archived (plist-get options
:with-archived-trees
))
1812 (tags (org-export-get-tags blob options nil t
)))
1814 (and (eq (org-element-type blob
) 'inlinetask
)
1815 (not (plist-get options
:with-inlinetasks
)))
1816 ;; Ignore subtrees with an exclude tag.
1817 (cl-loop for k in
(plist-get options
:exclude-tags
)
1818 thereis
(member k tags
))
1819 ;; When a select tag is present in the buffer, ignore any tree
1821 (and selected
(not (memq blob selected
)))
1822 ;; Ignore commented sub-trees.
1823 (org-element-property :commentedp blob
)
1824 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
1825 (and (not archived
) (org-element-property :archivedp blob
))
1826 ;; Ignore tasks, if specified by `:with-tasks' property.
1828 (or (not with-tasks
)
1829 (and (memq with-tasks
'(todo done
))
1830 (not (eq todo-type with-tasks
)))
1831 (and (consp with-tasks
) (not (member todo with-tasks
))))))))
1832 ((latex-environment latex-fragment
) (not (plist-get options
:with-latex
)))
1834 (let ((properties-set (plist-get options
:with-properties
)))
1835 (cond ((null properties-set
) t
)
1836 ((consp properties-set
)
1837 (not (member-ignore-case (org-element-property :key blob
)
1838 properties-set
))))))
1839 (planning (not (plist-get options
:with-planning
)))
1840 (property-drawer (not (plist-get options
:with-properties
)))
1841 (statistics-cookie (not (plist-get options
:with-statistics-cookies
)))
1842 (table (not (plist-get options
:with-tables
)))
1844 (and (org-export-table-has-special-column-p
1845 (org-export-get-parent-table blob
))
1846 (org-export-first-sibling-p blob options
)))
1847 (table-row (org-export-table-row-is-special-p blob options
))
1849 ;; `:with-timestamps' only applies to isolated timestamps
1850 ;; objects, i.e. timestamp objects in a paragraph containing only
1851 ;; timestamps and whitespaces.
1852 (when (let ((parent (org-export-get-parent-element blob
)))
1853 (and (memq (org-element-type parent
) '(paragraph verse-block
))
1854 (not (org-element-map parent
1856 (remq 'timestamp org-element-all-objects
))
1858 (or (not (stringp obj
)) (org-string-nw-p obj
)))
1860 (cl-case (plist-get options
:with-timestamps
)
1863 (not (memq (org-element-property :type blob
) '(active active-range
))))
1865 (not (memq (org-element-property :type blob
)
1866 '(inactive inactive-range
)))))))))
1871 ;; `org-export-data' reads a parse tree (obtained with, i.e.
1872 ;; `org-element-parse-buffer') and transcodes it into a specified
1873 ;; back-end output. It takes care of filtering out elements or
1874 ;; objects according to export options and organizing the output blank
1875 ;; lines and white space are preserved. The function memoizes its
1876 ;; results, so it is cheap to call it within transcoders.
1878 ;; It is possible to modify locally the back-end used by
1879 ;; `org-export-data' or even use a temporary back-end by using
1880 ;; `org-export-data-with-backend'.
1882 ;; `org-export-transcoder' is an accessor returning appropriate
1883 ;; translator function for a given element or object.
1885 (defun org-export-transcoder (blob info
)
1886 "Return appropriate transcoder for BLOB.
1887 INFO is a plist containing export directives."
1888 (let ((type (org-element-type blob
)))
1889 ;; Return contents only for complete parse trees.
1890 (if (eq type
'org-data
) (lambda (_datum contents _info
) contents
)
1891 (let ((transcoder (cdr (assq type
(plist-get info
:translate-alist
)))))
1892 (and (functionp transcoder
) transcoder
)))))
1894 (defun org-export-data (data info
)
1895 "Convert DATA into current back-end format.
1897 DATA is a parse tree, an element or an object or a secondary
1898 string. INFO is a plist holding export options.
1901 (or (gethash data
(plist-get info
:exported-data
))
1902 ;; Handle broken links according to
1903 ;; `org-export-with-broken-links'.
1905 ((broken-link-handler
1907 `(condition-case err
1910 (pcase (plist-get info
:with-broken-links
)
1911 (`nil
(user-error "Unable to resolve link: %S" (nth 1 err
)))
1912 (`mark
(org-export-data
1913 (format "[BROKEN LINK: %s]" (nth 1 err
)) info
))
1915 (let* ((type (org-element-type data
))
1916 (parent (org-export-get-parent data
))
1919 ;; Ignored element/object.
1920 ((memq data
(plist-get info
:ignore-list
)) nil
)
1922 ((eq type
'plain-text
)
1923 (org-export-filter-apply-functions
1924 (plist-get info
:filter-plain-text
)
1925 (let ((transcoder (org-export-transcoder data info
)))
1926 (if transcoder
(funcall transcoder data info
) data
))
1928 ;; Secondary string.
1930 (mapconcat (lambda (obj) (org-export-data obj info
)) data
""))
1931 ;; Element/Object without contents or, as a special
1932 ;; case, headline with archive tag and archived trees
1933 ;; restricted to title only.
1934 ((or (not (org-element-contents data
))
1935 (and (eq type
'headline
)
1936 (eq (plist-get info
:with-archived-trees
) 'headline
)
1937 (org-element-property :archivedp data
)))
1938 (let ((transcoder (org-export-transcoder data info
)))
1939 (or (and (functionp transcoder
)
1940 (broken-link-handler
1941 (funcall transcoder data nil info
)))
1942 ;; Export snippets never return a nil value so
1943 ;; that white spaces following them are never
1945 (and (eq type
'export-snippet
) ""))))
1946 ;; Element/Object with contents.
1948 (let ((transcoder (org-export-transcoder data info
)))
1950 (let* ((greaterp (memq type org-element-greater-elements
))
1953 (memq type org-element-recursive-objects
)))
1956 (lambda (element) (org-export-data element info
))
1957 (org-element-contents
1958 (if (or greaterp objectp
) data
1959 ;; Elements directly containing
1960 ;; objects must have their indentation
1961 ;; normalized first.
1962 (org-element-normalize-contents
1964 ;; When normalizing contents of the
1965 ;; first paragraph in an item or
1966 ;; a footnote definition, ignore
1967 ;; first line's indentation: there is
1968 ;; none and it might be misleading.
1969 (when (eq type
'paragraph
)
1971 (eq (car (org-element-contents parent
))
1973 (memq (org-element-type parent
)
1974 '(footnote-definition item
)))))))
1976 (broken-link-handler
1977 (funcall transcoder data
1978 (if (not greaterp
) contents
1979 (org-element-normalize-string contents
))
1981 ;; Final result will be memoized before being returned.
1986 ((memq type
'(org-data plain-text nil
)) results
)
1987 ;; Append the same white space between elements or objects
1988 ;; as in the original buffer, and call appropriate filters.
1990 (org-export-filter-apply-functions
1991 (plist-get info
(intern (format ":filter-%s" type
)))
1992 (let ((blank (or (org-element-property :post-blank data
) 0)))
1993 (if (eq (org-element-class data parent
) 'object
)
1994 (concat results
(make-string blank ?\s
))
1995 (concat (org-element-normalize-string results
)
1996 (make-string blank ?
\n))))
1998 (plist-get info
:exported-data
))))))
2000 (defun org-export-data-with-backend (data backend info
)
2001 "Convert DATA into BACKEND format.
2003 DATA is an element, an object, a secondary string or a string.
2004 BACKEND is a symbol. INFO is a plist used as a communication
2007 Unlike to `org-export-with-backend', this function will
2008 recursively convert DATA using BACKEND translation table."
2009 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
2010 ;; Set-up a new communication channel with translations defined in
2011 ;; BACKEND as the translate table and a new hash table for
2016 (list :back-end backend
2017 :translate-alist
(org-export-get-all-transcoders backend
)
2018 ;; Size of the hash table is reduced since this
2019 ;; function will probably be used on small trees.
2020 :exported-data
(make-hash-table :test
'eq
:size
401)))))
2021 (prog1 (org-export-data data new-info
)
2022 ;; Preserve `:internal-references', as those do not depend on
2023 ;; the back-end used; we need to make sure that any new
2024 ;; reference when the temporary back-end was active gets through
2026 (plist-put info
:internal-references
2027 (plist-get new-info
:internal-references
)))))
2029 (defun org-export-expand (blob contents
&optional with-affiliated
)
2030 "Expand a parsed element or object to its original state.
2032 BLOB is either an element or an object. CONTENTS is its
2033 contents, as a string or nil.
2035 When optional argument WITH-AFFILIATED is non-nil, add affiliated
2036 keywords before output."
2037 (let ((type (org-element-type blob
)))
2038 (concat (and with-affiliated
2039 (eq (org-element-class blob
) 'element
)
2040 (org-element--interpret-affiliated-keywords blob
))
2041 (funcall (intern (format "org-element-%s-interpreter" type
))
2046 ;;; The Filter System
2048 ;; Filters allow end-users to tweak easily the transcoded output.
2049 ;; They are the functional counterpart of hooks, as every filter in
2050 ;; a set is applied to the return value of the previous one.
2052 ;; Every set is back-end agnostic. Although, a filter is always
2053 ;; called, in addition to the string it applies to, with the back-end
2054 ;; used as argument, so it's easy for the end-user to add back-end
2055 ;; specific filters in the set. The communication channel, as
2056 ;; a plist, is required as the third argument.
2058 ;; From the developer side, filters sets can be installed in the
2059 ;; process with the help of `org-export-define-backend', which
2060 ;; internally stores filters as an alist. Each association has a key
2061 ;; among the following symbols and a function or a list of functions
2064 ;; - `:filter-options' applies to the property list containing export
2065 ;; options. Unlike to other filters, functions in this list accept
2066 ;; two arguments instead of three: the property list containing
2067 ;; export options and the back-end. Users can set its value through
2068 ;; `org-export-filter-options-functions' variable.
2070 ;; - `:filter-parse-tree' applies directly to the complete parsed
2071 ;; tree. Users can set it through
2072 ;; `org-export-filter-parse-tree-functions' variable.
2074 ;; - `:filter-body' applies to the body of the output, before template
2075 ;; translator chimes in. Users can set it through
2076 ;; `org-export-filter-body-functions' variable.
2078 ;; - `:filter-final-output' applies to the final transcoded string.
2079 ;; Users can set it with `org-export-filter-final-output-functions'
2082 ;; - `:filter-plain-text' applies to any string not recognized as Org
2083 ;; syntax. `org-export-filter-plain-text-functions' allows users to
2086 ;; - `:filter-TYPE' applies on the string returned after an element or
2087 ;; object of type TYPE has been transcoded. A user can modify
2088 ;; `org-export-filter-TYPE-functions' to install these filters.
2090 ;; All filters sets are applied with
2091 ;; `org-export-filter-apply-functions' function. Filters in a set are
2092 ;; applied in a LIFO fashion. It allows developers to be sure that
2093 ;; their filters will be applied first.
2095 ;; Filters properties are installed in communication channel with
2096 ;; `org-export-install-filters' function.
2098 ;; Eventually, two hooks (`org-export-before-processing-hook' and
2099 ;; `org-export-before-parsing-hook') are run at the beginning of the
2100 ;; export process and just before parsing to allow for heavy structure
2106 (defvar org-export-before-processing-hook nil
2107 "Hook run at the beginning of the export process.
2109 This is run before include keywords and macros are expanded and
2110 Babel code blocks executed, on a copy of the original buffer
2111 being exported. Visibility and narrowing are preserved. Point
2112 is at the beginning of the buffer.
2114 Every function in this hook will be called with one argument: the
2115 back-end currently used, as a symbol.")
2117 (defvar org-export-before-parsing-hook nil
2118 "Hook run before parsing an export buffer.
2120 This is run after include keywords and macros have been expanded
2121 and Babel code blocks executed, on a copy of the original buffer
2122 being exported. Visibility and narrowing are preserved. Point
2123 is at the beginning of the buffer.
2125 Every function in this hook will be called with one argument: the
2126 back-end currently used, as a symbol.")
2129 ;;;; Special Filters
2131 (defvar org-export-filter-options-functions nil
2132 "List of functions applied to the export options.
2133 Each filter is called with two arguments: the export options, as
2134 a plist, and the back-end, as a symbol. It must return
2135 a property list containing export options.")
2137 (defvar org-export-filter-parse-tree-functions nil
2138 "List of functions applied to the parsed tree.
2139 Each filter is called with three arguments: the parse tree, as
2140 returned by `org-element-parse-buffer', the back-end, as
2141 a symbol, and the communication channel, as a plist. It must
2142 return the modified parse tree to transcode.")
2144 (defvar org-export-filter-plain-text-functions nil
2145 "List of functions applied to plain text.
2146 Each filter is called with three arguments: a string which
2147 contains no Org syntax, the back-end, as a symbol, and the
2148 communication channel, as a plist. It must return a string or
2151 (defvar org-export-filter-body-functions nil
2152 "List of functions applied to transcoded body.
2153 Each filter is called with three arguments: a string which
2154 contains no Org syntax, the back-end, as a symbol, and the
2155 communication channel, as a plist. It must return a string or
2158 (defvar org-export-filter-final-output-functions nil
2159 "List of functions applied to the transcoded string.
2160 Each filter is called with three arguments: the full transcoded
2161 string, the back-end, as a symbol, and the communication channel,
2162 as a plist. It must return a string that will be used as the
2163 final export output.")
2166 ;;;; Elements Filters
2168 (defvar org-export-filter-babel-call-functions nil
2169 "List of functions applied to a transcoded babel-call.
2170 Each filter is called with three arguments: the transcoded data,
2171 as a string, the back-end, as a symbol, and the communication
2172 channel, as a plist. It must return a string or nil.")
2174 (defvar org-export-filter-center-block-functions nil
2175 "List of functions applied to a transcoded center block.
2176 Each filter is called with three arguments: the transcoded data,
2177 as a string, the back-end, as a symbol, and the communication
2178 channel, as a plist. It must return a string or nil.")
2180 (defvar org-export-filter-clock-functions nil
2181 "List of functions applied to a transcoded clock.
2182 Each filter is called with three arguments: the transcoded data,
2183 as a string, the back-end, as a symbol, and the communication
2184 channel, as a plist. It must return a string or nil.")
2186 (defvar org-export-filter-diary-sexp-functions nil
2187 "List of functions applied to a transcoded diary-sexp.
2188 Each filter is called with three arguments: the transcoded data,
2189 as a string, the back-end, as a symbol, and the communication
2190 channel, as a plist. It must return a string or nil.")
2192 (defvar org-export-filter-drawer-functions nil
2193 "List of functions applied to a transcoded drawer.
2194 Each filter is called with three arguments: the transcoded data,
2195 as a string, the back-end, as a symbol, and the communication
2196 channel, as a plist. It must return a string or nil.")
2198 (defvar org-export-filter-dynamic-block-functions nil
2199 "List of functions applied to a transcoded dynamic-block.
2200 Each filter is called with three arguments: the transcoded data,
2201 as a string, the back-end, as a symbol, and the communication
2202 channel, as a plist. It must return a string or nil.")
2204 (defvar org-export-filter-example-block-functions nil
2205 "List of functions applied to a transcoded example-block.
2206 Each filter is called with three arguments: the transcoded data,
2207 as a string, the back-end, as a symbol, and the communication
2208 channel, as a plist. It must return a string or nil.")
2210 (defvar org-export-filter-export-block-functions nil
2211 "List of functions applied to a transcoded export-block.
2212 Each filter is called with three arguments: the transcoded data,
2213 as a string, the back-end, as a symbol, and the communication
2214 channel, as a plist. It must return a string or nil.")
2216 (defvar org-export-filter-fixed-width-functions nil
2217 "List of functions applied to a transcoded fixed-width.
2218 Each filter is called with three arguments: the transcoded data,
2219 as a string, the back-end, as a symbol, and the communication
2220 channel, as a plist. It must return a string or nil.")
2222 (defvar org-export-filter-footnote-definition-functions nil
2223 "List of functions applied to a transcoded footnote-definition.
2224 Each filter is called with three arguments: the transcoded data,
2225 as a string, the back-end, as a symbol, and the communication
2226 channel, as a plist. It must return a string or nil.")
2228 (defvar org-export-filter-headline-functions nil
2229 "List of functions applied to a transcoded headline.
2230 Each filter is called with three arguments: the transcoded data,
2231 as a string, the back-end, as a symbol, and the communication
2232 channel, as a plist. It must return a string or nil.")
2234 (defvar org-export-filter-horizontal-rule-functions nil
2235 "List of functions applied to a transcoded horizontal-rule.
2236 Each filter is called with three arguments: the transcoded data,
2237 as a string, the back-end, as a symbol, and the communication
2238 channel, as a plist. It must return a string or nil.")
2240 (defvar org-export-filter-inlinetask-functions nil
2241 "List of functions applied to a transcoded inlinetask.
2242 Each filter is called with three arguments: the transcoded data,
2243 as a string, the back-end, as a symbol, and the communication
2244 channel, as a plist. It must return a string or nil.")
2246 (defvar org-export-filter-item-functions nil
2247 "List of functions applied to a transcoded item.
2248 Each filter is called with three arguments: the transcoded data,
2249 as a string, the back-end, as a symbol, and the communication
2250 channel, as a plist. It must return a string or nil.")
2252 (defvar org-export-filter-keyword-functions nil
2253 "List of functions applied to a transcoded keyword.
2254 Each filter is called with three arguments: the transcoded data,
2255 as a string, the back-end, as a symbol, and the communication
2256 channel, as a plist. It must return a string or nil.")
2258 (defvar org-export-filter-latex-environment-functions nil
2259 "List of functions applied to a transcoded latex-environment.
2260 Each filter is called with three arguments: the transcoded data,
2261 as a string, the back-end, as a symbol, and the communication
2262 channel, as a plist. It must return a string or nil.")
2264 (defvar org-export-filter-node-property-functions nil
2265 "List of functions applied to a transcoded node-property.
2266 Each filter is called with three arguments: the transcoded data,
2267 as a string, the back-end, as a symbol, and the communication
2268 channel, as a plist. It must return a string or nil.")
2270 (defvar org-export-filter-paragraph-functions nil
2271 "List of functions applied to a transcoded paragraph.
2272 Each filter is called with three arguments: the transcoded data,
2273 as a string, the back-end, as a symbol, and the communication
2274 channel, as a plist. It must return a string or nil.")
2276 (defvar org-export-filter-plain-list-functions nil
2277 "List of functions applied to a transcoded plain-list.
2278 Each filter is called with three arguments: the transcoded data,
2279 as a string, the back-end, as a symbol, and the communication
2280 channel, as a plist. It must return a string or nil.")
2282 (defvar org-export-filter-planning-functions nil
2283 "List of functions applied to a transcoded planning.
2284 Each filter is called with three arguments: the transcoded data,
2285 as a string, the back-end, as a symbol, and the communication
2286 channel, as a plist. It must return a string or nil.")
2288 (defvar org-export-filter-property-drawer-functions nil
2289 "List of functions applied to a transcoded property-drawer.
2290 Each filter is called with three arguments: the transcoded data,
2291 as a string, the back-end, as a symbol, and the communication
2292 channel, as a plist. It must return a string or nil.")
2294 (defvar org-export-filter-quote-block-functions nil
2295 "List of functions applied to a transcoded quote block.
2296 Each filter is called with three arguments: the transcoded quote
2297 data, as a string, the back-end, as a symbol, and the
2298 communication channel, as a plist. It must return a string or
2301 (defvar org-export-filter-section-functions nil
2302 "List of functions applied to a transcoded section.
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-special-block-functions nil
2308 "List of functions applied to a transcoded special block.
2309 Each filter is called with three arguments: the transcoded data,
2310 as a string, the back-end, as a symbol, and the communication
2311 channel, as a plist. It must return a string or nil.")
2313 (defvar org-export-filter-src-block-functions nil
2314 "List of functions applied to a transcoded src-block.
2315 Each filter is called with three arguments: the transcoded data,
2316 as a string, the back-end, as a symbol, and the communication
2317 channel, as a plist. It must return a string or nil.")
2319 (defvar org-export-filter-table-functions nil
2320 "List of functions applied to a transcoded table.
2321 Each filter is called with three arguments: the transcoded data,
2322 as a string, the back-end, as a symbol, and the communication
2323 channel, as a plist. It must return a string or nil.")
2325 (defvar org-export-filter-table-cell-functions nil
2326 "List of functions applied to a transcoded table-cell.
2327 Each filter is called with three arguments: the transcoded data,
2328 as a string, the back-end, as a symbol, and the communication
2329 channel, as a plist. It must return a string or nil.")
2331 (defvar org-export-filter-table-row-functions nil
2332 "List of functions applied to a transcoded table-row.
2333 Each filter is called with three arguments: the transcoded data,
2334 as a string, the back-end, as a symbol, and the communication
2335 channel, as a plist. It must return a string or nil.")
2337 (defvar org-export-filter-verse-block-functions nil
2338 "List of functions applied to a transcoded verse block.
2339 Each filter is called with three arguments: the transcoded data,
2340 as a string, the back-end, as a symbol, and the communication
2341 channel, as a plist. It must return a string or nil.")
2344 ;;;; Objects Filters
2346 (defvar org-export-filter-bold-functions nil
2347 "List of functions applied to transcoded bold text.
2348 Each filter is called with three arguments: the transcoded data,
2349 as a string, the back-end, as a symbol, and the communication
2350 channel, as a plist. It must return a string or nil.")
2352 (defvar org-export-filter-code-functions nil
2353 "List of functions applied to transcoded code text.
2354 Each filter is called with three arguments: the transcoded data,
2355 as a string, the back-end, as a symbol, and the communication
2356 channel, as a plist. It must return a string or nil.")
2358 (defvar org-export-filter-entity-functions nil
2359 "List of functions applied to a transcoded entity.
2360 Each filter is called with three arguments: the transcoded data,
2361 as a string, the back-end, as a symbol, and the communication
2362 channel, as a plist. It must return a string or nil.")
2364 (defvar org-export-filter-export-snippet-functions nil
2365 "List of functions applied to a transcoded export-snippet.
2366 Each filter is called with three arguments: the transcoded data,
2367 as a string, the back-end, as a symbol, and the communication
2368 channel, as a plist. It must return a string or nil.")
2370 (defvar org-export-filter-footnote-reference-functions nil
2371 "List of functions applied to a transcoded footnote-reference.
2372 Each filter is called with three arguments: the transcoded data,
2373 as a string, the back-end, as a symbol, and the communication
2374 channel, as a plist. It must return a string or nil.")
2376 (defvar org-export-filter-inline-babel-call-functions nil
2377 "List of functions applied to a transcoded inline-babel-call.
2378 Each filter is called with three arguments: the transcoded data,
2379 as a string, the back-end, as a symbol, and the communication
2380 channel, as a plist. It must return a string or nil.")
2382 (defvar org-export-filter-inline-src-block-functions nil
2383 "List of functions applied to a transcoded inline-src-block.
2384 Each filter is called with three arguments: the transcoded data,
2385 as a string, the back-end, as a symbol, and the communication
2386 channel, as a plist. It must return a string or nil.")
2388 (defvar org-export-filter-italic-functions nil
2389 "List of functions applied to transcoded italic text.
2390 Each filter is called with three arguments: the transcoded data,
2391 as a string, the back-end, as a symbol, and the communication
2392 channel, as a plist. It must return a string or nil.")
2394 (defvar org-export-filter-latex-fragment-functions nil
2395 "List of functions applied to a transcoded latex-fragment.
2396 Each filter is called with three arguments: the transcoded data,
2397 as a string, the back-end, as a symbol, and the communication
2398 channel, as a plist. It must return a string or nil.")
2400 (defvar org-export-filter-line-break-functions nil
2401 "List of functions applied to a transcoded line-break.
2402 Each filter is called with three arguments: the transcoded data,
2403 as a string, the back-end, as a symbol, and the communication
2404 channel, as a plist. It must return a string or nil.")
2406 (defvar org-export-filter-link-functions nil
2407 "List of functions applied to a transcoded link.
2408 Each filter is called with three arguments: the transcoded data,
2409 as a string, the back-end, as a symbol, and the communication
2410 channel, as a plist. It must return a string or nil.")
2412 (defvar org-export-filter-radio-target-functions nil
2413 "List of functions applied to a transcoded radio-target.
2414 Each filter is called with three arguments: the transcoded data,
2415 as a string, the back-end, as a symbol, and the communication
2416 channel, as a plist. It must return a string or nil.")
2418 (defvar org-export-filter-statistics-cookie-functions nil
2419 "List of functions applied to a transcoded statistics-cookie.
2420 Each filter is called with three arguments: the transcoded data,
2421 as a string, the back-end, as a symbol, and the communication
2422 channel, as a plist. It must return a string or nil.")
2424 (defvar org-export-filter-strike-through-functions nil
2425 "List of functions applied to transcoded strike-through text.
2426 Each filter is called with three arguments: the transcoded data,
2427 as a string, the back-end, as a symbol, and the communication
2428 channel, as a plist. It must return a string or nil.")
2430 (defvar org-export-filter-subscript-functions nil
2431 "List of functions applied to a transcoded subscript.
2432 Each filter is called with three arguments: the transcoded data,
2433 as a string, the back-end, as a symbol, and the communication
2434 channel, as a plist. It must return a string or nil.")
2436 (defvar org-export-filter-superscript-functions nil
2437 "List of functions applied to a transcoded superscript.
2438 Each filter is called with three arguments: the transcoded data,
2439 as a string, the back-end, as a symbol, and the communication
2440 channel, as a plist. It must return a string or nil.")
2442 (defvar org-export-filter-target-functions nil
2443 "List of functions applied to a transcoded target.
2444 Each filter is called with three arguments: the transcoded data,
2445 as a string, the back-end, as a symbol, and the communication
2446 channel, as a plist. It must return a string or nil.")
2448 (defvar org-export-filter-timestamp-functions nil
2449 "List of functions applied to a transcoded timestamp.
2450 Each filter is called with three arguments: the transcoded data,
2451 as a string, the back-end, as a symbol, and the communication
2452 channel, as a plist. It must return a string or nil.")
2454 (defvar org-export-filter-underline-functions nil
2455 "List of functions applied to transcoded underline text.
2456 Each filter is called with three arguments: the transcoded data,
2457 as a string, the back-end, as a symbol, and the communication
2458 channel, as a plist. It must return a string or nil.")
2460 (defvar org-export-filter-verbatim-functions nil
2461 "List of functions applied to transcoded verbatim text.
2462 Each filter is called with three arguments: the transcoded data,
2463 as a string, the back-end, as a symbol, and the communication
2464 channel, as a plist. It must return a string or nil.")
2469 ;; Internal function `org-export-install-filters' installs filters
2470 ;; hard-coded in back-ends (developer filters) and filters from global
2471 ;; variables (user filters) in the communication channel.
2473 ;; Internal function `org-export-filter-apply-functions' takes care
2474 ;; about applying each filter in order to a given data. It ignores
2475 ;; filters returning a nil value but stops whenever a filter returns
2478 (defun org-export-filter-apply-functions (filters value info
)
2479 "Call every function in FILTERS.
2481 Functions are called with three arguments: a value, the export
2482 back-end name and the communication channel. First function in
2483 FILTERS is called with VALUE as its first argument. Second
2484 function in FILTERS is called with the previous result as its
2487 Functions returning nil are skipped. Any function returning the
2488 empty string ends the process, which returns the empty string.
2490 Call is done in a LIFO fashion, to be sure that developer
2491 specified filters, if any, are called first."
2493 (let* ((backend (plist-get info
:back-end
))
2494 (backend-name (and backend
(org-export-backend-name backend
))))
2495 (dolist (filter filters value
)
2496 (let ((result (funcall filter value backend-name info
)))
2497 (cond ((not result
))
2498 ((equal result
"") (throw :exit
""))
2499 (t (setq value result
))))))))
2501 (defun org-export-install-filters (info)
2502 "Install filters properties in communication channel.
2503 INFO is a plist containing the current communication channel.
2504 Return the updated communication channel."
2506 ;; Install user-defined filters with `org-export-filters-alist'
2507 ;; and filters already in INFO (through ext-plist mechanism).
2508 (dolist (p org-export-filters-alist
)
2509 (let* ((prop (car p
))
2510 (info-value (plist-get info prop
))
2511 (default-value (symbol-value (cdr p
))))
2513 (plist-put plist prop
2514 ;; Filters in INFO will be called
2515 ;; before those user provided.
2516 (append (if (listp info-value
) info-value
2519 ;; Prepend back-end specific filters to that list.
2520 (dolist (p (org-export-get-all-filters (plist-get info
:back-end
)))
2521 ;; Single values get consed, lists are appended.
2522 (let ((key (car p
)) (value (cdr p
)))
2527 (if (atom value
) (cons value
(plist-get plist key
))
2528 (append value
(plist-get plist key
))))))))
2529 ;; Return new communication channel.
2530 (org-combine-plists info plist
)))
2536 ;; This is the room for the main function, `org-export-as', along with
2537 ;; its derivative, `org-export-string-as'.
2538 ;; `org-export--copy-to-kill-ring-p' determines if output of these
2539 ;; function should be added to kill ring.
2541 ;; Note that `org-export-as' doesn't really parse the current buffer,
2542 ;; but a copy of it (with the same buffer-local variables and
2543 ;; visibility), where macros and include keywords are expanded and
2544 ;; Babel blocks are executed, if appropriate.
2545 ;; `org-export-with-buffer-copy' macro prepares that copy.
2547 ;; File inclusion is taken care of by
2548 ;; `org-export-expand-include-keyword' and
2549 ;; `org-export--prepare-file-contents'. Structure wise, including
2550 ;; a whole Org file in a buffer often makes little sense. For
2551 ;; example, if the file contains a headline and the include keyword
2552 ;; was within an item, the item should contain the headline. That's
2553 ;; why file inclusion should be done before any structure can be
2554 ;; associated to the file, that is before parsing.
2556 ;; `org-export-insert-default-template' is a command to insert
2557 ;; a default template (or a back-end specific template) at point or in
2560 (defun org-export-copy-buffer ()
2561 "Return a copy of the current buffer.
2562 The copy preserves Org buffer-local variables, visibility and
2564 (let ((copy-buffer-fun (org-export--generate-copy-script (current-buffer)))
2565 (new-buf (generate-new-buffer (buffer-name))))
2566 (with-current-buffer new-buf
2567 (funcall copy-buffer-fun
)
2568 (set-buffer-modified-p nil
))
2571 (defmacro org-export-with-buffer-copy
(&rest body
)
2572 "Apply BODY in a copy of the current buffer.
2573 The copy preserves local variables, visibility and contents of
2574 the original buffer. Point is at the beginning of the buffer
2575 when BODY is applied."
2577 (org-with-gensyms (buf-copy)
2578 `(let ((,buf-copy
(org-export-copy-buffer)))
2580 (with-current-buffer ,buf-copy
2581 (goto-char (point-min))
2583 (and (buffer-live-p ,buf-copy
)
2584 ;; Kill copy without confirmation.
2585 (progn (with-current-buffer ,buf-copy
2586 (restore-buffer-modified-p nil
))
2587 (kill-buffer ,buf-copy
)))))))
2589 (defun org-export--generate-copy-script (buffer)
2590 "Generate a function duplicating BUFFER.
2592 The copy will preserve local variables, visibility, contents and
2593 narrowing of the original buffer. If a region was active in
2594 BUFFER, contents will be narrowed to that region instead.
2596 The resulting function can be evaluated at a later time, from
2597 another buffer, effectively cloning the original buffer there.
2599 The function assumes BUFFER's major mode is `org-mode'."
2600 (with-current-buffer buffer
2602 (let ((inhibit-modification-hooks t
))
2603 ;; Set major mode. Ignore `org-mode-hook' as it has been run
2604 ;; already in BUFFER.
2605 (let ((org-mode-hook nil
) (org-inhibit-startup t
)) (org-mode))
2606 ;; Copy specific buffer local variables and variables set
2607 ;; through BIND keywords.
2608 ,@(let ((bound-variables (org-export--list-bound-variables))
2610 (dolist (entry (buffer-local-variables (buffer-base-buffer)) vars
)
2612 (let ((var (car entry
))
2614 (and (not (memq var org-export-ignored-local-variables
))
2618 buffer-file-coding-system
))
2619 (assq var bound-variables
)
2620 (string-match "^\\(org-\\|orgtbl-\\)"
2622 ;; Skip unreadable values, as they cannot be
2623 ;; sent to external process.
2624 (or (not val
) (ignore-errors (read (format "%S" val
))))
2625 (push `(set (make-local-variable (quote ,var
))
2628 ;; Whole buffer contents.
2630 ,(org-with-wide-buffer
2631 (buffer-substring-no-properties
2632 (point-min) (point-max))))
2634 ,(if (org-region-active-p)
2635 `(narrow-to-region ,(region-beginning) ,(region-end))
2636 `(narrow-to-region ,(point-min) ,(point-max)))
2637 ;; Current position of point.
2638 (goto-char ,(point))
2639 ;; Overlays with invisible property.
2641 (dolist (ov (overlays-in (point-min) (point-max)) ov-set
)
2642 (let ((invis-prop (overlay-get ov
'invisible
)))
2645 (make-overlay ,(overlay-start ov
)
2647 'invisible
(quote ,invis-prop
))
2650 (defun org-export--delete-comments ()
2651 "Delete commented areas in the buffer.
2652 Commented areas are comments, comment blocks, commented trees and
2653 inlinetasks. Trailing blank lines after a comment or a comment
2654 block are removed, as long as it doesn't alter the structure of
2655 the document. Narrowing, if any, is ignored."
2656 (org-with-wide-buffer
2657 (goto-char (point-min))
2658 (let* ((case-fold-search t
)
2659 (comment-re "^[ \t]*#\\(?: \\|$\\|\\+end_comment\\)")
2660 (regexp (concat org-outline-regexp-bol
".*" org-comment-string
"\\|"
2662 (while (re-search-forward regexp nil t
)
2663 (let ((element (org-element-at-point)))
2664 (pcase (org-element-type element
)
2665 ((or `headline
`inlinetask
)
2666 (when (org-element-property :commentedp element
)
2667 (delete-region (org-element-property :begin element
)
2668 (org-element-property :end element
))))
2669 ((or `comment
`comment-block
)
2670 (let* ((parent (org-element-property :parent element
))
2671 (start (org-element-property :begin element
))
2672 (end (org-element-property :end element
))
2673 ;; We remove trailing blank lines. Doing so could
2674 ;; modify the structure of the document. Therefore
2675 ;; we ensure that any comment between elements is
2676 ;; replaced with one empty line, so as to keep them
2682 (eq (org-element-property :contents-begin parent
)
2684 (eq (org-element-property :contents-end parent
)
2688 (or (looking-at-p "^[ \t]*$")
2689 (org-with-limited-levels
2690 (org-at-heading-p)))))))))
2691 (delete-region start end
)
2692 (when add-blank?
(insert "\n"))))))))))
2694 (defun org-export--prune-tree (data info
)
2695 "Prune non exportable elements from DATA.
2696 DATA is the parse tree to traverse. INFO is the plist holding
2697 export info. Also set `:ignore-list' in INFO to a list of
2698 objects which should be ignored during export, but not removed
2700 (letrec ((ignore nil
)
2701 ;; First find trees containing a select tag, if any.
2702 (selected (org-export--selected-trees data info
))
2705 ;; Prune non-exportable elements and objects from tree.
2706 ;; As a special case, special rows and cells from tables
2707 ;; are stored in IGNORE, as they still need to be
2708 ;; accessed during export.
2710 (let ((type (org-element-type data
)))
2711 (if (org-export--skip-p data info selected
)
2712 (if (memq type
'(table-cell table-row
)) (push data ignore
)
2713 (org-element-extract-element data
))
2714 (if (and (eq type
'headline
)
2715 (eq (plist-get info
:with-archived-trees
)
2717 (org-element-property :archivedp data
))
2718 ;; If headline is archived but tree below has
2719 ;; to be skipped, remove contents.
2720 (org-element-set-contents data
)
2721 ;; Move into recursive objects/elements.
2722 (mapc walk-data
(org-element-contents data
)))
2723 ;; Move into secondary string, if any.
2724 (dolist (p (cdr (assq type
2725 org-element-secondary-value-alist
)))
2726 (mapc walk-data
(org-element-property p data
))))))))
2728 ;; Collect definitions before possibly pruning them so as
2729 ;; to avoid parsing them again if they are required.
2730 (org-element-map data
'(footnote-definition footnote-reference
)
2733 ((eq (org-element-type f
) 'footnote-definition
) f
)
2734 ((eq (org-element-property :type f
) 'standard
) nil
)
2735 (t (let ((label (org-element-property :label f
)))
2736 (when label
;Skip anonymous references.
2738 #'org-element-create
2739 'footnote-definition
`(:label
,label
:post-blank
1)
2740 (org-element-contents f
))))))))))
2741 ;; If a select tag is active, also ignore the section before the
2742 ;; first headline, if any.
2744 (let ((first-element (car (org-element-contents data
))))
2745 (when (eq (org-element-type first-element
) 'section
)
2746 (org-element-extract-element first-element
))))
2747 ;; Prune tree and communication channel.
2748 (funcall walk-data data
)
2749 (dolist (entry (append
2750 ;; Priority is given to back-end specific options.
2751 (org-export-get-all-options (plist-get info
:back-end
))
2752 org-export-options-alist
))
2753 (when (eq (nth 4 entry
) 'parse
)
2754 (funcall walk-data
(plist-get info
(car entry
)))))
2755 (let ((missing (org-export--missing-definitions data definitions
)))
2756 (funcall walk-data missing
)
2757 (org-export--install-footnote-definitions missing data
))
2758 ;; Eventually set `:ignore-list'.
2759 (plist-put info
:ignore-list ignore
)))
2761 (defun org-export--missing-definitions (tree definitions
)
2762 "List footnote definitions missing from TREE.
2763 Missing definitions are searched within DEFINITIONS, which is
2764 a list of footnote definitions or in the widened buffer."
2767 ;; List all footnote labels encountered in DATA. Inline
2768 ;; footnote references are ignored.
2769 (org-element-map data
'footnote-reference
2771 (and (eq (org-element-property :type reference
) 'standard
)
2772 (org-element-property :label reference
))))))
2773 defined undefined missing-definitions
)
2774 ;; Partition DIRECT-REFERENCES between DEFINED and UNDEFINED
2776 (let ((known-definitions
2777 (org-element-map tree
'(footnote-reference footnote-definition
)
2779 (and (or (eq (org-element-type f
) 'footnote-definition
)
2780 (eq (org-element-property :type f
) 'inline
))
2781 (org-element-property :label f
)))))
2783 (dolist (l (funcall list-labels tree
))
2784 (cond ((member l seen
))
2785 ((member l known-definitions
) (push l defined
))
2786 (t (push l undefined
)))))
2787 ;; Complete MISSING-DEFINITIONS by finding the definition of every
2788 ;; undefined label, first by looking into DEFINITIONS, then by
2789 ;; searching the widened buffer. This is a recursive process
2790 ;; since definitions found can themselves contain an undefined
2793 (let* ((label (pop undefined
))
2797 (lambda (d) (and (equal (org-element-property :label d
) label
)
2800 ((pcase (org-footnote-get-definition label
)
2802 (org-with-wide-buffer
2804 (let ((datum (org-element-context)))
2805 (if (eq (org-element-type datum
) 'footnote-reference
)
2807 ;; Parse definition with contents.
2810 (org-element-property :begin datum
)
2811 (org-element-property :end datum
))
2812 (org-element-map (org-element-parse-buffer)
2813 'footnote-definition
#'identity nil t
))))))
2815 (t (user-error "Definition not found for footnote %s" label
)))))
2816 (push label defined
)
2817 (push definition missing-definitions
)
2818 ;; Look for footnote references within DEFINITION, since
2819 ;; we may need to also find their definition.
2820 (dolist (l (funcall list-labels definition
))
2821 (unless (or (member l defined
) ;Known label
2822 (member l undefined
)) ;Processed later
2823 (push l undefined
)))))
2824 ;; MISSING-DEFINITIONS may contain footnote references with inline
2825 ;; definitions. Make sure those are changed into real footnote
2828 (if (eq (org-element-type d
) 'footnote-definition
) d
2829 (let ((label (org-element-property :label d
)))
2830 (apply #'org-element-create
2831 'footnote-definition
`(:label
,label
:post-blank
1)
2832 (org-element-contents d
)))))
2833 missing-definitions
)))
2835 (defun org-export--install-footnote-definitions (definitions tree
)
2836 "Install footnote definitions in tree.
2838 DEFINITIONS is the list of footnote definitions to install. TREE
2841 If there is a footnote section in TREE, definitions found are
2842 appended to it. If `org-footnote-section' is non-nil, a new
2843 footnote section containing all definitions is inserted in TREE.
2844 Otherwise, definitions are appended at the end of the section
2845 containing their first reference."
2847 ((null definitions
))
2848 ;; If there is a footnote section, insert definitions there.
2849 ((let ((footnote-section
2850 (org-element-map tree
'headline
2851 (lambda (h) (and (org-element-property :footnote-section-p h
) h
))
2853 (and footnote-section
2854 (apply #'org-element-adopt-elements
2856 (nreverse definitions
)))))
2857 ;; If there should be a footnote section, create one containing all
2858 ;; the definitions at the end of the tree.
2859 (org-footnote-section
2860 (org-element-adopt-elements
2862 (org-element-create 'headline
2863 (list :footnote-section-p t
2865 :title org-footnote-section
)
2866 (apply #'org-element-create
2869 (nreverse definitions
)))))
2870 ;; Otherwise add each definition at the end of the section where it
2871 ;; is first referenced.
2876 ;; Insert footnote definitions in the same section as
2877 ;; their first reference in DATA.
2878 (org-element-map data
'footnote-reference
2880 (when (eq (org-element-property :type reference
) 'standard
)
2881 (let ((label (org-element-property :label reference
)))
2882 (unless (member label seen
)
2887 (and (equal (org-element-property :label d
)
2891 (org-element-adopt-elements
2892 (org-element-lineage reference
'(section))
2894 ;; Also insert definitions for nested
2895 ;; references, if any.
2896 (funcall insert-definitions definition
))))))))))
2897 (funcall insert-definitions tree
)))))
2899 (defun org-export--remove-uninterpreted-data (data info
)
2900 "Change uninterpreted elements back into Org syntax.
2901 DATA is the parse tree. INFO is a plist containing export
2902 options. Each uninterpreted element or object is changed back
2903 into a string. Contents, if any, are not modified. The parse
2904 tree is modified by side effect."
2905 (org-export--remove-uninterpreted-data-1 data info
)
2906 (dolist (entry org-export-options-alist
)
2907 (when (eq (nth 4 entry
) 'parse
)
2908 (let ((p (car entry
)))
2911 (org-export--remove-uninterpreted-data-1
2915 (defun org-export--remove-uninterpreted-data-1 (data info
)
2916 "Change uninterpreted elements back into Org syntax.
2917 DATA is a parse tree or a secondary string. INFO is a plist
2918 containing export options. It is modified by side effect and
2919 returned by the function."
2920 (org-element-map data
2921 '(entity bold italic latex-environment latex-fragment strike-through
2922 subscript superscript underline
)
2925 (cl-case (org-element-type blob
)
2928 (and (not (plist-get info
:with-entities
))
2930 (org-export-expand blob nil
)
2932 (or (org-element-property :post-blank blob
) 0)
2935 ((bold italic strike-through underline
)
2936 (and (not (plist-get info
:with-emphasize
))
2937 (let ((marker (cl-case (org-element-type blob
)
2940 (strike-through "+")
2944 (org-element-contents blob
)
2948 (or (org-element-property :post-blank blob
)
2951 ;; ... LaTeX environments and fragments...
2952 ((latex-environment latex-fragment
)
2953 (and (eq (plist-get info
:with-latex
) 'verbatim
)
2954 (list (org-export-expand blob nil
))))
2955 ;; ... sub/superscripts...
2956 ((subscript superscript
)
2957 (let ((sub/super-p
(plist-get info
:with-sub-superscript
))
2958 (bracketp (org-element-property :use-brackets-p blob
)))
2959 (and (or (not sub
/super-p
)
2960 (and (eq sub
/super-p
'{}) (not bracketp
)))
2963 (if (eq (org-element-type blob
) 'subscript
)
2966 (and bracketp
"{")))
2967 (org-element-contents blob
)
2970 (and (org-element-property :post-blank blob
)
2972 (org-element-property :post-blank blob
)
2975 ;; Splice NEW at BLOB location in parse tree.
2976 (dolist (e new
(org-element-extract-element blob
))
2977 (unless (equal e
"") (org-element-insert-before e blob
))))))
2979 ;; Return modified parse tree.
2983 (defun org-export-as
2984 (backend &optional subtreep visible-only body-only ext-plist
)
2985 "Transcode current Org buffer into BACKEND code.
2987 BACKEND is either an export back-end, as returned by, e.g.,
2988 `org-export-create-backend', or a symbol referring to
2989 a registered back-end.
2991 If narrowing is active in the current buffer, only transcode its
2994 If a region is active, transcode that region.
2996 When optional argument SUBTREEP is non-nil, transcode the
2997 sub-tree at point, extracting information from the headline
3000 When optional argument VISIBLE-ONLY is non-nil, don't export
3001 contents of hidden elements.
3003 When optional argument BODY-ONLY is non-nil, only return body
3004 code, without surrounding template.
3006 Optional argument EXT-PLIST, when provided, is a property list
3007 with external parameters overriding Org default settings, but
3008 still inferior to file-local settings.
3010 Return code as a string."
3011 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
3012 (org-export-barf-if-invalid-backend backend
)
3015 ;; Narrow buffer to an appropriate region or subtree for
3016 ;; parsing. If parsing subtree, be sure to remove main
3017 ;; headline, planning data and property drawer.
3018 (cond ((org-region-active-p)
3019 (narrow-to-region (region-beginning) (region-end)))
3021 (org-narrow-to-subtree)
3022 (goto-char (point-min))
3023 (org-end-of-meta-data)
3024 (narrow-to-region (point) (point-max))))
3025 ;; Initialize communication channel with original buffer
3026 ;; attributes, unavailable in its copy.
3027 (let* ((org-export-current-backend (org-export-backend-name backend
))
3028 (info (org-combine-plists
3029 (org-export--get-export-attributes
3030 backend subtreep visible-only body-only
)
3031 (org-export--get-buffer-attributes)))
3034 (mapcar (lambda (o) (and (eq (nth 4 o
) 'parse
) (nth 1 o
)))
3035 (append (org-export-get-all-options backend
)
3036 org-export-options-alist
))))
3038 ;; Update communication channel and get parse tree. Buffer
3039 ;; isn't parsed directly. Instead, all buffer modifications
3040 ;; and consequent parsing are undertaken in a temporary copy.
3041 (org-export-with-buffer-copy
3042 ;; Run first hook with current back-end's name as argument.
3043 (run-hook-with-args 'org-export-before-processing-hook
3044 (org-export-backend-name backend
))
3045 ;; Include files, delete comments and expand macros.
3046 (org-export-expand-include-keyword)
3047 (org-export--delete-comments)
3048 (org-macro-initialize-templates)
3049 (org-macro-replace-all org-macro-templates nil parsed-keywords
)
3050 ;; Refresh buffer properties and radio targets after
3051 ;; potentially invasive previous changes. Likewise, do it
3052 ;; again after executing Babel code.
3053 (org-set-regexps-and-options)
3054 (org-update-radio-target-regexp)
3055 (when org-export-use-babel
3056 (org-babel-exp-process-buffer)
3057 (org-set-regexps-and-options)
3058 (org-update-radio-target-regexp))
3059 ;; Run last hook with current back-end's name as argument.
3060 ;; Update buffer properties and radio targets one last time
3062 (goto-char (point-min))
3064 (run-hook-with-args 'org-export-before-parsing-hook
3065 (org-export-backend-name backend
)))
3066 (org-set-regexps-and-options)
3067 (org-update-radio-target-regexp)
3068 ;; Update communication channel with environment. Also
3069 ;; install user's and developer's filters.
3071 (org-export-install-filters
3073 info
(org-export-get-environment backend subtreep ext-plist
))))
3074 ;; Call options filters and update export options. We do not
3075 ;; use `org-export-filter-apply-functions' here since the
3076 ;; arity of such filters is different.
3077 (let ((backend-name (org-export-backend-name backend
)))
3078 (dolist (filter (plist-get info
:filter-options
))
3079 (let ((result (funcall filter info backend-name
)))
3080 (when result
(setq info result
)))))
3081 ;; Expand export-specific set of macros: {{{author}}},
3082 ;; {{{date(FORMAT)}}}, {{{email}}} and {{{title}}}. It must
3083 ;; be done once regular macros have been expanded, since
3084 ;; parsed keywords may contain one of them.
3085 (org-macro-replace-all
3087 (cons "author" (org-element-interpret-data (plist-get info
:author
)))
3089 (let* ((date (plist-get info
:date
))
3090 (value (or (org-element-interpret-data date
) "")))
3091 (if (and (consp date
)
3093 (eq (org-element-type (car date
)) 'timestamp
))
3094 (format "(eval (if (org-string-nw-p \"$1\") %s %S))"
3095 (format "(org-timestamp-format '%S \"$1\")"
3096 (org-element-copy (car date
)))
3099 (cons "email" (org-element-interpret-data (plist-get info
:email
)))
3100 (cons "title" (org-element-interpret-data (plist-get info
:title
)))
3101 (cons "results" "$1"))
3105 (setq tree
(org-element-parse-buffer nil visible-only
))
3106 ;; Prune tree from non-exported elements and transform
3107 ;; uninterpreted elements or objects in both parse tree and
3108 ;; communication channel.
3109 (org-export--prune-tree tree info
)
3110 (org-export--remove-uninterpreted-data tree info
)
3111 ;; Call parse tree filters.
3113 (org-export-filter-apply-functions
3114 (plist-get info
:filter-parse-tree
) tree info
))
3115 ;; Now tree is complete, compute its properties and add them
3116 ;; to communication channel.
3117 (setq info
(org-export--collect-tree-properties tree info
))
3118 ;; Eventually transcode TREE. Wrap the resulting string into
3120 (let* ((body (org-element-normalize-string
3121 (or (org-export-data tree info
) "")))
3122 (inner-template (cdr (assq 'inner-template
3123 (plist-get info
:translate-alist
))))
3124 (full-body (org-export-filter-apply-functions
3125 (plist-get info
:filter-body
)
3126 (if (not (functionp inner-template
)) body
3127 (funcall inner-template body info
))
3129 (template (cdr (assq 'template
3130 (plist-get info
:translate-alist
)))))
3131 ;; Remove all text properties since they cannot be
3132 ;; retrieved from an external process. Finally call
3133 ;; final-output filter and return result.
3135 (org-export-filter-apply-functions
3136 (plist-get info
:filter-final-output
)
3137 (if (or (not (functionp template
)) body-only
) full-body
3138 (funcall template full-body info
))
3142 (defun org-export-string-as (string backend
&optional body-only ext-plist
)
3143 "Transcode STRING into BACKEND code.
3145 BACKEND is either an export back-end, as returned by, e.g.,
3146 `org-export-create-backend', or a symbol referring to
3147 a registered back-end.
3149 When optional argument BODY-ONLY is non-nil, only return body
3150 code, without preamble nor postamble.
3152 Optional argument EXT-PLIST, when provided, is a property list
3153 with external parameters overriding Org default settings, but
3154 still inferior to file-local settings.
3156 Return code as a string."
3159 (let ((org-inhibit-startup t
)) (org-mode))
3160 (org-export-as backend nil nil body-only ext-plist
)))
3163 (defun org-export-replace-region-by (backend)
3164 "Replace the active region by its export to BACKEND.
3165 BACKEND is either an export back-end, as returned by, e.g.,
3166 `org-export-create-backend', or a symbol referring to
3167 a registered back-end."
3168 (unless (org-region-active-p) (user-error "No active region to replace"))
3170 (org-export-string-as
3171 (delete-and-extract-region (region-beginning) (region-end)) backend t
)))
3174 (defun org-export-insert-default-template (&optional backend subtreep
)
3175 "Insert all export keywords with default values at beginning of line.
3177 BACKEND is a symbol referring to the name of a registered export
3178 back-end, for which specific export options should be added to
3179 the template, or `default' for default template. When it is nil,
3180 the user will be prompted for a category.
3182 If SUBTREEP is non-nil, export configuration will be set up
3183 locally for the subtree through node properties."
3185 (unless (derived-mode-p 'org-mode
) (user-error "Not in an Org mode buffer"))
3186 (when (and subtreep
(org-before-first-heading-p))
3187 (user-error "No subtree to set export options for"))
3188 (let ((node (and subtreep
(save-excursion (org-back-to-heading t
) (point))))
3192 (org-completing-read
3193 "Options category: "
3196 (symbol-name (org-export-backend-name b
)))
3197 org-export-registered-backends
))
3200 ;; Populate OPTIONS and KEYWORDS.
3201 (dolist (entry (cond ((eq backend
'default
) org-export-options-alist
)
3202 ((org-export-backend-p backend
)
3203 (org-export-backend-options backend
))
3204 (t (org-export-backend-options
3205 (org-export-get-backend backend
)))))
3206 (let ((keyword (nth 1 entry
))
3207 (option (nth 2 entry
)))
3209 (keyword (unless (assoc keyword keywords
)
3211 (if (eq (nth 4 entry
) 'split
)
3212 (mapconcat #'identity
(eval (nth 3 entry
)) " ")
3213 (eval (nth 3 entry
)))))
3214 (push (cons keyword value
) keywords
))))
3215 (option (unless (assoc option options
)
3216 (push (cons option
(eval (nth 3 entry
))) options
))))))
3217 ;; Move to an appropriate location in order to insert options.
3218 (unless subtreep
(beginning-of-line))
3219 ;; First (multiple) OPTIONS lines. Never go past fill-column.
3223 #'(lambda (opt) (format "%s:%S" (car opt
) (cdr opt
)))
3224 (sort options
(lambda (k1 k2
) (string< (car k1
) (car k2
)))))))
3227 node
"EXPORT_OPTIONS" (mapconcat 'identity items
" "))
3229 (insert "#+OPTIONS:")
3232 (< (+ width
(length (car items
)) 1) fill-column
))
3233 (let ((item (pop items
)))
3235 (cl-incf width
(1+ (length item
))))))
3237 ;; Then the rest of keywords, in the order specified in either
3238 ;; `org-export-options-alist' or respective export back-ends.
3239 (dolist (key (nreverse keywords
))
3240 (let ((val (cond ((equal (car key
) "DATE")
3243 (org-insert-time-stamp (current-time)))))
3244 ((equal (car key
) "TITLE")
3245 (or (let ((visited-file
3246 (buffer-file-name (buffer-base-buffer))))
3248 (file-name-sans-extension
3249 (file-name-nondirectory visited-file
))))
3250 (buffer-name (buffer-base-buffer))))
3252 (if subtreep
(org-entry-put node
(concat "EXPORT_" (car key
)) val
)
3256 (if (org-string-nw-p val
) (format " %s" val
) ""))))))))
3258 (defun org-export-expand-include-keyword (&optional included dir footnotes
)
3259 "Expand every include keyword in buffer.
3260 Optional argument INCLUDED is a list of included file names along
3261 with their line restriction, when appropriate. It is used to
3262 avoid infinite recursion. Optional argument DIR is the current
3263 working directory. It is used to properly resolve relative
3264 paths. Optional argument FOOTNOTES is a hash-table used for
3265 storing and resolving footnotes. It is created automatically."
3266 (let ((case-fold-search t
)
3267 (file-prefix (make-hash-table :test
#'equal
))
3269 (footnotes (or footnotes
(make-hash-table :test
#'equal
)))
3270 (include-re "^[ \t]*#\\+INCLUDE:"))
3271 ;; If :minlevel is not set the text-property
3272 ;; `:org-include-induced-level' will be used to determine the
3273 ;; relative level when expanding INCLUDE.
3274 ;; Only affects included Org documents.
3275 (goto-char (point-min))
3276 (while (re-search-forward include-re nil t
)
3277 (put-text-property (line-beginning-position) (line-end-position)
3278 :org-include-induced-level
3279 (1+ (org-reduced-level (or (org-current-level) 0)))))
3280 ;; Expand INCLUDE keywords.
3281 (goto-char (point-min))
3282 (while (re-search-forward include-re nil t
)
3283 (let ((element (save-match-data (org-element-at-point))))
3284 (when (eq (org-element-type element
) 'keyword
)
3286 ;; Extract arguments from keyword's value.
3287 (let* ((value (org-element-property :value element
))
3288 (ind (org-get-indentation))
3292 "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value
)
3295 (let ((matched (match-string 1 value
)))
3296 (when (string-match "\\(::\\(.*?\\)\\)\"?\\'"
3298 (setq location
(match-string 2 matched
))
3300 (replace-match "" nil nil matched
1)))
3302 (org-unbracket-string "\"" "\"" matched
)
3304 (setq value
(replace-match "" nil nil value
)))))
3306 (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
3308 (prog1 (org-not-nil (match-string 1 value
))
3309 (setq value
(replace-match "" nil nil value
)))))
3312 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
3314 (prog1 (match-string 1 value
)
3315 (setq value
(replace-match "" nil nil value
)))))
3317 ((string-match "\\<example\\>" value
) 'literal
)
3318 ((string-match "\\<export\\(?: +\\(.*\\)\\)?" value
)
3320 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value
)
3322 ;; Minimal level of included file defaults to the child
3323 ;; level of the current headline, if any, or one. It
3324 ;; only applies is the file is meant to be included as
3328 (if (string-match ":minlevel +\\([0-9]+\\)" value
)
3329 (prog1 (string-to-number (match-string 1 value
))
3330 (setq value
(replace-match "" nil nil value
)))
3331 (get-text-property (point)
3332 :org-include-induced-level
))))
3333 (args (and (eq env
'literal
) (match-string 1 value
)))
3334 (block (and (string-match "\\<\\(\\S-+\\)\\>" value
)
3335 (match-string 1 value
))))
3337 (delete-region (point) (line-beginning-position 2))
3340 ((not (file-readable-p file
))
3341 (error "Cannot include file %s" file
))
3342 ;; Check if files has already been parsed. Look after
3343 ;; inclusion lines too, as different parts of the same file
3344 ;; can be included too.
3345 ((member (list file lines
) included
)
3346 (error "Recursive file inclusion: %s" file
))
3351 (let ((ind-str (make-string ind ?\s
))
3352 (arg-str (if (stringp args
) (format " %s" args
) ""))
3354 (org-escape-code-in-string
3355 (org-export--prepare-file-contents file lines
))))
3356 (format "%s#+BEGIN_%s%s\n%s%s#+END_%s\n"
3357 ind-str block arg-str contents ind-str block
))))
3360 (let ((ind-str (make-string ind ?\s
))
3362 (org-export--prepare-file-contents file lines
)))
3363 (format "%s#+BEGIN_%s\n%s%s#+END_%s\n"
3364 ind-str block contents ind-str block
))))
3368 (let ((org-inhibit-startup t
)
3371 (org-export--inclusion-absolute-lines
3372 file location only-contents lines
)
3376 (org-export--prepare-file-contents
3377 file lines ind minlevel
3378 (or (gethash file file-prefix
)
3379 (puthash file
(cl-incf current-prefix
) file-prefix
))
3381 (org-export-expand-include-keyword
3382 (cons (list file lines
) included
)
3383 (file-name-directory file
)
3386 ;; Expand footnotes after all files have been included.
3387 ;; Footnotes are stored at end of buffer.
3389 (org-with-wide-buffer
3390 (goto-char (point-max))
3391 (maphash (lambda (k v
) (insert (format "\n[fn:%s] %s\n" k v
)))
3392 footnotes
)))))))))))
3394 (defun org-export--inclusion-absolute-lines (file location only-contents lines
)
3395 "Resolve absolute lines for an included file with file-link.
3397 FILE is string file-name of the file to include. LOCATION is a
3398 string name within FILE to be included (located via
3399 `org-link-search'). If ONLY-CONTENTS is non-nil only the
3400 contents of the named element will be included, as determined
3401 Org-Element. If LINES is non-nil only those lines are included.
3403 Return a string of lines to be included in the format expected by
3404 `org-export--prepare-file-contents'."
3406 (insert-file-contents file
)
3407 (unless (eq major-mode
'org-mode
)
3408 (let ((org-inhibit-startup t
)) (org-mode)))
3410 ;; Enforce consistent search.
3411 (let ((org-link-search-must-match-exact-headline nil
))
3412 (org-link-search location
))
3414 (error "%s for %s::%s" (error-message-string err
) file location
)))
3415 (let* ((element (org-element-at-point))
3417 (and only-contents
(org-element-property :contents-begin element
))))
3419 (or contents-begin
(org-element-property :begin element
))
3420 (org-element-property (if contents-begin
:contents-end
:end
) element
))
3421 (when (and only-contents
3422 (memq (org-element-type element
) '(headline inlinetask
)))
3423 ;; Skip planning line and property-drawer.
3424 (goto-char (point-min))
3425 (when (looking-at-p org-planning-line-re
) (forward-line))
3426 (when (looking-at org-property-drawer-re
) (goto-char (match-end 0)))
3427 (unless (bolp) (forward-line))
3428 (narrow-to-region (point) (point-max))))
3430 (org-skip-whitespace)
3432 (let* ((lines (split-string lines
"-"))
3433 (lbeg (string-to-number (car lines
)))
3434 (lend (string-to-number (cadr lines
)))
3435 (beg (if (zerop lbeg
) (point-min)
3436 (goto-char (point-min))
3437 (forward-line (1- lbeg
))
3439 (end (if (zerop lend
) (point-max)
3441 (forward-line (1- lend
))
3443 (narrow-to-region beg end
)))
3444 (let ((end (point-max)))
3445 (goto-char (point-min))
3447 (let ((start-line (line-number-at-pos)))
3453 (while (< (point) end
) (cl-incf counter
) (forward-line))
3456 (defun org-export--prepare-file-contents
3457 (file &optional lines ind minlevel id footnotes
)
3458 "Prepare contents of FILE for inclusion and return it as a string.
3460 When optional argument LINES is a string specifying a range of
3461 lines, include only those lines.
3463 Optional argument IND, when non-nil, is an integer specifying the
3464 global indentation of returned contents. Since its purpose is to
3465 allow an included file to stay in the same environment it was
3466 created (e.g., a list item), it doesn't apply past the first
3467 headline encountered.
3469 Optional argument MINLEVEL, when non-nil, is an integer
3470 specifying the level that any top-level headline in the included
3473 Optional argument ID is an integer that will be inserted before
3474 each footnote definition and reference if FILE is an Org file.
3475 This is useful to avoid conflicts when more than one Org file
3476 with footnotes is included in a document.
3478 Optional argument FOOTNOTES is a hash-table to store footnotes in
3479 the included document."
3481 (insert-file-contents file
)
3483 (let* ((lines (split-string lines
"-"))
3484 (lbeg (string-to-number (car lines
)))
3485 (lend (string-to-number (cadr lines
)))
3486 (beg (if (zerop lbeg
) (point-min)
3487 (goto-char (point-min))
3488 (forward-line (1- lbeg
))
3490 (end (if (zerop lend
) (point-max)
3491 (goto-char (point-min))
3492 (forward-line (1- lend
))
3494 (narrow-to-region beg end
)))
3495 ;; Remove blank lines at beginning and end of contents. The logic
3496 ;; behind that removal is that blank lines around include keyword
3497 ;; override blank lines in included file.
3498 (goto-char (point-min))
3499 (org-skip-whitespace)
3501 (delete-region (point-min) (point))
3502 (goto-char (point-max))
3503 (skip-chars-backward " \r\t\n")
3505 (delete-region (point) (point-max))
3506 ;; If IND is set, preserve indentation of include keyword until
3507 ;; the first headline encountered.
3508 (when (and ind
(> ind
0))
3509 (unless (eq major-mode
'org-mode
)
3510 (let ((org-inhibit-startup t
)) (org-mode)))
3511 (goto-char (point-min))
3512 (let ((ind-str (make-string ind ?\s
)))
3513 (while (not (or (eobp) (looking-at org-outline-regexp-bol
)))
3514 ;; Do not move footnote definitions out of column 0.
3515 (unless (and (looking-at org-footnote-definition-re
)
3516 (eq (org-element-type (org-element-at-point))
3517 'footnote-definition
))
3520 ;; When MINLEVEL is specified, compute minimal level for headlines
3521 ;; in the file (CUR-MIN), and remove stars to each headline so
3522 ;; that headlines with minimal level have a level of MINLEVEL.
3524 (unless (eq major-mode
'org-mode
)
3525 (let ((org-inhibit-startup t
)) (org-mode)))
3526 (org-with-limited-levels
3527 (let ((levels (org-map-entries
3528 (lambda () (org-reduced-level (org-current-level))))))
3530 (let ((offset (- minlevel
(apply #'min levels
))))
3531 (unless (zerop offset
)
3532 (when org-odd-levels-only
(setq offset
(* offset
2)))
3533 ;; Only change stars, don't bother moving whole
3537 (if (< offset
0) (delete-char (abs offset
))
3538 (insert (make-string offset ?
*)))))))))))
3539 ;; Append ID to all footnote references and definitions, so they
3540 ;; become file specific and cannot collide with footnotes in other
3541 ;; included files. Further, collect relevant footnote definitions
3542 ;; outside of LINES, in order to reintroduce them later.
3544 (let ((marker-min (point-min-marker))
3545 (marker-max (point-max-marker))
3548 ;; Generate new label from LABEL by prefixing it with
3550 (format "-%d-%s" id label
)))
3553 ;; Replace OLD label with NEW in footnote F.
3555 (goto-char (+ (org-element-property :begin f
) 4))
3556 (looking-at (regexp-quote old
))
3557 (replace-match new
))))
3559 (goto-char (point-min))
3560 (while (re-search-forward org-footnote-re nil t
)
3561 (let ((footnote (save-excursion
3563 (org-element-context))))
3564 (when (memq (org-element-type footnote
)
3565 '(footnote-definition footnote-reference
))
3566 (let* ((label (org-element-property :label footnote
)))
3567 ;; Update the footnote-reference at point and collect
3568 ;; the new label, which is only used for footnotes
3571 (let ((seen (cdr (assoc label seen-alist
))))
3572 (if seen
(funcall set-new-label footnote label seen
)
3573 (let ((new (funcall get-new-label label
)))
3574 (push (cons label new
) seen-alist
)
3575 (org-with-wide-buffer
3576 (let* ((def (org-footnote-get-definition label
))
3579 (or (< beg marker-min
)
3580 (>= beg marker-max
)))
3581 ;; Store since footnote-definition is
3582 ;; outside of LINES.
3584 (org-element-normalize-string (nth 3 def
))
3586 (funcall set-new-label footnote label new
)))))))))
3587 (set-marker marker-min nil
)
3588 (set-marker marker-max nil
)))
3589 (org-element-normalize-string (buffer-string))))
3591 (defun org-export--copy-to-kill-ring-p ()
3592 "Return a non-nil value when output should be added to the kill ring.
3593 See also `org-export-copy-to-kill-ring'."
3594 (if (eq org-export-copy-to-kill-ring
'if-interactive
)
3595 (not (or executing-kbd-macro noninteractive
))
3596 (eq org-export-copy-to-kill-ring t
)))
3600 ;;; Tools For Back-Ends
3602 ;; A whole set of tools is available to help build new exporters. Any
3603 ;; function general enough to have its use across many back-ends
3604 ;; should be added here.
3606 ;;;; For Affiliated Keywords
3608 ;; `org-export-read-attribute' reads a property from a given element
3609 ;; as a plist. It can be used to normalize affiliated keywords'
3612 ;; Since captions can span over multiple lines and accept dual values,
3613 ;; their internal representation is a bit tricky. Therefore,
3614 ;; `org-export-get-caption' transparently returns a given element's
3615 ;; caption as a secondary string.
3617 (defun org-export-read-attribute (attribute element
&optional property
)
3618 "Turn ATTRIBUTE property from ELEMENT into a plist.
3620 When optional argument PROPERTY is non-nil, return the value of
3621 that property within attributes.
3623 This function assumes attributes are defined as \":keyword
3624 value\" pairs. It is appropriate for `:attr_html' like
3627 All values will become strings except the empty string and
3628 \"nil\", which will become nil. Also, values containing only
3629 double quotes will be read as-is, which means that \"\" value
3630 will become the empty string."
3631 (let* ((prepare-value
3634 (cond ((member str
'(nil "" "nil")) nil
)
3635 ((string-match "^\"\\(\"+\\)?\"$" str
)
3636 (or (match-string 1 str
) ""))
3639 (let ((value (org-element-property attribute element
)))
3641 (let ((s (mapconcat 'identity value
" ")) result
)
3642 (while (string-match
3643 "\\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ \t]+\\|$\\)"
3645 (let ((value (substring s
0 (match-beginning 0))))
3646 (push (funcall prepare-value value
) result
))
3647 (push (intern (match-string 1 s
)) result
)
3648 (setq s
(substring s
(match-end 0))))
3649 ;; Ignore any string before first property with `cdr'.
3650 (cdr (nreverse (cons (funcall prepare-value s
) result
))))))))
3651 (if property
(plist-get attributes property
) attributes
)))
3653 (defun org-export-get-caption (element &optional shortp
)
3654 "Return caption from ELEMENT as a secondary string.
3656 When optional argument SHORTP is non-nil, return short caption,
3657 as a secondary string, instead.
3659 Caption lines are separated by a white space."
3660 (let ((full-caption (org-element-property :caption element
)) caption
)
3661 (dolist (line full-caption
(cdr caption
))
3662 (let ((cap (funcall (if shortp
'cdr
'car
) line
)))
3664 (setq caption
(nconc (list " ") (copy-sequence cap
) caption
)))))))
3667 ;;;; For Derived Back-ends
3669 ;; `org-export-with-backend' is a function allowing to locally use
3670 ;; another back-end to transcode some object or element. In a derived
3671 ;; back-end, it may be used as a fall-back function once all specific
3672 ;; cases have been treated.
3674 (defun org-export-with-backend (backend data
&optional contents info
)
3675 "Call a transcoder from BACKEND on DATA.
3676 BACKEND is an export back-end, as returned by, e.g.,
3677 `org-export-create-backend', or a symbol referring to
3678 a registered back-end. DATA is an Org element, object, secondary
3679 string or string. CONTENTS, when non-nil, is the transcoded
3680 contents of DATA element, as a string. INFO, when non-nil, is
3681 the communication channel used for export, as a plist."
3682 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
3683 (org-export-barf-if-invalid-backend backend
)
3684 (let ((type (org-element-type data
)))
3685 (when (memq type
'(nil org-data
)) (error "No foreign transcoder available"))
3686 (let* ((all-transcoders (org-export-get-all-transcoders backend
))
3687 (transcoder (cdr (assq type all-transcoders
))))
3688 (unless (functionp transcoder
) (error "No foreign transcoder available"))
3693 :translate-alist all-transcoders
3694 :exported-data
(make-hash-table :test
#'eq
:size
401)))))
3695 ;; `:internal-references' are shared across back-ends.
3696 (prog1 (funcall transcoder data contents new-info
)
3697 (plist-put info
:internal-references
3698 (plist-get new-info
:internal-references
)))))))
3701 ;;;; For Export Snippets
3703 ;; Every export snippet is transmitted to the back-end. Though, the
3704 ;; latter will only retain one type of export-snippet, ignoring
3705 ;; others, based on the former's target back-end. The function
3706 ;; `org-export-snippet-backend' returns that back-end for a given
3709 (defun org-export-snippet-backend (export-snippet)
3710 "Return EXPORT-SNIPPET targeted back-end as a symbol.
3711 Translation, with `org-export-snippet-translation-alist', is
3713 (let ((back-end (org-element-property :back-end export-snippet
)))
3715 (or (cdr (assoc back-end org-export-snippet-translation-alist
))
3721 ;; `org-export-collect-footnote-definitions' is a tool to list
3722 ;; actually used footnotes definitions in the whole parse tree, or in
3723 ;; a headline, in order to add footnote listings throughout the
3726 ;; `org-export-footnote-first-reference-p' is a predicate used by some
3727 ;; back-ends, when they need to attach the footnote definition only to
3728 ;; the first occurrence of the corresponding label.
3730 ;; `org-export-get-footnote-definition' and
3731 ;; `org-export-get-footnote-number' provide easier access to
3732 ;; additional information relative to a footnote reference.
3734 (defun org-export-get-footnote-definition (footnote-reference info
)
3735 "Return definition of FOOTNOTE-REFERENCE as parsed data.
3736 INFO is the plist used as a communication channel. If no such
3737 definition can be found, raise an error."
3738 (let ((label (org-element-property :label footnote-reference
)))
3739 (if (not label
) (org-element-contents footnote-reference
)
3740 (let ((cache (or (plist-get info
:footnote-definition-cache
)
3741 (let ((hash (make-hash-table :test
#'equal
)))
3742 (plist-put info
:footnote-definition-cache hash
)
3745 (gethash label cache
)
3747 (org-element-map (plist-get info
:parse-tree
)
3748 '(footnote-definition footnote-reference
)
3751 ;; Skip any footnote with a different label.
3752 ;; Also skip any standard footnote reference
3753 ;; with the same label since those cannot
3754 ;; contain a definition.
3755 ((not (equal (org-element-property :label f
) label
)) nil
)
3756 ((eq (org-element-property :type f
) 'standard
) nil
)
3757 ((org-element-contents f
))
3758 ;; Even if the contents are empty, we can not
3759 ;; return nil since that would eventually raise
3760 ;; the error. Instead, return the equivalent
3765 (error "Definition not found for footnote %s" label
))))))
3767 (defun org-export--footnote-reference-map
3768 (function data info
&optional body-first
)
3769 "Apply FUNCTION on every footnote reference in DATA.
3770 INFO is a plist containing export state. By default, as soon as
3771 a new footnote reference is encountered, FUNCTION is called onto
3772 its definition. However, if BODY-FIRST is non-nil, this step is
3773 delayed until the end of the process."
3774 (letrec ((definitions nil
)
3777 (lambda (data delayp
)
3778 ;; Search footnote references through DATA, filling
3779 ;; SEEN-REFS along the way. When DELAYP is non-nil,
3780 ;; store footnote definitions so they can be entered
3782 (org-element-map data
'footnote-reference
3784 (funcall function f
)
3785 (let ((--label (org-element-property :label f
)))
3786 (unless (and --label
(member --label seen-refs
))
3787 (when --label
(push --label seen-refs
))
3788 ;; Search for subsequent references in footnote
3789 ;; definition so numbering follows reading
3790 ;; logic, unless DELAYP in non-nil.
3793 (push (org-export-get-footnote-definition f info
)
3795 ;; Do not force entering inline definitions,
3796 ;; since `org-element-map' already traverses
3797 ;; them at the right time.
3798 ((eq (org-element-property :type f
) 'inline
))
3799 (t (funcall search-ref
3800 (org-export-get-footnote-definition f info
)
3803 ;; Don't enter footnote definitions since it will
3804 ;; happen when their first reference is found.
3805 ;; Moreover, if DELAYP is non-nil, make sure we
3806 ;; postpone entering definitions of inline references.
3807 (if delayp
'(footnote-definition footnote-reference
)
3808 'footnote-definition
)))))
3809 (funcall search-ref data body-first
)
3810 (funcall search-ref
(nreverse definitions
) nil
)))
3812 (defun org-export-collect-footnote-definitions (info &optional data body-first
)
3813 "Return an alist between footnote numbers, labels and definitions.
3815 INFO is the current export state, as a plist.
3817 Definitions are collected throughout the whole parse tree, or
3820 Sorting is done by order of references. As soon as a new
3821 reference is encountered, other references are searched within
3822 its definition. However, if BODY-FIRST is non-nil, this step is
3823 delayed after the whole tree is checked. This alters results
3824 when references are found in footnote definitions.
3826 Definitions either appear as Org data or as a secondary string
3827 for inlined footnotes. Unreferenced definitions are ignored."
3828 (let ((n 0) labels alist
)
3829 (org-export--footnote-reference-map
3831 ;; Collect footnote number, label and definition.
3832 (let ((l (org-element-property :label f
)))
3833 (unless (and l
(member l labels
))
3835 (push (list n l
(org-export-get-footnote-definition f info
)) alist
))
3836 (when l
(push l labels
))))
3837 (or data
(plist-get info
:parse-tree
)) info body-first
)
3840 (defun org-export-footnote-first-reference-p
3841 (footnote-reference info
&optional data body-first
)
3842 "Non-nil when a footnote reference is the first one for its label.
3844 FOOTNOTE-REFERENCE is the footnote reference being considered.
3845 INFO is a plist containing current export state.
3847 Search is done throughout the whole parse tree, or DATA when
3850 By default, as soon as a new footnote reference is encountered,
3851 other references are searched within its definition. However, if
3852 BODY-FIRST is non-nil, this step is delayed after the whole tree
3853 is checked. This alters results when references are found in
3854 footnote definitions."
3855 (let ((label (org-element-property :label footnote-reference
)))
3856 ;; Anonymous footnotes are always a first reference.
3859 (org-export--footnote-reference-map
3861 (let ((l (org-element-property :label f
)))
3862 (when (and l label
(string= label l
))
3863 (throw 'exit
(eq footnote-reference f
)))))
3864 (or data
(plist-get info
:parse-tree
)) info body-first
)))))
3866 (defun org-export-get-footnote-number (footnote info
&optional data body-first
)
3867 "Return number associated to a footnote.
3869 FOOTNOTE is either a footnote reference or a footnote definition.
3870 INFO is the plist containing export state.
3872 Number is unique throughout the whole parse tree, or DATA, when
3875 By default, as soon as a new footnote reference is encountered,
3876 counting process moves into its definition. However, if
3877 BODY-FIRST is non-nil, this step is delayed until the end of the
3878 process, leading to a different order when footnotes are nested."
3881 (label (org-element-property :label footnote
)))
3883 (org-export--footnote-reference-map
3885 (let ((l (org-element-property :label f
)))
3887 ;; Anonymous footnote match: return number.
3888 ((and (not l
) (not label
) (eq footnote f
)) (throw 'exit
(1+ count
)))
3889 ;; Labels match: return number.
3890 ((and label l
(string= label l
)) (throw 'exit
(1+ count
)))
3891 ;; Otherwise store label and increase counter if label
3892 ;; wasn't encountered yet.
3893 ((not l
) (cl-incf count
))
3894 ((not (member l seen
)) (push l seen
) (cl-incf count
)))))
3895 (or data
(plist-get info
:parse-tree
)) info body-first
))))
3900 ;; `org-export-get-relative-level' is a shortcut to get headline
3901 ;; level, relatively to the lower headline level in the parsed tree.
3903 ;; `org-export-get-headline-number' returns the section number of an
3904 ;; headline, while `org-export-number-to-roman' allows it to be
3905 ;; converted to roman numbers. With an optional argument,
3906 ;; `org-export-get-headline-number' returns a number to unnumbered
3907 ;; headlines (used for internal id).
3909 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
3910 ;; `org-export-last-sibling-p' are three useful predicates when it
3911 ;; comes to fulfill the `:headline-levels' property.
3913 ;; `org-export-get-tags', `org-export-get-category' and
3914 ;; `org-export-get-node-property' extract useful information from an
3915 ;; headline or a parent headline. They all handle inheritance.
3917 ;; `org-export-get-alt-title' tries to retrieve an alternative title,
3918 ;; as a secondary string, suitable for table of contents. It falls
3919 ;; back onto default title.
3921 (defun org-export-get-relative-level (headline info
)
3922 "Return HEADLINE relative level within current parsed tree.
3923 INFO is a plist holding contextual information."
3924 (+ (org-element-property :level headline
)
3925 (or (plist-get info
:headline-offset
) 0)))
3927 (defun org-export-low-level-p (headline info
)
3928 "Non-nil when HEADLINE is considered as low level.
3930 INFO is a plist used as a communication channel.
3932 A low level headlines has a relative level greater than
3933 `:headline-levels' property value.
3935 Return value is the difference between HEADLINE relative level
3936 and the last level being considered as high enough, or nil."
3937 (let ((limit (plist-get info
:headline-levels
)))
3938 (when (wholenump limit
)
3939 (let ((level (org-export-get-relative-level headline info
)))
3940 (and (> level limit
) (- level limit
))))))
3942 (defun org-export-get-headline-number (headline info
)
3943 "Return numbered HEADLINE numbering as a list of numbers.
3944 INFO is a plist holding contextual information."
3945 (and (org-export-numbered-headline-p headline info
)
3946 (cdr (assq headline
(plist-get info
:headline-numbering
)))))
3948 (defun org-export-numbered-headline-p (headline info
)
3949 "Return a non-nil value if HEADLINE element should be numbered.
3950 INFO is a plist used as a communication channel."
3952 (lambda (head) (org-not-nil (org-element-property :UNNUMBERED head
)))
3953 (org-element-lineage headline nil t
))
3954 (let ((sec-num (plist-get info
:section-numbers
))
3955 (level (org-export-get-relative-level headline info
)))
3956 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))))
3958 (defun org-export-number-to-roman (n)
3959 "Convert integer N into a roman numeral."
3960 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
3961 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
3962 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
3966 (number-to-string n
)
3968 (if (>= n
(caar roman
))
3969 (setq n
(- n
(caar roman
))
3970 res
(concat res
(cdar roman
)))
3974 (defun org-export-get-tags (element info
&optional tags inherited
)
3975 "Return list of tags associated to ELEMENT.
3977 ELEMENT has either an `headline' or an `inlinetask' type. INFO
3978 is a plist used as a communication channel.
3980 When non-nil, optional argument TAGS should be a list of strings.
3981 Any tag belonging to this list will also be removed.
3983 When optional argument INHERITED is non-nil, tags can also be
3984 inherited from parent headlines and FILETAGS keywords."
3986 (lambda (tag) (member tag tags
))
3987 (if (not inherited
) (org-element-property :tags element
)
3988 ;; Build complete list of inherited tags.
3989 (let ((current-tag-list (org-element-property :tags element
)))
3990 (dolist (parent (org-element-lineage element
))
3991 (dolist (tag (org-element-property :tags parent
))
3992 (when (and (memq (org-element-type parent
) '(headline inlinetask
))
3993 (not (member tag current-tag-list
)))
3994 (push tag current-tag-list
))))
3995 ;; Add FILETAGS keywords and return results.
3996 (org-uniquify (append (plist-get info
:filetags
) current-tag-list
))))))
3998 (defun org-export-get-node-property (property blob
&optional inherited
)
3999 "Return node PROPERTY value for BLOB.
4001 PROPERTY is an upcase symbol (i.e. `:COOKIE_DATA'). BLOB is an
4004 If optional argument INHERITED is non-nil, the value can be
4005 inherited from a parent headline.
4007 Return value is a string or nil."
4008 (let ((headline (if (eq (org-element-type blob
) 'headline
) blob
4009 (org-export-get-parent-headline blob
))))
4010 (if (not inherited
) (org-element-property property blob
)
4011 (let ((parent headline
))
4014 (when (plist-member (nth 1 parent
) property
)
4015 (throw 'found
(org-element-property property parent
)))
4016 (setq parent
(org-element-property :parent parent
))))))))
4018 (defun org-export-get-category (blob info
)
4019 "Return category for element or object BLOB.
4021 INFO is a plist used as a communication channel.
4023 CATEGORY is automatically inherited from a parent headline, from
4024 #+CATEGORY: keyword or created out of original file name. If all
4025 fail, the fall-back value is \"???\"."
4026 (or (org-export-get-node-property :CATEGORY blob t
)
4027 (org-element-map (plist-get info
:parse-tree
) 'keyword
4029 (when (equal (org-element-property :key kwd
) "CATEGORY")
4030 (org-element-property :value kwd
)))
4032 (let ((file (plist-get info
:input-file
)))
4033 (and file
(file-name-sans-extension (file-name-nondirectory file
))))
4036 (defun org-export-get-alt-title (headline _
)
4037 "Return alternative title for HEADLINE, as a secondary string.
4038 If no optional title is defined, fall-back to the regular title."
4039 (let ((alt (org-element-property :ALT_TITLE headline
)))
4040 (if alt
(org-element-parse-secondary-string
4041 alt
(org-element-restriction 'headline
) headline
)
4042 (org-element-property :title headline
))))
4044 (defun org-export-first-sibling-p (blob info
)
4045 "Non-nil when BLOB is the first sibling in its parent.
4046 BLOB is an element or an object. If BLOB is a headline, non-nil
4047 means it is the first sibling in the sub-tree. INFO is a plist
4048 used as a communication channel."
4049 (memq (org-element-type (org-export-get-previous-element blob info
))
4052 (defun org-export-last-sibling-p (blob info
)
4053 "Non-nil when BLOB is the last sibling in its parent.
4054 BLOB is an element or an object. INFO is a plist used as
4055 a communication channel."
4056 (not (org-export-get-next-element blob info
)))
4061 ;; `org-export-get-date' returns a date appropriate for the document
4062 ;; to about to be exported. In particular, it takes care of
4063 ;; `org-export-date-timestamp-format'.
4065 (defun org-export-get-date (info &optional fmt
)
4066 "Return date value for the current document.
4068 INFO is a plist used as a communication channel. FMT, when
4069 non-nil, is a time format string that will be applied on the date
4070 if it consists in a single timestamp object. It defaults to
4071 `org-export-date-timestamp-format' when nil.
4073 A proper date can be a secondary string, a string or nil. It is
4074 meant to be translated with `org-export-data' or alike."
4075 (let ((date (plist-get info
:date
))
4076 (fmt (or fmt org-export-date-timestamp-format
)))
4077 (cond ((not date
) nil
)
4080 (eq (org-element-type (car date
)) 'timestamp
))
4081 (org-timestamp-format (car date
) fmt
))
4087 ;; `org-export-custom-protocol-maybe' handles custom protocol defined
4088 ;; in `org-link-parameters'.
4090 ;; `org-export-get-coderef-format' returns an appropriate format
4091 ;; string for coderefs.
4093 ;; `org-export-inline-image-p' returns a non-nil value when the link
4094 ;; provided should be considered as an inline image.
4096 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
4097 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
4098 ;; returns an appropriate unique identifier.
4100 ;; `org-export-resolve-id-link' returns the first headline with
4101 ;; specified id or custom-id in parse tree, the path to the external
4102 ;; file with the id.
4104 ;; `org-export-resolve-coderef' associates a reference to a line
4105 ;; number in the element it belongs, or returns the reference itself
4106 ;; when the element isn't numbered.
4108 ;; `org-export-file-uri' expands a filename as stored in :path value
4109 ;; of a "file" link into a file URI.
4111 ;; Broken links raise a `org-link-broken' error, which is caught by
4112 ;; `org-export-data' for further processing, depending on
4113 ;; `org-export-with-broken-links' value.
4115 (org-define-error 'org-link-broken
"Unable to resolve link; aborting")
4117 (defun org-export-custom-protocol-maybe (link desc backend
)
4118 "Try exporting LINK with a dedicated function.
4120 DESC is its description, as a string, or nil. BACKEND is the
4121 back-end used for export, as a symbol.
4123 Return output as a string, or nil if no protocol handles LINK.
4125 A custom protocol has precedence over regular back-end export.
4126 The function ignores links with an implicit type (e.g.,
4128 (let ((type (org-element-property :type link
)))
4129 (unless (or (member type
'("coderef" "custom-id" "fuzzy" "radio"))
4131 (let ((protocol (org-link-get-parameter type
:export
)))
4132 (and (functionp protocol
)
4134 (org-link-unescape (org-element-property :path link
))
4138 (defun org-export-get-coderef-format (path desc
)
4139 "Return format string for code reference link.
4140 PATH is the link path. DESC is its description."
4142 (cond ((not desc
) "%s")
4143 ((string-match (regexp-quote (concat "(" path
")")) desc
)
4144 (replace-match "%s" t t desc
))
4147 (defun org-export-inline-image-p (link &optional rules
)
4148 "Non-nil if LINK object points to an inline image.
4150 Optional argument is a set of RULES defining inline images. It
4151 is an alist where associations have the following shape:
4155 Applying a rule means apply REGEXP against LINK's path when its
4156 type is TYPE. The function will return a non-nil value if any of
4157 the provided rules is non-nil. The default rule is
4158 `org-export-default-inline-image-rule'.
4160 This only applies to links without a description."
4161 (and (not (org-element-contents link
))
4162 (let ((case-fold-search t
))
4163 (cl-some (lambda (rule)
4164 (and (string= (org-element-property :type link
) (car rule
))
4165 (string-match-p (cdr rule
)
4166 (org-element-property :path link
))))
4167 (or rules org-export-default-inline-image-rule
)))))
4169 (defun org-export-insert-image-links (data info
&optional rules
)
4170 "Insert image links in DATA.
4172 Org syntax do not support nested links. Nevertheless, some
4173 export back-ends support image as descriptions of links. Since
4174 images are really link to image files, we need to make an
4175 exception about link nesting.
4177 This function recognizes links whose contents are really images
4178 and turn them into proper nested links. It is meant to be used
4179 as a parse tree filter in back-ends supporting such constructs.
4181 DATA is a parse tree. INFO is the current state of the export
4182 process, as a plist.
4184 A description is a valid images if it matches any rule in RULES,
4185 if non-nil, or `org-export-default-inline-image-rule' otherwise.
4186 See `org-export-inline-image-p' for more information about the
4189 Return modified DATA."
4190 (let ((link-re (format "\\`\\(?:%s\\|%s\\)\\'"
4193 (case-fold-search t
))
4194 (org-element-map data
'link
4196 (let ((contents (org-element-interpret-data (org-element-contents l
))))
4197 (when (and (org-string-nw-p contents
)
4198 (string-match link-re contents
))
4199 (let ((type (match-string 1 contents
))
4200 (path (match-string 2 contents
)))
4201 (when (cl-some (lambda (rule)
4202 (and (string= type
(car rule
))
4203 (string-match-p (cdr rule
) path
)))
4204 (or rules org-export-default-inline-image-rule
))
4205 (org-element-set-contents
4208 (save-excursion (insert contents
))
4209 (org-element-link-parser))))))))
4213 (defun org-export-resolve-coderef (ref info
)
4214 "Resolve a code reference REF.
4216 INFO is a plist used as a communication channel.
4218 Return associated line number in source code, or REF itself,
4219 depending on src-block or example element's switches. Throw an
4220 error if no block contains REF."
4221 (or (org-element-map (plist-get info
:parse-tree
) '(example-block src-block
)
4224 (insert (org-trim (org-element-property :value el
)))
4225 (let* ((label-fmt (or (org-element-property :label-fmt el
)
4226 org-coderef-label-format
))
4227 (ref-re (org-src-coderef-regexp label-fmt ref
)))
4228 ;; Element containing REF is found. Resolve it to
4229 ;; either a label or a line number, as needed.
4230 (when (re-search-backward ref-re nil t
)
4231 (if (org-element-property :use-labels el
) ref
4232 (+ (or (org-export-get-loc el info
) 0)
4233 (line-number-at-pos)))))))
4235 (signal 'org-link-broken
(list ref
))))
4237 (defun org-export-search-cells (datum)
4238 "List search cells for element or object DATUM.
4240 A search cell follows the pattern (TYPE . SEARCH) where
4242 TYPE is a symbol among `headline', `custom-id', `target' and
4245 SEARCH is the string a link is expected to match. More
4248 - headline's title, as a list of strings, if TYPE is
4251 - CUSTOM_ID value, as a string, if TYPE is `custom-id'.
4253 - target's or radio-target's name as a list of strings if
4256 - NAME affiliated keyword is TYPE is `other'.
4258 A search cell is the internal representation of a fuzzy link. It
4259 ignores white spaces and statistics cookies, if applicable."
4260 (pcase (org-element-type datum
)
4262 (let ((title (split-string
4263 (replace-regexp-in-string
4264 "\\[[0-9]*\\(?:%\\|/[0-9]*\\)\\]" ""
4265 (org-element-property :raw-value datum
)))))
4268 (cons 'headline title
)
4270 (let ((custom-id (org-element-property :custom-id datum
)))
4271 (and custom-id
(cons 'custom-id custom-id
)))))))
4273 (list (cons 'target
(split-string (org-element-property :value datum
)))))
4274 ((and (let name
(org-element-property :name datum
))
4276 (list (cons 'other
(split-string name
))))
4279 (defun org-export-string-to-search-cell (s)
4280 "Return search cells associated to string S.
4281 S is either the path of a fuzzy link or a search option, i.e., it
4282 tries to match either a headline (through custom ID or title),
4283 a target or a named element."
4284 (pcase (string-to-char s
)
4285 (?
* (list (cons 'headline
(split-string (substring s
1)))))
4286 (?
# (list (cons 'custom-id
(substring s
1))))
4287 ((let search
(split-string s
))
4288 (list (cons 'target search
) (cons 'other search
)))))
4290 (defun org-export-match-search-cell-p (datum cells
)
4291 "Non-nil when DATUM matches search cells CELLS.
4292 DATUM is an element or object. CELLS is a list of search cells,
4293 as returned by `org-export-search-cells'."
4294 (let ((targets (org-export-search-cells datum
)))
4295 (and targets
(cl-some (lambda (cell) (member cell targets
)) cells
))))
4297 (defun org-export-resolve-fuzzy-link (link info
)
4298 "Return LINK destination.
4300 INFO is a plist holding contextual information.
4302 Return value can be an object or an element:
4304 - If LINK path matches a target object (i.e. <<path>>) return it.
4306 - If LINK path exactly matches the name affiliated keyword
4307 (i.e. #+NAME: path) of an element, return that element.
4309 - If LINK path exactly matches any headline name, return that
4312 - Otherwise, throw an error.
4314 Assume LINK type is \"fuzzy\". White spaces are not
4316 (let* ((search-cells (org-export-string-to-search-cell
4317 (org-link-unescape (org-element-property :path link
))))
4319 (or (plist-get info
:resolve-fuzzy-link-cache
)
4320 (plist-get (plist-put info
4321 :resolve-fuzzy-link-cache
4322 (make-hash-table :test
#'equal
))
4323 :resolve-fuzzy-link-cache
)))
4324 (cached (gethash search-cells link-cache
'not-found
)))
4325 (if (not (eq cached
'not-found
)) cached
4327 (org-element-map (plist-get info
:parse-tree
)
4328 (cons 'target org-element-all-elements
)
4330 (and (org-export-match-search-cell-p datum search-cells
)
4333 (signal 'org-link-broken
4334 (list (org-element-property :raw-path link
))))
4337 ;; There can be multiple matches for un-typed searches, i.e.,
4338 ;; for searches not starting with # or *. In this case,
4339 ;; prioritize targets and names over headline titles.
4340 ;; Matching both a name and a target is not valid, and
4341 ;; therefore undefined.
4342 (or (cl-some (lambda (datum)
4343 (and (not (eq (org-element-type datum
) 'headline
))
4349 (defun org-export-resolve-id-link (link info
)
4350 "Return headline referenced as LINK destination.
4352 INFO is a plist used as a communication channel.
4354 Return value can be the headline element matched in current parse
4355 tree or a file name. Assume LINK type is either \"id\" or
4356 \"custom-id\". Throw an error if no match is found."
4357 (let ((id (org-element-property :path link
)))
4358 ;; First check if id is within the current parse tree.
4359 (or (org-element-map (plist-get info
:parse-tree
) 'headline
4361 (when (or (equal (org-element-property :ID headline
) id
)
4362 (equal (org-element-property :CUSTOM_ID headline
) id
))
4365 ;; Otherwise, look for external files.
4366 (cdr (assoc id
(plist-get info
:id-alist
)))
4367 (signal 'org-link-broken
(list id
)))))
4369 (defun org-export-resolve-radio-link (link info
)
4370 "Return radio-target object referenced as LINK destination.
4372 INFO is a plist used as a communication channel.
4374 Return value can be a radio-target object or nil. Assume LINK
4375 has type \"radio\"."
4376 (let ((path (replace-regexp-in-string
4377 "[ \r\t\n]+" " " (org-element-property :path link
))))
4378 (org-element-map (plist-get info
:parse-tree
) 'radio-target
4380 (and (eq (compare-strings
4381 (replace-regexp-in-string
4382 "[ \r\t\n]+" " " (org-element-property :value radio
))
4383 nil nil path nil nil t
)
4386 info
'first-match
)))
4388 (defun org-export-file-uri (filename)
4389 "Return file URI associated to FILENAME."
4390 (cond ((string-match-p "\\`//" filename
) (concat "file:" filename
))
4391 ((not (file-name-absolute-p filename
)) filename
)
4392 ((org-file-remote-p filename
) (concat "file:/" filename
))
4393 (t (concat "file://" (expand-file-name filename
)))))
4398 ;; `org-export-get-reference' associate a unique reference for any
4399 ;; object or element. It uses `org-export-new-reference' and
4400 ;; `org-export-format-reference' to, respectively, generate new
4401 ;; internal references and turn them into a string suitable for
4404 ;; `org-export-get-ordinal' associates a sequence number to any object
4407 (defun org-export-new-reference (references)
4408 "Return a unique reference, among REFERENCES.
4409 REFERENCES is an alist whose values are in-use references, as
4410 numbers. Returns a number, which is the internal representation
4411 of a reference. See also `org-export-format-reference'."
4412 ;; Generate random 7 digits hexadecimal numbers. Collisions
4413 ;; increase exponentially with the numbers of references. However,
4414 ;; the odds for encountering at least one collision with 1000 active
4415 ;; references in the same document are roughly 0.2%, so this
4416 ;; shouldn't be the bottleneck.
4417 (let ((new (random #x10000000
)))
4418 (while (rassq new references
) (setq new
(random #x10000000
)))
4421 (defun org-export-format-reference (reference)
4422 "Format REFERENCE into a string.
4423 REFERENCE is a number representing a reference, as returned by
4424 `org-export-new-reference', which see."
4425 (format "org%07x" reference
))
4427 (defun org-export-get-reference (datum info
)
4428 "Return a unique reference for DATUM, as a string.
4430 DATUM is either an element or an object. INFO is the current
4431 export state, as a plist.
4433 This function checks `:crossrefs' property in INFO for search
4434 cells matching DATUM before creating a new reference. Returned
4435 reference consists of alphanumeric characters only."
4436 (let ((cache (plist-get info
:internal-references
)))
4437 (or (car (rassq datum cache
))
4438 (let* ((crossrefs (plist-get info
:crossrefs
))
4439 (cells (org-export-search-cells datum
))
4440 ;; Preserve any pre-existing association between
4441 ;; a search cell and a reference, i.e., when some
4442 ;; previously published document referenced a location
4443 ;; within current file (see
4444 ;; `org-publish-resolve-external-link').
4446 ;; However, there is no guarantee that search cells are
4447 ;; unique, e.g., there might be duplicate custom ID or
4448 ;; two headings with the same title in the file.
4450 ;; As a consequence, before re-using any reference to
4451 ;; an element or object, we check that it doesn't refer
4452 ;; to a previous element or object.
4455 (let ((stored (cdr (assoc cell crossrefs
))))
4457 (let ((old (org-export-format-reference stored
)))
4458 (and (not (assoc old cache
)) stored
)))))
4460 (org-export-new-reference cache
)))
4461 (reference-string (org-export-format-reference new
)))
4462 ;; Cache contains both data already associated to
4463 ;; a reference and in-use internal references, so as to make
4464 ;; unique references.
4465 (dolist (cell cells
) (push (cons cell new
) cache
))
4466 ;; Retain a direct association between reference string and
4467 ;; DATUM since (1) not every object or element can be given
4468 ;; a search cell (2) it permits quick lookup.
4469 (push (cons reference-string datum
) cache
)
4470 (plist-put info
:internal-references cache
)
4471 reference-string
))))
4473 (defun org-export-get-ordinal (element info
&optional types predicate
)
4474 "Return ordinal number of an element or object.
4476 ELEMENT is the element or object considered. INFO is the plist
4477 used as a communication channel.
4479 Optional argument TYPES, when non-nil, is a list of element or
4480 object types, as symbols, that should also be counted in.
4481 Otherwise, only provided element's type is considered.
4483 Optional argument PREDICATE is a function returning a non-nil
4484 value if the current element or object should be counted in. It
4485 accepts two arguments: the element or object being considered and
4486 the plist used as a communication channel. This allows counting
4487 only a certain type of object (i.e. inline images).
4489 Return value is a list of numbers if ELEMENT is a headline or an
4490 item. It is nil for keywords. It represents the footnote number
4491 for footnote definitions and footnote references. If ELEMENT is
4492 a target, return the same value as if ELEMENT was the closest
4493 table, item or headline containing the target. In any other
4494 case, return the sequence number of ELEMENT among elements or
4495 objects of the same type."
4496 ;; Ordinal of a target object refer to the ordinal of the closest
4497 ;; table, item, or headline containing the object.
4498 (when (eq (org-element-type element
) 'target
)
4500 (org-element-lineage
4502 '(footnote-definition footnote-reference headline item table
))))
4503 (cl-case (org-element-type element
)
4504 ;; Special case 1: A headline returns its number as a list.
4505 (headline (org-export-get-headline-number element info
))
4506 ;; Special case 2: An item returns its number as a list.
4507 (item (let ((struct (org-element-property :structure element
)))
4508 (org-list-get-item-number
4509 (org-element-property :begin element
)
4511 (org-list-prevs-alist struct
)
4512 (org-list-parents-alist struct
))))
4513 ((footnote-definition footnote-reference
)
4514 (org-export-get-footnote-number element info
))
4517 ;; Increment counter until ELEMENT is found again.
4518 (org-element-map (plist-get info
:parse-tree
)
4519 (or types
(org-element-type element
))
4522 ((eq element el
) (1+ counter
))
4523 ((not predicate
) (cl-incf counter
) nil
)
4524 ((funcall predicate el info
) (cl-incf counter
) nil
)))
4525 info
'first-match
)))))
4530 ;; `org-export-get-loc' counts number of code lines accumulated in
4531 ;; src-block or example-block elements with a "+n" switch until
4532 ;; a given element, excluded. Note: "-n" switches reset that count.
4534 ;; `org-export-unravel-code' extracts source code (along with a code
4535 ;; references alist) from an `element-block' or `src-block' type
4538 ;; `org-export-format-code' applies a formatting function to each line
4539 ;; of code, providing relative line number and code reference when
4540 ;; appropriate. Since it doesn't access the original element from
4541 ;; which the source code is coming, it expects from the code calling
4542 ;; it to know if lines should be numbered and if code references
4545 ;; Eventually, `org-export-format-code-default' is a higher-level
4546 ;; function (it makes use of the two previous functions) which handles
4547 ;; line numbering and code references inclusion, and returns source
4548 ;; code in a format suitable for plain text or verbatim output.
4550 (defun org-export-get-loc (element info
)
4551 "Return count of lines of code before ELEMENT.
4553 ELEMENT is an example-block or src-block element. INFO is the
4554 plist used as a communication channel.
4556 Count includes every line of code in example-block or src-block
4557 with a \"+n\" or \"-n\" switch before block. Return nil if
4558 ELEMENT doesn't allow line numbering."
4559 (pcase (org-element-property :number-lines element
)
4563 (org-element-map (plist-get info
:parse-tree
) '(src-block example-block
)
4565 ;; ELEMENT is reached: Quit loop and return locs.
4566 (if (eq el element
) (+ loc n
)
4567 ;; Only count lines from src-block and example-block
4568 ;; elements with a "+n" or "-n" switch.
4569 (let ((linum (org-element-property :number-lines el
)))
4571 (let ((lines (org-count-lines
4572 (org-trim (org-element-property :value el
)))))
4573 ;; Accumulate locs or reset them.
4575 (`(new .
,n
) (setq loc
(+ n lines
)))
4576 (`(continued .
,n
) (cl-incf loc
(+ n lines
)))))))
4577 nil
)) ;Return nil to stay in the loop.
4578 info
'first-match
)))))
4580 (defun org-export-unravel-code (element)
4581 "Clean source code and extract references out of it.
4583 ELEMENT has either a `src-block' an `example-block' type.
4585 Return a cons cell whose CAR is the source code, cleaned from any
4586 reference, protective commas and spurious indentation, and CDR is
4587 an alist between relative line number (integer) and name of code
4588 reference on that line (string)."
4589 (let* ((line 0) refs
4590 (value (org-element-property :value element
))
4591 ;; Get code and clean it. Remove blank lines at its
4592 ;; beginning and end.
4593 (code (replace-regexp-in-string
4594 "\\`\\([ \t]*\n\\)+" ""
4595 (replace-regexp-in-string
4596 "\\([ \t]*\n\\)*[ \t]*\\'" "\n"
4597 (if (or org-src-preserve-indentation
4598 (org-element-property :preserve-indent element
))
4600 (org-remove-indentation value
)))))
4601 ;; Build a regexp matching a loc with a reference.
4602 (ref-re (org-src-coderef-regexp (org-src-coderef-format element
))))
4605 ;; Code with references removed.
4606 (org-element-normalize-string
4610 (if (not (string-match ref-re loc
)) loc
4611 ;; Ref line: remove ref, and signal its position in REFS.
4612 (push (cons line
(match-string 3 loc
)) refs
)
4613 (replace-match "" nil nil loc
1)))
4614 (org-split-string code
"\n") "\n"))
4618 (defun org-export-format-code (code fun
&optional num-lines ref-alist
)
4619 "Format CODE by applying FUN line-wise and return it.
4621 CODE is a string representing the code to format. FUN is
4622 a function. It must accept three arguments: a line of
4623 code (string), the current line number (integer) or nil and the
4624 reference associated to the current line (string) or nil.
4626 Optional argument NUM-LINES can be an integer representing the
4627 number of code lines accumulated until the current code. Line
4628 numbers passed to FUN will take it into account. If it is nil,
4629 FUN's second argument will always be nil. This number can be
4630 obtained with `org-export-get-loc' function.
4632 Optional argument REF-ALIST can be an alist between relative line
4633 number (i.e. ignoring NUM-LINES) and the name of the code
4634 reference on it. If it is nil, FUN's third argument will always
4635 be nil. It can be obtained through the use of
4636 `org-export-unravel-code' function."
4637 (let ((--locs (org-split-string code
"\n"))
4639 (org-element-normalize-string
4643 (let ((--ref (cdr (assq --line ref-alist
))))
4644 (funcall fun --loc
(and num-lines
(+ num-lines --line
)) --ref
)))
4647 (defun org-export-format-code-default (element info
)
4648 "Return source code from ELEMENT, formatted in a standard way.
4650 ELEMENT is either a `src-block' or `example-block' element. INFO
4651 is a plist used as a communication channel.
4653 This function takes care of line numbering and code references
4654 inclusion. Line numbers, when applicable, appear at the
4655 beginning of the line, separated from the code by two white
4656 spaces. Code references, on the other hand, appear flushed to
4657 the right, separated by six white spaces from the widest line of
4659 ;; Extract code and references.
4660 (let* ((code-info (org-export-unravel-code element
))
4661 (code (car code-info
))
4662 (code-lines (org-split-string code
"\n")))
4663 (if (null code-lines
) ""
4664 (let* ((refs (and (org-element-property :retain-labels element
)
4666 ;; Handle line numbering.
4667 (num-start (org-export-get-loc element info
))
4671 (length (number-to-string
4672 (+ (length code-lines
) num-start
))))))
4673 ;; Prepare references display, if required. Any reference
4674 ;; should start six columns after the widest line of code,
4675 ;; wrapped with parenthesis.
4677 (+ (apply 'max
(mapcar 'length code-lines
))
4678 (if (not num-start
) 0 (length (format num-fmt num-start
))))))
4679 (org-export-format-code
4681 (lambda (loc line-num ref
)
4682 (let ((number-str (and num-fmt
(format num-fmt line-num
))))
4687 (concat (make-string
4689 (+ (length loc
) (length number-str
))) ?
)
4690 (format "(%s)" ref
))))))
4696 ;; `org-export-table-has-special-column-p' and and
4697 ;; `org-export-table-row-is-special-p' are predicates used to look for
4698 ;; meta-information about the table structure.
4700 ;; `org-table-has-header-p' tells when the rows before the first rule
4701 ;; should be considered as table's header.
4703 ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
4704 ;; and `org-export-table-cell-borders' extract information from
4705 ;; a table-cell element.
4707 ;; `org-export-table-dimensions' gives the number on rows and columns
4708 ;; in the table, ignoring horizontal rules and special columns.
4709 ;; `org-export-table-cell-address', given a table-cell object, returns
4710 ;; the absolute address of a cell. On the other hand,
4711 ;; `org-export-get-table-cell-at' does the contrary.
4713 ;; `org-export-table-cell-starts-colgroup-p',
4714 ;; `org-export-table-cell-ends-colgroup-p',
4715 ;; `org-export-table-row-starts-rowgroup-p',
4716 ;; `org-export-table-row-ends-rowgroup-p',
4717 ;; `org-export-table-row-starts-header-p',
4718 ;; `org-export-table-row-ends-header-p' and
4719 ;; `org-export-table-row-in-header-p' indicate position of current row
4720 ;; or cell within the table.
4722 (defun org-export-table-has-special-column-p (table)
4723 "Non-nil when TABLE has a special column.
4724 All special columns will be ignored during export."
4725 ;; The table has a special column when every first cell of every row
4726 ;; has an empty value or contains a symbol among "/", "#", "!", "$",
4727 ;; "*" "_" and "^". Though, do not consider a first row containing
4728 ;; only empty cells as special.
4729 (let ((special-column-p 'empty
))
4731 (dolist (row (org-element-contents table
))
4732 (when (eq (org-element-property :type row
) 'standard
)
4733 (let ((value (org-element-contents
4734 (car (org-element-contents row
)))))
4735 (cond ((member value
'(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
4736 (setq special-column-p
'special
))
4738 (t (throw 'exit nil
))))))
4739 (eq special-column-p
'special
))))
4741 (defun org-export-table-has-header-p (table info
)
4742 "Non-nil when TABLE has a header.
4744 INFO is a plist used as a communication channel.
4746 A table has a header when it contains at least two row groups."
4747 (let ((cache (or (plist-get info
:table-header-cache
)
4748 (plist-get (setq info
4749 (plist-put info
:table-header-cache
4750 (make-hash-table :test
'eq
)))
4751 :table-header-cache
))))
4752 (or (gethash table cache
)
4753 (let ((rowgroup 1) row-flag
)
4756 (org-element-map table
'table-row
4760 ((and row-flag
(eq (org-element-property :type row
) 'rule
))
4761 (cl-incf rowgroup
) (setq row-flag nil
))
4762 ((and (not row-flag
) (eq (org-element-property :type row
)
4764 (setq row-flag t
) nil
)))
4768 (defun org-export-table-row-is-special-p (table-row _
)
4769 "Non-nil if TABLE-ROW is considered special.
4770 All special rows will be ignored during export."
4771 (when (eq (org-element-property :type table-row
) 'standard
)
4772 (let ((first-cell (org-element-contents
4773 (car (org-element-contents table-row
)))))
4774 ;; A row is special either when...
4776 ;; ... it starts with a field only containing "/",
4777 (equal first-cell
'("/"))
4778 ;; ... the table contains a special column and the row start
4779 ;; with a marking character among, "^", "_", "$" or "!",
4780 (and (org-export-table-has-special-column-p
4781 (org-export-get-parent table-row
))
4782 (member first-cell
'(("^") ("_") ("$") ("!"))))
4783 ;; ... it contains only alignment cookies and empty cells.
4784 (let ((special-row-p 'empty
))
4786 (dolist (cell (org-element-contents table-row
))
4787 (let ((value (org-element-contents cell
)))
4788 ;; Since VALUE is a secondary string, the following
4789 ;; checks avoid expanding it with `org-export-data'.
4791 ((and (not (cdr value
))
4792 (stringp (car value
))
4793 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
4795 (setq special-row-p
'cookie
))
4796 (t (throw 'exit nil
)))))
4797 (eq special-row-p
'cookie
)))))))
4799 (defun org-export-table-row-group (table-row info
)
4800 "Return TABLE-ROW's group number, as an integer.
4802 INFO is a plist used as the communication channel.
4804 Return value is the group number, as an integer, or nil for
4805 special rows and rows separators. First group is also table's
4807 (let ((cache (or (plist-get info
:table-row-group-cache
)
4808 (plist-get (setq info
4809 (plist-put info
:table-row-group-cache
4810 (make-hash-table :test
'eq
)))
4811 :table-row-group-cache
))))
4812 (cond ((gethash table-row cache
))
4813 ((eq (org-element-property :type table-row
) 'rule
) nil
)
4814 (t (let ((group 0) row-flag
)
4815 (org-element-map (org-export-get-parent table-row
) 'table-row
4817 (if (eq (org-element-property :type row
) 'rule
)
4819 (unless row-flag
(cl-incf group
) (setq row-flag t
)))
4820 (when (eq table-row row
) (puthash table-row group cache
)))
4821 info
'first-match
))))))
4823 (defun org-export-table-cell-width (table-cell info
)
4824 "Return TABLE-CELL contents width.
4826 INFO is a plist used as the communication channel.
4828 Return value is the width given by the last width cookie in the
4829 same column as TABLE-CELL, or nil."
4830 (let* ((row (org-export-get-parent table-cell
))
4831 (table (org-export-get-parent row
))
4832 (cells (org-element-contents row
))
4833 (columns (length cells
))
4834 (column (- columns
(length (memq table-cell cells
))))
4835 (cache (or (plist-get info
:table-cell-width-cache
)
4836 (plist-get (setq info
4837 (plist-put info
:table-cell-width-cache
4838 (make-hash-table :test
'eq
)))
4839 :table-cell-width-cache
)))
4840 (width-vector (or (gethash table cache
)
4841 (puthash table
(make-vector columns
'empty
) cache
)))
4842 (value (aref width-vector column
)))
4843 (if (not (eq value
'empty
)) value
4845 (dolist (row (org-element-contents table
)
4846 (aset width-vector column cookie-width
))
4847 (when (org-export-table-row-is-special-p row info
)
4848 ;; In a special row, try to find a width cookie at COLUMN.
4849 (let* ((value (org-element-contents
4850 (elt (org-element-contents row
) column
)))
4851 (cookie (car value
)))
4852 ;; The following checks avoid expanding unnecessarily
4853 ;; the cell with `org-export-data'.
4857 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" cookie
)
4858 (match-string 1 cookie
))
4860 (string-to-number (match-string 1 cookie
)))))))))))
4862 (defun org-export-table-cell-alignment (table-cell info
)
4863 "Return TABLE-CELL contents alignment.
4865 INFO is a plist used as the communication channel.
4867 Return alignment as specified by the last alignment cookie in the
4868 same column as TABLE-CELL. If no such cookie is found, a default
4869 alignment value will be deduced from fraction of numbers in the
4870 column (see `org-table-number-fraction' for more information).
4871 Possible values are `left', `right' and `center'."
4872 ;; Load `org-table-number-fraction' and `org-table-number-regexp'.
4873 (require 'org-table
)
4874 (let* ((row (org-export-get-parent table-cell
))
4875 (table (org-export-get-parent row
))
4876 (cells (org-element-contents row
))
4877 (columns (length cells
))
4878 (column (- columns
(length (memq table-cell cells
))))
4879 (cache (or (plist-get info
:table-cell-alignment-cache
)
4880 (plist-get (setq info
4881 (plist-put info
:table-cell-alignment-cache
4882 (make-hash-table :test
'eq
)))
4883 :table-cell-alignment-cache
)))
4884 (align-vector (or (gethash table cache
)
4885 (puthash table
(make-vector columns nil
) cache
))))
4886 (or (aref align-vector column
)
4887 (let ((number-cells 0)
4890 previous-cell-number-p
)
4891 (dolist (row (org-element-contents (org-export-get-parent row
)))
4893 ;; In a special row, try to find an alignment cookie at
4895 ((org-export-table-row-is-special-p row info
)
4896 (let ((value (org-element-contents
4897 (elt (org-element-contents row
) column
))))
4898 ;; Since VALUE is a secondary string, the following
4899 ;; checks avoid useless expansion through
4900 ;; `org-export-data'.
4903 (stringp (car value
))
4904 (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
4906 (match-string 1 (car value
)))
4907 (setq cookie-align
(match-string 1 (car value
))))))
4908 ;; Ignore table rules.
4909 ((eq (org-element-property :type row
) 'rule
))
4910 ;; In a standard row, check if cell's contents are
4911 ;; expressing some kind of number. Increase NUMBER-CELLS
4912 ;; accordingly. Though, don't bother if an alignment
4913 ;; cookie has already defined cell's alignment.
4915 (let ((value (org-export-data
4916 (org-element-contents
4917 (elt (org-element-contents row
) column
))
4919 (cl-incf total-cells
)
4920 ;; Treat an empty cell as a number if it follows
4922 (if (not (or (string-match org-table-number-regexp value
)
4923 (and (string= value
"") previous-cell-number-p
)))
4924 (setq previous-cell-number-p nil
)
4925 (setq previous-cell-number-p t
)
4926 (cl-incf number-cells
))))))
4927 ;; Return value. Alignment specified by cookies has
4928 ;; precedence over alignment deduced from cell's contents.
4931 (cond ((equal cookie-align
"l") 'left
)
4932 ((equal cookie-align
"r") 'right
)
4933 ((equal cookie-align
"c") 'center
)
4934 ((>= (/ (float number-cells
) total-cells
)
4935 org-table-number-fraction
)
4939 (defun org-export-table-cell-borders (table-cell info
)
4940 "Return TABLE-CELL borders.
4942 INFO is a plist used as a communication channel.
4944 Return value is a list of symbols, or nil. Possible values are:
4945 `top', `bottom', `above', `below', `left' and `right'. Note:
4946 `top' (resp. `bottom') only happen for a cell in the first
4947 row (resp. last row) of the table, ignoring table rules, if any.
4949 Returned borders ignore special rows."
4950 (let* ((row (org-export-get-parent table-cell
))
4951 (table (org-export-get-parent-table table-cell
))
4953 ;; Top/above border? TABLE-CELL has a border above when a rule
4954 ;; used to demarcate row groups can be found above. Hence,
4955 ;; finding a rule isn't sufficient to push `above' in BORDERS:
4956 ;; another regular row has to be found above that rule.
4959 ;; Look at every row before the current one.
4960 (dolist (row (cdr (memq row
(reverse (org-element-contents table
)))))
4961 (cond ((eq (org-element-property :type row
) 'rule
)
4963 ((not (org-export-table-row-is-special-p row info
))
4964 (if rule-flag
(throw 'exit
(push 'above borders
))
4965 (throw 'exit nil
)))))
4966 ;; No rule above, or rule found starts the table (ignoring any
4967 ;; special row): TABLE-CELL is at the top of the table.
4968 (when rule-flag
(push 'above borders
))
4969 (push 'top borders
)))
4970 ;; Bottom/below border? TABLE-CELL has a border below when next
4971 ;; non-regular row below is a rule.
4974 ;; Look at every row after the current one.
4975 (dolist (row (cdr (memq row
(org-element-contents table
))))
4976 (cond ((eq (org-element-property :type row
) 'rule
)
4978 ((not (org-export-table-row-is-special-p row info
))
4979 (if rule-flag
(throw 'exit
(push 'below borders
))
4980 (throw 'exit nil
)))))
4981 ;; No rule below, or rule found ends the table (modulo some
4982 ;; special row): TABLE-CELL is at the bottom of the table.
4983 (when rule-flag
(push 'below borders
))
4984 (push 'bottom borders
)))
4985 ;; Right/left borders? They can only be specified by column
4986 ;; groups. Column groups are defined in a row starting with "/".
4987 ;; Also a column groups row only contains "<", "<>", ">" or blank
4990 (let ((column (let ((cells (org-element-contents row
)))
4991 (- (length cells
) (length (memq table-cell cells
))))))
4992 ;; Table rows are read in reverse order so last column groups
4993 ;; row has precedence over any previous one.
4994 (dolist (row (reverse (org-element-contents table
)))
4995 (unless (eq (org-element-property :type row
) 'rule
)
4996 (when (equal (org-element-contents
4997 (car (org-element-contents row
)))
4999 (let ((column-groups
5002 (let ((value (org-element-contents cell
)))
5003 (when (member value
'(("<") ("<>") (">") nil
))
5005 (org-element-contents row
))))
5006 ;; There's a left border when previous cell, if
5007 ;; any, ends a group, or current one starts one.
5008 (when (or (and (not (zerop column
))
5009 (member (elt column-groups
(1- column
))
5011 (member (elt column-groups column
) '("<" "<>")))
5012 (push 'left borders
))
5013 ;; There's a right border when next cell, if any,
5014 ;; starts a group, or current one ends one.
5015 (when (or (and (/= (1+ column
) (length column-groups
))
5016 (member (elt column-groups
(1+ column
))
5018 (member (elt column-groups column
) '(">" "<>")))
5019 (push 'right borders
))
5020 (throw 'exit nil
)))))))
5024 (defun org-export-table-cell-starts-colgroup-p (table-cell info
)
5025 "Non-nil when TABLE-CELL is at the beginning of a column group.
5026 INFO is a plist used as a communication channel."
5027 ;; A cell starts a column group either when it is at the beginning
5028 ;; of a row (or after the special column, if any) or when it has
5030 (or (eq (org-element-map (org-export-get-parent table-cell
) 'table-cell
5031 'identity info
'first-match
)
5033 (memq 'left
(org-export-table-cell-borders table-cell info
))))
5035 (defun org-export-table-cell-ends-colgroup-p (table-cell info
)
5036 "Non-nil when TABLE-CELL is at the end of a column group.
5037 INFO is a plist used as a communication channel."
5038 ;; A cell ends a column group either when it is at the end of a row
5039 ;; or when it has a right border.
5040 (or (eq (car (last (org-element-contents
5041 (org-export-get-parent table-cell
))))
5043 (memq 'right
(org-export-table-cell-borders table-cell info
))))
5045 (defun org-export-table-row-starts-rowgroup-p (table-row info
)
5046 "Non-nil when TABLE-ROW is at the beginning of a row group.
5047 INFO is a plist used as a communication channel."
5048 (unless (or (eq (org-element-property :type table-row
) 'rule
)
5049 (org-export-table-row-is-special-p table-row info
))
5050 (let ((borders (org-export-table-cell-borders
5051 (car (org-element-contents table-row
)) info
)))
5052 (or (memq 'top borders
) (memq 'above borders
)))))
5054 (defun org-export-table-row-ends-rowgroup-p (table-row info
)
5055 "Non-nil when TABLE-ROW is at the end of a row group.
5056 INFO is a plist used as a communication channel."
5057 (unless (or (eq (org-element-property :type table-row
) 'rule
)
5058 (org-export-table-row-is-special-p table-row info
))
5059 (let ((borders (org-export-table-cell-borders
5060 (car (org-element-contents table-row
)) info
)))
5061 (or (memq 'bottom borders
) (memq 'below borders
)))))
5063 (defun org-export-table-row-in-header-p (table-row info
)
5064 "Non-nil when TABLE-ROW is located within table's header.
5065 INFO is a plist used as a communication channel. Always return
5066 nil for special rows and rows separators."
5067 (and (org-export-table-has-header-p
5068 (org-export-get-parent-table table-row
) info
)
5069 (eql (org-export-table-row-group table-row info
) 1)))
5071 (defun org-export-table-row-starts-header-p (table-row info
)
5072 "Non-nil when TABLE-ROW is the first table header's row.
5073 INFO is a plist used as a communication channel."
5074 (and (org-export-table-row-in-header-p table-row info
)
5075 (org-export-table-row-starts-rowgroup-p table-row info
)))
5077 (defun org-export-table-row-ends-header-p (table-row info
)
5078 "Non-nil when TABLE-ROW is the last table header's row.
5079 INFO is a plist used as a communication channel."
5080 (and (org-export-table-row-in-header-p table-row info
)
5081 (org-export-table-row-ends-rowgroup-p table-row info
)))
5083 (defun org-export-table-row-number (table-row info
)
5084 "Return TABLE-ROW number.
5085 INFO is a plist used as a communication channel. Return value is
5086 zero-based and ignores separators. The function returns nil for
5087 special columns and separators."
5088 (when (and (eq (org-element-property :type table-row
) 'standard
)
5089 (not (org-export-table-row-is-special-p table-row info
)))
5091 (org-element-map (org-export-get-parent-table table-row
) 'table-row
5093 (cond ((eq row table-row
) number
)
5094 ((eq (org-element-property :type row
) 'standard
)
5095 (cl-incf number
) nil
)))
5096 info
'first-match
))))
5098 (defun org-export-table-dimensions (table info
)
5099 "Return TABLE dimensions.
5101 INFO is a plist used as a communication channel.
5103 Return value is a CONS like (ROWS . COLUMNS) where
5104 ROWS (resp. COLUMNS) is the number of exportable
5105 rows (resp. columns)."
5106 (let (first-row (columns 0) (rows 0))
5107 ;; Set number of rows, and extract first one.
5108 (org-element-map table
'table-row
5110 (when (eq (org-element-property :type row
) 'standard
)
5112 (unless first-row
(setq first-row row
)))) info
)
5113 ;; Set number of columns.
5114 (org-element-map first-row
'table-cell
(lambda (_) (cl-incf columns
)) info
)
5116 (cons rows columns
)))
5118 (defun org-export-table-cell-address (table-cell info
)
5119 "Return address of a regular TABLE-CELL object.
5121 TABLE-CELL is the cell considered. INFO is a plist used as
5122 a communication channel.
5124 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
5125 zero-based index. Only exportable cells are considered. The
5126 function returns nil for other cells."
5127 (let* ((table-row (org-export-get-parent table-cell
))
5128 (row-number (org-export-table-row-number table-row info
)))
5131 (let ((col-count 0))
5132 (org-element-map table-row
'table-cell
5134 (if (eq cell table-cell
) col-count
(cl-incf col-count
) nil
))
5135 info
'first-match
))))))
5137 (defun org-export-get-table-cell-at (address table info
)
5138 "Return regular table-cell object at ADDRESS in TABLE.
5140 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
5141 zero-based index. TABLE is a table type element. INFO is
5142 a plist used as a communication channel.
5144 If no table-cell, among exportable cells, is found at ADDRESS,
5146 (let ((column-pos (cdr address
)) (column-count 0))
5148 ;; Row at (car address) or nil.
5149 (let ((row-pos (car address
)) (row-count 0))
5150 (org-element-map table
'table-row
5152 (cond ((eq (org-element-property :type row
) 'rule
) nil
)
5153 ((= row-count row-pos
) row
)
5154 (t (cl-incf row-count
) nil
)))
5158 (if (= column-count column-pos
) cell
5159 (cl-incf column-count
) nil
))
5160 info
'first-match
)))
5163 ;;;; For Tables Of Contents
5165 ;; `org-export-collect-headlines' builds a list of all exportable
5166 ;; headline elements, maybe limited to a certain depth. One can then
5167 ;; easily parse it and transcode it.
5169 ;; Building lists of tables, figures or listings is quite similar.
5170 ;; Once the generic function `org-export-collect-elements' is defined,
5171 ;; `org-export-collect-tables', `org-export-collect-figures' and
5172 ;; `org-export-collect-listings' can be derived from it.
5174 (defun org-export-collect-headlines (info &optional n scope
)
5175 "Collect headlines in order to build a table of contents.
5177 INFO is a plist used as a communication channel.
5179 When optional argument N is an integer, it specifies the depth of
5180 the table of contents. Otherwise, it is set to the value of the
5181 last headline level. See `org-export-headline-levels' for more
5184 Optional argument SCOPE, when non-nil, is an element. If it is
5185 a headline, only children of SCOPE are collected. Otherwise,
5186 collect children of the headline containing provided element. If
5187 there is no such headline, collect all headlines. In any case,
5188 argument N becomes relative to the level of that headline.
5190 Return a list of all exportable headlines as parsed elements.
5191 Footnote sections are ignored."
5192 (let* ((scope (cond ((not scope
) (plist-get info
:parse-tree
))
5193 ((eq (org-element-type scope
) 'headline
) scope
)
5194 ((org-export-get-parent-headline scope
))
5195 (t (plist-get info
:parse-tree
))))
5196 (limit (plist-get info
:headline-levels
))
5197 (n (if (not (wholenump n
)) limit
5198 (min (if (eq (org-element-type scope
) 'org-data
) n
5199 (+ (org-export-get-relative-level scope info
) n
))
5201 (org-element-map (org-element-contents scope
) 'headline
5203 (unless (org-element-property :footnote-section-p headline
)
5204 (let ((level (org-export-get-relative-level headline info
)))
5205 (and (<= level n
) headline
))))
5208 (defun org-export-collect-elements (type info
&optional predicate
)
5209 "Collect referenceable elements of a determined type.
5211 TYPE can be a symbol or a list of symbols specifying element
5212 types to search. Only elements with a caption are collected.
5214 INFO is a plist used as a communication channel.
5216 When non-nil, optional argument PREDICATE is a function accepting
5217 one argument, an element of type TYPE. It returns a non-nil
5218 value when that element should be collected.
5220 Return a list of all elements found, in order of appearance."
5221 (org-element-map (plist-get info
:parse-tree
) type
5223 (and (org-element-property :caption element
)
5224 (or (not predicate
) (funcall predicate element
))
5228 (defun org-export-collect-tables (info)
5229 "Build a list of tables.
5230 INFO is a plist used as a communication channel.
5232 Return a list of table elements with a caption."
5233 (org-export-collect-elements 'table info
))
5235 (defun org-export-collect-figures (info predicate
)
5236 "Build a list of figures.
5238 INFO is a plist used as a communication channel. PREDICATE is
5239 a function which accepts one argument: a paragraph element and
5240 whose return value is non-nil when that element should be
5243 A figure is a paragraph type element, with a caption, verifying
5244 PREDICATE. The latter has to be provided since a \"figure\" is
5245 a vague concept that may depend on back-end.
5247 Return a list of elements recognized as figures."
5248 (org-export-collect-elements 'paragraph info predicate
))
5250 (defun org-export-collect-listings (info)
5251 "Build a list of src blocks.
5253 INFO is a plist used as a communication channel.
5255 Return a list of src-block elements with a caption."
5256 (org-export-collect-elements 'src-block info
))
5261 ;; The main function for the smart quotes sub-system is
5262 ;; `org-export-activate-smart-quotes', which replaces every quote in
5263 ;; a given string from the parse tree with its "smart" counterpart.
5265 ;; Dictionary for smart quotes is stored in
5266 ;; `org-export-smart-quotes-alist'.
5268 (defconst org-export-smart-quotes-alist
5270 ;; one may use: »...«, "...", ›...‹, or '...'.
5271 ;; http://sproget.dk/raad-og-regler/retskrivningsregler/retskrivningsregler/a7-40-60/a7-58-anforselstegn/
5272 ;; LaTeX quotes require Babel!
5274 :utf-8
"»" :html
"»" :latex
">>" :texinfo
"@guillemetright{}")
5276 :utf-8
"«" :html
"«" :latex
"<<" :texinfo
"@guillemetleft{}")
5278 :utf-8
"›" :html
"›" :latex
"\\frq{}" :texinfo
"@guilsinglright{}")
5280 :utf-8
"‹" :html
"‹" :latex
"\\flq{}" :texinfo
"@guilsingleft{}")
5281 (apostrophe :utf-8
"’" :html
"’"))
5284 :utf-8
"„" :html
"„" :latex
"\"`" :texinfo
"@quotedblbase{}")
5286 :utf-8
"“" :html
"“" :latex
"\"'" :texinfo
"@quotedblleft{}")
5288 :utf-8
"‚" :html
"‚" :latex
"\\glq{}" :texinfo
"@quotesinglbase{}")
5290 :utf-8
"‘" :html
"‘" :latex
"\\grq{}" :texinfo
"@quoteleft{}")
5291 (apostrophe :utf-8
"’" :html
"’"))
5293 (primary-opening :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
5294 (primary-closing :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
5295 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5296 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5297 (apostrophe :utf-8
"’" :html
"’"))
5300 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5301 :texinfo
"@guillemetleft{}")
5303 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5304 :texinfo
"@guillemetright{}")
5305 (secondary-opening :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
5306 (secondary-closing :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
5307 (apostrophe :utf-8
"’" :html
"’"))
5310 :utf-8
"« " :html
"« " :latex
"\\og "
5311 :texinfo
"@guillemetleft{}@tie{}")
5313 :utf-8
" »" :html
" »" :latex
"\\fg{}"
5314 :texinfo
"@tie{}@guillemetright{}")
5316 :utf-8
"« " :html
"« " :latex
"\\og "
5317 :texinfo
"@guillemetleft{}@tie{}")
5318 (secondary-closing :utf-8
" »" :html
" »" :latex
"\\fg{}"
5319 :texinfo
"@tie{}@guillemetright{}")
5320 (apostrophe :utf-8
"’" :html
"’"))
5323 :utf-8
"„" :html
"„" :latex
"\"`" :texinfo
"@quotedblbase{}")
5325 :utf-8
"“" :html
"“" :latex
"\"'" :texinfo
"@quotedblleft{}")
5327 :utf-8
"‚" :html
"‚" :latex
"\\glq{}" :texinfo
"@quotesinglbase{}")
5329 :utf-8
"‘" :html
"‘" :latex
"\\grq{}" :texinfo
"@quoteleft{}")
5330 (apostrophe :utf-8
"’" :html
"’"))
5332 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5334 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5335 :texinfo
"@guillemetleft{}")
5337 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5338 :texinfo
"@guillemetright{}")
5339 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5340 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5341 (apostrophe :utf-8
"’" :html
"’"))
5343 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5345 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5346 :texinfo
"@guillemetleft{}")
5348 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5349 :texinfo
"@guillemetright{}")
5350 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5351 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5352 (apostrophe :utf-8
"’" :html
"’"))
5354 ;; https://nn.wikipedia.org/wiki/Sitatteikn
5356 :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
5357 :texinfo
"@guillemetleft{}")
5359 :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
5360 :texinfo
"@guillemetright{}")
5361 (secondary-opening :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
5362 (secondary-closing :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
5363 (apostrophe :utf-8
"’" :html
"’"))
5365 ;; 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
5366 ;; http://www.artlebedev.ru/kovodstvo/sections/104/
5367 (primary-opening :utf-8
"«" :html
"«" :latex
"{}<<"
5368 :texinfo
"@guillemetleft{}")
5369 (primary-closing :utf-8
"»" :html
"»" :latex
">>{}"
5370 :texinfo
"@guillemetright{}")
5372 :utf-8
"„" :html
"„" :latex
"\\glqq{}" :texinfo
"@quotedblbase{}")
5374 :utf-8
"“" :html
"“" :latex
"\\grqq{}" :texinfo
"@quotedblleft{}")
5375 (apostrophe :utf-8
"’" :html
: "'"))
5377 ;; based on https://sv.wikipedia.org/wiki/Citattecken
5378 (primary-opening :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
5379 (primary-closing :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
5380 (secondary-opening :utf-8
"’" :html
"’" :latex
"’" :texinfo
"`")
5381 (secondary-closing :utf-8
"’" :html
"’" :latex
"’" :texinfo
"'")
5382 (apostrophe :utf-8
"’" :html
"’")))
5383 "Smart quotes translations.
5385 Alist whose CAR is a language string and CDR is an alist with
5386 quote type as key and a plist associating various encodings to
5387 their translation as value.
5389 A quote type can be any symbol among `primary-opening',
5390 `primary-closing', `secondary-opening', `secondary-closing' and
5393 Valid encodings include `:utf-8', `:html', `:latex' and
5396 If no translation is found, the quote character is left as-is.")
5398 (defun org-export--smart-quote-status (s info
)
5399 "Return smart quote status at the beginning of string S.
5400 INFO is the current export state, as a plist."
5401 (let* ((parent (org-element-property :parent s
))
5402 (cache (or (plist-get info
:smart-quote-cache
)
5403 (let ((table (make-hash-table :test
#'eq
)))
5404 (plist-put info
:smart-quote-cache table
)
5406 (value (gethash parent cache
'missing-data
)))
5407 (if (not (eq value
'missing-data
)) (cdr (assq s value
))
5408 (let (level1-open full-status
)
5410 (let ((secondary (org-element-secondary-p s
)))
5411 (if secondary
(org-element-property secondary parent
)
5412 (org-element-contents parent
)))
5415 (let ((start 0) current-status
)
5416 (while (setq start
(string-match "['\"]" text start
))
5419 ((equal (match-string 0 text
) "\"")
5420 (setf level1-open
(not level1-open
))
5421 (if level1-open
'primary-opening
'primary-closing
))
5422 ;; Not already in a level 1 quote: this is an
5424 ((not level1-open
) 'apostrophe
)
5425 ;; Extract previous char and next char. As
5426 ;; a special case, they can also be set to `blank',
5427 ;; `no-blank' or nil. Then determine if current
5428 ;; match is allowed as an opening quote or a closing
5432 (if (> start
0) (substring text
(1- start
) start
)
5433 (let ((p (org-export-get-previous-element
5436 ((stringp p
) (substring p -
1))
5437 ((memq (org-element-property :post-blank p
)
5442 (if (< (1+ start
) (length text
))
5443 (substring text
(1+ start
) (+ start
2))
5444 (let ((n (org-export-get-next-element text info
)))
5446 ((stringp n
) (substring n
0 1))
5449 (and (if (stringp previous
)
5450 (string-match "\\s\"\\|\\s-\\|\\s("
5452 (memq previous
'(blank nil
)))
5454 (string-match "\\w\\|\\s.\\|\\s_" next
)
5455 (eq next
'no-blank
))))
5457 (and (if (stringp previous
)
5458 (string-match "\\w\\|\\s.\\|\\s_" previous
)
5459 (eq previous
'no-blank
))
5461 (string-match "\\s-\\|\\s)\\|\\s.\\|\\s\""
5463 (memq next
'(blank nil
))))))
5465 ((and allow-open allow-close
) (error "Should not happen"))
5466 (allow-open 'secondary-opening
)
5467 (allow-close 'secondary-closing
)
5471 (when current-status
5472 (push (cons text
(nreverse current-status
)) full-status
))))
5473 info nil org-element-recursive-objects
)
5474 (puthash parent full-status cache
)
5475 (cdr (assq s full-status
))))))
5477 (defun org-export-activate-smart-quotes (s encoding info
&optional original
)
5478 "Replace regular quotes with \"smart\" quotes in string S.
5480 ENCODING is a symbol among `:html', `:latex', `:texinfo' and
5481 `:utf-8'. INFO is a plist used as a communication channel.
5483 The function has to retrieve information about string
5484 surroundings in parse tree. It can only happen with an
5485 unmodified string. Thus, if S has already been through another
5486 process, a non-nil ORIGINAL optional argument will provide that
5489 Return the new string."
5491 (copy-sequence (org-export--smart-quote-status (or original s
) info
))))
5492 (replace-regexp-in-string
5496 (cdr (assq (pop quote-status
)
5497 (cdr (assoc (plist-get info
:language
)
5498 org-export-smart-quotes-alist
))))
5505 ;; Here are various functions to retrieve information about the
5506 ;; neighborhood of a given element or object. Neighbors of interest
5507 ;; are direct parent (`org-export-get-parent'), parent headline
5508 ;; (`org-export-get-parent-headline'), first element containing an
5509 ;; object, (`org-export-get-parent-element'), parent table
5510 ;; (`org-export-get-parent-table'), previous element or object
5511 ;; (`org-export-get-previous-element') and next element or object
5512 ;; (`org-export-get-next-element').
5514 ;; defsubst org-export-get-parent must be defined before first use
5516 (defun org-export-get-parent-headline (blob)
5517 "Return BLOB parent headline or nil.
5518 BLOB is the element or object being considered."
5519 (org-element-lineage blob
'(headline)))
5521 (defun org-export-get-parent-element (object)
5522 "Return first element containing OBJECT or nil.
5523 OBJECT is the object to consider."
5524 (org-element-lineage object org-element-all-elements
))
5526 (defun org-export-get-parent-table (object)
5527 "Return OBJECT parent table or nil.
5528 OBJECT is either a `table-cell' or `table-element' type object."
5529 (org-element-lineage object
'(table)))
5531 (defun org-export-get-previous-element (blob info
&optional n
)
5532 "Return previous element or object.
5534 BLOB is an element or object. INFO is a plist used as
5535 a communication channel. Return previous exportable element or
5536 object, a string, or nil.
5538 When optional argument N is a positive integer, return a list
5539 containing up to N siblings before BLOB, from farthest to
5540 closest. With any other non-nil value, return a list containing
5542 (let* ((secondary (org-element-secondary-p blob
))
5543 (parent (org-export-get-parent blob
))
5545 (if secondary
(org-element-property secondary parent
)
5546 (org-element-contents parent
)))
5549 (dolist (obj (cdr (memq blob
(reverse siblings
))) prev
)
5550 (cond ((memq obj
(plist-get info
:ignore-list
)))
5551 ((null n
) (throw 'exit obj
))
5552 ((not (wholenump n
)) (push obj prev
))
5553 ((zerop n
) (throw 'exit prev
))
5554 (t (cl-decf n
) (push obj prev
)))))))
5556 (defun org-export-get-next-element (blob info
&optional n
)
5557 "Return next element or object.
5559 BLOB is an element or object. INFO is a plist used as
5560 a communication channel. Return next exportable element or
5561 object, a string, or nil.
5563 When optional argument N is a positive integer, return a list
5564 containing up to N siblings after BLOB, from closest to farthest.
5565 With any other non-nil value, return a list containing all of
5567 (let* ((secondary (org-element-secondary-p blob
))
5568 (parent (org-export-get-parent blob
))
5571 (if secondary
(org-element-property secondary parent
)
5572 (org-element-contents parent
)))))
5575 (dolist (obj siblings
(nreverse next
))
5576 (cond ((memq obj
(plist-get info
:ignore-list
)))
5577 ((null n
) (throw 'exit obj
))
5578 ((not (wholenump n
)) (push obj next
))
5579 ((zerop n
) (throw 'exit
(nreverse next
)))
5580 (t (cl-decf n
) (push obj next
)))))))
5585 ;; `org-export-translate' translates a string according to the language
5586 ;; specified by the LANGUAGE keyword. `org-export-dictionary' contains
5587 ;; the dictionary used for the translation.
5589 (defconst org-export-dictionary
5591 ("fr" :default
"%e %n : %c" :html
"%e %n : %c"))
5593 ("ca" :default
"Autor")
5594 ("cs" :default
"Autor")
5595 ("da" :default
"Forfatter")
5596 ("de" :default
"Autor")
5597 ("eo" :html
"Aŭtoro")
5598 ("es" :default
"Autor")
5599 ("et" :default
"Autor")
5600 ("fi" :html
"Tekijä")
5601 ("fr" :default
"Auteur")
5602 ("hu" :default
"Szerzõ")
5603 ("is" :html
"Höfundur")
5604 ("it" :default
"Autore")
5605 ("ja" :default
"著者" :html
"著者")
5606 ("nl" :default
"Auteur")
5607 ("no" :default
"Forfatter")
5608 ("nb" :default
"Forfatter")
5609 ("nn" :default
"Forfattar")
5610 ("pl" :default
"Autor")
5611 ("pt_BR" :default
"Autor")
5612 ("ru" :html
"Автор" :utf-8
"Автор")
5613 ("sv" :html
"Författare")
5614 ("uk" :html
"Автор" :utf-8
"Автор")
5615 ("zh-CN" :html
"作者" :utf-8
"作者")
5616 ("zh-TW" :html
"作者" :utf-8
"作者"))
5617 ("Continued from previous page"
5618 ("de" :default
"Fortsetzung von vorheriger Seite")
5619 ("es" :html
"Continúa de la página anterior" :ascii
"Continua de la pagina anterior" :default
"Continúa de la página anterior")
5620 ("fr" :default
"Suite de la page précédente")
5621 ("it" :default
"Continua da pagina precedente")
5622 ("ja" :default
"前ページからの続き")
5623 ("nl" :default
"Vervolg van vorige pagina")
5624 ("pt" :default
"Continuação da página anterior")
5625 ("ru" :html
"(Продолжение)"
5626 :utf-8
"(Продолжение)"))
5627 ("Continued on next page"
5628 ("de" :default
"Fortsetzung nächste Seite")
5629 ("es" :html
"Continúa en la siguiente página" :ascii
"Continua en la siguiente pagina" :default
"Continúa en la siguiente página")
5630 ("fr" :default
"Suite page suivante")
5631 ("it" :default
"Continua alla pagina successiva")
5632 ("ja" :default
"次ページに続く")
5633 ("nl" :default
"Vervolg op volgende pagina")
5634 ("pt" :default
"Continua na página seguinte")
5635 ("ru" :html
"(Продолжение следует)"
5636 :utf-8
"(Продолжение следует)"))
5638 ("ca" :default
"Data")
5639 ("cs" :default
"Datum")
5640 ("da" :default
"Dato")
5641 ("de" :default
"Datum")
5642 ("eo" :default
"Dato")
5643 ("es" :default
"Fecha")
5644 ("et" :html
"Kuupäev" :utf-8
"Kuupäev")
5645 ("fi" :html
"Päivämäärä")
5646 ("hu" :html
"Dátum")
5647 ("is" :default
"Dagsetning")
5648 ("it" :default
"Data")
5649 ("ja" :default
"日付" :html
"日付")
5650 ("nl" :default
"Datum")
5651 ("no" :default
"Dato")
5652 ("nb" :default
"Dato")
5653 ("nn" :default
"Dato")
5654 ("pl" :default
"Data")
5655 ("pt_BR" :default
"Data")
5656 ("ru" :html
"Дата" :utf-8
"Дата")
5657 ("sv" :default
"Datum")
5658 ("uk" :html
"Дата" :utf-8
"Дата")
5659 ("zh-CN" :html
"日期" :utf-8
"日期")
5660 ("zh-TW" :html
"日期" :utf-8
"日期"))
5662 ("da" :default
"Ligning")
5663 ("de" :default
"Gleichung")
5664 ("es" :ascii
"Ecuacion" :html
"Ecuación" :default
"Ecuación")
5665 ("et" :html
"Võrrand" :utf-8
"Võrrand")
5666 ("fr" :ascii
"Equation" :default
"Équation")
5667 ("is" :default
"Jafna")
5668 ("ja" :default
"方程式")
5669 ("no" :default
"Ligning")
5670 ("nb" :default
"Ligning")
5671 ("nn" :default
"Likning")
5672 ("pt_BR" :html
"Equação" :default
"Equação" :ascii
"Equacao")
5673 ("ru" :html
"Уравнение"
5675 ("sv" :default
"Ekvation")
5676 ("zh-CN" :html
"方程" :utf-8
"方程"))
5678 ("da" :default
"Figur")
5679 ("de" :default
"Abbildung")
5680 ("es" :default
"Figura")
5681 ("et" :default
"Joonis")
5682 ("is" :default
"Mynd")
5683 ("ja" :default
"図" :html
"図")
5684 ("no" :default
"Illustrasjon")
5685 ("nb" :default
"Illustrasjon")
5686 ("nn" :default
"Illustrasjon")
5687 ("pt_BR" :default
"Figura")
5688 ("ru" :html
"Рисунок" :utf-8
"Рисунок")
5689 ("sv" :default
"Illustration")
5690 ("zh-CN" :html
"图" :utf-8
"图"))
5692 ("da" :default
"Figur %d")
5693 ("de" :default
"Abbildung %d:")
5694 ("es" :default
"Figura %d:")
5695 ("et" :default
"Joonis %d:")
5696 ("fr" :default
"Figure %d :" :html
"Figure %d :")
5697 ("is" :default
"Mynd %d")
5698 ("ja" :default
"図%d: " :html
"図%d: ")
5699 ("no" :default
"Illustrasjon %d")
5700 ("nb" :default
"Illustrasjon %d")
5701 ("nn" :default
"Illustrasjon %d")
5702 ("pt_BR" :default
"Figura %d:")
5703 ("ru" :html
"Рис. %d.:" :utf-8
"Рис. %d.:")
5704 ("sv" :default
"Illustration %d")
5705 ("zh-CN" :html
"图%d " :utf-8
"图%d "))
5707 ("ca" :html
"Peus de pàgina")
5708 ("cs" :default
"Pozn\xe1mky pod carou")
5709 ("da" :default
"Fodnoter")
5710 ("de" :html
"Fußnoten" :default
"Fußnoten")
5711 ("eo" :default
"Piednotoj")
5712 ("es" :ascii
"Nota al pie de pagina" :html
"Nota al pie de página" :default
"Nota al pie de página")
5713 ("et" :html
"Allmärkused" :utf-8
"Allmärkused")
5714 ("fi" :default
"Alaviitteet")
5715 ("fr" :default
"Notes de bas de page")
5716 ("hu" :html
"Lábjegyzet")
5717 ("is" :html
"Aftanmálsgreinar")
5718 ("it" :html
"Note a piè di pagina")
5719 ("ja" :default
"脚注" :html
"脚注")
5720 ("nl" :default
"Voetnoten")
5721 ("no" :default
"Fotnoter")
5722 ("nb" :default
"Fotnoter")
5723 ("nn" :default
"Fotnotar")
5724 ("pl" :default
"Przypis")
5725 ("pt_BR" :html
"Notas de Rodapé" :default
"Notas de Rodapé" :ascii
"Notas de Rodape")
5726 ("ru" :html
"Сноски" :utf-8
"Сноски")
5727 ("sv" :default
"Fotnoter")
5728 ("uk" :html
"Примітки"
5730 ("zh-CN" :html
"脚注" :utf-8
"脚注")
5731 ("zh-TW" :html
"腳註" :utf-8
"腳註"))
5733 ("da" :default
"Programmer")
5734 ("de" :default
"Programmauflistungsverzeichnis")
5735 ("es" :ascii
"Indice de Listados de programas" :html
"Índice de Listados de programas" :default
"Índice de Listados de programas")
5736 ("et" :default
"Loendite nimekiri")
5737 ("fr" :default
"Liste des programmes")
5738 ("ja" :default
"ソースコード目次")
5739 ("no" :default
"Dataprogrammer")
5740 ("nb" :default
"Dataprogrammer")
5741 ("ru" :html
"Список распечаток"
5742 :utf-8
"Список распечаток")
5743 ("zh-CN" :html
"代码目录" :utf-8
"代码目录"))
5745 ("da" :default
"Tabeller")
5746 ("de" :default
"Tabellenverzeichnis")
5747 ("es" :ascii
"Indice de tablas" :html
"Índice de tablas" :default
"Índice de tablas")
5748 ("et" :default
"Tabelite nimekiri")
5749 ("fr" :default
"Liste des tableaux")
5750 ("is" :default
"Töfluskrá" :html
"Töfluskrá")
5751 ("ja" :default
"表目次")
5752 ("no" :default
"Tabeller")
5753 ("nb" :default
"Tabeller")
5754 ("nn" :default
"Tabeller")
5755 ("pt_BR" :default
"Índice de Tabelas" :ascii
"Indice de Tabelas")
5756 ("ru" :html
"Список таблиц"
5757 :utf-8
"Список таблиц")
5758 ("sv" :default
"Tabeller")
5759 ("zh-CN" :html
"表格目录" :utf-8
"表格目录"))
5761 ("da" :default
"Program")
5762 ("de" :default
"Programmlisting")
5763 ("es" :default
"Listado de programa")
5764 ("et" :default
"Loend")
5765 ("fr" :default
"Programme" :html
"Programme")
5766 ("ja" :default
"ソースコード")
5767 ("no" :default
"Dataprogram")
5768 ("nb" :default
"Dataprogram")
5769 ("pt_BR" :default
"Listagem")
5770 ("ru" :html
"Распечатка"
5771 :utf-8
"Распечатка")
5772 ("zh-CN" :html
"代码" :utf-8
"代码"))
5774 ("da" :default
"Program %d")
5775 ("de" :default
"Programmlisting %d")
5776 ("es" :default
"Listado de programa %d")
5777 ("et" :default
"Loend %d")
5778 ("fr" :default
"Programme %d :" :html
"Programme %d :")
5779 ("ja" :default
"ソースコード%d:")
5780 ("no" :default
"Dataprogram %d")
5781 ("nb" :default
"Dataprogram %d")
5782 ("pt_BR" :default
"Listagem %d")
5783 ("ru" :html
"Распечатка %d.:"
5784 :utf-8
"Распечатка %d.:")
5785 ("zh-CN" :html
"代码%d " :utf-8
"代码%d "))
5787 ("fr" :ascii
"References" :default
"Références")
5788 ("de" :default
"Quellen")
5789 ("es" :default
"Referencias"))
5791 ("fr" :default
"cf. figure %s"
5792 :html
"cf. figure %s" :latex
"cf.~figure~%s"))
5794 ("fr" :default
"cf. programme %s"
5795 :html
"cf. programme %s" :latex
"cf.~programme~%s"))
5797 ("da" :default
"jævnfør afsnit %s")
5798 ("de" :default
"siehe Abschnitt %s")
5799 ("es" :ascii
"Vea seccion %s" :html
"Vea sección %s" :default
"Vea sección %s")
5800 ("et" :html
"Vaata peatükki %s" :utf-8
"Vaata peatükki %s")
5801 ("fr" :default
"cf. section %s")
5802 ("ja" :default
"セクション %s を参照")
5803 ("pt_BR" :html
"Veja a seção %s" :default
"Veja a seção %s"
5804 :ascii
"Veja a secao %s")
5805 ("ru" :html
"См. раздел %s"
5806 :utf-8
"См. раздел %s")
5807 ("zh-CN" :html
"参见第%s节" :utf-8
"参见第%s节"))
5809 ("fr" :default
"cf. tableau %s"
5810 :html
"cf. tableau %s" :latex
"cf.~tableau~%s"))
5812 ("de" :default
"Tabelle")
5813 ("es" :default
"Tabla")
5814 ("et" :default
"Tabel")
5815 ("fr" :default
"Tableau")
5816 ("is" :default
"Tafla")
5817 ("ja" :default
"表" :html
"表")
5818 ("pt_BR" :default
"Tabela")
5819 ("ru" :html
"Таблица"
5821 ("zh-CN" :html
"表" :utf-8
"表"))
5823 ("da" :default
"Tabel %d")
5824 ("de" :default
"Tabelle %d")
5825 ("es" :default
"Tabla %d")
5826 ("et" :default
"Tabel %d")
5827 ("fr" :default
"Tableau %d :")
5828 ("is" :default
"Tafla %d")
5829 ("ja" :default
"表%d:" :html
"表%d:")
5830 ("no" :default
"Tabell %d")
5831 ("nb" :default
"Tabell %d")
5832 ("nn" :default
"Tabell %d")
5833 ("pt_BR" :default
"Tabela %d")
5834 ("ru" :html
"Таблица %d.:"
5835 :utf-8
"Таблица %d.:")
5836 ("sv" :default
"Tabell %d")
5837 ("zh-CN" :html
"表%d " :utf-8
"表%d "))
5838 ("Table of Contents"
5839 ("ca" :html
"Índex")
5840 ("cs" :default
"Obsah")
5841 ("da" :default
"Indhold")
5842 ("de" :default
"Inhaltsverzeichnis")
5843 ("eo" :default
"Enhavo")
5844 ("es" :ascii
"Indice" :html
"Índice" :default
"Índice")
5845 ("et" :default
"Sisukord")
5846 ("fi" :html
"Sisällysluettelo")
5847 ("fr" :ascii
"Sommaire" :default
"Table des matières")
5848 ("hu" :html
"Tartalomjegyzék")
5849 ("is" :default
"Efnisyfirlit")
5850 ("it" :default
"Indice")
5851 ("ja" :default
"目次" :html
"目次")
5852 ("nl" :default
"Inhoudsopgave")
5853 ("no" :default
"Innhold")
5854 ("nb" :default
"Innhold")
5855 ("nn" :default
"Innhald")
5856 ("pl" :html
"Spis treści")
5857 ("pt_BR" :html
"Índice" :utf8
"Índice" :ascii
"Indice")
5858 ("ru" :html
"Содержание"
5859 :utf-8
"Содержание")
5860 ("sv" :html
"Innehåll")
5861 ("uk" :html
"Зміст" :utf-8
"Зміст")
5862 ("zh-CN" :html
"目录" :utf-8
"目录")
5863 ("zh-TW" :html
"目錄" :utf-8
"目錄"))
5864 ("Unknown reference"
5865 ("da" :default
"ukendt reference")
5866 ("de" :default
"Unbekannter Verweis")
5867 ("es" :default
"Referencia desconocida")
5868 ("et" :default
"Tundmatu viide")
5869 ("fr" :ascii
"Destination inconnue" :default
"Référence inconnue")
5870 ("ja" :default
"不明な参照先")
5871 ("pt_BR" :default
"Referência desconhecida"
5872 :ascii
"Referencia desconhecida")
5873 ("ru" :html
"Неизвестная ссылка"
5874 :utf-8
"Неизвестная ссылка")
5875 ("zh-CN" :html
"未知引用" :utf-8
"未知引用")))
5876 "Dictionary for export engine.
5878 Alist whose car is the string to translate and cdr is an alist
5879 whose car is the language string and cdr is a plist whose
5880 properties are possible charsets and values translated terms.
5882 It is used as a database for `org-export-translate'. Since this
5883 function returns the string as-is if no translation was found,
5884 the variable only needs to record values different from the
5887 (defun org-export-translate (s encoding info
)
5888 "Translate string S according to language specification.
5890 ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
5891 and `:utf-8'. INFO is a plist used as a communication channel.
5893 Translation depends on `:language' property. Return the
5894 translated string. If no translation is found, try to fall back
5895 to `:default' encoding. If it fails, return S."
5896 (let* ((lang (plist-get info
:language
))
5897 (translations (cdr (assoc lang
5898 (cdr (assoc s org-export-dictionary
))))))
5899 (or (plist-get translations encoding
)
5900 (plist-get translations
:default
)
5905 ;;; Asynchronous Export
5907 ;; `org-export-async-start' is the entry point for asynchronous
5908 ;; export. It recreates current buffer (including visibility,
5909 ;; narrowing and visited file) in an external Emacs process, and
5910 ;; evaluates a command there. It then applies a function on the
5911 ;; returned results in the current process.
5913 ;; At a higher level, `org-export-to-buffer' and `org-export-to-file'
5914 ;; allow exporting to a buffer or a file, asynchronously or not.
5916 ;; `org-export-output-file-name' is an auxiliary function meant to be
5917 ;; used with `org-export-to-file'. With a given extension, it tries
5918 ;; to provide a canonical file name to write export output to.
5920 ;; Asynchronously generated results are never displayed directly.
5921 ;; Instead, they are stored in `org-export-stack-contents'. They can
5922 ;; then be retrieved by calling `org-export-stack'.
5924 ;; Export Stack is viewed through a dedicated major mode
5925 ;;`org-export-stack-mode' and tools: `org-export-stack-refresh',
5926 ;;`org-export-stack-delete', `org-export-stack-view' and
5927 ;;`org-export-stack-clear'.
5929 ;; For back-ends, `org-export-add-to-stack' add a new source to stack.
5930 ;; It should be used whenever `org-export-async-start' is called.
5932 (defmacro org-export-async-start
(fun &rest body
)
5933 "Call function FUN on the results returned by BODY evaluation.
5935 FUN is an anonymous function of one argument. BODY evaluation
5936 happens in an asynchronous process, from a buffer which is an
5937 exact copy of the current one.
5939 Use `org-export-add-to-stack' in FUN in order to register results
5942 This is a low level function. See also `org-export-to-buffer'
5943 and `org-export-to-file' for more specialized functions."
5944 (declare (indent 1) (debug t
))
5945 (org-with-gensyms (process temp-file copy-fun proc-buffer coding
)
5946 ;; Write the full sexp evaluating BODY in a copy of the current
5947 ;; buffer to a temporary file, as it may be too long for program
5948 ;; args in `start-process'.
5949 `(with-temp-message "Initializing asynchronous export process"
5950 (let ((,copy-fun
(org-export--generate-copy-script (current-buffer)))
5951 (,temp-file
(make-temp-file "org-export-process"))
5952 (,coding buffer-file-coding-system
))
5953 (with-temp-file ,temp-file
5955 ;; Null characters (from variable values) are inserted
5956 ;; within the file. As a consequence, coding system for
5957 ;; buffer contents will not be recognized properly. So,
5958 ;; we make sure it is the same as the one used to display
5959 ;; the original buffer.
5960 (format ";; -*- coding: %s; -*-\n%S"
5963 (when org-export-async-debug
'(setq debug-on-error t
))
5964 ;; Ignore `kill-emacs-hook' and code evaluation
5965 ;; queries from Babel as we need a truly
5966 ;; non-interactive process.
5967 (setq kill-emacs-hook nil
5968 org-babel-confirm-evaluate-answer-no t
)
5969 ;; Initialize export framework.
5971 ;; Re-create current buffer there.
5972 (funcall ,,copy-fun
)
5973 (restore-buffer-modified-p nil
)
5974 ;; Sexp to evaluate in the buffer.
5975 (print (progn ,,@body
))))))
5976 ;; Start external process.
5977 (let* ((process-connection-type nil
)
5978 (,proc-buffer
(generate-new-buffer-name "*Org Export Process*"))
5983 (list "org-export-process"
5985 (expand-file-name invocation-name invocation-directory
)
5987 (if org-export-async-init-file
5988 (list "-Q" "-l" org-export-async-init-file
)
5989 (list "-l" user-init-file
))
5990 (list "-l" ,temp-file
)))))
5991 ;; Register running process in stack.
5992 (org-export-add-to-stack (get-buffer ,proc-buffer
) nil
,process
)
5993 ;; Set-up sentinel in order to catch results.
5994 (let ((handler ,fun
))
5995 (set-process-sentinel
5998 (let ((proc-buffer (process-buffer p
)))
5999 (when (eq (process-status p
) 'exit
)
6001 (if (zerop (process-exit-status p
))
6004 (with-current-buffer proc-buffer
6005 (goto-char (point-max))
6007 (read (current-buffer)))))
6008 (funcall ,handler results
))
6009 (unless org-export-async-debug
6010 (and (get-buffer proc-buffer
)
6011 (kill-buffer proc-buffer
))))
6012 (org-export-add-to-stack proc-buffer nil p
)
6014 (message "Process `%s' exited abnormally" p
))
6015 (unless org-export-async-debug
6016 (delete-file ,,temp-file
)))))))))))))
6019 (defun org-export-to-buffer
6021 &optional async subtreep visible-only body-only ext-plist
6023 "Call `org-export-as' with output to a specified buffer.
6025 BACKEND is either an export back-end, as returned by, e.g.,
6026 `org-export-create-backend', or a symbol referring to
6027 a registered back-end.
6029 BUFFER is the name of the output buffer. If it already exists,
6030 it will be erased first, otherwise, it will be created.
6032 A non-nil optional argument ASYNC means the process should happen
6033 asynchronously. The resulting buffer should then be accessible
6034 through the `org-export-stack' interface. When ASYNC is nil, the
6035 buffer is displayed if `org-export-show-temporary-export-buffer'
6038 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
6039 EXT-PLIST are similar to those used in `org-export-as', which
6042 Optional argument POST-PROCESS is a function which should accept
6043 no argument. It is always called within the current process,
6044 from BUFFER, with point at its beginning. Export back-ends can
6045 use it to set a major mode there, e.g,
6047 (defun org-latex-export-as-latex
6048 (&optional async subtreep visible-only body-only ext-plist)
6050 (org-export-to-buffer \\='latex \"*Org LATEX Export*\"
6051 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
6053 This function returns BUFFER."
6054 (declare (indent 2))
6056 (org-export-async-start
6058 (with-current-buffer (get-buffer-create ,buffer
)
6060 (setq buffer-file-coding-system
',buffer-file-coding-system
)
6062 (goto-char (point-min))
6063 (org-export-add-to-stack (current-buffer) ',backend
)
6064 (ignore-errors (funcall ,post-process
))))
6066 ',backend
,subtreep
,visible-only
,body-only
',ext-plist
))
6068 (org-export-as backend subtreep visible-only body-only ext-plist
))
6069 (buffer (get-buffer-create buffer
))
6070 (encoding buffer-file-coding-system
))
6071 (when (and (org-string-nw-p output
) (org-export--copy-to-kill-ring-p))
6072 (org-kill-new output
))
6073 (with-current-buffer buffer
6075 (setq buffer-file-coding-system encoding
)
6077 (goto-char (point-min))
6078 (and (functionp post-process
) (funcall post-process
)))
6079 (when org-export-show-temporary-export-buffer
6080 (switch-to-buffer-other-window buffer
))
6084 (defun org-export-to-file
6085 (backend file
&optional async subtreep visible-only body-only ext-plist
6087 "Call `org-export-as' with output to a specified file.
6089 BACKEND is either an export back-end, as returned by, e.g.,
6090 `org-export-create-backend', or a symbol referring to
6091 a registered back-end. FILE is the name of the output file, as
6094 A non-nil optional argument ASYNC means the process should happen
6095 asynchronously. The resulting buffer will then be accessible
6096 through the `org-export-stack' interface.
6098 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
6099 EXT-PLIST are similar to those used in `org-export-as', which
6102 Optional argument POST-PROCESS is called with FILE as its
6103 argument and happens asynchronously when ASYNC is non-nil. It
6104 has to return a file name, or nil. Export back-ends can use this
6105 to send the output file through additional processing, e.g,
6107 (defun org-latex-export-to-latex
6108 (&optional async subtreep visible-only body-only ext-plist)
6110 (let ((outfile (org-export-output-file-name \".tex\" subtreep)))
6111 (org-export-to-file \\='latex outfile
6112 async subtreep visible-only body-only ext-plist
6113 (lambda (file) (org-latex-compile file)))
6115 The function returns either a file name returned by POST-PROCESS,
6117 (declare (indent 2))
6118 (if (not (file-writable-p file
)) (error "Output file not writable")
6119 (let ((ext-plist (org-combine-plists `(:output-file
,file
) ext-plist
))
6120 (encoding (or org-export-coding-system buffer-file-coding-system
)))
6122 (org-export-async-start
6124 (org-export-add-to-stack (expand-file-name file
) ',backend
))
6127 ',backend
,subtreep
,visible-only
,body-only
6131 (let ((coding-system-for-write ',encoding
))
6132 (write-file ,file
)))
6133 (or (ignore-errors (funcall ',post-process
,file
)) ,file
)))
6134 (let ((output (org-export-as
6135 backend subtreep visible-only body-only ext-plist
)))
6138 (let ((coding-system-for-write encoding
))
6140 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p output
))
6141 (org-kill-new output
))
6142 ;; Get proper return value.
6143 (or (and (functionp post-process
) (funcall post-process file
))
6146 (defun org-export-output-file-name (extension &optional subtreep pub-dir
)
6147 "Return output file's name according to buffer specifications.
6149 EXTENSION is a string representing the output file extension,
6150 with the leading dot.
6152 With a non-nil optional argument SUBTREEP, try to determine
6153 output file's name by looking for \"EXPORT_FILE_NAME\" property
6154 of subtree at point.
6156 When optional argument PUB-DIR is set, use it as the publishing
6159 Return file name as a string."
6160 (let* ((visited-file (buffer-file-name (buffer-base-buffer)))
6162 ;; File name may come from EXPORT_FILE_NAME subtree
6164 (file-name-sans-extension
6165 (or (and subtreep
(org-entry-get nil
"EXPORT_FILE_NAME" 'selective
))
6166 ;; File name may be extracted from buffer's associated
6168 (and visited-file
(file-name-nondirectory visited-file
))
6169 ;; Can't determine file name on our own: Ask user.
6171 "Output file: " pub-dir nil nil nil
6173 (string= (file-name-extension name t
) extension
))))))
6175 ;; Build file name. Enforce EXTENSION over whatever user
6176 ;; may have come up with. PUB-DIR, if defined, always has
6177 ;; precedence over any provided path.
6180 (concat (file-name-as-directory pub-dir
)
6181 (file-name-nondirectory base-name
)
6183 ((file-name-absolute-p base-name
) (concat base-name extension
))
6184 (t (concat (file-name-as-directory ".") base-name extension
)))))
6185 ;; If writing to OUTPUT-FILE would overwrite original file, append
6186 ;; EXTENSION another time to final name.
6187 (if (and visited-file
(file-equal-p visited-file output-file
))
6188 (concat output-file extension
)
6191 (defun org-export-add-to-stack (source backend
&optional process
)
6192 "Add a new result to export stack if not present already.
6194 SOURCE is a buffer or a file name containing export results.
6195 BACKEND is a symbol representing export back-end used to generate
6198 Entries already pointing to SOURCE and unavailable entries are
6199 removed beforehand. Return the new stack."
6200 (setq org-export-stack-contents
6201 (cons (list source backend
(or process
(current-time)))
6202 (org-export-stack-remove source
))))
6204 (defun org-export-stack ()
6205 "Menu for asynchronous export results and running processes."
6207 (let ((buffer (get-buffer-create "*Org Export Stack*")))
6208 (with-current-buffer buffer
6209 (org-export-stack-mode)
6210 (tabulated-list-print t
))
6211 (pop-to-buffer buffer
))
6212 (message "Type \"q\" to quit, \"?\" for help"))
6214 (defun org-export-stack-clear ()
6215 "Remove all entries from export stack."
6217 (setq org-export-stack-contents nil
))
6219 (defun org-export-stack-refresh ()
6220 "Refresh the export stack."
6222 (tabulated-list-print t
))
6224 (defun org-export-stack-remove (&optional source
)
6225 "Remove export results at point from stack.
6226 If optional argument SOURCE is non-nil, remove it instead."
6228 (let ((source (or source
(org-export--stack-source-at-point))))
6229 (setq org-export-stack-contents
6230 (cl-remove-if (lambda (el) (equal (car el
) source
))
6231 org-export-stack-contents
))))
6233 (defun org-export-stack-view (&optional in-emacs
)
6234 "View export results at point in stack.
6235 With an optional prefix argument IN-EMACS, force viewing files
6238 (let ((source (org-export--stack-source-at-point)))
6239 (cond ((processp source
)
6240 (org-switch-to-buffer-other-window (process-buffer source
)))
6241 ((bufferp source
) (org-switch-to-buffer-other-window source
))
6242 (t (org-open-file source in-emacs
)))))
6244 (defvar org-export-stack-mode-map
6245 (let ((km (make-sparse-keymap)))
6246 (set-keymap-parent km tabulated-list-mode-map
)
6247 (define-key km
" " 'next-line
)
6248 (define-key km
"\C-n" 'next-line
)
6249 (define-key km
[down] 'next-line)
6250 (define-key km "\C-p" 'previous-line)
6251 (define-key km "\C-?" 'previous-line)
6252 (define-key km [up] 'previous-line)
6253 (define-key km "C" 'org-export-stack-clear)
6254 (define-key km "v" 'org-export-stack-view)
6255 (define-key km (kbd "RET") 'org-export-stack-view)
6256 (define-key km "d" 'org-export-stack-remove)
6258 "Keymap for Org Export Stack.")
6260 (define-derived-mode org-export-stack-mode tabulated-list-mode "Org-Stack"
6261 "Mode for displaying asynchronous export stack.
6263 Type `\\[org-export-stack]' to visualize the asynchronous export
6266 In an Org Export Stack buffer, use \
6267 \\<org-export-stack-mode-map>`\\[org-export-stack-view]' to view export output
6268 on current line, `\\[org-export-stack-remove]' to remove it from the stack and \
6269 `\\[org-export-stack-clear]' to clear
6272 Removing entries in a stack buffer does not affect files
6273 or buffers, only display.
6275 \\{org-export-stack-mode-map}"
6276 (setq tabulated-list-format
6277 (vector (list "#" 4 #'org-export--stack-num-predicate)
6278 (list "Back-End" 12 t)
6280 (list "Source" 0 nil)))
6281 (setq tabulated-list-sort-key (cons "#" nil))
6282 (setq tabulated-list-entries #'org-export--stack-generate)
6283 (add-hook 'tabulated-list-revert-hook #'org-export--stack-generate nil t)
6284 (add-hook 'post-command-hook #'org-export-stack-refresh nil t)
6285 (tabulated-list-init-header))
6287 (defun org-export--stack-generate ()
6288 "Generate the asynchronous export stack for display.
6289 Unavailable sources are removed from the list. Return a list
6290 appropriate for `tabulated-list-print'."
6291 ;; Clear stack from exited processes, dead buffers or non-existent
6293 (setq org-export-stack-contents
6296 (if (processp (nth 2 el))
6297 (buffer-live-p (process-buffer (nth 2 el)))
6298 (let ((source (car el)))
6299 (if (bufferp source) (buffer-live-p source)
6300 (file-exists-p source)))))
6301 org-export-stack-contents))
6302 ;; Update `tabulated-list-entries'.
6306 (let ((source (car entry)))
6310 (number-to-string (cl-incf counter))
6312 (if (nth 1 entry) (symbol-name (nth 1 entry)) "")
6314 (let ((info (nth 2 entry)))
6315 (if (processp info) (symbol-name (process-status info))
6316 (format-seconds "%h:%.2m" (float-time (time-since info)))))
6318 (if (stringp source) source (buffer-name source))))))
6319 org-export-stack-contents)))
6321 (defun org-export--stack-num-predicate (a b)
6322 (< (string-to-number (aref (nth 1 a) 0))
6323 (string-to-number (aref (nth 1 b) 0))))
6325 (defun org-export--stack-source-at-point ()
6326 "Return source from export results at point in stack."
6327 (let ((source (car (nth (1- (org-current-line)) org-export-stack-contents))))
6328 (if (not source) (error "Source unavailable, please refresh buffer")
6329 (let ((source-name (if (stringp source) source (buffer-name source))))
6332 (looking-at-p (concat ".* +" (regexp-quote source-name) "$")))
6334 ;; SOURCE is not consistent with current line. The stack
6335 ;; view is outdated.
6336 (error (substitute-command-keys
6337 "Source unavailable; type `\\[org-export-stack-refresh]' \
6338 to refresh buffer")))))))
6344 ;; `org-export-dispatch' is the standard interactive way to start an
6345 ;; export process. It uses `org-export--dispatch-ui' as a subroutine
6346 ;; for its interface, which, in turn, delegates response to key
6347 ;; pressed to `org-export--dispatch-action'.
6350 (defun org-export-dispatch (&optional arg)
6351 "Export dispatcher for Org mode.
6353 It provides an access to common export related tasks in a buffer.
6354 Its interface comes in two flavors: standard and expert.
6356 While both share the same set of bindings, only the former
6357 displays the valid keys associations in a dedicated buffer.
6358 Scrolling (resp. line-wise motion) in this buffer is done with
6359 SPC and DEL (resp. C-n and C-p) keys.
6361 Set variable `org-export-dispatch-use-expert-ui' to switch to one
6362 flavor or the other.
6364 When ARG is `\\[universal-argument]', repeat the last export action, with the\
6366 set of options used back then, on the current buffer.
6368 When ARG is `\\[universal-argument] \\[universal-argument]', display the \
6369 asynchronous export stack."
6372 (cond ((equal arg '(16)) '(stack))
6373 ((and arg org-export-dispatch-last-action))
6374 (t (save-window-excursion
6377 ;; Remember where we are
6378 (move-marker org-export-dispatch-last-position
6380 (org-base-buffer (current-buffer)))
6381 ;; Get and store an export command
6382 (setq org-export-dispatch-last-action
6383 (org-export--dispatch-ui
6384 (list org-export-initial-scope
6385 (and org-export-in-background 'async))
6387 org-export-dispatch-use-expert-ui)))
6388 (and (get-buffer "*Org Export Dispatcher*")
6389 (kill-buffer "*Org Export Dispatcher*")))))))
6390 (action (car input))
6391 (optns (cdr input)))
6392 (unless (memq 'subtree optns)
6393 (move-marker org-export-dispatch-last-position nil))
6395 ;; First handle special hard-coded actions.
6396 (template (org-export-insert-default-template nil optns))
6397 (stack (org-export-stack))
6398 (publish-current-file
6399 (org-publish-current-file (memq 'force optns) (memq 'async optns)))
6400 (publish-current-project
6401 (org-publish-current-project (memq 'force optns) (memq 'async optns)))
6402 (publish-choose-project
6403 (org-publish (assoc (completing-read
6405 org-publish-project-alist nil t)
6406 org-publish-project-alist)
6408 (memq 'async optns)))
6409 (publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
6413 ;; Repeating command, maybe move cursor to restore subtree
6415 (if (eq (marker-buffer org-export-dispatch-last-position)
6416 (org-base-buffer (current-buffer)))
6417 (goto-char org-export-dispatch-last-position)
6418 ;; We are in a different buffer, forget position.
6419 (move-marker org-export-dispatch-last-position nil)))
6421 ;; Return a symbol instead of a list to ease
6422 ;; asynchronous export macro use.
6423 (and (memq 'async optns) t)
6424 (and (memq 'subtree optns) t)
6425 (and (memq 'visible optns) t)
6426 (and (memq 'body optns) t)))))))
6428 (defun org-export--dispatch-ui (options first-key expertp)
6429 "Handle interface for `org-export-dispatch'.
6431 OPTIONS is a list containing current interactive options set for
6432 export. It can contain any of the following symbols:
6433 `body' toggles a body-only export
6434 `subtree' restricts export to current subtree
6435 `visible' restricts export to visible part of buffer.
6436 `force' force publishing files.
6437 `async' use asynchronous export process
6439 FIRST-KEY is the key pressed to select the first level menu. It
6440 is nil when this menu hasn't been selected yet.
6442 EXPERTP, when non-nil, triggers expert UI. In that case, no help
6443 buffer is provided, but indications about currently active
6444 options are given in the prompt. Moreover, [?] allows switching
6445 back to standard interface."
6447 (lambda (key &optional access-key)
6448 ;; Fontify KEY string. Optional argument ACCESS-KEY, when
6449 ;; non-nil is the required first-level key to activate
6450 ;; KEY. When its value is t, activate KEY independently
6451 ;; on the first key, if any. A nil value means KEY will
6452 ;; only be activated at first level.
6453 (if (or (eq access-key t) (eq access-key first-key))
6454 (propertize key 'face 'org-warning)
6458 ;; Fontify VALUE string.
6459 (propertize value 'face 'font-lock-variable-name-face)))
6460 ;; Prepare menu entries by extracting them from registered
6461 ;; back-ends and sorting them by access key and by ordinal,
6464 (sort (sort (delq nil
6465 (mapcar #'org-export-backend-menu
6466 org-export-registered-backends))
6468 (let ((key-a (nth 1 a))
6470 (cond ((and (numberp key-a) (numberp key-b))
6472 ((numberp key-b) t)))))
6473 'car-less-than-car))
6474 ;; Compute a list of allowed keys based on the first key
6475 ;; pressed, if any. Some keys
6476 ;; (?^B, ?^V, ?^S, ?^F, ?^A, ?&, ?# and ?q) are always
6479 (nconc (list 2 22 19 6 1)
6480 (if (not first-key) (org-uniquify (mapcar 'car entries))
6482 (dolist (entry entries (sort (mapcar 'car sub-menu) '<))
6483 (when (eq (car entry) first-key)
6484 (setq sub-menu (append (nth 2 entry) sub-menu))))))
6485 (cond ((eq first-key ?P) (list ?f ?p ?x ?a))
6486 ((not first-key) (list ?P)))
6488 (when expertp (list ??))
6490 ;; Build the help menu for standard UI.
6494 ;; Options are hard-coded.
6495 (format "[%s] Body only: %s [%s] Visible only: %s
6496 \[%s] Export scope: %s [%s] Force publishing: %s
6497 \[%s] Async export: %s\n\n"
6498 (funcall fontify-key "C-b" t)
6499 (funcall fontify-value
6500 (if (memq 'body options) "On " "Off"))
6501 (funcall fontify-key "C-v" t)
6502 (funcall fontify-value
6503 (if (memq 'visible options) "On " "Off"))
6504 (funcall fontify-key "C-s" t)
6505 (funcall fontify-value
6506 (if (memq 'subtree options) "Subtree" "Buffer "))
6507 (funcall fontify-key "C-f" t)
6508 (funcall fontify-value
6509 (if (memq 'force options) "On " "Off"))
6510 (funcall fontify-key "C-a" t)
6511 (funcall fontify-value
6512 (if (memq 'async options) "On " "Off")))
6513 ;; Display registered back-end entries. When a key
6514 ;; appears for the second time, do not create another
6515 ;; entry, but append its sub-menu to existing menu.
6519 (let ((top-key (car entry)))
6521 (unless (eq top-key last-key)
6522 (setq last-key top-key)
6523 (format "\n[%s] %s\n"
6524 (funcall fontify-key (char-to-string top-key))
6526 (let ((sub-menu (nth 2 entry)))
6527 (unless (functionp sub-menu)
6528 ;; Split sub-menu into two columns.
6535 (if (zerop (mod index 2)) " [%s] %-26s"
6537 (funcall fontify-key
6538 (char-to-string (car sub-entry))
6542 (when (zerop (mod index 2)) "\n"))))))))
6544 ;; Publishing menu is hard-coded.
6545 (format "\n[%s] Publish
6546 [%s] Current file [%s] Current project
6547 [%s] Choose project [%s] All projects\n\n\n"
6548 (funcall fontify-key "P")
6549 (funcall fontify-key "f" ?P)
6550 (funcall fontify-key "p" ?P)
6551 (funcall fontify-key "x" ?P)
6552 (funcall fontify-key "a" ?P))
6553 (format "[%s] Export stack [%s] Insert template\n"
6554 (funcall fontify-key "&" t)
6555 (funcall fontify-key "#" t))
6557 (funcall fontify-key "q" t)
6558 (if first-key "Main menu" "Exit")))))
6559 ;; Build prompts for both standard and expert UI.
6560 (standard-prompt (unless expertp "Export command: "))
6564 "Export command (C-%s%s%s%s%s) [%s]: "
6565 (if (memq 'body options) (funcall fontify-key "b" t) "b")
6566 (if (memq 'visible options) (funcall fontify-key "v" t) "v")
6567 (if (memq 'subtree options) (funcall fontify-key "s" t) "s")
6568 (if (memq 'force options) (funcall fontify-key "f" t) "f")
6569 (if (memq 'async options) (funcall fontify-key "a" t) "a")
6570 (mapconcat (lambda (k)
6571 ;; Strip control characters.
6572 (unless (< k 27) (char-to-string k)))
6573 allowed-keys "")))))
6574 ;; With expert UI, just read key with a fancy prompt. In standard
6575 ;; UI, display an intrusive help buffer.
6577 (org-export--dispatch-action
6578 expert-prompt allowed-keys entries options first-key expertp)
6579 ;; At first call, create frame layout in order to display menu.
6580 (unless (get-buffer "*Org Export Dispatcher*")
6581 (delete-other-windows)
6582 (org-switch-to-buffer-other-window
6583 (get-buffer-create "*Org Export Dispatcher*"))
6584 (setq cursor-type nil
6585 header-line-format "Use SPC, DEL, C-n or C-p to navigate.")
6586 ;; Make sure that invisible cursor will not highlight square
6588 (set-syntax-table (copy-syntax-table))
6589 (modify-syntax-entry ?\[ "w"))
6590 ;; At this point, the buffer containing the menu exists and is
6591 ;; visible in the current window. So, refresh it.
6592 (with-current-buffer "*Org Export Dispatcher*"
6593 ;; Refresh help. Maintain display continuity by re-visiting
6594 ;; previous window position.
6595 (let ((pos (window-start)))
6598 (set-window-start nil pos)))
6599 (org-fit-window-to-buffer)
6600 (org-export--dispatch-action
6601 standard-prompt allowed-keys entries options first-key expertp))))
6603 (defun org-export--dispatch-action
6604 (prompt allowed-keys entries options first-key expertp)
6605 "Read a character from command input and act accordingly.
6607 PROMPT is the displayed prompt, as a string. ALLOWED-KEYS is
6608 a list of characters available at a given step in the process.
6609 ENTRIES is a list of menu entries. OPTIONS, FIRST-KEY and
6610 EXPERTP are the same as defined in `org-export--dispatch-ui',
6613 Toggle export options when required. Otherwise, return value is
6614 a list with action as CAR and a list of interactive export
6617 ;; Scrolling: when in non-expert mode, act on motion keys (C-n,
6619 (while (and (setq key (read-char-exclusive prompt))
6621 (memq key '(14 16 ?\s ?\d)))
6623 (14 (if (not (pos-visible-in-window-p (point-max)))
6624 (ignore-errors (scroll-up 1))
6625 (message "End of buffer")
6627 (16 (if (not (pos-visible-in-window-p (point-min)))
6628 (ignore-errors (scroll-down 1))
6629 (message "Beginning of buffer")
6631 (?\s (if (not (pos-visible-in-window-p (point-max)))
6633 (message "End of buffer")
6635 (?\d (if (not (pos-visible-in-window-p (point-min)))
6637 (message "Beginning of buffer")
6640 ;; Ignore undefined associations.
6641 ((not (memq key allowed-keys))
6643 (unless expertp (message "Invalid key") (sit-for 1))
6644 (org-export--dispatch-ui options first-key expertp))
6645 ;; q key at first level aborts export. At second level, cancel
6646 ;; first key instead.
6647 ((eq key ?q) (if (not first-key) (error "Export aborted")
6648 (org-export--dispatch-ui options nil expertp)))
6649 ;; Help key: Switch back to standard interface if expert UI was
6651 ((eq key ??) (org-export--dispatch-ui options first-key nil))
6652 ;; Send request for template insertion along with export scope.
6653 ((eq key ?#) (cons 'template (memq 'subtree options)))
6654 ;; Switch to asynchronous export stack.
6655 ((eq key ?&) '(stack))
6656 ;; Toggle options: C-b (2) C-v (22) C-s (19) C-f (6) C-a (1).
6657 ((memq key '(2 22 19 6 1))
6658 (org-export--dispatch-ui
6659 (let ((option (cl-case key (2 'body) (22 'visible) (19 'subtree)
6660 (6 'force) (1 'async))))
6661 (if (memq option options) (remq option options)
6662 (cons option options)))
6664 ;; Action selected: Send key and options back to
6665 ;; `org-export-dispatch'.
6666 ((or first-key (functionp (nth 2 (assq key entries))))
6668 ((not first-key) (nth 2 (assq key entries)))
6669 ;; Publishing actions are hard-coded. Send a special
6670 ;; signal to `org-export-dispatch'.
6673 (?f 'publish-current-file)
6674 (?p 'publish-current-project)
6675 (?x 'publish-choose-project)
6677 ;; Return first action associated to FIRST-KEY + KEY
6678 ;; path. Indeed, derived backends can share the same
6681 (dolist (entry (member (assq first-key entries) entries))
6682 (let ((match (assq key (nth 2 entry))))
6683 (when match (throw 'found (nth 2 match))))))))
6685 ;; Otherwise, enter sub-menu.
6686 (t (org-export--dispatch-ui options key expertp)))))
6693 ;; generated-autoload-file: "org-loaddefs.el"