Move functions operating on timestamp objects into org.el
[org-mode.git] / contrib / lisp / org-export.el
blob067abe10d9101ea86af5cffaaed59287a76a751e
1 ;;; org-export.el --- Generic Export Engine For Org
3 ;; Copyright (C) 2012, 2013 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements a generic export engine for Org, built on
24 ;; its syntactical parser: Org Elements.
26 ;; Besides that parser, the generic exporter is made of three distinct
27 ;; parts:
29 ;; - The communication channel consists in a property list, which is
30 ;; created and updated during the process. Its use is to offer
31 ;; every piece of information, would it be about initial environment
32 ;; or contextual data, all in a single place. The exhaustive list
33 ;; of properties is given in "The Communication Channel" section of
34 ;; this file.
36 ;; - The transcoder walks the parse tree, ignores or treat as plain
37 ;; text elements and objects according to export options, and
38 ;; eventually calls back-end specific functions to do the real
39 ;; transcoding, concatenating their return value along the way.
41 ;; - The filter system is activated at the very beginning and the very
42 ;; end of the export process, and each time an element or an object
43 ;; has been converted. It is the entry point to fine-tune standard
44 ;; output from back-end transcoders. See "The Filter System"
45 ;; section for more information.
47 ;; The core function is `org-export-as'. It returns the transcoded
48 ;; buffer as a string.
50 ;; An export back-end is defined with `org-export-define-backend',
51 ;; which defines one mandatory information: his translation table.
52 ;; Its value is an alist whose keys are elements and objects types and
53 ;; values translator functions. See function's docstring for more
54 ;; information about translators.
56 ;; Optionally, `org-export-define-backend' can also support specific
57 ;; buffer keywords, OPTION keyword's items and filters. Also refer to
58 ;; function documentation for more information.
60 ;; If the new back-end shares most properties with another one,
61 ;; `org-export-define-derived-backend' can be used to simplify the
62 ;; process.
64 ;; Any back-end can define its own variables. Among them, those
65 ;; customizable should belong to the `org-export-BACKEND' group.
67 ;; Tools for common tasks across back-ends are implemented in the
68 ;; following part of then file.
70 ;; Then, a wrapper macro for asynchronous export,
71 ;; `org-export-async-start', along with tools to display results. are
72 ;; given in the penultimate part.
74 ;; Eventually, a dispatcher (`org-export-dispatch') for standard
75 ;; back-ends is provided in the last one.
77 ;;; Code:
79 (eval-when-compile (require 'cl))
80 (require 'org-element)
81 (require 'ob-exp)
83 (declare-function org-e-publish "org-e-publish" (project &optional force async))
84 (declare-function org-e-publish-all "org-e-publish" (&optional force async))
85 (declare-function
86 org-e-publish-current-file "org-e-publish" (&optional force async))
87 (declare-function org-e-publish-current-project "org-e-publish"
88 (&optional force async))
90 (defvar org-e-publish-project-alist)
91 (defvar org-table-number-fraction)
92 (defvar org-table-number-regexp)
96 ;;; Internal Variables
98 ;; Among internal variables, the most important is
99 ;; `org-export-options-alist'. This variable define the global export
100 ;; options, shared between every exporter, and how they are acquired.
102 (defconst org-export-max-depth 19
103 "Maximum nesting depth for headlines, counting from 0.")
105 (defconst org-export-options-alist
106 '((:author "AUTHOR" nil user-full-name t)
107 (:creator "CREATOR" nil org-export-creator-string)
108 (:date "DATE" nil nil t)
109 (:description "DESCRIPTION" nil nil newline)
110 (:email "EMAIL" nil user-mail-address t)
111 (:exclude-tags "EXCLUDE_TAGS" nil org-export-exclude-tags split)
112 (:headline-levels nil "H" org-export-headline-levels)
113 (:keywords "KEYWORDS" nil nil space)
114 (:language "LANGUAGE" nil org-export-default-language t)
115 (:preserve-breaks nil "\\n" org-export-preserve-breaks)
116 (:section-numbers nil "num" org-export-with-section-numbers)
117 (:select-tags "SELECT_TAGS" nil org-export-select-tags split)
118 (:time-stamp-file nil "timestamp" org-export-time-stamp-file)
119 (:title "TITLE" nil nil space)
120 (:with-archived-trees nil "arch" org-export-with-archived-trees)
121 (:with-author nil "author" org-export-with-author)
122 (:with-clocks nil "c" org-export-with-clocks)
123 (:with-creator nil "creator" org-export-with-creator)
124 (:with-date nil "date" org-export-with-date)
125 (:with-drawers nil "d" org-export-with-drawers)
126 (:with-email nil "email" org-export-with-email)
127 (:with-emphasize nil "*" org-export-with-emphasize)
128 (:with-entities nil "e" org-export-with-entities)
129 (:with-fixed-width nil ":" org-export-with-fixed-width)
130 (:with-footnotes nil "f" org-export-with-footnotes)
131 (:with-inlinetasks nil "inline" org-export-with-inlinetasks)
132 (:with-plannings nil "p" org-export-with-planning)
133 (:with-priority nil "pri" org-export-with-priority)
134 (:with-smart-quotes nil "'" org-export-with-smart-quotes)
135 (:with-special-strings nil "-" org-export-with-special-strings)
136 (:with-statistics-cookies nil "stat" org-export-with-statistics-cookies)
137 (:with-sub-superscript nil "^" org-export-with-sub-superscripts)
138 (:with-toc nil "toc" org-export-with-toc)
139 (:with-tables nil "|" org-export-with-tables)
140 (:with-tags nil "tags" org-export-with-tags)
141 (:with-tasks nil "tasks" org-export-with-tasks)
142 (:with-timestamps nil "<" org-export-with-timestamps)
143 (:with-todo-keywords nil "todo" org-export-with-todo-keywords))
144 "Alist between export properties and ways to set them.
146 The CAR of the alist is the property name, and the CDR is a list
147 like (KEYWORD OPTION DEFAULT BEHAVIOUR) where:
149 KEYWORD is a string representing a buffer keyword, or nil. Each
150 property defined this way can also be set, during subtree
151 export, through an headline property named after the keyword
152 with the \"EXPORT_\" prefix (i.e. DATE keyword and EXPORT_DATE
153 property).
154 OPTION is a string that could be found in an #+OPTIONS: line.
155 DEFAULT is the default value for the property.
156 BEHAVIOUR determines how Org should handle multiple keywords for
157 the same property. It is a symbol among:
158 nil Keep old value and discard the new one.
159 t Replace old value with the new one.
160 `space' Concatenate the values, separating them with a space.
161 `newline' Concatenate the values, separating them with
162 a newline.
163 `split' Split values at white spaces, and cons them to the
164 previous list.
166 Values set through KEYWORD and OPTION have precedence over
167 DEFAULT.
169 All these properties should be back-end agnostic. Back-end
170 specific properties are set through `org-export-define-backend'.
171 Properties redefined there have precedence over these.")
173 (defconst org-export-special-keywords '("FILETAGS" "SETUP_FILE" "OPTIONS")
174 "List of in-buffer keywords that require special treatment.
175 These keywords are not directly associated to a property. The
176 way they are handled must be hard-coded into
177 `org-export--get-inbuffer-options' function.")
179 (defconst org-export-filters-alist
180 '((:filter-bold . org-export-filter-bold-functions)
181 (:filter-babel-call . org-export-filter-babel-call-functions)
182 (:filter-center-block . org-export-filter-center-block-functions)
183 (:filter-clock . org-export-filter-clock-functions)
184 (:filter-code . org-export-filter-code-functions)
185 (:filter-comment . org-export-filter-comment-functions)
186 (:filter-comment-block . org-export-filter-comment-block-functions)
187 (:filter-diary-sexp . org-export-filter-diary-sexp-functions)
188 (:filter-drawer . org-export-filter-drawer-functions)
189 (:filter-dynamic-block . org-export-filter-dynamic-block-functions)
190 (:filter-entity . org-export-filter-entity-functions)
191 (:filter-example-block . org-export-filter-example-block-functions)
192 (:filter-export-block . org-export-filter-export-block-functions)
193 (:filter-export-snippet . org-export-filter-export-snippet-functions)
194 (:filter-final-output . org-export-filter-final-output-functions)
195 (:filter-fixed-width . org-export-filter-fixed-width-functions)
196 (:filter-footnote-definition . org-export-filter-footnote-definition-functions)
197 (:filter-footnote-reference . org-export-filter-footnote-reference-functions)
198 (:filter-headline . org-export-filter-headline-functions)
199 (:filter-horizontal-rule . org-export-filter-horizontal-rule-functions)
200 (:filter-inline-babel-call . org-export-filter-inline-babel-call-functions)
201 (:filter-inline-src-block . org-export-filter-inline-src-block-functions)
202 (:filter-inlinetask . org-export-filter-inlinetask-functions)
203 (:filter-italic . org-export-filter-italic-functions)
204 (:filter-item . org-export-filter-item-functions)
205 (:filter-keyword . org-export-filter-keyword-functions)
206 (:filter-latex-environment . org-export-filter-latex-environment-functions)
207 (:filter-latex-fragment . org-export-filter-latex-fragment-functions)
208 (:filter-line-break . org-export-filter-line-break-functions)
209 (:filter-link . org-export-filter-link-functions)
210 (:filter-macro . org-export-filter-macro-functions)
211 (:filter-node-property . org-export-filter-node-property-functions)
212 (:filter-paragraph . org-export-filter-paragraph-functions)
213 (:filter-parse-tree . org-export-filter-parse-tree-functions)
214 (:filter-plain-list . org-export-filter-plain-list-functions)
215 (:filter-plain-text . org-export-filter-plain-text-functions)
216 (:filter-planning . org-export-filter-planning-functions)
217 (:filter-property-drawer . org-export-filter-property-drawer-functions)
218 (:filter-quote-block . org-export-filter-quote-block-functions)
219 (:filter-quote-section . org-export-filter-quote-section-functions)
220 (:filter-radio-target . org-export-filter-radio-target-functions)
221 (:filter-section . org-export-filter-section-functions)
222 (:filter-special-block . org-export-filter-special-block-functions)
223 (:filter-src-block . org-export-filter-src-block-functions)
224 (:filter-statistics-cookie . org-export-filter-statistics-cookie-functions)
225 (:filter-strike-through . org-export-filter-strike-through-functions)
226 (:filter-subscript . org-export-filter-subscript-functions)
227 (:filter-superscript . org-export-filter-superscript-functions)
228 (:filter-table . org-export-filter-table-functions)
229 (:filter-table-cell . org-export-filter-table-cell-functions)
230 (:filter-table-row . org-export-filter-table-row-functions)
231 (:filter-target . org-export-filter-target-functions)
232 (:filter-timestamp . org-export-filter-timestamp-functions)
233 (:filter-underline . org-export-filter-underline-functions)
234 (:filter-verbatim . org-export-filter-verbatim-functions)
235 (:filter-verse-block . org-export-filter-verse-block-functions))
236 "Alist between filters properties and initial values.
238 The key of each association is a property name accessible through
239 the communication channel. Its value is a configurable global
240 variable defining initial filters.
242 This list is meant to install user specified filters. Back-end
243 developers may install their own filters using
244 `org-export-define-backend'. Filters defined there will always
245 be prepended to the current list, so they always get applied
246 first.")
248 (defconst org-export-default-inline-image-rule
249 `(("file" .
250 ,(format "\\.%s\\'"
251 (regexp-opt
252 '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
253 "xpm" "pbm" "pgm" "ppm") t))))
254 "Default rule for link matching an inline image.
255 This rule applies to links with no description. By default, it
256 will be considered as an inline image if it targets a local file
257 whose extension is either \"png\", \"jpeg\", \"jpg\", \"gif\",
258 \"tiff\", \"tif\", \"xbm\", \"xpm\", \"pbm\", \"pgm\" or \"ppm\".
259 See `org-export-inline-image-p' for more information about
260 rules.")
262 (defvar org-export-async-debug nil
263 "Non-nil means asynchronous export process should leave data behind.
265 This data is found in the appropriate \"*Org Export Process*\"
266 buffer, and in files prefixed with \"org-export-process\" and
267 located in `temporary-file-directory'.
269 When non-nil, it will also set `debug-on-error' to a non-nil
270 value in the external process.")
272 (defvar org-export-stack-contents nil
273 "Record asynchronously generated export results and processes.
274 This is an alist: its CAR is the source of the
275 result (destination file or buffer for a finished process,
276 original buffer for a running one) and its CDR is a list
277 containing the back-end used, as a symbol, and either a process
278 or the time at which it finished. It is used to build the menu
279 from `org-export-stack'.")
281 (defvar org-export-registered-backends nil
282 "List of backends currently available in the exporter.
284 A backend is stored as a list where CAR is its name, as a symbol,
285 and CDR is a plist with the following properties:
286 `:filters-alist', `:menu-entry', `:options-alist' and
287 `:translate-alist'.
289 This variable is set with `org-export-define-backend' and
290 `org-export-define-derived-backend' functions.")
292 (defvar org-export-dispatch-last-action nil
293 "Last command called from the dispatcher.
294 The value should be a list. Its CAR is the action, as a symbol,
295 and its CDR is a list of export options.")
299 ;;; User-configurable Variables
301 ;; Configuration for the masses.
303 ;; They should never be accessed directly, as their value is to be
304 ;; stored in a property list (cf. `org-export-options-alist').
305 ;; Back-ends will read their value from there instead.
307 (defgroup org-export nil
308 "Options for exporting Org mode files."
309 :tag "Org Export"
310 :group 'org)
312 (defgroup org-export-general nil
313 "General options for export engine."
314 :tag "Org Export General"
315 :group 'org-export)
317 (defcustom org-export-with-archived-trees 'headline
318 "Whether sub-trees with the ARCHIVE tag should be exported.
320 This can have three different values:
321 nil Do not export, pretend this tree is not present.
322 t Do export the entire tree.
323 `headline' Only export the headline, but skip the tree below it.
325 This option can also be set with the #+OPTIONS line,
326 e.g. \"arch:nil\"."
327 :group 'org-export-general
328 :type '(choice
329 (const :tag "Not at all" nil)
330 (const :tag "Headline only" 'headline)
331 (const :tag "Entirely" t)))
333 (defcustom org-export-with-author t
334 "Non-nil means insert author name into the exported file.
335 This option can also be set with the #+OPTIONS line,
336 e.g. \"author:nil\"."
337 :group 'org-export-general
338 :type 'boolean)
340 (defcustom org-export-with-clocks nil
341 "Non-nil means export CLOCK keywords.
342 This option can also be set with the #+OPTIONS line,
343 e.g. \"c:t\"."
344 :group 'org-export-general
345 :type 'boolean)
347 (defcustom org-export-with-creator 'comment
348 "Non-nil means the postamble should contain a creator sentence.
350 The sentence can be set in `org-export-creator-string' and
351 defaults to \"Generated by Org mode XX in Emacs XXX.\".
353 If the value is `comment' insert it as a comment."
354 :group 'org-export-general
355 :type '(choice
356 (const :tag "No creator sentence" nil)
357 (const :tag "Sentence as a comment" 'comment)
358 (const :tag "Insert the sentence" t)))
360 (defcustom org-export-with-date t
361 "Non-nil means insert date in the exported document.
362 This options can also be set with the OPTIONS keyword,
363 e.g. \"date:nil\".")
365 (defcustom org-export-creator-string
366 (format "Generated by Org mode %s in Emacs %s."
367 (if (fboundp 'org-version) (org-version) "(Unknown)")
368 emacs-version)
369 "String to insert at the end of the generated document."
370 :group 'org-export-general
371 :type '(string :tag "Creator string"))
373 (defcustom org-export-with-drawers t
374 "Non-nil means export contents of standard drawers.
376 When t, all drawers are exported. This may also be a list of
377 drawer names to export. This variable doesn't apply to
378 properties drawers.
380 This option can also be set with the #+OPTIONS line,
381 e.g. \"d:nil\"."
382 :group 'org-export-general
383 :type '(choice
384 (const :tag "All drawers" t)
385 (const :tag "None" nil)
386 (repeat :tag "Selected drawers"
387 (string :tag "Drawer name"))))
389 (defcustom org-export-with-email nil
390 "Non-nil means insert author email into the exported file.
391 This option can also be set with the #+OPTIONS line,
392 e.g. \"email:t\"."
393 :group 'org-export-general
394 :type 'boolean)
396 (defcustom org-export-with-emphasize t
397 "Non-nil means interpret *word*, /word/, _word_ and +word+.
399 If the export target supports emphasizing text, the word will be
400 typeset in bold, italic, with an underline or strike-through,
401 respectively.
403 This option can also be set with the #+OPTIONS line, e.g. \"*:nil\"."
404 :group 'org-export-general
405 :type 'boolean)
407 (defcustom org-export-exclude-tags '("noexport")
408 "Tags that exclude a tree from export.
410 All trees carrying any of these tags will be excluded from
411 export. This is without condition, so even subtrees inside that
412 carry one of the `org-export-select-tags' will be removed.
414 This option can also be set with the #+EXCLUDE_TAGS: keyword."
415 :group 'org-export-general
416 :type '(repeat (string :tag "Tag")))
418 (defcustom org-export-with-fixed-width t
419 "Non-nil means lines starting with \":\" will be in fixed width font.
421 This can be used to have pre-formatted text, fragments of code
422 etc. For example:
423 : ;; Some Lisp examples
424 : (while (defc cnt)
425 : (ding))
426 will be looking just like this in also HTML. See also the QUOTE
427 keyword. Not all export backends support this.
429 This option can also be set with the #+OPTIONS line, e.g. \"::nil\"."
430 :group 'org-export-translation
431 :type 'boolean)
433 (defcustom org-export-with-footnotes t
434 "Non-nil means Org footnotes should be exported.
435 This option can also be set with the #+OPTIONS line,
436 e.g. \"f:nil\"."
437 :group 'org-export-general
438 :type 'boolean)
440 (defcustom org-export-headline-levels 3
441 "The last level which is still exported as a headline.
443 Inferior levels will produce itemize lists when exported.
445 This option can also be set with the #+OPTIONS line, e.g. \"H:2\"."
446 :group 'org-export-general
447 :type 'integer)
449 (defcustom org-export-default-language "en"
450 "The default language for export and clocktable translations, as a string.
451 This may have an association in
452 `org-clock-clocktable-language-setup'."
453 :group 'org-export-general
454 :type '(string :tag "Language"))
456 (defcustom org-export-preserve-breaks nil
457 "Non-nil means preserve all line breaks when exporting.
459 Normally, in HTML output paragraphs will be reformatted.
461 This option can also be set with the #+OPTIONS line,
462 e.g. \"\\n:t\"."
463 :group 'org-export-general
464 :type 'boolean)
466 (defcustom org-export-with-entities t
467 "Non-nil means interpret entities when exporting.
469 For example, HTML export converts \\alpha to &alpha; and \\AA to
470 &Aring;.
472 For a list of supported names, see the constant `org-entities'
473 and the user option `org-entities-user'.
475 This option can also be set with the #+OPTIONS line,
476 e.g. \"e:nil\"."
477 :group 'org-export-general
478 :type 'boolean)
480 (defcustom org-export-with-inlinetasks t
481 "Non-nil means inlinetasks should be exported.
482 This option can also be set with the #+OPTIONS line,
483 e.g. \"inline:nil\"."
484 :group 'org-export-general
485 :type 'boolean)
487 (defcustom org-export-with-planning nil
488 "Non-nil means include planning info in export.
489 This option can also be set with the #+OPTIONS: line,
490 e.g. \"p:t\"."
491 :group 'org-export-general
492 :type 'boolean)
494 (defcustom org-export-with-priority nil
495 "Non-nil means include priority cookies in export.
496 This option can also be set with the #+OPTIONS line,
497 e.g. \"pri:t\"."
498 :group 'org-export-general
499 :type 'boolean)
501 (defcustom org-export-with-section-numbers t
502 "Non-nil means add section numbers to headlines when exporting.
504 When set to an integer n, numbering will only happen for
505 headlines whose relative level is higher or equal to n.
507 This option can also be set with the #+OPTIONS line,
508 e.g. \"num:t\"."
509 :group 'org-export-general
510 :type 'boolean)
512 (defcustom org-export-select-tags '("export")
513 "Tags that select a tree for export.
515 If any such tag is found in a buffer, all trees that do not carry
516 one of these tags will be ignored during export. Inside trees
517 that are selected like this, you can still deselect a subtree by
518 tagging it with one of the `org-export-exclude-tags'.
520 This option can also be set with the #+SELECT_TAGS: keyword."
521 :group 'org-export-general
522 :type '(repeat (string :tag "Tag")))
524 (defcustom org-export-with-smart-quotes nil
525 "Non-nil means activate smart quotes during export.
526 This option can also be set with the #+OPTIONS: line,
527 e.g. \"':t\"."
528 :group 'org-export-general
529 :type 'boolean)
531 (defcustom org-export-with-special-strings t
532 "Non-nil means interpret \"\\-\", \"--\" and \"---\" for export.
534 When this option is turned on, these strings will be exported as:
536 Org HTML LaTeX UTF-8
537 -----+----------+--------+-------
538 \\- &shy; \\-
539 -- &ndash; -- –
540 --- &mdash; --- —
541 ... &hellip; \\ldots …
543 This option can also be set with the #+OPTIONS line,
544 e.g. \"-:nil\"."
545 :group 'org-export-general
546 :type 'boolean)
548 (defcustom org-export-with-statistics-cookies t
549 "Non-nil means include statistics cookies in export.
550 This option can also be set with the #+OPTIONS: line,
551 e.g. \"stat:nil\""
552 :group 'org-export-general
553 :type 'boolean)
555 (defcustom org-export-with-sub-superscripts t
556 "Non-nil means interpret \"_\" and \"^\" for export.
558 When this option is turned on, you can use TeX-like syntax for
559 sub- and superscripts. Several characters after \"_\" or \"^\"
560 will be considered as a single item - so grouping with {} is
561 normally not needed. For example, the following things will be
562 parsed as single sub- or superscripts.
564 10^24 or 10^tau several digits will be considered 1 item.
565 10^-12 or 10^-tau a leading sign with digits or a word
566 x^2-y^3 will be read as x^2 - y^3, because items are
567 terminated by almost any nonword/nondigit char.
568 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
570 Still, ambiguity is possible - so when in doubt use {} to enclose
571 the sub/superscript. If you set this variable to the symbol
572 `{}', the braces are *required* in order to trigger
573 interpretations as sub/superscript. This can be helpful in
574 documents that need \"_\" frequently in plain text.
576 This option can also be set with the #+OPTIONS line,
577 e.g. \"^:nil\"."
578 :group 'org-export-general
579 :type '(choice
580 (const :tag "Interpret them" t)
581 (const :tag "Curly brackets only" {})
582 (const :tag "Do not interpret them" nil)))
584 (defcustom org-export-with-toc t
585 "Non-nil means create a table of contents in exported files.
587 The TOC contains headlines with levels up
588 to`org-export-headline-levels'. When an integer, include levels
589 up to N in the toc, this may then be different from
590 `org-export-headline-levels', but it will not be allowed to be
591 larger than the number of headline levels. When nil, no table of
592 contents is made.
594 This option can also be set with the #+OPTIONS line,
595 e.g. \"toc:nil\" or \"toc:3\"."
596 :group 'org-export-general
597 :type '(choice
598 (const :tag "No Table of Contents" nil)
599 (const :tag "Full Table of Contents" t)
600 (integer :tag "TOC to level")))
602 (defcustom org-export-with-tables t
603 "If non-nil, lines starting with \"|\" define a table.
604 For example:
606 | Name | Address | Birthday |
607 |-------------+----------+-----------|
608 | Arthur Dent | England | 29.2.2100 |
610 This option can also be set with the #+OPTIONS line, e.g. \"|:nil\"."
611 :group 'org-export-general
612 :type 'boolean)
614 (defcustom org-export-with-tags t
615 "If nil, do not export tags, just remove them from headlines.
617 If this is the symbol `not-in-toc', tags will be removed from
618 table of contents entries, but still be shown in the headlines of
619 the document.
621 This option can also be set with the #+OPTIONS line,
622 e.g. \"tags:nil\"."
623 :group 'org-export-general
624 :type '(choice
625 (const :tag "Off" nil)
626 (const :tag "Not in TOC" not-in-toc)
627 (const :tag "On" t)))
629 (defcustom org-export-with-tasks t
630 "Non-nil means include TODO items for export.
632 This may have the following values:
633 t include tasks independent of state.
634 `todo' include only tasks that are not yet done.
635 `done' include only tasks that are already done.
636 nil ignore all tasks.
637 list of keywords include tasks with these keywords.
639 This option can also be set with the #+OPTIONS line,
640 e.g. \"tasks:nil\"."
641 :group 'org-export-general
642 :type '(choice
643 (const :tag "All tasks" t)
644 (const :tag "No tasks" nil)
645 (const :tag "Not-done tasks" todo)
646 (const :tag "Only done tasks" done)
647 (repeat :tag "Specific TODO keywords"
648 (string :tag "Keyword"))))
650 (defcustom org-export-time-stamp-file t
651 "Non-nil means insert a time stamp into the exported file.
652 The time stamp shows when the file was created.
654 This option can also be set with the #+OPTIONS line,
655 e.g. \"timestamp:nil\"."
656 :group 'org-export-general
657 :type 'boolean)
659 (defcustom org-export-with-timestamps t
660 "Non nil means allow timestamps in export.
662 It can be set to `active', `inactive', t or nil, in order to
663 export, respectively, only active timestamps, only inactive ones,
664 all of them or none.
666 This option can also be set with the #+OPTIONS line, e.g.
667 \"<:nil\"."
668 :group 'org-export-general
669 :type '(choice
670 (const :tag "All timestamps" t)
671 (const :tag "Only active timestamps" active)
672 (const :tag "Only inactive timestamps" inactive)
673 (const :tag "No timestamp" nil)))
675 (defcustom org-export-with-todo-keywords t
676 "Non-nil means include TODO keywords in export.
677 When nil, remove all these keywords from the export."
678 :group 'org-export-general
679 :type 'boolean)
681 (defcustom org-export-allow-BIND 'confirm
682 "Non-nil means allow #+BIND to define local variable values for export.
683 This is a potential security risk, which is why the user must
684 confirm the use of these lines."
685 :group 'org-export-general
686 :type '(choice
687 (const :tag "Never" nil)
688 (const :tag "Always" t)
689 (const :tag "Ask a confirmation for each file" confirm)))
691 (defcustom org-export-snippet-translation-alist nil
692 "Alist between export snippets back-ends and exporter back-ends.
694 This variable allows to provide shortcuts for export snippets.
696 For example, with a value of '\(\(\"h\" . \"e-html\"\)\), the
697 HTML back-end will recognize the contents of \"@@h:<b>@@\" as
698 HTML code while every other back-end will ignore it."
699 :group 'org-export-general
700 :type '(repeat
701 (cons
702 (string :tag "Shortcut")
703 (string :tag "Back-end"))))
705 (defcustom org-export-coding-system nil
706 "Coding system for the exported file."
707 :group 'org-export-general
708 :type 'coding-system)
710 (defcustom org-export-copy-to-kill-ring t
711 "Non-nil means exported stuff will also be pushed onto the kill ring."
712 :group 'org-export-general
713 :type 'boolean)
715 (defcustom org-export-initial-scope 'buffer
716 "The initial scope when exporting with `org-export-dispatch'.
717 This variable can be either set to `buffer' or `subtree'."
718 :group 'org-export-general
719 :type '(choice
720 (const :tag "Export current buffer" 'buffer)
721 (const :tag "Export current subtree" 'subtree)))
723 (defcustom org-export-show-temporary-export-buffer t
724 "Non-nil means show buffer after exporting to temp buffer.
725 When Org exports to a file, the buffer visiting that file is ever
726 shown, but remains buried. However, when exporting to
727 a temporary buffer, that buffer is popped up in a second window.
728 When this variable is nil, the buffer remains buried also in
729 these cases."
730 :group 'org-export-general
731 :type 'boolean)
733 (defcustom org-export-in-background nil
734 "Non-nil means export and publishing commands will run in background.
735 Results from an asynchronous export are never displayed. You can
736 retrieve them with \\[org-export-stack]."
737 :group 'org-export-general
738 :type 'boolean)
740 (defcustom org-export-async-init-file user-init-file
741 "File used to initialize external export process.
742 Value must be an absolute file name. It defaults to user's
743 initialization file. Though, a specific configuration makes the
744 process faster and the export more portable."
745 :group 'org-export-general
746 :type '(file :must-match t))
748 (defcustom org-export-dispatch-use-expert-ui nil
749 "Non-nil means using a non-intrusive `org-export-dispatch'.
750 In that case, no help buffer is displayed. Though, an indicator
751 for current export scope is added to the prompt (\"b\" when
752 output is restricted to body only, \"s\" when it is restricted to
753 the current subtree, \"v\" when only visible elements are
754 considered for export and \"f\" when publishing functions should
755 be passed the FORCE argument). Also, \[?] allows to switch back
756 to standard mode."
757 :group 'org-export-general
758 :type 'boolean)
762 ;;; Defining Back-ends
764 ;; `org-export-define-backend' is the standard way to define an export
765 ;; back-end. It allows to specify translators, filters, buffer
766 ;; options and a menu entry. If the new back-end shares translators
767 ;; with another back-end, `org-export-define-derived-backend' may be
768 ;; used instead.
770 ;; Internally, a back-end is stored as a list, of which CAR is the
771 ;; name of the back-end, as a symbol, and CDR a plist. Accessors to
772 ;; properties of a given back-end are: `org-export-backend-filters',
773 ;; `org-export-backend-menu', `org-export-backend-options' and
774 ;; `org-export-backend-translate-table'.
776 ;; Eventually `org-export-barf-if-invalid-backend' returns an error
777 ;; when a given back-end hasn't been registered yet.
779 (defmacro org-export-define-backend (backend translators &rest body)
780 "Define a new back-end BACKEND.
782 TRANSLATORS is an alist between object or element types and
783 functions handling them.
785 These functions should return a string without any trailing
786 space, or nil. They must accept three arguments: the object or
787 element itself, its contents or nil when it isn't recursive and
788 the property list used as a communication channel.
790 Contents, when not nil, are stripped from any global indentation
791 \(although the relative one is preserved). They also always end
792 with a single newline character.
794 If, for a given type, no function is found, that element or
795 object type will simply be ignored, along with any blank line or
796 white space at its end. The same will happen if the function
797 returns the nil value. If that function returns the empty
798 string, the type will be ignored, but the blank lines or white
799 spaces will be kept.
801 In addition to element and object types, one function can be
802 associated to the `template' symbol and another one to the
803 `plain-text' symbol.
805 The former returns the final transcoded string, and can be used
806 to add a preamble and a postamble to document's body. It must
807 accept two arguments: the transcoded string and the property list
808 containing export options.
810 The latter, when defined, is to be called on every text not
811 recognized as an element or an object. It must accept two
812 arguments: the text string and the information channel. It is an
813 appropriate place to protect special chars relative to the
814 back-end.
816 BODY can start with pre-defined keyword arguments. The following
817 keywords are understood:
819 :export-block
821 String, or list of strings, representing block names that
822 will not be parsed. This is used to specify blocks that will
823 contain raw code specific to the back-end. These blocks
824 still have to be handled by the relative `export-block' type
825 translator.
827 :filters-alist
829 Alist between filters and function, or list of functions,
830 specific to the back-end. See `org-export-filters-alist' for
831 a list of all allowed filters. Filters defined here
832 shouldn't make a back-end test, as it may prevent back-ends
833 derived from this one to behave properly.
835 :menu-entry
837 Menu entry for the export dispatcher. It should be a list
838 like:
840 \(KEY DESCRIPTION-OR-ORDINAL ACTION-OR-MENU)
842 where :
844 KEY is a free character selecting the back-end.
846 DESCRIPTION-OR-ORDINAL is either a string or a number.
848 If it is a string, is will be used to name the back-end in
849 its menu entry. If it is a number, the following menu will
850 be displayed as a sub-menu of the back-end with the same
851 KEY. Also, the number will be used to determine in which
852 order such sub-menus will appear (lowest first).
854 ACTION-OR-MENU is either a function or an alist.
856 If it is an action, it will be called with four
857 arguments (booleans): ASYNC, SUBTREEP, VISIBLE-ONLY and
858 BODY-ONLY. See `org-export-as' for further explanations on
859 some of them.
861 If it is an alist, associations should follow the
862 pattern:
864 \(KEY DESCRIPTION ACTION)
866 where KEY, DESCRIPTION and ACTION are described above.
868 Valid values include:
870 \(?m \"My Special Back-end\" my-special-export-function)
874 \(?l \"Export to LaTeX\"
875 \(?p \"As PDF file\" org-e-latex-export-to-pdf)
876 \(?o \"As PDF file and open\"
877 \(lambda (a s v b)
878 \(if a (org-e-latex-export-to-pdf t s v b)
879 \(org-open-file
880 \(org-e-latex-export-to-pdf nil s v b)))))))
882 or the following, which will be added to the previous
883 sub-menu,
885 \(?l 1
886 \((?B \"As TEX buffer (Beamer)\" org-e-beamer-export-as-latex)
887 \(?P \"As PDF file (Beamer)\" org-e-beamer-export-to-pdf)))
889 :options-alist
891 Alist between back-end specific properties introduced in
892 communication channel and how their value are acquired. See
893 `org-export-options-alist' for more information about
894 structure of the values."
895 (declare (debug (&define name sexp [&rest [keywordp sexp]] defbody))
896 (indent 1))
897 (let (export-block filters menu-entry options contents)
898 (while (keywordp (car body))
899 (case (pop body)
900 (:export-block (let ((names (pop body)))
901 (setq export-block
902 (if (consp names) (mapcar 'upcase names)
903 (list (upcase names))))))
904 (:filters-alist (setq filters (pop body)))
905 (:menu-entry (setq menu-entry (pop body)))
906 (:options-alist (setq options (pop body)))
907 (t (pop body))))
908 (setq contents (append (list :translate-alist translators)
909 (and filters (list :filters-alist filters))
910 (and options (list :options-alist options))
911 (and menu-entry (list :menu-entry menu-entry))))
912 `(progn
913 ;; Register back-end.
914 (let ((registeredp (assq ',backend org-export-registered-backends)))
915 (if registeredp (setcdr registeredp ',contents)
916 (push (cons ',backend ',contents) org-export-registered-backends)))
917 ;; Tell parser to not parse EXPORT-BLOCK blocks.
918 ,(when export-block
919 `(mapc
920 (lambda (name)
921 (add-to-list 'org-element-block-name-alist
922 `(,name . org-element-export-block-parser)))
923 ',export-block))
924 ;; Splice in the body, if any.
925 ,@body)))
927 (defmacro org-export-define-derived-backend (child parent &rest body)
928 "Create a new back-end as a variant of an existing one.
930 CHILD is the name of the derived back-end. PARENT is the name of
931 the parent back-end.
933 BODY can start with pre-defined keyword arguments. The following
934 keywords are understood:
936 :export-block
938 String, or list of strings, representing block names that
939 will not be parsed. This is used to specify blocks that will
940 contain raw code specific to the back-end. These blocks
941 still have to be handled by the relative `export-block' type
942 translator.
944 :filters-alist
946 Alist of filters that will overwrite or complete filters
947 defined in PARENT back-end. See `org-export-filters-alist'
948 for a list of allowed filters.
950 :menu-entry
952 Menu entry for the export dispatcher. See
953 `org-export-define-backend' for more information about the
954 expected value.
956 :options-alist
958 Alist of back-end specific properties that will overwrite or
959 complete those defined in PARENT back-end. Refer to
960 `org-export-options-alist' for more information about
961 structure of the values.
963 :translate-alist
965 Alist of element and object types and transcoders that will
966 overwrite or complete transcode table from PARENT back-end.
967 Refer to `org-export-define-backend' for detailed information
968 about transcoders.
970 As an example, here is how one could define \"my-latex\" back-end
971 as a variant of `e-latex' back-end with a custom template
972 function:
974 \(org-export-define-derived-backend my-latex e-latex
975 :translate-alist ((template . my-latex-template-fun)))
977 The back-end could then be called with, for example:
979 \(org-export-to-buffer 'my-latex \"*Test my-latex*\")"
980 (declare (debug (&define name sexp [&rest [keywordp sexp]] def-body))
981 (indent 2))
982 (org-export-barf-if-invalid-backend parent)
983 (let (export-block filters menu-entry options translators contents)
984 (while (keywordp (car body))
985 (case (pop body)
986 (:export-block (let ((names (pop body)))
987 (setq export-block
988 (if (consp names) (mapcar 'upcase names)
989 (list (upcase names))))))
990 (:filters-alist (setq filters (pop body)))
991 (:menu-entry (setq menu-entry (pop body)))
992 (:options-alist (setq options (pop body)))
993 (:translate-alist (setq translators (pop body)))
994 (t (pop body))))
995 (setq contents (append
996 (list :parent parent)
997 (let ((p-table (org-export-backend-translate-table parent)))
998 (list :translate-alist (append translators p-table)))
999 (let ((p-filters (org-export-backend-filters parent)))
1000 (list :filters-alist (append filters p-filters)))
1001 (let ((p-options (org-export-backend-options parent)))
1002 (list :options-alist (append options p-options)))
1003 (and menu-entry (list :menu-entry menu-entry))))
1004 `(progn
1005 ;; Register back-end.
1006 (let ((registeredp (assq ',child org-export-registered-backends)))
1007 (if registeredp (setcdr registeredp ',contents)
1008 (push (cons ',child ',contents) org-export-registered-backends)))
1009 ;; Tell parser to not parse EXPORT-BLOCK blocks.
1010 ,(when export-block
1011 `(mapc
1012 (lambda (name)
1013 (add-to-list 'org-element-block-name-alist
1014 `(,name . org-element-export-block-parser)))
1015 ',export-block))
1016 ;; Splice in the body, if any.
1017 ,@body)))
1019 (defun org-export-backend-filters (backend)
1020 "Return filters for BACKEND."
1021 (plist-get (cdr (assq backend org-export-registered-backends))
1022 :filters-alist))
1024 (defun org-export-backend-menu (backend)
1025 "Return menu entry for BACKEND."
1026 (plist-get (cdr (assq backend org-export-registered-backends))
1027 :menu-entry))
1029 (defun org-export-backend-options (backend)
1030 "Return export options for BACKEND."
1031 (plist-get (cdr (assq backend org-export-registered-backends))
1032 :options-alist))
1034 (defun org-export-backend-translate-table (backend)
1035 "Return translate table for BACKEND."
1036 (plist-get (cdr (assq backend org-export-registered-backends))
1037 :translate-alist))
1039 (defun org-export-barf-if-invalid-backend (backend)
1040 "Signal an error if BACKEND isn't defined."
1041 (unless (org-export-backend-translate-table backend)
1042 (error "Unknown \"%s\" back-end: Aborting export" backend)))
1044 (defun org-export-derived-backend-p (backend &rest backends)
1045 "Non-nil if BACKEND is derived from one of BACKENDS."
1046 (let ((parent backend))
1047 (while (and (not (memq parent backends))
1048 (setq parent
1049 (plist-get (cdr (assq parent
1050 org-export-registered-backends))
1051 :parent))))
1052 parent))
1056 ;;; The Communication Channel
1058 ;; During export process, every function has access to a number of
1059 ;; properties. They are of two types:
1061 ;; 1. Environment options are collected once at the very beginning of
1062 ;; the process, out of the original buffer and configuration.
1063 ;; Collecting them is handled by `org-export-get-environment'
1064 ;; function.
1066 ;; Most environment options are defined through the
1067 ;; `org-export-options-alist' variable.
1069 ;; 2. Tree properties are extracted directly from the parsed tree,
1070 ;; just before export, by `org-export-collect-tree-properties'.
1072 ;; Here is the full list of properties available during transcode
1073 ;; process, with their category and their value type.
1075 ;; + `:author' :: Author's name.
1076 ;; - category :: option
1077 ;; - type :: string
1079 ;; + `:back-end' :: Current back-end used for transcoding.
1080 ;; - category :: tree
1081 ;; - type :: symbol
1083 ;; + `:creator' :: String to write as creation information.
1084 ;; - category :: option
1085 ;; - type :: string
1087 ;; + `:date' :: String to use as date.
1088 ;; - category :: option
1089 ;; - type :: string
1091 ;; + `:description' :: Description text for the current data.
1092 ;; - category :: option
1093 ;; - type :: string
1095 ;; + `:email' :: Author's email.
1096 ;; - category :: option
1097 ;; - type :: string
1099 ;; + `:exclude-tags' :: Tags for exclusion of subtrees from export
1100 ;; process.
1101 ;; - category :: option
1102 ;; - type :: list of strings
1104 ;; + `:exported-data' :: Hash table used for memoizing
1105 ;; `org-export-data'.
1106 ;; - category :: tree
1107 ;; - type :: hash table
1109 ;; + `:filetags' :: List of global tags for buffer. Used by
1110 ;; `org-export-get-tags' to get tags with inheritance.
1111 ;; - category :: option
1112 ;; - type :: list of strings
1114 ;; + `:footnote-definition-alist' :: Alist between footnote labels and
1115 ;; their definition, as parsed data. Only non-inlined footnotes
1116 ;; are represented in this alist. Also, every definition isn't
1117 ;; guaranteed to be referenced in the parse tree. The purpose of
1118 ;; this property is to preserve definitions from oblivion
1119 ;; (i.e. when the parse tree comes from a part of the original
1120 ;; buffer), it isn't meant for direct use in a back-end. To
1121 ;; retrieve a definition relative to a reference, use
1122 ;; `org-export-get-footnote-definition' instead.
1123 ;; - category :: option
1124 ;; - type :: alist (STRING . LIST)
1126 ;; + `:headline-levels' :: Maximum level being exported as an
1127 ;; headline. Comparison is done with the relative level of
1128 ;; headlines in the parse tree, not necessarily with their
1129 ;; actual level.
1130 ;; - category :: option
1131 ;; - type :: integer
1133 ;; + `:headline-offset' :: Difference between relative and real level
1134 ;; of headlines in the parse tree. For example, a value of -1
1135 ;; means a level 2 headline should be considered as level
1136 ;; 1 (cf. `org-export-get-relative-level').
1137 ;; - category :: tree
1138 ;; - type :: integer
1140 ;; + `:headline-numbering' :: Alist between headlines and their
1141 ;; numbering, as a list of numbers
1142 ;; (cf. `org-export-get-headline-number').
1143 ;; - category :: tree
1144 ;; - type :: alist (INTEGER . LIST)
1146 ;; + `:id-alist' :: Alist between ID strings and destination file's
1147 ;; path, relative to current directory. It is used by
1148 ;; `org-export-resolve-id-link' to resolve ID links targeting an
1149 ;; external file.
1150 ;; - category :: option
1151 ;; - type :: alist (STRING . STRING)
1153 ;; + `:ignore-list' :: List of elements and objects that should be
1154 ;; ignored during export.
1155 ;; - category :: tree
1156 ;; - type :: list of elements and objects
1158 ;; + `:input-file' :: Full path to input file, if any.
1159 ;; - category :: option
1160 ;; - type :: string or nil
1162 ;; + `:keywords' :: List of keywords attached to data.
1163 ;; - category :: option
1164 ;; - type :: string
1166 ;; + `:language' :: Default language used for translations.
1167 ;; - category :: option
1168 ;; - type :: string
1170 ;; + `:parse-tree' :: Whole parse tree, available at any time during
1171 ;; transcoding.
1172 ;; - category :: option
1173 ;; - type :: list (as returned by `org-element-parse-buffer')
1175 ;; + `:preserve-breaks' :: Non-nil means transcoding should preserve
1176 ;; all line breaks.
1177 ;; - category :: option
1178 ;; - type :: symbol (nil, t)
1180 ;; + `:section-numbers' :: Non-nil means transcoding should add
1181 ;; section numbers to headlines.
1182 ;; - category :: option
1183 ;; - type :: symbol (nil, t)
1185 ;; + `:select-tags' :: List of tags enforcing inclusion of sub-trees
1186 ;; in transcoding. When such a tag is present, subtrees without
1187 ;; it are de facto excluded from the process. See
1188 ;; `use-select-tags'.
1189 ;; - category :: option
1190 ;; - type :: list of strings
1192 ;; + `:target-list' :: List of targets encountered in the parse tree.
1193 ;; This is used to partly resolve "fuzzy" links
1194 ;; (cf. `org-export-resolve-fuzzy-link').
1195 ;; - category :: tree
1196 ;; - type :: list of strings
1198 ;; + `:time-stamp-file' :: Non-nil means transcoding should insert
1199 ;; a time stamp in the output.
1200 ;; - category :: option
1201 ;; - type :: symbol (nil, t)
1203 ;; + `:translate-alist' :: Alist between element and object types and
1204 ;; transcoding functions relative to the current back-end.
1205 ;; Special keys `template' and `plain-text' are also possible.
1206 ;; - category :: option
1207 ;; - type :: alist (SYMBOL . FUNCTION)
1209 ;; + `:with-archived-trees' :: Non-nil when archived subtrees should
1210 ;; also be transcoded. If it is set to the `headline' symbol,
1211 ;; only the archived headline's name is retained.
1212 ;; - category :: option
1213 ;; - type :: symbol (nil, t, `headline')
1215 ;; + `:with-author' :: Non-nil means author's name should be included
1216 ;; in the output.
1217 ;; - category :: option
1218 ;; - type :: symbol (nil, t)
1220 ;; + `:with-clocks' :: Non-nil means clock keywords should be exported.
1221 ;; - category :: option
1222 ;; - type :: symbol (nil, t)
1224 ;; + `:with-creator' :: Non-nil means a creation sentence should be
1225 ;; inserted at the end of the transcoded string. If the value
1226 ;; is `comment', it should be commented.
1227 ;; - category :: option
1228 ;; - type :: symbol (`comment', nil, t)
1230 ;; + `:with-date' :: Non-nil means output should contain a date.
1231 ;; - category :: option
1232 ;; - type :. symbol (nil, t)
1234 ;; + `:with-drawers' :: Non-nil means drawers should be exported. If
1235 ;; its value is a list of names, only drawers with such names
1236 ;; will be transcoded.
1237 ;; - category :: option
1238 ;; - type :: symbol (nil, t) or list of strings
1240 ;; + `:with-email' :: Non-nil means output should contain author's
1241 ;; email.
1242 ;; - category :: option
1243 ;; - type :: symbol (nil, t)
1245 ;; + `:with-emphasize' :: Non-nil means emphasized text should be
1246 ;; interpreted.
1247 ;; - category :: option
1248 ;; - type :: symbol (nil, t)
1250 ;; + `:with-fixed-width' :: Non-nil if transcoder should interpret
1251 ;; strings starting with a colon as a fixed-with (verbatim) area.
1252 ;; - category :: option
1253 ;; - type :: symbol (nil, t)
1255 ;; + `:with-footnotes' :: Non-nil if transcoder should interpret
1256 ;; footnotes.
1257 ;; - category :: option
1258 ;; - type :: symbol (nil, t)
1260 ;; + `:with-plannings' :: Non-nil means transcoding should include
1261 ;; planning info.
1262 ;; - category :: option
1263 ;; - type :: symbol (nil, t)
1265 ;; + `:with-priority' :: Non-nil means transcoding should include
1266 ;; priority cookies.
1267 ;; - category :: option
1268 ;; - type :: symbol (nil, t)
1270 ;; + `:with-smart-quotes' :: Non-nil means activate smart quotes in
1271 ;; plain text.
1272 ;; - category :: option
1273 ;; - type :: symbol (nil, t)
1275 ;; + `:with-special-strings' :: Non-nil means transcoding should
1276 ;; interpret special strings in plain text.
1277 ;; - category :: option
1278 ;; - type :: symbol (nil, t)
1280 ;; + `:with-sub-superscript' :: Non-nil means transcoding should
1281 ;; interpret subscript and superscript. With a value of "{}",
1282 ;; only interpret those using curly brackets.
1283 ;; - category :: option
1284 ;; - type :: symbol (nil, {}, t)
1286 ;; + `:with-tables' :: Non-nil means transcoding should interpret
1287 ;; tables.
1288 ;; - category :: option
1289 ;; - type :: symbol (nil, t)
1291 ;; + `:with-tags' :: Non-nil means transcoding should keep tags in
1292 ;; headlines. A `not-in-toc' value will remove them from the
1293 ;; table of contents, if any, nonetheless.
1294 ;; - category :: option
1295 ;; - type :: symbol (nil, t, `not-in-toc')
1297 ;; + `:with-tasks' :: Non-nil means transcoding should include
1298 ;; headlines with a TODO keyword. A `todo' value will only
1299 ;; include headlines with a todo type keyword while a `done'
1300 ;; value will do the contrary. If a list of strings is provided,
1301 ;; only tasks with keywords belonging to that list will be kept.
1302 ;; - category :: option
1303 ;; - type :: symbol (t, todo, done, nil) or list of strings
1305 ;; + `:with-timestamps' :: Non-nil means transcoding should include
1306 ;; time stamps. Special value `active' (resp. `inactive') ask to
1307 ;; export only active (resp. inactive) timestamps. Otherwise,
1308 ;; completely remove them.
1309 ;; - category :: option
1310 ;; - type :: symbol: (`active', `inactive', t, nil)
1312 ;; + `:with-toc' :: Non-nil means that a table of contents has to be
1313 ;; added to the output. An integer value limits its depth.
1314 ;; - category :: option
1315 ;; - type :: symbol (nil, t or integer)
1317 ;; + `:with-todo-keywords' :: Non-nil means transcoding should
1318 ;; include TODO keywords.
1319 ;; - category :: option
1320 ;; - type :: symbol (nil, t)
1323 ;;;; Environment Options
1325 ;; Environment options encompass all parameters defined outside the
1326 ;; scope of the parsed data. They come from five sources, in
1327 ;; increasing precedence order:
1329 ;; - Global variables,
1330 ;; - Buffer's attributes,
1331 ;; - Options keyword symbols,
1332 ;; - Buffer keywords,
1333 ;; - Subtree properties.
1335 ;; The central internal function with regards to environment options
1336 ;; is `org-export-get-environment'. It updates global variables with
1337 ;; "#+BIND:" keywords, then retrieve and prioritize properties from
1338 ;; the different sources.
1340 ;; The internal functions doing the retrieval are:
1341 ;; `org-export--get-global-options',
1342 ;; `org-export--get-buffer-attributes',
1343 ;; `org-export--parse-option-keyword',
1344 ;; `org-export--get-subtree-options' and
1345 ;; `org-export--get-inbuffer-options'
1347 ;; Also, `org-export--confirm-letbind' and `org-export--install-letbind'
1348 ;; take care of the part relative to "#+BIND:" keywords.
1350 (defun org-export-get-environment (&optional backend subtreep ext-plist)
1351 "Collect export options from the current buffer.
1353 Optional argument BACKEND is a symbol specifying which back-end
1354 specific options to read, if any.
1356 When optional argument SUBTREEP is non-nil, assume the export is
1357 done against the current sub-tree.
1359 Third optional argument EXT-PLIST is a property list with
1360 external parameters overriding Org default settings, but still
1361 inferior to file-local settings."
1362 ;; First install #+BIND variables.
1363 (org-export--install-letbind-maybe)
1364 ;; Get and prioritize export options...
1365 (org-combine-plists
1366 ;; ... from global variables...
1367 (org-export--get-global-options backend)
1368 ;; ... from an external property list...
1369 ext-plist
1370 ;; ... from in-buffer settings...
1371 (org-export--get-inbuffer-options
1372 backend
1373 (and buffer-file-name (org-remove-double-quotes buffer-file-name)))
1374 ;; ... and from subtree, when appropriate.
1375 (and subtreep (org-export--get-subtree-options backend))
1376 ;; Eventually add misc. properties.
1377 (list
1378 :back-end
1379 backend
1380 :translate-alist
1381 (org-export-backend-translate-table backend)
1382 :footnote-definition-alist
1383 ;; Footnotes definitions must be collected in the original
1384 ;; buffer, as there's no insurance that they will still be in
1385 ;; the parse tree, due to possible narrowing.
1386 (let (alist)
1387 (org-with-wide-buffer
1388 (goto-char (point-min))
1389 (while (re-search-forward org-footnote-definition-re nil t)
1390 (let ((def (save-match-data (org-element-at-point))))
1391 (when (eq (org-element-type def) 'footnote-definition)
1392 (push
1393 (cons (org-element-property :label def)
1394 (let ((cbeg (org-element-property :contents-begin def)))
1395 (when cbeg
1396 (org-element--parse-elements
1397 cbeg (org-element-property :contents-end def)
1398 nil nil nil nil (list 'org-data nil)))))
1399 alist))))
1400 alist))
1401 :id-alist
1402 ;; Collect id references.
1403 (let (alist)
1404 (org-with-wide-buffer
1405 (goto-char (point-min))
1406 (while (re-search-forward "\\[\\[id:\\S-+?\\]" nil t)
1407 (let ((link (org-element-context)))
1408 (when (eq (org-element-type link) 'link)
1409 (let* ((id (org-element-property :path link))
1410 (file (org-id-find-id-file id)))
1411 (when file
1412 (push (cons id (file-relative-name file)) alist)))))))
1413 alist))))
1415 (defun org-export--parse-option-keyword (options &optional backend)
1416 "Parse an OPTIONS line and return values as a plist.
1417 Optional argument BACKEND is a symbol specifying which back-end
1418 specific items to read, if any."
1419 (let* ((all (append org-export-options-alist
1420 (and backend (org-export-backend-options backend))))
1421 ;; Build an alist between #+OPTION: item and property-name.
1422 (alist (delq nil
1423 (mapcar (lambda (e)
1424 (when (nth 2 e) (cons (regexp-quote (nth 2 e))
1425 (car e))))
1426 all)))
1427 plist)
1428 (mapc (lambda (e)
1429 (when (string-match (concat "\\(\\`\\|[ \t]\\)"
1430 (car e)
1431 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
1432 options)
1433 (setq plist (plist-put plist
1434 (cdr e)
1435 (car (read-from-string
1436 (match-string 2 options)))))))
1437 alist)
1438 plist))
1440 (defun org-export--get-subtree-options (&optional backend)
1441 "Get export options in subtree at point.
1442 Optional argument BACKEND is a symbol specifying back-end used
1443 for export. Return options as a plist."
1444 ;; For each buffer keyword, create an headline property setting the
1445 ;; same property in communication channel. The name for the property
1446 ;; is the keyword with "EXPORT_" appended to it.
1447 (org-with-wide-buffer
1448 (let (prop plist)
1449 ;; Make sure point is at an heading.
1450 (unless (org-at-heading-p) (org-back-to-heading t))
1451 ;; Take care of EXPORT_TITLE. If it isn't defined, use headline's
1452 ;; title as its fallback value.
1453 (when (setq prop (or (org-entry-get (point) "EXPORT_TITLE")
1454 (progn (looking-at org-todo-line-regexp)
1455 (org-match-string-no-properties 3))))
1456 (setq plist
1457 (plist-put
1458 plist :title
1459 (org-element-parse-secondary-string
1460 prop (org-element-restriction 'keyword)))))
1461 ;; EXPORT_OPTIONS are parsed in a non-standard way.
1462 (when (setq prop (org-entry-get (point) "EXPORT_OPTIONS"))
1463 (setq plist
1464 (nconc plist (org-export--parse-option-keyword prop backend))))
1465 ;; Handle other keywords. TITLE keyword is excluded as it has
1466 ;; been handled already.
1467 (let ((seen '("TITLE")))
1468 (mapc
1469 (lambda (option)
1470 (let ((property (nth 1 option)))
1471 (when (and property (not (member property seen)))
1472 (let* ((subtree-prop (concat "EXPORT_" property))
1473 ;; Export properties are not case-sensitive.
1474 (value (let ((case-fold-search t))
1475 (org-entry-get (point) subtree-prop))))
1476 (push property seen)
1477 (when value
1478 (setq plist
1479 (plist-put
1480 plist
1481 (car option)
1482 (cond
1483 ;; Parse VALUE if required.
1484 ((member property org-element-document-properties)
1485 (org-element-parse-secondary-string
1486 value (org-element-restriction 'keyword)))
1487 ;; If BEHAVIOUR is `split' expected value is
1488 ;; a list of strings, not a string.
1489 ((eq (nth 4 option) 'split) (org-split-string value))
1490 (t value)))))))))
1491 ;; Also look for both general keywords and back-end specific
1492 ;; options if BACKEND is provided.
1493 (append (and backend (org-export-backend-options backend))
1494 org-export-options-alist)))
1495 ;; Return value.
1496 plist)))
1498 (defun org-export--get-inbuffer-options (&optional backend files)
1499 "Return current buffer export options, as a plist.
1501 Optional argument BACKEND, when non-nil, is a symbol specifying
1502 which back-end specific options should also be read in the
1503 process.
1505 Optional argument FILES is a list of setup files names read so
1506 far, used to avoid circular dependencies.
1508 Assume buffer is in Org mode. Narrowing, if any, is ignored."
1509 (org-with-wide-buffer
1510 (goto-char (point-min))
1511 (let ((case-fold-search t) plist)
1512 ;; 1. Special keywords, as in `org-export-special-keywords'.
1513 (let ((special-re
1514 (format "^[ \t]*#\\+%s:" (regexp-opt org-export-special-keywords))))
1515 (while (re-search-forward special-re nil t)
1516 (let ((element (org-element-at-point)))
1517 (when (eq (org-element-type element) 'keyword)
1518 (let* ((key (org-element-property :key element))
1519 (val (org-element-property :value element))
1520 (prop
1521 (cond
1522 ((equal key "SETUP_FILE")
1523 (let ((file
1524 (expand-file-name
1525 (org-remove-double-quotes (org-trim val)))))
1526 ;; Avoid circular dependencies.
1527 (unless (member file files)
1528 (with-temp-buffer
1529 (insert (org-file-contents file 'noerror))
1530 (org-mode)
1531 (org-export--get-inbuffer-options
1532 backend (cons file files))))))
1533 ((equal key "OPTIONS")
1534 (org-export--parse-option-keyword val backend))
1535 ((equal key "FILETAGS")
1536 (list :filetags
1537 (org-uniquify
1538 (append (org-split-string val ":")
1539 (plist-get plist :filetags))))))))
1540 (setq plist (org-combine-plists plist prop)))))))
1541 ;; 2. Standard options, as in `org-export-options-alist'.
1542 (let* ((all (append org-export-options-alist
1543 ;; Also look for back-end specific options if
1544 ;; BACKEND is defined.
1545 (and backend (org-export-backend-options backend))))
1546 ;; Build ALIST between keyword name and property name.
1547 (alist
1548 (delq nil (mapcar
1549 (lambda (e) (when (nth 1 e) (cons (nth 1 e) (car e))))
1550 all)))
1551 ;; Build regexp matching all keywords associated to export
1552 ;; options. Note: the search is case insensitive.
1553 (opt-re (format "^[ \t]*#\\+%s:"
1554 (regexp-opt
1555 (delq nil (mapcar (lambda (e) (nth 1 e)) all))))))
1556 (goto-char (point-min))
1557 (while (re-search-forward opt-re nil t)
1558 (let ((element (org-element-at-point)))
1559 (when (eq (org-element-type element) 'keyword)
1560 (let* ((key (org-element-property :key element))
1561 (val (org-element-property :value element))
1562 (prop (cdr (assoc key alist)))
1563 (behaviour (nth 4 (assq prop all))))
1564 (setq plist
1565 (plist-put
1566 plist prop
1567 ;; Handle value depending on specified BEHAVIOUR.
1568 (case behaviour
1569 (space
1570 (if (not (plist-get plist prop)) (org-trim val)
1571 (concat (plist-get plist prop) " " (org-trim val))))
1572 (newline
1573 (org-trim
1574 (concat (plist-get plist prop) "\n" (org-trim val))))
1575 (split
1576 `(,@(plist-get plist prop) ,@(org-split-string val)))
1577 ('t val)
1578 (otherwise (if (not (plist-member plist prop)) val
1579 (plist-get plist prop))))))))))
1580 ;; Parse keywords specified in
1581 ;; `org-element-document-properties'.
1582 (mapc
1583 (lambda (key)
1584 (let* ((prop (cdr (assoc key alist)))
1585 (value (and prop (plist-get plist prop))))
1586 (when (stringp value)
1587 (setq plist
1588 (plist-put
1589 plist prop
1590 (org-element-parse-secondary-string
1591 value (org-element-restriction 'keyword)))))))
1592 org-element-document-properties))
1593 ;; 3. Return final value.
1594 plist)))
1596 (defun org-export--get-buffer-attributes ()
1597 "Return properties related to buffer attributes, as a plist."
1598 (let ((visited-file (buffer-file-name (buffer-base-buffer))))
1599 (list
1600 ;; Store full path of input file name, or nil. For internal use.
1601 :input-file visited-file
1602 :title (or (and visited-file
1603 (file-name-sans-extension
1604 (file-name-nondirectory visited-file)))
1605 (buffer-name (buffer-base-buffer))))))
1607 (defun org-export--get-global-options (&optional backend)
1608 "Return global export options as a plist.
1610 Optional argument BACKEND, if non-nil, is a symbol specifying
1611 which back-end specific export options should also be read in the
1612 process."
1613 (let ((all (append org-export-options-alist
1614 (and backend (org-export-backend-options backend))))
1615 ;; Output value.
1616 plist)
1617 (mapc
1618 (lambda (cell)
1619 (setq plist
1620 (plist-put
1621 plist
1622 (car cell)
1623 ;; Eval default value provided. If keyword is a member
1624 ;; of `org-element-document-properties', parse it as
1625 ;; a secondary string before storing it.
1626 (let ((value (eval (nth 3 cell))))
1627 (if (not (stringp value)) value
1628 (let ((keyword (nth 1 cell)))
1629 (if (not (member keyword org-element-document-properties))
1630 value
1631 (org-element-parse-secondary-string
1632 value (org-element-restriction 'keyword)))))))))
1633 all)
1634 ;; Return value.
1635 plist))
1637 (defvar org-export--allow-BIND-local nil)
1638 (defun org-export--confirm-letbind ()
1639 "Can we use #+BIND values during export?
1640 By default this will ask for confirmation by the user, to divert
1641 possible security risks."
1642 (cond
1643 ((not org-export-allow-BIND) nil)
1644 ((eq org-export-allow-BIND t) t)
1645 ((local-variable-p 'org-export--allow-BIND-local)
1646 org-export--allow-BIND-local)
1647 (t (org-set-local 'org-export--allow-BIND-local
1648 (yes-or-no-p "Allow BIND values in this buffer? ")))))
1650 (defun org-export--install-letbind-maybe ()
1651 "Install the values from #+BIND lines as local variables.
1652 Variables must be installed before in-buffer options are
1653 retrieved."
1654 (let ((case-fold-search t) letbind pair)
1655 (org-with-wide-buffer
1656 (goto-char (point-min))
1657 (while (re-search-forward "^[ \t]*#\\+BIND:" nil t)
1658 (let* ((element (org-element-at-point))
1659 (value (org-element-property :value element)))
1660 (when (and (eq (org-element-type element) 'keyword)
1661 (not (equal value ""))
1662 (org-export--confirm-letbind))
1663 (push (read (format "(%s)" value)) letbind)))))
1664 (dolist (pair (nreverse letbind))
1665 (org-set-local (car pair) (nth 1 pair)))))
1668 ;;;; Tree Properties
1670 ;; Tree properties are information extracted from parse tree. They
1671 ;; are initialized at the beginning of the transcoding process by
1672 ;; `org-export-collect-tree-properties'.
1674 ;; Dedicated functions focus on computing the value of specific tree
1675 ;; properties during initialization. Thus,
1676 ;; `org-export--populate-ignore-list' lists elements and objects that
1677 ;; should be skipped during export, `org-export--get-min-level' gets
1678 ;; the minimal exportable level, used as a basis to compute relative
1679 ;; level for headlines. Eventually
1680 ;; `org-export--collect-headline-numbering' builds an alist between
1681 ;; headlines and their numbering.
1683 (defun org-export-collect-tree-properties (data info)
1684 "Extract tree properties from parse tree.
1686 DATA is the parse tree from which information is retrieved. INFO
1687 is a list holding export options.
1689 Following tree properties are set or updated:
1691 `:exported-data' Hash table used to memoize results from
1692 `org-export-data'.
1694 `:footnote-definition-alist' List of footnotes definitions in
1695 original buffer and current parse tree.
1697 `:headline-offset' Offset between true level of headlines and
1698 local level. An offset of -1 means an headline
1699 of level 2 should be considered as a level
1700 1 headline in the context.
1702 `:headline-numbering' Alist of all headlines as key an the
1703 associated numbering as value.
1705 `:ignore-list' List of elements that should be ignored during
1706 export.
1708 `:target-list' List of all targets in the parse tree.
1710 Return updated plist."
1711 ;; Install the parse tree in the communication channel, in order to
1712 ;; use `org-export-get-genealogy' and al.
1713 (setq info (plist-put info :parse-tree data))
1714 ;; Get the list of elements and objects to ignore, and put it into
1715 ;; `:ignore-list'. Do not overwrite any user ignore that might have
1716 ;; been done during parse tree filtering.
1717 (setq info
1718 (plist-put info
1719 :ignore-list
1720 (append (org-export--populate-ignore-list data info)
1721 (plist-get info :ignore-list))))
1722 ;; Compute `:headline-offset' in order to be able to use
1723 ;; `org-export-get-relative-level'.
1724 (setq info
1725 (plist-put info
1726 :headline-offset
1727 (- 1 (org-export--get-min-level data info))))
1728 ;; Update footnotes definitions list with definitions in parse tree.
1729 ;; This is required since buffer expansion might have modified
1730 ;; boundaries of footnote definitions contained in the parse tree.
1731 ;; This way, definitions in `footnote-definition-alist' are bound to
1732 ;; match those in the parse tree.
1733 (let ((defs (plist-get info :footnote-definition-alist)))
1734 (org-element-map
1735 data 'footnote-definition
1736 (lambda (fn)
1737 (push (cons (org-element-property :label fn)
1738 `(org-data nil ,@(org-element-contents fn)))
1739 defs)))
1740 (setq info (plist-put info :footnote-definition-alist defs)))
1741 ;; Properties order doesn't matter: get the rest of the tree
1742 ;; properties.
1743 (nconc
1744 `(:target-list
1745 ,(org-element-map
1746 data '(keyword target)
1747 (lambda (blob)
1748 (when (or (eq (org-element-type blob) 'target)
1749 (string= (org-element-property :key blob) "TARGET"))
1750 blob)) info)
1751 :headline-numbering ,(org-export--collect-headline-numbering data info)
1752 :exported-data ,(make-hash-table :test 'eq :size 4001))
1753 info))
1755 (defun org-export--get-min-level (data options)
1756 "Return minimum exportable headline's level in DATA.
1757 DATA is parsed tree as returned by `org-element-parse-buffer'.
1758 OPTIONS is a plist holding export options."
1759 (catch 'exit
1760 (let ((min-level 10000))
1761 (mapc
1762 (lambda (blob)
1763 (when (and (eq (org-element-type blob) 'headline)
1764 (not (memq blob (plist-get options :ignore-list))))
1765 (setq min-level
1766 (min (org-element-property :level blob) min-level)))
1767 (when (= min-level 1) (throw 'exit 1)))
1768 (org-element-contents data))
1769 ;; If no headline was found, for the sake of consistency, set
1770 ;; minimum level to 1 nonetheless.
1771 (if (= min-level 10000) 1 min-level))))
1773 (defun org-export--collect-headline-numbering (data options)
1774 "Return numbering of all exportable headlines in a parse tree.
1776 DATA is the parse tree. OPTIONS is the plist holding export
1777 options.
1779 Return an alist whose key is an headline and value is its
1780 associated numbering \(in the shape of a list of numbers\)."
1781 (let ((numbering (make-vector org-export-max-depth 0)))
1782 (org-element-map
1783 data
1784 'headline
1785 (lambda (headline)
1786 (let ((relative-level
1787 (1- (org-export-get-relative-level headline options))))
1788 (cons
1789 headline
1790 (loop for n across numbering
1791 for idx from 0 to org-export-max-depth
1792 when (< idx relative-level) collect n
1793 when (= idx relative-level) collect (aset numbering idx (1+ n))
1794 when (> idx relative-level) do (aset numbering idx 0)))))
1795 options)))
1797 (defun org-export--populate-ignore-list (data options)
1798 "Return list of elements and objects to ignore during export.
1799 DATA is the parse tree to traverse. OPTIONS is the plist holding
1800 export options."
1801 (let* (ignore
1802 walk-data
1803 ;; First find trees containing a select tag, if any.
1804 (selected (org-export--selected-trees data options))
1805 (walk-data
1806 (lambda (data)
1807 ;; Collect ignored elements or objects into IGNORE-LIST.
1808 (let ((type (org-element-type data)))
1809 (if (org-export--skip-p data options selected) (push data ignore)
1810 (if (and (eq type 'headline)
1811 (eq (plist-get options :with-archived-trees) 'headline)
1812 (org-element-property :archivedp data))
1813 ;; If headline is archived but tree below has
1814 ;; to be skipped, add it to ignore list.
1815 (mapc (lambda (e) (push e ignore))
1816 (org-element-contents data))
1817 ;; Move into secondary string, if any.
1818 (let ((sec-prop
1819 (cdr (assq type org-element-secondary-value-alist))))
1820 (when sec-prop
1821 (mapc walk-data (org-element-property sec-prop data))))
1822 ;; Move into recursive objects/elements.
1823 (mapc walk-data (org-element-contents data))))))))
1824 ;; Main call.
1825 (funcall walk-data data)
1826 ;; Return value.
1827 ignore))
1829 (defun org-export--selected-trees (data info)
1830 "Return list of headlines containing a select tag in their tree.
1831 DATA is parsed data as returned by `org-element-parse-buffer'.
1832 INFO is a plist holding export options."
1833 (let* (selected-trees
1834 walk-data ; for byte-compiler.
1835 (walk-data
1836 (function
1837 (lambda (data genealogy)
1838 (case (org-element-type data)
1839 (org-data (mapc (lambda (el) (funcall walk-data el genealogy))
1840 (org-element-contents data)))
1841 (headline
1842 (let ((tags (org-element-property :tags data)))
1843 (if (loop for tag in (plist-get info :select-tags)
1844 thereis (member tag tags))
1845 ;; When a select tag is found, mark full
1846 ;; genealogy and every headline within the tree
1847 ;; as acceptable.
1848 (setq selected-trees
1849 (append
1850 genealogy
1851 (org-element-map data 'headline 'identity)
1852 selected-trees))
1853 ;; Else, continue searching in tree, recursively.
1854 (mapc
1855 (lambda (el) (funcall walk-data el (cons data genealogy)))
1856 (org-element-contents data))))))))))
1857 (funcall walk-data data nil) selected-trees))
1859 (defun org-export--skip-p (blob options selected)
1860 "Non-nil when element or object BLOB should be skipped during export.
1861 OPTIONS is the plist holding export options. SELECTED, when
1862 non-nil, is a list of headlines belonging to a tree with a select
1863 tag."
1864 (case (org-element-type blob)
1865 (clock (not (plist-get options :with-clocks)))
1866 (drawer
1867 (or (not (plist-get options :with-drawers))
1868 (and (consp (plist-get options :with-drawers))
1869 (not (member (org-element-property :drawer-name blob)
1870 (plist-get options :with-drawers))))))
1871 (headline
1872 (let ((with-tasks (plist-get options :with-tasks))
1873 (todo (org-element-property :todo-keyword blob))
1874 (todo-type (org-element-property :todo-type blob))
1875 (archived (plist-get options :with-archived-trees))
1876 (tags (org-element-property :tags blob)))
1878 ;; Ignore subtrees with an exclude tag.
1879 (loop for k in (plist-get options :exclude-tags)
1880 thereis (member k tags))
1881 ;; When a select tag is present in the buffer, ignore any tree
1882 ;; without it.
1883 (and selected (not (memq blob selected)))
1884 ;; Ignore commented sub-trees.
1885 (org-element-property :commentedp blob)
1886 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
1887 (and (not archived) (org-element-property :archivedp blob))
1888 ;; Ignore tasks, if specified by `:with-tasks' property.
1889 (and todo
1890 (or (not with-tasks)
1891 (and (memq with-tasks '(todo done))
1892 (not (eq todo-type with-tasks)))
1893 (and (consp with-tasks) (not (member todo with-tasks))))))))
1894 (inlinetask (not (plist-get options :with-inlinetasks)))
1895 (planning (not (plist-get options :with-plannings)))
1896 (statistics-cookie (not (plist-get options :with-statistics-cookies)))
1897 (table-cell
1898 (and (org-export-table-has-special-column-p
1899 (org-export-get-parent-table blob))
1900 (not (org-export-get-previous-element blob options))))
1901 (table-row (org-export-table-row-is-special-p blob options))
1902 (timestamp
1903 (case (plist-get options :with-timestamps)
1904 ;; No timestamp allowed.
1905 ('nil t)
1906 ;; Only active timestamps allowed and the current one isn't
1907 ;; active.
1908 (active
1909 (not (memq (org-element-property :type blob)
1910 '(active active-range))))
1911 ;; Only inactive timestamps allowed and the current one isn't
1912 ;; inactive.
1913 (inactive
1914 (not (memq (org-element-property :type blob)
1915 '(inactive inactive-range))))))))
1919 ;;; The Transcoder
1921 ;; `org-export-data' reads a parse tree (obtained with, i.e.
1922 ;; `org-element-parse-buffer') and transcodes it into a specified
1923 ;; back-end output. It takes care of filtering out elements or
1924 ;; objects according to export options and organizing the output blank
1925 ;; lines and white space are preserved. The function memoizes its
1926 ;; results, so it is cheap to call it within translators.
1928 ;; It is possible to modify locally the back-end used by
1929 ;; `org-export-data' or even use a temporary back-end by using
1930 ;; `org-export-data-with-translations' and
1931 ;; `org-export-data-with-backend'.
1933 ;; Internally, three functions handle the filtering of objects and
1934 ;; elements during the export. In particular,
1935 ;; `org-export-ignore-element' marks an element or object so future
1936 ;; parse tree traversals skip it, `org-export--interpret-p' tells which
1937 ;; elements or objects should be seen as real Org syntax and
1938 ;; `org-export-expand' transforms the others back into their original
1939 ;; shape
1941 ;; `org-export-transcoder' is an accessor returning appropriate
1942 ;; translator function for a given element or object.
1944 (defun org-export-transcoder (blob info)
1945 "Return appropriate transcoder for BLOB.
1946 INFO is a plist containing export directives."
1947 (let ((type (org-element-type blob)))
1948 ;; Return contents only for complete parse trees.
1949 (if (eq type 'org-data) (lambda (blob contents info) contents)
1950 (let ((transcoder (cdr (assq type (plist-get info :translate-alist)))))
1951 (and (functionp transcoder) transcoder)))))
1953 (defun org-export-data (data info)
1954 "Convert DATA into current back-end format.
1956 DATA is a parse tree, an element or an object or a secondary
1957 string. INFO is a plist holding export options.
1959 Return transcoded string."
1960 (let ((memo (gethash data (plist-get info :exported-data) 'no-memo)))
1961 (if (not (eq memo 'no-memo)) memo
1962 (let* ((type (org-element-type data))
1963 (results
1964 (cond
1965 ;; Ignored element/object.
1966 ((memq data (plist-get info :ignore-list)) nil)
1967 ;; Plain text.
1968 ((eq type 'plain-text)
1969 (org-export-filter-apply-functions
1970 (plist-get info :filter-plain-text)
1971 (let ((transcoder (org-export-transcoder data info)))
1972 (if transcoder (funcall transcoder data info) data))
1973 info))
1974 ;; Uninterpreted element/object: change it back to Org
1975 ;; syntax and export again resulting raw string.
1976 ((not (org-export--interpret-p data info))
1977 (org-export-data
1978 (org-export-expand
1979 data
1980 (mapconcat (lambda (blob) (org-export-data blob info))
1981 (org-element-contents data)
1982 ""))
1983 info))
1984 ;; Secondary string.
1985 ((not type)
1986 (mapconcat (lambda (obj) (org-export-data obj info)) data ""))
1987 ;; Element/Object without contents or, as a special case,
1988 ;; headline with archive tag and archived trees restricted
1989 ;; to title only.
1990 ((or (not (org-element-contents data))
1991 (and (eq type 'headline)
1992 (eq (plist-get info :with-archived-trees) 'headline)
1993 (org-element-property :archivedp data)))
1994 (let ((transcoder (org-export-transcoder data info)))
1995 (and (functionp transcoder)
1996 (funcall transcoder data nil info))))
1997 ;; Element/Object with contents.
1999 (let ((transcoder (org-export-transcoder data info)))
2000 (when transcoder
2001 (let* ((greaterp (memq type org-element-greater-elements))
2002 (objectp
2003 (and (not greaterp)
2004 (memq type org-element-recursive-objects)))
2005 (contents
2006 (mapconcat
2007 (lambda (element) (org-export-data element info))
2008 (org-element-contents
2009 (if (or greaterp objectp) data
2010 ;; Elements directly containing objects
2011 ;; must have their indentation normalized
2012 ;; first.
2013 (org-element-normalize-contents
2014 data
2015 ;; When normalizing contents of the first
2016 ;; paragraph in an item or a footnote
2017 ;; definition, ignore first line's
2018 ;; indentation: there is none and it
2019 ;; might be misleading.
2020 (when (eq type 'paragraph)
2021 (let ((parent (org-export-get-parent data)))
2022 (and
2023 (eq (car (org-element-contents parent))
2024 data)
2025 (memq (org-element-type parent)
2026 '(footnote-definition item))))))))
2027 "")))
2028 (funcall transcoder data
2029 (if (not greaterp) contents
2030 (org-element-normalize-string contents))
2031 info))))))))
2032 ;; Final result will be memoized before being returned.
2033 (puthash
2034 data
2035 (cond
2036 ((not results) nil)
2037 ((memq type '(org-data plain-text nil)) results)
2038 ;; Append the same white space between elements or objects as in
2039 ;; the original buffer, and call appropriate filters.
2041 (let ((results
2042 (org-export-filter-apply-functions
2043 (plist-get info (intern (format ":filter-%s" type)))
2044 (let ((post-blank (or (org-element-property :post-blank data)
2045 0)))
2046 (if (memq type org-element-all-elements)
2047 (concat (org-element-normalize-string results)
2048 (make-string post-blank ?\n))
2049 (concat results (make-string post-blank ? ))))
2050 info)))
2051 results)))
2052 (plist-get info :exported-data))))))
2054 (defun org-export-data-with-translations (data translations info)
2055 "Convert DATA into another format using a given translation table.
2056 DATA is an element, an object, a secondary string or a string.
2057 TRANSLATIONS is an alist between element or object types and
2058 a functions handling them. See `org-export-define-backend' for
2059 more information. INFO is a plist used as a communication
2060 channel."
2061 (org-export-data
2062 data
2063 ;; Set-up a new communication channel with TRANSLATIONS as the
2064 ;; translate table and a new hash table for memoization.
2065 (org-combine-plists
2066 info
2067 (list :translate-alist translations
2068 ;; Size of the hash table is reduced since this function
2069 ;; will probably be used on short trees.
2070 :exported-data (make-hash-table :test 'eq :size 401)))))
2072 (defun org-export-data-with-backend (data backend info)
2073 "Convert DATA into BACKEND format.
2075 DATA is an element, an object, a secondary string or a string.
2076 BACKEND is a symbol. INFO is a plist used as a communication
2077 channel.
2079 Unlike to `org-export-with-backend', this function will
2080 recursively convert DATA using BACKEND translation table."
2081 (org-export-barf-if-invalid-backend backend)
2082 (org-export-data-with-translations
2083 data (org-export-backend-translate-table backend) info))
2085 (defun org-export--interpret-p (blob info)
2086 "Non-nil if element or object BLOB should be interpreted as Org syntax.
2087 Check is done according to export options INFO, stored as
2088 a plist."
2089 (case (org-element-type blob)
2090 ;; ... entities...
2091 (entity (plist-get info :with-entities))
2092 ;; ... emphasis...
2093 ((bold italic strike-through underline)
2094 (plist-get info :with-emphasize))
2095 ;; ... fixed-width areas.
2096 (fixed-width (plist-get info :with-fixed-width))
2097 ;; ... footnotes...
2098 ((footnote-definition footnote-reference)
2099 (plist-get info :with-footnotes))
2100 ;; ... sub/superscripts...
2101 ((subscript superscript)
2102 (let ((sub/super-p (plist-get info :with-sub-superscript)))
2103 (if (eq sub/super-p '{})
2104 (org-element-property :use-brackets-p blob)
2105 sub/super-p)))
2106 ;; ... tables...
2107 (table (plist-get info :with-tables))
2108 (otherwise t)))
2110 (defun org-export-expand (blob contents)
2111 "Expand a parsed element or object to its original state.
2112 BLOB is either an element or an object. CONTENTS is its
2113 contents, as a string or nil."
2114 (funcall
2115 (intern (format "org-element-%s-interpreter" (org-element-type blob)))
2116 blob contents))
2118 (defun org-export-ignore-element (element info)
2119 "Add ELEMENT to `:ignore-list' in INFO.
2121 Any element in `:ignore-list' will be skipped when using
2122 `org-element-map'. INFO is modified by side effects."
2123 (plist-put info :ignore-list (cons element (plist-get info :ignore-list))))
2127 ;;; The Filter System
2129 ;; Filters allow end-users to tweak easily the transcoded output.
2130 ;; They are the functional counterpart of hooks, as every filter in
2131 ;; a set is applied to the return value of the previous one.
2133 ;; Every set is back-end agnostic. Although, a filter is always
2134 ;; called, in addition to the string it applies to, with the back-end
2135 ;; used as argument, so it's easy for the end-user to add back-end
2136 ;; specific filters in the set. The communication channel, as
2137 ;; a plist, is required as the third argument.
2139 ;; From the developer side, filters sets can be installed in the
2140 ;; process with the help of `org-export-define-backend', which
2141 ;; internally stores filters as an alist. Each association has a key
2142 ;; among the following symbols and a function or a list of functions
2143 ;; as value.
2145 ;; - `:filter-parse-tree' applies directly on the complete parsed
2146 ;; tree. It's the only filters set that doesn't apply to a string.
2147 ;; Users can set it through `org-export-filter-parse-tree-functions'
2148 ;; variable.
2150 ;; - `:filter-final-output' applies to the final transcoded string.
2151 ;; Users can set it with `org-export-filter-final-output-functions'
2152 ;; variable
2154 ;; - `:filter-plain-text' applies to any string not recognized as Org
2155 ;; syntax. `org-export-filter-plain-text-functions' allows users to
2156 ;; configure it.
2158 ;; - `:filter-TYPE' applies on the string returned after an element or
2159 ;; object of type TYPE has been transcoded. An user can modify
2160 ;; `org-export-filter-TYPE-functions'
2162 ;; All filters sets are applied with
2163 ;; `org-export-filter-apply-functions' function. Filters in a set are
2164 ;; applied in a LIFO fashion. It allows developers to be sure that
2165 ;; their filters will be applied first.
2167 ;; Filters properties are installed in communication channel with
2168 ;; `org-export-install-filters' function.
2170 ;; Eventually, two hooks (`org-export-before-processing-hook' and
2171 ;; `org-export-before-parsing-hook') are run at the beginning of the
2172 ;; export process and just before parsing to allow for heavy structure
2173 ;; modifications.
2176 ;;;; Hooks
2178 (defvar org-export-before-processing-hook nil
2179 "Hook run at the beginning of the export process.
2181 This is run before include keywords and macros are expanded and
2182 Babel code blocks executed, on a copy of the original buffer
2183 being exported. Visibility and narrowing are preserved. Point
2184 is at the beginning of the buffer.
2186 Every function in this hook will be called with one argument: the
2187 back-end currently used, as a symbol.")
2189 (defvar org-export-before-parsing-hook nil
2190 "Hook run before parsing an export buffer.
2192 This is run after include keywords and macros have been expanded
2193 and Babel code blocks executed, on a copy of the original buffer
2194 being exported. Visibility and narrowing are preserved. Point
2195 is at the beginning of the buffer.
2197 Every function in this hook will be called with one argument: the
2198 back-end currently used, as a symbol.")
2201 ;;;; Special Filters
2203 (defvar org-export-filter-parse-tree-functions nil
2204 "List of functions applied to the parsed tree.
2205 Each filter is called with three arguments: the parse tree, as
2206 returned by `org-element-parse-buffer', the back-end, as
2207 a symbol, and the communication channel, as a plist. It must
2208 return the modified parse tree to transcode.")
2210 (defvar org-export-filter-final-output-functions nil
2211 "List of functions applied to the transcoded string.
2212 Each filter is called with three arguments: the full transcoded
2213 string, the back-end, as a symbol, and the communication channel,
2214 as a plist. It must return a string that will be used as the
2215 final export output.")
2217 (defvar org-export-filter-plain-text-functions nil
2218 "List of functions applied to plain text.
2219 Each filter is called with three arguments: a string which
2220 contains no Org syntax, the back-end, as a symbol, and the
2221 communication channel, as a plist. It must return a string or
2222 nil.")
2225 ;;;; Elements Filters
2227 (defvar org-export-filter-babel-call-functions nil
2228 "List of functions applied to a transcoded babel-call.
2229 Each filter is called with three arguments: the transcoded data,
2230 as a string, the back-end, as a symbol, and the communication
2231 channel, as a plist. It must return a string or nil.")
2233 (defvar org-export-filter-center-block-functions nil
2234 "List of functions applied to a transcoded center block.
2235 Each filter is called with three arguments: the transcoded data,
2236 as a string, the back-end, as a symbol, and the communication
2237 channel, as a plist. It must return a string or nil.")
2239 (defvar org-export-filter-clock-functions nil
2240 "List of functions applied to a transcoded clock.
2241 Each filter is called with three arguments: the transcoded data,
2242 as a string, the back-end, as a symbol, and the communication
2243 channel, as a plist. It must return a string or nil.")
2245 (defvar org-export-filter-comment-functions nil
2246 "List of functions applied to a transcoded comment.
2247 Each filter is called with three arguments: the transcoded data,
2248 as a string, the back-end, as a symbol, and the communication
2249 channel, as a plist. It must return a string or nil.")
2251 (defvar org-export-filter-comment-block-functions nil
2252 "List of functions applied to a transcoded comment-block.
2253 Each filter is called with three arguments: the transcoded data,
2254 as a string, the back-end, as a symbol, and the communication
2255 channel, as a plist. It must return a string or nil.")
2257 (defvar org-export-filter-diary-sexp-functions nil
2258 "List of functions applied to a transcoded diary-sexp.
2259 Each filter is called with three arguments: the transcoded data,
2260 as a string, the back-end, as a symbol, and the communication
2261 channel, as a plist. It must return a string or nil.")
2263 (defvar org-export-filter-drawer-functions nil
2264 "List of functions applied to a transcoded drawer.
2265 Each filter is called with three arguments: the transcoded data,
2266 as a string, the back-end, as a symbol, and the communication
2267 channel, as a plist. It must return a string or nil.")
2269 (defvar org-export-filter-dynamic-block-functions nil
2270 "List of functions applied to a transcoded dynamic-block.
2271 Each filter is called with three arguments: the transcoded data,
2272 as a string, the back-end, as a symbol, and the communication
2273 channel, as a plist. It must return a string or nil.")
2275 (defvar org-export-filter-example-block-functions nil
2276 "List of functions applied to a transcoded example-block.
2277 Each filter is called with three arguments: the transcoded data,
2278 as a string, the back-end, as a symbol, and the communication
2279 channel, as a plist. It must return a string or nil.")
2281 (defvar org-export-filter-export-block-functions nil
2282 "List of functions applied to a transcoded export-block.
2283 Each filter is called with three arguments: the transcoded data,
2284 as a string, the back-end, as a symbol, and the communication
2285 channel, as a plist. It must return a string or nil.")
2287 (defvar org-export-filter-fixed-width-functions nil
2288 "List of functions applied to a transcoded fixed-width.
2289 Each filter is called with three arguments: the transcoded data,
2290 as a string, the back-end, as a symbol, and the communication
2291 channel, as a plist. It must return a string or nil.")
2293 (defvar org-export-filter-footnote-definition-functions nil
2294 "List of functions applied to a transcoded footnote-definition.
2295 Each filter is called with three arguments: the transcoded data,
2296 as a string, the back-end, as a symbol, and the communication
2297 channel, as a plist. It must return a string or nil.")
2299 (defvar org-export-filter-headline-functions nil
2300 "List of functions applied to a transcoded headline.
2301 Each filter is called with three arguments: the transcoded data,
2302 as a string, the back-end, as a symbol, and the communication
2303 channel, as a plist. It must return a string or nil.")
2305 (defvar org-export-filter-horizontal-rule-functions nil
2306 "List of functions applied to a transcoded horizontal-rule.
2307 Each filter is called with three arguments: the transcoded data,
2308 as a string, the back-end, as a symbol, and the communication
2309 channel, as a plist. It must return a string or nil.")
2311 (defvar org-export-filter-inlinetask-functions nil
2312 "List of functions applied to a transcoded inlinetask.
2313 Each filter is called with three arguments: the transcoded data,
2314 as a string, the back-end, as a symbol, and the communication
2315 channel, as a plist. It must return a string or nil.")
2317 (defvar org-export-filter-item-functions nil
2318 "List of functions applied to a transcoded item.
2319 Each filter is called with three arguments: the transcoded data,
2320 as a string, the back-end, as a symbol, and the communication
2321 channel, as a plist. It must return a string or nil.")
2323 (defvar org-export-filter-keyword-functions nil
2324 "List of functions applied to a transcoded keyword.
2325 Each filter is called with three arguments: the transcoded data,
2326 as a string, the back-end, as a symbol, and the communication
2327 channel, as a plist. It must return a string or nil.")
2329 (defvar org-export-filter-latex-environment-functions nil
2330 "List of functions applied to a transcoded latex-environment.
2331 Each filter is called with three arguments: the transcoded data,
2332 as a string, the back-end, as a symbol, and the communication
2333 channel, as a plist. It must return a string or nil.")
2335 (defvar org-export-filter-node-property-functions nil
2336 "List of functions applied to a transcoded node-property.
2337 Each filter is called with three arguments: the transcoded data,
2338 as a string, the back-end, as a symbol, and the communication
2339 channel, as a plist. It must return a string or nil.")
2341 (defvar org-export-filter-paragraph-functions nil
2342 "List of functions applied to a transcoded paragraph.
2343 Each filter is called with three arguments: the transcoded data,
2344 as a string, the back-end, as a symbol, and the communication
2345 channel, as a plist. It must return a string or nil.")
2347 (defvar org-export-filter-plain-list-functions nil
2348 "List of functions applied to a transcoded plain-list.
2349 Each filter is called with three arguments: the transcoded data,
2350 as a string, the back-end, as a symbol, and the communication
2351 channel, as a plist. It must return a string or nil.")
2353 (defvar org-export-filter-planning-functions nil
2354 "List of functions applied to a transcoded planning.
2355 Each filter is called with three arguments: the transcoded data,
2356 as a string, the back-end, as a symbol, and the communication
2357 channel, as a plist. It must return a string or nil.")
2359 (defvar org-export-filter-property-drawer-functions nil
2360 "List of functions applied to a transcoded property-drawer.
2361 Each filter is called with three arguments: the transcoded data,
2362 as a string, the back-end, as a symbol, and the communication
2363 channel, as a plist. It must return a string or nil.")
2365 (defvar org-export-filter-quote-block-functions nil
2366 "List of functions applied to a transcoded quote block.
2367 Each filter is called with three arguments: the transcoded quote
2368 data, as a string, the back-end, as a symbol, and the
2369 communication channel, as a plist. It must return a string or
2370 nil.")
2372 (defvar org-export-filter-quote-section-functions nil
2373 "List of functions applied to a transcoded quote-section.
2374 Each filter is called with three arguments: the transcoded data,
2375 as a string, the back-end, as a symbol, and the communication
2376 channel, as a plist. It must return a string or nil.")
2378 (defvar org-export-filter-section-functions nil
2379 "List of functions applied to a transcoded section.
2380 Each filter is called with three arguments: the transcoded data,
2381 as a string, the back-end, as a symbol, and the communication
2382 channel, as a plist. It must return a string or nil.")
2384 (defvar org-export-filter-special-block-functions nil
2385 "List of functions applied to a transcoded special block.
2386 Each filter is called with three arguments: the transcoded data,
2387 as a string, the back-end, as a symbol, and the communication
2388 channel, as a plist. It must return a string or nil.")
2390 (defvar org-export-filter-src-block-functions nil
2391 "List of functions applied to a transcoded src-block.
2392 Each filter is called with three arguments: the transcoded data,
2393 as a string, the back-end, as a symbol, and the communication
2394 channel, as a plist. It must return a string or nil.")
2396 (defvar org-export-filter-table-functions nil
2397 "List of functions applied to a transcoded table.
2398 Each filter is called with three arguments: the transcoded data,
2399 as a string, the back-end, as a symbol, and the communication
2400 channel, as a plist. It must return a string or nil.")
2402 (defvar org-export-filter-table-cell-functions nil
2403 "List of functions applied to a transcoded table-cell.
2404 Each filter is called with three arguments: the transcoded data,
2405 as a string, the back-end, as a symbol, and the communication
2406 channel, as a plist. It must return a string or nil.")
2408 (defvar org-export-filter-table-row-functions nil
2409 "List of functions applied to a transcoded table-row.
2410 Each filter is called with three arguments: the transcoded data,
2411 as a string, the back-end, as a symbol, and the communication
2412 channel, as a plist. It must return a string or nil.")
2414 (defvar org-export-filter-verse-block-functions nil
2415 "List of functions applied to a transcoded verse block.
2416 Each filter is called with three arguments: the transcoded data,
2417 as a string, the back-end, as a symbol, and the communication
2418 channel, as a plist. It must return a string or nil.")
2421 ;;;; Objects Filters
2423 (defvar org-export-filter-bold-functions nil
2424 "List of functions applied to transcoded bold text.
2425 Each filter is called with three arguments: the transcoded data,
2426 as a string, the back-end, as a symbol, and the communication
2427 channel, as a plist. It must return a string or nil.")
2429 (defvar org-export-filter-code-functions nil
2430 "List of functions applied to transcoded code text.
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-entity-functions nil
2436 "List of functions applied to a transcoded entity.
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-export-snippet-functions nil
2442 "List of functions applied to a transcoded export-snippet.
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-footnote-reference-functions nil
2448 "List of functions applied to a transcoded footnote-reference.
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-inline-babel-call-functions nil
2454 "List of functions applied to a transcoded inline-babel-call.
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-inline-src-block-functions nil
2460 "List of functions applied to a transcoded inline-src-block.
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-italic-functions nil
2466 "List of functions applied to transcoded italic text.
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-latex-fragment-functions nil
2472 "List of functions applied to a transcoded latex-fragment.
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-line-break-functions nil
2478 "List of functions applied to a transcoded line-break.
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-link-functions nil
2484 "List of functions applied to a transcoded link.
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-macro-functions nil
2490 "List of functions applied to a transcoded macro.
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-radio-target-functions nil
2496 "List of functions applied to a transcoded radio-target.
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-statistics-cookie-functions nil
2502 "List of functions applied to a transcoded statistics-cookie.
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-strike-through-functions nil
2508 "List of functions applied to transcoded strike-through text.
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-subscript-functions nil
2514 "List of functions applied to a transcoded subscript.
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-superscript-functions nil
2520 "List of functions applied to a transcoded superscript.
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-target-functions nil
2526 "List of functions applied to a transcoded target.
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-timestamp-functions nil
2532 "List of functions applied to a transcoded timestamp.
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-underline-functions nil
2538 "List of functions applied to transcoded underline text.
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-verbatim-functions nil
2544 "List of functions applied to transcoded verbatim text.
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.")
2550 ;;;; Filters Tools
2552 ;; Internal function `org-export-install-filters' installs filters
2553 ;; hard-coded in back-ends (developer filters) and filters from global
2554 ;; variables (user filters) in the communication channel.
2556 ;; Internal function `org-export-filter-apply-functions' takes care
2557 ;; about applying each filter in order to a given data. It ignores
2558 ;; filters returning a nil value but stops whenever a filter returns
2559 ;; an empty string.
2561 (defun org-export-filter-apply-functions (filters value info)
2562 "Call every function in FILTERS.
2564 Functions are called with arguments VALUE, current export
2565 back-end and INFO. A function returning a nil value will be
2566 skipped. If it returns the empty string, the process ends and
2567 VALUE is ignored.
2569 Call is done in a LIFO fashion, to be sure that developer
2570 specified filters, if any, are called first."
2571 (catch 'exit
2572 (dolist (filter filters value)
2573 (let ((result (funcall filter value (plist-get info :back-end) info)))
2574 (cond ((not result) value)
2575 ((equal value "") (throw 'exit nil))
2576 (t (setq value result)))))))
2578 (defun org-export-install-filters (info)
2579 "Install filters properties in communication channel.
2581 INFO is a plist containing the current communication channel.
2583 Return the updated communication channel."
2584 (let (plist)
2585 ;; Install user defined filters with `org-export-filters-alist'.
2586 (mapc (lambda (p)
2587 (setq plist (plist-put plist (car p) (eval (cdr p)))))
2588 org-export-filters-alist)
2589 ;; Prepend back-end specific filters to that list.
2590 (mapc (lambda (p)
2591 ;; Single values get consed, lists are prepended.
2592 (let ((key (car p)) (value (cdr p)))
2593 (when value
2594 (setq plist
2595 (plist-put
2596 plist key
2597 (if (atom value) (cons value (plist-get plist key))
2598 (append value (plist-get plist key))))))))
2599 (org-export-backend-filters (plist-get info :back-end)))
2600 ;; Return new communication channel.
2601 (org-combine-plists info plist)))
2605 ;;; Core functions
2607 ;; This is the room for the main function, `org-export-as', along with
2608 ;; its derivatives, `org-export-to-buffer' and `org-export-to-file'.
2609 ;; They differ only by the way they output the resulting code.
2611 ;; `org-export-output-file-name' is an auxiliary function meant to be
2612 ;; used with `org-export-to-file'. With a given extension, it tries
2613 ;; to provide a canonical file name to write export output to.
2615 ;; Note that `org-export-as' doesn't really parse the current buffer,
2616 ;; but a copy of it (with the same buffer-local variables and
2617 ;; visibility), where macros and include keywords are expanded and
2618 ;; Babel blocks are executed, if appropriate.
2619 ;; `org-export-with-buffer-copy' macro prepares that copy.
2621 ;; File inclusion is taken care of by
2622 ;; `org-export-expand-include-keyword' and
2623 ;; `org-export--prepare-file-contents'. Structure wise, including
2624 ;; a whole Org file in a buffer often makes little sense. For
2625 ;; example, if the file contains an headline and the include keyword
2626 ;; was within an item, the item should contain the headline. That's
2627 ;; why file inclusion should be done before any structure can be
2628 ;; associated to the file, that is before parsing.
2630 (defun org-export-as
2631 (backend &optional subtreep visible-only body-only ext-plist)
2632 "Transcode current Org buffer into BACKEND code.
2634 If narrowing is active in the current buffer, only transcode its
2635 narrowed part.
2637 If a region is active, transcode that region.
2639 When optional argument SUBTREEP is non-nil, transcode the
2640 sub-tree at point, extracting information from the headline
2641 properties first.
2643 When optional argument VISIBLE-ONLY is non-nil, don't export
2644 contents of hidden elements.
2646 When optional argument BODY-ONLY is non-nil, only return body
2647 code, without preamble nor postamble.
2649 Optional argument EXT-PLIST, when provided, is a property list
2650 with external parameters overriding Org default settings, but
2651 still inferior to file-local settings.
2653 Return code as a string."
2654 ;; Barf if BACKEND isn't registered.
2655 (org-export-barf-if-invalid-backend backend)
2656 (save-excursion
2657 (save-restriction
2658 ;; Narrow buffer to an appropriate region or subtree for
2659 ;; parsing. If parsing subtree, be sure to remove main headline
2660 ;; too.
2661 (cond ((org-region-active-p)
2662 (narrow-to-region (region-beginning) (region-end)))
2663 (subtreep
2664 (org-narrow-to-subtree)
2665 (goto-char (point-min))
2666 (forward-line)
2667 (narrow-to-region (point) (point-max))))
2668 ;; Initialize communication channel with original buffer
2669 ;; attributes, unavailable in its copy.
2670 (let ((info (org-export--get-buffer-attributes)) tree)
2671 ;; Update communication channel and get parse tree. Buffer
2672 ;; isn't parsed directly. Instead, a temporary copy is
2673 ;; created, where include keywords, macros are expanded and
2674 ;; code blocks are evaluated.
2675 (org-export-with-buffer-copy
2676 ;; Run first hook with current back-end as argument.
2677 (run-hook-with-args 'org-export-before-processing-hook backend)
2678 (org-export-expand-include-keyword)
2679 ;; Update macro templates since #+INCLUDE keywords might have
2680 ;; added some new ones.
2681 (org-macro-initialize-templates)
2682 (org-macro-replace-all org-macro-templates)
2683 (org-export-execute-babel-code)
2684 ;; Update radio targets since keyword inclusion might have
2685 ;; added some more.
2686 (org-update-radio-target-regexp)
2687 ;; Run last hook with current back-end as argument.
2688 (goto-char (point-min))
2689 (run-hook-with-args 'org-export-before-parsing-hook backend)
2690 ;; Update communication channel with environment. Also
2691 ;; install user's and developer's filters.
2692 (setq info
2693 (org-export-install-filters
2694 (org-combine-plists
2695 info (org-export-get-environment backend subtreep ext-plist))))
2696 ;; Expand export-specific set of macros: {{{author}}},
2697 ;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done
2698 ;; once regular macros have been expanded, since document
2699 ;; keywords may contain one of them.
2700 (org-macro-replace-all
2701 (list (cons "author"
2702 (org-element-interpret-data (plist-get info :author)))
2703 (cons "date"
2704 (org-element-interpret-data (plist-get info :date)))
2705 ;; EMAIL is not a parsed keyword: store it as-is.
2706 (cons "email" (or (plist-get info :email) ""))
2707 (cons "title"
2708 (org-element-interpret-data (plist-get info :title)))))
2709 ;; Eventually parse buffer. Call parse-tree filters to get
2710 ;; the final tree.
2711 (setq tree
2712 (org-export-filter-apply-functions
2713 (plist-get info :filter-parse-tree)
2714 (org-element-parse-buffer nil visible-only) info)))
2715 ;; Now tree is complete, compute its properties and add them
2716 ;; to communication channel.
2717 (setq info
2718 (org-combine-plists
2719 info (org-export-collect-tree-properties tree info)))
2720 ;; Eventually transcode TREE. Wrap the resulting string into
2721 ;; a template, if required. Finally call final-output filter.
2722 (let* ((body (org-element-normalize-string
2723 (or (org-export-data tree info) "")))
2724 (template (cdr (assq 'template
2725 (plist-get info :translate-alist))))
2726 ;; Remove all text properties since they cannot be
2727 ;; retrieved from an external process.
2728 (output (org-no-properties
2729 (org-export-filter-apply-functions
2730 (plist-get info :filter-final-output)
2731 (if (or (not (functionp template)) body-only) body
2732 (funcall template body info))
2733 info))))
2734 ;; Maybe add final OUTPUT to kill ring, then return it.
2735 (when (and org-export-copy-to-kill-ring (org-string-nw-p output))
2736 (org-kill-new output))
2737 output)))))
2739 (defun org-export-to-buffer
2740 (backend buffer &optional subtreep visible-only body-only ext-plist)
2741 "Call `org-export-as' with output to a specified buffer.
2743 BACKEND is the back-end used for transcoding, as a symbol.
2745 BUFFER is the output buffer. If it already exists, it will be
2746 erased first, otherwise, it will be created.
2748 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
2749 EXT-PLIST are similar to those used in `org-export-as', which
2750 see.
2752 Return buffer."
2753 (let ((out (org-export-as backend subtreep visible-only body-only ext-plist))
2754 (buffer (get-buffer-create buffer)))
2755 (with-current-buffer buffer
2756 (erase-buffer)
2757 (insert out)
2758 (goto-char (point-min)))
2759 buffer))
2761 (defun org-export-to-file
2762 (backend file &optional subtreep visible-only body-only ext-plist)
2763 "Call `org-export-as' with output to a specified file.
2765 BACKEND is the back-end used for transcoding, as a symbol. FILE
2766 is the name of the output file, as a string.
2768 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
2769 EXT-PLIST are similar to those used in `org-export-as', which
2770 see.
2772 Return output file's name."
2773 ;; Checks for FILE permissions. `write-file' would do the same, but
2774 ;; we'd rather avoid needless transcoding of parse tree.
2775 (unless (file-writable-p file) (error "Output file not writable"))
2776 ;; Insert contents to a temporary buffer and write it to FILE.
2777 (let ((out (org-export-as backend subtreep visible-only body-only ext-plist)))
2778 (with-temp-buffer
2779 (insert out)
2780 (let ((coding-system-for-write org-export-coding-system))
2781 (write-file file))))
2782 ;; Return full path.
2783 file)
2785 (defun org-export-output-file-name (extension &optional subtreep pub-dir)
2786 "Return output file's name according to buffer specifications.
2788 EXTENSION is a string representing the output file extension,
2789 with the leading dot.
2791 With a non-nil optional argument SUBTREEP, try to determine
2792 output file's name by looking for \"EXPORT_FILE_NAME\" property
2793 of subtree at point.
2795 When optional argument PUB-DIR is set, use it as the publishing
2796 directory.
2798 When optional argument VISIBLE-ONLY is non-nil, don't export
2799 contents of hidden elements.
2801 Return file name as a string, or nil if it couldn't be
2802 determined."
2803 (let ((base-name
2804 ;; File name may come from EXPORT_FILE_NAME subtree property,
2805 ;; assuming point is at beginning of said sub-tree.
2806 (file-name-sans-extension
2807 (or (and subtreep
2808 (org-entry-get
2809 (save-excursion
2810 (ignore-errors (org-back-to-heading) (point)))
2811 "EXPORT_FILE_NAME" t))
2812 ;; File name may be extracted from buffer's associated
2813 ;; file, if any.
2814 (let ((visited-file (buffer-file-name (buffer-base-buffer))))
2815 (and visited-file (file-name-nondirectory visited-file)))
2816 ;; Can't determine file name on our own: Ask user.
2817 (let ((read-file-name-function
2818 (and org-completion-use-ido 'ido-read-file-name)))
2819 (read-file-name
2820 "Output file: " pub-dir nil nil nil
2821 (lambda (name)
2822 (string= (file-name-extension name t) extension))))))))
2823 ;; Build file name. Enforce EXTENSION over whatever user may have
2824 ;; come up with. PUB-DIR, if defined, always has precedence over
2825 ;; any provided path.
2826 (cond
2827 (pub-dir
2828 (concat (file-name-as-directory pub-dir)
2829 (file-name-nondirectory base-name)
2830 extension))
2831 ((file-name-absolute-p base-name) (concat base-name extension))
2832 (t (concat (file-name-as-directory ".") base-name extension)))))
2834 (defun org-export-copy-buffer ()
2835 "Return a copy of the current buffer.
2836 The copy preserves Org buffer-local variables, visibility and
2837 narrowing."
2838 (let ((copy-buffer-fun (org-export--generate-copy-script (current-buffer)))
2839 (new-buf (generate-new-buffer (buffer-name))))
2840 (with-current-buffer new-buf
2841 (funcall copy-buffer-fun)
2842 (set-buffer-modified-p nil))
2843 new-buf))
2845 (defmacro org-export-with-buffer-copy (&rest body)
2846 "Apply BODY in a copy of the current buffer.
2847 The copy preserves local variables, visibility and contents of
2848 the original buffer. Point is at the beginning of the buffer
2849 when BODY is applied."
2850 (declare (debug t))
2851 (org-with-gensyms (buf-copy)
2852 `(let ((,buf-copy (org-export-copy-buffer)))
2853 (unwind-protect
2854 (with-current-buffer ,buf-copy
2855 (goto-char (point-min))
2856 (progn ,@body))
2857 (and (buffer-live-p ,buf-copy)
2858 ;; Kill copy without confirmation.
2859 (progn (with-current-buffer ,buf-copy
2860 (restore-buffer-modified-p nil))
2861 (kill-buffer ,buf-copy)))))))
2863 (defun org-export--generate-copy-script (buffer)
2864 "Generate a function duplicating BUFFER.
2866 The copy will preserve local variables, visibility, contents and
2867 narrowing of the original buffer. If a region was active in
2868 BUFFER, contents will be narrowed to that region instead.
2870 The resulting function can be eval'ed at a later time, from
2871 another buffer, effectively cloning the original buffer there."
2872 (with-current-buffer buffer
2873 `(lambda ()
2874 (let ((inhibit-modification-hooks t))
2875 ;; Buffer local variables.
2876 ,@(let (local-vars)
2877 (mapc
2878 (lambda (entry)
2879 (when (consp entry)
2880 (let ((var (car entry))
2881 (val (cdr entry)))
2882 (and (not (eq var 'org-font-lock-keywords))
2883 (or (memq var
2884 '(major-mode default-directory
2885 buffer-file-name outline-level
2886 outline-regexp
2887 buffer-invisibility-spec))
2888 (string-match "^\\(org-\\|orgtbl-\\)"
2889 (symbol-name var)))
2890 ;; Skip unreadable values, as they cannot be
2891 ;; sent to external process.
2892 (or (not val) (ignore-errors (read (format "%S" val))))
2893 (push `(set (make-local-variable (quote ,var))
2894 (quote ,val))
2895 local-vars)))))
2896 (buffer-local-variables (buffer-base-buffer)))
2897 local-vars)
2898 ;; Whole buffer contents.
2899 (insert
2900 ,(org-with-wide-buffer
2901 (buffer-substring-no-properties
2902 (point-min) (point-max))))
2903 ;; Narrowing.
2904 ,(if (org-region-active-p)
2905 `(narrow-to-region ,(region-beginning) ,(region-end))
2906 `(narrow-to-region ,(point-min) ,(point-max)))
2907 ;; Current position of point.
2908 (goto-char ,(point))
2909 ;; Overlays with invisible property.
2910 ,@(let (ov-set)
2911 (mapc
2912 (lambda (ov)
2913 (let ((invis-prop (overlay-get ov 'invisible)))
2914 (when invis-prop
2915 (push `(overlay-put
2916 (make-overlay ,(overlay-start ov)
2917 ,(overlay-end ov))
2918 'invisible (quote ,invis-prop))
2919 ov-set))))
2920 (overlays-in (point-min) (point-max)))
2921 ov-set)))))
2923 (defun org-export-expand-include-keyword (&optional included dir)
2924 "Expand every include keyword in buffer.
2925 Optional argument INCLUDED is a list of included file names along
2926 with their line restriction, when appropriate. It is used to
2927 avoid infinite recursion. Optional argument DIR is the current
2928 working directory. It is used to properly resolve relative
2929 paths."
2930 (let ((case-fold-search t))
2931 (goto-char (point-min))
2932 (while (re-search-forward "^[ \t]*#\\+INCLUDE: +\\(.*\\)[ \t]*$" nil t)
2933 (when (eq (org-element-type (save-match-data (org-element-at-point)))
2934 'keyword)
2935 (beginning-of-line)
2936 ;; Extract arguments from keyword's value.
2937 (let* ((value (match-string 1))
2938 (ind (org-get-indentation))
2939 (file (and (string-match "^\"\\(\\S-+\\)\"" value)
2940 (prog1 (expand-file-name (match-string 1 value) dir)
2941 (setq value (replace-match "" nil nil value)))))
2942 (lines
2943 (and (string-match
2944 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\"" value)
2945 (prog1 (match-string 1 value)
2946 (setq value (replace-match "" nil nil value)))))
2947 (env (cond ((string-match "\\<example\\>" value) 'example)
2948 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
2949 (match-string 1 value))))
2950 ;; Minimal level of included file defaults to the child
2951 ;; level of the current headline, if any, or one. It
2952 ;; only applies is the file is meant to be included as
2953 ;; an Org one.
2954 (minlevel
2955 (and (not env)
2956 (if (string-match ":minlevel +\\([0-9]+\\)" value)
2957 (prog1 (string-to-number (match-string 1 value))
2958 (setq value (replace-match "" nil nil value)))
2959 (let ((cur (org-current-level)))
2960 (if cur (1+ (org-reduced-level cur)) 1))))))
2961 ;; Remove keyword.
2962 (delete-region (point) (progn (forward-line) (point)))
2963 (cond
2964 ((not file) (error "Invalid syntax in INCLUDE keyword"))
2965 ((not (file-readable-p file)) (error "Cannot include file %s" file))
2966 ;; Check if files has already been parsed. Look after
2967 ;; inclusion lines too, as different parts of the same file
2968 ;; can be included too.
2969 ((member (list file lines) included)
2970 (error "Recursive file inclusion: %s" file))
2972 (cond
2973 ((eq env 'example)
2974 (insert
2975 (let ((ind-str (make-string ind ? ))
2976 (contents
2977 (org-escape-code-in-string
2978 (org-export--prepare-file-contents file lines))))
2979 (format "%s#+BEGIN_EXAMPLE\n%s%s#+END_EXAMPLE\n"
2980 ind-str contents ind-str))))
2981 ((stringp env)
2982 (insert
2983 (let ((ind-str (make-string ind ? ))
2984 (contents
2985 (org-escape-code-in-string
2986 (org-export--prepare-file-contents file lines))))
2987 (format "%s#+BEGIN_SRC %s\n%s%s#+END_SRC\n"
2988 ind-str env contents ind-str))))
2990 (insert
2991 (with-temp-buffer
2992 (org-mode)
2993 (insert
2994 (org-export--prepare-file-contents file lines ind minlevel))
2995 (org-export-expand-include-keyword
2996 (cons (list file lines) included)
2997 (file-name-directory file))
2998 (buffer-string))))))))))))
3000 (defun org-export--prepare-file-contents (file &optional lines ind minlevel)
3001 "Prepare the contents of FILE for inclusion and return them as a string.
3003 When optional argument LINES is a string specifying a range of
3004 lines, include only those lines.
3006 Optional argument IND, when non-nil, is an integer specifying the
3007 global indentation of returned contents. Since its purpose is to
3008 allow an included file to stay in the same environment it was
3009 created \(i.e. a list item), it doesn't apply past the first
3010 headline encountered.
3012 Optional argument MINLEVEL, when non-nil, is an integer
3013 specifying the level that any top-level headline in the included
3014 file should have."
3015 (with-temp-buffer
3016 (insert-file-contents file)
3017 (when lines
3018 (let* ((lines (split-string lines "-"))
3019 (lbeg (string-to-number (car lines)))
3020 (lend (string-to-number (cadr lines)))
3021 (beg (if (zerop lbeg) (point-min)
3022 (goto-char (point-min))
3023 (forward-line (1- lbeg))
3024 (point)))
3025 (end (if (zerop lend) (point-max)
3026 (goto-char (point-min))
3027 (forward-line (1- lend))
3028 (point))))
3029 (narrow-to-region beg end)))
3030 ;; Remove blank lines at beginning and end of contents. The logic
3031 ;; behind that removal is that blank lines around include keyword
3032 ;; override blank lines in included file.
3033 (goto-char (point-min))
3034 (org-skip-whitespace)
3035 (beginning-of-line)
3036 (delete-region (point-min) (point))
3037 (goto-char (point-max))
3038 (skip-chars-backward " \r\t\n")
3039 (forward-line)
3040 (delete-region (point) (point-max))
3041 ;; If IND is set, preserve indentation of include keyword until
3042 ;; the first headline encountered.
3043 (when ind
3044 (unless (eq major-mode 'org-mode) (org-mode))
3045 (goto-char (point-min))
3046 (let ((ind-str (make-string ind ? )))
3047 (while (not (or (eobp) (looking-at org-outline-regexp-bol)))
3048 ;; Do not move footnote definitions out of column 0.
3049 (unless (and (looking-at org-footnote-definition-re)
3050 (eq (org-element-type (org-element-at-point))
3051 'footnote-definition))
3052 (insert ind-str))
3053 (forward-line))))
3054 ;; When MINLEVEL is specified, compute minimal level for headlines
3055 ;; in the file (CUR-MIN), and remove stars to each headline so
3056 ;; that headlines with minimal level have a level of MINLEVEL.
3057 (when minlevel
3058 (unless (eq major-mode 'org-mode) (org-mode))
3059 (org-with-limited-levels
3060 (let ((levels (org-map-entries
3061 (lambda () (org-reduced-level (org-current-level))))))
3062 (when levels
3063 (let ((offset (- minlevel (apply 'min levels))))
3064 (unless (zerop offset)
3065 (when org-odd-levels-only (setq offset (* offset 2)))
3066 ;; Only change stars, don't bother moving whole
3067 ;; sections.
3068 (org-map-entries
3069 (lambda () (if (< offset 0) (delete-char (abs offset))
3070 (insert (make-string offset ?*)))))))))))
3071 (org-element-normalize-string (buffer-string))))
3073 (defun org-export-execute-babel-code ()
3074 "Execute every Babel code in the visible part of current buffer.
3075 This function will return an error if the current buffer is
3076 visiting a file."
3077 ;; Get a pristine copy of current buffer so Babel references can be
3078 ;; properly resolved.
3079 (let ((reference (org-export-copy-buffer)))
3080 (unwind-protect (let ((org-current-export-file reference))
3081 (org-export-blocks-preprocess))
3082 (kill-buffer reference))))
3086 ;;; Tools For Back-Ends
3088 ;; A whole set of tools is available to help build new exporters. Any
3089 ;; function general enough to have its use across many back-ends
3090 ;; should be added here.
3092 ;;;; For Affiliated Keywords
3094 ;; `org-export-read-attribute' reads a property from a given element
3095 ;; as a plist. It can be used to normalize affiliated keywords'
3096 ;; syntax.
3098 ;; Since captions can span over multiple lines and accept dual values,
3099 ;; their internal representation is a bit tricky. Therefore,
3100 ;; `org-export-get-caption' transparently returns a given element's
3101 ;; caption as a secondary string.
3103 (defun org-export-read-attribute (attribute element &optional property)
3104 "Turn ATTRIBUTE property from ELEMENT into a plist.
3106 When optional argument PROPERTY is non-nil, return the value of
3107 that property within attributes.
3109 This function assumes attributes are defined as \":keyword
3110 value\" pairs. It is appropriate for `:attr_html' like
3111 properties."
3112 (let ((attributes
3113 (let ((value (org-element-property attribute element)))
3114 (and value
3115 (read (format "(%s)" (mapconcat 'identity value " ")))))))
3116 (if property (plist-get attributes property) attributes)))
3118 (defun org-export-get-caption (element &optional shortp)
3119 "Return caption from ELEMENT as a secondary string.
3121 When optional argument SHORTP is non-nil, return short caption,
3122 as a secondary string, instead.
3124 Caption lines are separated by a white space."
3125 (let ((full-caption (org-element-property :caption element)) caption)
3126 (dolist (line full-caption (cdr caption))
3127 (let ((cap (funcall (if shortp 'cdr 'car) line)))
3128 (when cap
3129 (setq caption (nconc (list " ") (copy-sequence cap) caption)))))))
3132 ;;;; For Derived Back-ends
3134 ;; `org-export-with-backend' is a function allowing to locally use
3135 ;; another back-end to transcode some object or element. In a derived
3136 ;; back-end, it may be used as a fall-back function once all specific
3137 ;; cases have been treated.
3139 (defun org-export-with-backend (back-end data &optional contents info)
3140 "Call a transcoder from BACK-END on DATA.
3141 CONTENTS, when non-nil, is the transcoded contents of DATA
3142 element, as a string. INFO, when non-nil, is the communication
3143 channel used for export, as a plist.."
3144 (org-export-barf-if-invalid-backend back-end)
3145 (let ((type (org-element-type data)))
3146 (if (memq type '(nil org-data)) (error "No foreign transcoder available")
3147 (let ((transcoder
3148 (cdr (assq type (org-export-backend-translate-table back-end)))))
3149 (if (functionp transcoder) (funcall transcoder data contents info)
3150 (error "No foreign transcoder available"))))))
3153 ;;;; For Export Snippets
3155 ;; Every export snippet is transmitted to the back-end. Though, the
3156 ;; latter will only retain one type of export-snippet, ignoring
3157 ;; others, based on the former's target back-end. The function
3158 ;; `org-export-snippet-backend' returns that back-end for a given
3159 ;; export-snippet.
3161 (defun org-export-snippet-backend (export-snippet)
3162 "Return EXPORT-SNIPPET targeted back-end as a symbol.
3163 Translation, with `org-export-snippet-translation-alist', is
3164 applied."
3165 (let ((back-end (org-element-property :back-end export-snippet)))
3166 (intern
3167 (or (cdr (assoc back-end org-export-snippet-translation-alist))
3168 back-end))))
3171 ;;;; For Footnotes
3173 ;; `org-export-collect-footnote-definitions' is a tool to list
3174 ;; actually used footnotes definitions in the whole parse tree, or in
3175 ;; an headline, in order to add footnote listings throughout the
3176 ;; transcoded data.
3178 ;; `org-export-footnote-first-reference-p' is a predicate used by some
3179 ;; back-ends, when they need to attach the footnote definition only to
3180 ;; the first occurrence of the corresponding label.
3182 ;; `org-export-get-footnote-definition' and
3183 ;; `org-export-get-footnote-number' provide easier access to
3184 ;; additional information relative to a footnote reference.
3186 (defun org-export-collect-footnote-definitions (data info)
3187 "Return an alist between footnote numbers, labels and definitions.
3189 DATA is the parse tree from which definitions are collected.
3190 INFO is the plist used as a communication channel.
3192 Definitions are sorted by order of references. They either
3193 appear as Org data or as a secondary string for inlined
3194 footnotes. Unreferenced definitions are ignored."
3195 (let* (num-alist
3196 collect-fn ; for byte-compiler.
3197 (collect-fn
3198 (function
3199 (lambda (data)
3200 ;; Collect footnote number, label and definition in DATA.
3201 (org-element-map
3202 data 'footnote-reference
3203 (lambda (fn)
3204 (when (org-export-footnote-first-reference-p fn info)
3205 (let ((def (org-export-get-footnote-definition fn info)))
3206 (push
3207 (list (org-export-get-footnote-number fn info)
3208 (org-element-property :label fn)
3209 def)
3210 num-alist)
3211 ;; Also search in definition for nested footnotes.
3212 (when (eq (org-element-property :type fn) 'standard)
3213 (funcall collect-fn def)))))
3214 ;; Don't enter footnote definitions since it will happen
3215 ;; when their first reference is found.
3216 info nil 'footnote-definition)))))
3217 (funcall collect-fn (plist-get info :parse-tree))
3218 (reverse num-alist)))
3220 (defun org-export-footnote-first-reference-p (footnote-reference info)
3221 "Non-nil when a footnote reference is the first one for its label.
3223 FOOTNOTE-REFERENCE is the footnote reference being considered.
3224 INFO is the plist used as a communication channel."
3225 (let ((label (org-element-property :label footnote-reference)))
3226 ;; Anonymous footnotes are always a first reference.
3227 (if (not label) t
3228 ;; Otherwise, return the first footnote with the same LABEL and
3229 ;; test if it is equal to FOOTNOTE-REFERENCE.
3230 (let* (search-refs ; for byte-compiler.
3231 (search-refs
3232 (function
3233 (lambda (data)
3234 (org-element-map
3235 data 'footnote-reference
3236 (lambda (fn)
3237 (cond
3238 ((string= (org-element-property :label fn) label)
3239 (throw 'exit fn))
3240 ;; If FN isn't inlined, be sure to traverse its
3241 ;; definition before resuming search. See
3242 ;; comments in `org-export-get-footnote-number'
3243 ;; for more information.
3244 ((eq (org-element-property :type fn) 'standard)
3245 (funcall search-refs
3246 (org-export-get-footnote-definition fn info)))))
3247 ;; Don't enter footnote definitions since it will
3248 ;; happen when their first reference is found.
3249 info 'first-match 'footnote-definition)))))
3250 (eq (catch 'exit (funcall search-refs (plist-get info :parse-tree)))
3251 footnote-reference)))))
3253 (defun org-export-get-footnote-definition (footnote-reference info)
3254 "Return definition of FOOTNOTE-REFERENCE as parsed data.
3255 INFO is the plist used as a communication channel."
3256 (let ((label (org-element-property :label footnote-reference)))
3257 (or (org-element-property :inline-definition footnote-reference)
3258 (cdr (assoc label (plist-get info :footnote-definition-alist))))))
3260 (defun org-export-get-footnote-number (footnote info)
3261 "Return number associated to a footnote.
3263 FOOTNOTE is either a footnote reference or a footnote definition.
3264 INFO is the plist used as a communication channel."
3265 (let* ((label (org-element-property :label footnote))
3266 seen-refs
3267 search-ref ; For byte-compiler.
3268 (search-ref
3269 (function
3270 (lambda (data)
3271 ;; Search footnote references through DATA, filling
3272 ;; SEEN-REFS along the way.
3273 (org-element-map
3274 data 'footnote-reference
3275 (lambda (fn)
3276 (let ((fn-lbl (org-element-property :label fn)))
3277 (cond
3278 ;; Anonymous footnote match: return number.
3279 ((and (not fn-lbl) (eq fn footnote))
3280 (throw 'exit (1+ (length seen-refs))))
3281 ;; Labels match: return number.
3282 ((and label (string= label fn-lbl))
3283 (throw 'exit (1+ (length seen-refs))))
3284 ;; Anonymous footnote: it's always a new one. Also,
3285 ;; be sure to return nil from the `cond' so
3286 ;; `first-match' doesn't get us out of the loop.
3287 ((not fn-lbl) (push 'inline seen-refs) nil)
3288 ;; Label not seen so far: add it so SEEN-REFS.
3290 ;; Also search for subsequent references in
3291 ;; footnote definition so numbering follows reading
3292 ;; logic. Note that we don't have to care about
3293 ;; inline definitions, since `org-element-map'
3294 ;; already traverses them at the right time.
3296 ;; Once again, return nil to stay in the loop.
3297 ((not (member fn-lbl seen-refs))
3298 (push fn-lbl seen-refs)
3299 (funcall search-ref
3300 (org-export-get-footnote-definition fn info))
3301 nil))))
3302 ;; Don't enter footnote definitions since it will happen
3303 ;; when their first reference is found.
3304 info 'first-match 'footnote-definition)))))
3305 (catch 'exit (funcall search-ref (plist-get info :parse-tree)))))
3308 ;;;; For Headlines
3310 ;; `org-export-get-relative-level' is a shortcut to get headline
3311 ;; level, relatively to the lower headline level in the parsed tree.
3313 ;; `org-export-get-headline-number' returns the section number of an
3314 ;; headline, while `org-export-number-to-roman' allows to convert it
3315 ;; to roman numbers.
3317 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
3318 ;; `org-export-last-sibling-p' are three useful predicates when it
3319 ;; comes to fulfill the `:headline-levels' property.
3321 ;; `org-export-get-tags', `org-export-get-category' and
3322 ;; `org-export-get-node-property' extract useful information from an
3323 ;; headline or a parent headline. They all handle inheritance.
3325 (defun org-export-get-relative-level (headline info)
3326 "Return HEADLINE relative level within current parsed tree.
3327 INFO is a plist holding contextual information."
3328 (+ (org-element-property :level headline)
3329 (or (plist-get info :headline-offset) 0)))
3331 (defun org-export-low-level-p (headline info)
3332 "Non-nil when HEADLINE is considered as low level.
3334 INFO is a plist used as a communication channel.
3336 A low level headlines has a relative level greater than
3337 `:headline-levels' property value.
3339 Return value is the difference between HEADLINE relative level
3340 and the last level being considered as high enough, or nil."
3341 (let ((limit (plist-get info :headline-levels)))
3342 (when (wholenump limit)
3343 (let ((level (org-export-get-relative-level headline info)))
3344 (and (> level limit) (- level limit))))))
3346 (defun org-export-get-headline-number (headline info)
3347 "Return HEADLINE numbering as a list of numbers.
3348 INFO is a plist holding contextual information."
3349 (cdr (assoc headline (plist-get info :headline-numbering))))
3351 (defun org-export-numbered-headline-p (headline info)
3352 "Return a non-nil value if HEADLINE element should be numbered.
3353 INFO is a plist used as a communication channel."
3354 (let ((sec-num (plist-get info :section-numbers))
3355 (level (org-export-get-relative-level headline info)))
3356 (if (wholenump sec-num) (<= level sec-num) sec-num)))
3358 (defun org-export-number-to-roman (n)
3359 "Convert integer N into a roman numeral."
3360 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
3361 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
3362 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
3363 ( 1 . "I")))
3364 (res ""))
3365 (if (<= n 0)
3366 (number-to-string n)
3367 (while roman
3368 (if (>= n (caar roman))
3369 (setq n (- n (caar roman))
3370 res (concat res (cdar roman)))
3371 (pop roman)))
3372 res)))
3374 (defun org-export-get-tags (element info &optional tags inherited)
3375 "Return list of tags associated to ELEMENT.
3377 ELEMENT has either an `headline' or an `inlinetask' type. INFO
3378 is a plist used as a communication channel.
3380 Select tags (see `org-export-select-tags') and exclude tags (see
3381 `org-export-exclude-tags') are removed from the list.
3383 When non-nil, optional argument TAGS should be a list of strings.
3384 Any tag belonging to this list will also be removed.
3386 When optional argument INHERITED is non-nil, tags can also be
3387 inherited from parent headlines and FILETAGS keywords."
3388 (org-remove-if
3389 (lambda (tag) (or (member tag (plist-get info :select-tags))
3390 (member tag (plist-get info :exclude-tags))
3391 (member tag tags)))
3392 (if (not inherited) (org-element-property :tags element)
3393 ;; Build complete list of inherited tags.
3394 (let ((current-tag-list (org-element-property :tags element)))
3395 (mapc
3396 (lambda (parent)
3397 (mapc
3398 (lambda (tag)
3399 (when (and (memq (org-element-type parent) '(headline inlinetask))
3400 (not (member tag current-tag-list)))
3401 (push tag current-tag-list)))
3402 (org-element-property :tags parent)))
3403 (org-export-get-genealogy element))
3404 ;; Add FILETAGS keywords and return results.
3405 (org-uniquify (append (plist-get info :filetags) current-tag-list))))))
3407 (defun org-export-get-node-property (property blob &optional inherited)
3408 "Return node PROPERTY value for BLOB.
3410 PROPERTY is normalized symbol (i.e. `:cookie-data'). BLOB is an
3411 element or object.
3413 If optional argument INHERITED is non-nil, the value can be
3414 inherited from a parent headline.
3416 Return value is a string or nil."
3417 (let ((headline (if (eq (org-element-type blob) 'headline) blob
3418 (org-export-get-parent-headline blob))))
3419 (if (not inherited) (org-element-property property blob)
3420 (let ((parent headline) value)
3421 (catch 'found
3422 (while parent
3423 (when (plist-member (nth 1 parent) property)
3424 (throw 'found (org-element-property property parent)))
3425 (setq parent (org-element-property :parent parent))))))))
3427 (defun org-export-get-category (blob info)
3428 "Return category for element or object BLOB.
3430 INFO is a plist used as a communication channel.
3432 CATEGORY is automatically inherited from a parent headline, from
3433 #+CATEGORY: keyword or created out of original file name. If all
3434 fail, the fall-back value is \"???\"."
3435 (or (let ((headline (if (eq (org-element-type blob) 'headline) blob
3436 (org-export-get-parent-headline blob))))
3437 ;; Almost like `org-export-node-property', but we cannot trust
3438 ;; `plist-member' as every headline has a `:category'
3439 ;; property, would it be nil or equal to "???" (which has the
3440 ;; same meaning).
3441 (let ((parent headline) value)
3442 (catch 'found
3443 (while parent
3444 (let ((category (org-element-property :category parent)))
3445 (and category (not (equal "???" category))
3446 (throw 'found category)))
3447 (setq parent (org-element-property :parent parent))))))
3448 (org-element-map
3449 (plist-get info :parse-tree) 'keyword
3450 (lambda (kwd)
3451 (when (equal (org-element-property :key kwd) "CATEGORY")
3452 (org-element-property :value kwd)))
3453 info 'first-match)
3454 (let ((file (plist-get info :input-file)))
3455 (and file (file-name-sans-extension (file-name-nondirectory file))))
3456 "???"))
3458 (defun org-export-first-sibling-p (headline info)
3459 "Non-nil when HEADLINE is the first sibling in its sub-tree.
3460 INFO is a plist used as a communication channel."
3461 (not (eq (org-element-type (org-export-get-previous-element headline info))
3462 'headline)))
3464 (defun org-export-last-sibling-p (headline info)
3465 "Non-nil when HEADLINE is the last sibling in its sub-tree.
3466 INFO is a plist used as a communication channel."
3467 (not (org-export-get-next-element headline info)))
3470 ;;;; For Links
3472 ;; `org-export-solidify-link-text' turns a string into a safer version
3473 ;; for links, replacing most non-standard characters with hyphens.
3475 ;; `org-export-get-coderef-format' returns an appropriate format
3476 ;; string for coderefs.
3478 ;; `org-export-inline-image-p' returns a non-nil value when the link
3479 ;; provided should be considered as an inline image.
3481 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
3482 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
3483 ;; returns an appropriate unique identifier when found, or nil.
3485 ;; `org-export-resolve-id-link' returns the first headline with
3486 ;; specified id or custom-id in parse tree, the path to the external
3487 ;; file with the id or nil when neither was found.
3489 ;; `org-export-resolve-coderef' associates a reference to a line
3490 ;; number in the element it belongs, or returns the reference itself
3491 ;; when the element isn't numbered.
3493 (defun org-export-solidify-link-text (s)
3494 "Take link text S and make a safe target out of it."
3495 (save-match-data
3496 (mapconcat 'identity (org-split-string s "[^a-zA-Z0-9_.-:]+") "-")))
3498 (defun org-export-get-coderef-format (path desc)
3499 "Return format string for code reference link.
3500 PATH is the link path. DESC is its description."
3501 (save-match-data
3502 (cond ((not desc) "%s")
3503 ((string-match (regexp-quote (concat "(" path ")")) desc)
3504 (replace-match "%s" t t desc))
3505 (t desc))))
3507 (defun org-export-inline-image-p (link &optional rules)
3508 "Non-nil if LINK object points to an inline image.
3510 Optional argument is a set of RULES defining inline images. It
3511 is an alist where associations have the following shape:
3513 \(TYPE . REGEXP)
3515 Applying a rule means apply REGEXP against LINK's path when its
3516 type is TYPE. The function will return a non-nil value if any of
3517 the provided rules is non-nil. The default rule is
3518 `org-export-default-inline-image-rule'.
3520 This only applies to links without a description."
3521 (and (not (org-element-contents link))
3522 (let ((case-fold-search t)
3523 (rules (or rules org-export-default-inline-image-rule)))
3524 (catch 'exit
3525 (mapc
3526 (lambda (rule)
3527 (and (string= (org-element-property :type link) (car rule))
3528 (string-match (cdr rule)
3529 (org-element-property :path link))
3530 (throw 'exit t)))
3531 rules)
3532 ;; Return nil if no rule matched.
3533 nil))))
3535 (defun org-export-resolve-coderef (ref info)
3536 "Resolve a code reference REF.
3538 INFO is a plist used as a communication channel.
3540 Return associated line number in source code, or REF itself,
3541 depending on src-block or example element's switches."
3542 (org-element-map
3543 (plist-get info :parse-tree) '(example-block src-block)
3544 (lambda (el)
3545 (with-temp-buffer
3546 (insert (org-trim (org-element-property :value el)))
3547 (let* ((label-fmt (regexp-quote
3548 (or (org-element-property :label-fmt el)
3549 org-coderef-label-format)))
3550 (ref-re
3551 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
3552 (replace-regexp-in-string "%s" ref label-fmt nil t))))
3553 ;; Element containing REF is found. Resolve it to either
3554 ;; a label or a line number, as needed.
3555 (when (re-search-backward ref-re nil t)
3556 (cond
3557 ((org-element-property :use-labels el) ref)
3558 ((eq (org-element-property :number-lines el) 'continued)
3559 (+ (org-export-get-loc el info) (line-number-at-pos)))
3560 (t (line-number-at-pos)))))))
3561 info 'first-match))
3563 (defun org-export-resolve-fuzzy-link (link info)
3564 "Return LINK destination.
3566 INFO is a plist holding contextual information.
3568 Return value can be an object, an element, or nil:
3570 - If LINK path matches a target object (i.e. <<path>>) or
3571 element (i.e. \"#+TARGET: path\"), return it.
3573 - If LINK path exactly matches the name affiliated keyword
3574 \(i.e. #+NAME: path) of an element, return that element.
3576 - If LINK path exactly matches any headline name, return that
3577 element. If more than one headline share that name, priority
3578 will be given to the one with the closest common ancestor, if
3579 any, or the first one in the parse tree otherwise.
3581 - Otherwise, return nil.
3583 Assume LINK type is \"fuzzy\"."
3584 (let* ((path (org-element-property :path link))
3585 (match-title-p (eq (aref path 0) ?*)))
3586 (cond
3587 ;; First try to find a matching "<<path>>" unless user specified
3588 ;; he was looking for an headline (path starts with a *
3589 ;; character).
3590 ((and (not match-title-p)
3591 (loop for target in (plist-get info :target-list)
3592 when (string= (org-element-property :value target) path)
3593 return target)))
3594 ;; Then try to find an element with a matching "#+NAME: path"
3595 ;; affiliated keyword.
3596 ((and (not match-title-p)
3597 (org-element-map
3598 (plist-get info :parse-tree) org-element-all-elements
3599 (lambda (el)
3600 (when (string= (org-element-property :name el) path) el))
3601 info 'first-match)))
3602 ;; Last case: link either points to an headline or to
3603 ;; nothingness. Try to find the source, with priority given to
3604 ;; headlines with the closest common ancestor. If such candidate
3605 ;; is found, return it, otherwise return nil.
3607 (let ((find-headline
3608 (function
3609 ;; Return first headline whose `:raw-value' property
3610 ;; is NAME in parse tree DATA, or nil.
3611 (lambda (name data)
3612 (org-element-map
3613 data 'headline
3614 (lambda (headline)
3615 (when (string=
3616 (org-element-property :raw-value headline)
3617 name)
3618 headline))
3619 info 'first-match)))))
3620 ;; Search among headlines sharing an ancestor with link,
3621 ;; from closest to farthest.
3622 (or (catch 'exit
3623 (mapc
3624 (lambda (parent)
3625 (when (eq (org-element-type parent) 'headline)
3626 (let ((foundp (funcall find-headline path parent)))
3627 (when foundp (throw 'exit foundp)))))
3628 (org-export-get-genealogy link)) nil)
3629 ;; No match with a common ancestor: try the full parse-tree.
3630 (funcall find-headline
3631 (if match-title-p (substring path 1) path)
3632 (plist-get info :parse-tree))))))))
3634 (defun org-export-resolve-id-link (link info)
3635 "Return headline referenced as LINK destination.
3637 INFO is a plist used as a communication channel.
3639 Return value can be the headline element matched in current parse
3640 tree, a file name or nil. Assume LINK type is either \"id\" or
3641 \"custom-id\"."
3642 (let ((id (org-element-property :path link)))
3643 ;; First check if id is within the current parse tree.
3644 (or (org-element-map
3645 (plist-get info :parse-tree) 'headline
3646 (lambda (headline)
3647 (when (or (string= (org-element-property :id headline) id)
3648 (string= (org-element-property :custom-id headline) id))
3649 headline))
3650 info 'first-match)
3651 ;; Otherwise, look for external files.
3652 (cdr (assoc id (plist-get info :id-alist))))))
3654 (defun org-export-resolve-radio-link (link info)
3655 "Return radio-target object referenced as LINK destination.
3657 INFO is a plist used as a communication channel.
3659 Return value can be a radio-target object or nil. Assume LINK
3660 has type \"radio\"."
3661 (let ((path (org-element-property :path link)))
3662 (org-element-map
3663 (plist-get info :parse-tree) 'radio-target
3664 (lambda (radio)
3665 (when (equal (org-element-property :value radio) path) radio))
3666 info 'first-match)))
3669 ;;;; For References
3671 ;; `org-export-get-ordinal' associates a sequence number to any object
3672 ;; or element.
3674 (defun org-export-get-ordinal (element info &optional types predicate)
3675 "Return ordinal number of an element or object.
3677 ELEMENT is the element or object considered. INFO is the plist
3678 used as a communication channel.
3680 Optional argument TYPES, when non-nil, is a list of element or
3681 object types, as symbols, that should also be counted in.
3682 Otherwise, only provided element's type is considered.
3684 Optional argument PREDICATE is a function returning a non-nil
3685 value if the current element or object should be counted in. It
3686 accepts two arguments: the element or object being considered and
3687 the plist used as a communication channel. This allows to count
3688 only a certain type of objects (i.e. inline images).
3690 Return value is a list of numbers if ELEMENT is an headline or an
3691 item. It is nil for keywords. It represents the footnote number
3692 for footnote definitions and footnote references. If ELEMENT is
3693 a target, return the same value as if ELEMENT was the closest
3694 table, item or headline containing the target. In any other
3695 case, return the sequence number of ELEMENT among elements or
3696 objects of the same type."
3697 ;; A target keyword, representing an invisible target, never has
3698 ;; a sequence number.
3699 (unless (eq (org-element-type element) 'keyword)
3700 ;; Ordinal of a target object refer to the ordinal of the closest
3701 ;; table, item, or headline containing the object.
3702 (when (eq (org-element-type element) 'target)
3703 (setq element
3704 (loop for parent in (org-export-get-genealogy element)
3705 when
3706 (memq
3707 (org-element-type parent)
3708 '(footnote-definition footnote-reference headline item
3709 table))
3710 return parent)))
3711 (case (org-element-type element)
3712 ;; Special case 1: An headline returns its number as a list.
3713 (headline (org-export-get-headline-number element info))
3714 ;; Special case 2: An item returns its number as a list.
3715 (item (let ((struct (org-element-property :structure element)))
3716 (org-list-get-item-number
3717 (org-element-property :begin element)
3718 struct
3719 (org-list-prevs-alist struct)
3720 (org-list-parents-alist struct))))
3721 ((footnote-definition footnote-reference)
3722 (org-export-get-footnote-number element info))
3723 (otherwise
3724 (let ((counter 0))
3725 ;; Increment counter until ELEMENT is found again.
3726 (org-element-map
3727 (plist-get info :parse-tree) (or types (org-element-type element))
3728 (lambda (el)
3729 (cond
3730 ((eq element el) (1+ counter))
3731 ((not predicate) (incf counter) nil)
3732 ((funcall predicate el info) (incf counter) nil)))
3733 info 'first-match))))))
3736 ;;;; For Src-Blocks
3738 ;; `org-export-get-loc' counts number of code lines accumulated in
3739 ;; src-block or example-block elements with a "+n" switch until
3740 ;; a given element, excluded. Note: "-n" switches reset that count.
3742 ;; `org-export-unravel-code' extracts source code (along with a code
3743 ;; references alist) from an `element-block' or `src-block' type
3744 ;; element.
3746 ;; `org-export-format-code' applies a formatting function to each line
3747 ;; of code, providing relative line number and code reference when
3748 ;; appropriate. Since it doesn't access the original element from
3749 ;; which the source code is coming, it expects from the code calling
3750 ;; it to know if lines should be numbered and if code references
3751 ;; should appear.
3753 ;; Eventually, `org-export-format-code-default' is a higher-level
3754 ;; function (it makes use of the two previous functions) which handles
3755 ;; line numbering and code references inclusion, and returns source
3756 ;; code in a format suitable for plain text or verbatim output.
3758 (defun org-export-get-loc (element info)
3759 "Return accumulated lines of code up to ELEMENT.
3761 INFO is the plist used as a communication channel.
3763 ELEMENT is excluded from count."
3764 (let ((loc 0))
3765 (org-element-map
3766 (plist-get info :parse-tree)
3767 `(src-block example-block ,(org-element-type element))
3768 (lambda (el)
3769 (cond
3770 ;; ELEMENT is reached: Quit the loop.
3771 ((eq el element))
3772 ;; Only count lines from src-block and example-block elements
3773 ;; with a "+n" or "-n" switch. A "-n" switch resets counter.
3774 ((not (memq (org-element-type el) '(src-block example-block))) nil)
3775 ((let ((linums (org-element-property :number-lines el)))
3776 (when linums
3777 ;; Accumulate locs or reset them.
3778 (let ((lines (org-count-lines
3779 (org-trim (org-element-property :value el)))))
3780 (setq loc (if (eq linums 'new) lines (+ loc lines))))))
3781 ;; Return nil to stay in the loop.
3782 nil)))
3783 info 'first-match)
3784 ;; Return value.
3785 loc))
3787 (defun org-export-unravel-code (element)
3788 "Clean source code and extract references out of it.
3790 ELEMENT has either a `src-block' an `example-block' type.
3792 Return a cons cell whose CAR is the source code, cleaned from any
3793 reference and protective comma and CDR is an alist between
3794 relative line number (integer) and name of code reference on that
3795 line (string)."
3796 (let* ((line 0) refs
3797 ;; Get code and clean it. Remove blank lines at its
3798 ;; beginning and end.
3799 (code (let ((c (replace-regexp-in-string
3800 "\\`\\([ \t]*\n\\)+" ""
3801 (replace-regexp-in-string
3802 "\\(:?[ \t]*\n\\)*[ \t]*\\'" "\n"
3803 (org-element-property :value element)))))
3804 ;; If appropriate, remove global indentation.
3805 (if (or org-src-preserve-indentation
3806 (org-element-property :preserve-indent element))
3808 (org-remove-indentation c))))
3809 ;; Get format used for references.
3810 (label-fmt (regexp-quote
3811 (or (org-element-property :label-fmt element)
3812 org-coderef-label-format)))
3813 ;; Build a regexp matching a loc with a reference.
3814 (with-ref-re
3815 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)[ \t]*\\)$"
3816 (replace-regexp-in-string
3817 "%s" "\\([-a-zA-Z0-9_ ]+\\)" label-fmt nil t))))
3818 ;; Return value.
3819 (cons
3820 ;; Code with references removed.
3821 (org-element-normalize-string
3822 (mapconcat
3823 (lambda (loc)
3824 (incf line)
3825 (if (not (string-match with-ref-re loc)) loc
3826 ;; Ref line: remove ref, and signal its position in REFS.
3827 (push (cons line (match-string 3 loc)) refs)
3828 (replace-match "" nil nil loc 1)))
3829 (org-split-string code "\n") "\n"))
3830 ;; Reference alist.
3831 refs)))
3833 (defun org-export-format-code (code fun &optional num-lines ref-alist)
3834 "Format CODE by applying FUN line-wise and return it.
3836 CODE is a string representing the code to format. FUN is
3837 a function. It must accept three arguments: a line of
3838 code (string), the current line number (integer) or nil and the
3839 reference associated to the current line (string) or nil.
3841 Optional argument NUM-LINES can be an integer representing the
3842 number of code lines accumulated until the current code. Line
3843 numbers passed to FUN will take it into account. If it is nil,
3844 FUN's second argument will always be nil. This number can be
3845 obtained with `org-export-get-loc' function.
3847 Optional argument REF-ALIST can be an alist between relative line
3848 number (i.e. ignoring NUM-LINES) and the name of the code
3849 reference on it. If it is nil, FUN's third argument will always
3850 be nil. It can be obtained through the use of
3851 `org-export-unravel-code' function."
3852 (let ((--locs (org-split-string code "\n"))
3853 (--line 0))
3854 (org-element-normalize-string
3855 (mapconcat
3856 (lambda (--loc)
3857 (incf --line)
3858 (let ((--ref (cdr (assq --line ref-alist))))
3859 (funcall fun --loc (and num-lines (+ num-lines --line)) --ref)))
3860 --locs "\n"))))
3862 (defun org-export-format-code-default (element info)
3863 "Return source code from ELEMENT, formatted in a standard way.
3865 ELEMENT is either a `src-block' or `example-block' element. INFO
3866 is a plist used as a communication channel.
3868 This function takes care of line numbering and code references
3869 inclusion. Line numbers, when applicable, appear at the
3870 beginning of the line, separated from the code by two white
3871 spaces. Code references, on the other hand, appear flushed to
3872 the right, separated by six white spaces from the widest line of
3873 code."
3874 ;; Extract code and references.
3875 (let* ((code-info (org-export-unravel-code element))
3876 (code (car code-info))
3877 (code-lines (org-split-string code "\n"))
3878 (refs (and (org-element-property :retain-labels element)
3879 (cdr code-info)))
3880 ;; Handle line numbering.
3881 (num-start (case (org-element-property :number-lines element)
3882 (continued (org-export-get-loc element info))
3883 (new 0)))
3884 (num-fmt
3885 (and num-start
3886 (format "%%%ds "
3887 (length (number-to-string
3888 (+ (length code-lines) num-start))))))
3889 ;; Prepare references display, if required. Any reference
3890 ;; should start six columns after the widest line of code,
3891 ;; wrapped with parenthesis.
3892 (max-width
3893 (+ (apply 'max (mapcar 'length code-lines))
3894 (if (not num-start) 0 (length (format num-fmt num-start))))))
3895 (org-export-format-code
3896 code
3897 (lambda (loc line-num ref)
3898 (let ((number-str (and num-fmt (format num-fmt line-num))))
3899 (concat
3900 number-str
3902 (and ref
3903 (concat (make-string
3904 (- (+ 6 max-width)
3905 (+ (length loc) (length number-str))) ? )
3906 (format "(%s)" ref))))))
3907 num-start refs)))
3910 ;;;; For Tables
3912 ;; `org-export-table-has-special-column-p' and and
3913 ;; `org-export-table-row-is-special-p' are predicates used to look for
3914 ;; meta-information about the table structure.
3916 ;; `org-table-has-header-p' tells when the rows before the first rule
3917 ;; should be considered as table's header.
3919 ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
3920 ;; and `org-export-table-cell-borders' extract information from
3921 ;; a table-cell element.
3923 ;; `org-export-table-dimensions' gives the number on rows and columns
3924 ;; in the table, ignoring horizontal rules and special columns.
3925 ;; `org-export-table-cell-address', given a table-cell object, returns
3926 ;; the absolute address of a cell. On the other hand,
3927 ;; `org-export-get-table-cell-at' does the contrary.
3929 ;; `org-export-table-cell-starts-colgroup-p',
3930 ;; `org-export-table-cell-ends-colgroup-p',
3931 ;; `org-export-table-row-starts-rowgroup-p',
3932 ;; `org-export-table-row-ends-rowgroup-p',
3933 ;; `org-export-table-row-starts-header-p' and
3934 ;; `org-export-table-row-ends-header-p' indicate position of current
3935 ;; row or cell within the table.
3937 (defun org-export-table-has-special-column-p (table)
3938 "Non-nil when TABLE has a special column.
3939 All special columns will be ignored during export."
3940 ;; The table has a special column when every first cell of every row
3941 ;; has an empty value or contains a symbol among "/", "#", "!", "$",
3942 ;; "*" "_" and "^". Though, do not consider a first row containing
3943 ;; only empty cells as special.
3944 (let ((special-column-p 'empty))
3945 (catch 'exit
3946 (mapc
3947 (lambda (row)
3948 (when (eq (org-element-property :type row) 'standard)
3949 (let ((value (org-element-contents
3950 (car (org-element-contents row)))))
3951 (cond ((member value '(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
3952 (setq special-column-p 'special))
3953 ((not value))
3954 (t (throw 'exit nil))))))
3955 (org-element-contents table))
3956 (eq special-column-p 'special))))
3958 (defun org-export-table-has-header-p (table info)
3959 "Non-nil when TABLE has an header.
3961 INFO is a plist used as a communication channel.
3963 A table has an header when it contains at least two row groups."
3964 (let ((rowgroup 1) row-flag)
3965 (org-element-map
3966 table 'table-row
3967 (lambda (row)
3968 (cond
3969 ((> rowgroup 1) t)
3970 ((and row-flag (eq (org-element-property :type row) 'rule))
3971 (incf rowgroup) (setq row-flag nil))
3972 ((and (not row-flag) (eq (org-element-property :type row) 'standard))
3973 (setq row-flag t) nil)))
3974 info)))
3976 (defun org-export-table-row-is-special-p (table-row info)
3977 "Non-nil if TABLE-ROW is considered special.
3979 INFO is a plist used as the communication channel.
3981 All special rows will be ignored during export."
3982 (when (eq (org-element-property :type table-row) 'standard)
3983 (let ((first-cell (org-element-contents
3984 (car (org-element-contents table-row)))))
3985 ;; A row is special either when...
3987 ;; ... it starts with a field only containing "/",
3988 (equal first-cell '("/"))
3989 ;; ... the table contains a special column and the row start
3990 ;; with a marking character among, "^", "_", "$" or "!",
3991 (and (org-export-table-has-special-column-p
3992 (org-export-get-parent table-row))
3993 (member first-cell '(("^") ("_") ("$") ("!"))))
3994 ;; ... it contains only alignment cookies and empty cells.
3995 (let ((special-row-p 'empty))
3996 (catch 'exit
3997 (mapc
3998 (lambda (cell)
3999 (let ((value (org-element-contents cell)))
4000 ;; Since VALUE is a secondary string, the following
4001 ;; checks avoid expanding it with `org-export-data'.
4002 (cond ((not value))
4003 ((and (not (cdr value))
4004 (stringp (car value))
4005 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
4006 (car value)))
4007 (setq special-row-p 'cookie))
4008 (t (throw 'exit nil)))))
4009 (org-element-contents table-row))
4010 (eq special-row-p 'cookie)))))))
4012 (defun org-export-table-row-group (table-row info)
4013 "Return TABLE-ROW's group.
4015 INFO is a plist used as the communication channel.
4017 Return value is the group number, as an integer, or nil special
4018 rows and table rules. Group 1 is also table's header."
4019 (unless (or (eq (org-element-property :type table-row) 'rule)
4020 (org-export-table-row-is-special-p table-row info))
4021 (let ((group 0) row-flag)
4022 (catch 'found
4023 (mapc
4024 (lambda (row)
4025 (cond
4026 ((and (eq (org-element-property :type row) 'standard)
4027 (not (org-export-table-row-is-special-p row info)))
4028 (unless row-flag (incf group) (setq row-flag t)))
4029 ((eq (org-element-property :type row) 'rule)
4030 (setq row-flag nil)))
4031 (when (eq table-row row) (throw 'found group)))
4032 (org-element-contents (org-export-get-parent table-row)))))))
4034 (defun org-export-table-cell-width (table-cell info)
4035 "Return TABLE-CELL contents width.
4037 INFO is a plist used as the communication channel.
4039 Return value is the width given by the last width cookie in the
4040 same column as TABLE-CELL, or nil."
4041 (let* ((row (org-export-get-parent table-cell))
4042 (column (let ((cells (org-element-contents row)))
4043 (- (length cells) (length (memq table-cell cells)))))
4044 (table (org-export-get-parent-table table-cell))
4045 cookie-width)
4046 (mapc
4047 (lambda (row)
4048 (cond
4049 ;; In a special row, try to find a width cookie at COLUMN.
4050 ((org-export-table-row-is-special-p row info)
4051 (let ((value (org-element-contents
4052 (elt (org-element-contents row) column))))
4053 ;; The following checks avoid expanding unnecessarily the
4054 ;; cell with `org-export-data'
4055 (when (and value
4056 (not (cdr value))
4057 (stringp (car value))
4058 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" (car value))
4059 (match-string 1 (car value)))
4060 (setq cookie-width
4061 (string-to-number (match-string 1 (car value)))))))
4062 ;; Ignore table rules.
4063 ((eq (org-element-property :type row) 'rule))))
4064 (org-element-contents table))
4065 ;; Return value.
4066 cookie-width))
4068 (defun org-export-table-cell-alignment (table-cell info)
4069 "Return TABLE-CELL contents alignment.
4071 INFO is a plist used as the communication channel.
4073 Return alignment as specified by the last alignment cookie in the
4074 same column as TABLE-CELL. If no such cookie is found, a default
4075 alignment value will be deduced from fraction of numbers in the
4076 column (see `org-table-number-fraction' for more information).
4077 Possible values are `left', `right' and `center'."
4078 (let* ((row (org-export-get-parent table-cell))
4079 (column (let ((cells (org-element-contents row)))
4080 (- (length cells) (length (memq table-cell cells)))))
4081 (table (org-export-get-parent-table table-cell))
4082 (number-cells 0)
4083 (total-cells 0)
4084 cookie-align)
4085 (mapc
4086 (lambda (row)
4087 (cond
4088 ;; In a special row, try to find an alignment cookie at
4089 ;; COLUMN.
4090 ((org-export-table-row-is-special-p row info)
4091 (let ((value (org-element-contents
4092 (elt (org-element-contents row) column))))
4093 ;; Since VALUE is a secondary string, the following checks
4094 ;; avoid useless expansion through `org-export-data'.
4095 (when (and value
4096 (not (cdr value))
4097 (stringp (car value))
4098 (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
4099 (car value))
4100 (match-string 1 (car value)))
4101 (setq cookie-align (match-string 1 (car value))))))
4102 ;; Ignore table rules.
4103 ((eq (org-element-property :type row) 'rule))
4104 ;; In a standard row, check if cell's contents are expressing
4105 ;; some kind of number. Increase NUMBER-CELLS accordingly.
4106 ;; Though, don't bother if an alignment cookie has already
4107 ;; defined cell's alignment.
4108 ((not cookie-align)
4109 (let ((value (org-export-data
4110 (org-element-contents
4111 (elt (org-element-contents row) column))
4112 info)))
4113 (incf total-cells)
4114 (when (string-match org-table-number-regexp value)
4115 (incf number-cells))))))
4116 (org-element-contents table))
4117 ;; Return value. Alignment specified by cookies has precedence
4118 ;; over alignment deduced from cells contents.
4119 (cond ((equal cookie-align "l") 'left)
4120 ((equal cookie-align "r") 'right)
4121 ((equal cookie-align "c") 'center)
4122 ((>= (/ (float number-cells) total-cells) org-table-number-fraction)
4123 'right)
4124 (t 'left))))
4126 (defun org-export-table-cell-borders (table-cell info)
4127 "Return TABLE-CELL borders.
4129 INFO is a plist used as a communication channel.
4131 Return value is a list of symbols, or nil. Possible values are:
4132 `top', `bottom', `above', `below', `left' and `right'. Note:
4133 `top' (resp. `bottom') only happen for a cell in the first
4134 row (resp. last row) of the table, ignoring table rules, if any.
4136 Returned borders ignore special rows."
4137 (let* ((row (org-export-get-parent table-cell))
4138 (table (org-export-get-parent-table table-cell))
4139 borders)
4140 ;; Top/above border? TABLE-CELL has a border above when a rule
4141 ;; used to demarcate row groups can be found above. Hence,
4142 ;; finding a rule isn't sufficient to push `above' in BORDERS:
4143 ;; another regular row has to be found above that rule.
4144 (let (rule-flag)
4145 (catch 'exit
4146 (mapc (lambda (row)
4147 (cond ((eq (org-element-property :type row) 'rule)
4148 (setq rule-flag t))
4149 ((not (org-export-table-row-is-special-p row info))
4150 (if rule-flag (throw 'exit (push 'above borders))
4151 (throw 'exit nil)))))
4152 ;; Look at every row before the current one.
4153 (cdr (memq row (reverse (org-element-contents table)))))
4154 ;; No rule above, or rule found starts the table (ignoring any
4155 ;; special row): TABLE-CELL is at the top of the table.
4156 (when rule-flag (push 'above borders))
4157 (push 'top borders)))
4158 ;; Bottom/below border? TABLE-CELL has a border below when next
4159 ;; non-regular row below is a rule.
4160 (let (rule-flag)
4161 (catch 'exit
4162 (mapc (lambda (row)
4163 (cond ((eq (org-element-property :type row) 'rule)
4164 (setq rule-flag t))
4165 ((not (org-export-table-row-is-special-p row info))
4166 (if rule-flag (throw 'exit (push 'below borders))
4167 (throw 'exit nil)))))
4168 ;; Look at every row after the current one.
4169 (cdr (memq row (org-element-contents table))))
4170 ;; No rule below, or rule found ends the table (modulo some
4171 ;; special row): TABLE-CELL is at the bottom of the table.
4172 (when rule-flag (push 'below borders))
4173 (push 'bottom borders)))
4174 ;; Right/left borders? They can only be specified by column
4175 ;; groups. Column groups are defined in a row starting with "/".
4176 ;; Also a column groups row only contains "<", "<>", ">" or blank
4177 ;; cells.
4178 (catch 'exit
4179 (let ((column (let ((cells (org-element-contents row)))
4180 (- (length cells) (length (memq table-cell cells))))))
4181 (mapc
4182 (lambda (row)
4183 (unless (eq (org-element-property :type row) 'rule)
4184 (when (equal (org-element-contents
4185 (car (org-element-contents row)))
4186 '("/"))
4187 (let ((column-groups
4188 (mapcar
4189 (lambda (cell)
4190 (let ((value (org-element-contents cell)))
4191 (when (member value '(("<") ("<>") (">") nil))
4192 (car value))))
4193 (org-element-contents row))))
4194 ;; There's a left border when previous cell, if
4195 ;; any, ends a group, or current one starts one.
4196 (when (or (and (not (zerop column))
4197 (member (elt column-groups (1- column))
4198 '(">" "<>")))
4199 (member (elt column-groups column) '("<" "<>")))
4200 (push 'left borders))
4201 ;; There's a right border when next cell, if any,
4202 ;; starts a group, or current one ends one.
4203 (when (or (and (/= (1+ column) (length column-groups))
4204 (member (elt column-groups (1+ column))
4205 '("<" "<>")))
4206 (member (elt column-groups column) '(">" "<>")))
4207 (push 'right borders))
4208 (throw 'exit nil)))))
4209 ;; Table rows are read in reverse order so last column groups
4210 ;; row has precedence over any previous one.
4211 (reverse (org-element-contents table)))))
4212 ;; Return value.
4213 borders))
4215 (defun org-export-table-cell-starts-colgroup-p (table-cell info)
4216 "Non-nil when TABLE-CELL is at the beginning of a row group.
4217 INFO is a plist used as a communication channel."
4218 ;; A cell starts a column group either when it is at the beginning
4219 ;; of a row (or after the special column, if any) or when it has
4220 ;; a left border.
4221 (or (eq (org-element-map
4222 (org-export-get-parent table-cell)
4223 'table-cell 'identity info 'first-match)
4224 table-cell)
4225 (memq 'left (org-export-table-cell-borders table-cell info))))
4227 (defun org-export-table-cell-ends-colgroup-p (table-cell info)
4228 "Non-nil when TABLE-CELL is at the end of a row group.
4229 INFO is a plist used as a communication channel."
4230 ;; A cell ends a column group either when it is at the end of a row
4231 ;; or when it has a right border.
4232 (or (eq (car (last (org-element-contents
4233 (org-export-get-parent table-cell))))
4234 table-cell)
4235 (memq 'right (org-export-table-cell-borders table-cell info))))
4237 (defun org-export-table-row-starts-rowgroup-p (table-row info)
4238 "Non-nil when TABLE-ROW is at the beginning of a column group.
4239 INFO is a plist used as a communication channel."
4240 (unless (or (eq (org-element-property :type table-row) 'rule)
4241 (org-export-table-row-is-special-p table-row info))
4242 (let ((borders (org-export-table-cell-borders
4243 (car (org-element-contents table-row)) info)))
4244 (or (memq 'top borders) (memq 'above borders)))))
4246 (defun org-export-table-row-ends-rowgroup-p (table-row info)
4247 "Non-nil when TABLE-ROW is at the end of a column group.
4248 INFO is a plist used as a communication channel."
4249 (unless (or (eq (org-element-property :type table-row) 'rule)
4250 (org-export-table-row-is-special-p table-row info))
4251 (let ((borders (org-export-table-cell-borders
4252 (car (org-element-contents table-row)) info)))
4253 (or (memq 'bottom borders) (memq 'below borders)))))
4255 (defun org-export-table-row-starts-header-p (table-row info)
4256 "Non-nil when TABLE-ROW is the first table header's row.
4257 INFO is a plist used as a communication channel."
4258 (and (org-export-table-has-header-p
4259 (org-export-get-parent-table table-row) info)
4260 (org-export-table-row-starts-rowgroup-p table-row info)
4261 (= (org-export-table-row-group table-row info) 1)))
4263 (defun org-export-table-row-ends-header-p (table-row info)
4264 "Non-nil when TABLE-ROW is the last table header's row.
4265 INFO is a plist used as a communication channel."
4266 (and (org-export-table-has-header-p
4267 (org-export-get-parent-table table-row) info)
4268 (org-export-table-row-ends-rowgroup-p table-row info)
4269 (= (org-export-table-row-group table-row info) 1)))
4271 (defun org-export-table-dimensions (table info)
4272 "Return TABLE dimensions.
4274 INFO is a plist used as a communication channel.
4276 Return value is a CONS like (ROWS . COLUMNS) where
4277 ROWS (resp. COLUMNS) is the number of exportable
4278 rows (resp. columns)."
4279 (let (first-row (columns 0) (rows 0))
4280 ;; Set number of rows, and extract first one.
4281 (org-element-map
4282 table 'table-row
4283 (lambda (row)
4284 (when (eq (org-element-property :type row) 'standard)
4285 (incf rows)
4286 (unless first-row (setq first-row row)))) info)
4287 ;; Set number of columns.
4288 (org-element-map first-row 'table-cell (lambda (cell) (incf columns)) info)
4289 ;; Return value.
4290 (cons rows columns)))
4292 (defun org-export-table-cell-address (table-cell info)
4293 "Return address of a regular TABLE-CELL object.
4295 TABLE-CELL is the cell considered. INFO is a plist used as
4296 a communication channel.
4298 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4299 zero-based index. Only exportable cells are considered. The
4300 function returns nil for other cells."
4301 (let* ((table-row (org-export-get-parent table-cell))
4302 (table (org-export-get-parent-table table-cell)))
4303 ;; Ignore cells in special rows or in special column.
4304 (unless (or (org-export-table-row-is-special-p table-row info)
4305 (and (org-export-table-has-special-column-p table)
4306 (eq (car (org-element-contents table-row)) table-cell)))
4307 (cons
4308 ;; Row number.
4309 (let ((row-count 0))
4310 (org-element-map
4311 table 'table-row
4312 (lambda (row)
4313 (cond ((eq (org-element-property :type row) 'rule) nil)
4314 ((eq row table-row) row-count)
4315 (t (incf row-count) nil)))
4316 info 'first-match))
4317 ;; Column number.
4318 (let ((col-count 0))
4319 (org-element-map
4320 table-row 'table-cell
4321 (lambda (cell)
4322 (if (eq cell table-cell) col-count (incf col-count) nil))
4323 info 'first-match))))))
4325 (defun org-export-get-table-cell-at (address table info)
4326 "Return regular table-cell object at ADDRESS in TABLE.
4328 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4329 zero-based index. TABLE is a table type element. INFO is
4330 a plist used as a communication channel.
4332 If no table-cell, among exportable cells, is found at ADDRESS,
4333 return nil."
4334 (let ((column-pos (cdr address)) (column-count 0))
4335 (org-element-map
4336 ;; Row at (car address) or nil.
4337 (let ((row-pos (car address)) (row-count 0))
4338 (org-element-map
4339 table 'table-row
4340 (lambda (row)
4341 (cond ((eq (org-element-property :type row) 'rule) nil)
4342 ((= row-count row-pos) row)
4343 (t (incf row-count) nil)))
4344 info 'first-match))
4345 'table-cell
4346 (lambda (cell)
4347 (if (= column-count column-pos) cell
4348 (incf column-count) nil))
4349 info 'first-match)))
4352 ;;;; For Tables Of Contents
4354 ;; `org-export-collect-headlines' builds a list of all exportable
4355 ;; headline elements, maybe limited to a certain depth. One can then
4356 ;; easily parse it and transcode it.
4358 ;; Building lists of tables, figures or listings is quite similar.
4359 ;; Once the generic function `org-export-collect-elements' is defined,
4360 ;; `org-export-collect-tables', `org-export-collect-figures' and
4361 ;; `org-export-collect-listings' can be derived from it.
4363 (defun org-export-collect-headlines (info &optional n)
4364 "Collect headlines in order to build a table of contents.
4366 INFO is a plist used as a communication channel.
4368 When optional argument N is an integer, it specifies the depth of
4369 the table of contents. Otherwise, it is set to the value of the
4370 last headline level. See `org-export-headline-levels' for more
4371 information.
4373 Return a list of all exportable headlines as parsed elements."
4374 (unless (wholenump n) (setq n (plist-get info :headline-levels)))
4375 (org-element-map
4376 (plist-get info :parse-tree)
4377 'headline
4378 (lambda (headline)
4379 ;; Strip contents from HEADLINE.
4380 (let ((relative-level (org-export-get-relative-level headline info)))
4381 (unless (> relative-level n) headline)))
4382 info))
4384 (defun org-export-collect-elements (type info &optional predicate)
4385 "Collect referenceable elements of a determined type.
4387 TYPE can be a symbol or a list of symbols specifying element
4388 types to search. Only elements with a caption are collected.
4390 INFO is a plist used as a communication channel.
4392 When non-nil, optional argument PREDICATE is a function accepting
4393 one argument, an element of type TYPE. It returns a non-nil
4394 value when that element should be collected.
4396 Return a list of all elements found, in order of appearance."
4397 (org-element-map
4398 (plist-get info :parse-tree) type
4399 (lambda (element)
4400 (and (org-element-property :caption element)
4401 (or (not predicate) (funcall predicate element))
4402 element))
4403 info))
4405 (defun org-export-collect-tables (info)
4406 "Build a list of tables.
4407 INFO is a plist used as a communication channel.
4409 Return a list of table elements with a caption."
4410 (org-export-collect-elements 'table info))
4412 (defun org-export-collect-figures (info predicate)
4413 "Build a list of figures.
4415 INFO is a plist used as a communication channel. PREDICATE is
4416 a function which accepts one argument: a paragraph element and
4417 whose return value is non-nil when that element should be
4418 collected.
4420 A figure is a paragraph type element, with a caption, verifying
4421 PREDICATE. The latter has to be provided since a \"figure\" is
4422 a vague concept that may depend on back-end.
4424 Return a list of elements recognized as figures."
4425 (org-export-collect-elements 'paragraph info predicate))
4427 (defun org-export-collect-listings (info)
4428 "Build a list of src blocks.
4430 INFO is a plist used as a communication channel.
4432 Return a list of src-block elements with a caption."
4433 (org-export-collect-elements 'src-block info))
4436 ;;;; Smart Quotes
4438 ;; The main function for the smart quotes sub-system is
4439 ;; `org-export-activate-smart-quotes', which replaces every quote in
4440 ;; a given string from the parse tree with its "smart" counterpart.
4442 ;; Dictionary for smart quotes is stored in
4443 ;; `org-export-smart-quotes-alist'.
4445 ;; Internally, regexps matching potential smart quotes (checks at
4446 ;; string boundaries are also necessary) are defined in
4447 ;; `org-export-smart-quotes-regexps'.
4449 (defconst org-export-smart-quotes-alist
4450 '(("de"
4451 (opening-double-quote :utf-8 "„" :html "&bdquo;" :latex "\"`"
4452 :texinfo "@quotedblbase{}")
4453 (closing-double-quote :utf-8 "“" :html "&ldquo;" :latex "\"'"
4454 :texinfo "@quotedblleft{}")
4455 (opening-single-quote :utf-8 "‚" :html "&sbquo;" :latex "\\glq{}"
4456 :texinfo "@quotesinglbase{}")
4457 (closing-single-quote :utf-8 "‘" :html "&lsquo;" :latex "\\grq{}"
4458 :texinfo "@quoteleft{}")
4459 (apostrophe :utf-8 "’" :html "&rsquo;"))
4460 ("en"
4461 (opening-double-quote :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
4462 (closing-double-quote :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
4463 (opening-single-quote :utf-8 "‘" :html "&lsquo;" :latex "`" :texinfo "`")
4464 (closing-single-quote :utf-8 "’" :html "&rsquo;" :latex "'" :texinfo "'")
4465 (apostrophe :utf-8 "’" :html "&rsquo;"))
4466 ("es"
4467 (opening-double-quote :utf-8 "«" :html "&laquo;" :latex "\\guillemotleft{}"
4468 :texinfo "@guillemetleft{}")
4469 (closing-double-quote :utf-8 "»" :html "&raquo;" :latex "\\guillemotright{}"
4470 :texinfo "@guillemetright{}")
4471 (opening-single-quote :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
4472 (closing-single-quote :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
4473 (apostrophe :utf-8 "’" :html "&rsquo;"))
4474 ("fr"
4475 (opening-double-quote :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
4476 :texinfo "@guillemetleft{}@tie{}")
4477 (closing-double-quote :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
4478 :texinfo "@tie{}@guillemetright{}")
4479 (opening-single-quote :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
4480 :texinfo "@guillemetleft{}@tie{}")
4481 (closing-single-quote :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
4482 :texinfo "@tie{}@guillemetright{}")
4483 (apostrophe :utf-8 "’" :html "&rsquo;")))
4484 "Smart quotes translations.
4486 Alist whose CAR is a language string and CDR is an alist with
4487 quote type as key and a plist associating various encodings to
4488 their translation as value.
4490 A quote type can be any symbol among `opening-double-quote',
4491 `closing-double-quote', `opening-single-quote',
4492 `closing-single-quote' and `apostrophe'.
4494 Valid encodings include `:utf-8', `:html', `:latex' and
4495 `:texinfo'.
4497 If no translation is found, the quote character is left as-is.")
4499 (defconst org-export-smart-quotes-regexps
4500 (list
4501 ;; Possible opening quote at beginning of string.
4502 "\\`\\([\"']\\)\\(\\w\\|\\s.\\|\\s_\\)"
4503 ;; Possible closing quote at beginning of string.
4504 "\\`\\([\"']\\)\\(\\s-\\|\\s)\\|\\s.\\)"
4505 ;; Possible apostrophe at beginning of string.
4506 "\\`\\('\\)\\S-"
4507 ;; Opening single and double quotes.
4508 "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\(?:\\w\\|\\s.\\|\\s_\\)"
4509 ;; Closing single and double quotes.
4510 "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\(?:\\s-\\|\\s)\\|\\s.\\)"
4511 ;; Apostrophe.
4512 "\\S-\\('\\)\\S-"
4513 ;; Possible opening quote at end of string.
4514 "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\'"
4515 ;; Possible closing quote at end of string.
4516 "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\'"
4517 ;; Possible apostrophe at end of string.
4518 "\\S-\\('\\)\\'")
4519 "List of regexps matching a quote or an apostrophe.
4520 In every regexp, quote or apostrophe matched is put in group 1.")
4522 (defun org-export-activate-smart-quotes (s encoding info &optional original)
4523 "Replace regular quotes with \"smart\" quotes in string S.
4525 ENCODING is a symbol among `:html', `:latex', `:texinfo' and
4526 `:utf-8'. INFO is a plist used as a communication channel.
4528 The function has to retrieve information about string
4529 surroundings in parse tree. It can only happen with an
4530 unmodified string. Thus, if S has already been through another
4531 process, a non-nil ORIGINAL optional argument will provide that
4532 original string.
4534 Return the new string."
4535 (if (equal s "") ""
4536 (let* ((prev (org-export-get-previous-element (or original s) info))
4537 (pre-blank (and prev (org-element-property :post-blank prev)))
4538 (next (org-export-get-next-element (or original s) info))
4539 (get-smart-quote
4540 (lambda (q type)
4541 ;; Return smart quote associated to a give quote Q, as
4542 ;; a string. TYPE is a symbol among `open', `close' and
4543 ;; `apostrophe'.
4544 (let ((key (case type
4545 (apostrophe 'apostrophe)
4546 (open (if (equal "'" q) 'opening-single-quote
4547 'opening-double-quote))
4548 (otherwise (if (equal "'" q) 'closing-single-quote
4549 'closing-double-quote)))))
4550 (or (plist-get
4551 (cdr (assq key
4552 (cdr (assoc (plist-get info :language)
4553 org-export-smart-quotes-alist))))
4554 encoding)
4555 q)))))
4556 (if (or (equal "\"" s) (equal "'" s))
4557 ;; Only a quote: no regexp can match. We have to check both
4558 ;; sides and decide what to do.
4559 (cond ((and (not prev) (not next)) s)
4560 ((not prev) (funcall get-smart-quote s 'open))
4561 ((and (not next) (zerop pre-blank))
4562 (funcall get-smart-quote s 'close))
4563 ((not next) s)
4564 ((zerop pre-blank) (funcall get-smart-quote s 'apostrophe))
4565 (t (funcall get-smart-quote 'open)))
4566 ;; 1. Replace quote character at the beginning of S.
4567 (cond
4568 ;; Apostrophe?
4569 ((and prev (zerop pre-blank)
4570 (string-match (nth 2 org-export-smart-quotes-regexps) s))
4571 (setq s (replace-match
4572 (funcall get-smart-quote (match-string 1 s) 'apostrophe)
4573 nil t s 1)))
4574 ;; Closing quote?
4575 ((and prev (zerop pre-blank)
4576 (string-match (nth 1 org-export-smart-quotes-regexps) s))
4577 (setq s (replace-match
4578 (funcall get-smart-quote (match-string 1 s) 'close)
4579 nil t s 1)))
4580 ;; Opening quote?
4581 ((and (or (not prev) (> pre-blank 0))
4582 (string-match (nth 0 org-export-smart-quotes-regexps) s))
4583 (setq s (replace-match
4584 (funcall get-smart-quote (match-string 1 s) 'open)
4585 nil t s 1))))
4586 ;; 2. Replace quotes in the middle of the string.
4587 (setq s (replace-regexp-in-string
4588 ;; Opening quotes.
4589 (nth 3 org-export-smart-quotes-regexps)
4590 (lambda (text)
4591 (funcall get-smart-quote (match-string 1 text) 'open))
4592 s nil t 1))
4593 (setq s (replace-regexp-in-string
4594 ;; Closing quotes.
4595 (nth 4 org-export-smart-quotes-regexps)
4596 (lambda (text)
4597 (funcall get-smart-quote (match-string 1 text) 'close))
4598 s nil t 1))
4599 (setq s (replace-regexp-in-string
4600 ;; Apostrophes.
4601 (nth 5 org-export-smart-quotes-regexps)
4602 (lambda (text)
4603 (funcall get-smart-quote (match-string 1 text) 'apostrophe))
4604 s nil t 1))
4605 ;; 3. Replace quote character at the end of S.
4606 (cond
4607 ;; Apostrophe?
4608 ((and next (string-match (nth 8 org-export-smart-quotes-regexps) s))
4609 (setq s (replace-match
4610 (funcall get-smart-quote (match-string 1 s) 'apostrophe)
4611 nil t s 1)))
4612 ;; Closing quote?
4613 ((and (not next)
4614 (string-match (nth 7 org-export-smart-quotes-regexps) s))
4615 (setq s (replace-match
4616 (funcall get-smart-quote (match-string 1 s) 'close)
4617 nil t s 1)))
4618 ;; Opening quote?
4619 ((and next (string-match (nth 6 org-export-smart-quotes-regexps) s))
4620 (setq s (replace-match
4621 (funcall get-smart-quote (match-string 1 s) 'open)
4622 nil t s 1))))
4623 ;; Return string with smart quotes.
4624 s))))
4626 ;;;; Topology
4628 ;; Here are various functions to retrieve information about the
4629 ;; neighbourhood of a given element or object. Neighbours of interest
4630 ;; are direct parent (`org-export-get-parent'), parent headline
4631 ;; (`org-export-get-parent-headline'), first element containing an
4632 ;; object, (`org-export-get-parent-element'), parent table
4633 ;; (`org-export-get-parent-table'), previous element or object
4634 ;; (`org-export-get-previous-element') and next element or object
4635 ;; (`org-export-get-next-element').
4637 ;; `org-export-get-genealogy' returns the full genealogy of a given
4638 ;; element or object, from closest parent to full parse tree.
4640 (defun org-export-get-parent (blob)
4641 "Return BLOB parent or nil.
4642 BLOB is the element or object considered."
4643 (org-element-property :parent blob))
4645 (defun org-export-get-genealogy (blob)
4646 "Return full genealogy relative to a given element or object.
4648 BLOB is the element or object being considered.
4650 Ancestors are returned from closest to farthest, the last one
4651 being the full parse tree."
4652 (let (genealogy (parent blob))
4653 (while (setq parent (org-element-property :parent parent))
4654 (push parent genealogy))
4655 (nreverse genealogy)))
4657 (defun org-export-get-parent-headline (blob)
4658 "Return BLOB parent headline or nil.
4659 BLOB is the element or object being considered."
4660 (let ((parent blob))
4661 (while (and (setq parent (org-element-property :parent parent))
4662 (not (eq (org-element-type parent) 'headline))))
4663 parent))
4665 (defun org-export-get-parent-element (object)
4666 "Return first element containing OBJECT or nil.
4667 OBJECT is the object to consider."
4668 (let ((parent object))
4669 (while (and (setq parent (org-element-property :parent parent))
4670 (memq (org-element-type parent) org-element-all-objects)))
4671 parent))
4673 (defun org-export-get-parent-table (object)
4674 "Return OBJECT parent table or nil.
4675 OBJECT is either a `table-cell' or `table-element' type object."
4676 (let ((parent object))
4677 (while (and (setq parent (org-element-property :parent parent))
4678 (not (eq (org-element-type parent) 'table))))
4679 parent))
4681 (defun org-export-get-previous-element (blob info &optional n)
4682 "Return previous element or object.
4684 BLOB is an element or object. INFO is a plist used as
4685 a communication channel. Return previous exportable element or
4686 object, a string, or nil.
4688 When optional argument N is a positive integer, return a list
4689 containing up to N siblings before BLOB, from closest to
4690 farthest. With any other non-nil value, return a list containing
4691 all of them."
4692 (let ((siblings
4693 ;; An object can belong to the contents of its parent or
4694 ;; to a secondary string. We check the latter option
4695 ;; first.
4696 (let ((parent (org-export-get-parent blob)))
4697 (or (and (not (memq (org-element-type blob)
4698 org-element-all-elements))
4699 (let ((sec-value
4700 (org-element-property
4701 (cdr (assq (org-element-type parent)
4702 org-element-secondary-value-alist))
4703 parent)))
4704 (and (memq blob sec-value) sec-value)))
4705 (org-element-contents parent))))
4706 prev)
4707 (catch 'exit
4708 (mapc (lambda (obj)
4709 (cond ((memq obj (plist-get info :ignore-list)))
4710 ((null n) (throw 'exit obj))
4711 ((not (wholenump n)) (push obj prev))
4712 ((zerop n) (throw 'exit (nreverse prev)))
4713 (t (decf n) (push obj prev))))
4714 (cdr (memq blob (reverse siblings))))
4715 (nreverse prev))))
4717 (defun org-export-get-next-element (blob info &optional n)
4718 "Return next element or object.
4720 BLOB is an element or object. INFO is a plist used as
4721 a communication channel. Return next exportable element or
4722 object, a string, or nil.
4724 When optional argument N is a positive integer, return a list
4725 containing up to N siblings after BLOB, from closest to farthest.
4726 With any other non-nil value, return a list containing all of
4727 them."
4728 (let ((siblings
4729 ;; An object can belong to the contents of its parent or to
4730 ;; a secondary string. We check the latter option first.
4731 (let ((parent (org-export-get-parent blob)))
4732 (or (and (not (memq (org-element-type blob)
4733 org-element-all-objects))
4734 (let ((sec-value
4735 (org-element-property
4736 (cdr (assq (org-element-type parent)
4737 org-element-secondary-value-alist))
4738 parent)))
4739 (cdr (memq blob sec-value))))
4740 (cdr (memq blob (org-element-contents parent))))))
4741 next)
4742 (catch 'exit
4743 (mapc (lambda (obj)
4744 (cond ((memq obj (plist-get info :ignore-list)))
4745 ((null n) (throw 'exit obj))
4746 ((not (wholenump n)) (push obj next))
4747 ((zerop n) (throw 'exit (nreverse next)))
4748 (t (decf n) (push obj next))))
4749 siblings)
4750 (nreverse next))))
4753 ;;;; Translation
4755 ;; `org-export-translate' translates a string according to language
4756 ;; specified by LANGUAGE keyword or `org-export-language-setup'
4757 ;; variable and a specified charset. `org-export-dictionary' contains
4758 ;; the dictionary used for the translation.
4760 (defconst org-export-dictionary
4761 '(("Author"
4762 ("ca" :default "Autor")
4763 ("cs" :default "Autor")
4764 ("da" :default "Ophavsmand")
4765 ("de" :default "Autor")
4766 ("eo" :html "A&#365;toro")
4767 ("es" :default "Autor")
4768 ("fi" :html "Tekij&auml;")
4769 ("fr" :default "Auteur")
4770 ("hu" :default "Szerz&otilde;")
4771 ("is" :html "H&ouml;fundur")
4772 ("it" :default "Autore")
4773 ("ja" :html "&#33879;&#32773;" :utf-8 "著者")
4774 ("nl" :default "Auteur")
4775 ("no" :default "Forfatter")
4776 ("nb" :default "Forfatter")
4777 ("nn" :default "Forfattar")
4778 ("pl" :default "Autor")
4779 ("ru" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
4780 ("sv" :html "F&ouml;rfattare")
4781 ("uk" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
4782 ("zh-CN" :html "&#20316;&#32773;" :utf-8 "作者")
4783 ("zh-TW" :html "&#20316;&#32773;" :utf-8 "作者"))
4784 ("Date"
4785 ("ca" :default "Data")
4786 ("cs" :default "Datum")
4787 ("da" :default "Dato")
4788 ("de" :default "Datum")
4789 ("eo" :default "Dato")
4790 ("es" :default "Fecha")
4791 ("fi" :html "P&auml;iv&auml;m&auml;&auml;r&auml;")
4792 ("hu" :html "D&aacute;tum")
4793 ("is" :default "Dagsetning")
4794 ("it" :default "Data")
4795 ("ja" :html "&#26085;&#20184;" :utf-8 "日付")
4796 ("nl" :default "Datum")
4797 ("no" :default "Dato")
4798 ("nb" :default "Dato")
4799 ("nn" :default "Dato")
4800 ("pl" :default "Data")
4801 ("ru" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
4802 ("sv" :default "Datum")
4803 ("uk" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
4804 ("zh-CN" :html "&#26085;&#26399;" :utf-8 "日期")
4805 ("zh-TW" :html "&#26085;&#26399;" :utf-8 "日期"))
4806 ("Equation"
4807 ("fr" :ascii "Equation" :default "Équation"))
4808 ("Figure")
4809 ("Footnotes"
4810 ("ca" :html "Peus de p&agrave;gina")
4811 ("cs" :default "Pozn\xe1mky pod carou")
4812 ("da" :default "Fodnoter")
4813 ("de" :html "Fu&szlig;noten")
4814 ("eo" :default "Piednotoj")
4815 ("es" :html "Pies de p&aacute;gina")
4816 ("fi" :default "Alaviitteet")
4817 ("fr" :default "Notes de bas de page")
4818 ("hu" :html "L&aacute;bjegyzet")
4819 ("is" :html "Aftanm&aacute;lsgreinar")
4820 ("it" :html "Note a pi&egrave; di pagina")
4821 ("ja" :html "&#33050;&#27880;" :utf-8 "脚注")
4822 ("nl" :default "Voetnoten")
4823 ("no" :default "Fotnoter")
4824 ("nb" :default "Fotnoter")
4825 ("nn" :default "Fotnotar")
4826 ("pl" :default "Przypis")
4827 ("ru" :html "&#1057;&#1085;&#1086;&#1089;&#1082;&#1080;" :utf-8 "Сноски")
4828 ("sv" :default "Fotnoter")
4829 ("uk" :html "&#1055;&#1088;&#1080;&#1084;&#1110;&#1090;&#1082;&#1080;"
4830 :utf-8 "Примітки")
4831 ("zh-CN" :html "&#33050;&#27880;" :utf-8 "脚注")
4832 ("zh-TW" :html "&#33139;&#35387;" :utf-8 "腳註"))
4833 ("List of Listings"
4834 ("fr" :default "Liste des programmes"))
4835 ("List of Tables"
4836 ("fr" :default "Liste des tableaux"))
4837 ("Listing %d:"
4838 ("fr"
4839 :ascii "Programme %d :" :default "Programme nº %d :"
4840 :latin1 "Programme %d :"))
4841 ("Listing %d: %s"
4842 ("fr"
4843 :ascii "Programme %d : %s" :default "Programme nº %d : %s"
4844 :latin1 "Programme %d : %s"))
4845 ("See section %s"
4846 ("fr" :default "cf. section %s"))
4847 ("Table %d:"
4848 ("fr"
4849 :ascii "Tableau %d :" :default "Tableau nº %d :" :latin1 "Tableau %d :"))
4850 ("Table %d: %s"
4851 ("fr"
4852 :ascii "Tableau %d : %s" :default "Tableau nº %d : %s"
4853 :latin1 "Tableau %d : %s"))
4854 ("Table of Contents"
4855 ("ca" :html "&Iacute;ndex")
4856 ("cs" :default "Obsah")
4857 ("da" :default "Indhold")
4858 ("de" :default "Inhaltsverzeichnis")
4859 ("eo" :default "Enhavo")
4860 ("es" :html "&Iacute;ndice")
4861 ("fi" :html "Sis&auml;llysluettelo")
4862 ("fr" :ascii "Sommaire" :default "Table des matières")
4863 ("hu" :html "Tartalomjegyz&eacute;k")
4864 ("is" :default "Efnisyfirlit")
4865 ("it" :default "Indice")
4866 ("ja" :html "&#30446;&#27425;" :utf-8 "目次")
4867 ("nl" :default "Inhoudsopgave")
4868 ("no" :default "Innhold")
4869 ("nb" :default "Innhold")
4870 ("nn" :default "Innhald")
4871 ("pl" :html "Spis tre&#x015b;ci")
4872 ("ru" :html "&#1057;&#1086;&#1076;&#1077;&#1088;&#1078;&#1072;&#1085;&#1080;&#1077;"
4873 :utf-8 "Содержание")
4874 ("sv" :html "Inneh&aring;ll")
4875 ("uk" :html "&#1047;&#1084;&#1110;&#1089;&#1090;" :utf-8 "Зміст")
4876 ("zh-CN" :html "&#30446;&#24405;" :utf-8 "目录")
4877 ("zh-TW" :html "&#30446;&#37636;" :utf-8 "目錄"))
4878 ("Unknown reference"
4879 ("fr" :ascii "Destination inconnue" :default "Référence inconnue")))
4880 "Dictionary for export engine.
4882 Alist whose CAR is the string to translate and CDR is an alist
4883 whose CAR is the language string and CDR is a plist whose
4884 properties are possible charsets and values translated terms.
4886 It is used as a database for `org-export-translate'. Since this
4887 function returns the string as-is if no translation was found,
4888 the variable only needs to record values different from the
4889 entry.")
4891 (defun org-export-translate (s encoding info)
4892 "Translate string S according to language specification.
4894 ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
4895 and `:utf-8'. INFO is a plist used as a communication channel.
4897 Translation depends on `:language' property. Return the
4898 translated string. If no translation is found, try to fall back
4899 to `:default' encoding. If it fails, return S."
4900 (let* ((lang (plist-get info :language))
4901 (translations (cdr (assoc lang
4902 (cdr (assoc s org-export-dictionary))))))
4903 (or (plist-get translations encoding)
4904 (plist-get translations :default)
4905 s)))
4909 ;;; Asynchronous Export
4911 ;; `org-export-async-start' is the entry point for asynchronous
4912 ;; export. It recreates current buffer (including visibility,
4913 ;; narrowing and visited file) in an external Emacs process, and
4914 ;; evaluates a command there. It then applies a function on the
4915 ;; returned results in the current process.
4917 ;; Asynchronously generated results are never displayed directly.
4918 ;; Instead, they are stored in `org-export-stack-contents'. They can
4919 ;; then be retrieved by calling `org-export-stack'.
4921 ;; Export Stack is viewed through a dedicated major mode
4922 ;;`org-export-stack-mode' and tools: `org-export--stack-refresh',
4923 ;;`org-export--stack-delete', `org-export--stack-view' and
4924 ;;`org-export--stack-clear'.
4926 ;; For back-ends, `org-export-add-to-stack' add a new source to stack.
4927 ;; It should used whenever `org-export-async-start' is called.
4929 (defmacro org-export-async-start (fun &rest body)
4930 "Call function FUN on the results returned by BODY evaluation.
4932 BODY evaluation happens in an asynchronous process, from a buffer
4933 which is an exact copy of the current one.
4935 Use `org-export-add-to-stack' in FUN in order to register results
4936 in the stack. Examples for, respectively a temporary buffer and
4937 a file are:
4939 \(org-export-async-start
4940 \(lambda (output)
4941 \(with-current-buffer (get-buffer-create \"*Org BACKEND Export*\")
4942 \(erase-buffer)
4943 \(insert output)
4944 \(goto-char (point-min))
4945 \(org-export-add-to-stack (current-buffer) 'backend)))
4946 `(org-export-as 'backend ,subtreep ,visible-only ,body-only ',ext-plist))
4950 \(org-export-async-start
4951 \(lambda (f) (org-export-add-to-stack f 'backend))
4952 `(expand-file-name
4953 \(org-export-to-file
4954 'backend ,outfile ,subtreep ,visible-only ,body-only ',ext-plist)))"
4955 (declare (indent 1) (debug t))
4956 (org-with-gensyms (process temp-file copy-fun proc-buffer handler)
4957 ;; Write the full sexp evaluating BODY in a copy of the current
4958 ;; buffer to a temporary file, as it may be too long for program
4959 ;; args in `start-process'.
4960 `(with-temp-message "Initializing asynchronous export process"
4961 (let ((,copy-fun (org-export--generate-copy-script (current-buffer)))
4962 (,temp-file (make-temp-file "org-export-process")))
4963 (with-temp-file ,temp-file
4964 (insert
4965 (format
4966 "%S"
4967 `(with-temp-buffer
4968 ,(when org-export-async-debug '(setq debug-on-error t))
4969 ;; Initialize `org-mode' in the external process.
4970 (org-mode)
4971 ;; Re-create current buffer there.
4972 (funcall ,,copy-fun)
4973 (restore-buffer-modified-p nil)
4974 ;; Sexp to evaluate in the buffer.
4975 (print (progn ,,@body))))))
4976 ;; Start external process.
4977 (let* ((process-connection-type nil)
4978 (,proc-buffer (generate-new-buffer-name "*Org Export Process*"))
4979 (,process
4980 (start-process
4981 "org-export-process" ,proc-buffer
4982 (expand-file-name invocation-name invocation-directory)
4983 "-Q" "--batch"
4984 "-l" org-export-async-init-file
4985 "-l" ,temp-file)))
4986 ;; Register running process in stack.
4987 (org-export-add-to-stack (get-buffer ,proc-buffer) nil ,process)
4988 ;; Set-up sentinel in order to catch results.
4989 (set-process-sentinel
4990 ,process
4991 (let ((handler #',fun))
4992 `(lambda (p status)
4993 (let ((proc-buffer (process-buffer p)))
4994 (when (eq (process-status p) 'exit)
4995 (unwind-protect
4996 (if (zerop (process-exit-status p))
4997 (unwind-protect
4998 (let ((results
4999 (with-current-buffer proc-buffer
5000 (goto-char (point-max))
5001 (backward-sexp)
5002 (read (current-buffer)))))
5003 (funcall ,handler results))
5004 (unless org-export-async-debug
5005 (and (get-buffer proc-buffer)
5006 (kill-buffer proc-buffer))))
5007 (org-export-add-to-stack proc-buffer nil p)
5008 (ding)
5009 (message "Process '%s' exited abnormally" p))
5010 (unless org-export-async-debug
5011 (delete-file ,,temp-file)))))))))))))
5013 (defun org-export-add-to-stack (source backend &optional process)
5014 "Add a new result to export stack if not present already.
5016 SOURCE is a buffer or a file name containing export results.
5017 BACKEND is a symbol representing export back-end used to generate
5020 Entries already pointing to SOURCE and unavailable entries are
5021 removed beforehand. Return the new stack."
5022 (setq org-export-stack-contents
5023 (cons (list source backend (or process (current-time)))
5024 (org-export--stack-remove source))))
5026 (defun org-export-stack ()
5027 "Menu for asynchronous export results and running processes."
5028 (interactive)
5029 (let ((buffer (get-buffer-create "*Org Export Stack*")))
5030 (set-buffer buffer)
5031 (when (zerop (buffer-size)) (org-export-stack-mode))
5032 (org-export--stack-refresh)
5033 (pop-to-buffer buffer))
5034 (message "Type \"q\" to quit, \"?\" for help"))
5036 (defun org-export--stack-source-at-point ()
5037 "Return source from export results at point in stack."
5038 (let ((source (car (nth (1- (org-current-line)) org-export-stack-contents))))
5039 (if (not source) (error "Source unavailable, please refresh buffer")
5040 (let ((source-name (if (stringp source) source (buffer-name source))))
5041 (if (save-excursion
5042 (beginning-of-line)
5043 (looking-at (concat ".* +" (regexp-quote source-name) "$")))
5044 source
5045 ;; SOURCE is not consistent with current line. The stack
5046 ;; view is outdated.
5047 (error "Source unavailable; type `g' to update buffer"))))))
5049 (defun org-export--stack-clear ()
5050 "Remove all entries from export stack."
5051 (interactive)
5052 (setq org-export-stack-contents nil))
5054 (defun org-export--stack-refresh (&rest dummy)
5055 "Refresh the asynchronous export stack.
5056 DUMMY is ignored. Unavailable sources are removed from the list.
5057 Return the new stack."
5058 (let ((inhibit-read-only t))
5059 (org-preserve-lc
5060 (erase-buffer)
5061 (insert (concat
5062 (let ((counter 0))
5063 (mapconcat
5064 (lambda (entry)
5065 (let ((proc-p (processp (nth 2 entry))))
5066 (concat
5067 ;; Back-end.
5068 (format " %-12s " (or (nth 1 entry) ""))
5069 ;; Age.
5070 (let ((data (nth 2 entry)))
5071 (if proc-p (format " %6s " (process-status data))
5072 ;; Compute age of the results.
5073 (org-format-seconds
5074 "%4h:%.2m "
5075 (float-time (time-since data)))))
5076 ;; Source.
5077 (format " %s"
5078 (let ((source (car entry)))
5079 (if (stringp source) source
5080 (buffer-name source)))))))
5081 ;; Clear stack from exited processes, dead buffers or
5082 ;; non-existent files.
5083 (setq org-export-stack-contents
5084 (org-remove-if-not
5085 (lambda (el)
5086 (if (processp (nth 2 el))
5087 (buffer-live-p (process-buffer (nth 2 el)))
5088 (let ((source (car el)))
5089 (if (bufferp source) (buffer-live-p source)
5090 (file-exists-p source)))))
5091 org-export-stack-contents)) "\n")))))))
5093 (defun org-export--stack-remove (&optional source)
5094 "Remove export results at point from stack.
5095 If optional argument SOURCE is non-nil, remove it instead."
5096 (interactive)
5097 (let ((source (or source (org-export--stack-source-at-point))))
5098 (setq org-export-stack-contents
5099 (org-remove-if (lambda (el) (equal (car el) source))
5100 org-export-stack-contents))))
5102 (defun org-export--stack-view (&optional in-emacs)
5103 "View export results at point in stack.
5104 With an optional prefix argument IN-EMACS, force viewing files
5105 within Emacs."
5106 (interactive "P")
5107 (let ((source (org-export--stack-source-at-point)))
5108 (cond ((processp source)
5109 (org-switch-to-buffer-other-window (process-buffer source)))
5110 ((bufferp source) (org-switch-to-buffer-other-window source))
5111 (t (org-open-file source in-emacs)))))
5113 (defconst org-export-stack-mode-map
5114 (let ((km (make-sparse-keymap)))
5115 (define-key km " " 'next-line)
5116 (define-key km "n" 'next-line)
5117 (define-key km "\C-n" 'next-line)
5118 (define-key km [down] 'next-line)
5119 (define-key km "p" 'previous-line)
5120 (define-key km "\C-p" 'previous-line)
5121 (define-key km "\C-?" 'previous-line)
5122 (define-key km [up] 'previous-line)
5123 (define-key km "C" 'org-export--stack-clear)
5124 (define-key km "v" 'org-export--stack-view)
5125 (define-key km (kbd "RET") 'org-export--stack-view)
5126 (define-key km "d" 'org-export--stack-remove)
5128 "Keymap for Org Export Stack.")
5130 (define-derived-mode org-export-stack-mode special-mode "Org-Stack"
5131 "Mode for displaying asynchronous export stack.
5133 Type \\[org-export-stack] to visualize the asynchronous export
5134 stack.
5136 In an Org Export Stack buffer, use \\<org-export-stack-mode-map>\\[org-export--stack-view] to view export output
5137 on current line, \\[org-export--stack-remove] to remove it from the stack and \\[org-export--stack-clear] to clear
5138 stack completely.
5140 Removal entries in an Org Export Stack buffer doesn't affect
5141 files or buffers, only view in the stack.
5143 \\{org-export-stack-mode-map}"
5144 (abbrev-mode 0)
5145 (auto-fill-mode 0)
5146 (setq buffer-read-only t
5147 buffer-undo-list t
5148 truncate-lines t
5149 header-line-format
5150 '(:eval
5151 (format " %-12s | %6s | %s" "Back-End" "Age" "Source")))
5152 (add-hook 'post-command-hook 'org-export--stack-refresh nil t)
5153 (set (make-local-variable 'revert-buffer-function)
5154 'org-export--stack-refresh))
5158 ;;; The Dispatcher
5160 ;; `org-export-dispatch' is the standard interactive way to start an
5161 ;; export process. It uses `org-export-dispatch-ui' as a subroutine
5162 ;; for its interface, which, in turn, delegates response to key
5163 ;; pressed to `org-export-dispatch-action'.
5165 ;;;###autoload
5166 (defun org-export-dispatch (&optional arg)
5167 "Export dispatcher for Org mode.
5169 It provides an access to common export related tasks in a buffer.
5170 Its interface comes in two flavours: standard and expert. While
5171 both share the same set of bindings, only the former displays the
5172 valid keys associations. Set `org-export-dispatch-use-expert-ui'
5173 to switch to one or the other.
5175 When called with C-u prefix ARG, repeat the last export action,
5176 with the same set of options used back then, on the current
5177 buffer.
5179 When called with a double universal argument, display the
5180 asynchronous export stack directly."
5181 (interactive "P")
5182 (let* ((input
5183 (cond ((equal arg '(16)) '(stack))
5184 ((and arg org-export-dispatch-last-action))
5185 (t (save-window-excursion
5186 (unwind-protect
5187 ;; Store this export command.
5188 (setq org-export-dispatch-last-action
5189 (org-export-dispatch-ui
5190 (list org-export-initial-scope
5191 (and org-export-in-background 'async))
5193 org-export-dispatch-use-expert-ui))
5194 (and (get-buffer "*Org Export Dispatcher*")
5195 (kill-buffer "*Org Export Dispatcher*")))))))
5196 (action (car input))
5197 (optns (cdr input)))
5198 (case action
5199 ;; First handle special hard-coded actions.
5200 (stack (org-export-stack))
5201 (publish-current-file
5202 (org-e-publish-current-file (memq 'force optns) (memq 'async optns)))
5203 (publish-current-project
5204 (org-e-publish-current-project (memq 'force optns) (memq 'async optns)))
5205 (publish-choose-project
5206 (org-e-publish (assoc (org-icompleting-read
5207 "Publish project: "
5208 org-e-publish-project-alist nil t)
5209 org-e-publish-project-alist)
5210 (memq 'force optns)
5211 (memq 'async optns)))
5212 (publish-all (org-e-publish-all (memq 'force optns) (memq 'async optns)))
5213 (otherwise (funcall action
5214 ;; Return a symbol instead of a list to ease
5215 ;; asynchronous export macro use.
5216 (and (memq 'async optns) t)
5217 (and (memq 'subtree optns) t)
5218 (and (memq 'visible optns) t)
5219 (and (memq 'body optns) t))))))
5221 (defun org-export-dispatch-ui (options first-key expertp)
5222 "Handle interface for `org-export-dispatch'.
5224 OPTIONS is a list containing current interactive options set for
5225 export. It can contain any of the following symbols:
5226 `body' toggles a body-only export
5227 `subtree' restricts export to current subtree
5228 `visible' restricts export to visible part of buffer.
5229 `force' force publishing files.
5230 `async' use asynchronous export process
5232 FIRST-KEY is the key pressed to select the first level menu. It
5233 is nil when this menu hasn't been selected yet.
5235 EXPERTP, when non-nil, triggers expert UI. In that case, no help
5236 buffer is provided, but indications about currently active
5237 options are given in the prompt. Moreover, \[?] allows to switch
5238 back to standard interface."
5239 (let* ((fontify-key
5240 (lambda (key &optional access-key)
5241 ;; Fontify KEY string. Optional argument ACCESS-KEY, when
5242 ;; non-nil is the required first-level key to activate
5243 ;; KEY. When its value is t, activate KEY independently
5244 ;; on the first key, if any. A nil value means KEY will
5245 ;; only be activated at first level.
5246 (if (or (eq access-key t) (eq access-key first-key))
5247 (org-add-props key nil 'face 'org-warning)
5248 (org-no-properties key))))
5249 ;; Prepare menu entries by extracting them from
5250 ;; `org-export-registered-backends', and sorting them by
5251 ;; access key and by ordinal, if any.
5252 (backends (sort
5253 (sort
5254 (delq nil
5255 (mapcar (lambda (b)
5256 (org-export-backend-menu (car b)))
5257 org-export-registered-backends))
5258 (lambda (a b)
5259 (let ((key-a (nth 1 a))
5260 (key-b (nth 1 b)))
5261 (cond ((and (numberp key-a) (numberp key-b))
5262 (< key-a key-b))
5263 ((numberp key-b) t)))))
5264 (lambda (a b) (< (car a) (car b)))))
5265 ;; Compute a list of allowed keys based on the first key
5266 ;; pressed, if any. Some keys (?1, ?2, ?3, ?4, ?5 and ?q)
5267 ;; are always available.
5268 (allowed-keys
5269 (nconc (list ?1 ?2 ?3 ?4 ?5)
5270 (if (not first-key) (org-uniquify (mapcar 'car backends))
5271 (let (sub-menu)
5272 (dolist (backend backends (sort (mapcar 'car sub-menu) '<))
5273 (when (eq (car backend) first-key)
5274 (setq sub-menu (append (nth 2 backend) sub-menu))))))
5275 (cond ((eq first-key ?P) (list ?f ?p ?x ?a))
5276 ((not first-key) (list ?P)))
5277 (list ?&)
5278 (when expertp (list ??))
5279 (list ?q)))
5280 ;; Build the help menu for standard UI.
5281 (help
5282 (unless expertp
5283 (concat
5284 ;; Options are hard-coded.
5285 (format "Options
5286 [%s] Body only: %s [%s] Visible only: %s
5287 [%s] Export scope: %s [%s] Force publishing: %s
5288 [%s] Asynchronous export: %s\n"
5289 (funcall fontify-key "1" t)
5290 (if (memq 'body options) "On " "Off")
5291 (funcall fontify-key "2" t)
5292 (if (memq 'visible options) "On " "Off")
5293 (funcall fontify-key "3" t)
5294 (if (memq 'subtree options) "Subtree" "Buffer ")
5295 (funcall fontify-key "4" t)
5296 (if (memq 'force options) "On " "Off")
5297 (funcall fontify-key "5" t)
5298 (if (memq 'async options) "On " "Off"))
5299 ;; Display registered back-end entries. When a key
5300 ;; appears for the second time, do not create another
5301 ;; entry, but append its sub-menu to existing menu.
5302 (let (last-key)
5303 (mapconcat
5304 (lambda (entry)
5305 (let ((top-key (car entry)))
5306 (concat
5307 (unless (eq top-key last-key)
5308 (setq last-key top-key)
5309 (format "\n[%s] %s\n"
5310 (funcall fontify-key (char-to-string top-key))
5311 (nth 1 entry)))
5312 (let ((sub-menu (nth 2 entry)))
5313 (unless (functionp sub-menu)
5314 ;; Split sub-menu into two columns.
5315 (let ((index -1))
5316 (concat
5317 (mapconcat
5318 (lambda (sub-entry)
5319 (incf index)
5320 (format
5321 (if (zerop (mod index 2)) " [%s] %-24s"
5322 "[%s] %s\n")
5323 (funcall fontify-key
5324 (char-to-string (car sub-entry))
5325 top-key)
5326 (nth 1 sub-entry)))
5327 sub-menu "")
5328 (when (zerop (mod index 2)) "\n"))))))))
5329 backends ""))
5330 ;; Publishing menu is hard-coded.
5331 (format "\n[%s] Publish
5332 [%s] Current file [%s] Current project
5333 [%s] Choose project [%s] All projects\n\n"
5334 (funcall fontify-key "P")
5335 (funcall fontify-key "f" ?P)
5336 (funcall fontify-key "p" ?P)
5337 (funcall fontify-key "x" ?P)
5338 (funcall fontify-key "a" ?P))
5339 (format "\[%s] Export stack\n" (funcall fontify-key "&" t))
5340 (format "\[%s] %s"
5341 (funcall fontify-key "q" t)
5342 (if first-key "Main menu" "Exit")))))
5343 ;; Build prompts for both standard and expert UI.
5344 (standard-prompt (unless expertp "Export command: "))
5345 (expert-prompt
5346 (when expertp
5347 (format
5348 "Export command (Options: %s%s%s%s%s) [%s]: "
5349 (if (memq 'body options) (funcall fontify-key "b" t) "-")
5350 (if (memq 'visible options) (funcall fontify-key "v" t) "-")
5351 (if (memq 'subtree options) (funcall fontify-key "s" t) "-")
5352 (if (memq 'force options) (funcall fontify-key "f" t) "-")
5353 (if (memq 'async options) (funcall fontify-key "a" t) "-")
5354 (concat allowed-keys)))))
5355 ;; With expert UI, just read key with a fancy prompt. In standard
5356 ;; UI, display an intrusive help buffer.
5357 (if expertp
5358 (org-export-dispatch-action
5359 expert-prompt allowed-keys backends options first-key expertp)
5360 ;; At first call, create frame layout in order to display menu.
5361 (unless (get-buffer "*Org Export Dispatcher*")
5362 (delete-other-windows)
5363 (org-switch-to-buffer-other-window
5364 (get-buffer-create "*Org Export Dispatcher*"))
5365 (setq cursor-type nil))
5366 ;; At this point, the buffer containing the menu exists and is
5367 ;; visible in the current window. So, refresh it.
5368 (with-current-buffer "*Org Export Dispatcher*"
5369 (erase-buffer)
5370 (insert help))
5371 (org-fit-window-to-buffer)
5372 (org-export-dispatch-action
5373 standard-prompt allowed-keys backends options first-key expertp))))
5375 (defun org-export-dispatch-action
5376 (prompt allowed-keys backends options first-key expertp)
5377 "Read a character from command input and act accordingly.
5379 PROMPT is the displayed prompt, as a string. ALLOWED-KEYS is
5380 a list of characters available at a given step in the process.
5381 BACKENDS is a list of menu entries. OPTIONS, FIRST-KEY and
5382 EXPERTP are the same as defined in `org-export-dispatch-ui',
5383 which see.
5385 Toggle export options when required. Otherwise, return value is
5386 a list with action as CAR and a list of interactive export
5387 options as CDR."
5388 (let ((key (let ((k (read-char-exclusive prompt)))
5389 ;; Translate "C-a", "C-b"... into "a", "b"... Then take action
5390 ;; depending on user's key pressed.
5391 (if (< k 27) (+ k 96) k))))
5392 (cond
5393 ;; Ignore non-standard characters (i.e. "M-a") and
5394 ;; undefined associations.
5395 ((not (memq key allowed-keys))
5396 (ding)
5397 (unless expertp (message "Invalid key") (sit-for 1))
5398 (org-export-dispatch-ui options first-key expertp))
5399 ;; q key at first level aborts export. At second
5400 ;; level, cancel first key instead.
5401 ((eq key ?q) (if (not first-key) (error "Export aborted")
5402 (org-export-dispatch-ui options nil expertp)))
5403 ;; Help key: Switch back to standard interface if
5404 ;; expert UI was active.
5405 ((eq key ??) (org-export-dispatch-ui options first-key nil))
5406 ;; Switch to asynchronous export stack.
5407 ((eq key ?&) '(stack))
5408 ;; Toggle export options.
5409 ((memq key '(?1 ?2 ?3 ?4 ?5))
5410 (org-export-dispatch-ui
5411 (let ((option (case key (?1 'body) (?2 'visible) (?3 'subtree)
5412 (?4 'force) (?5 'async))))
5413 (if (memq option options) (remq option options)
5414 (cons option options)))
5415 first-key expertp))
5416 ;; Action selected: Send key and options back to
5417 ;; `org-export-dispatch'.
5418 ((or first-key (functionp (nth 2 (assq key backends))))
5419 (cons (cond
5420 ((not first-key) (nth 2 (assq key backends)))
5421 ;; Publishing actions are hard-coded. Send a special
5422 ;; signal to `org-export-dispatch'.
5423 ((eq first-key ?P)
5424 (case key
5425 (?f 'publish-current-file)
5426 (?p 'publish-current-project)
5427 (?x 'publish-choose-project)
5428 (?a 'publish-all)))
5429 ;; Return first action associated to FIRST-KEY + KEY
5430 ;; path. Indeed, derived backends can share the same
5431 ;; FIRST-KEY.
5432 (t (catch 'found
5433 (mapc (lambda (backend)
5434 (let ((match (assq key (nth 2 backend))))
5435 (when match (throw 'found (nth 2 match)))))
5436 (member (assq first-key backends) backends)))))
5437 options))
5438 ;; Otherwise, enter sub-menu.
5439 (t (org-export-dispatch-ui options key expertp)))))
5442 (provide 'org-export)
5443 ;;; org-export.el ends here