1 ;;; ox.el --- Generic Export Engine for Org Mode
3 ;; Copyright (C) 2012-2014 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 in 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. The exhaustive list
35 ;; of properties is given in "The Communication Channel" section of
38 ;; - The transcoder walks the parse tree, ignores or treat as plain
39 ;; text elements and objects according to export options, and
40 ;; eventually calls back-end specific functions to do the real
41 ;; transcoding, concatenating their return value along the way.
43 ;; - The filter system is activated at the very beginning and the very
44 ;; end of the export process, and each time an element or an object
45 ;; has been converted. It is the entry point to fine-tune standard
46 ;; output from back-end transcoders. See "The Filter System"
47 ;; section for more information.
49 ;; The core function is `org-export-as'. It returns the transcoded
50 ;; buffer as a string.
52 ;; An export back-end is defined with `org-export-define-backend'.
53 ;; This function can also support specific buffer keywords, OPTION
54 ;; keyword's items and filters. Refer to function's documentation for
57 ;; If the new back-end shares most properties with another one,
58 ;; `org-export-define-derived-backend' can be used to simplify the
61 ;; Any back-end can define its own variables. Among them, those
62 ;; customizable should belong to the `org-export-BACKEND' group.
64 ;; Tools for common tasks across back-ends are implemented in the
65 ;; following part of the file.
67 ;; Then, a wrapper macro for asynchronous export,
68 ;; `org-export-async-start', along with tools to display results. are
69 ;; given in the penultimate part.
71 ;; Eventually, a dispatcher (`org-export-dispatch') for standard
72 ;; back-ends is provided in the last one.
76 (eval-when-compile (require 'cl
))
77 (require 'org-element
)
81 (declare-function org-publish
"ox-publish" (project &optional force async
))
82 (declare-function org-publish-all
"ox-publish" (&optional force async
))
84 org-publish-current-file
"ox-publish" (&optional force async
))
85 (declare-function org-publish-current-project
"ox-publish"
86 (&optional force async
))
88 (defvar org-publish-project-alist
)
89 (defvar org-table-number-fraction
)
90 (defvar org-table-number-regexp
)
94 ;;; Internal Variables
96 ;; Among internal variables, the most important is
97 ;; `org-export-options-alist'. This variable define the global export
98 ;; options, shared between every exporter, and how they are acquired.
100 (defconst org-export-max-depth
19
101 "Maximum nesting depth for headlines, counting from 0.")
103 (defconst org-export-options-alist
104 '((:author
"AUTHOR" nil user-full-name t
)
105 (:creator
"CREATOR" nil org-export-creator-string
)
106 (:date
"DATE" nil nil t
)
107 (:description
"DESCRIPTION" nil nil newline
)
108 (:email
"EMAIL" nil user-mail-address t
)
109 (:exclude-tags
"EXCLUDE_TAGS" nil org-export-exclude-tags split
)
110 (:headline-levels nil
"H" org-export-headline-levels
)
111 (:keywords
"KEYWORDS" nil nil space
)
112 (:language
"LANGUAGE" nil org-export-default-language t
)
113 (:preserve-breaks nil
"\\n" org-export-preserve-breaks
)
114 (:section-numbers nil
"num" org-export-with-section-numbers
)
115 (:select-tags
"SELECT_TAGS" nil org-export-select-tags split
)
116 (:time-stamp-file nil
"timestamp" org-export-time-stamp-file
)
117 (:title
"TITLE" nil nil space
)
118 (:with-archived-trees nil
"arch" org-export-with-archived-trees
)
119 (:with-author nil
"author" org-export-with-author
)
120 (:with-clocks nil
"c" org-export-with-clocks
)
121 (:with-creator nil
"creator" org-export-with-creator
)
122 (:with-date nil
"date" org-export-with-date
)
123 (:with-drawers nil
"d" org-export-with-drawers
)
124 (:with-email nil
"email" org-export-with-email
)
125 (:with-emphasize nil
"*" org-export-with-emphasize
)
126 (:with-entities nil
"e" org-export-with-entities
)
127 (:with-fixed-width nil
":" org-export-with-fixed-width
)
128 (:with-footnotes nil
"f" org-export-with-footnotes
)
129 (:with-inlinetasks nil
"inline" org-export-with-inlinetasks
)
130 (:with-latex nil
"tex" org-export-with-latex
)
131 (:with-planning nil
"p" org-export-with-planning
)
132 (:with-priority nil
"pri" org-export-with-priority
)
133 (:with-smart-quotes nil
"'" org-export-with-smart-quotes
)
134 (:with-special-strings nil
"-" org-export-with-special-strings
)
135 (:with-statistics-cookies nil
"stat" org-export-with-statistics-cookies
)
136 (:with-sub-superscript nil
"^" org-export-with-sub-superscripts
)
137 (:with-toc nil
"toc" org-export-with-toc
)
138 (:with-tables nil
"|" org-export-with-tables
)
139 (:with-tags nil
"tags" org-export-with-tags
)
140 (:with-tasks nil
"tasks" org-export-with-tasks
)
141 (:with-timestamps nil
"<" org-export-with-timestamps
)
142 (:with-todo-keywords nil
"todo" org-export-with-todo-keywords
))
143 "Alist between export properties and ways to set them.
145 The CAR of the alist is the property name, and the CDR is a list
146 like (KEYWORD OPTION DEFAULT BEHAVIOR) where:
148 KEYWORD is a string representing a buffer keyword, or nil. Each
149 property defined this way can also be set, during subtree
150 export, through a headline property named after the keyword
151 with the \"EXPORT_\" prefix (i.e. DATE keyword and EXPORT_DATE
153 OPTION is a string that could be found in an #+OPTIONS: line.
154 DEFAULT is the default value for the property.
155 BEHAVIOR determines how Org should handle multiple keywords for
156 the same property. It is a symbol among:
157 nil Keep old value and discard the new one.
158 t Replace old value with the new one.
159 `space' Concatenate the values, separating them with a space.
160 `newline' Concatenate the values, separating them with
162 `split' Split values at white spaces, and cons them to the
165 Values set through KEYWORD and OPTION have precedence over
168 All these properties should be back-end agnostic. Back-end
169 specific properties are set through `org-export-define-backend'.
170 Properties redefined there have precedence over these.")
172 (defconst org-export-special-keywords
'("FILETAGS" "SETUPFILE" "OPTIONS")
173 "List of in-buffer keywords that require special treatment.
174 These keywords are not directly associated to a property. The
175 way they are handled must be hard-coded into
176 `org-export--get-inbuffer-options' function.")
178 (defconst org-export-filters-alist
179 '((:filter-bold . org-export-filter-bold-functions
)
180 (:filter-babel-call . org-export-filter-babel-call-functions
)
181 (:filter-center-block . org-export-filter-center-block-functions
)
182 (:filter-clock . org-export-filter-clock-functions
)
183 (:filter-code . org-export-filter-code-functions
)
184 (:filter-comment . org-export-filter-comment-functions
)
185 (:filter-comment-block . org-export-filter-comment-block-functions
)
186 (:filter-diary-sexp . org-export-filter-diary-sexp-functions
)
187 (:filter-drawer . org-export-filter-drawer-functions
)
188 (:filter-dynamic-block . org-export-filter-dynamic-block-functions
)
189 (:filter-entity . org-export-filter-entity-functions
)
190 (:filter-example-block . org-export-filter-example-block-functions
)
191 (:filter-export-block . org-export-filter-export-block-functions
)
192 (:filter-export-snippet . org-export-filter-export-snippet-functions
)
193 (:filter-final-output . org-export-filter-final-output-functions
)
194 (:filter-fixed-width . org-export-filter-fixed-width-functions
)
195 (:filter-footnote-definition . org-export-filter-footnote-definition-functions
)
196 (:filter-footnote-reference . org-export-filter-footnote-reference-functions
)
197 (:filter-headline . org-export-filter-headline-functions
)
198 (:filter-horizontal-rule . org-export-filter-horizontal-rule-functions
)
199 (:filter-inline-babel-call . org-export-filter-inline-babel-call-functions
)
200 (:filter-inline-src-block . org-export-filter-inline-src-block-functions
)
201 (:filter-inlinetask . org-export-filter-inlinetask-functions
)
202 (:filter-italic . org-export-filter-italic-functions
)
203 (:filter-item . org-export-filter-item-functions
)
204 (:filter-keyword . org-export-filter-keyword-functions
)
205 (:filter-latex-environment . org-export-filter-latex-environment-functions
)
206 (:filter-latex-fragment . org-export-filter-latex-fragment-functions
)
207 (:filter-line-break . org-export-filter-line-break-functions
)
208 (:filter-link . org-export-filter-link-functions
)
209 (:filter-node-property . org-export-filter-node-property-functions
)
210 (:filter-options . org-export-filter-options-functions
)
211 (:filter-paragraph . org-export-filter-paragraph-functions
)
212 (:filter-parse-tree . org-export-filter-parse-tree-functions
)
213 (:filter-plain-list . org-export-filter-plain-list-functions
)
214 (:filter-plain-text . org-export-filter-plain-text-functions
)
215 (:filter-planning . org-export-filter-planning-functions
)
216 (:filter-property-drawer . org-export-filter-property-drawer-functions
)
217 (:filter-quote-block . org-export-filter-quote-block-functions
)
218 (:filter-quote-section . org-export-filter-quote-section-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 (defvar org-export-async-debug nil
262 "Non-nil means asynchronous export process should leave data behind.
264 This data is found in the appropriate \"*Org Export Process*\"
265 buffer, and in files prefixed with \"org-export-process\" and
266 located in `temporary-file-directory'.
268 When non-nil, it will also set `debug-on-error' to a non-nil
269 value in the external process.")
271 (defvar org-export-stack-contents nil
272 "Record asynchronously generated export results and processes.
273 This is an alist: its CAR is the source of the
274 result (destination file or buffer for a finished process,
275 original buffer for a running one) and its CDR is a list
276 containing the back-end used, as a symbol, and either a process
277 or the time at which it finished. It is used to build the menu
278 from `org-export-stack'.")
280 (defvar org-export--registered-backends nil
281 "List of backends currently available in the exporter.
282 This variable is set with `org-export-define-backend' and
283 `org-export-define-derived-backend' functions.")
285 (defvar org-export-dispatch-last-action nil
286 "Last command called from the dispatcher.
287 The value should be a list. Its CAR is the action, as a symbol,
288 and its CDR is a list of export options.")
290 (defvar org-export-dispatch-last-position
(make-marker)
291 "The position where the last export command was created using the dispatcher.
292 This marker will be used with `C-u C-c C-e' to make sure export repetition
293 uses the same subtree if the previous command was restricted to a subtree.")
295 ;; For compatibility with Org < 8
296 (defvar org-export-current-backend nil
297 "Name, if any, of the back-end used during an export process.
299 Its value is a symbol such as `html', `latex', `ascii', or nil if
300 the back-end is anonymous (see `org-export-create-backend') or if
301 there is no export process in progress.
303 It can be used to teach Babel blocks how to act differently
304 according to the back-end used.")
307 ;;; User-configurable Variables
309 ;; Configuration for the masses.
311 ;; They should never be accessed directly, as their value is to be
312 ;; stored in a property list (cf. `org-export-options-alist').
313 ;; Back-ends will read their value from there instead.
315 (defgroup org-export nil
316 "Options for exporting Org mode files."
320 (defgroup org-export-general nil
321 "General options for export engine."
322 :tag
"Org Export General"
325 (defcustom org-export-with-archived-trees
'headline
326 "Whether sub-trees with the ARCHIVE tag should be exported.
328 This can have three different values:
329 nil Do not export, pretend this tree is not present.
330 t Do export the entire tree.
331 `headline' Only export the headline, but skip the tree below it.
333 This option can also be set with the OPTIONS keyword,
335 :group
'org-export-general
337 (const :tag
"Not at all" nil
)
338 (const :tag
"Headline only" headline
)
339 (const :tag
"Entirely" t
)))
341 (defcustom org-export-with-author t
342 "Non-nil means insert author name into the exported file.
343 This option can also be set with the OPTIONS keyword,
344 e.g. \"author:nil\"."
345 :group
'org-export-general
348 (defcustom org-export-with-clocks nil
349 "Non-nil means export CLOCK keywords.
350 This option can also be set with the OPTIONS keyword,
352 :group
'org-export-general
355 (defcustom org-export-with-creator
'comment
356 "Non-nil means the postamble should contain a creator sentence.
358 The sentence can be set in `org-export-creator-string' and
359 defaults to \"Generated by Org mode XX in Emacs XXX.\".
361 If the value is `comment' insert it as a comment."
362 :group
'org-export-general
364 (const :tag
"No creator sentence" nil
)
365 (const :tag
"Sentence as a comment" comment
)
366 (const :tag
"Insert the sentence" t
)))
368 (defcustom org-export-with-date t
369 "Non-nil means insert date in the exported document.
370 This option can also be set with the OPTIONS keyword,
372 :group
'org-export-general
375 (defcustom org-export-date-timestamp-format nil
376 "Time-stamp format string to use for DATE keyword.
378 The format string, when specified, only applies if date consists
379 in a single time-stamp. Otherwise its value will be ignored.
381 See `format-time-string' for details on how to build this
383 :group
'org-export-general
385 (string :tag
"Time-stamp format string")
386 (const :tag
"No format string" nil
)))
388 (defcustom org-export-creator-string
389 (format "Emacs %s (Org mode %s)"
391 (if (fboundp 'org-version
) (org-version) "unknown version"))
392 "Information about the creator of the document.
393 This option can also be set on with the CREATOR keyword."
394 :group
'org-export-general
395 :type
'(string :tag
"Creator string"))
397 (defcustom org-export-with-drawers
'(not "LOGBOOK")
398 "Non-nil means export contents of standard drawers.
400 When t, all drawers are exported. This may also be a list of
401 drawer names to export. If that list starts with `not', only
402 drawers with such names will be ignored.
404 This variable doesn't apply to properties drawers.
406 This option can also be set with the OPTIONS keyword,
408 :group
'org-export-general
410 :package-version
'(Org .
"8.0")
412 (const :tag
"All drawers" t
)
413 (const :tag
"None" nil
)
414 (repeat :tag
"Selected drawers"
415 (string :tag
"Drawer name"))
416 (list :tag
"Ignored drawers"
417 (const :format
"" not
)
418 (repeat :tag
"Specify names of drawers to ignore during export"
420 (string :tag
"Drawer name")))))
422 (defcustom org-export-with-email nil
423 "Non-nil means insert author email into the exported file.
424 This option can also be set with the OPTIONS keyword,
426 :group
'org-export-general
429 (defcustom org-export-with-emphasize t
430 "Non-nil means interpret *word*, /word/, _word_ and +word+.
432 If the export target supports emphasizing text, the word will be
433 typeset in bold, italic, with an underline or strike-through,
436 This option can also be set with the OPTIONS keyword,
438 :group
'org-export-general
441 (defcustom org-export-exclude-tags
'("noexport")
442 "Tags that exclude a tree from export.
444 All trees carrying any of these tags will be excluded from
445 export. This is without condition, so even subtrees inside that
446 carry one of the `org-export-select-tags' will be removed.
448 This option can also be set with the EXCLUDE_TAGS keyword."
449 :group
'org-export-general
450 :type
'(repeat (string :tag
"Tag")))
452 (defcustom org-export-with-fixed-width t
453 "Non-nil means lines starting with \":\" will be in fixed width font.
455 This can be used to have pre-formatted text, fragments of code
457 : ;; Some Lisp examples
460 will be looking just like this in also HTML. See also the QUOTE
461 keyword. Not all export backends support this.
463 This option can also be set with the OPTIONS keyword,
465 :group
'org-export-general
468 (defcustom org-export-with-footnotes t
469 "Non-nil means Org footnotes should be exported.
470 This option can also be set with the OPTIONS keyword,
472 :group
'org-export-general
475 (defcustom org-export-with-latex t
476 "Non-nil means process LaTeX environments and fragments.
478 This option can also be set with the OPTIONS line,
479 e.g. \"tex:verbatim\". Allowed values are:
481 nil Ignore math snippets.
482 `verbatim' Keep everything in verbatim.
483 t Allow export of math snippets."
484 :group
'org-export-general
486 :package-version
'(Org .
"8.0")
488 (const :tag
"Do not process math in any way" nil
)
489 (const :tag
"Interpret math snippets" t
)
490 (const :tag
"Leave math verbatim" verbatim
)))
492 (defcustom org-export-headline-levels
3
493 "The last level which is still exported as a headline.
495 Inferior levels will usually produce itemize or enumerate lists
496 when exported, but back-end behaviour may differ.
498 This option can also be set with the OPTIONS keyword,
500 :group
'org-export-general
503 (defcustom org-export-default-language
"en"
504 "The default language for export and clocktable translations, as a string.
505 This may have an association in
506 `org-clock-clocktable-language-setup',
507 `org-export-smart-quotes-alist' and `org-export-dictionary'.
508 This option can also be set with the LANGUAGE keyword."
509 :group
'org-export-general
510 :type
'(string :tag
"Language"))
512 (defcustom org-export-preserve-breaks nil
513 "Non-nil means preserve all line breaks when exporting.
514 This option can also be set with the OPTIONS keyword,
516 :group
'org-export-general
519 (defcustom org-export-with-entities t
520 "Non-nil means interpret entities when exporting.
522 For example, HTML export converts \\alpha to α and \\AA to
525 For a list of supported names, see the constant `org-entities'
526 and the user option `org-entities-user'.
528 This option can also be set with the OPTIONS keyword,
530 :group
'org-export-general
533 (defcustom org-export-with-inlinetasks t
534 "Non-nil means inlinetasks should be exported.
535 This option can also be set with the OPTIONS keyword,
536 e.g. \"inline:nil\"."
537 :group
'org-export-general
539 :package-version
'(Org .
"8.0")
542 (defcustom org-export-with-planning nil
543 "Non-nil means include planning info in export.
545 Planning info is the line containing either SCHEDULED:,
546 DEADLINE:, CLOSED: time-stamps, or a combination of them.
548 This option can also be set with the OPTIONS keyword,
550 :group
'org-export-general
552 :package-version
'(Org .
"8.0")
555 (defcustom org-export-with-priority nil
556 "Non-nil means include priority cookies in export.
557 This option can also be set with the OPTIONS keyword,
559 :group
'org-export-general
562 (defcustom org-export-with-section-numbers t
563 "Non-nil means add section numbers to headlines when exporting.
565 When set to an integer n, numbering will only happen for
566 headlines whose relative level is higher or equal to n.
568 This option can also be set with the OPTIONS keyword,
570 :group
'org-export-general
573 (defcustom org-export-select-tags
'("export")
574 "Tags that select a tree for export.
576 If any such tag is found in a buffer, all trees that do not carry
577 one of these tags will be ignored during export. Inside trees
578 that are selected like this, you can still deselect a subtree by
579 tagging it with one of the `org-export-exclude-tags'.
581 This option can also be set with the SELECT_TAGS keyword."
582 :group
'org-export-general
583 :type
'(repeat (string :tag
"Tag")))
585 (defcustom org-export-with-smart-quotes nil
586 "Non-nil means activate smart quotes during export.
587 This option can also be set with the OPTIONS keyword,
590 When setting this to non-nil, you need to take care of
591 using the correct Babel package when exporting to LaTeX.
592 E.g., you can load Babel for french like this:
594 #+LATEX_HEADER: \\usepackage[french]{babel}"
595 :group
'org-export-general
597 :package-version
'(Org .
"8.0")
600 (defcustom org-export-with-special-strings t
601 "Non-nil means interpret \"\\-\", \"--\" and \"---\" for export.
603 When this option is turned on, these strings will be exported as:
606 -----+----------+--------+-------
610 ... … \\ldots …
612 This option can also be set with the OPTIONS keyword,
614 :group
'org-export-general
617 (defcustom org-export-with-statistics-cookies t
618 "Non-nil means include statistics cookies in export.
619 This option can also be set with the OPTIONS keyword,
621 :group
'org-export-general
623 :package-version
'(Org .
"8.0")
626 (defcustom org-export-with-sub-superscripts t
627 "Non-nil means interpret \"_\" and \"^\" for export.
629 If you want to control how Org displays those characters, see
630 `org-use-sub-superscripts'. `org-export-with-sub-superscripts'
631 used to be an alias for `org-use-sub-superscripts' in Org <8.0,
634 When this option is turned on, you can use TeX-like syntax for
635 sub- and superscripts and see them exported correctly.
637 You can also set the option with #+OPTIONS: ^:t
639 Several characters after \"_\" or \"^\" will be considered as a
640 single item - so grouping with {} is normally not needed. For
641 example, the following things will be parsed as single sub- or
644 10^24 or 10^tau several digits will be considered 1 item.
645 10^-12 or 10^-tau a leading sign with digits or a word
646 x^2-y^3 will be read as x^2 - y^3, because items are
647 terminated by almost any nonword/nondigit char.
648 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
650 Still, ambiguity is possible. So when in doubt, use {} to enclose
651 the sub/superscript. If you set this variable to the symbol `{}',
652 the braces are *required* in order to trigger interpretations as
653 sub/superscript. This can be helpful in documents that need \"_\"
654 frequently in plain text."
655 :group
'org-export-general
657 :package-version
'(Org .
"8.0")
659 (const :tag
"Interpret them" t
)
660 (const :tag
"Curly brackets only" {})
661 (const :tag
"Do not interpret them" nil
)))
663 (defcustom org-export-with-toc t
664 "Non-nil means create a table of contents in exported files.
666 The TOC contains headlines with levels up
667 to`org-export-headline-levels'. When an integer, include levels
668 up to N in the toc, this may then be different from
669 `org-export-headline-levels', but it will not be allowed to be
670 larger than the number of headline levels. When nil, no table of
673 This option can also be set with the OPTIONS keyword,
674 e.g. \"toc:nil\" or \"toc:3\"."
675 :group
'org-export-general
677 (const :tag
"No Table of Contents" nil
)
678 (const :tag
"Full Table of Contents" t
)
679 (integer :tag
"TOC to level")))
681 (defcustom org-export-with-tables t
682 "If non-nil, lines starting with \"|\" define a table.
685 | Name | Address | Birthday |
686 |-------------+----------+-----------|
687 | Arthur Dent | England | 29.2.2100 |
689 This option can also be set with the OPTIONS keyword,
691 :group
'org-export-general
694 (defcustom org-export-with-tags t
695 "If nil, do not export tags, just remove them from headlines.
697 If this is the symbol `not-in-toc', tags will be removed from
698 table of contents entries, but still be shown in the headlines of
701 This option can also be set with the OPTIONS keyword,
703 :group
'org-export-general
705 (const :tag
"Off" nil
)
706 (const :tag
"Not in TOC" not-in-toc
)
707 (const :tag
"On" t
)))
709 (defcustom org-export-with-tasks t
710 "Non-nil means include TODO items for export.
712 This may have the following values:
713 t include tasks independent of state.
714 `todo' include only tasks that are not yet done.
715 `done' include only tasks that are already done.
716 nil ignore all tasks.
717 list of keywords include tasks with these keywords.
719 This option can also be set with the OPTIONS keyword,
721 :group
'org-export-general
723 (const :tag
"All tasks" t
)
724 (const :tag
"No tasks" nil
)
725 (const :tag
"Not-done tasks" todo
)
726 (const :tag
"Only done tasks" done
)
727 (repeat :tag
"Specific TODO keywords"
728 (string :tag
"Keyword"))))
730 (defcustom org-export-time-stamp-file t
731 "Non-nil means insert a time stamp into the exported file.
732 The time stamp shows when the file was created. This option can
733 also be set with the OPTIONS keyword, e.g. \"timestamp:nil\"."
734 :group
'org-export-general
737 (defcustom org-export-with-timestamps t
738 "Non nil means allow timestamps in export.
740 It can be set to any of the following values:
741 t export all timestamps.
742 `active' export active timestamps only.
743 `inactive' export inactive timestamps only.
744 nil do not export timestamps
746 This only applies to timestamps isolated in a paragraph
747 containing only timestamps. Other timestamps are always
750 This option can also be set with the OPTIONS keyword, e.g.
752 :group
'org-export-general
754 (const :tag
"All timestamps" t
)
755 (const :tag
"Only active timestamps" active
)
756 (const :tag
"Only inactive timestamps" inactive
)
757 (const :tag
"No timestamp" nil
)))
759 (defcustom org-export-with-todo-keywords t
760 "Non-nil means include TODO keywords in export.
761 When nil, remove all these keywords from the export. This option
762 can also be set with the OPTIONS keyword, e.g. \"todo:nil\"."
763 :group
'org-export-general
766 (defcustom org-export-allow-bind-keywords nil
767 "Non-nil means BIND keywords can define local variable values.
768 This is a potential security risk, which is why the default value
769 is nil. You can also allow them through local buffer variables."
770 :group
'org-export-general
772 :package-version
'(Org .
"8.0")
775 (defcustom org-export-snippet-translation-alist nil
776 "Alist between export snippets back-ends and exporter back-ends.
778 This variable allows to provide shortcuts for export snippets.
780 For example, with a value of '\(\(\"h\" . \"html\"\)\), the
781 HTML back-end will recognize the contents of \"@@h:<b>@@\" as
782 HTML code while every other back-end will ignore it."
783 :group
'org-export-general
785 :package-version
'(Org .
"8.0")
787 (cons (string :tag
"Shortcut")
788 (string :tag
"Back-end"))))
790 (defcustom org-export-coding-system nil
791 "Coding system for the exported file."
792 :group
'org-export-general
794 :package-version
'(Org .
"8.0")
795 :type
'coding-system
)
797 (defcustom org-export-copy-to-kill-ring
'if-interactive
798 "Should we push exported content to the kill ring?"
799 :group
'org-export-general
802 (const :tag
"Always" t
)
803 (const :tag
"When export is done interactively" if-interactive
)
804 (const :tag
"Never" nil
)))
806 (defcustom org-export-initial-scope
'buffer
807 "The initial scope when exporting with `org-export-dispatch'.
808 This variable can be either set to `buffer' or `subtree'."
809 :group
'org-export-general
811 (const :tag
"Export current buffer" buffer
)
812 (const :tag
"Export current subtree" subtree
)))
814 (defcustom org-export-show-temporary-export-buffer t
815 "Non-nil means show buffer after exporting to temp buffer.
816 When Org exports to a file, the buffer visiting that file is ever
817 shown, but remains buried. However, when exporting to
818 a temporary buffer, that buffer is popped up in a second window.
819 When this variable is nil, the buffer remains buried also in
821 :group
'org-export-general
824 (defcustom org-export-in-background nil
825 "Non-nil means export and publishing commands will run in background.
826 Results from an asynchronous export are never displayed
827 automatically. But you can retrieve them with \\[org-export-stack]."
828 :group
'org-export-general
830 :package-version
'(Org .
"8.0")
833 (defcustom org-export-async-init-file user-init-file
834 "File used to initialize external export process.
835 Value must be an absolute file name. It defaults to user's
836 initialization file. Though, a specific configuration makes the
837 process faster and the export more portable."
838 :group
'org-export-general
840 :package-version
'(Org .
"8.0")
841 :type
'(file :must-match t
))
843 (defcustom org-export-dispatch-use-expert-ui nil
844 "Non-nil means using a non-intrusive `org-export-dispatch'.
845 In that case, no help buffer is displayed. Though, an indicator
846 for current export scope is added to the prompt (\"b\" when
847 output is restricted to body only, \"s\" when it is restricted to
848 the current subtree, \"v\" when only visible elements are
849 considered for export, \"f\" when publishing functions should be
850 passed the FORCE argument and \"a\" when the export should be
851 asynchronous). Also, \[?] allows to switch back to standard
853 :group
'org-export-general
855 :package-version
'(Org .
"8.0")
860 ;;; Defining Back-ends
862 ;; An export back-end is a structure with `org-export-backend' type
863 ;; and `name', `parent', `transcoders', `options', `filters', `blocks'
866 ;; At the lowest level, a back-end is created with
867 ;; `org-export-create-backend' function.
869 ;; A named back-end can be registered with
870 ;; `org-export-register-backend' function. A registered back-end can
871 ;; later be referred to by its name, with `org-export-get-backend'
872 ;; function. Also, such a back-end can become the parent of a derived
873 ;; back-end from which slot values will be inherited by default.
874 ;; `org-export-derived-backend-p' can check if a given back-end is
875 ;; derived from a list of back-end names.
877 ;; `org-export-get-all-transcoders', `org-export-get-all-options' and
878 ;; `org-export-get-all-filters' return the full alist of transcoders,
879 ;; options and filters, including those inherited from ancestors.
881 ;; At a higher level, `org-export-define-backend' is the standard way
882 ;; to define an export back-end. If the new back-end is similar to
883 ;; a registered back-end, `org-export-define-derived-backend' may be
886 ;; Eventually `org-export-barf-if-invalid-backend' returns an error
887 ;; when a given back-end hasn't been registered yet.
889 (defstruct (org-export-backend (:constructor org-export-create-backend
)
891 name parent transcoders options filters blocks menu
)
893 (defun org-export-get-backend (name)
894 "Return export back-end named after NAME.
895 NAME is a symbol. Return nil if no such back-end is found."
897 (dolist (b org-export--registered-backends
)
898 (when (eq (org-export-backend-name b
) name
)
901 (defun org-export-register-backend (backend)
902 "Register BACKEND as a known export back-end.
903 BACKEND is a structure with `org-export-backend' type."
904 ;; Refuse to register an unnamed back-end.
905 (unless (org-export-backend-name backend
)
906 (error "Cannot register a unnamed export back-end"))
907 ;; Refuse to register a back-end with an unknown parent.
908 (let ((parent (org-export-backend-parent backend
)))
909 (when (and parent
(not (org-export-get-backend parent
)))
910 (error "Cannot use unknown \"%s\" back-end as a parent" parent
)))
911 ;; Register dedicated export blocks in the parser.
912 (dolist (name (org-export-backend-blocks backend
))
913 (add-to-list 'org-element-block-name-alist
914 (cons name
'org-element-export-block-parser
)))
915 ;; If a back-end with the same name as BACKEND is already
916 ;; registered, replace it with BACKEND. Otherwise, simply add
917 ;; BACKEND to the list of registered back-ends.
918 (let ((old (org-export-get-backend (org-export-backend-name backend
))))
919 (if old
(setcar (memq old org-export--registered-backends
) backend
)
920 (push backend org-export--registered-backends
))))
922 (defun org-export-barf-if-invalid-backend (backend)
923 "Signal an error if BACKEND isn't defined."
924 (unless (org-export-backend-p backend
)
925 (error "Unknown \"%s\" back-end: Aborting export" backend
)))
927 (defun org-export-derived-backend-p (backend &rest backends
)
928 "Non-nil if BACKEND is derived from one of BACKENDS.
929 BACKEND is an export back-end, as returned by, e.g.,
930 `org-export-create-backend', or a symbol referring to
931 a registered back-end. BACKENDS is constituted of symbols."
932 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
935 (while (org-export-backend-parent backend
)
936 (when (memq (org-export-backend-name backend
) backends
)
939 (org-export-get-backend (org-export-backend-parent backend
))))
940 (memq (org-export-backend-name backend
) backends
))))
942 (defun org-export-get-all-transcoders (backend)
943 "Return full translation table for BACKEND.
945 BACKEND is an export back-end, as return by, e.g,,
946 `org-export-create-backend'. Return value is an alist where
947 keys are element or object types, as symbols, and values are
950 Unlike to `org-export-backend-transcoders', this function
951 also returns transcoders inherited from parent back-ends,
953 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
955 (let ((transcoders (org-export-backend-transcoders backend
))
957 (while (setq parent
(org-export-backend-parent backend
))
958 (setq backend
(org-export-get-backend parent
))
960 (append transcoders
(org-export-backend-transcoders backend
))))
963 (defun org-export-get-all-options (backend)
964 "Return export options for BACKEND.
966 BACKEND is an export back-end, as return by, e.g,,
967 `org-export-create-backend'. See `org-export-options-alist'
968 for the shape of the return value.
970 Unlike to `org-export-backend-options', this function also
971 returns options inherited from parent back-ends, if any."
972 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
974 (let ((options (org-export-backend-options backend
))
976 (while (setq parent
(org-export-backend-parent backend
))
977 (setq backend
(org-export-get-backend parent
))
978 (setq options
(append options
(org-export-backend-options backend
))))
981 (defun org-export-get-all-filters (backend)
982 "Return complete list of filters for BACKEND.
984 BACKEND is an export back-end, as return by, e.g,,
985 `org-export-create-backend'. Return value is an alist where
986 keys are symbols and values lists of functions.
988 Unlike to `org-export-backend-filters', this function also
989 returns filters inherited from parent back-ends, if any."
990 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
992 (let ((filters (org-export-backend-filters backend
))
994 (while (setq parent
(org-export-backend-parent backend
))
995 (setq backend
(org-export-get-backend parent
))
996 (setq filters
(append filters
(org-export-backend-filters backend
))))
999 (defun org-export-define-backend (backend transcoders
&rest body
)
1000 "Define a new back-end BACKEND.
1002 TRANSCODERS is an alist between object or element types and
1003 functions handling them.
1005 These functions should return a string without any trailing
1006 space, or nil. They must accept three arguments: the object or
1007 element itself, its contents or nil when it isn't recursive and
1008 the property list used as a communication channel.
1010 Contents, when not nil, are stripped from any global indentation
1011 \(although the relative one is preserved). They also always end
1012 with a single newline character.
1014 If, for a given type, no function is found, that element or
1015 object type will simply be ignored, along with any blank line or
1016 white space at its end. The same will happen if the function
1017 returns the nil value. If that function returns the empty
1018 string, the type will be ignored, but the blank lines or white
1019 spaces will be kept.
1021 In addition to element and object types, one function can be
1022 associated to the `template' (or `inner-template') symbol and
1023 another one to the `plain-text' symbol.
1025 The former returns the final transcoded string, and can be used
1026 to add a preamble and a postamble to document's body. It must
1027 accept two arguments: the transcoded string and the property list
1028 containing export options. A function associated to `template'
1029 will not be applied if export has option \"body-only\".
1030 A function associated to `inner-template' is always applied.
1032 The latter, when defined, is to be called on every text not
1033 recognized as an element or an object. It must accept two
1034 arguments: the text string and the information channel. It is an
1035 appropriate place to protect special chars relative to the
1038 BODY can start with pre-defined keyword arguments. The following
1039 keywords are understood:
1043 String, or list of strings, representing block names that
1044 will not be parsed. This is used to specify blocks that will
1045 contain raw code specific to the back-end. These blocks
1046 still have to be handled by the relative `export-block' type
1051 Alist between filters and function, or list of functions,
1052 specific to the back-end. See `org-export-filters-alist' for
1053 a list of all allowed filters. Filters defined here
1054 shouldn't make a back-end test, as it may prevent back-ends
1055 derived from this one to behave properly.
1059 Menu entry for the export dispatcher. It should be a list
1062 '(KEY DESCRIPTION-OR-ORDINAL ACTION-OR-MENU)
1066 KEY is a free character selecting the back-end.
1068 DESCRIPTION-OR-ORDINAL is either a string or a number.
1070 If it is a string, is will be used to name the back-end in
1071 its menu entry. If it is a number, the following menu will
1072 be displayed as a sub-menu of the back-end with the same
1073 KEY. Also, the number will be used to determine in which
1074 order such sub-menus will appear (lowest first).
1076 ACTION-OR-MENU is either a function or an alist.
1078 If it is an action, it will be called with four
1079 arguments (booleans): ASYNC, SUBTREEP, VISIBLE-ONLY and
1080 BODY-ONLY. See `org-export-as' for further explanations on
1083 If it is an alist, associations should follow the
1086 '(KEY DESCRIPTION ACTION)
1088 where KEY, DESCRIPTION and ACTION are described above.
1090 Valid values include:
1092 '(?m \"My Special Back-end\" my-special-export-function)
1096 '(?l \"Export to LaTeX\"
1097 \(?p \"As PDF file\" org-latex-export-to-pdf)
1098 \(?o \"As PDF file and open\"
1100 \(if a (org-latex-export-to-pdf t s v b)
1102 \(org-latex-export-to-pdf nil s v b)))))))
1104 or the following, which will be added to the previous
1108 \((?B \"As TEX buffer (Beamer)\" org-beamer-export-as-latex)
1109 \(?P \"As PDF file (Beamer)\" org-beamer-export-to-pdf)))
1113 Alist between back-end specific properties introduced in
1114 communication channel and how their value are acquired. See
1115 `org-export-options-alist' for more information about
1116 structure of the values."
1117 (declare (indent 1))
1118 (let (blocks filters menu-entry options contents
)
1119 (while (keywordp (car body
))
1121 (:export-block
(let ((names (pop body
)))
1122 (setq blocks
(if (consp names
) (mapcar 'upcase names
)
1123 (list (upcase names
))))))
1124 (:filters-alist
(setq filters
(pop body
)))
1125 (:menu-entry
(setq menu-entry
(pop body
)))
1126 (:options-alist
(setq options
(pop body
)))
1128 (org-export-register-backend
1129 (org-export-create-backend :name backend
1130 :transcoders transcoders
1134 :menu menu-entry
))))
1136 (defun org-export-define-derived-backend (child parent
&rest body
)
1137 "Create a new back-end as a variant of an existing one.
1139 CHILD is the name of the derived back-end. PARENT is the name of
1140 the parent back-end.
1142 BODY can start with pre-defined keyword arguments. The following
1143 keywords are understood:
1147 String, or list of strings, representing block names that
1148 will not be parsed. This is used to specify blocks that will
1149 contain raw code specific to the back-end. These blocks
1150 still have to be handled by the relative `export-block' type
1155 Alist of filters that will overwrite or complete filters
1156 defined in PARENT back-end. See `org-export-filters-alist'
1157 for a list of allowed filters.
1161 Menu entry for the export dispatcher. See
1162 `org-export-define-backend' for more information about the
1167 Alist of back-end specific properties that will overwrite or
1168 complete those defined in PARENT back-end. Refer to
1169 `org-export-options-alist' for more information about
1170 structure of the values.
1174 Alist of element and object types and transcoders that will
1175 overwrite or complete transcode table from PARENT back-end.
1176 Refer to `org-export-define-backend' for detailed information
1179 As an example, here is how one could define \"my-latex\" back-end
1180 as a variant of `latex' back-end with a custom template function:
1182 \(org-export-define-derived-backend 'my-latex 'latex
1183 :translate-alist '((template . my-latex-template-fun)))
1185 The back-end could then be called with, for example:
1187 \(org-export-to-buffer 'my-latex \"*Test my-latex*\")"
1188 (declare (indent 2))
1189 (let (blocks filters menu-entry options transcoders contents
)
1190 (while (keywordp (car body
))
1192 (:export-block
(let ((names (pop body
)))
1193 (setq blocks
(if (consp names
) (mapcar 'upcase names
)
1194 (list (upcase names
))))))
1195 (:filters-alist
(setq filters
(pop body
)))
1196 (:menu-entry
(setq menu-entry
(pop body
)))
1197 (:options-alist
(setq options
(pop body
)))
1198 (:translate-alist
(setq transcoders
(pop body
)))
1200 (org-export-register-backend
1201 (org-export-create-backend :name child
1203 :transcoders transcoders
1207 :menu menu-entry
))))
1211 ;;; The Communication Channel
1213 ;; During export process, every function has access to a number of
1214 ;; properties. They are of two types:
1216 ;; 1. Environment options are collected once at the very beginning of
1217 ;; the process, out of the original buffer and configuration.
1218 ;; Collecting them is handled by `org-export-get-environment'
1221 ;; Most environment options are defined through the
1222 ;; `org-export-options-alist' variable.
1224 ;; 2. Tree properties are extracted directly from the parsed tree,
1225 ;; just before export, by `org-export-collect-tree-properties'.
1227 ;; Here is the full list of properties available during transcode
1228 ;; process, with their category and their value type.
1230 ;; + `:author' :: Author's name.
1231 ;; - category :: option
1234 ;; + `:back-end' :: Current back-end used for transcoding.
1235 ;; - category :: tree
1238 ;; + `:creator' :: String to write as creation information.
1239 ;; - category :: option
1242 ;; + `:date' :: String to use as date.
1243 ;; - category :: option
1246 ;; + `:description' :: Description text for the current data.
1247 ;; - category :: option
1250 ;; + `:email' :: Author's email.
1251 ;; - category :: option
1254 ;; + `:exclude-tags' :: Tags for exclusion of subtrees from export
1256 ;; - category :: option
1257 ;; - type :: list of strings
1259 ;; + `:export-options' :: List of export options available for current
1261 ;; - category :: none
1262 ;; - type :: list of symbols, among `subtree', `body-only' and
1265 ;; + `:exported-data' :: Hash table used for memoizing
1266 ;; `org-export-data'.
1267 ;; - category :: tree
1268 ;; - type :: hash table
1270 ;; + `:filetags' :: List of global tags for buffer. Used by
1271 ;; `org-export-get-tags' to get tags with inheritance.
1272 ;; - category :: option
1273 ;; - type :: list of strings
1275 ;; + `:footnote-definition-alist' :: Alist between footnote labels and
1276 ;; their definition, as parsed data. Only non-inlined footnotes
1277 ;; are represented in this alist. Also, every definition isn't
1278 ;; guaranteed to be referenced in the parse tree. The purpose of
1279 ;; this property is to preserve definitions from oblivion
1280 ;; (i.e. when the parse tree comes from a part of the original
1281 ;; buffer), it isn't meant for direct use in a back-end. To
1282 ;; retrieve a definition relative to a reference, use
1283 ;; `org-export-get-footnote-definition' instead.
1284 ;; - category :: option
1285 ;; - type :: alist (STRING . LIST)
1287 ;; + `:headline-levels' :: Maximum level being exported as an
1288 ;; headline. Comparison is done with the relative level of
1289 ;; headlines in the parse tree, not necessarily with their
1291 ;; - category :: option
1292 ;; - type :: integer
1294 ;; + `:headline-offset' :: Difference between relative and real level
1295 ;; of headlines in the parse tree. For example, a value of -1
1296 ;; means a level 2 headline should be considered as level
1297 ;; 1 (cf. `org-export-get-relative-level').
1298 ;; - category :: tree
1299 ;; - type :: integer
1301 ;; + `:headline-numbering' :: Alist between headlines and their
1302 ;; numbering, as a list of numbers
1303 ;; (cf. `org-export-get-headline-number').
1304 ;; - category :: tree
1305 ;; - type :: alist (INTEGER . LIST)
1307 ;; + `:id-alist' :: Alist between ID strings and destination file's
1308 ;; path, relative to current directory. It is used by
1309 ;; `org-export-resolve-id-link' to resolve ID links targeting an
1311 ;; - category :: option
1312 ;; - type :: alist (STRING . STRING)
1314 ;; + `:ignore-list' :: List of elements and objects that should be
1315 ;; ignored during export.
1316 ;; - category :: tree
1317 ;; - type :: list of elements and objects
1319 ;; + `:input-file' :: Full path to input file, if any.
1320 ;; - category :: option
1321 ;; - type :: string or nil
1323 ;; + `:keywords' :: List of keywords attached to data.
1324 ;; - category :: option
1327 ;; + `:language' :: Default language used for translations.
1328 ;; - category :: option
1331 ;; + `:parse-tree' :: Whole parse tree, available at any time during
1333 ;; - category :: option
1334 ;; - type :: list (as returned by `org-element-parse-buffer')
1336 ;; + `:preserve-breaks' :: Non-nil means transcoding should preserve
1338 ;; - category :: option
1339 ;; - type :: symbol (nil, t)
1341 ;; + `:section-numbers' :: Non-nil means transcoding should add
1342 ;; section numbers to headlines.
1343 ;; - category :: option
1344 ;; - type :: symbol (nil, t)
1346 ;; + `:select-tags' :: List of tags enforcing inclusion of sub-trees
1347 ;; in transcoding. When such a tag is present, subtrees without
1348 ;; it are de facto excluded from the process. See
1349 ;; `use-select-tags'.
1350 ;; - category :: option
1351 ;; - type :: list of strings
1353 ;; + `:time-stamp-file' :: Non-nil means transcoding should insert
1354 ;; a time stamp in the output.
1355 ;; - category :: option
1356 ;; - type :: symbol (nil, t)
1358 ;; + `:translate-alist' :: Alist between element and object types and
1359 ;; transcoding functions relative to the current back-end.
1360 ;; Special keys `inner-template', `template' and `plain-text' are
1362 ;; - category :: option
1363 ;; - type :: alist (SYMBOL . FUNCTION)
1365 ;; + `:with-archived-trees' :: Non-nil when archived subtrees should
1366 ;; also be transcoded. If it is set to the `headline' symbol,
1367 ;; only the archived headline's name is retained.
1368 ;; - category :: option
1369 ;; - type :: symbol (nil, t, `headline')
1371 ;; + `:with-author' :: Non-nil means author's name should be included
1373 ;; - category :: option
1374 ;; - type :: symbol (nil, t)
1376 ;; + `:with-clocks' :: Non-nil means clock keywords should be exported.
1377 ;; - category :: option
1378 ;; - type :: symbol (nil, t)
1380 ;; + `:with-creator' :: Non-nil means a creation sentence should be
1381 ;; inserted at the end of the transcoded string. If the value
1382 ;; is `comment', it should be commented.
1383 ;; - category :: option
1384 ;; - type :: symbol (`comment', nil, t)
1386 ;; + `:with-date' :: Non-nil means output should contain a date.
1387 ;; - category :: option
1388 ;; - type :. symbol (nil, t)
1390 ;; + `:with-drawers' :: Non-nil means drawers should be exported. If
1391 ;; its value is a list of names, only drawers with such names
1392 ;; will be transcoded. If that list starts with `not', drawer
1393 ;; with these names will be skipped.
1394 ;; - category :: option
1395 ;; - type :: symbol (nil, t) or list of strings
1397 ;; + `:with-email' :: Non-nil means output should contain author's
1399 ;; - category :: option
1400 ;; - type :: symbol (nil, t)
1402 ;; + `:with-emphasize' :: Non-nil means emphasized text should be
1404 ;; - category :: option
1405 ;; - type :: symbol (nil, t)
1407 ;; + `:with-fixed-width' :: Non-nil if transcoder should interpret
1408 ;; strings starting with a colon as a fixed-with (verbatim) area.
1409 ;; - category :: option
1410 ;; - type :: symbol (nil, t)
1412 ;; + `:with-footnotes' :: Non-nil if transcoder should interpret
1414 ;; - category :: option
1415 ;; - type :: symbol (nil, t)
1417 ;; + `:with-latex' :: Non-nil means `latex-environment' elements and
1418 ;; `latex-fragment' objects should appear in export output. When
1419 ;; this property is set to `verbatim', they will be left as-is.
1420 ;; - category :: option
1421 ;; - type :: symbol (`verbatim', nil, t)
1423 ;; + `:with-planning' :: Non-nil means transcoding should include
1425 ;; - category :: option
1426 ;; - type :: symbol (nil, t)
1428 ;; + `:with-priority' :: Non-nil means transcoding should include
1429 ;; priority cookies.
1430 ;; - category :: option
1431 ;; - type :: symbol (nil, t)
1433 ;; + `:with-smart-quotes' :: Non-nil means activate smart quotes in
1435 ;; - category :: option
1436 ;; - type :: symbol (nil, t)
1438 ;; + `:with-special-strings' :: Non-nil means transcoding should
1439 ;; interpret special strings in plain text.
1440 ;; - category :: option
1441 ;; - type :: symbol (nil, t)
1443 ;; + `:with-sub-superscript' :: Non-nil means transcoding should
1444 ;; interpret subscript and superscript. With a value of "{}",
1445 ;; only interpret those using curly brackets.
1446 ;; - category :: option
1447 ;; - type :: symbol (nil, {}, t)
1449 ;; + `:with-tables' :: Non-nil means transcoding should interpret
1451 ;; - category :: option
1452 ;; - type :: symbol (nil, t)
1454 ;; + `:with-tags' :: Non-nil means transcoding should keep tags in
1455 ;; headlines. A `not-in-toc' value will remove them from the
1456 ;; table of contents, if any, nonetheless.
1457 ;; - category :: option
1458 ;; - type :: symbol (nil, t, `not-in-toc')
1460 ;; + `:with-tasks' :: Non-nil means transcoding should include
1461 ;; headlines with a TODO keyword. A `todo' value will only
1462 ;; include headlines with a todo type keyword while a `done'
1463 ;; value will do the contrary. If a list of strings is provided,
1464 ;; only tasks with keywords belonging to that list will be kept.
1465 ;; - category :: option
1466 ;; - type :: symbol (t, todo, done, nil) or list of strings
1468 ;; + `:with-timestamps' :: Non-nil means transcoding should include
1469 ;; time stamps. Special value `active' (resp. `inactive') ask to
1470 ;; export only active (resp. inactive) timestamps. Otherwise,
1471 ;; completely remove them.
1472 ;; - category :: option
1473 ;; - type :: symbol: (`active', `inactive', t, nil)
1475 ;; + `:with-toc' :: Non-nil means that a table of contents has to be
1476 ;; added to the output. An integer value limits its depth.
1477 ;; - category :: option
1478 ;; - type :: symbol (nil, t or integer)
1480 ;; + `:with-todo-keywords' :: Non-nil means transcoding should
1481 ;; include TODO keywords.
1482 ;; - category :: option
1483 ;; - type :: symbol (nil, t)
1486 ;;;; Environment Options
1488 ;; Environment options encompass all parameters defined outside the
1489 ;; scope of the parsed data. They come from five sources, in
1490 ;; increasing precedence order:
1492 ;; - Global variables,
1493 ;; - Buffer's attributes,
1494 ;; - Options keyword symbols,
1495 ;; - Buffer keywords,
1496 ;; - Subtree properties.
1498 ;; The central internal function with regards to environment options
1499 ;; is `org-export-get-environment'. It updates global variables with
1500 ;; "#+BIND:" keywords, then retrieve and prioritize properties from
1501 ;; the different sources.
1503 ;; The internal functions doing the retrieval are:
1504 ;; `org-export--get-global-options',
1505 ;; `org-export--get-buffer-attributes',
1506 ;; `org-export--parse-option-keyword',
1507 ;; `org-export--get-subtree-options' and
1508 ;; `org-export--get-inbuffer-options'
1510 ;; Also, `org-export--list-bound-variables' collects bound variables
1511 ;; along with their value in order to set them as buffer local
1512 ;; variables later in the process.
1514 (defun org-export-get-environment (&optional backend subtreep ext-plist
)
1515 "Collect export options from the current buffer.
1517 Optional argument BACKEND is an export back-end, as returned by
1518 `org-export-create-backend'.
1520 When optional argument SUBTREEP is non-nil, assume the export is
1521 done against the current sub-tree.
1523 Third optional argument EXT-PLIST is a property list with
1524 external parameters overriding Org default settings, but still
1525 inferior to file-local settings."
1526 ;; First install #+BIND variables since these must be set before
1527 ;; global options are read.
1528 (dolist (pair (org-export--list-bound-variables))
1529 (org-set-local (car pair
) (nth 1 pair
)))
1530 ;; Get and prioritize export options...
1532 ;; ... from global variables...
1533 (org-export--get-global-options backend
)
1534 ;; ... from an external property list...
1536 ;; ... from in-buffer settings...
1537 (org-export--get-inbuffer-options backend
)
1538 ;; ... and from subtree, when appropriate.
1539 (and subtreep
(org-export--get-subtree-options backend
))
1540 ;; Eventually add misc. properties.
1544 :translate-alist
(org-export-get-all-transcoders backend
)
1545 :footnote-definition-alist
1546 ;; Footnotes definitions must be collected in the original
1547 ;; buffer, as there's no insurance that they will still be in
1548 ;; the parse tree, due to possible narrowing.
1550 (org-with-wide-buffer
1551 (goto-char (point-min))
1552 (while (re-search-forward org-footnote-definition-re nil t
)
1553 (let ((def (save-match-data (org-element-at-point))))
1554 (when (eq (org-element-type def
) 'footnote-definition
)
1556 (cons (org-element-property :label def
)
1557 (let ((cbeg (org-element-property :contents-begin def
)))
1559 (org-element--parse-elements
1560 cbeg
(org-element-property :contents-end def
)
1561 nil nil nil nil
(list 'org-data nil
)))))
1565 ;; Collect id references.
1567 (org-with-wide-buffer
1568 (goto-char (point-min))
1569 (while (re-search-forward "\\[\\[id:\\S-+?\\]" nil t
)
1570 (let ((link (org-element-context)))
1571 (when (eq (org-element-type link
) 'link
)
1572 (let* ((id (org-element-property :path link
))
1573 (file (org-id-find-id-file id
)))
1575 (push (cons id
(file-relative-name file
)) alist
)))))))
1578 (defun org-export--parse-option-keyword (options &optional backend
)
1579 "Parse an OPTIONS line and return values as a plist.
1580 Optional argument BACKEND is an export back-end, as returned by,
1581 e.g., `org-export-create-backend'. It specifies which back-end
1582 specific items to read, if any."
1584 ;; Priority is given to back-end specific options.
1585 (append (and backend
(org-export-get-all-options backend
))
1586 org-export-options-alist
))
1588 (dolist (option all
)
1589 (let ((property (car option
))
1590 (item (nth 2 option
)))
1592 (not (plist-member plist property
))
1593 (string-match (concat "\\(\\`\\|[ \t]\\)"
1595 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
1597 (setq plist
(plist-put plist
1599 (car (read-from-string
1600 (match-string 2 options
))))))))
1603 (defun org-export--get-subtree-options (&optional backend
)
1604 "Get export options in subtree at point.
1605 Optional argument BACKEND is an export back-end, as returned by,
1606 e.g., `org-export-create-backend'. It specifies back-end used
1607 for export. Return options as a plist."
1608 ;; For each buffer keyword, create a headline property setting the
1609 ;; same property in communication channel. The name for the property
1610 ;; is the keyword with "EXPORT_" appended to it.
1611 (org-with-wide-buffer
1613 ;; Make sure point is at a heading.
1614 (if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t
))
1615 ;; Take care of EXPORT_TITLE. If it isn't defined, use headline's
1616 ;; title as its fallback value.
1617 (when (setq prop
(or (org-entry-get (point) "EXPORT_TITLE")
1618 (progn (looking-at org-todo-line-regexp
)
1619 (org-match-string-no-properties 3))))
1623 (org-element-parse-secondary-string
1624 prop
(org-element-restriction 'keyword
)))))
1625 ;; EXPORT_OPTIONS are parsed in a non-standard way.
1626 (when (setq prop
(org-entry-get (point) "EXPORT_OPTIONS"))
1628 (nconc plist
(org-export--parse-option-keyword prop backend
))))
1629 ;; Handle other keywords. TITLE keyword is excluded as it has
1630 ;; been handled already.
1631 (let ((seen '("TITLE")))
1634 (let ((property (car option
))
1635 (keyword (nth 1 option
)))
1636 (when (and keyword
(not (member keyword seen
)))
1637 (let* ((subtree-prop (concat "EXPORT_" keyword
))
1638 ;; Export properties are not case-sensitive.
1639 (value (let ((case-fold-search t
))
1640 (org-entry-get (point) subtree-prop
))))
1642 (when (and value
(not (plist-member plist property
)))
1648 ;; Parse VALUE if required.
1649 ((member keyword org-element-document-properties
)
1650 (org-element-parse-secondary-string
1651 value
(org-element-restriction 'keyword
)))
1652 ;; If BEHAVIOR is `split' expected value is
1653 ;; a list of strings, not a string.
1654 ((eq (nth 4 option
) 'split
) (org-split-string value
))
1656 ;; Look for both general keywords and back-end specific
1657 ;; options, with priority given to the latter.
1658 (append (and backend
(org-export-get-all-options backend
))
1659 org-export-options-alist
)))
1663 (defun org-export--get-inbuffer-options (&optional backend
)
1664 "Return current buffer export options, as a plist.
1666 Optional argument BACKEND, when non-nil, is an export back-end,
1667 as returned by, e.g., `org-export-create-backend'. It specifies
1668 which back-end specific options should also be read in the
1671 Assume buffer is in Org mode. Narrowing, if any, is ignored."
1673 get-options
; For byte-compiler.
1674 (case-fold-search t
)
1676 ;; Priority is given to back-end specific options.
1677 (and backend
(org-export-get-all-options backend
))
1678 org-export-options-alist
))
1679 (regexp (format "^[ \t]*#\\+%s:"
1680 (regexp-opt (nconc (delq nil
(mapcar 'cadr options
))
1681 org-export-special-keywords
))))
1684 ;; Return all properties associated to KEYWORD.
1686 (dolist (option options properties
)
1687 (when (equal (nth 1 option
) keyword
)
1688 (pushnew (car option
) properties
))))))
1690 (lambda (&optional files plist
)
1691 ;; Recursively read keywords in buffer. FILES is a list
1692 ;; of files read so far. PLIST is the current property
1694 (org-with-wide-buffer
1695 (goto-char (point-min))
1696 (while (re-search-forward regexp nil t
)
1697 (let ((element (org-element-at-point)))
1698 (when (eq (org-element-type element
) 'keyword
)
1699 (let ((key (org-element-property :key element
))
1700 (val (org-element-property :value element
)))
1702 ;; Options in `org-export-special-keywords'.
1703 ((equal key
"SETUPFILE")
1704 (let ((file (expand-file-name
1705 (org-remove-double-quotes (org-trim val
)))))
1706 ;; Avoid circular dependencies.
1707 (unless (member file files
)
1709 (insert (org-file-contents file
'noerror
))
1710 (let ((org-inhibit-startup t
)) (org-mode))
1711 (setq plist
(funcall get-options
1712 (cons file files
) plist
))))))
1713 ((equal key
"OPTIONS")
1717 (org-export--parse-option-keyword val backend
))))
1718 ((equal key
"FILETAGS")
1724 (append (org-split-string val
":")
1725 (plist-get plist
:filetags
)))))))
1727 ;; Options in `org-export-options-alist'.
1728 (dolist (property (funcall find-properties key
))
1729 (let ((behaviour (nth 4 (assq property options
))))
1733 ;; Handle value depending on specified
1737 (if (not (plist-get plist property
))
1739 (concat (plist-get plist property
)
1744 (concat (plist-get plist property
)
1747 (split `(,@(plist-get plist property
)
1748 ,@(org-split-string val
)))
1751 (if (not (plist-member plist property
)) val
1752 (plist-get plist property
))))))))))))))
1753 ;; Return final value.
1755 ;; Read options in the current buffer.
1756 (setq plist
(funcall get-options
1757 (and buffer-file-name
(list buffer-file-name
)) nil
))
1758 ;; Parse keywords specified in `org-element-document-properties'
1759 ;; and return PLIST.
1760 (dolist (keyword org-element-document-properties plist
)
1761 (dolist (property (funcall find-properties keyword
))
1762 (let ((value (plist-get plist property
)))
1763 (when (stringp value
)
1765 (plist-put plist property
1766 (org-element-parse-secondary-string
1767 value
(org-element-restriction 'keyword
))))))))))
1769 (defun org-export--get-buffer-attributes ()
1770 "Return properties related to buffer attributes, as a plist."
1771 ;; Store full path of input file name, or nil. For internal use.
1772 (let ((visited-file (buffer-file-name (buffer-base-buffer))))
1773 (list :input-file visited-file
1774 :title
(if (not visited-file
) (buffer-name (buffer-base-buffer))
1775 (file-name-sans-extension
1776 (file-name-nondirectory visited-file
))))))
1778 (defun org-export--get-global-options (&optional backend
)
1779 "Return global export options as a plist.
1780 Optional argument BACKEND, if non-nil, is an export back-end, as
1781 returned by, e.g., `org-export-create-backend'. It specifies
1782 which back-end specific export options should also be read in the
1785 ;; Priority is given to back-end specific options.
1786 (all (append (and backend
(org-export-get-all-options backend
))
1787 org-export-options-alist
)))
1788 (dolist (cell all plist
)
1789 (let ((prop (car cell
))
1790 (default-value (nth 3 cell
)))
1791 (unless (or (not default-value
) (plist-member plist prop
))
1796 ;; Eval default value provided. If keyword is
1797 ;; a member of `org-element-document-properties',
1798 ;; parse it as a secondary string before storing it.
1799 (let ((value (eval (nth 3 cell
))))
1800 (if (not (stringp value
)) value
1801 (let ((keyword (nth 1 cell
)))
1802 (if (member keyword org-element-document-properties
)
1803 (org-element-parse-secondary-string
1804 value
(org-element-restriction 'keyword
))
1807 (defun org-export--list-bound-variables ()
1808 "Return variables bound from BIND keywords in current buffer.
1809 Also look for BIND keywords in setup files. The return value is
1810 an alist where associations are (VARIABLE-NAME VALUE)."
1811 (when org-export-allow-bind-keywords
1812 (let* (collect-bind ; For byte-compiler.
1814 (lambda (files alist
)
1815 ;; Return an alist between variable names and their
1816 ;; value. FILES is a list of setup files names read so
1817 ;; far, used to avoid circular dependencies. ALIST is
1818 ;; the alist collected so far.
1819 (let ((case-fold-search t
))
1820 (org-with-wide-buffer
1821 (goto-char (point-min))
1822 (while (re-search-forward
1823 "^[ \t]*#\\+\\(BIND\\|SETUPFILE\\):" nil t
)
1824 (let ((element (org-element-at-point)))
1825 (when (eq (org-element-type element
) 'keyword
)
1826 (let ((val (org-element-property :value element
)))
1827 (if (equal (org-element-property :key element
) "BIND")
1828 (push (read (format "(%s)" val
)) alist
)
1829 ;; Enter setup file.
1830 (let ((file (expand-file-name
1831 (org-remove-double-quotes val
))))
1832 (unless (member file files
)
1834 (let ((org-inhibit-startup t
)) (org-mode))
1835 (insert (org-file-contents file
'noerror
))
1837 (funcall collect-bind
1841 ;; Return value in appropriate order of appearance.
1842 (nreverse (funcall collect-bind nil nil
)))))
1845 ;;;; Tree Properties
1847 ;; Tree properties are information extracted from parse tree. They
1848 ;; are initialized at the beginning of the transcoding process by
1849 ;; `org-export-collect-tree-properties'.
1851 ;; Dedicated functions focus on computing the value of specific tree
1852 ;; properties during initialization. Thus,
1853 ;; `org-export--populate-ignore-list' lists elements and objects that
1854 ;; should be skipped during export, `org-export--get-min-level' gets
1855 ;; the minimal exportable level, used as a basis to compute relative
1856 ;; level for headlines. Eventually
1857 ;; `org-export--collect-headline-numbering' builds an alist between
1858 ;; headlines and their numbering.
1860 (defun org-export-collect-tree-properties (data info
)
1861 "Extract tree properties from parse tree.
1863 DATA is the parse tree from which information is retrieved. INFO
1864 is a list holding export options.
1866 Following tree properties are set or updated:
1868 `:exported-data' Hash table used to memoize results from
1871 `:footnote-definition-alist' List of footnotes definitions in
1872 original buffer and current parse tree.
1874 `:headline-offset' Offset between true level of headlines and
1875 local level. An offset of -1 means a headline
1876 of level 2 should be considered as a level
1877 1 headline in the context.
1879 `:headline-numbering' Alist of all headlines as key an the
1880 associated numbering as value.
1882 `:ignore-list' List of elements that should be ignored during
1885 Return updated plist."
1886 ;; Install the parse tree in the communication channel, in order to
1887 ;; use `org-export-get-genealogy' and al.
1888 (setq info
(plist-put info
:parse-tree data
))
1889 ;; Get the list of elements and objects to ignore, and put it into
1890 ;; `:ignore-list'. Do not overwrite any user ignore that might have
1891 ;; been done during parse tree filtering.
1895 (append (org-export--populate-ignore-list data info
)
1896 (plist-get info
:ignore-list
))))
1897 ;; Compute `:headline-offset' in order to be able to use
1898 ;; `org-export-get-relative-level'.
1902 (- 1 (org-export--get-min-level data info
))))
1903 ;; Update footnotes definitions list with definitions in parse tree.
1904 ;; This is required since buffer expansion might have modified
1905 ;; boundaries of footnote definitions contained in the parse tree.
1906 ;; This way, definitions in `footnote-definition-alist' are bound to
1907 ;; match those in the parse tree.
1908 (let ((defs (plist-get info
:footnote-definition-alist
)))
1909 (org-element-map data
'footnote-definition
1911 (push (cons (org-element-property :label fn
)
1912 `(org-data nil
,@(org-element-contents fn
)))
1914 (setq info
(plist-put info
:footnote-definition-alist defs
)))
1915 ;; Properties order doesn't matter: get the rest of the tree
1918 `(:headline-numbering
,(org-export--collect-headline-numbering data info
)
1919 :exported-data
,(make-hash-table :test
'eq
:size
4001))
1922 (defun org-export--get-min-level (data options
)
1923 "Return minimum exportable headline's level in DATA.
1924 DATA is parsed tree as returned by `org-element-parse-buffer'.
1925 OPTIONS is a plist holding export options."
1927 (let ((min-level 10000))
1930 (when (and (eq (org-element-type blob
) 'headline
)
1931 (not (org-element-property :footnote-section-p blob
))
1932 (not (memq blob
(plist-get options
:ignore-list
))))
1933 (setq min-level
(min (org-element-property :level blob
) min-level
)))
1934 (when (= min-level
1) (throw 'exit
1)))
1935 (org-element-contents data
))
1936 ;; If no headline was found, for the sake of consistency, set
1937 ;; minimum level to 1 nonetheless.
1938 (if (= min-level
10000) 1 min-level
))))
1940 (defun org-export--collect-headline-numbering (data options
)
1941 "Return numbering of all exportable headlines in a parse tree.
1943 DATA is the parse tree. OPTIONS is the plist holding export
1946 Return an alist whose key is a headline and value is its
1947 associated numbering \(in the shape of a list of numbers\) or nil
1948 for a footnotes section."
1949 (let ((numbering (make-vector org-export-max-depth
0)))
1950 (org-element-map data
'headline
1952 (unless (org-element-property :footnote-section-p headline
)
1953 (let ((relative-level
1954 (1- (org-export-get-relative-level headline options
))))
1957 (loop for n across numbering
1958 for idx from
0 to org-export-max-depth
1959 when
(< idx relative-level
) collect n
1960 when
(= idx relative-level
) collect
(aset numbering idx
(1+ n
))
1961 when
(> idx relative-level
) do
(aset numbering idx
0))))))
1964 (defun org-export--populate-ignore-list (data options
)
1965 "Return list of elements and objects to ignore during export.
1966 DATA is the parse tree to traverse. OPTIONS is the plist holding
1970 ;; First find trees containing a select tag, if any.
1971 (selected (org-export--selected-trees data options
))
1974 ;; Collect ignored elements or objects into IGNORE-LIST.
1975 (let ((type (org-element-type data
)))
1976 (if (org-export--skip-p data options selected
) (push data ignore
)
1977 (if (and (eq type
'headline
)
1978 (eq (plist-get options
:with-archived-trees
) 'headline
)
1979 (org-element-property :archivedp data
))
1980 ;; If headline is archived but tree below has
1981 ;; to be skipped, add it to ignore list.
1982 (mapc (lambda (e) (push e ignore
))
1983 (org-element-contents data
))
1984 ;; Move into secondary string, if any.
1986 (cdr (assq type org-element-secondary-value-alist
))))
1988 (mapc walk-data
(org-element-property sec-prop data
))))
1989 ;; Move into recursive objects/elements.
1990 (mapc walk-data
(org-element-contents data
))))))))
1992 (funcall walk-data data
)
1996 (defun org-export--selected-trees (data info
)
1997 "Return list of headlines and inlinetasks with a select tag in their tree.
1998 DATA is parsed data as returned by `org-element-parse-buffer'.
1999 INFO is a plist holding export options."
2000 (let* (selected-trees
2001 walk-data
; For byte-compiler.
2004 (lambda (data genealogy
)
2005 (let ((type (org-element-type data
)))
2007 ((memq type
'(headline inlinetask
))
2008 (let ((tags (org-element-property :tags data
)))
2009 (if (loop for tag in
(plist-get info
:select-tags
)
2010 thereis
(member tag tags
))
2011 ;; When a select tag is found, mark full
2012 ;; genealogy and every headline within the tree
2014 (setq selected-trees
2017 (org-element-map data
'(headline inlinetask
)
2020 ;; If at a headline, continue searching in tree,
2022 (when (eq type
'headline
)
2024 (funcall walk-data el
(cons data genealogy
)))
2025 (org-element-contents data
))))))
2026 ((or (eq type
'org-data
)
2027 (memq type org-element-greater-elements
))
2028 (mapc (lambda (el) (funcall walk-data el genealogy
))
2029 (org-element-contents data
)))))))))
2030 (funcall walk-data data nil
)
2033 (defun org-export--skip-p (blob options selected
)
2034 "Non-nil when element or object BLOB should be skipped during export.
2035 OPTIONS is the plist holding export options. SELECTED, when
2036 non-nil, is a list of headlines or inlinetasks belonging to
2037 a tree with a select tag."
2038 (case (org-element-type blob
)
2039 (clock (not (plist-get options
:with-clocks
)))
2041 (let ((with-drawers-p (plist-get options
:with-drawers
)))
2042 (or (not with-drawers-p
)
2043 (and (consp with-drawers-p
)
2044 ;; If `:with-drawers' value starts with `not', ignore
2045 ;; every drawer whose name belong to that list.
2046 ;; Otherwise, ignore drawers whose name isn't in that
2048 (let ((name (org-element-property :drawer-name blob
)))
2049 (if (eq (car with-drawers-p
) 'not
)
2050 (member-ignore-case name
(cdr with-drawers-p
))
2051 (not (member-ignore-case name with-drawers-p
))))))))
2052 ((footnote-definition footnote-reference
)
2053 (not (plist-get options
:with-footnotes
)))
2054 ((headline inlinetask
)
2055 (let ((with-tasks (plist-get options
:with-tasks
))
2056 (todo (org-element-property :todo-keyword blob
))
2057 (todo-type (org-element-property :todo-type blob
))
2058 (archived (plist-get options
:with-archived-trees
))
2059 (tags (org-element-property :tags blob
)))
2061 (and (eq (org-element-type blob
) 'inlinetask
)
2062 (not (plist-get options
:with-inlinetasks
)))
2063 ;; Ignore subtrees with an exclude tag.
2064 (loop for k in
(plist-get options
:exclude-tags
)
2065 thereis
(member k tags
))
2066 ;; When a select tag is present in the buffer, ignore any tree
2068 (and selected
(not (memq blob selected
)))
2069 ;; Ignore commented sub-trees.
2070 (org-element-property :commentedp blob
)
2071 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
2072 (and (not archived
) (org-element-property :archivedp blob
))
2073 ;; Ignore tasks, if specified by `:with-tasks' property.
2075 (or (not with-tasks
)
2076 (and (memq with-tasks
'(todo done
))
2077 (not (eq todo-type with-tasks
)))
2078 (and (consp with-tasks
) (not (member todo with-tasks
))))))))
2079 ((latex-environment latex-fragment
) (not (plist-get options
:with-latex
)))
2080 (planning (not (plist-get options
:with-planning
)))
2081 (statistics-cookie (not (plist-get options
:with-statistics-cookies
)))
2083 (and (org-export-table-has-special-column-p
2084 (org-export-get-parent-table blob
))
2085 (not (org-export-get-previous-element blob options
))))
2086 (table-row (org-export-table-row-is-special-p blob options
))
2088 ;; `:with-timestamps' only applies to isolated timestamps
2089 ;; objects, i.e. timestamp objects in a paragraph containing only
2090 ;; timestamps and whitespaces.
2091 (when (let ((parent (org-export-get-parent-element blob
)))
2092 (and (memq (org-element-type parent
) '(paragraph verse-block
))
2093 (not (org-element-map parent
2095 (remq 'timestamp org-element-all-objects
))
2097 (or (not (stringp obj
)) (org-string-nw-p obj
)))
2099 (case (plist-get options
:with-timestamps
)
2102 (not (memq (org-element-property :type blob
) '(active active-range
))))
2104 (not (memq (org-element-property :type blob
)
2105 '(inactive inactive-range
)))))))))
2110 ;; `org-export-data' reads a parse tree (obtained with, i.e.
2111 ;; `org-element-parse-buffer') and transcodes it into a specified
2112 ;; back-end output. It takes care of filtering out elements or
2113 ;; objects according to export options and organizing the output blank
2114 ;; lines and white space are preserved. The function memoizes its
2115 ;; results, so it is cheap to call it within transcoders.
2117 ;; It is possible to modify locally the back-end used by
2118 ;; `org-export-data' or even use a temporary back-end by using
2119 ;; `org-export-data-with-backend'.
2121 ;; Internally, three functions handle the filtering of objects and
2122 ;; elements during the export. In particular,
2123 ;; `org-export-ignore-element' marks an element or object so future
2124 ;; parse tree traversals skip it, `org-export--interpret-p' tells which
2125 ;; elements or objects should be seen as real Org syntax and
2126 ;; `org-export-expand' transforms the others back into their original
2129 ;; `org-export-transcoder' is an accessor returning appropriate
2130 ;; translator function for a given element or object.
2132 (defun org-export-transcoder (blob info
)
2133 "Return appropriate transcoder for BLOB.
2134 INFO is a plist containing export directives."
2135 (let ((type (org-element-type blob
)))
2136 ;; Return contents only for complete parse trees.
2137 (if (eq type
'org-data
) (lambda (blob contents info
) contents
)
2138 (let ((transcoder (cdr (assq type
(plist-get info
:translate-alist
)))))
2139 (and (functionp transcoder
) transcoder
)))))
2141 (defun org-export-data (data info
)
2142 "Convert DATA into current back-end format.
2144 DATA is a parse tree, an element or an object or a secondary
2145 string. INFO is a plist holding export options.
2147 Return transcoded string."
2148 (let ((memo (gethash data
(plist-get info
:exported-data
) 'no-memo
)))
2149 (if (not (eq memo
'no-memo
)) memo
2150 (let* ((type (org-element-type data
))
2153 ;; Ignored element/object.
2154 ((memq data
(plist-get info
:ignore-list
)) nil
)
2156 ((eq type
'plain-text
)
2157 (org-export-filter-apply-functions
2158 (plist-get info
:filter-plain-text
)
2159 (let ((transcoder (org-export-transcoder data info
)))
2160 (if transcoder
(funcall transcoder data info
) data
))
2162 ;; Uninterpreted element/object: change it back to Org
2163 ;; syntax and export again resulting raw string.
2164 ((not (org-export--interpret-p data info
))
2168 (mapconcat (lambda (blob) (org-export-data blob info
))
2169 (org-element-contents data
)
2172 ;; Secondary string.
2174 (mapconcat (lambda (obj) (org-export-data obj info
)) data
""))
2175 ;; Element/Object without contents or, as a special case,
2176 ;; headline with archive tag and archived trees restricted
2178 ((or (not (org-element-contents data
))
2179 (and (eq type
'headline
)
2180 (eq (plist-get info
:with-archived-trees
) 'headline
)
2181 (org-element-property :archivedp data
)))
2182 (let ((transcoder (org-export-transcoder data info
)))
2183 (or (and (functionp transcoder
)
2184 (funcall transcoder data nil info
))
2185 ;; Export snippets never return a nil value so
2186 ;; that white spaces following them are never
2188 (and (eq type
'export-snippet
) ""))))
2189 ;; Element/Object with contents.
2191 (let ((transcoder (org-export-transcoder data info
)))
2193 (let* ((greaterp (memq type org-element-greater-elements
))
2196 (memq type org-element-recursive-objects
)))
2199 (lambda (element) (org-export-data element info
))
2200 (org-element-contents
2201 (if (or greaterp objectp
) data
2202 ;; Elements directly containing objects
2203 ;; must have their indentation normalized
2205 (org-element-normalize-contents
2207 ;; When normalizing contents of the first
2208 ;; paragraph in an item or a footnote
2209 ;; definition, ignore first line's
2210 ;; indentation: there is none and it
2211 ;; might be misleading.
2212 (when (eq type
'paragraph
)
2213 (let ((parent (org-export-get-parent data
)))
2215 (eq (car (org-element-contents parent
))
2217 (memq (org-element-type parent
)
2218 '(footnote-definition item
))))))))
2220 (funcall transcoder data
2221 (if (not greaterp
) contents
2222 (org-element-normalize-string contents
))
2224 ;; Final result will be memoized before being returned.
2229 ((memq type
'(org-data plain-text nil
)) results
)
2230 ;; Append the same white space between elements or objects as in
2231 ;; the original buffer, and call appropriate filters.
2234 (org-export-filter-apply-functions
2235 (plist-get info
(intern (format ":filter-%s" type
)))
2236 (let ((post-blank (or (org-element-property :post-blank data
)
2238 (if (memq type org-element-all-elements
)
2239 (concat (org-element-normalize-string results
)
2240 (make-string post-blank ?
\n))
2241 (concat results
(make-string post-blank ?
))))
2244 (plist-get info
:exported-data
))))))
2246 (defun org-export-data-with-backend (data backend info
)
2247 "Convert DATA into BACKEND format.
2249 DATA is an element, an object, a secondary string or a string.
2250 BACKEND is a symbol. INFO is a plist used as a communication
2253 Unlike to `org-export-with-backend', this function will
2254 recursively convert DATA using BACKEND translation table."
2255 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
2258 ;; Set-up a new communication channel with translations defined in
2259 ;; BACKEND as the translate table and a new hash table for
2263 (list :back-end backend
2264 :translate-alist
(org-export-get-all-transcoders backend
)
2265 ;; Size of the hash table is reduced since this function
2266 ;; will probably be used on small trees.
2267 :exported-data
(make-hash-table :test
'eq
:size
401)))))
2269 (defun org-export--interpret-p (blob info
)
2270 "Non-nil if element or object BLOB should be interpreted during export.
2271 If nil, BLOB will appear as raw Org syntax. Check is done
2272 according to export options INFO, stored as a plist."
2273 (case (org-element-type blob
)
2275 (entity (plist-get info
:with-entities
))
2277 ((bold italic strike-through underline
)
2278 (plist-get info
:with-emphasize
))
2279 ;; ... fixed-width areas.
2280 (fixed-width (plist-get info
:with-fixed-width
))
2281 ;; ... LaTeX environments and fragments...
2282 ((latex-environment latex-fragment
)
2283 (let ((with-latex-p (plist-get info
:with-latex
)))
2284 (and with-latex-p
(not (eq with-latex-p
'verbatim
)))))
2285 ;; ... sub/superscripts...
2286 ((subscript superscript
)
2287 (let ((sub/super-p
(plist-get info
:with-sub-superscript
)))
2288 (if (eq sub
/super-p
'{})
2289 (org-element-property :use-brackets-p blob
)
2292 (table (plist-get info
:with-tables
))
2295 (defun org-export-expand (blob contents
&optional with-affiliated
)
2296 "Expand a parsed element or object to its original state.
2298 BLOB is either an element or an object. CONTENTS is its
2299 contents, as a string or nil.
2301 When optional argument WITH-AFFILIATED is non-nil, add affiliated
2302 keywords before output."
2303 (let ((type (org-element-type blob
)))
2304 (concat (and with-affiliated
(memq type org-element-all-elements
)
2305 (org-element--interpret-affiliated-keywords blob
))
2306 (funcall (intern (format "org-element-%s-interpreter" type
))
2309 (defun org-export-ignore-element (element info
)
2310 "Add ELEMENT to `:ignore-list' in INFO.
2312 Any element in `:ignore-list' will be skipped when using
2313 `org-element-map'. INFO is modified by side effects."
2314 (plist-put info
:ignore-list
(cons element
(plist-get info
:ignore-list
))))
2318 ;;; The Filter System
2320 ;; Filters allow end-users to tweak easily the transcoded output.
2321 ;; They are the functional counterpart of hooks, as every filter in
2322 ;; a set is applied to the return value of the previous one.
2324 ;; Every set is back-end agnostic. Although, a filter is always
2325 ;; called, in addition to the string it applies to, with the back-end
2326 ;; used as argument, so it's easy for the end-user to add back-end
2327 ;; specific filters in the set. The communication channel, as
2328 ;; a plist, is required as the third argument.
2330 ;; From the developer side, filters sets can be installed in the
2331 ;; process with the help of `org-export-define-backend', which
2332 ;; internally stores filters as an alist. Each association has a key
2333 ;; among the following symbols and a function or a list of functions
2336 ;; - `:filter-options' applies to the property list containing export
2337 ;; options. Unlike to other filters, functions in this list accept
2338 ;; two arguments instead of three: the property list containing
2339 ;; export options and the back-end. Users can set its value through
2340 ;; `org-export-filter-options-functions' variable.
2342 ;; - `:filter-parse-tree' applies directly to the complete parsed
2343 ;; tree. Users can set it through
2344 ;; `org-export-filter-parse-tree-functions' variable.
2346 ;; - `:filter-final-output' applies to the final transcoded string.
2347 ;; Users can set it with `org-export-filter-final-output-functions'
2350 ;; - `:filter-plain-text' applies to any string not recognized as Org
2351 ;; syntax. `org-export-filter-plain-text-functions' allows users to
2354 ;; - `:filter-TYPE' applies on the string returned after an element or
2355 ;; object of type TYPE has been transcoded. A user can modify
2356 ;; `org-export-filter-TYPE-functions'
2358 ;; All filters sets are applied with
2359 ;; `org-export-filter-apply-functions' function. Filters in a set are
2360 ;; applied in a LIFO fashion. It allows developers to be sure that
2361 ;; their filters will be applied first.
2363 ;; Filters properties are installed in communication channel with
2364 ;; `org-export-install-filters' function.
2366 ;; Eventually, two hooks (`org-export-before-processing-hook' and
2367 ;; `org-export-before-parsing-hook') are run at the beginning of the
2368 ;; export process and just before parsing to allow for heavy structure
2374 (defvar org-export-before-processing-hook nil
2375 "Hook run at the beginning of the export process.
2377 This is run before include keywords and macros are expanded and
2378 Babel code blocks executed, on a copy of the original buffer
2379 being exported. Visibility and narrowing are preserved. Point
2380 is at the beginning of the buffer.
2382 Every function in this hook will be called with one argument: the
2383 back-end currently used, as a symbol.")
2385 (defvar org-export-before-parsing-hook nil
2386 "Hook run before parsing an export buffer.
2388 This is run after include keywords and macros have been expanded
2389 and Babel code blocks executed, on a copy of the original buffer
2390 being exported. Visibility and narrowing are preserved. Point
2391 is at the beginning of the buffer.
2393 Every function in this hook will be called with one argument: the
2394 back-end currently used, as a symbol.")
2397 ;;;; Special Filters
2399 (defvar org-export-filter-options-functions nil
2400 "List of functions applied to the export options.
2401 Each filter is called with two arguments: the export options, as
2402 a plist, and the back-end, as a symbol. It must return
2403 a property list containing export options.")
2405 (defvar org-export-filter-parse-tree-functions nil
2406 "List of functions applied to the parsed tree.
2407 Each filter is called with three arguments: the parse tree, as
2408 returned by `org-element-parse-buffer', the back-end, as
2409 a symbol, and the communication channel, as a plist. It must
2410 return the modified parse tree to transcode.")
2412 (defvar org-export-filter-plain-text-functions nil
2413 "List of functions applied to plain text.
2414 Each filter is called with three arguments: a string which
2415 contains no Org syntax, the back-end, as a symbol, and the
2416 communication channel, as a plist. It must return a string or
2419 (defvar org-export-filter-final-output-functions nil
2420 "List of functions applied to the transcoded string.
2421 Each filter is called with three arguments: the full transcoded
2422 string, the back-end, as a symbol, and the communication channel,
2423 as a plist. It must return a string that will be used as the
2424 final export output.")
2427 ;;;; Elements Filters
2429 (defvar org-export-filter-babel-call-functions nil
2430 "List of functions applied to a transcoded babel-call.
2431 Each filter is called with three arguments: the transcoded data,
2432 as a string, the back-end, as a symbol, and the communication
2433 channel, as a plist. It must return a string or nil.")
2435 (defvar org-export-filter-center-block-functions nil
2436 "List of functions applied to a transcoded center block.
2437 Each filter is called with three arguments: the transcoded data,
2438 as a string, the back-end, as a symbol, and the communication
2439 channel, as a plist. It must return a string or nil.")
2441 (defvar org-export-filter-clock-functions nil
2442 "List of functions applied to a transcoded clock.
2443 Each filter is called with three arguments: the transcoded data,
2444 as a string, the back-end, as a symbol, and the communication
2445 channel, as a plist. It must return a string or nil.")
2447 (defvar org-export-filter-comment-functions nil
2448 "List of functions applied to a transcoded comment.
2449 Each filter is called with three arguments: the transcoded data,
2450 as a string, the back-end, as a symbol, and the communication
2451 channel, as a plist. It must return a string or nil.")
2453 (defvar org-export-filter-comment-block-functions nil
2454 "List of functions applied to a transcoded comment-block.
2455 Each filter is called with three arguments: the transcoded data,
2456 as a string, the back-end, as a symbol, and the communication
2457 channel, as a plist. It must return a string or nil.")
2459 (defvar org-export-filter-diary-sexp-functions nil
2460 "List of functions applied to a transcoded diary-sexp.
2461 Each filter is called with three arguments: the transcoded data,
2462 as a string, the back-end, as a symbol, and the communication
2463 channel, as a plist. It must return a string or nil.")
2465 (defvar org-export-filter-drawer-functions nil
2466 "List of functions applied to a transcoded drawer.
2467 Each filter is called with three arguments: the transcoded data,
2468 as a string, the back-end, as a symbol, and the communication
2469 channel, as a plist. It must return a string or nil.")
2471 (defvar org-export-filter-dynamic-block-functions nil
2472 "List of functions applied to a transcoded dynamic-block.
2473 Each filter is called with three arguments: the transcoded data,
2474 as a string, the back-end, as a symbol, and the communication
2475 channel, as a plist. It must return a string or nil.")
2477 (defvar org-export-filter-example-block-functions nil
2478 "List of functions applied to a transcoded example-block.
2479 Each filter is called with three arguments: the transcoded data,
2480 as a string, the back-end, as a symbol, and the communication
2481 channel, as a plist. It must return a string or nil.")
2483 (defvar org-export-filter-export-block-functions nil
2484 "List of functions applied to a transcoded export-block.
2485 Each filter is called with three arguments: the transcoded data,
2486 as a string, the back-end, as a symbol, and the communication
2487 channel, as a plist. It must return a string or nil.")
2489 (defvar org-export-filter-fixed-width-functions nil
2490 "List of functions applied to a transcoded fixed-width.
2491 Each filter is called with three arguments: the transcoded data,
2492 as a string, the back-end, as a symbol, and the communication
2493 channel, as a plist. It must return a string or nil.")
2495 (defvar org-export-filter-footnote-definition-functions nil
2496 "List of functions applied to a transcoded footnote-definition.
2497 Each filter is called with three arguments: the transcoded data,
2498 as a string, the back-end, as a symbol, and the communication
2499 channel, as a plist. It must return a string or nil.")
2501 (defvar org-export-filter-headline-functions nil
2502 "List of functions applied to a transcoded headline.
2503 Each filter is called with three arguments: the transcoded data,
2504 as a string, the back-end, as a symbol, and the communication
2505 channel, as a plist. It must return a string or nil.")
2507 (defvar org-export-filter-horizontal-rule-functions nil
2508 "List of functions applied to a transcoded horizontal-rule.
2509 Each filter is called with three arguments: the transcoded data,
2510 as a string, the back-end, as a symbol, and the communication
2511 channel, as a plist. It must return a string or nil.")
2513 (defvar org-export-filter-inlinetask-functions nil
2514 "List of functions applied to a transcoded inlinetask.
2515 Each filter is called with three arguments: the transcoded data,
2516 as a string, the back-end, as a symbol, and the communication
2517 channel, as a plist. It must return a string or nil.")
2519 (defvar org-export-filter-item-functions nil
2520 "List of functions applied to a transcoded item.
2521 Each filter is called with three arguments: the transcoded data,
2522 as a string, the back-end, as a symbol, and the communication
2523 channel, as a plist. It must return a string or nil.")
2525 (defvar org-export-filter-keyword-functions nil
2526 "List of functions applied to a transcoded keyword.
2527 Each filter is called with three arguments: the transcoded data,
2528 as a string, the back-end, as a symbol, and the communication
2529 channel, as a plist. It must return a string or nil.")
2531 (defvar org-export-filter-latex-environment-functions nil
2532 "List of functions applied to a transcoded latex-environment.
2533 Each filter is called with three arguments: the transcoded data,
2534 as a string, the back-end, as a symbol, and the communication
2535 channel, as a plist. It must return a string or nil.")
2537 (defvar org-export-filter-node-property-functions nil
2538 "List of functions applied to a transcoded node-property.
2539 Each filter is called with three arguments: the transcoded data,
2540 as a string, the back-end, as a symbol, and the communication
2541 channel, as a plist. It must return a string or nil.")
2543 (defvar org-export-filter-paragraph-functions nil
2544 "List of functions applied to a transcoded paragraph.
2545 Each filter is called with three arguments: the transcoded data,
2546 as a string, the back-end, as a symbol, and the communication
2547 channel, as a plist. It must return a string or nil.")
2549 (defvar org-export-filter-plain-list-functions nil
2550 "List of functions applied to a transcoded plain-list.
2551 Each filter is called with three arguments: the transcoded data,
2552 as a string, the back-end, as a symbol, and the communication
2553 channel, as a plist. It must return a string or nil.")
2555 (defvar org-export-filter-planning-functions nil
2556 "List of functions applied to a transcoded planning.
2557 Each filter is called with three arguments: the transcoded data,
2558 as a string, the back-end, as a symbol, and the communication
2559 channel, as a plist. It must return a string or nil.")
2561 (defvar org-export-filter-property-drawer-functions nil
2562 "List of functions applied to a transcoded property-drawer.
2563 Each filter is called with three arguments: the transcoded data,
2564 as a string, the back-end, as a symbol, and the communication
2565 channel, as a plist. It must return a string or nil.")
2567 (defvar org-export-filter-quote-block-functions nil
2568 "List of functions applied to a transcoded quote block.
2569 Each filter is called with three arguments: the transcoded quote
2570 data, as a string, the back-end, as a symbol, and the
2571 communication channel, as a plist. It must return a string or
2574 (defvar org-export-filter-quote-section-functions nil
2575 "List of functions applied to a transcoded quote-section.
2576 Each filter is called with three arguments: the transcoded data,
2577 as a string, the back-end, as a symbol, and the communication
2578 channel, as a plist. It must return a string or nil.")
2580 (defvar org-export-filter-section-functions nil
2581 "List of functions applied to a transcoded section.
2582 Each filter is called with three arguments: the transcoded data,
2583 as a string, the back-end, as a symbol, and the communication
2584 channel, as a plist. It must return a string or nil.")
2586 (defvar org-export-filter-special-block-functions nil
2587 "List of functions applied to a transcoded special block.
2588 Each filter is called with three arguments: the transcoded data,
2589 as a string, the back-end, as a symbol, and the communication
2590 channel, as a plist. It must return a string or nil.")
2592 (defvar org-export-filter-src-block-functions nil
2593 "List of functions applied to a transcoded src-block.
2594 Each filter is called with three arguments: the transcoded data,
2595 as a string, the back-end, as a symbol, and the communication
2596 channel, as a plist. It must return a string or nil.")
2598 (defvar org-export-filter-table-functions nil
2599 "List of functions applied to a transcoded table.
2600 Each filter is called with three arguments: the transcoded data,
2601 as a string, the back-end, as a symbol, and the communication
2602 channel, as a plist. It must return a string or nil.")
2604 (defvar org-export-filter-table-cell-functions nil
2605 "List of functions applied to a transcoded table-cell.
2606 Each filter is called with three arguments: the transcoded data,
2607 as a string, the back-end, as a symbol, and the communication
2608 channel, as a plist. It must return a string or nil.")
2610 (defvar org-export-filter-table-row-functions nil
2611 "List of functions applied to a transcoded table-row.
2612 Each filter is called with three arguments: the transcoded data,
2613 as a string, the back-end, as a symbol, and the communication
2614 channel, as a plist. It must return a string or nil.")
2616 (defvar org-export-filter-verse-block-functions nil
2617 "List of functions applied to a transcoded verse block.
2618 Each filter is called with three arguments: the transcoded data,
2619 as a string, the back-end, as a symbol, and the communication
2620 channel, as a plist. It must return a string or nil.")
2623 ;;;; Objects Filters
2625 (defvar org-export-filter-bold-functions nil
2626 "List of functions applied to transcoded bold text.
2627 Each filter is called with three arguments: the transcoded data,
2628 as a string, the back-end, as a symbol, and the communication
2629 channel, as a plist. It must return a string or nil.")
2631 (defvar org-export-filter-code-functions nil
2632 "List of functions applied to transcoded code text.
2633 Each filter is called with three arguments: the transcoded data,
2634 as a string, the back-end, as a symbol, and the communication
2635 channel, as a plist. It must return a string or nil.")
2637 (defvar org-export-filter-entity-functions nil
2638 "List of functions applied to a transcoded entity.
2639 Each filter is called with three arguments: the transcoded data,
2640 as a string, the back-end, as a symbol, and the communication
2641 channel, as a plist. It must return a string or nil.")
2643 (defvar org-export-filter-export-snippet-functions nil
2644 "List of functions applied to a transcoded export-snippet.
2645 Each filter is called with three arguments: the transcoded data,
2646 as a string, the back-end, as a symbol, and the communication
2647 channel, as a plist. It must return a string or nil.")
2649 (defvar org-export-filter-footnote-reference-functions nil
2650 "List of functions applied to a transcoded footnote-reference.
2651 Each filter is called with three arguments: the transcoded data,
2652 as a string, the back-end, as a symbol, and the communication
2653 channel, as a plist. It must return a string or nil.")
2655 (defvar org-export-filter-inline-babel-call-functions nil
2656 "List of functions applied to a transcoded inline-babel-call.
2657 Each filter is called with three arguments: the transcoded data,
2658 as a string, the back-end, as a symbol, and the communication
2659 channel, as a plist. It must return a string or nil.")
2661 (defvar org-export-filter-inline-src-block-functions nil
2662 "List of functions applied to a transcoded inline-src-block.
2663 Each filter is called with three arguments: the transcoded data,
2664 as a string, the back-end, as a symbol, and the communication
2665 channel, as a plist. It must return a string or nil.")
2667 (defvar org-export-filter-italic-functions nil
2668 "List of functions applied to transcoded italic text.
2669 Each filter is called with three arguments: the transcoded data,
2670 as a string, the back-end, as a symbol, and the communication
2671 channel, as a plist. It must return a string or nil.")
2673 (defvar org-export-filter-latex-fragment-functions nil
2674 "List of functions applied to a transcoded latex-fragment.
2675 Each filter is called with three arguments: the transcoded data,
2676 as a string, the back-end, as a symbol, and the communication
2677 channel, as a plist. It must return a string or nil.")
2679 (defvar org-export-filter-line-break-functions nil
2680 "List of functions applied to a transcoded line-break.
2681 Each filter is called with three arguments: the transcoded data,
2682 as a string, the back-end, as a symbol, and the communication
2683 channel, as a plist. It must return a string or nil.")
2685 (defvar org-export-filter-link-functions nil
2686 "List of functions applied to a transcoded link.
2687 Each filter is called with three arguments: the transcoded data,
2688 as a string, the back-end, as a symbol, and the communication
2689 channel, as a plist. It must return a string or nil.")
2691 (defvar org-export-filter-radio-target-functions nil
2692 "List of functions applied to a transcoded radio-target.
2693 Each filter is called with three arguments: the transcoded data,
2694 as a string, the back-end, as a symbol, and the communication
2695 channel, as a plist. It must return a string or nil.")
2697 (defvar org-export-filter-statistics-cookie-functions nil
2698 "List of functions applied to a transcoded statistics-cookie.
2699 Each filter is called with three arguments: the transcoded data,
2700 as a string, the back-end, as a symbol, and the communication
2701 channel, as a plist. It must return a string or nil.")
2703 (defvar org-export-filter-strike-through-functions nil
2704 "List of functions applied to transcoded strike-through text.
2705 Each filter is called with three arguments: the transcoded data,
2706 as a string, the back-end, as a symbol, and the communication
2707 channel, as a plist. It must return a string or nil.")
2709 (defvar org-export-filter-subscript-functions nil
2710 "List of functions applied to a transcoded subscript.
2711 Each filter is called with three arguments: the transcoded data,
2712 as a string, the back-end, as a symbol, and the communication
2713 channel, as a plist. It must return a string or nil.")
2715 (defvar org-export-filter-superscript-functions nil
2716 "List of functions applied to a transcoded superscript.
2717 Each filter is called with three arguments: the transcoded data,
2718 as a string, the back-end, as a symbol, and the communication
2719 channel, as a plist. It must return a string or nil.")
2721 (defvar org-export-filter-target-functions nil
2722 "List of functions applied to a transcoded target.
2723 Each filter is called with three arguments: the transcoded data,
2724 as a string, the back-end, as a symbol, and the communication
2725 channel, as a plist. It must return a string or nil.")
2727 (defvar org-export-filter-timestamp-functions nil
2728 "List of functions applied to a transcoded timestamp.
2729 Each filter is called with three arguments: the transcoded data,
2730 as a string, the back-end, as a symbol, and the communication
2731 channel, as a plist. It must return a string or nil.")
2733 (defvar org-export-filter-underline-functions nil
2734 "List of functions applied to transcoded underline text.
2735 Each filter is called with three arguments: the transcoded data,
2736 as a string, the back-end, as a symbol, and the communication
2737 channel, as a plist. It must return a string or nil.")
2739 (defvar org-export-filter-verbatim-functions nil
2740 "List of functions applied to transcoded verbatim text.
2741 Each filter is called with three arguments: the transcoded data,
2742 as a string, the back-end, as a symbol, and the communication
2743 channel, as a plist. It must return a string or nil.")
2748 ;; Internal function `org-export-install-filters' installs filters
2749 ;; hard-coded in back-ends (developer filters) and filters from global
2750 ;; variables (user filters) in the communication channel.
2752 ;; Internal function `org-export-filter-apply-functions' takes care
2753 ;; about applying each filter in order to a given data. It ignores
2754 ;; filters returning a nil value but stops whenever a filter returns
2757 (defun org-export-filter-apply-functions (filters value info
)
2758 "Call every function in FILTERS.
2760 Functions are called with arguments VALUE, current export
2761 back-end's name and INFO. A function returning a nil value will
2762 be skipped. If it returns the empty string, the process ends and
2765 Call is done in a LIFO fashion, to be sure that developer
2766 specified filters, if any, are called first."
2768 (let* ((backend (plist-get info
:back-end
))
2769 (backend-name (and backend
(org-export-backend-name backend
))))
2770 (dolist (filter filters value
)
2771 (let ((result (funcall filter value backend-name info
)))
2772 (cond ((not result
) value
)
2773 ((equal value
"") (throw 'exit nil
))
2774 (t (setq value result
))))))))
2776 (defun org-export-install-filters (info)
2777 "Install filters properties in communication channel.
2778 INFO is a plist containing the current communication channel.
2779 Return the updated communication channel."
2781 ;; Install user-defined filters with `org-export-filters-alist'
2782 ;; and filters already in INFO (through ext-plist mechanism).
2784 (let* ((prop (car p
))
2785 (info-value (plist-get info prop
))
2786 (default-value (symbol-value (cdr p
))))
2788 (plist-put plist prop
2789 ;; Filters in INFO will be called
2790 ;; before those user provided.
2791 (append (if (listp info-value
) info-value
2794 org-export-filters-alist
)
2795 ;; Prepend back-end specific filters to that list.
2797 ;; Single values get consed, lists are appended.
2798 (let ((key (car p
)) (value (cdr p
)))
2803 (if (atom value
) (cons value
(plist-get plist key
))
2804 (append value
(plist-get plist key
))))))))
2805 (org-export-get-all-filters (plist-get info
:back-end
)))
2806 ;; Return new communication channel.
2807 (org-combine-plists info plist
)))
2813 ;; This is the room for the main function, `org-export-as', along with
2814 ;; its derivative, `org-export-string-as'.
2815 ;; `org-export--copy-to-kill-ring-p' determines if output of these
2816 ;; function should be added to kill ring.
2818 ;; Note that `org-export-as' doesn't really parse the current buffer,
2819 ;; but a copy of it (with the same buffer-local variables and
2820 ;; visibility), where macros and include keywords are expanded and
2821 ;; Babel blocks are executed, if appropriate.
2822 ;; `org-export-with-buffer-copy' macro prepares that copy.
2824 ;; File inclusion is taken care of by
2825 ;; `org-export-expand-include-keyword' and
2826 ;; `org-export--prepare-file-contents'. Structure wise, including
2827 ;; a whole Org file in a buffer often makes little sense. For
2828 ;; example, if the file contains a headline and the include keyword
2829 ;; was within an item, the item should contain the headline. That's
2830 ;; why file inclusion should be done before any structure can be
2831 ;; associated to the file, that is before parsing.
2833 ;; `org-export-insert-default-template' is a command to insert
2834 ;; a default template (or a back-end specific template) at point or in
2837 (defun org-export-copy-buffer ()
2838 "Return a copy of the current buffer.
2839 The copy preserves Org buffer-local variables, visibility and
2841 (let ((copy-buffer-fun (org-export--generate-copy-script (current-buffer)))
2842 (new-buf (generate-new-buffer (buffer-name))))
2843 (with-current-buffer new-buf
2844 (funcall copy-buffer-fun
)
2845 (set-buffer-modified-p nil
))
2848 (defmacro org-export-with-buffer-copy
(&rest body
)
2849 "Apply BODY in a copy of the current buffer.
2850 The copy preserves local variables, visibility and contents of
2851 the original buffer. Point is at the beginning of the buffer
2852 when BODY is applied."
2854 (org-with-gensyms (buf-copy)
2855 `(let ((,buf-copy
(org-export-copy-buffer)))
2857 (with-current-buffer ,buf-copy
2858 (goto-char (point-min))
2860 (and (buffer-live-p ,buf-copy
)
2861 ;; Kill copy without confirmation.
2862 (progn (with-current-buffer ,buf-copy
2863 (restore-buffer-modified-p nil
))
2864 (kill-buffer ,buf-copy
)))))))
2866 (defun org-export--generate-copy-script (buffer)
2867 "Generate a function duplicating BUFFER.
2869 The copy will preserve local variables, visibility, contents and
2870 narrowing of the original buffer. If a region was active in
2871 BUFFER, contents will be narrowed to that region instead.
2873 The resulting function can be evaluated at a later time, from
2874 another buffer, effectively cloning the original buffer there.
2876 The function assumes BUFFER's major mode is `org-mode'."
2877 (with-current-buffer buffer
2879 (let ((inhibit-modification-hooks t
))
2880 ;; Set major mode. Ignore `org-mode-hook' as it has been run
2881 ;; already in BUFFER.
2882 (let ((org-mode-hook nil
) (org-inhibit-startup t
)) (org-mode))
2883 ;; Copy specific buffer local variables and variables set
2884 ;; through BIND keywords.
2885 ,@(let ((bound-variables (org-export--list-bound-variables))
2887 (dolist (entry (buffer-local-variables (buffer-base-buffer)) vars
)
2889 (let ((var (car entry
))
2891 (and (not (eq var
'org-font-lock-keywords
))
2895 buffer-file-coding-system
))
2896 (assq var bound-variables
)
2897 (string-match "^\\(org-\\|orgtbl-\\)"
2899 ;; Skip unreadable values, as they cannot be
2900 ;; sent to external process.
2901 (or (not val
) (ignore-errors (read (format "%S" val
))))
2902 (push `(set (make-local-variable (quote ,var
))
2905 ;; Whole buffer contents.
2907 ,(org-with-wide-buffer
2908 (buffer-substring-no-properties
2909 (point-min) (point-max))))
2911 ,(if (org-region-active-p)
2912 `(narrow-to-region ,(region-beginning) ,(region-end))
2913 `(narrow-to-region ,(point-min) ,(point-max)))
2914 ;; Current position of point.
2915 (goto-char ,(point))
2916 ;; Overlays with invisible property.
2920 (let ((invis-prop (overlay-get ov
'invisible
)))
2923 (make-overlay ,(overlay-start ov
)
2925 'invisible
(quote ,invis-prop
))
2927 (overlays-in (point-min) (point-max)))
2931 (defun org-export-as
2932 (backend &optional subtreep visible-only body-only ext-plist
)
2933 "Transcode current Org buffer into BACKEND code.
2935 BACKEND is either an export back-end, as returned by, e.g.,
2936 `org-export-create-backend', or a symbol referring to
2937 a registered back-end.
2939 If narrowing is active in the current buffer, only transcode its
2942 If a region is active, transcode that region.
2944 When optional argument SUBTREEP is non-nil, transcode the
2945 sub-tree at point, extracting information from the headline
2948 When optional argument VISIBLE-ONLY is non-nil, don't export
2949 contents of hidden elements.
2951 When optional argument BODY-ONLY is non-nil, only return body
2952 code, without surrounding template.
2954 Optional argument EXT-PLIST, when provided, is a property list
2955 with external parameters overriding Org default settings, but
2956 still inferior to file-local settings.
2958 Return code as a string."
2959 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
2960 (org-export-barf-if-invalid-backend backend
)
2963 ;; Narrow buffer to an appropriate region or subtree for
2964 ;; parsing. If parsing subtree, be sure to remove main headline
2966 (cond ((org-region-active-p)
2967 (narrow-to-region (region-beginning) (region-end)))
2969 (org-narrow-to-subtree)
2970 (goto-char (point-min))
2972 (narrow-to-region (point) (point-max))))
2973 ;; Initialize communication channel with original buffer
2974 ;; attributes, unavailable in its copy.
2975 (let* ((org-export-current-backend (org-export-backend-name backend
))
2976 (info (org-combine-plists
2977 (list :export-options
2979 (list (and subtreep
'subtree
)
2980 (and visible-only
'visible-only
)
2981 (and body-only
'body-only
))))
2982 (org-export--get-buffer-attributes)))
2984 ;; Update communication channel and get parse tree. Buffer
2985 ;; isn't parsed directly. Instead, a temporary copy is
2986 ;; created, where include keywords, macros are expanded and
2987 ;; code blocks are evaluated.
2988 (org-export-with-buffer-copy
2989 ;; Run first hook with current back-end's name as argument.
2990 (run-hook-with-args 'org-export-before-processing-hook
2991 (org-export-backend-name backend
))
2992 (org-export-expand-include-keyword)
2993 ;; Update macro templates since #+INCLUDE keywords might have
2994 ;; added some new ones.
2995 (org-macro-initialize-templates)
2996 (org-macro-replace-all org-macro-templates
)
2997 (org-export-execute-babel-code)
2998 ;; Update radio targets since keyword inclusion might have
3000 (org-update-radio-target-regexp)
3001 ;; Run last hook with current back-end's name as argument.
3002 (goto-char (point-min))
3004 (run-hook-with-args 'org-export-before-parsing-hook
3005 (org-export-backend-name backend
)))
3006 ;; Update communication channel with environment. Also
3007 ;; install user's and developer's filters.
3009 (org-export-install-filters
3011 info
(org-export-get-environment backend subtreep ext-plist
))))
3012 ;; Expand export-specific set of macros: {{{author}}},
3013 ;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done
3014 ;; once regular macros have been expanded, since document
3015 ;; keywords may contain one of them.
3016 (org-macro-replace-all
3017 (list (cons "author"
3018 (org-element-interpret-data (plist-get info
:author
)))
3020 (org-element-interpret-data (plist-get info
:date
)))
3021 ;; EMAIL is not a parsed keyword: store it as-is.
3022 (cons "email" (or (plist-get info
:email
) ""))
3024 (org-element-interpret-data (plist-get info
:title
)))))
3025 ;; Call options filters and update export options. We do not
3026 ;; use `org-export-filter-apply-functions' here since the
3027 ;; arity of such filters is different.
3028 (let ((backend-name (org-export-backend-name backend
)))
3029 (dolist (filter (plist-get info
:filter-options
))
3030 (let ((result (funcall filter info backend-name
)))
3031 (when result
(setq info result
)))))
3032 ;; Parse buffer and call parse-tree filter on it.
3034 (org-export-filter-apply-functions
3035 (plist-get info
:filter-parse-tree
)
3036 (org-element-parse-buffer nil visible-only
) info
))
3037 ;; Now tree is complete, compute its properties and add them
3038 ;; to communication channel.
3041 info
(org-export-collect-tree-properties tree info
)))
3042 ;; Eventually transcode TREE. Wrap the resulting string into
3044 (let* ((body (org-element-normalize-string
3045 (or (org-export-data tree info
) "")))
3046 (inner-template (cdr (assq 'inner-template
3047 (plist-get info
:translate-alist
))))
3048 (full-body (if (not (functionp inner-template
)) body
3049 (funcall inner-template body info
)))
3050 (template (cdr (assq 'template
3051 (plist-get info
:translate-alist
)))))
3052 ;; Remove all text properties since they cannot be
3053 ;; retrieved from an external process. Finally call
3054 ;; final-output filter and return result.
3056 (org-export-filter-apply-functions
3057 (plist-get info
:filter-final-output
)
3058 (if (or (not (functionp template
)) body-only
) full-body
3059 (funcall template full-body info
))
3063 (defun org-export-string-as (string backend
&optional body-only ext-plist
)
3064 "Transcode STRING into BACKEND code.
3066 BACKEND is either an export back-end, as returned by, e.g.,
3067 `org-export-create-backend', or a symbol referring to
3068 a registered back-end.
3070 When optional argument BODY-ONLY is non-nil, only return body
3071 code, without preamble nor postamble.
3073 Optional argument EXT-PLIST, when provided, is a property list
3074 with external parameters overriding Org default settings, but
3075 still inferior to file-local settings.
3077 Return code as a string."
3080 (let ((org-inhibit-startup t
)) (org-mode))
3081 (org-export-as backend nil nil body-only ext-plist
)))
3084 (defun org-export-replace-region-by (backend)
3085 "Replace the active region by its export to BACKEND.
3086 BACKEND is either an export back-end, as returned by, e.g.,
3087 `org-export-create-backend', or a symbol referring to
3088 a registered back-end."
3089 (if (not (org-region-active-p))
3090 (user-error "No active region to replace")
3091 (let* ((beg (region-beginning))
3093 (str (buffer-substring beg end
)) rpl
)
3094 (setq rpl
(org-export-string-as str backend t
))
3095 (delete-region beg end
)
3099 (defun org-export-insert-default-template (&optional backend subtreep
)
3100 "Insert all export keywords with default values at beginning of line.
3102 BACKEND is a symbol referring to the name of a registered export
3103 back-end, for which specific export options should be added to
3104 the template, or `default' for default template. When it is nil,
3105 the user will be prompted for a category.
3107 If SUBTREEP is non-nil, export configuration will be set up
3108 locally for the subtree through node properties."
3110 (unless (derived-mode-p 'org-mode
) (user-error "Not in an Org mode buffer"))
3111 (when (and subtreep
(org-before-first-heading-p))
3112 (user-error "No subtree to set export options for"))
3113 (let ((node (and subtreep
(save-excursion (org-back-to-heading t
) (point))))
3117 (org-completing-read
3118 "Options category: "
3121 (symbol-name (org-export-backend-name b
)))
3122 org-export--registered-backends
))))))
3124 ;; Populate OPTIONS and KEYWORDS.
3125 (dolist (entry (cond ((eq backend
'default
) org-export-options-alist
)
3126 ((org-export-backend-p backend
)
3127 (org-export-get-all-options backend
))
3128 (t (org-export-get-all-options
3129 (org-export-get-backend backend
)))))
3130 (let ((keyword (nth 1 entry
))
3131 (option (nth 2 entry
)))
3133 (keyword (unless (assoc keyword keywords
)
3135 (if (eq (nth 4 entry
) 'split
)
3136 (mapconcat 'identity
(eval (nth 3 entry
)) " ")
3137 (eval (nth 3 entry
)))))
3138 (push (cons keyword value
) keywords
))))
3139 (option (unless (assoc option options
)
3140 (push (cons option
(eval (nth 3 entry
))) options
))))))
3141 ;; Move to an appropriate location in order to insert options.
3142 (unless subtreep
(beginning-of-line))
3143 ;; First get TITLE, DATE, AUTHOR and EMAIL if they belong to the
3144 ;; list of available keywords.
3145 (when (assoc "TITLE" keywords
)
3147 (or (let ((visited-file (buffer-file-name (buffer-base-buffer))))
3149 (file-name-sans-extension
3150 (file-name-nondirectory visited-file
))))
3151 (buffer-name (buffer-base-buffer)))))
3152 (if (not subtreep
) (insert (format "#+TITLE: %s\n" title
))
3153 (org-entry-put node
"EXPORT_TITLE" title
))))
3154 (when (assoc "DATE" keywords
)
3155 (let ((date (with-temp-buffer (org-insert-time-stamp (current-time)))))
3156 (if (not subtreep
) (insert "#+DATE: " date
"\n")
3157 (org-entry-put node
"EXPORT_DATE" date
))))
3158 (when (assoc "AUTHOR" keywords
)
3159 (let ((author (cdr (assoc "AUTHOR" keywords
))))
3160 (if subtreep
(org-entry-put node
"EXPORT_AUTHOR" author
)
3162 (format "#+AUTHOR:%s\n"
3163 (if (not (org-string-nw-p author
)) ""
3164 (concat " " author
)))))))
3165 (when (assoc "EMAIL" keywords
)
3166 (let ((email (cdr (assoc "EMAIL" keywords
))))
3167 (if subtreep
(org-entry-put node
"EXPORT_EMAIL" email
)
3169 (format "#+EMAIL:%s\n"
3170 (if (not (org-string-nw-p email
)) ""
3171 (concat " " email
)))))))
3172 ;; Then (multiple) OPTIONS lines. Never go past fill-column.
3176 #'(lambda (opt) (format "%s:%S" (car opt
) (cdr opt
)))
3177 (sort options
(lambda (k1 k2
) (string< (car k1
) (car k2
)))))))
3180 node
"EXPORT_OPTIONS" (mapconcat 'identity items
" "))
3182 (insert "#+OPTIONS:")
3185 (< (+ width
(length (car items
)) 1) fill-column
))
3186 (let ((item (pop items
)))
3188 (incf width
(1+ (length item
))))))
3190 ;; And the rest of keywords.
3191 (dolist (key (sort keywords
(lambda (k1 k2
) (string< (car k1
) (car k2
)))))
3192 (unless (member (car key
) '("TITLE" "DATE" "AUTHOR" "EMAIL"))
3193 (let ((val (cdr key
)))
3194 (if subtreep
(org-entry-put node
(concat "EXPORT_" (car key
)) val
)
3198 (if (org-string-nw-p val
) (format " %s" val
) "")))))))))
3200 (defun org-export-expand-include-keyword (&optional included dir
)
3201 "Expand every include keyword in buffer.
3202 Optional argument INCLUDED is a list of included file names along
3203 with their line restriction, when appropriate. It is used to
3204 avoid infinite recursion. Optional argument DIR is the current
3205 working directory. It is used to properly resolve relative
3207 (let ((case-fold-search t
))
3208 (goto-char (point-min))
3209 (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t
)
3210 (let ((element (save-match-data (org-element-at-point))))
3211 (when (eq (org-element-type element
) 'keyword
)
3213 ;; Extract arguments from keyword's value.
3214 (let* ((value (org-element-property :value element
))
3215 (ind (org-get-indentation))
3216 (file (and (string-match
3217 "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value
)
3218 (prog1 (expand-file-name
3219 (org-remove-double-quotes
3220 (match-string 1 value
))
3222 (setq value
(replace-match "" nil nil value
)))))
3225 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
3227 (prog1 (match-string 1 value
)
3228 (setq value
(replace-match "" nil nil value
)))))
3229 (env (cond ((string-match "\\<example\\>" value
) 'example
)
3230 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value
)
3231 (match-string 1 value
))))
3232 ;; Minimal level of included file defaults to the child
3233 ;; level of the current headline, if any, or one. It
3234 ;; only applies is the file is meant to be included as
3238 (if (string-match ":minlevel +\\([0-9]+\\)" value
)
3239 (prog1 (string-to-number (match-string 1 value
))
3240 (setq value
(replace-match "" nil nil value
)))
3241 (let ((cur (org-current-level)))
3242 (if cur
(1+ (org-reduced-level cur
)) 1))))))
3244 (delete-region (point) (progn (forward-line) (point)))
3247 ((not (file-readable-p file
))
3248 (error "Cannot include file %s" file
))
3249 ;; Check if files has already been parsed. Look after
3250 ;; inclusion lines too, as different parts of the same file
3251 ;; can be included too.
3252 ((member (list file lines
) included
)
3253 (error "Recursive file inclusion: %s" file
))
3258 (let ((ind-str (make-string ind ?
))
3260 (org-escape-code-in-string
3261 (org-export--prepare-file-contents file lines
))))
3262 (format "%s#+BEGIN_EXAMPLE\n%s%s#+END_EXAMPLE\n"
3263 ind-str contents ind-str
))))
3266 (let ((ind-str (make-string ind ?
))
3268 (org-escape-code-in-string
3269 (org-export--prepare-file-contents file lines
))))
3270 (format "%s#+BEGIN_SRC %s\n%s%s#+END_SRC\n"
3271 ind-str env contents ind-str
))))
3275 (let ((org-inhibit-startup t
)) (org-mode))
3277 (org-export--prepare-file-contents file lines ind minlevel
))
3278 (org-export-expand-include-keyword
3279 (cons (list file lines
) included
)
3280 (file-name-directory file
))
3281 (buffer-string)))))))))))))
3283 (defun org-export--prepare-file-contents (file &optional lines ind minlevel
)
3284 "Prepare the contents of FILE for inclusion and return them as a string.
3286 When optional argument LINES is a string specifying a range of
3287 lines, include only those lines.
3289 Optional argument IND, when non-nil, is an integer specifying the
3290 global indentation of returned contents. Since its purpose is to
3291 allow an included file to stay in the same environment it was
3292 created \(i.e. a list item), it doesn't apply past the first
3293 headline encountered.
3295 Optional argument MINLEVEL, when non-nil, is an integer
3296 specifying the level that any top-level headline in the included
3299 (insert-file-contents file
)
3301 (let* ((lines (split-string lines
"-"))
3302 (lbeg (string-to-number (car lines
)))
3303 (lend (string-to-number (cadr lines
)))
3304 (beg (if (zerop lbeg
) (point-min)
3305 (goto-char (point-min))
3306 (forward-line (1- lbeg
))
3308 (end (if (zerop lend
) (point-max)
3309 (goto-char (point-min))
3310 (forward-line (1- lend
))
3312 (narrow-to-region beg end
)))
3313 ;; Remove blank lines at beginning and end of contents. The logic
3314 ;; behind that removal is that blank lines around include keyword
3315 ;; override blank lines in included file.
3316 (goto-char (point-min))
3317 (org-skip-whitespace)
3319 (delete-region (point-min) (point))
3320 (goto-char (point-max))
3321 (skip-chars-backward " \r\t\n")
3323 (delete-region (point) (point-max))
3324 ;; If IND is set, preserve indentation of include keyword until
3325 ;; the first headline encountered.
3327 (unless (eq major-mode
'org-mode
)
3328 (let ((org-inhibit-startup t
)) (org-mode)))
3329 (goto-char (point-min))
3330 (let ((ind-str (make-string ind ?
)))
3331 (while (not (or (eobp) (looking-at org-outline-regexp-bol
)))
3332 ;; Do not move footnote definitions out of column 0.
3333 (unless (and (looking-at org-footnote-definition-re
)
3334 (eq (org-element-type (org-element-at-point))
3335 'footnote-definition
))
3338 ;; When MINLEVEL is specified, compute minimal level for headlines
3339 ;; in the file (CUR-MIN), and remove stars to each headline so
3340 ;; that headlines with minimal level have a level of MINLEVEL.
3342 (unless (eq major-mode
'org-mode
)
3343 (let ((org-inhibit-startup t
)) (org-mode)))
3344 (org-with-limited-levels
3345 (let ((levels (org-map-entries
3346 (lambda () (org-reduced-level (org-current-level))))))
3348 (let ((offset (- minlevel
(apply 'min levels
))))
3349 (unless (zerop offset
)
3350 (when org-odd-levels-only
(setq offset
(* offset
2)))
3351 ;; Only change stars, don't bother moving whole
3354 (lambda () (if (< offset
0) (delete-char (abs offset
))
3355 (insert (make-string offset ?
*)))))))))))
3356 (org-element-normalize-string (buffer-string))))
3358 (defun org-export-execute-babel-code ()
3359 "Execute every Babel code in the visible part of current buffer."
3360 ;; Get a pristine copy of current buffer so Babel references can be
3361 ;; properly resolved.
3362 (let ((reference (org-export-copy-buffer)))
3363 (unwind-protect (let ((org-current-export-file reference
))
3364 (org-babel-exp-process-buffer))
3365 (kill-buffer reference
))))
3367 (defun org-export--copy-to-kill-ring-p ()
3368 "Return a non-nil value when output should be added to the kill ring.
3369 See also `org-export-copy-to-kill-ring'."
3370 (if (eq org-export-copy-to-kill-ring
'if-interactive
)
3371 (not (or executing-kbd-macro noninteractive
))
3372 (eq org-export-copy-to-kill-ring t
)))
3376 ;;; Tools For Back-Ends
3378 ;; A whole set of tools is available to help build new exporters. Any
3379 ;; function general enough to have its use across many back-ends
3380 ;; should be added here.
3382 ;;;; For Affiliated Keywords
3384 ;; `org-export-read-attribute' reads a property from a given element
3385 ;; as a plist. It can be used to normalize affiliated keywords'
3388 ;; Since captions can span over multiple lines and accept dual values,
3389 ;; their internal representation is a bit tricky. Therefore,
3390 ;; `org-export-get-caption' transparently returns a given element's
3391 ;; caption as a secondary string.
3393 (defun org-export-read-attribute (attribute element
&optional property
)
3394 "Turn ATTRIBUTE property from ELEMENT into a plist.
3396 When optional argument PROPERTY is non-nil, return the value of
3397 that property within attributes.
3399 This function assumes attributes are defined as \":keyword
3400 value\" pairs. It is appropriate for `:attr_html' like
3403 All values will become strings except the empty string and
3404 \"nil\", which will become nil. Also, values containing only
3405 double quotes will be read as-is, which means that \"\" value
3406 will become the empty string."
3407 (let* ((prepare-value
3410 (cond ((member str
'(nil "" "nil")) nil
)
3411 ((string-match "^\"\\(\"+\\)?\"$" str
)
3412 (or (match-string 1 str
) ""))
3415 (let ((value (org-element-property attribute element
)))
3417 (let ((s (mapconcat 'identity value
" ")) result
)
3418 (while (string-match
3419 "\\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ \t]+\\|$\\)"
3421 (let ((value (substring s
0 (match-beginning 0))))
3422 (push (funcall prepare-value value
) result
))
3423 (push (intern (match-string 1 s
)) result
)
3424 (setq s
(substring s
(match-end 0))))
3425 ;; Ignore any string before first property with `cdr'.
3426 (cdr (nreverse (cons (funcall prepare-value s
) result
))))))))
3427 (if property
(plist-get attributes property
) attributes
)))
3429 (defun org-export-get-caption (element &optional shortp
)
3430 "Return caption from ELEMENT as a secondary string.
3432 When optional argument SHORTP is non-nil, return short caption,
3433 as a secondary string, instead.
3435 Caption lines are separated by a white space."
3436 (let ((full-caption (org-element-property :caption element
)) caption
)
3437 (dolist (line full-caption
(cdr caption
))
3438 (let ((cap (funcall (if shortp
'cdr
'car
) line
)))
3440 (setq caption
(nconc (list " ") (copy-sequence cap
) caption
)))))))
3443 ;;;; For Derived Back-ends
3445 ;; `org-export-with-backend' is a function allowing to locally use
3446 ;; another back-end to transcode some object or element. In a derived
3447 ;; back-end, it may be used as a fall-back function once all specific
3448 ;; cases have been treated.
3450 (defun org-export-with-backend (backend data
&optional contents info
)
3451 "Call a transcoder from BACKEND on DATA.
3452 BACKEND is an export back-end, as returned by, e.g.,
3453 `org-export-create-backend', or a symbol referring to
3454 a registered back-end. DATA is an Org element, object, secondary
3455 string or string. CONTENTS, when non-nil, is the transcoded
3456 contents of DATA element, as a string. INFO, when non-nil, is
3457 the communication channel used for export, as a plist."
3458 (when (symbolp backend
) (setq backend
(org-export-get-backend backend
)))
3459 (org-export-barf-if-invalid-backend backend
)
3460 (let ((type (org-element-type data
)))
3461 (if (memq type
'(nil org-data
)) (error "No foreign transcoder available")
3462 (let* ((all-transcoders (org-export-get-all-transcoders backend
))
3463 (transcoder (cdr (assq type all-transcoders
))))
3464 (if (not (functionp transcoder
))
3465 (error "No foreign transcoder available")
3467 transcoder data contents
3469 info
(list :back-end backend
3470 :translate-alist all-transcoders
3471 :exported-data
(make-hash-table :test
'eq
:size
401)))))))))
3474 ;;;; For Export Snippets
3476 ;; Every export snippet is transmitted to the back-end. Though, the
3477 ;; latter will only retain one type of export-snippet, ignoring
3478 ;; others, based on the former's target back-end. The function
3479 ;; `org-export-snippet-backend' returns that back-end for a given
3482 (defun org-export-snippet-backend (export-snippet)
3483 "Return EXPORT-SNIPPET targeted back-end as a symbol.
3484 Translation, with `org-export-snippet-translation-alist', is
3486 (let ((back-end (org-element-property :back-end export-snippet
)))
3488 (or (cdr (assoc back-end org-export-snippet-translation-alist
))
3494 ;; `org-export-collect-footnote-definitions' is a tool to list
3495 ;; actually used footnotes definitions in the whole parse tree, or in
3496 ;; a headline, in order to add footnote listings throughout the
3499 ;; `org-export-footnote-first-reference-p' is a predicate used by some
3500 ;; back-ends, when they need to attach the footnote definition only to
3501 ;; the first occurrence of the corresponding label.
3503 ;; `org-export-get-footnote-definition' and
3504 ;; `org-export-get-footnote-number' provide easier access to
3505 ;; additional information relative to a footnote reference.
3507 (defun org-export-collect-footnote-definitions (data info
)
3508 "Return an alist between footnote numbers, labels and definitions.
3510 DATA is the parse tree from which definitions are collected.
3511 INFO is the plist used as a communication channel.
3513 Definitions are sorted by order of references. They either
3514 appear as Org data or as a secondary string for inlined
3515 footnotes. Unreferenced definitions are ignored."
3517 collect-fn
; for byte-compiler.
3521 ;; Collect footnote number, label and definition in DATA.
3522 (org-element-map data
'footnote-reference
3524 (when (org-export-footnote-first-reference-p fn info
)
3525 (let ((def (org-export-get-footnote-definition fn info
)))
3527 (list (org-export-get-footnote-number fn info
)
3528 (org-element-property :label fn
)
3531 ;; Also search in definition for nested footnotes.
3532 (when (eq (org-element-property :type fn
) 'standard
)
3533 (funcall collect-fn def
)))))
3534 ;; Don't enter footnote definitions since it will happen
3535 ;; when their first reference is found.
3536 info nil
'footnote-definition
)))))
3537 (funcall collect-fn
(plist-get info
:parse-tree
))
3538 (reverse num-alist
)))
3540 (defun org-export-footnote-first-reference-p (footnote-reference info
)
3541 "Non-nil when a footnote reference is the first one for its label.
3543 FOOTNOTE-REFERENCE is the footnote reference being considered.
3544 INFO is the plist used as a communication channel."
3545 (let ((label (org-element-property :label footnote-reference
)))
3546 ;; Anonymous footnotes are always a first reference.
3548 ;; Otherwise, return the first footnote with the same LABEL and
3549 ;; test if it is equal to FOOTNOTE-REFERENCE.
3550 (let* (search-refs ; for byte-compiler.
3554 (org-element-map data
'footnote-reference
3557 ((string= (org-element-property :label fn
) label
)
3559 ;; If FN isn't inlined, be sure to traverse its
3560 ;; definition before resuming search. See
3561 ;; comments in `org-export-get-footnote-number'
3562 ;; for more information.
3563 ((eq (org-element-property :type fn
) 'standard
)
3564 (funcall search-refs
3565 (org-export-get-footnote-definition fn info
)))))
3566 ;; Don't enter footnote definitions since it will
3567 ;; happen when their first reference is found.
3568 info
'first-match
'footnote-definition
)))))
3569 (eq (catch 'exit
(funcall search-refs
(plist-get info
:parse-tree
)))
3570 footnote-reference
)))))
3572 (defun org-export-get-footnote-definition (footnote-reference info
)
3573 "Return definition of FOOTNOTE-REFERENCE as parsed data.
3574 INFO is the plist used as a communication channel. If no such
3575 definition can be found, return the \"DEFINITION NOT FOUND\"
3577 (let ((label (org-element-property :label footnote-reference
)))
3578 (or (org-element-property :inline-definition footnote-reference
)
3579 (cdr (assoc label
(plist-get info
:footnote-definition-alist
)))
3580 "DEFINITION NOT FOUND.")))
3582 (defun org-export-get-footnote-number (footnote info
)
3583 "Return number associated to a footnote.
3585 FOOTNOTE is either a footnote reference or a footnote definition.
3586 INFO is the plist used as a communication channel."
3587 (let* ((label (org-element-property :label footnote
))
3589 search-ref
; For byte-compiler.
3593 ;; Search footnote references through DATA, filling
3594 ;; SEEN-REFS along the way.
3595 (org-element-map data
'footnote-reference
3597 (let ((fn-lbl (org-element-property :label fn
)))
3599 ;; Anonymous footnote match: return number.
3600 ((and (not fn-lbl
) (eq fn footnote
))
3601 (throw 'exit
(1+ (length seen-refs
))))
3602 ;; Labels match: return number.
3603 ((and label
(string= label fn-lbl
))
3604 (throw 'exit
(1+ (length seen-refs
))))
3605 ;; Anonymous footnote: it's always a new one.
3606 ;; Also, be sure to return nil from the `cond' so
3607 ;; `first-match' doesn't get us out of the loop.
3608 ((not fn-lbl
) (push 'inline seen-refs
) nil
)
3609 ;; Label not seen so far: add it so SEEN-REFS.
3611 ;; Also search for subsequent references in
3612 ;; footnote definition so numbering follows
3613 ;; reading logic. Note that we don't have to care
3614 ;; about inline definitions, since
3615 ;; `org-element-map' already traverses them at the
3618 ;; Once again, return nil to stay in the loop.
3619 ((not (member fn-lbl seen-refs
))
3620 (push fn-lbl seen-refs
)
3622 (org-export-get-footnote-definition fn info
))
3624 ;; Don't enter footnote definitions since it will
3625 ;; happen when their first reference is found.
3626 info
'first-match
'footnote-definition
)))))
3627 (catch 'exit
(funcall search-ref
(plist-get info
:parse-tree
)))))
3632 ;; `org-export-get-relative-level' is a shortcut to get headline
3633 ;; level, relatively to the lower headline level in the parsed tree.
3635 ;; `org-export-get-headline-number' returns the section number of an
3636 ;; headline, while `org-export-number-to-roman' allows to convert it
3637 ;; to roman numbers.
3639 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
3640 ;; `org-export-last-sibling-p' are three useful predicates when it
3641 ;; comes to fulfill the `:headline-levels' property.
3643 ;; `org-export-get-tags', `org-export-get-category' and
3644 ;; `org-export-get-node-property' extract useful information from an
3645 ;; headline or a parent headline. They all handle inheritance.
3647 ;; `org-export-get-alt-title' tries to retrieve an alternative title,
3648 ;; as a secondary string, suitable for table of contents. It falls
3649 ;; back onto default title.
3651 (defun org-export-get-relative-level (headline info
)
3652 "Return HEADLINE relative level within current parsed tree.
3653 INFO is a plist holding contextual information."
3654 (+ (org-element-property :level headline
)
3655 (or (plist-get info
:headline-offset
) 0)))
3657 (defun org-export-low-level-p (headline info
)
3658 "Non-nil when HEADLINE is considered as low level.
3660 INFO is a plist used as a communication channel.
3662 A low level headlines has a relative level greater than
3663 `:headline-levels' property value.
3665 Return value is the difference between HEADLINE relative level
3666 and the last level being considered as high enough, or nil."
3667 (let ((limit (plist-get info
:headline-levels
)))
3668 (when (wholenump limit
)
3669 (let ((level (org-export-get-relative-level headline info
)))
3670 (and (> level limit
) (- level limit
))))))
3672 (defun org-export-get-headline-number (headline info
)
3673 "Return HEADLINE numbering as a list of numbers.
3674 INFO is a plist holding contextual information."
3675 (cdr (assoc headline
(plist-get info
:headline-numbering
))))
3677 (defun org-export-numbered-headline-p (headline info
)
3678 "Return a non-nil value if HEADLINE element should be numbered.
3679 INFO is a plist used as a communication channel."
3680 (let ((sec-num (plist-get info
:section-numbers
))
3681 (level (org-export-get-relative-level headline info
)))
3682 (if (wholenump sec-num
) (<= level sec-num
) sec-num
)))
3684 (defun org-export-number-to-roman (n)
3685 "Convert integer N into a roman numeral."
3686 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
3687 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
3688 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
3692 (number-to-string n
)
3694 (if (>= n
(caar roman
))
3695 (setq n
(- n
(caar roman
))
3696 res
(concat res
(cdar roman
)))
3700 (defun org-export-get-tags (element info
&optional tags inherited
)
3701 "Return list of tags associated to ELEMENT.
3703 ELEMENT has either an `headline' or an `inlinetask' type. INFO
3704 is a plist used as a communication channel.
3706 Select tags (see `org-export-select-tags') and exclude tags (see
3707 `org-export-exclude-tags') are removed from the list.
3709 When non-nil, optional argument TAGS should be a list of strings.
3710 Any tag belonging to this list will also be removed.
3712 When optional argument INHERITED is non-nil, tags can also be
3713 inherited from parent headlines and FILETAGS keywords."
3715 (lambda (tag) (or (member tag
(plist-get info
:select-tags
))
3716 (member tag
(plist-get info
:exclude-tags
))
3718 (if (not inherited
) (org-element-property :tags element
)
3719 ;; Build complete list of inherited tags.
3720 (let ((current-tag-list (org-element-property :tags element
)))
3725 (when (and (memq (org-element-type parent
) '(headline inlinetask
))
3726 (not (member tag current-tag-list
)))
3727 (push tag current-tag-list
)))
3728 (org-element-property :tags parent
)))
3729 (org-export-get-genealogy element
))
3730 ;; Add FILETAGS keywords and return results.
3731 (org-uniquify (append (plist-get info
:filetags
) current-tag-list
))))))
3733 (defun org-export-get-node-property (property blob
&optional inherited
)
3734 "Return node PROPERTY value for BLOB.
3736 PROPERTY is an upcase symbol (i.e. `:COOKIE_DATA'). BLOB is an
3739 If optional argument INHERITED is non-nil, the value can be
3740 inherited from a parent headline.
3742 Return value is a string or nil."
3743 (let ((headline (if (eq (org-element-type blob
) 'headline
) blob
3744 (org-export-get-parent-headline blob
))))
3745 (if (not inherited
) (org-element-property property blob
)
3746 (let ((parent headline
) value
)
3749 (when (plist-member (nth 1 parent
) property
)
3750 (throw 'found
(org-element-property property parent
)))
3751 (setq parent
(org-element-property :parent parent
))))))))
3753 (defun org-export-get-category (blob info
)
3754 "Return category for element or object BLOB.
3756 INFO is a plist used as a communication channel.
3758 CATEGORY is automatically inherited from a parent headline, from
3759 #+CATEGORY: keyword or created out of original file name. If all
3760 fail, the fall-back value is \"???\"."
3761 (or (let ((headline (if (eq (org-element-type blob
) 'headline
) blob
3762 (org-export-get-parent-headline blob
))))
3763 ;; Almost like `org-export-node-property', but we cannot trust
3764 ;; `plist-member' as every headline has a `:CATEGORY'
3765 ;; property, would it be nil or equal to "???" (which has the
3767 (let ((parent headline
) value
)
3770 (let ((category (org-element-property :CATEGORY parent
)))
3771 (and category
(not (equal "???" category
))
3772 (throw 'found category
)))
3773 (setq parent
(org-element-property :parent parent
))))))
3774 (org-element-map (plist-get info
:parse-tree
) 'keyword
3776 (when (equal (org-element-property :key kwd
) "CATEGORY")
3777 (org-element-property :value kwd
)))
3779 (let ((file (plist-get info
:input-file
)))
3780 (and file
(file-name-sans-extension (file-name-nondirectory file
))))
3783 (defun org-export-get-alt-title (headline info
)
3784 "Return alternative title for HEADLINE, as a secondary string.
3785 INFO is a plist used as a communication channel. If no optional
3786 title is defined, fall-back to the regular title."
3787 (or (org-element-property :alt-title headline
)
3788 (org-element-property :title headline
)))
3790 (defun org-export-first-sibling-p (headline info
)
3791 "Non-nil when HEADLINE is the first sibling in its sub-tree.
3792 INFO is a plist used as a communication channel."
3793 (not (eq (org-element-type (org-export-get-previous-element headline info
))
3796 (defun org-export-last-sibling-p (headline info
)
3797 "Non-nil when HEADLINE is the last sibling in its sub-tree.
3798 INFO is a plist used as a communication channel."
3799 (not (org-export-get-next-element headline info
)))
3804 ;; `org-export-get-date' returns a date appropriate for the document
3805 ;; to about to be exported. In particular, it takes care of
3806 ;; `org-export-date-timestamp-format'.
3808 (defun org-export-get-date (info &optional fmt
)
3809 "Return date value for the current document.
3811 INFO is a plist used as a communication channel. FMT, when
3812 non-nil, is a time format string that will be applied on the date
3813 if it consists in a single timestamp object. It defaults to
3814 `org-export-date-timestamp-format' when nil.
3816 A proper date can be a secondary string, a string or nil. It is
3817 meant to be translated with `org-export-data' or alike."
3818 (let ((date (plist-get info
:date
))
3819 (fmt (or fmt org-export-date-timestamp-format
)))
3820 (cond ((not date
) nil
)
3823 (eq (org-element-type (car date
)) 'timestamp
))
3824 (org-timestamp-format (car date
) fmt
))
3830 ;; `org-export-solidify-link-text' turns a string into a safer version
3831 ;; for links, replacing most non-standard characters with hyphens.
3833 ;; `org-export-get-coderef-format' returns an appropriate format
3834 ;; string for coderefs.
3836 ;; `org-export-inline-image-p' returns a non-nil value when the link
3837 ;; provided should be considered as an inline image.
3839 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
3840 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
3841 ;; returns an appropriate unique identifier when found, or nil.
3843 ;; `org-export-resolve-id-link' returns the first headline with
3844 ;; specified id or custom-id in parse tree, the path to the external
3845 ;; file with the id or nil when neither was found.
3847 ;; `org-export-resolve-coderef' associates a reference to a line
3848 ;; number in the element it belongs, or returns the reference itself
3849 ;; when the element isn't numbered.
3851 (defun org-export-solidify-link-text (s)
3852 "Take link text S and make a safe target out of it."
3854 (mapconcat 'identity
(org-split-string s
"[^a-zA-Z0-9_.-:]+") "-")))
3856 (defun org-export-get-coderef-format (path desc
)
3857 "Return format string for code reference link.
3858 PATH is the link path. DESC is its description."
3860 (cond ((not desc
) "%s")
3861 ((string-match (regexp-quote (concat "(" path
")")) desc
)
3862 (replace-match "%s" t t desc
))
3865 (defun org-export-inline-image-p (link &optional rules
)
3866 "Non-nil if LINK object points to an inline image.
3868 Optional argument is a set of RULES defining inline images. It
3869 is an alist where associations have the following shape:
3873 Applying a rule means apply REGEXP against LINK's path when its
3874 type is TYPE. The function will return a non-nil value if any of
3875 the provided rules is non-nil. The default rule is
3876 `org-export-default-inline-image-rule'.
3878 This only applies to links without a description."
3879 (and (not (org-element-contents link
))
3880 (let ((case-fold-search t
)
3881 (rules (or rules org-export-default-inline-image-rule
)))
3885 (and (string= (org-element-property :type link
) (car rule
))
3886 (string-match (cdr rule
)
3887 (org-element-property :path link
))
3890 ;; Return nil if no rule matched.
3893 (defun org-export-resolve-coderef (ref info
)
3894 "Resolve a code reference REF.
3896 INFO is a plist used as a communication channel.
3898 Return associated line number in source code, or REF itself,
3899 depending on src-block or example element's switches."
3900 (org-element-map (plist-get info
:parse-tree
) '(example-block src-block
)
3903 (insert (org-trim (org-element-property :value el
)))
3904 (let* ((label-fmt (regexp-quote
3905 (or (org-element-property :label-fmt el
)
3906 org-coderef-label-format
)))
3908 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
3909 (replace-regexp-in-string "%s" ref label-fmt nil t
))))
3910 ;; Element containing REF is found. Resolve it to either
3911 ;; a label or a line number, as needed.
3912 (when (re-search-backward ref-re nil t
)
3914 ((org-element-property :use-labels el
) ref
)
3915 ((eq (org-element-property :number-lines el
) 'continued
)
3916 (+ (org-export-get-loc el info
) (line-number-at-pos)))
3917 (t (line-number-at-pos)))))))
3920 (defun org-export-resolve-fuzzy-link (link info
)
3921 "Return LINK destination.
3923 INFO is a plist holding contextual information.
3925 Return value can be an object, an element, or nil:
3927 - If LINK path matches a target object (i.e. <<path>>) return it.
3929 - If LINK path exactly matches the name affiliated keyword
3930 \(i.e. #+NAME: path) of an element, return that element.
3932 - If LINK path exactly matches any headline name, return that
3933 element. If more than one headline share that name, priority
3934 will be given to the one with the closest common ancestor, if
3935 any, or the first one in the parse tree otherwise.
3937 - Otherwise, return nil.
3939 Assume LINK type is \"fuzzy\". White spaces are not
3941 (let* ((raw-path (org-element-property :path link
))
3942 (match-title-p (eq (aref raw-path
0) ?
*))
3943 ;; Split PATH at white spaces so matches are space
3945 (path (org-split-string
3946 (if match-title-p
(substring raw-path
1) raw-path
)))
3947 ;; Cache for destinations that are not position dependent.
3949 (or (plist-get info
:resolve-fuzzy-link-cache
)
3950 (plist-get (setq info
(plist-put info
:resolve-fuzzy-link-cache
3951 (make-hash-table :test
'equal
)))
3952 :resolve-fuzzy-link-cache
)))
3953 (cached (gethash path link-cache
'not-found
)))
3955 ;; Destination is not position dependent: use cached value.
3956 ((and (not match-title-p
) (not (eq cached
'not-found
))) cached
)
3957 ;; First try to find a matching "<<path>>" unless user specified
3958 ;; he was looking for a headline (path starts with a "*"
3960 ((and (not match-title-p
)
3961 (let ((match (org-element-map (plist-get info
:parse-tree
) 'target
3963 (and (equal (org-split-string
3964 (org-element-property :value blob
))
3967 info
'first-match
)))
3968 (and match
(puthash path match link-cache
)))))
3969 ;; Then try to find an element with a matching "#+NAME: path"
3970 ;; affiliated keyword.
3971 ((and (not match-title-p
)
3972 (let ((match (org-element-map (plist-get info
:parse-tree
)
3973 org-element-all-elements
3975 (let ((name (org-element-property :name el
)))
3977 (equal (org-split-string name
) path
))
3979 info
'first-match
)))
3980 (and match
(puthash path match link-cache
)))))
3981 ;; Last case: link either points to a headline or to nothingness.
3982 ;; Try to find the source, with priority given to headlines with
3983 ;; the closest common ancestor. If such candidate is found,
3984 ;; return it, otherwise return nil.
3986 (let ((find-headline
3988 ;; Return first headline whose `:raw-value' property is
3989 ;; NAME in parse tree DATA, or nil. Statistics cookies
3992 (org-element-map data
'headline
3994 (when (equal (org-split-string
3995 (replace-regexp-in-string
3996 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
3997 (org-element-property :raw-value headline
)))
4000 info
'first-match
)))))
4001 ;; Search among headlines sharing an ancestor with link, from
4002 ;; closest to farthest.
4006 (let ((foundp (funcall find-headline path parent
)))
4007 (when foundp
(throw 'exit foundp
))))
4008 (let ((parent-hl (org-export-get-parent-headline link
)))
4009 (if (not parent-hl
) (list (plist-get info
:parse-tree
))
4010 (cons parent-hl
(org-export-get-genealogy parent-hl
)))))
4011 ;; No destination found: return nil.
4012 (and (not match-title-p
) (puthash path nil link-cache
))))))))
4014 (defun org-export-resolve-id-link (link info
)
4015 "Return headline referenced as LINK destination.
4017 INFO is a plist used as a communication channel.
4019 Return value can be the headline element matched in current parse
4020 tree, a file name or nil. Assume LINK type is either \"id\" or
4022 (let ((id (org-element-property :path link
)))
4023 ;; First check if id is within the current parse tree.
4024 (or (org-element-map (plist-get info
:parse-tree
) 'headline
4026 (when (or (string= (org-element-property :ID headline
) id
)
4027 (string= (org-element-property :CUSTOM_ID headline
) id
))
4030 ;; Otherwise, look for external files.
4031 (cdr (assoc id
(plist-get info
:id-alist
))))))
4033 (defun org-export-resolve-radio-link (link info
)
4034 "Return radio-target object referenced as LINK destination.
4036 INFO is a plist used as a communication channel.
4038 Return value can be a radio-target object or nil. Assume LINK
4039 has type \"radio\"."
4040 (let ((path (replace-regexp-in-string
4041 "[ \r\t\n]+" " " (org-element-property :path link
))))
4042 (org-element-map (plist-get info
:parse-tree
) 'radio-target
4044 (and (eq (compare-strings
4045 (replace-regexp-in-string
4046 "[ \r\t\n]+" " " (org-element-property :value radio
))
4047 nil nil path nil nil t
)
4050 info
'first-match
)))
4055 ;; `org-export-get-ordinal' associates a sequence number to any object
4058 (defun org-export-get-ordinal (element info
&optional types predicate
)
4059 "Return ordinal number of an element or object.
4061 ELEMENT is the element or object considered. INFO is the plist
4062 used as a communication channel.
4064 Optional argument TYPES, when non-nil, is a list of element or
4065 object types, as symbols, that should also be counted in.
4066 Otherwise, only provided element's type is considered.
4068 Optional argument PREDICATE is a function returning a non-nil
4069 value if the current element or object should be counted in. It
4070 accepts two arguments: the element or object being considered and
4071 the plist used as a communication channel. This allows to count
4072 only a certain type of objects (i.e. inline images).
4074 Return value is a list of numbers if ELEMENT is a headline or an
4075 item. It is nil for keywords. It represents the footnote number
4076 for footnote definitions and footnote references. If ELEMENT is
4077 a target, return the same value as if ELEMENT was the closest
4078 table, item or headline containing the target. In any other
4079 case, return the sequence number of ELEMENT among elements or
4080 objects of the same type."
4081 ;; Ordinal of a target object refer to the ordinal of the closest
4082 ;; table, item, or headline containing the object.
4083 (when (eq (org-element-type element
) 'target
)
4085 (loop for parent in
(org-export-get-genealogy element
)
4088 (org-element-type parent
)
4089 '(footnote-definition footnote-reference headline item
4092 (case (org-element-type element
)
4093 ;; Special case 1: A headline returns its number as a list.
4094 (headline (org-export-get-headline-number element info
))
4095 ;; Special case 2: An item returns its number as a list.
4096 (item (let ((struct (org-element-property :structure element
)))
4097 (org-list-get-item-number
4098 (org-element-property :begin element
)
4100 (org-list-prevs-alist struct
)
4101 (org-list-parents-alist struct
))))
4102 ((footnote-definition footnote-reference
)
4103 (org-export-get-footnote-number element info
))
4106 ;; Increment counter until ELEMENT is found again.
4107 (org-element-map (plist-get info
:parse-tree
)
4108 (or types
(org-element-type element
))
4111 ((eq element el
) (1+ counter
))
4112 ((not predicate
) (incf counter
) nil
)
4113 ((funcall predicate el info
) (incf counter
) nil
)))
4114 info
'first-match
)))))
4119 ;; `org-export-get-loc' counts number of code lines accumulated in
4120 ;; src-block or example-block elements with a "+n" switch until
4121 ;; a given element, excluded. Note: "-n" switches reset that count.
4123 ;; `org-export-unravel-code' extracts source code (along with a code
4124 ;; references alist) from an `element-block' or `src-block' type
4127 ;; `org-export-format-code' applies a formatting function to each line
4128 ;; of code, providing relative line number and code reference when
4129 ;; appropriate. Since it doesn't access the original element from
4130 ;; which the source code is coming, it expects from the code calling
4131 ;; it to know if lines should be numbered and if code references
4134 ;; Eventually, `org-export-format-code-default' is a higher-level
4135 ;; function (it makes use of the two previous functions) which handles
4136 ;; line numbering and code references inclusion, and returns source
4137 ;; code in a format suitable for plain text or verbatim output.
4139 (defun org-export-get-loc (element info
)
4140 "Return accumulated lines of code up to ELEMENT.
4142 INFO is the plist used as a communication channel.
4144 ELEMENT is excluded from count."
4146 (org-element-map (plist-get info
:parse-tree
)
4147 `(src-block example-block
,(org-element-type element
))
4150 ;; ELEMENT is reached: Quit the loop.
4152 ;; Only count lines from src-block and example-block elements
4153 ;; with a "+n" or "-n" switch. A "-n" switch resets counter.
4154 ((not (memq (org-element-type el
) '(src-block example-block
))) nil
)
4155 ((let ((linums (org-element-property :number-lines el
)))
4157 ;; Accumulate locs or reset them.
4158 (let ((lines (org-count-lines
4159 (org-trim (org-element-property :value el
)))))
4160 (setq loc
(if (eq linums
'new
) lines
(+ loc lines
))))))
4161 ;; Return nil to stay in the loop.
4167 (defun org-export-unravel-code (element)
4168 "Clean source code and extract references out of it.
4170 ELEMENT has either a `src-block' an `example-block' type.
4172 Return a cons cell whose CAR is the source code, cleaned from any
4173 reference and protective comma and CDR is an alist between
4174 relative line number (integer) and name of code reference on that
4176 (let* ((line 0) refs
4177 ;; Get code and clean it. Remove blank lines at its
4178 ;; beginning and end.
4179 (code (replace-regexp-in-string
4180 "\\`\\([ \t]*\n\\)+" ""
4181 (replace-regexp-in-string
4182 "\\([ \t]*\n\\)*[ \t]*\\'" "\n"
4183 (org-element-property :value element
))))
4184 ;; Get format used for references.
4185 (label-fmt (regexp-quote
4186 (or (org-element-property :label-fmt element
)
4187 org-coderef-label-format
)))
4188 ;; Build a regexp matching a loc with a reference.
4190 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)[ \t]*\\)$"
4191 (replace-regexp-in-string
4192 "%s" "\\([-a-zA-Z0-9_ ]+\\)" label-fmt nil t
))))
4195 ;; Code with references removed.
4196 (org-element-normalize-string
4200 (if (not (string-match with-ref-re loc
)) loc
4201 ;; Ref line: remove ref, and signal its position in REFS.
4202 (push (cons line
(match-string 3 loc
)) refs
)
4203 (replace-match "" nil nil loc
1)))
4204 (org-split-string code
"\n") "\n"))
4208 (defun org-export-format-code (code fun
&optional num-lines ref-alist
)
4209 "Format CODE by applying FUN line-wise and return it.
4211 CODE is a string representing the code to format. FUN is
4212 a function. It must accept three arguments: a line of
4213 code (string), the current line number (integer) or nil and the
4214 reference associated to the current line (string) or nil.
4216 Optional argument NUM-LINES can be an integer representing the
4217 number of code lines accumulated until the current code. Line
4218 numbers passed to FUN will take it into account. If it is nil,
4219 FUN's second argument will always be nil. This number can be
4220 obtained with `org-export-get-loc' function.
4222 Optional argument REF-ALIST can be an alist between relative line
4223 number (i.e. ignoring NUM-LINES) and the name of the code
4224 reference on it. If it is nil, FUN's third argument will always
4225 be nil. It can be obtained through the use of
4226 `org-export-unravel-code' function."
4227 (let ((--locs (org-split-string code
"\n"))
4229 (org-element-normalize-string
4233 (let ((--ref (cdr (assq --line ref-alist
))))
4234 (funcall fun --loc
(and num-lines
(+ num-lines --line
)) --ref
)))
4237 (defun org-export-format-code-default (element info
)
4238 "Return source code from ELEMENT, formatted in a standard way.
4240 ELEMENT is either a `src-block' or `example-block' element. INFO
4241 is a plist used as a communication channel.
4243 This function takes care of line numbering and code references
4244 inclusion. Line numbers, when applicable, appear at the
4245 beginning of the line, separated from the code by two white
4246 spaces. Code references, on the other hand, appear flushed to
4247 the right, separated by six white spaces from the widest line of
4249 ;; Extract code and references.
4250 (let* ((code-info (org-export-unravel-code element
))
4251 (code (car code-info
))
4252 (code-lines (org-split-string code
"\n")))
4253 (if (null code-lines
) ""
4254 (let* ((refs (and (org-element-property :retain-labels element
)
4256 ;; Handle line numbering.
4257 (num-start (case (org-element-property :number-lines element
)
4258 (continued (org-export-get-loc element info
))
4263 (length (number-to-string
4264 (+ (length code-lines
) num-start
))))))
4265 ;; Prepare references display, if required. Any reference
4266 ;; should start six columns after the widest line of code,
4267 ;; wrapped with parenthesis.
4269 (+ (apply 'max
(mapcar 'length code-lines
))
4270 (if (not num-start
) 0 (length (format num-fmt num-start
))))))
4271 (org-export-format-code
4273 (lambda (loc line-num ref
)
4274 (let ((number-str (and num-fmt
(format num-fmt line-num
))))
4279 (concat (make-string
4281 (+ (length loc
) (length number-str
))) ?
)
4282 (format "(%s)" ref
))))))
4288 ;; `org-export-table-has-special-column-p' and and
4289 ;; `org-export-table-row-is-special-p' are predicates used to look for
4290 ;; meta-information about the table structure.
4292 ;; `org-table-has-header-p' tells when the rows before the first rule
4293 ;; should be considered as table's header.
4295 ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
4296 ;; and `org-export-table-cell-borders' extract information from
4297 ;; a table-cell element.
4299 ;; `org-export-table-dimensions' gives the number on rows and columns
4300 ;; in the table, ignoring horizontal rules and special columns.
4301 ;; `org-export-table-cell-address', given a table-cell object, returns
4302 ;; the absolute address of a cell. On the other hand,
4303 ;; `org-export-get-table-cell-at' does the contrary.
4305 ;; `org-export-table-cell-starts-colgroup-p',
4306 ;; `org-export-table-cell-ends-colgroup-p',
4307 ;; `org-export-table-row-starts-rowgroup-p',
4308 ;; `org-export-table-row-ends-rowgroup-p',
4309 ;; `org-export-table-row-starts-header-p' and
4310 ;; `org-export-table-row-ends-header-p' indicate position of current
4311 ;; row or cell within the table.
4313 (defun org-export-table-has-special-column-p (table)
4314 "Non-nil when TABLE has a special column.
4315 All special columns will be ignored during export."
4316 ;; The table has a special column when every first cell of every row
4317 ;; has an empty value or contains a symbol among "/", "#", "!", "$",
4318 ;; "*" "_" and "^". Though, do not consider a first row containing
4319 ;; only empty cells as special.
4320 (let ((special-column-p 'empty
))
4324 (when (eq (org-element-property :type row
) 'standard
)
4325 (let ((value (org-element-contents
4326 (car (org-element-contents row
)))))
4327 (cond ((member value
'(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
4328 (setq special-column-p
'special
))
4330 (t (throw 'exit nil
))))))
4331 (org-element-contents table
))
4332 (eq special-column-p
'special
))))
4334 (defun org-export-table-has-header-p (table info
)
4335 "Non-nil when TABLE has a header.
4337 INFO is a plist used as a communication channel.
4339 A table has a header when it contains at least two row groups."
4340 (let ((cache (or (plist-get info
:table-header-cache
)
4341 (plist-get (setq info
4342 (plist-put info
:table-header-cache
4343 (make-hash-table :test
'eq
)))
4344 :table-header-cache
))))
4345 (or (gethash table cache
)
4346 (let ((rowgroup 1) row-flag
)
4349 (org-element-map table
'table-row
4353 ((and row-flag
(eq (org-element-property :type row
) 'rule
))
4354 (incf rowgroup
) (setq row-flag nil
))
4355 ((and (not row-flag
) (eq (org-element-property :type row
)
4357 (setq row-flag t
) nil
)))
4361 (defun org-export-table-row-is-special-p (table-row info
)
4362 "Non-nil if TABLE-ROW is considered special.
4364 INFO is a plist used as the communication channel.
4366 All special rows will be ignored during export."
4367 (when (eq (org-element-property :type table-row
) 'standard
)
4368 (let ((first-cell (org-element-contents
4369 (car (org-element-contents table-row
)))))
4370 ;; A row is special either when...
4372 ;; ... it starts with a field only containing "/",
4373 (equal first-cell
'("/"))
4374 ;; ... the table contains a special column and the row start
4375 ;; with a marking character among, "^", "_", "$" or "!",
4376 (and (org-export-table-has-special-column-p
4377 (org-export-get-parent table-row
))
4378 (member first-cell
'(("^") ("_") ("$") ("!"))))
4379 ;; ... it contains only alignment cookies and empty cells.
4380 (let ((special-row-p 'empty
))
4384 (let ((value (org-element-contents cell
)))
4385 ;; Since VALUE is a secondary string, the following
4386 ;; checks avoid expanding it with `org-export-data'.
4388 ((and (not (cdr value
))
4389 (stringp (car value
))
4390 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
4392 (setq special-row-p
'cookie
))
4393 (t (throw 'exit nil
)))))
4394 (org-element-contents table-row
))
4395 (eq special-row-p
'cookie
)))))))
4397 (defun org-export-table-row-group (table-row info
)
4398 "Return TABLE-ROW's group number, as an integer.
4400 INFO is a plist used as the communication channel.
4402 Return value is the group number, as an integer, or nil for
4403 special rows and rows separators. First group is also table's
4405 (let ((cache (or (plist-get info
:table-row-group-cache
)
4406 (plist-get (setq info
4407 (plist-put info
:table-row-group-cache
4408 (make-hash-table :test
'eq
)))
4409 :table-row-group-cache
))))
4410 (cond ((gethash table-row cache
))
4411 ((eq (org-element-property :type table-row
) 'rule
) nil
)
4412 (t (let ((group 0) row-flag
)
4413 (org-element-map (org-export-get-parent table-row
) 'table-row
4415 (if (eq (org-element-property :type row
) 'rule
)
4417 (unless row-flag
(incf group
) (setq row-flag t
)))
4418 (when (eq table-row row
) (puthash table-row group cache
)))
4419 info
'first-match
))))))
4421 (defun org-export-table-cell-width (table-cell info
)
4422 "Return TABLE-CELL contents width.
4424 INFO is a plist used as the communication channel.
4426 Return value is the width given by the last width cookie in the
4427 same column as TABLE-CELL, or nil."
4428 (let* ((row (org-export-get-parent table-cell
))
4429 (table (org-export-get-parent row
))
4430 (cells (org-element-contents row
))
4431 (columns (length cells
))
4432 (column (- columns
(length (memq table-cell cells
))))
4433 (cache (or (plist-get info
:table-cell-width-cache
)
4434 (plist-get (setq info
4435 (plist-put info
:table-cell-width-cache
4436 (make-hash-table :test
'eq
)))
4437 :table-cell-width-cache
)))
4438 (width-vector (or (gethash table cache
)
4439 (puthash table
(make-vector columns
'empty
) cache
)))
4440 (value (aref width-vector column
)))
4441 (if (not (eq value
'empty
)) value
4443 (dolist (row (org-element-contents table
)
4444 (aset width-vector column cookie-width
))
4445 (when (org-export-table-row-is-special-p row info
)
4446 ;; In a special row, try to find a width cookie at COLUMN.
4447 (let* ((value (org-element-contents
4448 (elt (org-element-contents row
) column
)))
4449 (cookie (car value
)))
4450 ;; The following checks avoid expanding unnecessarily
4451 ;; the cell with `org-export-data'.
4455 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" cookie
)
4456 (match-string 1 cookie
))
4458 (string-to-number (match-string 1 cookie
)))))))))))
4460 (defun org-export-table-cell-alignment (table-cell info
)
4461 "Return TABLE-CELL contents alignment.
4463 INFO is a plist used as the communication channel.
4465 Return alignment as specified by the last alignment cookie in the
4466 same column as TABLE-CELL. If no such cookie is found, a default
4467 alignment value will be deduced from fraction of numbers in the
4468 column (see `org-table-number-fraction' for more information).
4469 Possible values are `left', `right' and `center'."
4470 ;; Load `org-table-number-fraction' and `org-table-number-regexp'.
4471 (require 'org-table
)
4472 (let* ((row (org-export-get-parent table-cell
))
4473 (table (org-export-get-parent row
))
4474 (cells (org-element-contents row
))
4475 (columns (length cells
))
4476 (column (- columns
(length (memq table-cell cells
))))
4477 (cache (or (plist-get info
:table-cell-alignment-cache
)
4478 (plist-get (setq info
4479 (plist-put info
:table-cell-alignment-cache
4480 (make-hash-table :test
'eq
)))
4481 :table-cell-alignment-cache
)))
4482 (align-vector (or (gethash table cache
)
4483 (puthash table
(make-vector columns nil
) cache
))))
4484 (or (aref align-vector column
)
4485 (let ((number-cells 0)
4488 previous-cell-number-p
)
4489 (dolist (row (org-element-contents (org-export-get-parent row
)))
4491 ;; In a special row, try to find an alignment cookie at
4493 ((org-export-table-row-is-special-p row info
)
4494 (let ((value (org-element-contents
4495 (elt (org-element-contents row
) column
))))
4496 ;; Since VALUE is a secondary string, the following
4497 ;; checks avoid useless expansion through
4498 ;; `org-export-data'.
4501 (stringp (car value
))
4502 (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
4504 (match-string 1 (car value
)))
4505 (setq cookie-align
(match-string 1 (car value
))))))
4506 ;; Ignore table rules.
4507 ((eq (org-element-property :type row
) 'rule
))
4508 ;; In a standard row, check if cell's contents are
4509 ;; expressing some kind of number. Increase NUMBER-CELLS
4510 ;; accordingly. Though, don't bother if an alignment
4511 ;; cookie has already defined cell's alignment.
4513 (let ((value (org-export-data
4514 (org-element-contents
4515 (elt (org-element-contents row
) column
))
4518 ;; Treat an empty cell as a number if it follows
4520 (if (not (or (string-match org-table-number-regexp value
)
4521 (and (string= value
"") previous-cell-number-p
)))
4522 (setq previous-cell-number-p nil
)
4523 (setq previous-cell-number-p t
)
4524 (incf number-cells
))))))
4525 ;; Return value. Alignment specified by cookies has
4526 ;; precedence over alignment deduced from cell's contents.
4529 (cond ((equal cookie-align
"l") 'left
)
4530 ((equal cookie-align
"r") 'right
)
4531 ((equal cookie-align
"c") 'center
)
4532 ((>= (/ (float number-cells
) total-cells
)
4533 org-table-number-fraction
)
4537 (defun org-export-table-cell-borders (table-cell info
)
4538 "Return TABLE-CELL borders.
4540 INFO is a plist used as a communication channel.
4542 Return value is a list of symbols, or nil. Possible values are:
4543 `top', `bottom', `above', `below', `left' and `right'. Note:
4544 `top' (resp. `bottom') only happen for a cell in the first
4545 row (resp. last row) of the table, ignoring table rules, if any.
4547 Returned borders ignore special rows."
4548 (let* ((row (org-export-get-parent table-cell
))
4549 (table (org-export-get-parent-table table-cell
))
4551 ;; Top/above border? TABLE-CELL has a border above when a rule
4552 ;; used to demarcate row groups can be found above. Hence,
4553 ;; finding a rule isn't sufficient to push `above' in BORDERS:
4554 ;; another regular row has to be found above that rule.
4558 (cond ((eq (org-element-property :type row
) 'rule
)
4560 ((not (org-export-table-row-is-special-p row info
))
4561 (if rule-flag
(throw 'exit
(push 'above borders
))
4562 (throw 'exit nil
)))))
4563 ;; Look at every row before the current one.
4564 (cdr (memq row
(reverse (org-element-contents table
)))))
4565 ;; No rule above, or rule found starts the table (ignoring any
4566 ;; special row): TABLE-CELL is at the top of the table.
4567 (when rule-flag
(push 'above borders
))
4568 (push 'top borders
)))
4569 ;; Bottom/below border? TABLE-CELL has a border below when next
4570 ;; non-regular row below is a rule.
4574 (cond ((eq (org-element-property :type row
) 'rule
)
4576 ((not (org-export-table-row-is-special-p row info
))
4577 (if rule-flag
(throw 'exit
(push 'below borders
))
4578 (throw 'exit nil
)))))
4579 ;; Look at every row after the current one.
4580 (cdr (memq row
(org-element-contents table
))))
4581 ;; No rule below, or rule found ends the table (modulo some
4582 ;; special row): TABLE-CELL is at the bottom of the table.
4583 (when rule-flag
(push 'below borders
))
4584 (push 'bottom borders
)))
4585 ;; Right/left borders? They can only be specified by column
4586 ;; groups. Column groups are defined in a row starting with "/".
4587 ;; Also a column groups row only contains "<", "<>", ">" or blank
4590 (let ((column (let ((cells (org-element-contents row
)))
4591 (- (length cells
) (length (memq table-cell cells
))))))
4594 (unless (eq (org-element-property :type row
) 'rule
)
4595 (when (equal (org-element-contents
4596 (car (org-element-contents row
)))
4598 (let ((column-groups
4601 (let ((value (org-element-contents cell
)))
4602 (when (member value
'(("<") ("<>") (">") nil
))
4604 (org-element-contents row
))))
4605 ;; There's a left border when previous cell, if
4606 ;; any, ends a group, or current one starts one.
4607 (when (or (and (not (zerop column
))
4608 (member (elt column-groups
(1- column
))
4610 (member (elt column-groups column
) '("<" "<>")))
4611 (push 'left borders
))
4612 ;; There's a right border when next cell, if any,
4613 ;; starts a group, or current one ends one.
4614 (when (or (and (/= (1+ column
) (length column-groups
))
4615 (member (elt column-groups
(1+ column
))
4617 (member (elt column-groups column
) '(">" "<>")))
4618 (push 'right borders
))
4619 (throw 'exit nil
)))))
4620 ;; Table rows are read in reverse order so last column groups
4621 ;; row has precedence over any previous one.
4622 (reverse (org-element-contents table
)))))
4626 (defun org-export-table-cell-starts-colgroup-p (table-cell info
)
4627 "Non-nil when TABLE-CELL is at the beginning of a row group.
4628 INFO is a plist used as a communication channel."
4629 ;; A cell starts a column group either when it is at the beginning
4630 ;; of a row (or after the special column, if any) or when it has
4632 (or (eq (org-element-map (org-export-get-parent table-cell
) 'table-cell
4633 'identity info
'first-match
)
4635 (memq 'left
(org-export-table-cell-borders table-cell info
))))
4637 (defun org-export-table-cell-ends-colgroup-p (table-cell info
)
4638 "Non-nil when TABLE-CELL is at the end of a row group.
4639 INFO is a plist used as a communication channel."
4640 ;; A cell ends a column group either when it is at the end of a row
4641 ;; or when it has a right border.
4642 (or (eq (car (last (org-element-contents
4643 (org-export-get-parent table-cell
))))
4645 (memq 'right
(org-export-table-cell-borders table-cell info
))))
4647 (defun org-export-table-row-starts-rowgroup-p (table-row info
)
4648 "Non-nil when TABLE-ROW is at the beginning of a column group.
4649 INFO is a plist used as a communication channel."
4650 (unless (or (eq (org-element-property :type table-row
) 'rule
)
4651 (org-export-table-row-is-special-p table-row info
))
4652 (let ((borders (org-export-table-cell-borders
4653 (car (org-element-contents table-row
)) info
)))
4654 (or (memq 'top borders
) (memq 'above borders
)))))
4656 (defun org-export-table-row-ends-rowgroup-p (table-row info
)
4657 "Non-nil when TABLE-ROW is at the end of a column group.
4658 INFO is a plist used as a communication channel."
4659 (unless (or (eq (org-element-property :type table-row
) 'rule
)
4660 (org-export-table-row-is-special-p table-row info
))
4661 (let ((borders (org-export-table-cell-borders
4662 (car (org-element-contents table-row
)) info
)))
4663 (or (memq 'bottom borders
) (memq 'below borders
)))))
4665 (defun org-export-table-row-starts-header-p (table-row info
)
4666 "Non-nil when TABLE-ROW is the first table header's row.
4667 INFO is a plist used as a communication channel."
4668 (and (org-export-table-has-header-p
4669 (org-export-get-parent-table table-row
) info
)
4670 (org-export-table-row-starts-rowgroup-p table-row info
)
4671 (= (org-export-table-row-group table-row info
) 1)))
4673 (defun org-export-table-row-ends-header-p (table-row info
)
4674 "Non-nil when TABLE-ROW is the last table header's row.
4675 INFO is a plist used as a communication channel."
4676 (and (org-export-table-has-header-p
4677 (org-export-get-parent-table table-row
) info
)
4678 (org-export-table-row-ends-rowgroup-p table-row info
)
4679 (= (org-export-table-row-group table-row info
) 1)))
4681 (defun org-export-table-row-number (table-row info
)
4682 "Return TABLE-ROW number.
4683 INFO is a plist used as a communication channel. Return value is
4684 zero-based and ignores separators. The function returns nil for
4685 special columns and separators."
4686 (when (and (eq (org-element-property :type table-row
) 'standard
)
4687 (not (org-export-table-row-is-special-p table-row info
)))
4689 (org-element-map (org-export-get-parent-table table-row
) 'table-row
4691 (cond ((eq row table-row
) number
)
4692 ((eq (org-element-property :type row
) 'standard
)
4693 (incf number
) nil
)))
4694 info
'first-match
))))
4696 (defun org-export-table-dimensions (table info
)
4697 "Return TABLE dimensions.
4699 INFO is a plist used as a communication channel.
4701 Return value is a CONS like (ROWS . COLUMNS) where
4702 ROWS (resp. COLUMNS) is the number of exportable
4703 rows (resp. columns)."
4704 (let (first-row (columns 0) (rows 0))
4705 ;; Set number of rows, and extract first one.
4706 (org-element-map table
'table-row
4708 (when (eq (org-element-property :type row
) 'standard
)
4710 (unless first-row
(setq first-row row
)))) info
)
4711 ;; Set number of columns.
4712 (org-element-map first-row
'table-cell
(lambda (cell) (incf columns
)) info
)
4714 (cons rows columns
)))
4716 (defun org-export-table-cell-address (table-cell info
)
4717 "Return address of a regular TABLE-CELL object.
4719 TABLE-CELL is the cell considered. INFO is a plist used as
4720 a communication channel.
4722 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4723 zero-based index. Only exportable cells are considered. The
4724 function returns nil for other cells."
4725 (let* ((table-row (org-export-get-parent table-cell
))
4726 (row-number (org-export-table-row-number table-row info
)))
4729 (let ((col-count 0))
4730 (org-element-map table-row
'table-cell
4732 (if (eq cell table-cell
) col-count
(incf col-count
) nil
))
4733 info
'first-match
))))))
4735 (defun org-export-get-table-cell-at (address table info
)
4736 "Return regular table-cell object at ADDRESS in TABLE.
4738 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4739 zero-based index. TABLE is a table type element. INFO is
4740 a plist used as a communication channel.
4742 If no table-cell, among exportable cells, is found at ADDRESS,
4744 (let ((column-pos (cdr address
)) (column-count 0))
4746 ;; Row at (car address) or nil.
4747 (let ((row-pos (car address
)) (row-count 0))
4748 (org-element-map table
'table-row
4750 (cond ((eq (org-element-property :type row
) 'rule
) nil
)
4751 ((= row-count row-pos
) row
)
4752 (t (incf row-count
) nil
)))
4756 (if (= column-count column-pos
) cell
4757 (incf column-count
) nil
))
4758 info
'first-match
)))
4761 ;;;; For Tables Of Contents
4763 ;; `org-export-collect-headlines' builds a list of all exportable
4764 ;; headline elements, maybe limited to a certain depth. One can then
4765 ;; easily parse it and transcode it.
4767 ;; Building lists of tables, figures or listings is quite similar.
4768 ;; Once the generic function `org-export-collect-elements' is defined,
4769 ;; `org-export-collect-tables', `org-export-collect-figures' and
4770 ;; `org-export-collect-listings' can be derived from it.
4772 (defun org-export-collect-headlines (info &optional n
)
4773 "Collect headlines in order to build a table of contents.
4775 INFO is a plist used as a communication channel.
4777 When optional argument N is an integer, it specifies the depth of
4778 the table of contents. Otherwise, it is set to the value of the
4779 last headline level. See `org-export-headline-levels' for more
4782 Return a list of all exportable headlines as parsed elements.
4783 Footnote sections, if any, will be ignored."
4784 (let ((limit (plist-get info
:headline-levels
)))
4785 (setq n
(if (wholenump n
) (min n limit
) limit
))
4786 (org-element-map (plist-get info
:parse-tree
) 'headline
4787 #'(lambda (headline)
4788 (unless (org-element-property :footnote-section-p headline
)
4789 (let ((level (org-export-get-relative-level headline info
)))
4790 (and (<= level n
) headline
))))
4793 (defun org-export-collect-elements (type info
&optional predicate
)
4794 "Collect referenceable elements of a determined type.
4796 TYPE can be a symbol or a list of symbols specifying element
4797 types to search. Only elements with a caption are collected.
4799 INFO is a plist used as a communication channel.
4801 When non-nil, optional argument PREDICATE is a function accepting
4802 one argument, an element of type TYPE. It returns a non-nil
4803 value when that element should be collected.
4805 Return a list of all elements found, in order of appearance."
4806 (org-element-map (plist-get info
:parse-tree
) type
4808 (and (org-element-property :caption element
)
4809 (or (not predicate
) (funcall predicate element
))
4813 (defun org-export-collect-tables (info)
4814 "Build a list of tables.
4815 INFO is a plist used as a communication channel.
4817 Return a list of table elements with a caption."
4818 (org-export-collect-elements 'table info
))
4820 (defun org-export-collect-figures (info predicate
)
4821 "Build a list of figures.
4823 INFO is a plist used as a communication channel. PREDICATE is
4824 a function which accepts one argument: a paragraph element and
4825 whose return value is non-nil when that element should be
4828 A figure is a paragraph type element, with a caption, verifying
4829 PREDICATE. The latter has to be provided since a \"figure\" is
4830 a vague concept that may depend on back-end.
4832 Return a list of elements recognized as figures."
4833 (org-export-collect-elements 'paragraph info predicate
))
4835 (defun org-export-collect-listings (info)
4836 "Build a list of src blocks.
4838 INFO is a plist used as a communication channel.
4840 Return a list of src-block elements with a caption."
4841 (org-export-collect-elements 'src-block info
))
4846 ;; The main function for the smart quotes sub-system is
4847 ;; `org-export-activate-smart-quotes', which replaces every quote in
4848 ;; a given string from the parse tree with its "smart" counterpart.
4850 ;; Dictionary for smart quotes is stored in
4851 ;; `org-export-smart-quotes-alist'.
4853 ;; Internally, regexps matching potential smart quotes (checks at
4854 ;; string boundaries are also necessary) are defined in
4855 ;; `org-export-smart-quotes-regexps'.
4857 (defconst org-export-smart-quotes-alist
4859 ;; one may use: »...«, "...", ›...‹, or '...'.
4860 ;; http://sproget.dk/raad-og-regler/retskrivningsregler/retskrivningsregler/a7-40-60/a7-58-anforselstegn/
4861 ;; LaTeX quotes require Babel!
4862 (opening-double-quote :utf-8
"»" :html
"»" :latex
">>"
4863 :texinfo
"@guillemetright{}")
4864 (closing-double-quote :utf-8
"«" :html
"«" :latex
"<<"
4865 :texinfo
"@guillemetleft{}")
4866 (opening-single-quote :utf-8
"›" :html
"›" :latex
"\\frq{}"
4867 :texinfo
"@guilsinglright{}")
4868 (closing-single-quote :utf-8
"‹" :html
"‹" :latex
"\\flq{}"
4869 :texinfo
"@guilsingleft{}")
4870 (apostrophe :utf-8
"’" :html
"’"))
4872 (opening-double-quote :utf-8
"„" :html
"„" :latex
"\"`"
4873 :texinfo
"@quotedblbase{}")
4874 (closing-double-quote :utf-8
"“" :html
"“" :latex
"\"'"
4875 :texinfo
"@quotedblleft{}")
4876 (opening-single-quote :utf-8
"‚" :html
"‚" :latex
"\\glq{}"
4877 :texinfo
"@quotesinglbase{}")
4878 (closing-single-quote :utf-8
"‘" :html
"‘" :latex
"\\grq{}"
4879 :texinfo
"@quoteleft{}")
4880 (apostrophe :utf-8
"’" :html
"’"))
4882 (opening-double-quote :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
4883 (closing-double-quote :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
4884 (opening-single-quote :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
4885 (closing-single-quote :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
4886 (apostrophe :utf-8
"’" :html
"’"))
4888 (opening-double-quote :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
4889 :texinfo
"@guillemetleft{}")
4890 (closing-double-quote :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
4891 :texinfo
"@guillemetright{}")
4892 (opening-single-quote :utf-8
"“" :html
"“" :latex
"``" :texinfo
"``")
4893 (closing-single-quote :utf-8
"”" :html
"”" :latex
"''" :texinfo
"''")
4894 (apostrophe :utf-8
"’" :html
"’"))
4896 (opening-double-quote :utf-8
"« " :html
"« " :latex
"\\og "
4897 :texinfo
"@guillemetleft{}@tie{}")
4898 (closing-double-quote :utf-8
" »" :html
" »" :latex
"\\fg{}"
4899 :texinfo
"@tie{}@guillemetright{}")
4900 (opening-single-quote :utf-8
"« " :html
"« " :latex
"\\og "
4901 :texinfo
"@guillemetleft{}@tie{}")
4902 (closing-single-quote :utf-8
" »" :html
" »" :latex
"\\fg{}"
4903 :texinfo
"@tie{}@guillemetright{}")
4904 (apostrophe :utf-8
"’" :html
"’"))
4906 ;; https://nn.wikipedia.org/wiki/Sitatteikn
4907 (opening-double-quote :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
4908 :texinfo
"@guillemetleft{}")
4909 (closing-double-quote :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
4910 :texinfo
"@guillemetright{}")
4911 (opening-single-quote :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
4912 (closing-single-quote :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
4913 (apostrophe :utf-8
"’" :html
"’"))
4915 ;; https://nn.wikipedia.org/wiki/Sitatteikn
4916 (opening-double-quote :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
4917 :texinfo
"@guillemetleft{}")
4918 (closing-double-quote :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
4919 :texinfo
"@guillemetright{}")
4920 (opening-single-quote :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
4921 (closing-single-quote :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
4922 (apostrophe :utf-8
"’" :html
"’"))
4924 ;; https://nn.wikipedia.org/wiki/Sitatteikn
4925 (opening-double-quote :utf-8
"«" :html
"«" :latex
"\\guillemotleft{}"
4926 :texinfo
"@guillemetleft{}")
4927 (closing-double-quote :utf-8
"»" :html
"»" :latex
"\\guillemotright{}"
4928 :texinfo
"@guillemetright{}")
4929 (opening-single-quote :utf-8
"‘" :html
"‘" :latex
"`" :texinfo
"`")
4930 (closing-single-quote :utf-8
"’" :html
"’" :latex
"'" :texinfo
"'")
4931 (apostrophe :utf-8
"’" :html
"’"))
4933 ;; based on https://sv.wikipedia.org/wiki/Citattecken
4934 (opening-double-quote :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
4935 (closing-double-quote :utf-8
"”" :html
"”" :latex
"’’" :texinfo
"’’")
4936 (opening-single-quote :utf-8
"’" :html
"’" :latex
"’" :texinfo
"`")
4937 (closing-single-quote :utf-8
"’" :html
"’" :latex
"’" :texinfo
"'")
4938 (apostrophe :utf-8
"’" :html
"’"))
4940 "Smart quotes translations.
4942 Alist whose CAR is a language string and CDR is an alist with
4943 quote type as key and a plist associating various encodings to
4944 their translation as value.
4946 A quote type can be any symbol among `opening-double-quote',
4947 `closing-double-quote', `opening-single-quote',
4948 `closing-single-quote' and `apostrophe'.
4950 Valid encodings include `:utf-8', `:html', `:latex' and
4953 If no translation is found, the quote character is left as-is.")
4955 (defconst org-export-smart-quotes-regexps
4957 ;; Possible opening quote at beginning of string.
4958 "\\`\\([\"']\\)\\(\\w\\|\\s.\\|\\s_\\|\\s(\\)"
4959 ;; Possible closing quote at beginning of string.
4960 "\\`\\([\"']\\)\\(\\s-\\|\\s)\\|\\s.\\)"
4961 ;; Possible apostrophe at beginning of string.
4963 ;; Opening single and double quotes.
4964 "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\(?:\\w\\|\\s.\\|\\s_\\)"
4965 ;; Closing single and double quotes.
4966 "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\(?:\\s-\\|\\s)\\|\\s.\\)"
4969 ;; Possible opening quote at end of string.
4970 "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\'"
4971 ;; Possible closing quote at end of string.
4972 "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\'"
4973 ;; Possible apostrophe at end of string.
4975 "List of regexps matching a quote or an apostrophe.
4976 In every regexp, quote or apostrophe matched is put in group 1.")
4978 (defun org-export-activate-smart-quotes (s encoding info
&optional original
)
4979 "Replace regular quotes with \"smart\" quotes in string S.
4981 ENCODING is a symbol among `:html', `:latex', `:texinfo' and
4982 `:utf-8'. INFO is a plist used as a communication channel.
4984 The function has to retrieve information about string
4985 surroundings in parse tree. It can only happen with an
4986 unmodified string. Thus, if S has already been through another
4987 process, a non-nil ORIGINAL optional argument will provide that
4990 Return the new string."
4992 (let* ((prev (org-export-get-previous-element (or original s
) info
))
4993 ;; Try to be flexible when computing number of blanks
4994 ;; before object. The previous object may be a string
4995 ;; introduced by the back-end and not completely parsed.
4996 (pre-blank (and prev
4997 (or (org-element-property :post-blank prev
)
4998 ;; A string with missing `:post-blank'
5001 (string-match " *\\'" prev
)
5002 (length (match-string 0 prev
)))
5005 (next (org-export-get-next-element (or original s
) info
))
5008 ;; Return smart quote associated to a give quote Q, as
5009 ;; a string. TYPE is a symbol among `open', `close' and
5011 (let ((key (case type
5012 (apostrophe 'apostrophe
)
5013 (open (if (equal "'" q
) 'opening-single-quote
5014 'opening-double-quote
))
5015 (otherwise (if (equal "'" q
) 'closing-single-quote
5016 'closing-double-quote
)))))
5019 (cdr (assoc (plist-get info
:language
)
5020 org-export-smart-quotes-alist
))))
5023 (if (or (equal "\"" s
) (equal "'" s
))
5024 ;; Only a quote: no regexp can match. We have to check both
5025 ;; sides and decide what to do.
5026 (cond ((and (not prev
) (not next
)) s
)
5027 ((not prev
) (funcall get-smart-quote s
'open
))
5028 ((and (not next
) (zerop pre-blank
))
5029 (funcall get-smart-quote s
'close
))
5031 ((zerop pre-blank
) (funcall get-smart-quote s
'apostrophe
))
5032 (t (funcall get-smart-quote
'open
)))
5033 ;; 1. Replace quote character at the beginning of S.
5036 ((and prev
(zerop pre-blank
)
5037 (string-match (nth 2 org-export-smart-quotes-regexps
) s
))
5038 (setq s
(replace-match
5039 (funcall get-smart-quote
(match-string 1 s
) 'apostrophe
)
5042 ((and prev
(zerop pre-blank
)
5043 (string-match (nth 1 org-export-smart-quotes-regexps
) s
))
5044 (setq s
(replace-match
5045 (funcall get-smart-quote
(match-string 1 s
) 'close
)
5048 ((and (or (not prev
) (> pre-blank
0))
5049 (string-match (nth 0 org-export-smart-quotes-regexps
) s
))
5050 (setq s
(replace-match
5051 (funcall get-smart-quote
(match-string 1 s
) 'open
)
5053 ;; 2. Replace quotes in the middle of the string.
5054 (setq s
(replace-regexp-in-string
5056 (nth 3 org-export-smart-quotes-regexps
)
5058 (funcall get-smart-quote
(match-string 1 text
) 'open
))
5060 (setq s
(replace-regexp-in-string
5062 (nth 4 org-export-smart-quotes-regexps
)
5064 (funcall get-smart-quote
(match-string 1 text
) 'close
))
5066 (setq s
(replace-regexp-in-string
5068 (nth 5 org-export-smart-quotes-regexps
)
5070 (funcall get-smart-quote
(match-string 1 text
) 'apostrophe
))
5072 ;; 3. Replace quote character at the end of S.
5075 ((and next
(string-match (nth 8 org-export-smart-quotes-regexps
) s
))
5076 (setq s
(replace-match
5077 (funcall get-smart-quote
(match-string 1 s
) 'apostrophe
)
5081 (string-match (nth 7 org-export-smart-quotes-regexps
) s
))
5082 (setq s
(replace-match
5083 (funcall get-smart-quote
(match-string 1 s
) 'close
)
5086 ((and next
(string-match (nth 6 org-export-smart-quotes-regexps
) s
))
5087 (setq s
(replace-match
5088 (funcall get-smart-quote
(match-string 1 s
) 'open
)
5090 ;; Return string with smart quotes.
5095 ;; Here are various functions to retrieve information about the
5096 ;; neighborhood of a given element or object. Neighbors of interest
5097 ;; are direct parent (`org-export-get-parent'), parent headline
5098 ;; (`org-export-get-parent-headline'), first element containing an
5099 ;; object, (`org-export-get-parent-element'), parent table
5100 ;; (`org-export-get-parent-table'), previous element or object
5101 ;; (`org-export-get-previous-element') and next element or object
5102 ;; (`org-export-get-next-element').
5104 ;; `org-export-get-genealogy' returns the full genealogy of a given
5105 ;; element or object, from closest parent to full parse tree.
5107 (defsubst org-export-get-parent
(blob)
5108 "Return BLOB parent or nil.
5109 BLOB is the element or object considered."
5110 (org-element-property :parent blob
))
5112 (defun org-export-get-genealogy (blob)
5113 "Return full genealogy relative to a given element or object.
5115 BLOB is the element or object being considered.
5117 Ancestors are returned from closest to farthest, the last one
5118 being the full parse tree."
5119 (let (genealogy (parent blob
))
5120 (while (setq parent
(org-element-property :parent parent
))
5121 (push parent genealogy
))
5122 (nreverse genealogy
)))
5124 (defun org-export-get-parent-headline (blob)
5125 "Return BLOB parent headline or nil.
5126 BLOB is the element or object being considered."
5127 (let ((parent blob
))
5128 (while (and (setq parent
(org-element-property :parent parent
))
5129 (not (eq (org-element-type parent
) 'headline
))))
5132 (defun org-export-get-parent-element (object)
5133 "Return first element containing OBJECT or nil.
5134 OBJECT is the object to consider."
5135 (let ((parent object
))
5136 (while (and (setq parent
(org-element-property :parent parent
))
5137 (memq (org-element-type parent
) org-element-all-objects
)))
5140 (defun org-export-get-parent-table (object)
5141 "Return OBJECT parent table or nil.
5142 OBJECT is either a `table-cell' or `table-element' type object."
5143 (let ((parent object
))
5144 (while (and (setq parent
(org-element-property :parent parent
))
5145 (not (eq (org-element-type parent
) 'table
))))
5148 (defun org-export-get-previous-element (blob info
&optional n
)
5149 "Return previous element or object.
5151 BLOB is an element or object. INFO is a plist used as
5152 a communication channel. Return previous exportable element or
5153 object, a string, or nil.
5155 When optional argument N is a positive integer, return a list
5156 containing up to N siblings before BLOB, from farthest to
5157 closest. With any other non-nil value, return a list containing
5160 ;; An object can belong to the contents of its parent or
5161 ;; to a secondary string. We check the latter option
5163 (let ((parent (org-export-get-parent blob
)))
5164 (or (let ((sec-value (org-element-property
5165 (cdr (assq (org-element-type parent
)
5166 org-element-secondary-value-alist
))
5168 (and (memq blob sec-value
) sec-value
))
5169 (org-element-contents parent
))))
5173 (cond ((memq obj
(plist-get info
:ignore-list
)))
5174 ((null n
) (throw 'exit obj
))
5175 ((not (wholenump n
)) (push obj prev
))
5176 ((zerop n
) (throw 'exit prev
))
5177 (t (decf n
) (push obj prev
))))
5178 (cdr (memq blob
(reverse siblings
))))
5181 (defun org-export-get-next-element (blob info
&optional n
)
5182 "Return next element or object.
5184 BLOB is an element or object. INFO is a plist used as
5185 a communication channel. Return next exportable element or
5186 object, a string, or nil.
5188 When optional argument N is a positive integer, return a list
5189 containing up to N siblings after BLOB, from closest to farthest.
5190 With any other non-nil value, return a list containing all of
5193 ;; An object can belong to the contents of its parent or to
5194 ;; a secondary string. We check the latter option first.
5195 (let ((parent (org-export-get-parent blob
)))
5196 (or (let ((sec-value (org-element-property
5197 (cdr (assq (org-element-type parent
)
5198 org-element-secondary-value-alist
))
5200 (cdr (memq blob sec-value
)))
5201 (cdr (memq blob
(org-element-contents parent
))))))
5205 (cond ((memq obj
(plist-get info
:ignore-list
)))
5206 ((null n
) (throw 'exit obj
))
5207 ((not (wholenump n
)) (push obj next
))
5208 ((zerop n
) (throw 'exit
(nreverse next
)))
5209 (t (decf n
) (push obj next
))))
5216 ;; `org-export-translate' translates a string according to the language
5217 ;; specified by the LANGUAGE keyword. `org-export-dictionary' contains
5218 ;; the dictionary used for the translation.
5220 (defconst org-export-dictionary
5222 ("fr" :default
"%e %n : %c" :html
"%e %n : %c"))
5224 ("ca" :default
"Autor")
5225 ("cs" :default
"Autor")
5226 ("da" :default
"Forfatter")
5227 ("de" :default
"Autor")
5228 ("eo" :html
"Aŭtoro")
5229 ("es" :default
"Autor")
5230 ("fi" :html
"Tekijä")
5231 ("fr" :default
"Auteur")
5232 ("hu" :default
"Szerzõ")
5233 ("is" :html
"Höfundur")
5234 ("it" :default
"Autore")
5235 ("ja" :html
"著者" :utf-8
"著者")
5236 ("nl" :default
"Auteur")
5237 ("no" :default
"Forfatter")
5238 ("nb" :default
"Forfatter")
5239 ("nn" :default
"Forfattar")
5240 ("pl" :default
"Autor")
5241 ("ru" :html
"Автор" :utf-8
"Автор")
5242 ("sv" :html
"Författare")
5243 ("uk" :html
"Автор" :utf-8
"Автор")
5244 ("zh-CN" :html
"作者" :utf-8
"作者")
5245 ("zh-TW" :html
"作者" :utf-8
"作者"))
5247 ("ca" :default
"Data")
5248 ("cs" :default
"Datum")
5249 ("da" :default
"Dato")
5250 ("de" :default
"Datum")
5251 ("eo" :default
"Dato")
5252 ("es" :default
"Fecha")
5253 ("fi" :html
"Päivämäärä")
5254 ("hu" :html
"Dátum")
5255 ("is" :default
"Dagsetning")
5256 ("it" :default
"Data")
5257 ("ja" :html
"日付" :utf-8
"日付")
5258 ("nl" :default
"Datum")
5259 ("no" :default
"Dato")
5260 ("nb" :default
"Dato")
5261 ("nn" :default
"Dato")
5262 ("pl" :default
"Data")
5263 ("ru" :html
"Дата" :utf-8
"Дата")
5264 ("sv" :default
"Datum")
5265 ("uk" :html
"Дата" :utf-8
"Дата")
5266 ("zh-CN" :html
"日期" :utf-8
"日期")
5267 ("zh-TW" :html
"日期" :utf-8
"日期"))
5269 ("da" :default
"Ligning")
5270 ("de" :default
"Gleichung")
5271 ("es" :html
"Ecuación" :default
"Ecuación")
5272 ("fr" :ascii
"Equation" :default
"Équation")
5273 ("no" :default
"Ligning")
5274 ("nb" :default
"Ligning")
5275 ("nn" :default
"Likning")
5276 ("sv" :default
"Ekvation")
5277 ("zh-CN" :html
"方程" :utf-8
"方程"))
5279 ("da" :default
"Figur")
5280 ("de" :default
"Abbildung")
5281 ("es" :default
"Figura")
5282 ("ja" :html
"図" :utf-8
"図")
5283 ("no" :default
"Illustrasjon")
5284 ("nb" :default
"Illustrasjon")
5285 ("nn" :default
"Illustrasjon")
5286 ("sv" :default
"Illustration")
5287 ("zh-CN" :html
"图" :utf-8
"图"))
5289 ("da" :default
"Figur %d")
5290 ("de" :default
"Abbildung %d:")
5291 ("es" :default
"Figura %d:")
5292 ("fr" :default
"Figure %d :" :html
"Figure %d :")
5293 ("ja" :html
"図%d: " :utf-8
"図%d: ")
5294 ("no" :default
"Illustrasjon %d")
5295 ("nb" :default
"Illustrasjon %d")
5296 ("nn" :default
"Illustrasjon %d")
5297 ("sv" :default
"Illustration %d")
5298 ("zh-CN" :html
"图%d " :utf-8
"图%d "))
5300 ("ca" :html
"Peus de pàgina")
5301 ("cs" :default
"Pozn\xe1mky pod carou")
5302 ("da" :default
"Fodnoter")
5303 ("de" :html
"Fußnoten" :default
"Fußnoten")
5304 ("eo" :default
"Piednotoj")
5305 ("es" :html
"Nota al pie de página" :default
"Nota al pie de página")
5306 ("fi" :default
"Alaviitteet")
5307 ("fr" :default
"Notes de bas de page")
5308 ("hu" :html
"Lábjegyzet")
5309 ("is" :html
"Aftanmálsgreinar")
5310 ("it" :html
"Note a piè di pagina")
5311 ("ja" :html
"脚注" :utf-8
"脚注")
5312 ("nl" :default
"Voetnoten")
5313 ("no" :default
"Fotnoter")
5314 ("nb" :default
"Fotnoter")
5315 ("nn" :default
"Fotnotar")
5316 ("pl" :default
"Przypis")
5317 ("ru" :html
"Сноски" :utf-8
"Сноски")
5318 ("sv" :default
"Fotnoter")
5319 ("uk" :html
"Примітки"
5321 ("zh-CN" :html
"脚注" :utf-8
"脚注")
5322 ("zh-TW" :html
"腳註" :utf-8
"腳註"))
5324 ("da" :default
"Programmer")
5325 ("de" :default
"Programmauflistungsverzeichnis")
5326 ("es" :default
"Indice de Listados de programas")
5327 ("fr" :default
"Liste des programmes")
5328 ("no" :default
"Dataprogrammer")
5329 ("nb" :default
"Dataprogrammer")
5330 ("zh-CN" :html
"代码目录" :utf-8
"代码目录"))
5332 ("da" :default
"Tabeller")
5333 ("de" :default
"Tabellenverzeichnis")
5334 ("es" :default
"Indice de tablas")
5335 ("fr" :default
"Liste des tableaux")
5336 ("no" :default
"Tabeller")
5337 ("nb" :default
"Tabeller")
5338 ("nn" :default
"Tabeller")
5339 ("sv" :default
"Tabeller")
5340 ("zh-CN" :html
"表格目录" :utf-8
"表格目录"))
5342 ("da" :default
"Program %d")
5343 ("de" :default
"Programmlisting %d")
5344 ("es" :default
"Listado de programa %d")
5345 ("fr" :default
"Programme %d :" :html
"Programme %d :")
5346 ("no" :default
"Dataprogram")
5347 ("nb" :default
"Dataprogram")
5348 ("zh-CN" :html
"代码%d " :utf-8
"代码%d "))
5350 ("da" :default
"jævnfør afsnit %s")
5351 ("de" :default
"siehe Abschnitt %s")
5352 ("es" :default
"vea seccion %s")
5353 ("fr" :default
"cf. section %s")
5354 ("zh-CN" :html
"参见第%d节" :utf-8
"参见第%s节"))
5356 ("de" :default
"Tabelle")
5357 ("es" :default
"Tabla")
5358 ("fr" :default
"Tableau")
5359 ("ja" :html
"表" :utf-8
"表")
5360 ("zh-CN" :html
"表" :utf-8
"表"))
5362 ("da" :default
"Tabel %d")
5363 ("de" :default
"Tabelle %d")
5364 ("es" :default
"Tabla %d")
5365 ("fr" :default
"Tableau %d :")
5366 ("ja" :html
"表%d:" :utf-8
"表%d:")
5367 ("no" :default
"Tabell %d")
5368 ("nb" :default
"Tabell %d")
5369 ("nn" :default
"Tabell %d")
5370 ("sv" :default
"Tabell %d")
5371 ("zh-CN" :html
"表%d " :utf-8
"表%d "))
5372 ("Table of Contents"
5373 ("ca" :html
"Índex")
5374 ("cs" :default
"Obsah")
5375 ("da" :default
"Indhold")
5376 ("de" :default
"Inhaltsverzeichnis")
5377 ("eo" :default
"Enhavo")
5378 ("es" :html
"Índice")
5379 ("fi" :html
"Sisällysluettelo")
5380 ("fr" :ascii
"Sommaire" :default
"Table des matières")
5381 ("hu" :html
"Tartalomjegyzék")
5382 ("is" :default
"Efnisyfirlit")
5383 ("it" :default
"Indice")
5384 ("ja" :html
"目次" :utf-8
"目次")
5385 ("nl" :default
"Inhoudsopgave")
5386 ("no" :default
"Innhold")
5387 ("nb" :default
"Innhold")
5388 ("nn" :default
"Innhald")
5389 ("pl" :html
"Spis treści")
5390 ("ru" :html
"Содержание"
5391 :utf-8
"Содержание")
5392 ("sv" :html
"Innehåll")
5393 ("uk" :html
"Зміст" :utf-8
"Зміст")
5394 ("zh-CN" :html
"目录" :utf-8
"目录")
5395 ("zh-TW" :html
"目錄" :utf-8
"目錄"))
5396 ("Unknown reference"
5397 ("da" :default
"ukendt reference")
5398 ("de" :default
"Unbekannter Verweis")
5399 ("es" :default
"referencia desconocida")
5400 ("fr" :ascii
"Destination inconnue" :default
"Référence inconnue")
5401 ("zh-CN" :html
"未知引用" :utf-8
"未知引用")))
5402 "Dictionary for export engine.
5404 Alist whose CAR is the string to translate and CDR is an alist
5405 whose CAR is the language string and CDR is a plist whose
5406 properties are possible charsets and values translated terms.
5408 It is used as a database for `org-export-translate'. Since this
5409 function returns the string as-is if no translation was found,
5410 the variable only needs to record values different from the
5413 (defun org-export-translate (s encoding info
)
5414 "Translate string S according to language specification.
5416 ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
5417 and `:utf-8'. INFO is a plist used as a communication channel.
5419 Translation depends on `:language' property. Return the
5420 translated string. If no translation is found, try to fall back
5421 to `:default' encoding. If it fails, return S."
5422 (let* ((lang (plist-get info
:language
))
5423 (translations (cdr (assoc lang
5424 (cdr (assoc s org-export-dictionary
))))))
5425 (or (plist-get translations encoding
)
5426 (plist-get translations
:default
)
5431 ;;; Asynchronous Export
5433 ;; `org-export-async-start' is the entry point for asynchronous
5434 ;; export. It recreates current buffer (including visibility,
5435 ;; narrowing and visited file) in an external Emacs process, and
5436 ;; evaluates a command there. It then applies a function on the
5437 ;; returned results in the current process.
5439 ;; At a higher level, `org-export-to-buffer' and `org-export-to-file'
5440 ;; allow to export to a buffer or a file, asynchronously or not.
5442 ;; `org-export-output-file-name' is an auxiliary function meant to be
5443 ;; used with `org-export-to-file'. With a given extension, it tries
5444 ;; to provide a canonical file name to write export output to.
5446 ;; Asynchronously generated results are never displayed directly.
5447 ;; Instead, they are stored in `org-export-stack-contents'. They can
5448 ;; then be retrieved by calling `org-export-stack'.
5450 ;; Export Stack is viewed through a dedicated major mode
5451 ;;`org-export-stack-mode' and tools: `org-export-stack-refresh',
5452 ;;`org-export-stack-delete', `org-export-stack-view' and
5453 ;;`org-export-stack-clear'.
5455 ;; For back-ends, `org-export-add-to-stack' add a new source to stack.
5456 ;; It should be used whenever `org-export-async-start' is called.
5458 (defmacro org-export-async-start
(fun &rest body
)
5459 "Call function FUN on the results returned by BODY evaluation.
5461 BODY evaluation happens in an asynchronous process, from a buffer
5462 which is an exact copy of the current one.
5464 Use `org-export-add-to-stack' in FUN in order to register results
5467 This is a low level function. See also `org-export-to-buffer'
5468 and `org-export-to-file' for more specialized functions."
5469 (declare (indent 1) (debug t
))
5470 (org-with-gensyms (process temp-file copy-fun proc-buffer coding
)
5471 ;; Write the full sexp evaluating BODY in a copy of the current
5472 ;; buffer to a temporary file, as it may be too long for program
5473 ;; args in `start-process'.
5474 `(with-temp-message "Initializing asynchronous export process"
5475 (let ((,copy-fun
(org-export--generate-copy-script (current-buffer)))
5476 (,temp-file
(make-temp-file "org-export-process"))
5477 (,coding buffer-file-coding-system
))
5478 (with-temp-file ,temp-file
5480 ;; Null characters (from variable values) are inserted
5481 ;; within the file. As a consequence, coding system for
5482 ;; buffer contents will not be recognized properly. So,
5483 ;; we make sure it is the same as the one used to display
5484 ;; the original buffer.
5485 (format ";; -*- coding: %s; -*-\n%S"
5488 (when org-export-async-debug
'(setq debug-on-error t
))
5489 ;; Ignore `kill-emacs-hook' and code evaluation
5490 ;; queries from Babel as we need a truly
5491 ;; non-interactive process.
5492 (setq kill-emacs-hook nil
5493 org-babel-confirm-evaluate-answer-no t
)
5494 ;; Initialize export framework.
5496 ;; Re-create current buffer there.
5497 (funcall ,,copy-fun
)
5498 (restore-buffer-modified-p nil
)
5499 ;; Sexp to evaluate in the buffer.
5500 (print (progn ,,@body
))))))
5501 ;; Start external process.
5502 (let* ((process-connection-type nil
)
5503 (,proc-buffer
(generate-new-buffer-name "*Org Export Process*"))
5506 "org-export-process" ,proc-buffer
5507 (expand-file-name invocation-name invocation-directory
)
5509 "-l" org-export-async-init-file
5511 ;; Register running process in stack.
5512 (org-export-add-to-stack (get-buffer ,proc-buffer
) nil
,process
)
5513 ;; Set-up sentinel in order to catch results.
5514 (let ((handler ,fun
))
5515 (set-process-sentinel
5518 (let ((proc-buffer (process-buffer p
)))
5519 (when (eq (process-status p
) 'exit
)
5521 (if (zerop (process-exit-status p
))
5524 (with-current-buffer proc-buffer
5525 (goto-char (point-max))
5527 (read (current-buffer)))))
5528 (funcall ,handler results
))
5529 (unless org-export-async-debug
5530 (and (get-buffer proc-buffer
)
5531 (kill-buffer proc-buffer
))))
5532 (org-export-add-to-stack proc-buffer nil p
)
5534 (message "Process '%s' exited abnormally" p
))
5535 (unless org-export-async-debug
5536 (delete-file ,,temp-file
)))))))))))))
5539 (defun org-export-to-buffer
5541 &optional async subtreep visible-only body-only ext-plist
5543 "Call `org-export-as' with output to a specified buffer.
5545 BACKEND is either an export back-end, as returned by, e.g.,
5546 `org-export-create-backend', or a symbol referring to
5547 a registered back-end.
5549 BUFFER is the name of the output buffer. If it already exists,
5550 it will be erased first, otherwise, it will be created.
5552 A non-nil optional argument ASYNC means the process should happen
5553 asynchronously. The resulting buffer should then be accessible
5554 through the `org-export-stack' interface. When ASYNC is nil, the
5555 buffer is displayed if `org-export-show-temporary-export-buffer'
5558 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
5559 EXT-PLIST are similar to those used in `org-export-as', which
5562 Optional argument POST-PROCESS is a function which should accept
5563 no argument. It is always called within the current process,
5564 from BUFFER, with point at its beginning. Export back-ends can
5565 use it to set a major mode there, e.g,
5567 \(defun org-latex-export-as-latex
5568 \(&optional async subtreep visible-only body-only ext-plist)
5570 \(org-export-to-buffer 'latex \"*Org LATEX Export*\"
5571 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
5573 This function returns BUFFER."
5574 (declare (indent 2))
5576 (org-export-async-start
5578 (with-current-buffer (get-buffer-create ,buffer
)
5580 (setq buffer-file-coding-system
',buffer-file-coding-system
)
5582 (goto-char (point-min))
5583 (org-export-add-to-stack (current-buffer) ',backend
)
5584 (ignore-errors (funcall ,post-process
))))
5586 ',backend
,subtreep
,visible-only
,body-only
',ext-plist
))
5588 (org-export-as backend subtreep visible-only body-only ext-plist
))
5589 (buffer (get-buffer-create buffer
))
5590 (encoding buffer-file-coding-system
))
5591 (when (and (org-string-nw-p output
) (org-export--copy-to-kill-ring-p))
5592 (org-kill-new output
))
5593 (with-current-buffer buffer
5595 (setq buffer-file-coding-system encoding
)
5597 (goto-char (point-min))
5598 (and (functionp post-process
) (funcall post-process
)))
5599 (when org-export-show-temporary-export-buffer
5600 (switch-to-buffer-other-window buffer
))
5604 (defun org-export-to-file
5605 (backend file
&optional async subtreep visible-only body-only ext-plist
5607 "Call `org-export-as' with output to a specified file.
5609 BACKEND is either an export back-end, as returned by, e.g.,
5610 `org-export-create-backend', or a symbol referring to
5611 a registered back-end. FILE is the name of the output file, as
5614 A non-nil optional argument ASYNC means the process should happen
5615 asynchronously. The resulting buffer will then be accessible
5616 through the `org-export-stack' interface.
5618 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
5619 EXT-PLIST are similar to those used in `org-export-as', which
5622 Optional argument POST-PROCESS is called with FILE as its
5623 argument and happens asynchronously when ASYNC is non-nil. It
5624 has to return a file name, or nil. Export back-ends can use this
5625 to send the output file through additional processing, e.g,
5627 \(defun org-latex-export-to-latex
5628 \(&optional async subtreep visible-only body-only ext-plist)
5630 \(let ((outfile (org-export-output-file-name \".tex\" subtreep)))
5631 \(org-export-to-file 'latex outfile
5632 async subtreep visible-only body-only ext-plist
5633 \(lambda (file) (org-latex-compile file)))
5635 The function returns either a file name returned by POST-PROCESS,
5637 (declare (indent 2))
5638 (if (not (file-writable-p file
)) (error "Output file not writable")
5639 (let ((encoding (or org-export-coding-system buffer-file-coding-system
)))
5641 (org-export-async-start
5643 (org-export-add-to-stack (expand-file-name file
) ',backend
))
5646 ',backend
,subtreep
,visible-only
,body-only
5650 (let ((coding-system-for-write ',encoding
))
5651 (write-file ,file
)))
5652 (or (ignore-errors (funcall ',post-process
,file
)) ,file
)))
5653 (let ((output (org-export-as
5654 backend subtreep visible-only body-only ext-plist
)))
5657 (let ((coding-system-for-write encoding
))
5659 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p output
))
5660 (org-kill-new output
))
5661 ;; Get proper return value.
5662 (or (and (functionp post-process
) (funcall post-process file
))
5665 (defun org-export-output-file-name (extension &optional subtreep pub-dir
)
5666 "Return output file's name according to buffer specifications.
5668 EXTENSION is a string representing the output file extension,
5669 with the leading dot.
5671 With a non-nil optional argument SUBTREEP, try to determine
5672 output file's name by looking for \"EXPORT_FILE_NAME\" property
5673 of subtree at point.
5675 When optional argument PUB-DIR is set, use it as the publishing
5678 When optional argument VISIBLE-ONLY is non-nil, don't export
5679 contents of hidden elements.
5681 Return file name as a string."
5682 (let* ((visited-file (buffer-file-name (buffer-base-buffer)))
5684 ;; File name may come from EXPORT_FILE_NAME subtree
5685 ;; property, assuming point is at beginning of said
5687 (file-name-sans-extension
5691 (ignore-errors (org-back-to-heading) (point)))
5692 "EXPORT_FILE_NAME" t
))
5693 ;; File name may be extracted from buffer's associated
5695 (and visited-file
(file-name-nondirectory visited-file
))
5696 ;; Can't determine file name on our own: Ask user.
5697 (let ((read-file-name-function
5698 (and org-completion-use-ido
'ido-read-file-name
)))
5700 "Output file: " pub-dir nil nil nil
5702 (string= (file-name-extension name t
) extension
)))))))
5704 ;; Build file name. Enforce EXTENSION over whatever user
5705 ;; may have come up with. PUB-DIR, if defined, always has
5706 ;; precedence over any provided path.
5709 (concat (file-name-as-directory pub-dir
)
5710 (file-name-nondirectory base-name
)
5712 ((file-name-absolute-p base-name
) (concat base-name extension
))
5713 (t (concat (file-name-as-directory ".") base-name extension
)))))
5714 ;; If writing to OUTPUT-FILE would overwrite original file, append
5715 ;; EXTENSION another time to final name.
5716 (if (and visited-file
(org-file-equal-p visited-file output-file
))
5717 (concat output-file extension
)
5720 (defun org-export-add-to-stack (source backend
&optional process
)
5721 "Add a new result to export stack if not present already.
5723 SOURCE is a buffer or a file name containing export results.
5724 BACKEND is a symbol representing export back-end used to generate
5727 Entries already pointing to SOURCE and unavailable entries are
5728 removed beforehand. Return the new stack."
5729 (setq org-export-stack-contents
5730 (cons (list source backend
(or process
(current-time)))
5731 (org-export-stack-remove source
))))
5733 (defun org-export-stack ()
5734 "Menu for asynchronous export results and running processes."
5736 (let ((buffer (get-buffer-create "*Org Export Stack*")))
5738 (when (zerop (buffer-size)) (org-export-stack-mode))
5739 (org-export-stack-refresh)
5740 (pop-to-buffer buffer
))
5741 (message "Type \"q\" to quit, \"?\" for help"))
5743 (defun org-export--stack-source-at-point ()
5744 "Return source from export results at point in stack."
5745 (let ((source (car (nth (1- (org-current-line)) org-export-stack-contents
))))
5746 (if (not source
) (error "Source unavailable, please refresh buffer")
5747 (let ((source-name (if (stringp source
) source
(buffer-name source
))))
5750 (looking-at (concat ".* +" (regexp-quote source-name
) "$")))
5752 ;; SOURCE is not consistent with current line. The stack
5753 ;; view is outdated.
5754 (error "Source unavailable; type `g' to update buffer"))))))
5756 (defun org-export-stack-clear ()
5757 "Remove all entries from export stack."
5759 (setq org-export-stack-contents nil
))
5761 (defun org-export-stack-refresh (&rest dummy
)
5762 "Refresh the asynchronous export stack.
5763 DUMMY is ignored. Unavailable sources are removed from the list.
5764 Return the new stack."
5765 (let ((inhibit-read-only t
))
5772 (let ((proc-p (processp (nth 2 entry
))))
5775 (format " %-12s " (or (nth 1 entry
) ""))
5777 (let ((data (nth 2 entry
)))
5778 (if proc-p
(format " %6s " (process-status data
))
5779 ;; Compute age of the results.
5782 (float-time (time-since data
)))))
5785 (let ((source (car entry
)))
5786 (if (stringp source
) source
5787 (buffer-name source
)))))))
5788 ;; Clear stack from exited processes, dead buffers or
5789 ;; non-existent files.
5790 (setq org-export-stack-contents
5793 (if (processp (nth 2 el
))
5794 (buffer-live-p (process-buffer (nth 2 el
)))
5795 (let ((source (car el
)))
5796 (if (bufferp source
) (buffer-live-p source
)
5797 (file-exists-p source
)))))
5798 org-export-stack-contents
)) "\n")))))))
5800 (defun org-export-stack-remove (&optional source
)
5801 "Remove export results at point from stack.
5802 If optional argument SOURCE is non-nil, remove it instead."
5804 (let ((source (or source
(org-export--stack-source-at-point))))
5805 (setq org-export-stack-contents
5806 (org-remove-if (lambda (el) (equal (car el
) source
))
5807 org-export-stack-contents
))))
5809 (defun org-export-stack-view (&optional in-emacs
)
5810 "View export results at point in stack.
5811 With an optional prefix argument IN-EMACS, force viewing files
5814 (let ((source (org-export--stack-source-at-point)))
5815 (cond ((processp source
)
5816 (org-switch-to-buffer-other-window (process-buffer source
)))
5817 ((bufferp source
) (org-switch-to-buffer-other-window source
))
5818 (t (org-open-file source in-emacs
)))))
5820 (defvar org-export-stack-mode-map
5821 (let ((km (make-sparse-keymap)))
5822 (define-key km
" " 'next-line
)
5823 (define-key km
"n" 'next-line
)
5824 (define-key km
"\C-n" 'next-line
)
5825 (define-key km
[down] 'next-line)
5826 (define-key km "p" 'previous-line)
5827 (define-key km "\C-p" 'previous-line)
5828 (define-key km "\C-?" 'previous-line)
5829 (define-key km [up] 'previous-line)
5830 (define-key km "C" 'org-export-stack-clear)
5831 (define-key km "v" 'org-export-stack-view)
5832 (define-key km (kbd "RET") 'org-export-stack-view)
5833 (define-key km "d" 'org-export-stack-remove)
5835 "Keymap for Org Export Stack.")
5837 (define-derived-mode org-export-stack-mode special-mode "Org-Stack"
5838 "Mode for displaying asynchronous export stack.
5840 Type \\[org-export-stack] to visualize the asynchronous export
5843 In an Org Export Stack buffer, use \\<org-export-stack-mode-map>\\[org-export-stack-view] to view export output
5844 on current line, \\[org-export-stack-remove] to remove it from the stack and \\[org-export-stack-clear] to clear
5847 Removing entries in an Org Export Stack buffer doesn't affect
5848 files or buffers, only the display.
5850 \\{org-export-stack-mode-map}"
5853 (setq buffer-read-only t
5858 (format " %-12s | %6s | %s" "Back-End" "Age" "Source")))
5859 (org-add-hook 'post-command-hook 'org-export-stack-refresh nil t)
5860 (set (make-local-variable 'revert-buffer-function)
5861 'org-export-stack-refresh))
5867 ;; `org-export-dispatch' is the standard interactive way to start an
5868 ;; export process. It uses `org-export--dispatch-ui' as a subroutine
5869 ;; for its interface, which, in turn, delegates response to key
5870 ;; pressed to `org-export--dispatch-action'.
5873 (defun org-export-dispatch (&optional arg)
5874 "Export dispatcher for Org mode.
5876 It provides an access to common export related tasks in a buffer.
5877 Its interface comes in two flavors: standard and expert.
5879 While both share the same set of bindings, only the former
5880 displays the valid keys associations in a dedicated buffer.
5881 Scrolling (resp. line-wise motion) in this buffer is done with
5882 SPC and DEL (resp. C-n and C-p) keys.
5884 Set variable `org-export-dispatch-use-expert-ui' to switch to one
5885 flavor or the other.
5887 When ARG is \\[universal-argument], repeat the last export action, with the same set
5888 of options used back then, on the current buffer.
5890 When ARG is \\[universal-argument] \\[universal-argument], display the asynchronous export stack."
5893 (cond ((equal arg '(16)) '(stack))
5894 ((and arg org-export-dispatch-last-action))
5895 (t (save-window-excursion
5898 ;; Remember where we are
5899 (move-marker org-export-dispatch-last-position
5901 (org-base-buffer (current-buffer)))
5902 ;; Get and store an export command
5903 (setq org-export-dispatch-last-action
5904 (org-export--dispatch-ui
5905 (list org-export-initial-scope
5906 (and org-export-in-background 'async))
5908 org-export-dispatch-use-expert-ui)))
5909 (and (get-buffer "*Org Export Dispatcher*")
5910 (kill-buffer "*Org Export Dispatcher*")))))))
5911 (action (car input))
5912 (optns (cdr input)))
5913 (unless (memq 'subtree optns)
5914 (move-marker org-export-dispatch-last-position nil))
5916 ;; First handle special hard-coded actions.
5917 (template (org-export-insert-default-template nil optns))
5918 (stack (org-export-stack))
5919 (publish-current-file
5920 (org-publish-current-file (memq 'force optns) (memq 'async optns)))
5921 (publish-current-project
5922 (org-publish-current-project (memq 'force optns) (memq 'async optns)))
5923 (publish-choose-project
5924 (org-publish (assoc (org-icompleting-read
5926 org-publish-project-alist nil t)
5927 org-publish-project-alist)
5929 (memq 'async optns)))
5930 (publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
5934 ;; Repeating command, maybe move cursor to restore subtree
5936 (if (eq (marker-buffer org-export-dispatch-last-position)
5937 (org-base-buffer (current-buffer)))
5938 (goto-char org-export-dispatch-last-position)
5939 ;; We are in a different buffer, forget position.
5940 (move-marker org-export-dispatch-last-position nil)))
5942 ;; Return a symbol instead of a list to ease
5943 ;; asynchronous export macro use.
5944 (and (memq 'async optns) t)
5945 (and (memq 'subtree optns) t)
5946 (and (memq 'visible optns) t)
5947 (and (memq 'body optns) t)))))))
5949 (defun org-export--dispatch-ui (options first-key expertp)
5950 "Handle interface for `org-export-dispatch'.
5952 OPTIONS is a list containing current interactive options set for
5953 export. It can contain any of the following symbols:
5954 `body' toggles a body-only export
5955 `subtree' restricts export to current subtree
5956 `visible' restricts export to visible part of buffer.
5957 `force' force publishing files.
5958 `async' use asynchronous export process
5960 FIRST-KEY is the key pressed to select the first level menu. It
5961 is nil when this menu hasn't been selected yet.
5963 EXPERTP, when non-nil, triggers expert UI. In that case, no help
5964 buffer is provided, but indications about currently active
5965 options are given in the prompt. Moreover, \[?] allows to switch
5966 back to standard interface."
5968 (lambda (key &optional access-key)
5969 ;; Fontify KEY string. Optional argument ACCESS-KEY, when
5970 ;; non-nil is the required first-level key to activate
5971 ;; KEY. When its value is t, activate KEY independently
5972 ;; on the first key, if any. A nil value means KEY will
5973 ;; only be activated at first level.
5974 (if (or (eq access-key t) (eq access-key first-key))
5975 (org-propertize key 'face 'org-warning)
5979 ;; Fontify VALUE string.
5980 (org-propertize value 'face 'font-lock-variable-name-face)))
5981 ;; Prepare menu entries by extracting them from registered
5982 ;; back-ends and sorting them by access key and by ordinal,
5985 (sort (sort (delq nil
5986 (mapcar 'org-export-backend-menu
5987 org-export--registered-backends))
5989 (let ((key-a (nth 1 a))
5991 (cond ((and (numberp key-a) (numberp key-b))
5993 ((numberp key-b) t)))))
5994 'car-less-than-car))
5995 ;; Compute a list of allowed keys based on the first key
5996 ;; pressed, if any. Some keys
5997 ;; (?^B, ?^V, ?^S, ?^F, ?^A, ?&, ?# and ?q) are always
6000 (nconc (list 2 22 19 6 1)
6001 (if (not first-key) (org-uniquify (mapcar 'car entries))
6003 (dolist (entry entries (sort (mapcar 'car sub-menu) '<))
6004 (when (eq (car entry) first-key)
6005 (setq sub-menu (append (nth 2 entry) sub-menu))))))
6006 (cond ((eq first-key ?P) (list ?f ?p ?x ?a))
6007 ((not first-key) (list ?P)))
6009 (when expertp (list ??))
6011 ;; Build the help menu for standard UI.
6015 ;; Options are hard-coded.
6016 (format "[%s] Body only: %s [%s] Visible only: %s
6017 \[%s] Export scope: %s [%s] Force publishing: %s
6018 \[%s] Async export: %s\n\n"
6019 (funcall fontify-key "C-b" t)
6020 (funcall fontify-value
6021 (if (memq 'body options) "On " "Off"))
6022 (funcall fontify-key "C-v" t)
6023 (funcall fontify-value
6024 (if (memq 'visible options) "On " "Off"))
6025 (funcall fontify-key "C-s" t)
6026 (funcall fontify-value
6027 (if (memq 'subtree options) "Subtree" "Buffer "))
6028 (funcall fontify-key "C-f" t)
6029 (funcall fontify-value
6030 (if (memq 'force options) "On " "Off"))
6031 (funcall fontify-key "C-a" t)
6032 (funcall fontify-value
6033 (if (memq 'async options) "On " "Off")))
6034 ;; Display registered back-end entries. When a key
6035 ;; appears for the second time, do not create another
6036 ;; entry, but append its sub-menu to existing menu.
6040 (let ((top-key (car entry)))
6042 (unless (eq top-key last-key)
6043 (setq last-key top-key)
6044 (format "\n[%s] %s\n"
6045 (funcall fontify-key (char-to-string top-key))
6047 (let ((sub-menu (nth 2 entry)))
6048 (unless (functionp sub-menu)
6049 ;; Split sub-menu into two columns.
6056 (if (zerop (mod index 2)) " [%s] %-26s"
6058 (funcall fontify-key
6059 (char-to-string (car sub-entry))
6063 (when (zerop (mod index 2)) "\n"))))))))
6065 ;; Publishing menu is hard-coded.
6066 (format "\n[%s] Publish
6067 [%s] Current file [%s] Current project
6068 [%s] Choose project [%s] All projects\n\n\n"
6069 (funcall fontify-key "P")
6070 (funcall fontify-key "f" ?P)
6071 (funcall fontify-key "p" ?P)
6072 (funcall fontify-key "x" ?P)
6073 (funcall fontify-key "a" ?P))
6074 (format "[%s] Export stack [%s] Insert template\n"
6075 (funcall fontify-key "&" t)
6076 (funcall fontify-key "#" t))
6078 (funcall fontify-key "q" t)
6079 (if first-key "Main menu" "Exit")))))
6080 ;; Build prompts for both standard and expert UI.
6081 (standard-prompt (unless expertp "Export command: "))
6085 "Export command (C-%s%s%s%s%s) [%s]: "
6086 (if (memq 'body options) (funcall fontify-key "b" t) "b")
6087 (if (memq 'visible options) (funcall fontify-key "v" t) "v")
6088 (if (memq 'subtree options) (funcall fontify-key "s" t) "s")
6089 (if (memq 'force options) (funcall fontify-key "f" t) "f")
6090 (if (memq 'async options) (funcall fontify-key "a" t) "a")
6091 (mapconcat (lambda (k)
6092 ;; Strip control characters.
6093 (unless (< k 27) (char-to-string k)))
6094 allowed-keys "")))))
6095 ;; With expert UI, just read key with a fancy prompt. In standard
6096 ;; UI, display an intrusive help buffer.
6098 (org-export--dispatch-action
6099 expert-prompt allowed-keys entries options first-key expertp)
6100 ;; At first call, create frame layout in order to display menu.
6101 (unless (get-buffer "*Org Export Dispatcher*")
6102 (delete-other-windows)
6103 (org-switch-to-buffer-other-window
6104 (get-buffer-create "*Org Export Dispatcher*"))
6105 (setq cursor-type nil
6106 header-line-format "Use SPC, DEL, C-n or C-p to navigate.")
6107 ;; Make sure that invisible cursor will not highlight square
6109 (set-syntax-table (copy-syntax-table))
6110 (modify-syntax-entry ?\[ "w"))
6111 ;; At this point, the buffer containing the menu exists and is
6112 ;; visible in the current window. So, refresh it.
6113 (with-current-buffer "*Org Export Dispatcher*"
6114 ;; Refresh help. Maintain display continuity by re-visiting
6115 ;; previous window position.
6116 (let ((pos (window-start)))
6119 (set-window-start nil pos)))
6120 (org-fit-window-to-buffer)
6121 (org-export--dispatch-action
6122 standard-prompt allowed-keys entries options first-key expertp))))
6124 (defun org-export--dispatch-action
6125 (prompt allowed-keys entries options first-key expertp)
6126 "Read a character from command input and act accordingly.
6128 PROMPT is the displayed prompt, as a string. ALLOWED-KEYS is
6129 a list of characters available at a given step in the process.
6130 ENTRIES is a list of menu entries. OPTIONS, FIRST-KEY and
6131 EXPERTP are the same as defined in `org-export--dispatch-ui',
6134 Toggle export options when required. Otherwise, return value is
6135 a list with action as CAR and a list of interactive export
6138 ;; Scrolling: when in non-expert mode, act on motion keys (C-n,
6140 (while (and (setq key (read-char-exclusive prompt))
6142 (memq key '(14 16 ?\s ?\d)))
6144 (14 (if (not (pos-visible-in-window-p (point-max)))
6145 (ignore-errors (scroll-up 1))
6146 (message "End of buffer")
6148 (16 (if (not (pos-visible-in-window-p (point-min)))
6149 (ignore-errors (scroll-down 1))
6150 (message "Beginning of buffer")
6152 (?\s (if (not (pos-visible-in-window-p (point-max)))
6154 (message "End of buffer")
6156 (?\d (if (not (pos-visible-in-window-p (point-min)))
6158 (message "Beginning of buffer")
6161 ;; Ignore undefined associations.
6162 ((not (memq key allowed-keys))
6164 (unless expertp (message "Invalid key") (sit-for 1))
6165 (org-export--dispatch-ui options first-key expertp))
6166 ;; q key at first level aborts export. At second level, cancel
6167 ;; first key instead.
6168 ((eq key ?q) (if (not first-key) (error "Export aborted")
6169 (org-export--dispatch-ui options nil expertp)))
6170 ;; Help key: Switch back to standard interface if expert UI was
6172 ((eq key ??) (org-export--dispatch-ui options first-key nil))
6173 ;; Send request for template insertion along with export scope.
6174 ((eq key ?#) (cons 'template (memq 'subtree options)))
6175 ;; Switch to asynchronous export stack.
6176 ((eq key ?&) '(stack))
6177 ;; Toggle options: C-b (2) C-v (22) C-s (19) C-f (6) C-a (1).
6178 ((memq key '(2 22 19 6 1))
6179 (org-export--dispatch-ui
6180 (let ((option (case key (2 'body) (22 'visible) (19 'subtree)
6181 (6 'force) (1 'async))))
6182 (if (memq option options) (remq option options)
6183 (cons option options)))
6185 ;; Action selected: Send key and options back to
6186 ;; `org-export-dispatch'.
6187 ((or first-key (functionp (nth 2 (assq key entries))))
6189 ((not first-key) (nth 2 (assq key entries)))
6190 ;; Publishing actions are hard-coded. Send a special
6191 ;; signal to `org-export-dispatch'.
6194 (?f 'publish-current-file)
6195 (?p 'publish-current-project)
6196 (?x 'publish-choose-project)
6198 ;; Return first action associated to FIRST-KEY + KEY
6199 ;; path. Indeed, derived backends can share the same
6202 (mapc (lambda (entry)
6203 (let ((match (assq key (nth 2 entry))))
6204 (when match (throw 'found (nth 2 match)))))
6205 (member (assq first-key entries) entries)))))
6207 ;; Otherwise, enter sub-menu.
6208 (t (org-export--dispatch-ui options key expertp)))))
6215 ;; generated-autoload-file: "org-loaddefs.el"