ox: Fix 8c833ed9fbabae298054dd9eec574984acf3ab8b
[org-mode.git] / lisp / ox.el
blob8c68cdac42421cfbada4803cfd9f9645e8c8df5a
1 ;;; ox.el --- Generic Export Engine for Org Mode
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 ;; GNU Emacs 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 ;; GNU Emacs 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 GNU Emacs. 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 the 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 'org-macro)
82 (require 'ob-exp)
84 (declare-function org-publish "ox-publish" (project &optional force async))
85 (declare-function org-publish-all "ox-publish" (&optional force async))
86 (declare-function
87 org-publish-current-file "ox-publish" (&optional force async))
88 (declare-function org-publish-current-project "ox-publish"
89 (&optional force async))
91 (defvar org-publish-project-alist)
92 (defvar org-table-number-fraction)
93 (defvar org-table-number-regexp)
97 ;;; Internal Variables
99 ;; Among internal variables, the most important is
100 ;; `org-export-options-alist'. This variable define the global export
101 ;; options, shared between every exporter, and how they are acquired.
103 (defconst org-export-max-depth 19
104 "Maximum nesting depth for headlines, counting from 0.")
106 (defconst org-export-options-alist
107 '((:author "AUTHOR" nil user-full-name t)
108 (:creator "CREATOR" nil org-export-creator-string)
109 (:date "DATE" nil nil t)
110 (:description "DESCRIPTION" nil nil newline)
111 (:email "EMAIL" nil user-mail-address t)
112 (:exclude-tags "EXCLUDE_TAGS" nil org-export-exclude-tags split)
113 (:headline-levels nil "H" org-export-headline-levels)
114 (:keywords "KEYWORDS" nil nil space)
115 (:language "LANGUAGE" nil org-export-default-language t)
116 (:preserve-breaks nil "\\n" org-export-preserve-breaks)
117 (:section-numbers nil "num" org-export-with-section-numbers)
118 (:select-tags "SELECT_TAGS" nil org-export-select-tags split)
119 (:time-stamp-file nil "timestamp" org-export-time-stamp-file)
120 (:title "TITLE" nil nil space)
121 (:with-archived-trees nil "arch" org-export-with-archived-trees)
122 (:with-author nil "author" org-export-with-author)
123 (:with-clocks nil "c" org-export-with-clocks)
124 (:with-creator nil "creator" org-export-with-creator)
125 (:with-date nil "date" org-export-with-date)
126 (:with-drawers nil "d" org-export-with-drawers)
127 (:with-email nil "email" org-export-with-email)
128 (:with-emphasize nil "*" org-export-with-emphasize)
129 (:with-entities nil "e" org-export-with-entities)
130 (:with-fixed-width nil ":" org-export-with-fixed-width)
131 (:with-footnotes nil "f" org-export-with-footnotes)
132 (:with-inlinetasks nil "inline" org-export-with-inlinetasks)
133 (:with-latex nil "tex" org-export-with-latex)
134 (:with-planning nil "p" org-export-with-planning)
135 (:with-priority nil "pri" org-export-with-priority)
136 (:with-smart-quotes nil "'" org-export-with-smart-quotes)
137 (:with-special-strings nil "-" org-export-with-special-strings)
138 (:with-statistics-cookies nil "stat" org-export-with-statistics-cookies)
139 (:with-sub-superscript nil "^" org-export-with-sub-superscripts)
140 (:with-toc nil "toc" org-export-with-toc)
141 (:with-tables nil "|" org-export-with-tables)
142 (:with-tags nil "tags" org-export-with-tags)
143 (:with-tasks nil "tasks" org-export-with-tasks)
144 (:with-timestamps nil "<" org-export-with-timestamps)
145 (:with-todo-keywords nil "todo" org-export-with-todo-keywords))
146 "Alist between export properties and ways to set them.
148 The CAR of the alist is the property name, and the CDR is a list
149 like (KEYWORD OPTION DEFAULT BEHAVIOUR) where:
151 KEYWORD is a string representing a buffer keyword, or nil. Each
152 property defined this way can also be set, during subtree
153 export, through a headline property named after the keyword
154 with the \"EXPORT_\" prefix (i.e. DATE keyword and EXPORT_DATE
155 property).
156 OPTION is a string that could be found in an #+OPTIONS: line.
157 DEFAULT is the default value for the property.
158 BEHAVIOUR determines how Org should handle multiple keywords for
159 the same property. It is a symbol among:
160 nil Keep old value and discard the new one.
161 t Replace old value with the new one.
162 `space' Concatenate the values, separating them with a space.
163 `newline' Concatenate the values, separating them with
164 a newline.
165 `split' Split values at white spaces, and cons them to the
166 previous list.
168 Values set through KEYWORD and OPTION have precedence over
169 DEFAULT.
171 All these properties should be back-end agnostic. Back-end
172 specific properties are set through `org-export-define-backend'.
173 Properties redefined there have precedence over these.")
175 (defconst org-export-special-keywords '("FILETAGS" "SETUPFILE" "OPTIONS")
176 "List of in-buffer keywords that require special treatment.
177 These keywords are not directly associated to a property. The
178 way they are handled must be hard-coded into
179 `org-export--get-inbuffer-options' function.")
181 (defconst org-export-filters-alist
182 '((:filter-bold . org-export-filter-bold-functions)
183 (:filter-babel-call . org-export-filter-babel-call-functions)
184 (:filter-center-block . org-export-filter-center-block-functions)
185 (:filter-clock . org-export-filter-clock-functions)
186 (:filter-code . org-export-filter-code-functions)
187 (:filter-comment . org-export-filter-comment-functions)
188 (:filter-comment-block . org-export-filter-comment-block-functions)
189 (:filter-diary-sexp . org-export-filter-diary-sexp-functions)
190 (:filter-drawer . org-export-filter-drawer-functions)
191 (:filter-dynamic-block . org-export-filter-dynamic-block-functions)
192 (:filter-entity . org-export-filter-entity-functions)
193 (:filter-example-block . org-export-filter-example-block-functions)
194 (:filter-export-block . org-export-filter-export-block-functions)
195 (:filter-export-snippet . org-export-filter-export-snippet-functions)
196 (:filter-final-output . org-export-filter-final-output-functions)
197 (:filter-fixed-width . org-export-filter-fixed-width-functions)
198 (:filter-footnote-definition . org-export-filter-footnote-definition-functions)
199 (:filter-footnote-reference . org-export-filter-footnote-reference-functions)
200 (:filter-headline . org-export-filter-headline-functions)
201 (:filter-horizontal-rule . org-export-filter-horizontal-rule-functions)
202 (:filter-inline-babel-call . org-export-filter-inline-babel-call-functions)
203 (:filter-inline-src-block . org-export-filter-inline-src-block-functions)
204 (:filter-inlinetask . org-export-filter-inlinetask-functions)
205 (:filter-italic . org-export-filter-italic-functions)
206 (:filter-item . org-export-filter-item-functions)
207 (:filter-keyword . org-export-filter-keyword-functions)
208 (:filter-latex-environment . org-export-filter-latex-environment-functions)
209 (:filter-latex-fragment . org-export-filter-latex-fragment-functions)
210 (:filter-line-break . org-export-filter-line-break-functions)
211 (:filter-link . org-export-filter-link-functions)
212 (:filter-node-property . org-export-filter-node-property-functions)
213 (:filter-options . org-export-filter-options-functions)
214 (:filter-paragraph . org-export-filter-paragraph-functions)
215 (:filter-parse-tree . org-export-filter-parse-tree-functions)
216 (:filter-plain-list . org-export-filter-plain-list-functions)
217 (:filter-plain-text . org-export-filter-plain-text-functions)
218 (:filter-planning . org-export-filter-planning-functions)
219 (:filter-property-drawer . org-export-filter-property-drawer-functions)
220 (:filter-quote-block . org-export-filter-quote-block-functions)
221 (:filter-quote-section . org-export-filter-quote-section-functions)
222 (:filter-radio-target . org-export-filter-radio-target-functions)
223 (:filter-section . org-export-filter-section-functions)
224 (:filter-special-block . org-export-filter-special-block-functions)
225 (:filter-src-block . org-export-filter-src-block-functions)
226 (:filter-statistics-cookie . org-export-filter-statistics-cookie-functions)
227 (:filter-strike-through . org-export-filter-strike-through-functions)
228 (:filter-subscript . org-export-filter-subscript-functions)
229 (:filter-superscript . org-export-filter-superscript-functions)
230 (:filter-table . org-export-filter-table-functions)
231 (:filter-table-cell . org-export-filter-table-cell-functions)
232 (:filter-table-row . org-export-filter-table-row-functions)
233 (:filter-target . org-export-filter-target-functions)
234 (:filter-timestamp . org-export-filter-timestamp-functions)
235 (:filter-underline . org-export-filter-underline-functions)
236 (:filter-verbatim . org-export-filter-verbatim-functions)
237 (:filter-verse-block . org-export-filter-verse-block-functions))
238 "Alist between filters properties and initial values.
240 The key of each association is a property name accessible through
241 the communication channel. Its value is a configurable global
242 variable defining initial filters.
244 This list is meant to install user specified filters. Back-end
245 developers may install their own filters using
246 `org-export-define-backend'. Filters defined there will always
247 be prepended to the current list, so they always get applied
248 first.")
250 (defconst org-export-default-inline-image-rule
251 `(("file" .
252 ,(format "\\.%s\\'"
253 (regexp-opt
254 '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
255 "xpm" "pbm" "pgm" "ppm") t))))
256 "Default rule for link matching an inline image.
257 This rule applies to links with no description. By default, it
258 will be considered as an inline image if it targets a local file
259 whose extension is either \"png\", \"jpeg\", \"jpg\", \"gif\",
260 \"tiff\", \"tif\", \"xbm\", \"xpm\", \"pbm\", \"pgm\" or \"ppm\".
261 See `org-export-inline-image-p' for more information about
262 rules.")
264 (defvar org-export-async-debug nil
265 "Non-nil means asynchronous export process should leave data behind.
267 This data is found in the appropriate \"*Org Export Process*\"
268 buffer, and in files prefixed with \"org-export-process\" and
269 located in `temporary-file-directory'.
271 When non-nil, it will also set `debug-on-error' to a non-nil
272 value in the external process.")
274 (defvar org-export-stack-contents nil
275 "Record asynchronously generated export results and processes.
276 This is an alist: its CAR is the source of the
277 result (destination file or buffer for a finished process,
278 original buffer for a running one) and its CDR is a list
279 containing the back-end used, as a symbol, and either a process
280 or the time at which it finished. It is used to build the menu
281 from `org-export-stack'.")
283 (defvar org-export-registered-backends nil
284 "List of backends currently available in the exporter.
286 A backend is stored as a list where CAR is its name, as a symbol,
287 and CDR is a plist with the following properties:
288 `:filters-alist', `:menu-entry', `:options-alist' and
289 `:translate-alist'.
291 This variable is set with `org-export-define-backend' and
292 `org-export-define-derived-backend' functions.")
294 (defvar org-export-dispatch-last-action nil
295 "Last command called from the dispatcher.
296 The value should be a list. Its CAR is the action, as a symbol,
297 and its CDR is a list of export options.")
299 (defvar org-export-dispatch-last-position (make-marker)
300 "The position where the last export command was created using the dispatcher.
301 This marker will be used with `C-u C-c C-e' to make sure export repetition
302 uses the same subtree if the previous command was restricted to a subtree.")
304 ;; For compatibility with Org < 8
305 (defvar org-export-current-backend nil
306 "Name, if any, of the back-end used during an export process.
308 Its value is a symbol such as `html', `latex', `ascii', or nil if
309 the back-end is anonymous (see `org-export-create-backend') or if
310 there is no export process in progress.
312 It can be used to teach Babel blocks how to act differently
313 according to the back-end used.")
316 ;;; User-configurable Variables
318 ;; Configuration for the masses.
320 ;; They should never be accessed directly, as their value is to be
321 ;; stored in a property list (cf. `org-export-options-alist').
322 ;; Back-ends will read their value from there instead.
324 (defgroup org-export nil
325 "Options for exporting Org mode files."
326 :tag "Org Export"
327 :group 'org)
329 (defgroup org-export-general nil
330 "General options for export engine."
331 :tag "Org Export General"
332 :group 'org-export)
334 (defcustom org-export-with-archived-trees 'headline
335 "Whether sub-trees with the ARCHIVE tag should be exported.
337 This can have three different values:
338 nil Do not export, pretend this tree is not present.
339 t Do export the entire tree.
340 `headline' Only export the headline, but skip the tree below it.
342 This option can also be set with the OPTIONS keyword,
343 e.g. \"arch:nil\"."
344 :group 'org-export-general
345 :type '(choice
346 (const :tag "Not at all" nil)
347 (const :tag "Headline only" 'headline)
348 (const :tag "Entirely" t)))
350 (defcustom org-export-with-author t
351 "Non-nil means insert author name into the exported file.
352 This option can also be set with the OPTIONS keyword,
353 e.g. \"author:nil\"."
354 :group 'org-export-general
355 :type 'boolean)
357 (defcustom org-export-with-clocks nil
358 "Non-nil means export CLOCK keywords.
359 This option can also be set with the OPTIONS keyword,
360 e.g. \"c:t\"."
361 :group 'org-export-general
362 :type 'boolean)
364 (defcustom org-export-with-creator 'comment
365 "Non-nil means the postamble should contain a creator sentence.
367 The sentence can be set in `org-export-creator-string' and
368 defaults to \"Generated by Org mode XX in Emacs XXX.\".
370 If the value is `comment' insert it as a comment."
371 :group 'org-export-general
372 :type '(choice
373 (const :tag "No creator sentence" nil)
374 (const :tag "Sentence as a comment" 'comment)
375 (const :tag "Insert the sentence" t)))
377 (defcustom org-export-with-date t
378 "Non-nil means insert date in the exported document.
379 This option can also be set with the OPTIONS keyword,
380 e.g. \"date:nil\"."
381 :group 'org-export-general
382 :type 'boolean)
384 (defcustom org-export-date-timestamp-format nil
385 "Time-stamp format string to use for DATE keyword.
387 The format string, when specified, only applies if date consists
388 in a single time-stamp. Otherwise its value will be ignored.
390 See `format-time-string' for details on how to build this
391 string."
392 :group 'org-export-general
393 :type '(choice
394 (string :tag "Time-stamp format string")
395 (const :tag "No format string" nil)))
397 (defcustom org-export-creator-string
398 (format "Emacs %s (Org mode %s)"
399 emacs-version
400 (if (fboundp 'org-version) (org-version) "unknown version"))
401 "Information about the creator of the document.
402 This option can also be set on with the CREATOR keyword."
403 :group 'org-export-general
404 :type '(string :tag "Creator string"))
406 (defcustom org-export-with-drawers '(not "LOGBOOK")
407 "Non-nil means export contents of standard drawers.
409 When t, all drawers are exported. This may also be a list of
410 drawer names to export. If that list starts with `not', only
411 drawers with such names will be ignored.
413 This variable doesn't apply to properties drawers.
415 This option can also be set with the OPTIONS keyword,
416 e.g. \"d:nil\"."
417 :group 'org-export-general
418 :version "24.4"
419 :package-version '(Org . "8.0")
420 :type '(choice
421 (const :tag "All drawers" t)
422 (const :tag "None" nil)
423 (repeat :tag "Selected drawers"
424 (string :tag "Drawer name"))
425 (list :tag "Ignored drawers"
426 (const :format "" not)
427 (repeat :tag "Specify names of drawers to ignore during export"
428 :inline t
429 (string :tag "Drawer name")))))
431 (defcustom org-export-with-email nil
432 "Non-nil means insert author email into the exported file.
433 This option can also be set with the OPTIONS keyword,
434 e.g. \"email:t\"."
435 :group 'org-export-general
436 :type 'boolean)
438 (defcustom org-export-with-emphasize t
439 "Non-nil means interpret *word*, /word/, _word_ and +word+.
441 If the export target supports emphasizing text, the word will be
442 typeset in bold, italic, with an underline or strike-through,
443 respectively.
445 This option can also be set with the OPTIONS keyword,
446 e.g. \"*:nil\"."
447 :group 'org-export-general
448 :type 'boolean)
450 (defcustom org-export-exclude-tags '("noexport")
451 "Tags that exclude a tree from export.
453 All trees carrying any of these tags will be excluded from
454 export. This is without condition, so even subtrees inside that
455 carry one of the `org-export-select-tags' will be removed.
457 This option can also be set with the EXCLUDE_TAGS keyword."
458 :group 'org-export-general
459 :type '(repeat (string :tag "Tag")))
461 (defcustom org-export-with-fixed-width t
462 "Non-nil means lines starting with \":\" will be in fixed width font.
464 This can be used to have pre-formatted text, fragments of code
465 etc. For example:
466 : ;; Some Lisp examples
467 : (while (defc cnt)
468 : (ding))
469 will be looking just like this in also HTML. See also the QUOTE
470 keyword. Not all export backends support this.
472 This option can also be set with the OPTIONS keyword,
473 e.g. \"::nil\"."
474 :group 'org-export-general
475 :type 'boolean)
477 (defcustom org-export-with-footnotes t
478 "Non-nil means Org footnotes should be exported.
479 This option can also be set with the OPTIONS keyword,
480 e.g. \"f:nil\"."
481 :group 'org-export-general
482 :type 'boolean)
484 (defcustom org-export-with-latex t
485 "Non-nil means process LaTeX environments and fragments.
487 This option can also be set with the OPTIONS line,
488 e.g. \"tex:verbatim\". Allowed values are:
490 nil Ignore math snippets.
491 `verbatim' Keep everything in verbatim.
492 t Allow export of math snippets."
493 :group 'org-export-general
494 :version "24.4"
495 :package-version '(Org . "8.0")
496 :type '(choice
497 (const :tag "Do not process math in any way" nil)
498 (const :tag "Interpret math snippets" t)
499 (const :tag "Leave math verbatim" verbatim)))
501 (defcustom org-export-headline-levels 3
502 "The last level which is still exported as a headline.
504 Inferior levels will usually produce itemize or enumerate lists
505 when exported, but back-end behaviour may differ.
507 This option can also be set with the OPTIONS keyword,
508 e.g. \"H:2\"."
509 :group 'org-export-general
510 :type 'integer)
512 (defcustom org-export-default-language "en"
513 "The default language for export and clocktable translations, as a string.
514 This may have an association in
515 `org-clock-clocktable-language-setup'. This option can also be
516 set with the LANGUAGE keyword."
517 :group 'org-export-general
518 :type '(string :tag "Language"))
520 (defcustom org-export-preserve-breaks nil
521 "Non-nil means preserve all line breaks when exporting.
522 This option can also be set with the OPTIONS keyword,
523 e.g. \"\\n:t\"."
524 :group 'org-export-general
525 :type 'boolean)
527 (defcustom org-export-with-entities t
528 "Non-nil means interpret entities when exporting.
530 For example, HTML export converts \\alpha to &alpha; and \\AA to
531 &Aring;.
533 For a list of supported names, see the constant `org-entities'
534 and the user option `org-entities-user'.
536 This option can also be set with the OPTIONS keyword,
537 e.g. \"e:nil\"."
538 :group 'org-export-general
539 :type 'boolean)
541 (defcustom org-export-with-inlinetasks t
542 "Non-nil means inlinetasks should be exported.
543 This option can also be set with the OPTIONS keyword,
544 e.g. \"inline:nil\"."
545 :group 'org-export-general
546 :version "24.4"
547 :package-version '(Org . "8.0")
548 :type 'boolean)
550 (defcustom org-export-with-planning nil
551 "Non-nil means include planning info in export.
553 Planning info is the line containing either SCHEDULED:,
554 DEADLINE:, CLOSED: time-stamps, or a combination of them.
556 This option can also be set with the OPTIONS keyword,
557 e.g. \"p:t\"."
558 :group 'org-export-general
559 :version "24.4"
560 :package-version '(Org . "8.0")
561 :type 'boolean)
563 (defcustom org-export-with-priority nil
564 "Non-nil means include priority cookies in export.
565 This option can also be set with the OPTIONS keyword,
566 e.g. \"pri:t\"."
567 :group 'org-export-general
568 :type 'boolean)
570 (defcustom org-export-with-section-numbers t
571 "Non-nil means add section numbers to headlines when exporting.
573 When set to an integer n, numbering will only happen for
574 headlines whose relative level is higher or equal to n.
576 This option can also be set with the OPTIONS keyword,
577 e.g. \"num:t\"."
578 :group 'org-export-general
579 :type 'boolean)
581 (defcustom org-export-select-tags '("export")
582 "Tags that select a tree for export.
584 If any such tag is found in a buffer, all trees that do not carry
585 one of these tags will be ignored during export. Inside trees
586 that are selected like this, you can still deselect a subtree by
587 tagging it with one of the `org-export-exclude-tags'.
589 This option can also be set with the SELECT_TAGS keyword."
590 :group 'org-export-general
591 :type '(repeat (string :tag "Tag")))
593 (defcustom org-export-with-smart-quotes nil
594 "Non-nil means activate smart quotes during export.
595 This option can also be set with the OPTIONS keyword,
596 e.g., \"':t\".
598 When setting this to non-nil, you need to take care of
599 using the correct Babel package when exporting to LaTeX.
600 E.g., you can load Babel for french like this:
602 #+LATEX_HEADER: \\usepackage[french]{babel}"
603 :group 'org-export-general
604 :version "24.4"
605 :package-version '(Org . "8.0")
606 :type 'boolean)
608 (defcustom org-export-with-special-strings t
609 "Non-nil means interpret \"\\-\", \"--\" and \"---\" for export.
611 When this option is turned on, these strings will be exported as:
613 Org HTML LaTeX UTF-8
614 -----+----------+--------+-------
615 \\- &shy; \\-
616 -- &ndash; -- –
617 --- &mdash; --- —
618 ... &hellip; \\ldots …
620 This option can also be set with the OPTIONS keyword,
621 e.g. \"-:nil\"."
622 :group 'org-export-general
623 :type 'boolean)
625 (defcustom org-export-with-statistics-cookies t
626 "Non-nil means include statistics cookies in export.
627 This option can also be set with the OPTIONS keyword,
628 e.g. \"stat:nil\""
629 :group 'org-export-general
630 :version "24.4"
631 :package-version '(Org . "8.0")
632 :type 'boolean)
634 (defcustom org-export-with-sub-superscripts t
635 "Non-nil means interpret \"_\" and \"^\" for export.
637 When this option is turned on, you can use TeX-like syntax for
638 sub- and superscripts. Several characters after \"_\" or \"^\"
639 will be considered as a single item - so grouping with {} is
640 normally not needed. For example, the following things will be
641 parsed as single sub- or superscripts.
643 10^24 or 10^tau several digits will be considered 1 item.
644 10^-12 or 10^-tau a leading sign with digits or a word
645 x^2-y^3 will be read as x^2 - y^3, because items are
646 terminated by almost any nonword/nondigit char.
647 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
649 Still, ambiguity is possible - so when in doubt use {} to enclose
650 the sub/superscript. If you set this variable to the symbol
651 `{}', the braces are *required* in order to trigger
652 interpretations as sub/superscript. This can be helpful in
653 documents that need \"_\" frequently in plain text.
655 This option can also be set with the OPTIONS keyword,
656 e.g. \"^:nil\"."
657 :group 'org-export-general
658 :type '(choice
659 (const :tag "Interpret them" t)
660 (const :tag "Curly brackets only" {})
661 (const :tag "Do not interpret them" nil)))
663 (defcustom org-export-with-toc t
664 "Non-nil means create a table of contents in exported files.
666 The TOC contains headlines with levels up
667 to`org-export-headline-levels'. When an integer, include levels
668 up to N in the toc, this may then be different from
669 `org-export-headline-levels', but it will not be allowed to be
670 larger than the number of headline levels. When nil, no table of
671 contents is made.
673 This option can also be set with the OPTIONS keyword,
674 e.g. \"toc:nil\" or \"toc:3\"."
675 :group 'org-export-general
676 :type '(choice
677 (const :tag "No Table of Contents" nil)
678 (const :tag "Full Table of Contents" t)
679 (integer :tag "TOC to level")))
681 (defcustom org-export-with-tables t
682 "If non-nil, lines starting with \"|\" define a table.
683 For example:
685 | Name | Address | Birthday |
686 |-------------+----------+-----------|
687 | Arthur Dent | England | 29.2.2100 |
689 This option can also be set with the OPTIONS keyword,
690 e.g. \"|:nil\"."
691 :group 'org-export-general
692 :type 'boolean)
694 (defcustom org-export-with-tags t
695 "If nil, do not export tags, just remove them from headlines.
697 If this is the symbol `not-in-toc', tags will be removed from
698 table of contents entries, but still be shown in the headlines of
699 the document.
701 This option can also be set with the OPTIONS keyword,
702 e.g. \"tags:nil\"."
703 :group 'org-export-general
704 :type '(choice
705 (const :tag "Off" nil)
706 (const :tag "Not in TOC" not-in-toc)
707 (const :tag "On" t)))
709 (defcustom org-export-with-tasks t
710 "Non-nil means include TODO items for export.
712 This may have the following values:
713 t include tasks independent of state.
714 `todo' include only tasks that are not yet done.
715 `done' include only tasks that are already done.
716 nil ignore all tasks.
717 list of keywords include tasks with these keywords.
719 This option can also be set with the OPTIONS keyword,
720 e.g. \"tasks:nil\"."
721 :group 'org-export-general
722 :type '(choice
723 (const :tag "All tasks" t)
724 (const :tag "No tasks" nil)
725 (const :tag "Not-done tasks" todo)
726 (const :tag "Only done tasks" done)
727 (repeat :tag "Specific TODO keywords"
728 (string :tag "Keyword"))))
730 (defcustom org-export-time-stamp-file t
731 "Non-nil means insert a time stamp into the exported file.
732 The time stamp shows when the file was created. This option can
733 also be set with the OPTIONS keyword, e.g. \"timestamp:nil\"."
734 :group 'org-export-general
735 :type 'boolean)
737 (defcustom org-export-with-timestamps t
738 "Non nil means allow timestamps in export.
740 It can be set to any of the following values:
741 t export all timestamps.
742 `active' export active timestamps only.
743 `inactive' export inactive timestamps only.
744 nil do not export timestamps
746 This only applies to timestamps isolated in a paragraph
747 containing only timestamps. Other timestamps are always
748 exported.
750 This option can also be set with the OPTIONS keyword, e.g.
751 \"<:nil\"."
752 :group 'org-export-general
753 :type '(choice
754 (const :tag "All timestamps" t)
755 (const :tag "Only active timestamps" active)
756 (const :tag "Only inactive timestamps" inactive)
757 (const :tag "No timestamp" nil)))
759 (defcustom org-export-with-todo-keywords t
760 "Non-nil means include TODO keywords in export.
761 When nil, remove all these keywords from the export. This option
762 can also be set with the OPTIONS keyword, e.g. \"todo:nil\"."
763 :group 'org-export-general
764 :type 'boolean)
766 (defcustom org-export-allow-bind-keywords nil
767 "Non-nil means BIND keywords can define local variable values.
768 This is a potential security risk, which is why the default value
769 is nil. You can also allow them through local buffer variables."
770 :group 'org-export-general
771 :version "24.4"
772 :package-version '(Org . "8.0")
773 :type 'boolean)
775 (defcustom org-export-snippet-translation-alist nil
776 "Alist between export snippets back-ends and exporter back-ends.
778 This variable allows to provide shortcuts for export snippets.
780 For example, with a value of '\(\(\"h\" . \"html\"\)\), the
781 HTML back-end will recognize the contents of \"@@h:<b>@@\" as
782 HTML code while every other back-end will ignore it."
783 :group 'org-export-general
784 :version "24.4"
785 :package-version '(Org . "8.0")
786 :type '(repeat
787 (cons (string :tag "Shortcut")
788 (string :tag "Back-end"))))
790 (defcustom org-export-coding-system nil
791 "Coding system for the exported file."
792 :group 'org-export-general
793 :version "24.4"
794 :package-version '(Org . "8.0")
795 :type 'coding-system)
797 (defcustom org-export-copy-to-kill-ring 'if-interactive
798 "Should we push exported content to the kill ring?"
799 :group 'org-export-general
800 :version "24.3"
801 :type '(choice
802 (const :tag "Always" t)
803 (const :tag "When export is done interactively" if-interactive)
804 (const :tag "Never" nil)))
806 (defcustom org-export-initial-scope 'buffer
807 "The initial scope when exporting with `org-export-dispatch'.
808 This variable can be either set to `buffer' or `subtree'."
809 :group 'org-export-general
810 :type '(choice
811 (const :tag "Export current buffer" 'buffer)
812 (const :tag "Export current subtree" 'subtree)))
814 (defcustom org-export-show-temporary-export-buffer t
815 "Non-nil means show buffer after exporting to temp buffer.
816 When Org exports to a file, the buffer visiting that file is ever
817 shown, but remains buried. However, when exporting to
818 a temporary buffer, that buffer is popped up in a second window.
819 When this variable is nil, the buffer remains buried also in
820 these cases."
821 :group 'org-export-general
822 :type 'boolean)
824 (defcustom org-export-in-background nil
825 "Non-nil means export and publishing commands will run in background.
826 Results from an asynchronous export are never displayed
827 automatically. But you can retrieve them with \\[org-export-stack]."
828 :group 'org-export-general
829 :version "24.4"
830 :package-version '(Org . "8.0")
831 :type 'boolean)
833 (defcustom org-export-async-init-file user-init-file
834 "File used to initialize external export process.
835 Value must be an absolute file name. It defaults to user's
836 initialization file. Though, a specific configuration makes the
837 process faster and the export more portable."
838 :group 'org-export-general
839 :version "24.4"
840 :package-version '(Org . "8.0")
841 :type '(file :must-match t))
843 (defcustom org-export-invisible-backends nil
844 "List of back-ends that shouldn't appear in the dispatcher.
846 Any back-end belonging to this list or derived from a back-end
847 belonging to it will not appear in the dispatcher menu.
849 Indeed, Org may require some export back-ends without notice. If
850 these modules are never to be used interactively, adding them
851 here will avoid cluttering the dispatcher menu."
852 :group 'org-export-general
853 :version "24.4"
854 :package-version '(Org . "8.0")
855 :type '(repeat (symbol :tag "Back-End")))
857 (defcustom org-export-dispatch-use-expert-ui nil
858 "Non-nil means using a non-intrusive `org-export-dispatch'.
859 In that case, no help buffer is displayed. Though, an indicator
860 for current export scope is added to the prompt (\"b\" when
861 output is restricted to body only, \"s\" when it is restricted to
862 the current subtree, \"v\" when only visible elements are
863 considered for export, \"f\" when publishing functions should be
864 passed the FORCE argument and \"a\" when the export should be
865 asynchronous). Also, \[?] allows to switch back to standard
866 mode."
867 :group 'org-export-general
868 :version "24.4"
869 :package-version '(Org . "8.0")
870 :type 'boolean)
874 ;;; Defining Back-ends
876 ;; `org-export-define-backend' is the standard way to define an export
877 ;; back-end. It allows to specify translators, filters, buffer
878 ;; options and a menu entry. If the new back-end shares translators
879 ;; with another back-end, `org-export-define-derived-backend' may be
880 ;; used instead.
882 ;; Internally, a back-end is stored as a list, of which CAR is the
883 ;; name of the back-end, as a symbol, and CDR a plist. Accessors to
884 ;; properties of a given back-end are: `org-export-backend-filters',
885 ;; `org-export-backend-menu', `org-export-backend-options' and
886 ;; `org-export-backend-translate-table'.
888 ;; Eventually `org-export-barf-if-invalid-backend' returns an error
889 ;; when a given back-end hasn't been registered yet.
891 (defun org-export-define-backend (backend translators &rest body)
892 "Define a new back-end BACKEND.
894 TRANSLATORS is an alist between object or element types and
895 functions handling them.
897 These functions should return a string without any trailing
898 space, or nil. They must accept three arguments: the object or
899 element itself, its contents or nil when it isn't recursive and
900 the property list used as a communication channel.
902 Contents, when not nil, are stripped from any global indentation
903 \(although the relative one is preserved). They also always end
904 with a single newline character.
906 If, for a given type, no function is found, that element or
907 object type will simply be ignored, along with any blank line or
908 white space at its end. The same will happen if the function
909 returns the nil value. If that function returns the empty
910 string, the type will be ignored, but the blank lines or white
911 spaces will be kept.
913 In addition to element and object types, one function can be
914 associated to the `template' (or `inner-template') symbol and
915 another one to the `plain-text' symbol.
917 The former returns the final transcoded string, and can be used
918 to add a preamble and a postamble to document's body. It must
919 accept two arguments: the transcoded string and the property list
920 containing export options. A function associated to `template'
921 will not be applied if export has option \"body-only\".
922 A function associated to `inner-template' is always applied.
924 The latter, when defined, is to be called on every text not
925 recognized as an element or an object. It must accept two
926 arguments: the text string and the information channel. It is an
927 appropriate place to protect special chars relative to the
928 back-end.
930 BODY can start with pre-defined keyword arguments. The following
931 keywords are understood:
933 :export-block
935 String, or list of strings, representing block names that
936 will not be parsed. This is used to specify blocks that will
937 contain raw code specific to the back-end. These blocks
938 still have to be handled by the relative `export-block' type
939 translator.
941 :filters-alist
943 Alist between filters and function, or list of functions,
944 specific to the back-end. See `org-export-filters-alist' for
945 a list of all allowed filters. Filters defined here
946 shouldn't make a back-end test, as it may prevent back-ends
947 derived from this one to behave properly.
949 :menu-entry
951 Menu entry for the export dispatcher. It should be a list
952 like:
954 '(KEY DESCRIPTION-OR-ORDINAL ACTION-OR-MENU)
956 where :
958 KEY is a free character selecting the back-end.
960 DESCRIPTION-OR-ORDINAL is either a string or a number.
962 If it is a string, is will be used to name the back-end in
963 its menu entry. If it is a number, the following menu will
964 be displayed as a sub-menu of the back-end with the same
965 KEY. Also, the number will be used to determine in which
966 order such sub-menus will appear (lowest first).
968 ACTION-OR-MENU is either a function or an alist.
970 If it is an action, it will be called with four
971 arguments (booleans): ASYNC, SUBTREEP, VISIBLE-ONLY and
972 BODY-ONLY. See `org-export-as' for further explanations on
973 some of them.
975 If it is an alist, associations should follow the
976 pattern:
978 '(KEY DESCRIPTION ACTION)
980 where KEY, DESCRIPTION and ACTION are described above.
982 Valid values include:
984 '(?m \"My Special Back-end\" my-special-export-function)
988 '(?l \"Export to LaTeX\"
989 \(?p \"As PDF file\" org-latex-export-to-pdf)
990 \(?o \"As PDF file and open\"
991 \(lambda (a s v b)
992 \(if a (org-latex-export-to-pdf t s v b)
993 \(org-open-file
994 \(org-latex-export-to-pdf nil s v b)))))))
996 or the following, which will be added to the previous
997 sub-menu,
999 '(?l 1
1000 \((?B \"As TEX buffer (Beamer)\" org-beamer-export-as-latex)
1001 \(?P \"As PDF file (Beamer)\" org-beamer-export-to-pdf)))
1003 :options-alist
1005 Alist between back-end specific properties introduced in
1006 communication channel and how their value are acquired. See
1007 `org-export-options-alist' for more information about
1008 structure of the values."
1009 (declare (indent 1))
1010 (let (export-block filters menu-entry options contents)
1011 (while (keywordp (car body))
1012 (case (pop body)
1013 (:export-block (let ((names (pop body)))
1014 (setq export-block
1015 (if (consp names) (mapcar 'upcase names)
1016 (list (upcase names))))))
1017 (:filters-alist (setq filters (pop body)))
1018 (:menu-entry (setq menu-entry (pop body)))
1019 (:options-alist (setq options (pop body)))
1020 (t (pop body))))
1021 (setq contents (append (list :translate-alist translators)
1022 (and filters (list :filters-alist filters))
1023 (and options (list :options-alist options))
1024 (and menu-entry (list :menu-entry menu-entry))))
1025 ;; Register back-end.
1026 (let ((registeredp (assq backend org-export-registered-backends)))
1027 (if registeredp (setcdr registeredp contents)
1028 (push (cons backend contents) org-export-registered-backends)))
1029 ;; Tell parser to not parse EXPORT-BLOCK blocks.
1030 (when export-block
1031 (mapc
1032 (lambda (name)
1033 (add-to-list 'org-element-block-name-alist
1034 `(,name . org-element-export-block-parser)))
1035 export-block))))
1037 (defun org-export-define-derived-backend (child parent &rest body)
1038 "Create a new back-end as a variant of an existing one.
1040 CHILD is the name of the derived back-end. PARENT is the name of
1041 the parent back-end.
1043 BODY can start with pre-defined keyword arguments. The following
1044 keywords are understood:
1046 :export-block
1048 String, or list of strings, representing block names that
1049 will not be parsed. This is used to specify blocks that will
1050 contain raw code specific to the back-end. These blocks
1051 still have to be handled by the relative `export-block' type
1052 translator.
1054 :filters-alist
1056 Alist of filters that will overwrite or complete filters
1057 defined in PARENT back-end. See `org-export-filters-alist'
1058 for a list of allowed filters.
1060 :menu-entry
1062 Menu entry for the export dispatcher. See
1063 `org-export-define-backend' for more information about the
1064 expected value.
1066 :options-alist
1068 Alist of back-end specific properties that will overwrite or
1069 complete those defined in PARENT back-end. Refer to
1070 `org-export-options-alist' for more information about
1071 structure of the values.
1073 :translate-alist
1075 Alist of element and object types and transcoders that will
1076 overwrite or complete transcode table from PARENT back-end.
1077 Refer to `org-export-define-backend' for detailed information
1078 about transcoders.
1080 As an example, here is how one could define \"my-latex\" back-end
1081 as a variant of `latex' back-end with a custom template function:
1083 \(org-export-define-derived-backend 'my-latex 'latex
1084 :translate-alist '((template . my-latex-template-fun)))
1086 The back-end could then be called with, for example:
1088 \(org-export-to-buffer 'my-latex \"*Test my-latex*\")"
1089 (declare (indent 2))
1090 (let (export-block filters menu-entry options translators contents)
1091 (while (keywordp (car body))
1092 (case (pop body)
1093 (:export-block (let ((names (pop body)))
1094 (setq export-block
1095 (if (consp names) (mapcar 'upcase names)
1096 (list (upcase names))))))
1097 (:filters-alist (setq filters (pop body)))
1098 (:menu-entry (setq menu-entry (pop body)))
1099 (:options-alist (setq options (pop body)))
1100 (:translate-alist (setq translators (pop body)))
1101 (t (pop body))))
1102 (setq contents (append
1103 (list :parent parent)
1104 (let ((p-table (org-export-backend-translate-table parent)))
1105 (list :translate-alist (append translators p-table)))
1106 (let ((p-filters (org-export-backend-filters parent)))
1107 (list :filters-alist (append filters p-filters)))
1108 (let ((p-options (org-export-backend-options parent)))
1109 (list :options-alist (append options p-options)))
1110 (and menu-entry (list :menu-entry menu-entry))))
1111 (org-export-barf-if-invalid-backend parent)
1112 ;; Register back-end.
1113 (let ((registeredp (assq child org-export-registered-backends)))
1114 (if registeredp (setcdr registeredp contents)
1115 (push (cons child contents) org-export-registered-backends)))
1116 ;; Tell parser to not parse EXPORT-BLOCK blocks.
1117 (when export-block
1118 (mapc
1119 (lambda (name)
1120 (add-to-list 'org-element-block-name-alist
1121 `(,name . org-element-export-block-parser)))
1122 export-block))))
1124 (defun org-export-backend-parent (backend)
1125 "Return back-end from which BACKEND is derived, or nil."
1126 (plist-get (cdr (assq backend org-export-registered-backends)) :parent))
1128 (defun org-export-backend-filters (backend)
1129 "Return filters for BACKEND."
1130 (plist-get (cdr (assq backend org-export-registered-backends))
1131 :filters-alist))
1133 (defun org-export-backend-menu (backend)
1134 "Return menu entry for BACKEND."
1135 (plist-get (cdr (assq backend org-export-registered-backends))
1136 :menu-entry))
1138 (defun org-export-backend-options (backend)
1139 "Return export options for BACKEND."
1140 (plist-get (cdr (assq backend org-export-registered-backends))
1141 :options-alist))
1143 (defun org-export-backend-translate-table (backend)
1144 "Return translate table for BACKEND."
1145 (plist-get (cdr (assq backend org-export-registered-backends))
1146 :translate-alist))
1148 (defun org-export-barf-if-invalid-backend (backend)
1149 "Signal an error if BACKEND isn't defined."
1150 (unless (org-export-backend-translate-table backend)
1151 (error "Unknown \"%s\" back-end: Aborting export" backend)))
1153 (defun org-export-derived-backend-p (backend &rest backends)
1154 "Non-nil if BACKEND is derived from one of BACKENDS."
1155 (let ((parent backend))
1156 (while (and (not (memq parent backends))
1157 (setq parent (org-export-backend-parent parent))))
1158 parent))
1162 ;;; The Communication Channel
1164 ;; During export process, every function has access to a number of
1165 ;; properties. They are of two types:
1167 ;; 1. Environment options are collected once at the very beginning of
1168 ;; the process, out of the original buffer and configuration.
1169 ;; Collecting them is handled by `org-export-get-environment'
1170 ;; function.
1172 ;; Most environment options are defined through the
1173 ;; `org-export-options-alist' variable.
1175 ;; 2. Tree properties are extracted directly from the parsed tree,
1176 ;; just before export, by `org-export-collect-tree-properties'.
1178 ;; Here is the full list of properties available during transcode
1179 ;; process, with their category and their value type.
1181 ;; + `:author' :: Author's name.
1182 ;; - category :: option
1183 ;; - type :: string
1185 ;; + `:back-end' :: Current back-end used for transcoding.
1186 ;; - category :: tree
1187 ;; - type :: symbol
1189 ;; + `:creator' :: String to write as creation information.
1190 ;; - category :: option
1191 ;; - type :: string
1193 ;; + `:date' :: String to use as date.
1194 ;; - category :: option
1195 ;; - type :: string
1197 ;; + `:description' :: Description text for the current data.
1198 ;; - category :: option
1199 ;; - type :: string
1201 ;; + `:email' :: Author's email.
1202 ;; - category :: option
1203 ;; - type :: string
1205 ;; + `:exclude-tags' :: Tags for exclusion of subtrees from export
1206 ;; process.
1207 ;; - category :: option
1208 ;; - type :: list of strings
1210 ;; + `:export-options' :: List of export options available for current
1211 ;; process.
1212 ;; - category :: none
1213 ;; - type :: list of symbols, among `subtree', `body-only' and
1214 ;; `visible-only'.
1216 ;; + `:exported-data' :: Hash table used for memoizing
1217 ;; `org-export-data'.
1218 ;; - category :: tree
1219 ;; - type :: hash table
1221 ;; + `:filetags' :: List of global tags for buffer. Used by
1222 ;; `org-export-get-tags' to get tags with inheritance.
1223 ;; - category :: option
1224 ;; - type :: list of strings
1226 ;; + `:footnote-definition-alist' :: Alist between footnote labels and
1227 ;; their definition, as parsed data. Only non-inlined footnotes
1228 ;; are represented in this alist. Also, every definition isn't
1229 ;; guaranteed to be referenced in the parse tree. The purpose of
1230 ;; this property is to preserve definitions from oblivion
1231 ;; (i.e. when the parse tree comes from a part of the original
1232 ;; buffer), it isn't meant for direct use in a back-end. To
1233 ;; retrieve a definition relative to a reference, use
1234 ;; `org-export-get-footnote-definition' instead.
1235 ;; - category :: option
1236 ;; - type :: alist (STRING . LIST)
1238 ;; + `:headline-levels' :: Maximum level being exported as an
1239 ;; headline. Comparison is done with the relative level of
1240 ;; headlines in the parse tree, not necessarily with their
1241 ;; actual level.
1242 ;; - category :: option
1243 ;; - type :: integer
1245 ;; + `:headline-offset' :: Difference between relative and real level
1246 ;; of headlines in the parse tree. For example, a value of -1
1247 ;; means a level 2 headline should be considered as level
1248 ;; 1 (cf. `org-export-get-relative-level').
1249 ;; - category :: tree
1250 ;; - type :: integer
1252 ;; + `:headline-numbering' :: Alist between headlines and their
1253 ;; numbering, as a list of numbers
1254 ;; (cf. `org-export-get-headline-number').
1255 ;; - category :: tree
1256 ;; - type :: alist (INTEGER . LIST)
1258 ;; + `:id-alist' :: Alist between ID strings and destination file's
1259 ;; path, relative to current directory. It is used by
1260 ;; `org-export-resolve-id-link' to resolve ID links targeting an
1261 ;; external file.
1262 ;; - category :: option
1263 ;; - type :: alist (STRING . STRING)
1265 ;; + `:ignore-list' :: List of elements and objects that should be
1266 ;; ignored during export.
1267 ;; - category :: tree
1268 ;; - type :: list of elements and objects
1270 ;; + `:input-file' :: Full path to input file, if any.
1271 ;; - category :: option
1272 ;; - type :: string or nil
1274 ;; + `:keywords' :: List of keywords attached to data.
1275 ;; - category :: option
1276 ;; - type :: string
1278 ;; + `:language' :: Default language used for translations.
1279 ;; - category :: option
1280 ;; - type :: string
1282 ;; + `:parse-tree' :: Whole parse tree, available at any time during
1283 ;; transcoding.
1284 ;; - category :: option
1285 ;; - type :: list (as returned by `org-element-parse-buffer')
1287 ;; + `:preserve-breaks' :: Non-nil means transcoding should preserve
1288 ;; all line breaks.
1289 ;; - category :: option
1290 ;; - type :: symbol (nil, t)
1292 ;; + `:section-numbers' :: Non-nil means transcoding should add
1293 ;; section numbers to headlines.
1294 ;; - category :: option
1295 ;; - type :: symbol (nil, t)
1297 ;; + `:select-tags' :: List of tags enforcing inclusion of sub-trees
1298 ;; in transcoding. When such a tag is present, subtrees without
1299 ;; it are de facto excluded from the process. See
1300 ;; `use-select-tags'.
1301 ;; - category :: option
1302 ;; - type :: list of strings
1304 ;; + `:time-stamp-file' :: Non-nil means transcoding should insert
1305 ;; a time stamp in the output.
1306 ;; - category :: option
1307 ;; - type :: symbol (nil, t)
1309 ;; + `:translate-alist' :: Alist between element and object types and
1310 ;; transcoding functions relative to the current back-end.
1311 ;; Special keys `inner-template', `template' and `plain-text' are
1312 ;; also possible.
1313 ;; - category :: option
1314 ;; - type :: alist (SYMBOL . FUNCTION)
1316 ;; + `:with-archived-trees' :: Non-nil when archived subtrees should
1317 ;; also be transcoded. If it is set to the `headline' symbol,
1318 ;; only the archived headline's name is retained.
1319 ;; - category :: option
1320 ;; - type :: symbol (nil, t, `headline')
1322 ;; + `:with-author' :: Non-nil means author's name should be included
1323 ;; in the output.
1324 ;; - category :: option
1325 ;; - type :: symbol (nil, t)
1327 ;; + `:with-clocks' :: Non-nil means clock keywords should be exported.
1328 ;; - category :: option
1329 ;; - type :: symbol (nil, t)
1331 ;; + `:with-creator' :: Non-nil means a creation sentence should be
1332 ;; inserted at the end of the transcoded string. If the value
1333 ;; is `comment', it should be commented.
1334 ;; - category :: option
1335 ;; - type :: symbol (`comment', nil, t)
1337 ;; + `:with-date' :: Non-nil means output should contain a date.
1338 ;; - category :: option
1339 ;; - type :. symbol (nil, t)
1341 ;; + `:with-drawers' :: Non-nil means drawers should be exported. If
1342 ;; its value is a list of names, only drawers with such names
1343 ;; will be transcoded. If that list starts with `not', drawer
1344 ;; with these names will be skipped.
1345 ;; - category :: option
1346 ;; - type :: symbol (nil, t) or list of strings
1348 ;; + `:with-email' :: Non-nil means output should contain author's
1349 ;; email.
1350 ;; - category :: option
1351 ;; - type :: symbol (nil, t)
1353 ;; + `:with-emphasize' :: Non-nil means emphasized text should be
1354 ;; interpreted.
1355 ;; - category :: option
1356 ;; - type :: symbol (nil, t)
1358 ;; + `:with-fixed-width' :: Non-nil if transcoder should interpret
1359 ;; strings starting with a colon as a fixed-with (verbatim) area.
1360 ;; - category :: option
1361 ;; - type :: symbol (nil, t)
1363 ;; + `:with-footnotes' :: Non-nil if transcoder should interpret
1364 ;; footnotes.
1365 ;; - category :: option
1366 ;; - type :: symbol (nil, t)
1368 ;; + `:with-latex' :: Non-nil means `latex-environment' elements and
1369 ;; `latex-fragment' objects should appear in export output. When
1370 ;; this property is set to `verbatim', they will be left as-is.
1371 ;; - category :: option
1372 ;; - type :: symbol (`verbatim', nil, t)
1374 ;; + `:with-planning' :: Non-nil means transcoding should include
1375 ;; planning info.
1376 ;; - category :: option
1377 ;; - type :: symbol (nil, t)
1379 ;; + `:with-priority' :: Non-nil means transcoding should include
1380 ;; priority cookies.
1381 ;; - category :: option
1382 ;; - type :: symbol (nil, t)
1384 ;; + `:with-smart-quotes' :: Non-nil means activate smart quotes in
1385 ;; plain text.
1386 ;; - category :: option
1387 ;; - type :: symbol (nil, t)
1389 ;; + `:with-special-strings' :: Non-nil means transcoding should
1390 ;; interpret special strings in plain text.
1391 ;; - category :: option
1392 ;; - type :: symbol (nil, t)
1394 ;; + `:with-sub-superscript' :: Non-nil means transcoding should
1395 ;; interpret subscript and superscript. With a value of "{}",
1396 ;; only interpret those using curly brackets.
1397 ;; - category :: option
1398 ;; - type :: symbol (nil, {}, t)
1400 ;; + `:with-tables' :: Non-nil means transcoding should interpret
1401 ;; tables.
1402 ;; - category :: option
1403 ;; - type :: symbol (nil, t)
1405 ;; + `:with-tags' :: Non-nil means transcoding should keep tags in
1406 ;; headlines. A `not-in-toc' value will remove them from the
1407 ;; table of contents, if any, nonetheless.
1408 ;; - category :: option
1409 ;; - type :: symbol (nil, t, `not-in-toc')
1411 ;; + `:with-tasks' :: Non-nil means transcoding should include
1412 ;; headlines with a TODO keyword. A `todo' value will only
1413 ;; include headlines with a todo type keyword while a `done'
1414 ;; value will do the contrary. If a list of strings is provided,
1415 ;; only tasks with keywords belonging to that list will be kept.
1416 ;; - category :: option
1417 ;; - type :: symbol (t, todo, done, nil) or list of strings
1419 ;; + `:with-timestamps' :: Non-nil means transcoding should include
1420 ;; time stamps. Special value `active' (resp. `inactive') ask to
1421 ;; export only active (resp. inactive) timestamps. Otherwise,
1422 ;; completely remove them.
1423 ;; - category :: option
1424 ;; - type :: symbol: (`active', `inactive', t, nil)
1426 ;; + `:with-toc' :: Non-nil means that a table of contents has to be
1427 ;; added to the output. An integer value limits its depth.
1428 ;; - category :: option
1429 ;; - type :: symbol (nil, t or integer)
1431 ;; + `:with-todo-keywords' :: Non-nil means transcoding should
1432 ;; include TODO keywords.
1433 ;; - category :: option
1434 ;; - type :: symbol (nil, t)
1437 ;;;; Environment Options
1439 ;; Environment options encompass all parameters defined outside the
1440 ;; scope of the parsed data. They come from five sources, in
1441 ;; increasing precedence order:
1443 ;; - Global variables,
1444 ;; - Buffer's attributes,
1445 ;; - Options keyword symbols,
1446 ;; - Buffer keywords,
1447 ;; - Subtree properties.
1449 ;; The central internal function with regards to environment options
1450 ;; is `org-export-get-environment'. It updates global variables with
1451 ;; "#+BIND:" keywords, then retrieve and prioritize properties from
1452 ;; the different sources.
1454 ;; The internal functions doing the retrieval are:
1455 ;; `org-export--get-global-options',
1456 ;; `org-export--get-buffer-attributes',
1457 ;; `org-export--parse-option-keyword',
1458 ;; `org-export--get-subtree-options' and
1459 ;; `org-export--get-inbuffer-options'
1461 ;; Also, `org-export--install-letbind-maybe' takes care of the part
1462 ;; relative to "#+BIND:" keywords.
1464 (defun org-export-get-environment (&optional backend subtreep ext-plist)
1465 "Collect export options from the current buffer.
1467 Optional argument BACKEND is a symbol specifying which back-end
1468 specific options to read, if any.
1470 When optional argument SUBTREEP is non-nil, assume the export is
1471 done against the current sub-tree.
1473 Third optional argument EXT-PLIST is a property list with
1474 external parameters overriding Org default settings, but still
1475 inferior to file-local settings."
1476 ;; First install #+BIND variables since these must be set before
1477 ;; global options are read.
1478 (dolist (pair (org-export--list-bound-variables))
1479 (org-set-local (car pair) (nth 1 pair)))
1480 ;; Get and prioritize export options...
1481 (org-combine-plists
1482 ;; ... from global variables...
1483 (org-export--get-global-options backend)
1484 ;; ... from an external property list...
1485 ext-plist
1486 ;; ... from in-buffer settings...
1487 (org-export--get-inbuffer-options backend)
1488 ;; ... and from subtree, when appropriate.
1489 (and subtreep (org-export--get-subtree-options backend))
1490 ;; Eventually add misc. properties.
1491 (list
1492 :back-end
1493 backend
1494 :translate-alist
1495 (org-export-backend-translate-table backend)
1496 :footnote-definition-alist
1497 ;; Footnotes definitions must be collected in the original
1498 ;; buffer, as there's no insurance that they will still be in
1499 ;; the parse tree, due to possible narrowing.
1500 (let (alist)
1501 (org-with-wide-buffer
1502 (goto-char (point-min))
1503 (while (re-search-forward org-footnote-definition-re nil t)
1504 (let ((def (save-match-data (org-element-at-point))))
1505 (when (eq (org-element-type def) 'footnote-definition)
1506 (push
1507 (cons (org-element-property :label def)
1508 (let ((cbeg (org-element-property :contents-begin def)))
1509 (when cbeg
1510 (org-element--parse-elements
1511 cbeg (org-element-property :contents-end def)
1512 nil nil nil nil (list 'org-data nil)))))
1513 alist))))
1514 alist))
1515 :id-alist
1516 ;; Collect id references.
1517 (let (alist)
1518 (org-with-wide-buffer
1519 (goto-char (point-min))
1520 (while (re-search-forward "\\[\\[id:\\S-+?\\]" nil t)
1521 (let ((link (org-element-context)))
1522 (when (eq (org-element-type link) 'link)
1523 (let* ((id (org-element-property :path link))
1524 (file (org-id-find-id-file id)))
1525 (when file
1526 (push (cons id (file-relative-name file)) alist)))))))
1527 alist))))
1529 (defun org-export--parse-option-keyword (options &optional backend)
1530 "Parse an OPTIONS line and return values as a plist.
1531 Optional argument BACKEND is a symbol specifying which back-end
1532 specific items to read, if any."
1533 (let* ((all
1534 ;; Priority is given to back-end specific options.
1535 (append (and backend (org-export-backend-options backend))
1536 org-export-options-alist))
1537 plist)
1538 (dolist (option all)
1539 (let ((property (car option))
1540 (item (nth 2 option)))
1541 (when (and item
1542 (not (plist-member plist property))
1543 (string-match (concat "\\(\\`\\|[ \t]\\)"
1544 (regexp-quote item)
1545 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
1546 options))
1547 (setq plist (plist-put plist
1548 property
1549 (car (read-from-string
1550 (match-string 2 options))))))))
1551 plist))
1553 (defun org-export--get-subtree-options (&optional backend)
1554 "Get export options in subtree at point.
1555 Optional argument BACKEND is a symbol specifying back-end used
1556 for export. Return options as a plist."
1557 ;; For each buffer keyword, create a headline property setting the
1558 ;; same property in communication channel. The name for the property
1559 ;; is the keyword with "EXPORT_" appended to it.
1560 (org-with-wide-buffer
1561 (let (prop plist)
1562 ;; Make sure point is at a heading.
1563 (if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t))
1564 ;; Take care of EXPORT_TITLE. If it isn't defined, use headline's
1565 ;; title as its fallback value.
1566 (when (setq prop (or (org-entry-get (point) "EXPORT_TITLE")
1567 (progn (looking-at org-todo-line-regexp)
1568 (org-match-string-no-properties 3))))
1569 (setq plist
1570 (plist-put
1571 plist :title
1572 (org-element-parse-secondary-string
1573 prop (org-element-restriction 'keyword)))))
1574 ;; EXPORT_OPTIONS are parsed in a non-standard way.
1575 (when (setq prop (org-entry-get (point) "EXPORT_OPTIONS"))
1576 (setq plist
1577 (nconc plist (org-export--parse-option-keyword prop backend))))
1578 ;; Handle other keywords. TITLE keyword is excluded as it has
1579 ;; been handled already.
1580 (let ((seen '("TITLE")))
1581 (mapc
1582 (lambda (option)
1583 (let ((property (car option))
1584 (keyword (nth 1 option)))
1585 (when (and keyword (not (member keyword seen)))
1586 (let* ((subtree-prop (concat "EXPORT_" keyword))
1587 ;; Export properties are not case-sensitive.
1588 (value (let ((case-fold-search t))
1589 (org-entry-get (point) subtree-prop))))
1590 (push keyword seen)
1591 (when (and value (not (plist-member plist property)))
1592 (setq plist
1593 (plist-put
1594 plist
1595 property
1596 (cond
1597 ;; Parse VALUE if required.
1598 ((member keyword org-element-document-properties)
1599 (org-element-parse-secondary-string
1600 value (org-element-restriction 'keyword)))
1601 ;; If BEHAVIOUR is `split' expected value is
1602 ;; a list of strings, not a string.
1603 ((eq (nth 4 option) 'split) (org-split-string value))
1604 (t value)))))))))
1605 ;; Look for both general keywords and back-end specific
1606 ;; options, with priority given to the latter.
1607 (append (and backend (org-export-backend-options backend))
1608 org-export-options-alist)))
1609 ;; Return value.
1610 plist)))
1612 (defun org-export--get-inbuffer-options (&optional backend)
1613 "Return current buffer export options, as a plist.
1615 Optional argument BACKEND, when non-nil, is a symbol specifying
1616 which back-end specific options should also be read in the
1617 process.
1619 Assume buffer is in Org mode. Narrowing, if any, is ignored."
1620 (let* (plist
1621 get-options ; For byte-compiler.
1622 (case-fold-search t)
1623 (options (append
1624 ;; Priority is given to back-end specific options.
1625 (and backend (org-export-backend-options backend))
1626 org-export-options-alist))
1627 (regexp (format "^[ \t]*#\\+%s:"
1628 (regexp-opt (nconc (delq nil (mapcar 'cadr options))
1629 org-export-special-keywords))))
1630 (find-opt
1631 (lambda (keyword)
1632 ;; Return property name associated to KEYWORD.
1633 (catch 'exit
1634 (mapc (lambda (option)
1635 (when (equal (nth 1 option) keyword)
1636 (throw 'exit (car option))))
1637 options))))
1638 (get-options
1639 (lambda (&optional files plist)
1640 ;; Recursively read keywords in buffer. FILES is a list
1641 ;; of files read so far. PLIST is the current property
1642 ;; list obtained.
1643 (org-with-wide-buffer
1644 (goto-char (point-min))
1645 (while (re-search-forward regexp nil t)
1646 (let ((element (org-element-at-point)))
1647 (when (eq (org-element-type element) 'keyword)
1648 (let ((key (org-element-property :key element))
1649 (val (org-element-property :value element)))
1650 (cond
1651 ;; Options in `org-export-special-keywords'.
1652 ((equal key "SETUPFILE")
1653 (let ((file (expand-file-name
1654 (org-remove-double-quotes (org-trim val)))))
1655 ;; Avoid circular dependencies.
1656 (unless (member file files)
1657 (with-temp-buffer
1658 (insert (org-file-contents file 'noerror))
1659 (let ((org-inhibit-startup t)) (org-mode))
1660 (setq plist (funcall get-options
1661 (cons file files) plist))))))
1662 ((equal key "OPTIONS")
1663 (setq plist
1664 (org-combine-plists
1665 plist
1666 (org-export--parse-option-keyword val backend))))
1667 ((equal key "FILETAGS")
1668 (setq plist
1669 (org-combine-plists
1670 plist
1671 (list :filetags
1672 (org-uniquify
1673 (append (org-split-string val ":")
1674 (plist-get plist :filetags)))))))
1676 ;; Options in `org-export-options-alist'.
1677 (let* ((prop (funcall find-opt key))
1678 (behaviour (nth 4 (assq prop options))))
1679 (setq plist
1680 (plist-put
1681 plist prop
1682 ;; Handle value depending on specified
1683 ;; BEHAVIOUR.
1684 (case behaviour
1685 (space
1686 (if (not (plist-get plist prop))
1687 (org-trim val)
1688 (concat (plist-get plist prop)
1690 (org-trim val))))
1691 (newline
1692 (org-trim (concat (plist-get plist prop)
1693 "\n"
1694 (org-trim val))))
1695 (split `(,@(plist-get plist prop)
1696 ,@(org-split-string val)))
1697 ('t val)
1698 (otherwise
1699 (if (not (plist-member plist prop)) val
1700 (plist-get plist prop)))))))))))))
1701 ;; Return final value.
1702 plist))))
1703 ;; Read options in the current buffer.
1704 (setq plist
1705 (funcall get-options
1706 (and buffer-file-name (list buffer-file-name)) nil))
1707 ;; Parse keywords specified in `org-element-document-properties'.
1708 (mapc (lambda (keyword)
1709 ;; Find the property associated to the keyword.
1710 (let* ((prop (funcall find-opt keyword))
1711 (value (and prop (plist-get plist prop))))
1712 (when (stringp value)
1713 (setq plist
1714 (plist-put plist prop
1715 (org-element-parse-secondary-string
1716 value (org-element-restriction 'keyword)))))))
1717 org-element-document-properties)
1718 ;; Return value.
1719 plist))
1721 (defun org-export--get-buffer-attributes ()
1722 "Return properties related to buffer attributes, as a plist."
1723 ;; Store full path of input file name, or nil. For internal use.
1724 (let ((visited-file (buffer-file-name (buffer-base-buffer))))
1725 (list :input-file visited-file
1726 :title (if (not visited-file) (buffer-name (buffer-base-buffer))
1727 (file-name-sans-extension
1728 (file-name-nondirectory visited-file))))))
1730 (defun org-export--get-global-options (&optional backend)
1731 "Return global export options as a plist.
1732 Optional argument BACKEND, if non-nil, is a symbol specifying
1733 which back-end specific export options should also be read in the
1734 process."
1735 (let (plist
1736 ;; Priority is given to back-end specific options.
1737 (all (append (and backend (org-export-backend-options backend))
1738 org-export-options-alist)))
1739 (dolist (cell all plist)
1740 (let ((prop (car cell))
1741 (default-value (nth 3 cell)))
1742 (unless (or (not default-value) (plist-member plist prop))
1743 (setq plist
1744 (plist-put
1745 plist
1746 prop
1747 ;; Eval default value provided. If keyword is
1748 ;; a member of `org-element-document-properties',
1749 ;; parse it as a secondary string before storing it.
1750 (let ((value (eval (nth 3 cell))))
1751 (if (not (stringp value)) value
1752 (let ((keyword (nth 1 cell)))
1753 (if (member keyword org-element-document-properties)
1754 (org-element-parse-secondary-string
1755 value (org-element-restriction 'keyword))
1756 value)))))))))))
1758 (defun org-export--list-bound-variables ()
1759 "Return variables bound from BIND keywords in current buffer.
1760 Also look for BIND keywords in setup files. The return value is
1761 an alist where associations are (VARIABLE-NAME VALUE)."
1762 (when org-export-allow-bind-keywords
1763 (let* (collect-bind ; For byte-compiler.
1764 (collect-bind
1765 (lambda (files alist)
1766 ;; Return an alist between variable names and their
1767 ;; value. FILES is a list of setup files names read so
1768 ;; far, used to avoid circular dependencies. ALIST is
1769 ;; the alist collected so far.
1770 (let ((case-fold-search t))
1771 (org-with-wide-buffer
1772 (goto-char (point-min))
1773 (while (re-search-forward
1774 "^[ \t]*#\\+\\(BIND\\|SETUPFILE\\):" nil t)
1775 (let ((element (org-element-at-point)))
1776 (when (eq (org-element-type element) 'keyword)
1777 (let ((val (org-element-property :value element)))
1778 (if (equal (org-element-property :key element) "BIND")
1779 (push (read (format "(%s)" val)) alist)
1780 ;; Enter setup file.
1781 (let ((file (expand-file-name
1782 (org-remove-double-quotes val))))
1783 (unless (member file files)
1784 (with-temp-buffer
1785 (let ((org-inhibit-startup t)) (org-mode))
1786 (insert (org-file-contents file 'noerror))
1787 (setq alist
1788 (funcall collect-bind
1789 (cons file files)
1790 alist))))))))))
1791 alist)))))
1792 ;; Return value in appropriate order of appearance.
1793 (nreverse (funcall collect-bind nil nil)))))
1796 ;;;; Tree Properties
1798 ;; Tree properties are information extracted from parse tree. They
1799 ;; are initialized at the beginning of the transcoding process by
1800 ;; `org-export-collect-tree-properties'.
1802 ;; Dedicated functions focus on computing the value of specific tree
1803 ;; properties during initialization. Thus,
1804 ;; `org-export--populate-ignore-list' lists elements and objects that
1805 ;; should be skipped during export, `org-export--get-min-level' gets
1806 ;; the minimal exportable level, used as a basis to compute relative
1807 ;; level for headlines. Eventually
1808 ;; `org-export--collect-headline-numbering' builds an alist between
1809 ;; headlines and their numbering.
1811 (defun org-export-collect-tree-properties (data info)
1812 "Extract tree properties from parse tree.
1814 DATA is the parse tree from which information is retrieved. INFO
1815 is a list holding export options.
1817 Following tree properties are set or updated:
1819 `:exported-data' Hash table used to memoize results from
1820 `org-export-data'.
1822 `:footnote-definition-alist' List of footnotes definitions in
1823 original buffer and current parse tree.
1825 `:headline-offset' Offset between true level of headlines and
1826 local level. An offset of -1 means a headline
1827 of level 2 should be considered as a level
1828 1 headline in the context.
1830 `:headline-numbering' Alist of all headlines as key an the
1831 associated numbering as value.
1833 `:ignore-list' List of elements that should be ignored during
1834 export.
1836 Return updated plist."
1837 ;; Install the parse tree in the communication channel, in order to
1838 ;; use `org-export-get-genealogy' and al.
1839 (setq info (plist-put info :parse-tree data))
1840 ;; Get the list of elements and objects to ignore, and put it into
1841 ;; `:ignore-list'. Do not overwrite any user ignore that might have
1842 ;; been done during parse tree filtering.
1843 (setq info
1844 (plist-put info
1845 :ignore-list
1846 (append (org-export--populate-ignore-list data info)
1847 (plist-get info :ignore-list))))
1848 ;; Compute `:headline-offset' in order to be able to use
1849 ;; `org-export-get-relative-level'.
1850 (setq info
1851 (plist-put info
1852 :headline-offset
1853 (- 1 (org-export--get-min-level data info))))
1854 ;; Update footnotes definitions list with definitions in parse tree.
1855 ;; This is required since buffer expansion might have modified
1856 ;; boundaries of footnote definitions contained in the parse tree.
1857 ;; This way, definitions in `footnote-definition-alist' are bound to
1858 ;; match those in the parse tree.
1859 (let ((defs (plist-get info :footnote-definition-alist)))
1860 (org-element-map data 'footnote-definition
1861 (lambda (fn)
1862 (push (cons (org-element-property :label fn)
1863 `(org-data nil ,@(org-element-contents fn)))
1864 defs)))
1865 (setq info (plist-put info :footnote-definition-alist defs)))
1866 ;; Properties order doesn't matter: get the rest of the tree
1867 ;; properties.
1868 (nconc
1869 `(:headline-numbering ,(org-export--collect-headline-numbering data info)
1870 :exported-data ,(make-hash-table :test 'eq :size 4001))
1871 info))
1873 (defun org-export--get-min-level (data options)
1874 "Return minimum exportable headline's level in DATA.
1875 DATA is parsed tree as returned by `org-element-parse-buffer'.
1876 OPTIONS is a plist holding export options."
1877 (catch 'exit
1878 (let ((min-level 10000))
1879 (mapc
1880 (lambda (blob)
1881 (when (and (eq (org-element-type blob) 'headline)
1882 (not (org-element-property :footnote-section-p blob))
1883 (not (memq blob (plist-get options :ignore-list))))
1884 (setq min-level (min (org-element-property :level blob) min-level)))
1885 (when (= min-level 1) (throw 'exit 1)))
1886 (org-element-contents data))
1887 ;; If no headline was found, for the sake of consistency, set
1888 ;; minimum level to 1 nonetheless.
1889 (if (= min-level 10000) 1 min-level))))
1891 (defun org-export--collect-headline-numbering (data options)
1892 "Return numbering of all exportable headlines in a parse tree.
1894 DATA is the parse tree. OPTIONS is the plist holding export
1895 options.
1897 Return an alist whose key is a headline and value is its
1898 associated numbering \(in the shape of a list of numbers\) or nil
1899 for a footnotes section."
1900 (let ((numbering (make-vector org-export-max-depth 0)))
1901 (org-element-map data 'headline
1902 (lambda (headline)
1903 (unless (org-element-property :footnote-section-p headline)
1904 (let ((relative-level
1905 (1- (org-export-get-relative-level headline options))))
1906 (cons
1907 headline
1908 (loop for n across numbering
1909 for idx from 0 to org-export-max-depth
1910 when (< idx relative-level) collect n
1911 when (= idx relative-level) collect (aset numbering idx (1+ n))
1912 when (> idx relative-level) do (aset numbering idx 0))))))
1913 options)))
1915 (defun org-export--populate-ignore-list (data options)
1916 "Return list of elements and objects to ignore during export.
1917 DATA is the parse tree to traverse. OPTIONS is the plist holding
1918 export options."
1919 (let* (ignore
1920 walk-data
1921 ;; First find trees containing a select tag, if any.
1922 (selected (org-export--selected-trees data options))
1923 (walk-data
1924 (lambda (data)
1925 ;; Collect ignored elements or objects into IGNORE-LIST.
1926 (let ((type (org-element-type data)))
1927 (if (org-export--skip-p data options selected) (push data ignore)
1928 (if (and (eq type 'headline)
1929 (eq (plist-get options :with-archived-trees) 'headline)
1930 (org-element-property :archivedp data))
1931 ;; If headline is archived but tree below has
1932 ;; to be skipped, add it to ignore list.
1933 (mapc (lambda (e) (push e ignore))
1934 (org-element-contents data))
1935 ;; Move into secondary string, if any.
1936 (let ((sec-prop
1937 (cdr (assq type org-element-secondary-value-alist))))
1938 (when sec-prop
1939 (mapc walk-data (org-element-property sec-prop data))))
1940 ;; Move into recursive objects/elements.
1941 (mapc walk-data (org-element-contents data))))))))
1942 ;; Main call.
1943 (funcall walk-data data)
1944 ;; Return value.
1945 ignore))
1947 (defun org-export--selected-trees (data info)
1948 "Return list of headlines and inlinetasks with a select tag in their tree.
1949 DATA is parsed data as returned by `org-element-parse-buffer'.
1950 INFO is a plist holding export options."
1951 (let* (selected-trees
1952 walk-data ; For byte-compiler.
1953 (walk-data
1954 (function
1955 (lambda (data genealogy)
1956 (let ((type (org-element-type data)))
1957 (cond
1958 ((memq type '(headline inlinetask))
1959 (let ((tags (org-element-property :tags data)))
1960 (if (loop for tag in (plist-get info :select-tags)
1961 thereis (member tag tags))
1962 ;; When a select tag is found, mark full
1963 ;; genealogy and every headline within the tree
1964 ;; as acceptable.
1965 (setq selected-trees
1966 (append
1967 genealogy
1968 (org-element-map data '(headline inlinetask)
1969 'identity)
1970 selected-trees))
1971 ;; If at a headline, continue searching in tree,
1972 ;; recursively.
1973 (when (eq type 'headline)
1974 (mapc (lambda (el)
1975 (funcall walk-data el (cons data genealogy)))
1976 (org-element-contents data))))))
1977 ((or (eq type 'org-data)
1978 (memq type org-element-greater-elements))
1979 (mapc (lambda (el) (funcall walk-data el genealogy))
1980 (org-element-contents data)))))))))
1981 (funcall walk-data data nil)
1982 selected-trees))
1984 (defun org-export--skip-p (blob options selected)
1985 "Non-nil when element or object BLOB should be skipped during export.
1986 OPTIONS is the plist holding export options. SELECTED, when
1987 non-nil, is a list of headlines or inlinetasks belonging to
1988 a tree with a select tag."
1989 (case (org-element-type blob)
1990 (clock (not (plist-get options :with-clocks)))
1991 (drawer
1992 (let ((with-drawers-p (plist-get options :with-drawers)))
1993 (or (not with-drawers-p)
1994 (and (consp with-drawers-p)
1995 ;; If `:with-drawers' value starts with `not', ignore
1996 ;; every drawer whose name belong to that list.
1997 ;; Otherwise, ignore drawers whose name isn't in that
1998 ;; list.
1999 (let ((name (org-element-property :drawer-name blob)))
2000 (if (eq (car with-drawers-p) 'not)
2001 (member-ignore-case name (cdr with-drawers-p))
2002 (not (member-ignore-case name with-drawers-p))))))))
2003 ((footnote-definition footnote-reference)
2004 (not (plist-get options :with-footnotes)))
2005 ((headline inlinetask)
2006 (let ((with-tasks (plist-get options :with-tasks))
2007 (todo (org-element-property :todo-keyword blob))
2008 (todo-type (org-element-property :todo-type blob))
2009 (archived (plist-get options :with-archived-trees))
2010 (tags (org-element-property :tags blob)))
2012 (and (eq (org-element-type blob) 'inlinetask)
2013 (not (plist-get options :with-inlinetasks)))
2014 ;; Ignore subtrees with an exclude tag.
2015 (loop for k in (plist-get options :exclude-tags)
2016 thereis (member k tags))
2017 ;; When a select tag is present in the buffer, ignore any tree
2018 ;; without it.
2019 (and selected (not (memq blob selected)))
2020 ;; Ignore commented sub-trees.
2021 (org-element-property :commentedp blob)
2022 ;; Ignore archived subtrees if `:with-archived-trees' is nil.
2023 (and (not archived) (org-element-property :archivedp blob))
2024 ;; Ignore tasks, if specified by `:with-tasks' property.
2025 (and todo
2026 (or (not with-tasks)
2027 (and (memq with-tasks '(todo done))
2028 (not (eq todo-type with-tasks)))
2029 (and (consp with-tasks) (not (member todo with-tasks))))))))
2030 ((latex-environment latex-fragment) (not (plist-get options :with-latex)))
2031 (planning (not (plist-get options :with-planning)))
2032 (statistics-cookie (not (plist-get options :with-statistics-cookies)))
2033 (table-cell
2034 (and (org-export-table-has-special-column-p
2035 (org-export-get-parent-table blob))
2036 (not (org-export-get-previous-element blob options))))
2037 (table-row (org-export-table-row-is-special-p blob options))
2038 (timestamp
2039 ;; `:with-timestamps' only applies to isolated timestamps
2040 ;; objects, i.e. timestamp objects in a paragraph containing only
2041 ;; timestamps and whitespaces.
2042 (when (let ((parent (org-export-get-parent-element blob)))
2043 (and (memq (org-element-type parent) '(paragraph verse-block))
2044 (not (org-element-map parent
2045 (cons 'plain-text
2046 (remq 'timestamp org-element-all-objects))
2047 (lambda (obj)
2048 (or (not (stringp obj)) (org-string-nw-p obj)))
2049 options t))))
2050 (case (plist-get options :with-timestamps)
2051 ('nil t)
2052 (active
2053 (not (memq (org-element-property :type blob) '(active active-range))))
2054 (inactive
2055 (not (memq (org-element-property :type blob)
2056 '(inactive inactive-range)))))))))
2059 ;;; The Transcoder
2061 ;; `org-export-data' reads a parse tree (obtained with, i.e.
2062 ;; `org-element-parse-buffer') and transcodes it into a specified
2063 ;; back-end output. It takes care of filtering out elements or
2064 ;; objects according to export options and organizing the output blank
2065 ;; lines and white space are preserved. The function memoizes its
2066 ;; results, so it is cheap to call it within translators.
2068 ;; It is possible to modify locally the back-end used by
2069 ;; `org-export-data' or even use a temporary back-end by using
2070 ;; `org-export-data-with-translations' and
2071 ;; `org-export-data-with-backend'.
2073 ;; Internally, three functions handle the filtering of objects and
2074 ;; elements during the export. In particular,
2075 ;; `org-export-ignore-element' marks an element or object so future
2076 ;; parse tree traversals skip it, `org-export--interpret-p' tells which
2077 ;; elements or objects should be seen as real Org syntax and
2078 ;; `org-export-expand' transforms the others back into their original
2079 ;; shape
2081 ;; `org-export-transcoder' is an accessor returning appropriate
2082 ;; translator function for a given element or object.
2084 (defun org-export-transcoder (blob info)
2085 "Return appropriate transcoder for BLOB.
2086 INFO is a plist containing export directives."
2087 (let ((type (org-element-type blob)))
2088 ;; Return contents only for complete parse trees.
2089 (if (eq type 'org-data) (lambda (blob contents info) contents)
2090 (let ((transcoder (cdr (assq type (plist-get info :translate-alist)))))
2091 (and (functionp transcoder) transcoder)))))
2093 (defun org-export-data (data info)
2094 "Convert DATA into current back-end format.
2096 DATA is a parse tree, an element or an object or a secondary
2097 string. INFO is a plist holding export options.
2099 Return transcoded string."
2100 (let ((memo (gethash data (plist-get info :exported-data) 'no-memo)))
2101 (if (not (eq memo 'no-memo)) memo
2102 (let* ((type (org-element-type data))
2103 (results
2104 (cond
2105 ;; Ignored element/object.
2106 ((memq data (plist-get info :ignore-list)) nil)
2107 ;; Plain text.
2108 ((eq type 'plain-text)
2109 (org-export-filter-apply-functions
2110 (plist-get info :filter-plain-text)
2111 (let ((transcoder (org-export-transcoder data info)))
2112 (if transcoder (funcall transcoder data info) data))
2113 info))
2114 ;; Uninterpreted element/object: change it back to Org
2115 ;; syntax and export again resulting raw string.
2116 ((not (org-export--interpret-p data info))
2117 (org-export-data
2118 (org-export-expand
2119 data
2120 (mapconcat (lambda (blob) (org-export-data blob info))
2121 (org-element-contents data)
2122 ""))
2123 info))
2124 ;; Secondary string.
2125 ((not type)
2126 (mapconcat (lambda (obj) (org-export-data obj info)) data ""))
2127 ;; Element/Object without contents or, as a special case,
2128 ;; headline with archive tag and archived trees restricted
2129 ;; to title only.
2130 ((or (not (org-element-contents data))
2131 (and (eq type 'headline)
2132 (eq (plist-get info :with-archived-trees) 'headline)
2133 (org-element-property :archivedp data)))
2134 (let ((transcoder (org-export-transcoder data info)))
2135 (or (and (functionp transcoder)
2136 (funcall transcoder data nil info))
2137 ;; Export snippets never return a nil value so
2138 ;; that white spaces following them are never
2139 ;; ignored.
2140 (and (eq type 'export-snippet) ""))))
2141 ;; Element/Object with contents.
2143 (let ((transcoder (org-export-transcoder data info)))
2144 (when transcoder
2145 (let* ((greaterp (memq type org-element-greater-elements))
2146 (objectp
2147 (and (not greaterp)
2148 (memq type org-element-recursive-objects)))
2149 (contents
2150 (mapconcat
2151 (lambda (element) (org-export-data element info))
2152 (org-element-contents
2153 (if (or greaterp objectp) data
2154 ;; Elements directly containing objects
2155 ;; must have their indentation normalized
2156 ;; first.
2157 (org-element-normalize-contents
2158 data
2159 ;; When normalizing contents of the first
2160 ;; paragraph in an item or a footnote
2161 ;; definition, ignore first line's
2162 ;; indentation: there is none and it
2163 ;; might be misleading.
2164 (when (eq type 'paragraph)
2165 (let ((parent (org-export-get-parent data)))
2166 (and
2167 (eq (car (org-element-contents parent))
2168 data)
2169 (memq (org-element-type parent)
2170 '(footnote-definition item))))))))
2171 "")))
2172 (funcall transcoder data
2173 (if (not greaterp) contents
2174 (org-element-normalize-string contents))
2175 info))))))))
2176 ;; Final result will be memoized before being returned.
2177 (puthash
2178 data
2179 (cond
2180 ((not results) nil)
2181 ((memq type '(org-data plain-text nil)) results)
2182 ;; Append the same white space between elements or objects as in
2183 ;; the original buffer, and call appropriate filters.
2185 (let ((results
2186 (org-export-filter-apply-functions
2187 (plist-get info (intern (format ":filter-%s" type)))
2188 (let ((post-blank (or (org-element-property :post-blank data)
2189 0)))
2190 (if (memq type org-element-all-elements)
2191 (concat (org-element-normalize-string results)
2192 (make-string post-blank ?\n))
2193 (concat results (make-string post-blank ? ))))
2194 info)))
2195 results)))
2196 (plist-get info :exported-data))))))
2198 (defun org-export-data-with-translations (data translations info)
2199 "Convert DATA into another format using a given translation table.
2200 DATA is an element, an object, a secondary string or a string.
2201 TRANSLATIONS is an alist between element or object types and
2202 a functions handling them. See `org-export-define-backend' for
2203 more information. INFO is a plist used as a communication
2204 channel."
2205 (org-export-data
2206 data
2207 ;; Set-up a new communication channel with TRANSLATIONS as the
2208 ;; translate table and a new hash table for memoization.
2209 (org-combine-plists
2210 info
2211 (list :translate-alist translations
2212 ;; Size of the hash table is reduced since this function
2213 ;; will probably be used on short trees.
2214 :exported-data (make-hash-table :test 'eq :size 401)))))
2216 (defun org-export-data-with-backend (data backend info)
2217 "Convert DATA into BACKEND format.
2219 DATA is an element, an object, a secondary string or a string.
2220 BACKEND is a symbol. INFO is a plist used as a communication
2221 channel.
2223 Unlike to `org-export-with-backend', this function will
2224 recursively convert DATA using BACKEND translation table."
2225 (org-export-barf-if-invalid-backend backend)
2226 (org-export-data-with-translations
2227 data (org-export-backend-translate-table backend) info))
2229 (defun org-export--interpret-p (blob info)
2230 "Non-nil if element or object BLOB should be interpreted during export.
2231 If nil, BLOB will appear as raw Org syntax. Check is done
2232 according to export options INFO, stored as a plist."
2233 (case (org-element-type blob)
2234 ;; ... entities...
2235 (entity (plist-get info :with-entities))
2236 ;; ... emphasis...
2237 ((bold italic strike-through underline)
2238 (plist-get info :with-emphasize))
2239 ;; ... fixed-width areas.
2240 (fixed-width (plist-get info :with-fixed-width))
2241 ;; ... LaTeX environments and fragments...
2242 ((latex-environment latex-fragment)
2243 (let ((with-latex-p (plist-get info :with-latex)))
2244 (and with-latex-p (not (eq with-latex-p 'verbatim)))))
2245 ;; ... sub/superscripts...
2246 ((subscript superscript)
2247 (let ((sub/super-p (plist-get info :with-sub-superscript)))
2248 (if (eq sub/super-p '{})
2249 (org-element-property :use-brackets-p blob)
2250 sub/super-p)))
2251 ;; ... tables...
2252 (table (plist-get info :with-tables))
2253 (otherwise t)))
2255 (defun org-export-expand (blob contents &optional with-affiliated)
2256 "Expand a parsed element or object to its original state.
2258 BLOB is either an element or an object. CONTENTS is its
2259 contents, as a string or nil.
2261 When optional argument WITH-AFFILIATED is non-nil, add affiliated
2262 keywords before output."
2263 (let ((type (org-element-type blob)))
2264 (concat (and with-affiliated (memq type org-element-all-elements)
2265 (org-element--interpret-affiliated-keywords blob))
2266 (funcall (intern (format "org-element-%s-interpreter" type))
2267 blob contents))))
2269 (defun org-export-ignore-element (element info)
2270 "Add ELEMENT to `:ignore-list' in INFO.
2272 Any element in `:ignore-list' will be skipped when using
2273 `org-element-map'. INFO is modified by side effects."
2274 (plist-put info :ignore-list (cons element (plist-get info :ignore-list))))
2278 ;;; The Filter System
2280 ;; Filters allow end-users to tweak easily the transcoded output.
2281 ;; They are the functional counterpart of hooks, as every filter in
2282 ;; a set is applied to the return value of the previous one.
2284 ;; Every set is back-end agnostic. Although, a filter is always
2285 ;; called, in addition to the string it applies to, with the back-end
2286 ;; used as argument, so it's easy for the end-user to add back-end
2287 ;; specific filters in the set. The communication channel, as
2288 ;; a plist, is required as the third argument.
2290 ;; From the developer side, filters sets can be installed in the
2291 ;; process with the help of `org-export-define-backend', which
2292 ;; internally stores filters as an alist. Each association has a key
2293 ;; among the following symbols and a function or a list of functions
2294 ;; as value.
2296 ;; - `:filter-options' applies to the property list containing export
2297 ;; options. Unlike to other filters, functions in this list accept
2298 ;; two arguments instead of three: the property list containing
2299 ;; export options and the back-end. Users can set its value through
2300 ;; `org-export-filter-options-functions' variable.
2302 ;; - `:filter-parse-tree' applies directly to the complete parsed
2303 ;; tree. Users can set it through
2304 ;; `org-export-filter-parse-tree-functions' variable.
2306 ;; - `:filter-final-output' applies to the final transcoded string.
2307 ;; Users can set it with `org-export-filter-final-output-functions'
2308 ;; variable
2310 ;; - `:filter-plain-text' applies to any string not recognized as Org
2311 ;; syntax. `org-export-filter-plain-text-functions' allows users to
2312 ;; configure it.
2314 ;; - `:filter-TYPE' applies on the string returned after an element or
2315 ;; object of type TYPE has been transcoded. A user can modify
2316 ;; `org-export-filter-TYPE-functions'
2318 ;; All filters sets are applied with
2319 ;; `org-export-filter-apply-functions' function. Filters in a set are
2320 ;; applied in a LIFO fashion. It allows developers to be sure that
2321 ;; their filters will be applied first.
2323 ;; Filters properties are installed in communication channel with
2324 ;; `org-export-install-filters' function.
2326 ;; Eventually, two hooks (`org-export-before-processing-hook' and
2327 ;; `org-export-before-parsing-hook') are run at the beginning of the
2328 ;; export process and just before parsing to allow for heavy structure
2329 ;; modifications.
2332 ;;;; Hooks
2334 (defvar org-export-before-processing-hook nil
2335 "Hook run at the beginning of the export process.
2337 This is run before include keywords and macros are expanded and
2338 Babel code blocks executed, on a copy of the original buffer
2339 being exported. Visibility and narrowing are preserved. Point
2340 is at the beginning of the buffer.
2342 Every function in this hook will be called with one argument: the
2343 back-end currently used, as a symbol.")
2345 (defvar org-export-before-parsing-hook nil
2346 "Hook run before parsing an export buffer.
2348 This is run after include keywords and macros have been expanded
2349 and Babel code blocks executed, on a copy of the original buffer
2350 being exported. Visibility and narrowing are preserved. Point
2351 is at the beginning of the buffer.
2353 Every function in this hook will be called with one argument: the
2354 back-end currently used, as a symbol.")
2357 ;;;; Special Filters
2359 (defvar org-export-filter-options-functions nil
2360 "List of functions applied to the export options.
2361 Each filter is called with two arguments: the export options, as
2362 a plist, and the back-end, as a symbol. It must return
2363 a property list containing export options.")
2365 (defvar org-export-filter-parse-tree-functions nil
2366 "List of functions applied to the parsed tree.
2367 Each filter is called with three arguments: the parse tree, as
2368 returned by `org-element-parse-buffer', the back-end, as
2369 a symbol, and the communication channel, as a plist. It must
2370 return the modified parse tree to transcode.")
2372 (defvar org-export-filter-plain-text-functions nil
2373 "List of functions applied to plain text.
2374 Each filter is called with three arguments: a string which
2375 contains no Org syntax, the back-end, as a symbol, and the
2376 communication channel, as a plist. It must return a string or
2377 nil.")
2379 (defvar org-export-filter-final-output-functions nil
2380 "List of functions applied to the transcoded string.
2381 Each filter is called with three arguments: the full transcoded
2382 string, the back-end, as a symbol, and the communication channel,
2383 as a plist. It must return a string that will be used as the
2384 final export output.")
2387 ;;;; Elements Filters
2389 (defvar org-export-filter-babel-call-functions nil
2390 "List of functions applied to a transcoded babel-call.
2391 Each filter is called with three arguments: the transcoded data,
2392 as a string, the back-end, as a symbol, and the communication
2393 channel, as a plist. It must return a string or nil.")
2395 (defvar org-export-filter-center-block-functions nil
2396 "List of functions applied to a transcoded center block.
2397 Each filter is called with three arguments: the transcoded data,
2398 as a string, the back-end, as a symbol, and the communication
2399 channel, as a plist. It must return a string or nil.")
2401 (defvar org-export-filter-clock-functions nil
2402 "List of functions applied to a transcoded clock.
2403 Each filter is called with three arguments: the transcoded data,
2404 as a string, the back-end, as a symbol, and the communication
2405 channel, as a plist. It must return a string or nil.")
2407 (defvar org-export-filter-comment-functions nil
2408 "List of functions applied to a transcoded comment.
2409 Each filter is called with three arguments: the transcoded data,
2410 as a string, the back-end, as a symbol, and the communication
2411 channel, as a plist. It must return a string or nil.")
2413 (defvar org-export-filter-comment-block-functions nil
2414 "List of functions applied to a transcoded comment-block.
2415 Each filter is called with three arguments: the transcoded data,
2416 as a string, the back-end, as a symbol, and the communication
2417 channel, as a plist. It must return a string or nil.")
2419 (defvar org-export-filter-diary-sexp-functions nil
2420 "List of functions applied to a transcoded diary-sexp.
2421 Each filter is called with three arguments: the transcoded data,
2422 as a string, the back-end, as a symbol, and the communication
2423 channel, as a plist. It must return a string or nil.")
2425 (defvar org-export-filter-drawer-functions nil
2426 "List of functions applied to a transcoded drawer.
2427 Each filter is called with three arguments: the transcoded data,
2428 as a string, the back-end, as a symbol, and the communication
2429 channel, as a plist. It must return a string or nil.")
2431 (defvar org-export-filter-dynamic-block-functions nil
2432 "List of functions applied to a transcoded dynamic-block.
2433 Each filter is called with three arguments: the transcoded data,
2434 as a string, the back-end, as a symbol, and the communication
2435 channel, as a plist. It must return a string or nil.")
2437 (defvar org-export-filter-example-block-functions nil
2438 "List of functions applied to a transcoded example-block.
2439 Each filter is called with three arguments: the transcoded data,
2440 as a string, the back-end, as a symbol, and the communication
2441 channel, as a plist. It must return a string or nil.")
2443 (defvar org-export-filter-export-block-functions nil
2444 "List of functions applied to a transcoded export-block.
2445 Each filter is called with three arguments: the transcoded data,
2446 as a string, the back-end, as a symbol, and the communication
2447 channel, as a plist. It must return a string or nil.")
2449 (defvar org-export-filter-fixed-width-functions nil
2450 "List of functions applied to a transcoded fixed-width.
2451 Each filter is called with three arguments: the transcoded data,
2452 as a string, the back-end, as a symbol, and the communication
2453 channel, as a plist. It must return a string or nil.")
2455 (defvar org-export-filter-footnote-definition-functions nil
2456 "List of functions applied to a transcoded footnote-definition.
2457 Each filter is called with three arguments: the transcoded data,
2458 as a string, the back-end, as a symbol, and the communication
2459 channel, as a plist. It must return a string or nil.")
2461 (defvar org-export-filter-headline-functions nil
2462 "List of functions applied to a transcoded headline.
2463 Each filter is called with three arguments: the transcoded data,
2464 as a string, the back-end, as a symbol, and the communication
2465 channel, as a plist. It must return a string or nil.")
2467 (defvar org-export-filter-horizontal-rule-functions nil
2468 "List of functions applied to a transcoded horizontal-rule.
2469 Each filter is called with three arguments: the transcoded data,
2470 as a string, the back-end, as a symbol, and the communication
2471 channel, as a plist. It must return a string or nil.")
2473 (defvar org-export-filter-inlinetask-functions nil
2474 "List of functions applied to a transcoded inlinetask.
2475 Each filter is called with three arguments: the transcoded data,
2476 as a string, the back-end, as a symbol, and the communication
2477 channel, as a plist. It must return a string or nil.")
2479 (defvar org-export-filter-item-functions nil
2480 "List of functions applied to a transcoded item.
2481 Each filter is called with three arguments: the transcoded data,
2482 as a string, the back-end, as a symbol, and the communication
2483 channel, as a plist. It must return a string or nil.")
2485 (defvar org-export-filter-keyword-functions nil
2486 "List of functions applied to a transcoded keyword.
2487 Each filter is called with three arguments: the transcoded data,
2488 as a string, the back-end, as a symbol, and the communication
2489 channel, as a plist. It must return a string or nil.")
2491 (defvar org-export-filter-latex-environment-functions nil
2492 "List of functions applied to a transcoded latex-environment.
2493 Each filter is called with three arguments: the transcoded data,
2494 as a string, the back-end, as a symbol, and the communication
2495 channel, as a plist. It must return a string or nil.")
2497 (defvar org-export-filter-node-property-functions nil
2498 "List of functions applied to a transcoded node-property.
2499 Each filter is called with three arguments: the transcoded data,
2500 as a string, the back-end, as a symbol, and the communication
2501 channel, as a plist. It must return a string or nil.")
2503 (defvar org-export-filter-paragraph-functions nil
2504 "List of functions applied to a transcoded paragraph.
2505 Each filter is called with three arguments: the transcoded data,
2506 as a string, the back-end, as a symbol, and the communication
2507 channel, as a plist. It must return a string or nil.")
2509 (defvar org-export-filter-plain-list-functions nil
2510 "List of functions applied to a transcoded plain-list.
2511 Each filter is called with three arguments: the transcoded data,
2512 as a string, the back-end, as a symbol, and the communication
2513 channel, as a plist. It must return a string or nil.")
2515 (defvar org-export-filter-planning-functions nil
2516 "List of functions applied to a transcoded planning.
2517 Each filter is called with three arguments: the transcoded data,
2518 as a string, the back-end, as a symbol, and the communication
2519 channel, as a plist. It must return a string or nil.")
2521 (defvar org-export-filter-property-drawer-functions nil
2522 "List of functions applied to a transcoded property-drawer.
2523 Each filter is called with three arguments: the transcoded data,
2524 as a string, the back-end, as a symbol, and the communication
2525 channel, as a plist. It must return a string or nil.")
2527 (defvar org-export-filter-quote-block-functions nil
2528 "List of functions applied to a transcoded quote block.
2529 Each filter is called with three arguments: the transcoded quote
2530 data, as a string, the back-end, as a symbol, and the
2531 communication channel, as a plist. It must return a string or
2532 nil.")
2534 (defvar org-export-filter-quote-section-functions nil
2535 "List of functions applied to a transcoded quote-section.
2536 Each filter is called with three arguments: the transcoded data,
2537 as a string, the back-end, as a symbol, and the communication
2538 channel, as a plist. It must return a string or nil.")
2540 (defvar org-export-filter-section-functions nil
2541 "List of functions applied to a transcoded section.
2542 Each filter is called with three arguments: the transcoded data,
2543 as a string, the back-end, as a symbol, and the communication
2544 channel, as a plist. It must return a string or nil.")
2546 (defvar org-export-filter-special-block-functions nil
2547 "List of functions applied to a transcoded special block.
2548 Each filter is called with three arguments: the transcoded data,
2549 as a string, the back-end, as a symbol, and the communication
2550 channel, as a plist. It must return a string or nil.")
2552 (defvar org-export-filter-src-block-functions nil
2553 "List of functions applied to a transcoded src-block.
2554 Each filter is called with three arguments: the transcoded data,
2555 as a string, the back-end, as a symbol, and the communication
2556 channel, as a plist. It must return a string or nil.")
2558 (defvar org-export-filter-table-functions nil
2559 "List of functions applied to a transcoded table.
2560 Each filter is called with three arguments: the transcoded data,
2561 as a string, the back-end, as a symbol, and the communication
2562 channel, as a plist. It must return a string or nil.")
2564 (defvar org-export-filter-table-cell-functions nil
2565 "List of functions applied to a transcoded table-cell.
2566 Each filter is called with three arguments: the transcoded data,
2567 as a string, the back-end, as a symbol, and the communication
2568 channel, as a plist. It must return a string or nil.")
2570 (defvar org-export-filter-table-row-functions nil
2571 "List of functions applied to a transcoded table-row.
2572 Each filter is called with three arguments: the transcoded data,
2573 as a string, the back-end, as a symbol, and the communication
2574 channel, as a plist. It must return a string or nil.")
2576 (defvar org-export-filter-verse-block-functions nil
2577 "List of functions applied to a transcoded verse block.
2578 Each filter is called with three arguments: the transcoded data,
2579 as a string, the back-end, as a symbol, and the communication
2580 channel, as a plist. It must return a string or nil.")
2583 ;;;; Objects Filters
2585 (defvar org-export-filter-bold-functions nil
2586 "List of functions applied to transcoded bold text.
2587 Each filter is called with three arguments: the transcoded data,
2588 as a string, the back-end, as a symbol, and the communication
2589 channel, as a plist. It must return a string or nil.")
2591 (defvar org-export-filter-code-functions nil
2592 "List of functions applied to transcoded code text.
2593 Each filter is called with three arguments: the transcoded data,
2594 as a string, the back-end, as a symbol, and the communication
2595 channel, as a plist. It must return a string or nil.")
2597 (defvar org-export-filter-entity-functions nil
2598 "List of functions applied to a transcoded entity.
2599 Each filter is called with three arguments: the transcoded data,
2600 as a string, the back-end, as a symbol, and the communication
2601 channel, as a plist. It must return a string or nil.")
2603 (defvar org-export-filter-export-snippet-functions nil
2604 "List of functions applied to a transcoded export-snippet.
2605 Each filter is called with three arguments: the transcoded data,
2606 as a string, the back-end, as a symbol, and the communication
2607 channel, as a plist. It must return a string or nil.")
2609 (defvar org-export-filter-footnote-reference-functions nil
2610 "List of functions applied to a transcoded footnote-reference.
2611 Each filter is called with three arguments: the transcoded data,
2612 as a string, the back-end, as a symbol, and the communication
2613 channel, as a plist. It must return a string or nil.")
2615 (defvar org-export-filter-inline-babel-call-functions nil
2616 "List of functions applied to a transcoded inline-babel-call.
2617 Each filter is called with three arguments: the transcoded data,
2618 as a string, the back-end, as a symbol, and the communication
2619 channel, as a plist. It must return a string or nil.")
2621 (defvar org-export-filter-inline-src-block-functions nil
2622 "List of functions applied to a transcoded inline-src-block.
2623 Each filter is called with three arguments: the transcoded data,
2624 as a string, the back-end, as a symbol, and the communication
2625 channel, as a plist. It must return a string or nil.")
2627 (defvar org-export-filter-italic-functions nil
2628 "List of functions applied to transcoded italic text.
2629 Each filter is called with three arguments: the transcoded data,
2630 as a string, the back-end, as a symbol, and the communication
2631 channel, as a plist. It must return a string or nil.")
2633 (defvar org-export-filter-latex-fragment-functions nil
2634 "List of functions applied to a transcoded latex-fragment.
2635 Each filter is called with three arguments: the transcoded data,
2636 as a string, the back-end, as a symbol, and the communication
2637 channel, as a plist. It must return a string or nil.")
2639 (defvar org-export-filter-line-break-functions nil
2640 "List of functions applied to a transcoded line-break.
2641 Each filter is called with three arguments: the transcoded data,
2642 as a string, the back-end, as a symbol, and the communication
2643 channel, as a plist. It must return a string or nil.")
2645 (defvar org-export-filter-link-functions nil
2646 "List of functions applied to a transcoded link.
2647 Each filter is called with three arguments: the transcoded data,
2648 as a string, the back-end, as a symbol, and the communication
2649 channel, as a plist. It must return a string or nil.")
2651 (defvar org-export-filter-radio-target-functions nil
2652 "List of functions applied to a transcoded radio-target.
2653 Each filter is called with three arguments: the transcoded data,
2654 as a string, the back-end, as a symbol, and the communication
2655 channel, as a plist. It must return a string or nil.")
2657 (defvar org-export-filter-statistics-cookie-functions nil
2658 "List of functions applied to a transcoded statistics-cookie.
2659 Each filter is called with three arguments: the transcoded data,
2660 as a string, the back-end, as a symbol, and the communication
2661 channel, as a plist. It must return a string or nil.")
2663 (defvar org-export-filter-strike-through-functions nil
2664 "List of functions applied to transcoded strike-through text.
2665 Each filter is called with three arguments: the transcoded data,
2666 as a string, the back-end, as a symbol, and the communication
2667 channel, as a plist. It must return a string or nil.")
2669 (defvar org-export-filter-subscript-functions nil
2670 "List of functions applied to a transcoded subscript.
2671 Each filter is called with three arguments: the transcoded data,
2672 as a string, the back-end, as a symbol, and the communication
2673 channel, as a plist. It must return a string or nil.")
2675 (defvar org-export-filter-superscript-functions nil
2676 "List of functions applied to a transcoded superscript.
2677 Each filter is called with three arguments: the transcoded data,
2678 as a string, the back-end, as a symbol, and the communication
2679 channel, as a plist. It must return a string or nil.")
2681 (defvar org-export-filter-target-functions nil
2682 "List of functions applied to a transcoded target.
2683 Each filter is called with three arguments: the transcoded data,
2684 as a string, the back-end, as a symbol, and the communication
2685 channel, as a plist. It must return a string or nil.")
2687 (defvar org-export-filter-timestamp-functions nil
2688 "List of functions applied to a transcoded timestamp.
2689 Each filter is called with three arguments: the transcoded data,
2690 as a string, the back-end, as a symbol, and the communication
2691 channel, as a plist. It must return a string or nil.")
2693 (defvar org-export-filter-underline-functions nil
2694 "List of functions applied to transcoded underline text.
2695 Each filter is called with three arguments: the transcoded data,
2696 as a string, the back-end, as a symbol, and the communication
2697 channel, as a plist. It must return a string or nil.")
2699 (defvar org-export-filter-verbatim-functions nil
2700 "List of functions applied to transcoded verbatim text.
2701 Each filter is called with three arguments: the transcoded data,
2702 as a string, the back-end, as a symbol, and the communication
2703 channel, as a plist. It must return a string or nil.")
2706 ;;;; Filters Tools
2708 ;; Internal function `org-export-install-filters' installs filters
2709 ;; hard-coded in back-ends (developer filters) and filters from global
2710 ;; variables (user filters) in the communication channel.
2712 ;; Internal function `org-export-filter-apply-functions' takes care
2713 ;; about applying each filter in order to a given data. It ignores
2714 ;; filters returning a nil value but stops whenever a filter returns
2715 ;; an empty string.
2717 (defun org-export-filter-apply-functions (filters value info)
2718 "Call every function in FILTERS.
2720 Functions are called with arguments VALUE, current export
2721 back-end and INFO. A function returning a nil value will be
2722 skipped. If it returns the empty string, the process ends and
2723 VALUE is ignored.
2725 Call is done in a LIFO fashion, to be sure that developer
2726 specified filters, if any, are called first."
2727 (catch 'exit
2728 (dolist (filter filters value)
2729 (let ((result (funcall filter value (plist-get info :back-end) info)))
2730 (cond ((not result) value)
2731 ((equal value "") (throw 'exit nil))
2732 (t (setq value result)))))))
2734 (defun org-export-install-filters (info)
2735 "Install filters properties in communication channel.
2736 INFO is a plist containing the current communication channel.
2737 Return the updated communication channel."
2738 (let (plist)
2739 ;; Install user-defined filters with `org-export-filters-alist'
2740 ;; and filters already in INFO (through ext-plist mechanism).
2741 (mapc (lambda (p)
2742 (let* ((prop (car p))
2743 (info-value (plist-get info prop))
2744 (default-value (symbol-value (cdr p))))
2745 (setq plist
2746 (plist-put plist prop
2747 ;; Filters in INFO will be called
2748 ;; before those user provided.
2749 (append (if (listp info-value) info-value
2750 (list info-value))
2751 default-value)))))
2752 org-export-filters-alist)
2753 ;; Prepend back-end specific filters to that list.
2754 (mapc (lambda (p)
2755 ;; Single values get consed, lists are appended.
2756 (let ((key (car p)) (value (cdr p)))
2757 (when value
2758 (setq plist
2759 (plist-put
2760 plist key
2761 (if (atom value) (cons value (plist-get plist key))
2762 (append value (plist-get plist key))))))))
2763 (org-export-backend-filters (plist-get info :back-end)))
2764 ;; Return new communication channel.
2765 (org-combine-plists info plist)))
2769 ;;; Core functions
2771 ;; This is the room for the main function, `org-export-as', along with
2772 ;; its derivatives, `org-export-to-buffer', `org-export-to-file' and
2773 ;; `org-export-string-as'. They differ either by the way they output
2774 ;; the resulting code (for the first two) or by the input type (for
2775 ;; the latter). `org-export--copy-to-kill-ring-p' determines if
2776 ;; output of these function should be added to kill ring.
2778 ;; `org-export-output-file-name' is an auxiliary function meant to be
2779 ;; used with `org-export-to-file'. With a given extension, it tries
2780 ;; to provide a canonical file name to write export output to.
2782 ;; Note that `org-export-as' doesn't really parse the current buffer,
2783 ;; but a copy of it (with the same buffer-local variables and
2784 ;; visibility), where macros and include keywords are expanded and
2785 ;; Babel blocks are executed, if appropriate.
2786 ;; `org-export-with-buffer-copy' macro prepares that copy.
2788 ;; File inclusion is taken care of by
2789 ;; `org-export-expand-include-keyword' and
2790 ;; `org-export--prepare-file-contents'. Structure wise, including
2791 ;; a whole Org file in a buffer often makes little sense. For
2792 ;; example, if the file contains a headline and the include keyword
2793 ;; was within an item, the item should contain the headline. That's
2794 ;; why file inclusion should be done before any structure can be
2795 ;; associated to the file, that is before parsing.
2797 ;; `org-export-insert-default-template' is a command to insert
2798 ;; a default template (or a back-end specific template) at point or in
2799 ;; current subtree.
2801 (defun org-export-copy-buffer ()
2802 "Return a copy of the current buffer.
2803 The copy preserves Org buffer-local variables, visibility and
2804 narrowing."
2805 (let ((copy-buffer-fun (org-export--generate-copy-script (current-buffer)))
2806 (new-buf (generate-new-buffer (buffer-name))))
2807 (with-current-buffer new-buf
2808 (funcall copy-buffer-fun)
2809 (set-buffer-modified-p nil))
2810 new-buf))
2812 (defmacro org-export-with-buffer-copy (&rest body)
2813 "Apply BODY in a copy of the current buffer.
2814 The copy preserves local variables, visibility and contents of
2815 the original buffer. Point is at the beginning of the buffer
2816 when BODY is applied."
2817 (declare (debug t))
2818 (org-with-gensyms (buf-copy)
2819 `(let ((,buf-copy (org-export-copy-buffer)))
2820 (unwind-protect
2821 (with-current-buffer ,buf-copy
2822 (goto-char (point-min))
2823 (progn ,@body))
2824 (and (buffer-live-p ,buf-copy)
2825 ;; Kill copy without confirmation.
2826 (progn (with-current-buffer ,buf-copy
2827 (restore-buffer-modified-p nil))
2828 (kill-buffer ,buf-copy)))))))
2830 (defun org-export--generate-copy-script (buffer)
2831 "Generate a function duplicating BUFFER.
2833 The copy will preserve local variables, visibility, contents and
2834 narrowing of the original buffer. If a region was active in
2835 BUFFER, contents will be narrowed to that region instead.
2837 The resulting function can be evaled at a later time, from
2838 another buffer, effectively cloning the original buffer there.
2840 The function assumes BUFFER's major mode is `org-mode'."
2841 (with-current-buffer buffer
2842 `(lambda ()
2843 (let ((inhibit-modification-hooks t))
2844 ;; Set major mode. Ignore `org-mode-hook' as it has been run
2845 ;; already in BUFFER.
2846 (let ((org-mode-hook nil) (org-inhibit-startup t)) (org-mode))
2847 ;; Copy specific buffer local variables and variables set
2848 ;; through BIND keywords.
2849 ,@(let ((bound-variables (org-export--list-bound-variables))
2850 vars)
2851 (dolist (entry (buffer-local-variables (buffer-base-buffer)) vars)
2852 (when (consp entry)
2853 (let ((var (car entry))
2854 (val (cdr entry)))
2855 (and (not (eq var 'org-font-lock-keywords))
2856 (or (memq var
2857 '(default-directory
2858 buffer-file-name
2859 buffer-file-coding-system))
2860 (assq var bound-variables)
2861 (string-match "^\\(org-\\|orgtbl-\\)"
2862 (symbol-name var)))
2863 ;; Skip unreadable values, as they cannot be
2864 ;; sent to external process.
2865 (or (not val) (ignore-errors (read (format "%S" val))))
2866 (push `(set (make-local-variable (quote ,var))
2867 (quote ,val))
2868 vars))))))
2869 ;; Whole buffer contents.
2870 (insert
2871 ,(org-with-wide-buffer
2872 (buffer-substring-no-properties
2873 (point-min) (point-max))))
2874 ;; Narrowing.
2875 ,(if (org-region-active-p)
2876 `(narrow-to-region ,(region-beginning) ,(region-end))
2877 `(narrow-to-region ,(point-min) ,(point-max)))
2878 ;; Current position of point.
2879 (goto-char ,(point))
2880 ;; Overlays with invisible property.
2881 ,@(let (ov-set)
2882 (mapc
2883 (lambda (ov)
2884 (let ((invis-prop (overlay-get ov 'invisible)))
2885 (when invis-prop
2886 (push `(overlay-put
2887 (make-overlay ,(overlay-start ov)
2888 ,(overlay-end ov))
2889 'invisible (quote ,invis-prop))
2890 ov-set))))
2891 (overlays-in (point-min) (point-max)))
2892 ov-set)))))
2894 ;;;###autoload
2895 (defun org-export-as
2896 (backend &optional subtreep visible-only body-only ext-plist)
2897 "Transcode current Org buffer into BACKEND code.
2899 If narrowing is active in the current buffer, only transcode its
2900 narrowed part.
2902 If a region is active, transcode that region.
2904 When optional argument SUBTREEP is non-nil, transcode the
2905 sub-tree at point, extracting information from the headline
2906 properties first.
2908 When optional argument VISIBLE-ONLY is non-nil, don't export
2909 contents of hidden elements.
2911 When optional argument BODY-ONLY is non-nil, only return body
2912 code, without surrounding template.
2914 Optional argument EXT-PLIST, when provided, is a property list
2915 with external parameters overriding Org default settings, but
2916 still inferior to file-local settings.
2918 Return code as a string."
2919 (org-export-barf-if-invalid-backend backend)
2920 (save-excursion
2921 (save-restriction
2922 ;; Narrow buffer to an appropriate region or subtree for
2923 ;; parsing. If parsing subtree, be sure to remove main headline
2924 ;; too.
2925 (cond ((org-region-active-p)
2926 (narrow-to-region (region-beginning) (region-end)))
2927 (subtreep
2928 (org-narrow-to-subtree)
2929 (goto-char (point-min))
2930 (forward-line)
2931 (narrow-to-region (point) (point-max))))
2932 ;; Initialize communication channel with original buffer
2933 ;; attributes, unavailable in its copy.
2934 (let* ((org-export-current-backend backend)
2935 (info (org-combine-plists
2936 (list :export-options
2937 (delq nil
2938 (list (and subtreep 'subtree)
2939 (and visible-only 'visible-only)
2940 (and body-only 'body-only))))
2941 (org-export--get-buffer-attributes)))
2942 tree)
2943 ;; Update communication channel and get parse tree. Buffer
2944 ;; isn't parsed directly. Instead, a temporary copy is
2945 ;; created, where include keywords, macros are expanded and
2946 ;; code blocks are evaluated.
2947 (org-export-with-buffer-copy
2948 ;; Run first hook with current back-end as argument.
2949 (run-hook-with-args 'org-export-before-processing-hook backend)
2950 (org-export-expand-include-keyword)
2951 ;; Update macro templates since #+INCLUDE keywords might have
2952 ;; added some new ones.
2953 (org-macro-initialize-templates)
2954 (org-macro-replace-all org-macro-templates)
2955 (org-export-execute-babel-code)
2956 ;; Update radio targets since keyword inclusion might have
2957 ;; added some more.
2958 (org-update-radio-target-regexp)
2959 ;; Run last hook with current back-end as argument.
2960 (goto-char (point-min))
2961 (save-excursion
2962 (run-hook-with-args 'org-export-before-parsing-hook backend))
2963 ;; Update communication channel with environment. Also
2964 ;; install user's and developer's filters.
2965 (setq info
2966 (org-export-install-filters
2967 (org-combine-plists
2968 info (org-export-get-environment backend subtreep ext-plist))))
2969 ;; Expand export-specific set of macros: {{{author}}},
2970 ;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done
2971 ;; once regular macros have been expanded, since document
2972 ;; keywords may contain one of them.
2973 (org-macro-replace-all
2974 (list (cons "author"
2975 (org-element-interpret-data (plist-get info :author)))
2976 (cons "date"
2977 (org-element-interpret-data (plist-get info :date)))
2978 ;; EMAIL is not a parsed keyword: store it as-is.
2979 (cons "email" (or (plist-get info :email) ""))
2980 (cons "title"
2981 (org-element-interpret-data (plist-get info :title)))))
2982 ;; Call options filters and update export options. We do not
2983 ;; use `org-export-filter-apply-functions' here since the
2984 ;; arity of such filters is different.
2985 (dolist (filter (plist-get info :filter-options))
2986 (let ((result (funcall filter info backend)))
2987 (when result (setq info result))))
2988 ;; Parse buffer and call parse-tree filter on it.
2989 (setq tree
2990 (org-export-filter-apply-functions
2991 (plist-get info :filter-parse-tree)
2992 (org-element-parse-buffer nil visible-only) info))
2993 ;; Now tree is complete, compute its properties and add them
2994 ;; to communication channel.
2995 (setq info
2996 (org-combine-plists
2997 info (org-export-collect-tree-properties tree info)))
2998 ;; Eventually transcode TREE. Wrap the resulting string into
2999 ;; a template.
3000 (let* ((body (org-element-normalize-string
3001 (or (org-export-data tree info) "")))
3002 (inner-template (cdr (assq 'inner-template
3003 (plist-get info :translate-alist))))
3004 (full-body (if (not (functionp inner-template)) body
3005 (funcall inner-template body info)))
3006 (template (cdr (assq 'template
3007 (plist-get info :translate-alist)))))
3008 ;; Remove all text properties since they cannot be
3009 ;; retrieved from an external process. Finally call
3010 ;; final-output filter and return result.
3011 (org-no-properties
3012 (org-export-filter-apply-functions
3013 (plist-get info :filter-final-output)
3014 (if (or (not (functionp template)) body-only) full-body
3015 (funcall template full-body info))
3016 info))))))))
3018 ;;;###autoload
3019 (defun org-export-to-buffer
3020 (backend buffer &optional subtreep visible-only body-only ext-plist)
3021 "Call `org-export-as' with output to a specified buffer.
3023 BACKEND is the back-end used for transcoding, as a symbol.
3025 BUFFER is the output buffer. If it already exists, it will be
3026 erased first, otherwise, it will be created.
3028 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
3029 EXT-PLIST are similar to those used in `org-export-as', which
3030 see.
3032 Depending on `org-export-copy-to-kill-ring', add buffer contents
3033 to kill ring. Return buffer."
3034 (let ((out (org-export-as backend subtreep visible-only body-only ext-plist))
3035 (buffer (get-buffer-create buffer)))
3036 (with-current-buffer buffer
3037 (erase-buffer)
3038 (insert out)
3039 (goto-char (point-min)))
3040 ;; Maybe add buffer contents to kill ring.
3041 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p out))
3042 (org-kill-new out))
3043 ;; Return buffer.
3044 buffer))
3046 ;;;###autoload
3047 (defun org-export-to-file
3048 (backend file &optional subtreep visible-only body-only ext-plist)
3049 "Call `org-export-as' with output to a specified file.
3051 BACKEND is the back-end used for transcoding, as a symbol. FILE
3052 is the name of the output file, as a string.
3054 Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
3055 EXT-PLIST are similar to those used in `org-export-as', which
3056 see.
3058 Depending on `org-export-copy-to-kill-ring', add file contents
3059 to kill ring. Return output file's name."
3060 ;; Checks for FILE permissions. `write-file' would do the same, but
3061 ;; we'd rather avoid needless transcoding of parse tree.
3062 (unless (file-writable-p file) (error "Output file not writable"))
3063 ;; Insert contents to a temporary buffer and write it to FILE.
3064 (let ((coding buffer-file-coding-system)
3065 (out (org-export-as backend subtreep visible-only body-only ext-plist)))
3066 (with-temp-buffer
3067 (insert out)
3068 (let ((coding-system-for-write (or org-export-coding-system coding)))
3069 (write-file file)))
3070 ;; Maybe add file contents to kill ring.
3071 (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p out))
3072 (org-kill-new out)))
3073 ;; Return full path.
3074 file)
3076 ;;;###autoload
3077 (defun org-export-string-as (string backend &optional body-only ext-plist)
3078 "Transcode STRING into BACKEND code.
3080 When optional argument BODY-ONLY is non-nil, only return body
3081 code, without preamble nor postamble.
3083 Optional argument EXT-PLIST, when provided, is a property list
3084 with external parameters overriding Org default settings, but
3085 still inferior to file-local settings.
3087 Return code as a string."
3088 (with-temp-buffer
3089 (insert string)
3090 (let ((org-inhibit-startup t)) (org-mode))
3091 (org-export-as backend nil nil body-only ext-plist)))
3093 ;;;###autoload
3094 (defun org-export-replace-region-by (backend)
3095 "Replace the active region by its export to BACKEND."
3096 (if (not (org-region-active-p))
3097 (user-error "No active region to replace")
3098 (let* ((beg (region-beginning))
3099 (end (region-end))
3100 (str (buffer-substring beg end)) rpl)
3101 (setq rpl (org-export-string-as str backend t))
3102 (delete-region beg end)
3103 (insert rpl))))
3105 ;;;###autoload
3106 (defun org-export-insert-default-template (&optional backend subtreep)
3107 "Insert all export keywords with default values at beginning of line.
3109 BACKEND is a symbol representing the export back-end for which
3110 specific export options should be added to the template, or
3111 `default' for default template. When it is nil, the user will be
3112 prompted for a category.
3114 If SUBTREEP is non-nil, export configuration will be set up
3115 locally for the subtree through node properties."
3116 (interactive)
3117 (unless (derived-mode-p 'org-mode) (user-error "Not in an Org mode buffer"))
3118 (when (and subtreep (org-before-first-heading-p))
3119 (user-error "No subtree to set export options for"))
3120 (let ((node (and subtreep (save-excursion (org-back-to-heading t) (point))))
3121 (backend (or backend
3122 (intern
3123 (org-completing-read
3124 "Options category: "
3125 (cons "default"
3126 (mapcar (lambda (b) (symbol-name (car b)))
3127 org-export-registered-backends))))))
3128 options keywords)
3129 ;; Populate OPTIONS and KEYWORDS.
3130 (dolist (entry (if (eq backend 'default) org-export-options-alist
3131 (org-export-backend-options backend)))
3132 (let ((keyword (nth 1 entry))
3133 (option (nth 2 entry)))
3134 (cond
3135 (keyword (unless (assoc keyword keywords)
3136 (let ((value
3137 (if (eq (nth 4 entry) 'split)
3138 (mapconcat 'identity (eval (nth 3 entry)) " ")
3139 (eval (nth 3 entry)))))
3140 (push (cons keyword value) keywords))))
3141 (option (unless (assoc option options)
3142 (push (cons option (eval (nth 3 entry))) options))))))
3143 ;; Move to an appropriate location in order to insert options.
3144 (unless subtreep (beginning-of-line))
3145 ;; First get TITLE, DATE, AUTHOR and EMAIL if they belong to the
3146 ;; list of available keywords.
3147 (when (assoc "TITLE" keywords)
3148 (let ((title
3149 (or (let ((visited-file (buffer-file-name (buffer-base-buffer))))
3150 (and visited-file
3151 (file-name-sans-extension
3152 (file-name-nondirectory visited-file))))
3153 (buffer-name (buffer-base-buffer)))))
3154 (if (not subtreep) (insert (format "#+TITLE: %s\n" title))
3155 (org-entry-put node "EXPORT_TITLE" title))))
3156 (when (assoc "DATE" keywords)
3157 (let ((date (with-temp-buffer (org-insert-time-stamp (current-time)))))
3158 (if (not subtreep) (insert "#+DATE: " date "\n")
3159 (org-entry-put node "EXPORT_DATE" date))))
3160 (when (assoc "AUTHOR" keywords)
3161 (let ((author (cdr (assoc "AUTHOR" keywords))))
3162 (if subtreep (org-entry-put node "EXPORT_AUTHOR" author)
3163 (insert
3164 (format "#+AUTHOR:%s\n"
3165 (if (not (org-string-nw-p author)) ""
3166 (concat " " author)))))))
3167 (when (assoc "EMAIL" keywords)
3168 (let ((email (cdr (assoc "EMAIL" keywords))))
3169 (if subtreep (org-entry-put node "EXPORT_EMAIL" email)
3170 (insert
3171 (format "#+EMAIL:%s\n"
3172 (if (not (org-string-nw-p email)) ""
3173 (concat " " email)))))))
3174 ;; Then (multiple) OPTIONS lines. Never go past fill-column.
3175 (when options
3176 (let ((items
3177 (mapcar
3178 (lambda (opt)
3179 (format "%s:%s" (car opt) (format "%s" (cdr opt))))
3180 (sort options (lambda (k1 k2) (string< (car k1) (car k2)))))))
3181 (if subtreep
3182 (org-entry-put
3183 node "EXPORT_OPTIONS" (mapconcat 'identity items " "))
3184 (while items
3185 (insert "#+OPTIONS:")
3186 (let ((width 10))
3187 (while (and items
3188 (< (+ width (length (car items)) 1) fill-column))
3189 (let ((item (pop items)))
3190 (insert " " item)
3191 (incf width (1+ (length item))))))
3192 (insert "\n")))))
3193 ;; And the rest of keywords.
3194 (dolist (key (sort keywords (lambda (k1 k2) (string< (car k1) (car k2)))))
3195 (unless (member (car key) '("TITLE" "DATE" "AUTHOR" "EMAIL"))
3196 (let ((val (cdr key)))
3197 (if subtreep (org-entry-put node (concat "EXPORT_" (car key)) val)
3198 (insert
3199 (format "#+%s:%s\n"
3200 (car key)
3201 (if (org-string-nw-p val) (format " %s" val) "")))))))))
3203 (defun org-export-output-file-name (extension &optional subtreep pub-dir)
3204 "Return output file's name according to buffer specifications.
3206 EXTENSION is a string representing the output file extension,
3207 with the leading dot.
3209 With a non-nil optional argument SUBTREEP, try to determine
3210 output file's name by looking for \"EXPORT_FILE_NAME\" property
3211 of subtree at point.
3213 When optional argument PUB-DIR is set, use it as the publishing
3214 directory.
3216 When optional argument VISIBLE-ONLY is non-nil, don't export
3217 contents of hidden elements.
3219 Return file name as a string."
3220 (let* ((visited-file (buffer-file-name (buffer-base-buffer)))
3221 (base-name
3222 ;; File name may come from EXPORT_FILE_NAME subtree
3223 ;; property, assuming point is at beginning of said
3224 ;; sub-tree.
3225 (file-name-sans-extension
3226 (or (and subtreep
3227 (org-entry-get
3228 (save-excursion
3229 (ignore-errors (org-back-to-heading) (point)))
3230 "EXPORT_FILE_NAME" t))
3231 ;; File name may be extracted from buffer's associated
3232 ;; file, if any.
3233 (and visited-file (file-name-nondirectory visited-file))
3234 ;; Can't determine file name on our own: Ask user.
3235 (let ((read-file-name-function
3236 (and org-completion-use-ido 'ido-read-file-name)))
3237 (read-file-name
3238 "Output file: " pub-dir nil nil nil
3239 (lambda (name)
3240 (string= (file-name-extension name t) extension)))))))
3241 (output-file
3242 ;; Build file name. Enforce EXTENSION over whatever user
3243 ;; may have come up with. PUB-DIR, if defined, always has
3244 ;; precedence over any provided path.
3245 (cond
3246 (pub-dir
3247 (concat (file-name-as-directory pub-dir)
3248 (file-name-nondirectory base-name)
3249 extension))
3250 ((file-name-absolute-p base-name) (concat base-name extension))
3251 (t (concat (file-name-as-directory ".") base-name extension)))))
3252 ;; If writing to OUTPUT-FILE would overwrite original file, append
3253 ;; EXTENSION another time to final name.
3254 (if (and visited-file (org-file-equal-p visited-file output-file))
3255 (concat output-file extension)
3256 output-file)))
3258 (defun org-export-expand-include-keyword (&optional included dir)
3259 "Expand every include keyword in buffer.
3260 Optional argument INCLUDED is a list of included file names along
3261 with their line restriction, when appropriate. It is used to
3262 avoid infinite recursion. Optional argument DIR is the current
3263 working directory. It is used to properly resolve relative
3264 paths."
3265 (let ((case-fold-search t))
3266 (goto-char (point-min))
3267 (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
3268 (let ((element (save-match-data (org-element-at-point))))
3269 (when (eq (org-element-type element) 'keyword)
3270 (beginning-of-line)
3271 ;; Extract arguments from keyword's value.
3272 (let* ((value (org-element-property :value element))
3273 (ind (org-get-indentation))
3274 (file (and (string-match
3275 "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value)
3276 (prog1 (expand-file-name
3277 (org-remove-double-quotes
3278 (match-string 1 value))
3279 dir)
3280 (setq value (replace-match "" nil nil value)))))
3281 (lines
3282 (and (string-match
3283 ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
3284 value)
3285 (prog1 (match-string 1 value)
3286 (setq value (replace-match "" nil nil value)))))
3287 (env (cond ((string-match "\\<example\\>" value) 'example)
3288 ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
3289 (match-string 1 value))))
3290 ;; Minimal level of included file defaults to the child
3291 ;; level of the current headline, if any, or one. It
3292 ;; only applies is the file is meant to be included as
3293 ;; an Org one.
3294 (minlevel
3295 (and (not env)
3296 (if (string-match ":minlevel +\\([0-9]+\\)" value)
3297 (prog1 (string-to-number (match-string 1 value))
3298 (setq value (replace-match "" nil nil value)))
3299 (let ((cur (org-current-level)))
3300 (if cur (1+ (org-reduced-level cur)) 1))))))
3301 ;; Remove keyword.
3302 (delete-region (point) (progn (forward-line) (point)))
3303 (cond
3304 ((not file) nil)
3305 ((not (file-readable-p file))
3306 (error "Cannot include file %s" file))
3307 ;; Check if files has already been parsed. Look after
3308 ;; inclusion lines too, as different parts of the same file
3309 ;; can be included too.
3310 ((member (list file lines) included)
3311 (error "Recursive file inclusion: %s" file))
3313 (cond
3314 ((eq env 'example)
3315 (insert
3316 (let ((ind-str (make-string ind ? ))
3317 (contents
3318 (org-escape-code-in-string
3319 (org-export--prepare-file-contents file lines))))
3320 (format "%s#+BEGIN_EXAMPLE\n%s%s#+END_EXAMPLE\n"
3321 ind-str contents ind-str))))
3322 ((stringp env)
3323 (insert
3324 (let ((ind-str (make-string ind ? ))
3325 (contents
3326 (org-escape-code-in-string
3327 (org-export--prepare-file-contents file lines))))
3328 (format "%s#+BEGIN_SRC %s\n%s%s#+END_SRC\n"
3329 ind-str env contents ind-str))))
3331 (insert
3332 (with-temp-buffer
3333 (let ((org-inhibit-startup t)) (org-mode))
3334 (insert
3335 (org-export--prepare-file-contents file lines ind minlevel))
3336 (org-export-expand-include-keyword
3337 (cons (list file lines) included)
3338 (file-name-directory file))
3339 (buffer-string)))))))))))))
3341 (defun org-export--prepare-file-contents (file &optional lines ind minlevel)
3342 "Prepare the contents of FILE for inclusion and return them as a string.
3344 When optional argument LINES is a string specifying a range of
3345 lines, include only those lines.
3347 Optional argument IND, when non-nil, is an integer specifying the
3348 global indentation of returned contents. Since its purpose is to
3349 allow an included file to stay in the same environment it was
3350 created \(i.e. a list item), it doesn't apply past the first
3351 headline encountered.
3353 Optional argument MINLEVEL, when non-nil, is an integer
3354 specifying the level that any top-level headline in the included
3355 file should have."
3356 (with-temp-buffer
3357 (insert-file-contents file)
3358 (when lines
3359 (let* ((lines (split-string lines "-"))
3360 (lbeg (string-to-number (car lines)))
3361 (lend (string-to-number (cadr lines)))
3362 (beg (if (zerop lbeg) (point-min)
3363 (goto-char (point-min))
3364 (forward-line (1- lbeg))
3365 (point)))
3366 (end (if (zerop lend) (point-max)
3367 (goto-char (point-min))
3368 (forward-line (1- lend))
3369 (point))))
3370 (narrow-to-region beg end)))
3371 ;; Remove blank lines at beginning and end of contents. The logic
3372 ;; behind that removal is that blank lines around include keyword
3373 ;; override blank lines in included file.
3374 (goto-char (point-min))
3375 (org-skip-whitespace)
3376 (beginning-of-line)
3377 (delete-region (point-min) (point))
3378 (goto-char (point-max))
3379 (skip-chars-backward " \r\t\n")
3380 (forward-line)
3381 (delete-region (point) (point-max))
3382 ;; If IND is set, preserve indentation of include keyword until
3383 ;; the first headline encountered.
3384 (when ind
3385 (unless (eq major-mode 'org-mode)
3386 (let ((org-inhibit-startup t)) (org-mode)))
3387 (goto-char (point-min))
3388 (let ((ind-str (make-string ind ? )))
3389 (while (not (or (eobp) (looking-at org-outline-regexp-bol)))
3390 ;; Do not move footnote definitions out of column 0.
3391 (unless (and (looking-at org-footnote-definition-re)
3392 (eq (org-element-type (org-element-at-point))
3393 'footnote-definition))
3394 (insert ind-str))
3395 (forward-line))))
3396 ;; When MINLEVEL is specified, compute minimal level for headlines
3397 ;; in the file (CUR-MIN), and remove stars to each headline so
3398 ;; that headlines with minimal level have a level of MINLEVEL.
3399 (when minlevel
3400 (unless (eq major-mode 'org-mode)
3401 (let ((org-inhibit-startup t)) (org-mode)))
3402 (org-with-limited-levels
3403 (let ((levels (org-map-entries
3404 (lambda () (org-reduced-level (org-current-level))))))
3405 (when levels
3406 (let ((offset (- minlevel (apply 'min levels))))
3407 (unless (zerop offset)
3408 (when org-odd-levels-only (setq offset (* offset 2)))
3409 ;; Only change stars, don't bother moving whole
3410 ;; sections.
3411 (org-map-entries
3412 (lambda () (if (< offset 0) (delete-char (abs offset))
3413 (insert (make-string offset ?*)))))))))))
3414 (org-element-normalize-string (buffer-string))))
3416 (defun org-export-execute-babel-code ()
3417 "Execute every Babel code in the visible part of current buffer."
3418 ;; Get a pristine copy of current buffer so Babel references can be
3419 ;; properly resolved.
3420 (let ((reference (org-export-copy-buffer)))
3421 (unwind-protect (let ((org-current-export-file reference))
3422 (org-babel-exp-process-buffer))
3423 (kill-buffer reference))))
3425 (defun org-export--copy-to-kill-ring-p ()
3426 "Return a non-nil value when output should be added to the kill ring.
3427 See also `org-export-copy-to-kill-ring'."
3428 (if (eq org-export-copy-to-kill-ring 'if-interactive)
3429 (not (or executing-kbd-macro noninteractive))
3430 (eq org-export-copy-to-kill-ring t)))
3434 ;;; Tools For Back-Ends
3436 ;; A whole set of tools is available to help build new exporters. Any
3437 ;; function general enough to have its use across many back-ends
3438 ;; should be added here.
3440 ;;;; For Affiliated Keywords
3442 ;; `org-export-read-attribute' reads a property from a given element
3443 ;; as a plist. It can be used to normalize affiliated keywords'
3444 ;; syntax.
3446 ;; Since captions can span over multiple lines and accept dual values,
3447 ;; their internal representation is a bit tricky. Therefore,
3448 ;; `org-export-get-caption' transparently returns a given element's
3449 ;; caption as a secondary string.
3451 (defun org-export-read-attribute (attribute element &optional property)
3452 "Turn ATTRIBUTE property from ELEMENT into a plist.
3454 When optional argument PROPERTY is non-nil, return the value of
3455 that property within attributes.
3457 This function assumes attributes are defined as \":keyword
3458 value\" pairs. It is appropriate for `:attr_html' like
3459 properties.
3461 All values will become strings except the empty string and
3462 \"nil\", which will become nil. Also, values containing only
3463 double quotes will be read as-is, which means that \"\" value
3464 will become the empty string."
3465 (let* ((prepare-value
3466 (lambda (str)
3467 (save-match-data
3468 (cond ((member str '(nil "" "nil")) nil)
3469 ((string-match "^\"\\(\"+\\)?\"$" str)
3470 (or (match-string 1 str) ""))
3471 (t str)))))
3472 (attributes
3473 (let ((value (org-element-property attribute element)))
3474 (when value
3475 (let ((s (mapconcat 'identity value " ")) result)
3476 (while (string-match
3477 "\\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ \t]+\\|$\\)"
3479 (let ((value (substring s 0 (match-beginning 0))))
3480 (push (funcall prepare-value value) result))
3481 (push (intern (match-string 1 s)) result)
3482 (setq s (substring s (match-end 0))))
3483 ;; Ignore any string before first property with `cdr'.
3484 (cdr (nreverse (cons (funcall prepare-value s) result))))))))
3485 (if property (plist-get attributes property) attributes)))
3487 (defun org-export-get-caption (element &optional shortp)
3488 "Return caption from ELEMENT as a secondary string.
3490 When optional argument SHORTP is non-nil, return short caption,
3491 as a secondary string, instead.
3493 Caption lines are separated by a white space."
3494 (let ((full-caption (org-element-property :caption element)) caption)
3495 (dolist (line full-caption (cdr caption))
3496 (let ((cap (funcall (if shortp 'cdr 'car) line)))
3497 (when cap
3498 (setq caption (nconc (list " ") (copy-sequence cap) caption)))))))
3501 ;;;; For Derived Back-ends
3503 ;; `org-export-with-backend' is a function allowing to locally use
3504 ;; another back-end to transcode some object or element. In a derived
3505 ;; back-end, it may be used as a fall-back function once all specific
3506 ;; cases have been treated.
3508 (defun org-export-with-backend (back-end data &optional contents info)
3509 "Call a transcoder from BACK-END on DATA.
3510 CONTENTS, when non-nil, is the transcoded contents of DATA
3511 element, as a string. INFO, when non-nil, is the communication
3512 channel used for export, as a plist.."
3513 (org-export-barf-if-invalid-backend back-end)
3514 (let ((type (org-element-type data)))
3515 (if (memq type '(nil org-data)) (error "No foreign transcoder available")
3516 (let ((transcoder
3517 (cdr (assq type (org-export-backend-translate-table back-end)))))
3518 (if (functionp transcoder) (funcall transcoder data contents info)
3519 (error "No foreign transcoder available"))))))
3522 ;;;; For Export Snippets
3524 ;; Every export snippet is transmitted to the back-end. Though, the
3525 ;; latter will only retain one type of export-snippet, ignoring
3526 ;; others, based on the former's target back-end. The function
3527 ;; `org-export-snippet-backend' returns that back-end for a given
3528 ;; export-snippet.
3530 (defun org-export-snippet-backend (export-snippet)
3531 "Return EXPORT-SNIPPET targeted back-end as a symbol.
3532 Translation, with `org-export-snippet-translation-alist', is
3533 applied."
3534 (let ((back-end (org-element-property :back-end export-snippet)))
3535 (intern
3536 (or (cdr (assoc back-end org-export-snippet-translation-alist))
3537 back-end))))
3540 ;;;; For Footnotes
3542 ;; `org-export-collect-footnote-definitions' is a tool to list
3543 ;; actually used footnotes definitions in the whole parse tree, or in
3544 ;; a headline, in order to add footnote listings throughout the
3545 ;; transcoded data.
3547 ;; `org-export-footnote-first-reference-p' is a predicate used by some
3548 ;; back-ends, when they need to attach the footnote definition only to
3549 ;; the first occurrence of the corresponding label.
3551 ;; `org-export-get-footnote-definition' and
3552 ;; `org-export-get-footnote-number' provide easier access to
3553 ;; additional information relative to a footnote reference.
3555 (defun org-export-collect-footnote-definitions (data info)
3556 "Return an alist between footnote numbers, labels and definitions.
3558 DATA is the parse tree from which definitions are collected.
3559 INFO is the plist used as a communication channel.
3561 Definitions are sorted by order of references. They either
3562 appear as Org data or as a secondary string for inlined
3563 footnotes. Unreferenced definitions are ignored."
3564 (let* (num-alist
3565 collect-fn ; for byte-compiler.
3566 (collect-fn
3567 (function
3568 (lambda (data)
3569 ;; Collect footnote number, label and definition in DATA.
3570 (org-element-map data 'footnote-reference
3571 (lambda (fn)
3572 (when (org-export-footnote-first-reference-p fn info)
3573 (let ((def (org-export-get-footnote-definition fn info)))
3574 (push
3575 (list (org-export-get-footnote-number fn info)
3576 (org-element-property :label fn)
3577 def)
3578 num-alist)
3579 ;; Also search in definition for nested footnotes.
3580 (when (eq (org-element-property :type fn) 'standard)
3581 (funcall collect-fn def)))))
3582 ;; Don't enter footnote definitions since it will happen
3583 ;; when their first reference is found.
3584 info nil 'footnote-definition)))))
3585 (funcall collect-fn (plist-get info :parse-tree))
3586 (reverse num-alist)))
3588 (defun org-export-footnote-first-reference-p (footnote-reference info)
3589 "Non-nil when a footnote reference is the first one for its label.
3591 FOOTNOTE-REFERENCE is the footnote reference being considered.
3592 INFO is the plist used as a communication channel."
3593 (let ((label (org-element-property :label footnote-reference)))
3594 ;; Anonymous footnotes are always a first reference.
3595 (if (not label) t
3596 ;; Otherwise, return the first footnote with the same LABEL and
3597 ;; test if it is equal to FOOTNOTE-REFERENCE.
3598 (let* (search-refs ; for byte-compiler.
3599 (search-refs
3600 (function
3601 (lambda (data)
3602 (org-element-map data 'footnote-reference
3603 (lambda (fn)
3604 (cond
3605 ((string= (org-element-property :label fn) label)
3606 (throw 'exit fn))
3607 ;; If FN isn't inlined, be sure to traverse its
3608 ;; definition before resuming search. See
3609 ;; comments in `org-export-get-footnote-number'
3610 ;; for more information.
3611 ((eq (org-element-property :type fn) 'standard)
3612 (funcall search-refs
3613 (org-export-get-footnote-definition fn info)))))
3614 ;; Don't enter footnote definitions since it will
3615 ;; happen when their first reference is found.
3616 info 'first-match 'footnote-definition)))))
3617 (eq (catch 'exit (funcall search-refs (plist-get info :parse-tree)))
3618 footnote-reference)))))
3620 (defun org-export-get-footnote-definition (footnote-reference info)
3621 "Return definition of FOOTNOTE-REFERENCE as parsed data.
3622 INFO is the plist used as a communication channel. If no such
3623 definition can be found, return the \"DEFINITION NOT FOUND\"
3624 string."
3625 (let ((label (org-element-property :label footnote-reference)))
3626 (or (org-element-property :inline-definition footnote-reference)
3627 (cdr (assoc label (plist-get info :footnote-definition-alist)))
3628 "DEFINITION NOT FOUND.")))
3630 (defun org-export-get-footnote-number (footnote info)
3631 "Return number associated to a footnote.
3633 FOOTNOTE is either a footnote reference or a footnote definition.
3634 INFO is the plist used as a communication channel."
3635 (let* ((label (org-element-property :label footnote))
3636 seen-refs
3637 search-ref ; For byte-compiler.
3638 (search-ref
3639 (function
3640 (lambda (data)
3641 ;; Search footnote references through DATA, filling
3642 ;; SEEN-REFS along the way.
3643 (org-element-map data 'footnote-reference
3644 (lambda (fn)
3645 (let ((fn-lbl (org-element-property :label fn)))
3646 (cond
3647 ;; Anonymous footnote match: return number.
3648 ((and (not fn-lbl) (eq fn footnote))
3649 (throw 'exit (1+ (length seen-refs))))
3650 ;; Labels match: return number.
3651 ((and label (string= label fn-lbl))
3652 (throw 'exit (1+ (length seen-refs))))
3653 ;; Anonymous footnote: it's always a new one.
3654 ;; Also, be sure to return nil from the `cond' so
3655 ;; `first-match' doesn't get us out of the loop.
3656 ((not fn-lbl) (push 'inline seen-refs) nil)
3657 ;; Label not seen so far: add it so SEEN-REFS.
3659 ;; Also search for subsequent references in
3660 ;; footnote definition so numbering follows
3661 ;; reading logic. Note that we don't have to care
3662 ;; about inline definitions, since
3663 ;; `org-element-map' already traverses them at the
3664 ;; right time.
3666 ;; Once again, return nil to stay in the loop.
3667 ((not (member fn-lbl seen-refs))
3668 (push fn-lbl seen-refs)
3669 (funcall search-ref
3670 (org-export-get-footnote-definition fn info))
3671 nil))))
3672 ;; Don't enter footnote definitions since it will
3673 ;; happen when their first reference is found.
3674 info 'first-match 'footnote-definition)))))
3675 (catch 'exit (funcall search-ref (plist-get info :parse-tree)))))
3678 ;;;; For Headlines
3680 ;; `org-export-get-relative-level' is a shortcut to get headline
3681 ;; level, relatively to the lower headline level in the parsed tree.
3683 ;; `org-export-get-headline-number' returns the section number of an
3684 ;; headline, while `org-export-number-to-roman' allows to convert it
3685 ;; to roman numbers.
3687 ;; `org-export-low-level-p', `org-export-first-sibling-p' and
3688 ;; `org-export-last-sibling-p' are three useful predicates when it
3689 ;; comes to fulfill the `:headline-levels' property.
3691 ;; `org-export-get-tags', `org-export-get-category' and
3692 ;; `org-export-get-node-property' extract useful information from an
3693 ;; headline or a parent headline. They all handle inheritance.
3695 ;; `org-export-get-alt-title' tries to retrieve an alternative title,
3696 ;; as a secondary string, suitable for table of contents. It falls
3697 ;; back onto default title.
3699 (defun org-export-get-relative-level (headline info)
3700 "Return HEADLINE relative level within current parsed tree.
3701 INFO is a plist holding contextual information."
3702 (+ (org-element-property :level headline)
3703 (or (plist-get info :headline-offset) 0)))
3705 (defun org-export-low-level-p (headline info)
3706 "Non-nil when HEADLINE is considered as low level.
3708 INFO is a plist used as a communication channel.
3710 A low level headlines has a relative level greater than
3711 `:headline-levels' property value.
3713 Return value is the difference between HEADLINE relative level
3714 and the last level being considered as high enough, or nil."
3715 (let ((limit (plist-get info :headline-levels)))
3716 (when (wholenump limit)
3717 (let ((level (org-export-get-relative-level headline info)))
3718 (and (> level limit) (- level limit))))))
3720 (defun org-export-get-headline-number (headline info)
3721 "Return HEADLINE numbering as a list of numbers.
3722 INFO is a plist holding contextual information."
3723 (cdr (assoc headline (plist-get info :headline-numbering))))
3725 (defun org-export-numbered-headline-p (headline info)
3726 "Return a non-nil value if HEADLINE element should be numbered.
3727 INFO is a plist used as a communication channel."
3728 (let ((sec-num (plist-get info :section-numbers))
3729 (level (org-export-get-relative-level headline info)))
3730 (if (wholenump sec-num) (<= level sec-num) sec-num)))
3732 (defun org-export-number-to-roman (n)
3733 "Convert integer N into a roman numeral."
3734 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
3735 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
3736 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
3737 ( 1 . "I")))
3738 (res ""))
3739 (if (<= n 0)
3740 (number-to-string n)
3741 (while roman
3742 (if (>= n (caar roman))
3743 (setq n (- n (caar roman))
3744 res (concat res (cdar roman)))
3745 (pop roman)))
3746 res)))
3748 (defun org-export-get-tags (element info &optional tags inherited)
3749 "Return list of tags associated to ELEMENT.
3751 ELEMENT has either an `headline' or an `inlinetask' type. INFO
3752 is a plist used as a communication channel.
3754 Select tags (see `org-export-select-tags') and exclude tags (see
3755 `org-export-exclude-tags') are removed from the list.
3757 When non-nil, optional argument TAGS should be a list of strings.
3758 Any tag belonging to this list will also be removed.
3760 When optional argument INHERITED is non-nil, tags can also be
3761 inherited from parent headlines and FILETAGS keywords."
3762 (org-remove-if
3763 (lambda (tag) (or (member tag (plist-get info :select-tags))
3764 (member tag (plist-get info :exclude-tags))
3765 (member tag tags)))
3766 (if (not inherited) (org-element-property :tags element)
3767 ;; Build complete list of inherited tags.
3768 (let ((current-tag-list (org-element-property :tags element)))
3769 (mapc
3770 (lambda (parent)
3771 (mapc
3772 (lambda (tag)
3773 (when (and (memq (org-element-type parent) '(headline inlinetask))
3774 (not (member tag current-tag-list)))
3775 (push tag current-tag-list)))
3776 (org-element-property :tags parent)))
3777 (org-export-get-genealogy element))
3778 ;; Add FILETAGS keywords and return results.
3779 (org-uniquify (append (plist-get info :filetags) current-tag-list))))))
3781 (defun org-export-get-node-property (property blob &optional inherited)
3782 "Return node PROPERTY value for BLOB.
3784 PROPERTY is an upcase symbol (i.e. `:COOKIE_DATA'). BLOB is an
3785 element or object.
3787 If optional argument INHERITED is non-nil, the value can be
3788 inherited from a parent headline.
3790 Return value is a string or nil."
3791 (let ((headline (if (eq (org-element-type blob) 'headline) blob
3792 (org-export-get-parent-headline blob))))
3793 (if (not inherited) (org-element-property property blob)
3794 (let ((parent headline) value)
3795 (catch 'found
3796 (while parent
3797 (when (plist-member (nth 1 parent) property)
3798 (throw 'found (org-element-property property parent)))
3799 (setq parent (org-element-property :parent parent))))))))
3801 (defun org-export-get-category (blob info)
3802 "Return category for element or object BLOB.
3804 INFO is a plist used as a communication channel.
3806 CATEGORY is automatically inherited from a parent headline, from
3807 #+CATEGORY: keyword or created out of original file name. If all
3808 fail, the fall-back value is \"???\"."
3809 (or (let ((headline (if (eq (org-element-type blob) 'headline) blob
3810 (org-export-get-parent-headline blob))))
3811 ;; Almost like `org-export-node-property', but we cannot trust
3812 ;; `plist-member' as every headline has a `:CATEGORY'
3813 ;; property, would it be nil or equal to "???" (which has the
3814 ;; same meaning).
3815 (let ((parent headline) value)
3816 (catch 'found
3817 (while parent
3818 (let ((category (org-element-property :CATEGORY parent)))
3819 (and category (not (equal "???" category))
3820 (throw 'found category)))
3821 (setq parent (org-element-property :parent parent))))))
3822 (org-element-map (plist-get info :parse-tree) 'keyword
3823 (lambda (kwd)
3824 (when (equal (org-element-property :key kwd) "CATEGORY")
3825 (org-element-property :value kwd)))
3826 info 'first-match)
3827 (let ((file (plist-get info :input-file)))
3828 (and file (file-name-sans-extension (file-name-nondirectory file))))
3829 "???"))
3831 (defun org-export-get-alt-title (headline info)
3832 "Return alternative title for HEADLINE, as a secondary string.
3833 INFO is a plist used as a communication channel. If no optional
3834 title is defined, fall-back to the regular title."
3835 (or (org-element-property :alt-title headline)
3836 (org-element-property :title headline)))
3838 (defun org-export-first-sibling-p (headline info)
3839 "Non-nil when HEADLINE is the first sibling in its sub-tree.
3840 INFO is a plist used as a communication channel."
3841 (not (eq (org-element-type (org-export-get-previous-element headline info))
3842 'headline)))
3844 (defun org-export-last-sibling-p (headline info)
3845 "Non-nil when HEADLINE is the last sibling in its sub-tree.
3846 INFO is a plist used as a communication channel."
3847 (not (org-export-get-next-element headline info)))
3850 ;;;; For Keywords
3852 ;; `org-export-get-date' returns a date appropriate for the document
3853 ;; to about to be exported. In particular, it takes care of
3854 ;; `org-export-date-timestamp-format'.
3856 (defun org-export-get-date (info &optional fmt)
3857 "Return date value for the current document.
3859 INFO is a plist used as a communication channel. FMT, when
3860 non-nil, is a time format string that will be applied on the date
3861 if it consists in a single timestamp object. It defaults to
3862 `org-export-date-timestamp-format' when nil.
3864 A proper date can be a secondary string, a string or nil. It is
3865 meant to be translated with `org-export-data' or alike."
3866 (let ((date (plist-get info :date))
3867 (fmt (or fmt org-export-date-timestamp-format)))
3868 (cond ((not date) nil)
3869 ((and fmt
3870 (not (cdr date))
3871 (eq (org-element-type (car date)) 'timestamp))
3872 (org-timestamp-format (car date) fmt))
3873 (t date))))
3876 ;;;; For Links
3878 ;; `org-export-solidify-link-text' turns a string into a safer version
3879 ;; for links, replacing most non-standard characters with hyphens.
3881 ;; `org-export-get-coderef-format' returns an appropriate format
3882 ;; string for coderefs.
3884 ;; `org-export-inline-image-p' returns a non-nil value when the link
3885 ;; provided should be considered as an inline image.
3887 ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
3888 ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
3889 ;; returns an appropriate unique identifier when found, or nil.
3891 ;; `org-export-resolve-id-link' returns the first headline with
3892 ;; specified id or custom-id in parse tree, the path to the external
3893 ;; file with the id or nil when neither was found.
3895 ;; `org-export-resolve-coderef' associates a reference to a line
3896 ;; number in the element it belongs, or returns the reference itself
3897 ;; when the element isn't numbered.
3899 (defun org-export-solidify-link-text (s)
3900 "Take link text S and make a safe target out of it."
3901 (save-match-data
3902 (mapconcat 'identity (org-split-string s "[^a-zA-Z0-9_.-:]+") "-")))
3904 (defun org-export-get-coderef-format (path desc)
3905 "Return format string for code reference link.
3906 PATH is the link path. DESC is its description."
3907 (save-match-data
3908 (cond ((not desc) "%s")
3909 ((string-match (regexp-quote (concat "(" path ")")) desc)
3910 (replace-match "%s" t t desc))
3911 (t desc))))
3913 (defun org-export-inline-image-p (link &optional rules)
3914 "Non-nil if LINK object points to an inline image.
3916 Optional argument is a set of RULES defining inline images. It
3917 is an alist where associations have the following shape:
3919 \(TYPE . REGEXP)
3921 Applying a rule means apply REGEXP against LINK's path when its
3922 type is TYPE. The function will return a non-nil value if any of
3923 the provided rules is non-nil. The default rule is
3924 `org-export-default-inline-image-rule'.
3926 This only applies to links without a description."
3927 (and (not (org-element-contents link))
3928 (let ((case-fold-search t)
3929 (rules (or rules org-export-default-inline-image-rule)))
3930 (catch 'exit
3931 (mapc
3932 (lambda (rule)
3933 (and (string= (org-element-property :type link) (car rule))
3934 (string-match (cdr rule)
3935 (org-element-property :path link))
3936 (throw 'exit t)))
3937 rules)
3938 ;; Return nil if no rule matched.
3939 nil))))
3941 (defun org-export-resolve-coderef (ref info)
3942 "Resolve a code reference REF.
3944 INFO is a plist used as a communication channel.
3946 Return associated line number in source code, or REF itself,
3947 depending on src-block or example element's switches."
3948 (org-element-map (plist-get info :parse-tree) '(example-block src-block)
3949 (lambda (el)
3950 (with-temp-buffer
3951 (insert (org-trim (org-element-property :value el)))
3952 (let* ((label-fmt (regexp-quote
3953 (or (org-element-property :label-fmt el)
3954 org-coderef-label-format)))
3955 (ref-re
3956 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
3957 (replace-regexp-in-string "%s" ref label-fmt nil t))))
3958 ;; Element containing REF is found. Resolve it to either
3959 ;; a label or a line number, as needed.
3960 (when (re-search-backward ref-re nil t)
3961 (cond
3962 ((org-element-property :use-labels el) ref)
3963 ((eq (org-element-property :number-lines el) 'continued)
3964 (+ (org-export-get-loc el info) (line-number-at-pos)))
3965 (t (line-number-at-pos)))))))
3966 info 'first-match))
3968 (defun org-export-resolve-fuzzy-link (link info)
3969 "Return LINK destination.
3971 INFO is a plist holding contextual information.
3973 Return value can be an object, an element, or nil:
3975 - If LINK path matches a target object (i.e. <<path>>) return it.
3977 - If LINK path exactly matches the name affiliated keyword
3978 \(i.e. #+NAME: path) of an element, return that element.
3980 - If LINK path exactly matches any headline name, return that
3981 element. If more than one headline share that name, priority
3982 will be given to the one with the closest common ancestor, if
3983 any, or the first one in the parse tree otherwise.
3985 - Otherwise, return nil.
3987 Assume LINK type is \"fuzzy\". White spaces are not
3988 significant."
3989 (let* ((raw-path (org-element-property :path link))
3990 (match-title-p (eq (aref raw-path 0) ?*))
3991 ;; Split PATH at white spaces so matches are space
3992 ;; insensitive.
3993 (path (org-split-string
3994 (if match-title-p (substring raw-path 1) raw-path)))
3995 ;; Cache for destinations that are not position dependent.
3996 (link-cache
3997 (or (plist-get info :resolve-fuzzy-link-cache)
3998 (plist-get (setq info (plist-put info :resolve-fuzzy-link-cache
3999 (make-hash-table :test 'equal)))
4000 :resolve-fuzzy-link-cache)))
4001 (cached (gethash path link-cache 'not-found)))
4002 (cond
4003 ;; Destination is not position dependent: use cached value.
4004 ((and (not match-title-p) (not (eq cached 'not-found))) cached)
4005 ;; First try to find a matching "<<path>>" unless user specified
4006 ;; he was looking for a headline (path starts with a "*"
4007 ;; character).
4008 ((and (not match-title-p)
4009 (let ((match (org-element-map (plist-get info :parse-tree) 'target
4010 (lambda (blob)
4011 (and (equal (org-split-string
4012 (org-element-property :value blob))
4013 path)
4014 blob))
4015 info 'first-match)))
4016 (and match (puthash path match link-cache)))))
4017 ;; Then try to find an element with a matching "#+NAME: path"
4018 ;; affiliated keyword.
4019 ((and (not match-title-p)
4020 (let ((match (org-element-map (plist-get info :parse-tree)
4021 org-element-all-elements
4022 (lambda (el)
4023 (let ((name (org-element-property :name el)))
4024 (when (and name
4025 (equal (org-split-string name) path))
4026 el)))
4027 info 'first-match)))
4028 (and match (puthash path match link-cache)))))
4029 ;; Last case: link either points to a headline or to nothingness.
4030 ;; Try to find the source, with priority given to headlines with
4031 ;; the closest common ancestor. If such candidate is found,
4032 ;; return it, otherwise return nil.
4034 (let ((find-headline
4035 (function
4036 ;; Return first headline whose `:raw-value' property is
4037 ;; NAME in parse tree DATA, or nil. Statistics cookies
4038 ;; are ignored.
4039 (lambda (name data)
4040 (org-element-map data 'headline
4041 (lambda (headline)
4042 (when (equal (org-split-string
4043 (replace-regexp-in-string
4044 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
4045 (org-element-property :raw-value headline)))
4046 name)
4047 headline))
4048 info 'first-match)))))
4049 ;; Search among headlines sharing an ancestor with link, from
4050 ;; closest to farthest.
4051 (catch 'exit
4052 (mapc
4053 (lambda (parent)
4054 (let ((foundp (funcall find-headline path parent)))
4055 (when foundp (throw 'exit foundp))))
4056 (let ((parent-hl (org-export-get-parent-headline link)))
4057 (if (not parent-hl) (list (plist-get info :parse-tree))
4058 (cons parent-hl (org-export-get-genealogy parent-hl)))))
4059 ;; No destination found: return nil.
4060 (and (not match-title-p) (puthash path nil link-cache))))))))
4062 (defun org-export-resolve-id-link (link info)
4063 "Return headline referenced as LINK destination.
4065 INFO is a plist used as a communication channel.
4067 Return value can be the headline element matched in current parse
4068 tree, a file name or nil. Assume LINK type is either \"id\" or
4069 \"custom-id\"."
4070 (let ((id (org-element-property :path link)))
4071 ;; First check if id is within the current parse tree.
4072 (or (org-element-map (plist-get info :parse-tree) 'headline
4073 (lambda (headline)
4074 (when (or (string= (org-element-property :ID headline) id)
4075 (string= (org-element-property :CUSTOM_ID headline) id))
4076 headline))
4077 info 'first-match)
4078 ;; Otherwise, look for external files.
4079 (cdr (assoc id (plist-get info :id-alist))))))
4081 (defun org-export-resolve-radio-link (link info)
4082 "Return radio-target object referenced as LINK destination.
4084 INFO is a plist used as a communication channel.
4086 Return value can be a radio-target object or nil. Assume LINK
4087 has type \"radio\"."
4088 (let ((path (replace-regexp-in-string
4089 "[ \r\t\n]+" " " (org-element-property :path link))))
4090 (org-element-map (plist-get info :parse-tree) 'radio-target
4091 (lambda (radio)
4092 (and (eq (compare-strings
4093 (replace-regexp-in-string
4094 "[ \r\t\n]+" " " (org-element-property :value radio))
4095 nil nil path nil nil t)
4097 radio))
4098 info 'first-match)))
4101 ;;;; For References
4103 ;; `org-export-get-ordinal' associates a sequence number to any object
4104 ;; or element.
4106 (defun org-export-get-ordinal (element info &optional types predicate)
4107 "Return ordinal number of an element or object.
4109 ELEMENT is the element or object considered. INFO is the plist
4110 used as a communication channel.
4112 Optional argument TYPES, when non-nil, is a list of element or
4113 object types, as symbols, that should also be counted in.
4114 Otherwise, only provided element's type is considered.
4116 Optional argument PREDICATE is a function returning a non-nil
4117 value if the current element or object should be counted in. It
4118 accepts two arguments: the element or object being considered and
4119 the plist used as a communication channel. This allows to count
4120 only a certain type of objects (i.e. inline images).
4122 Return value is a list of numbers if ELEMENT is a headline or an
4123 item. It is nil for keywords. It represents the footnote number
4124 for footnote definitions and footnote references. If ELEMENT is
4125 a target, return the same value as if ELEMENT was the closest
4126 table, item or headline containing the target. In any other
4127 case, return the sequence number of ELEMENT among elements or
4128 objects of the same type."
4129 ;; Ordinal of a target object refer to the ordinal of the closest
4130 ;; table, item, or headline containing the object.
4131 (when (eq (org-element-type element) 'target)
4132 (setq element
4133 (loop for parent in (org-export-get-genealogy element)
4134 when
4135 (memq
4136 (org-element-type parent)
4137 '(footnote-definition footnote-reference headline item
4138 table))
4139 return parent)))
4140 (case (org-element-type element)
4141 ;; Special case 1: A headline returns its number as a list.
4142 (headline (org-export-get-headline-number element info))
4143 ;; Special case 2: An item returns its number as a list.
4144 (item (let ((struct (org-element-property :structure element)))
4145 (org-list-get-item-number
4146 (org-element-property :begin element)
4147 struct
4148 (org-list-prevs-alist struct)
4149 (org-list-parents-alist struct))))
4150 ((footnote-definition footnote-reference)
4151 (org-export-get-footnote-number element info))
4152 (otherwise
4153 (let ((counter 0))
4154 ;; Increment counter until ELEMENT is found again.
4155 (org-element-map (plist-get info :parse-tree)
4156 (or types (org-element-type element))
4157 (lambda (el)
4158 (cond
4159 ((eq element el) (1+ counter))
4160 ((not predicate) (incf counter) nil)
4161 ((funcall predicate el info) (incf counter) nil)))
4162 info 'first-match)))))
4165 ;;;; For Src-Blocks
4167 ;; `org-export-get-loc' counts number of code lines accumulated in
4168 ;; src-block or example-block elements with a "+n" switch until
4169 ;; a given element, excluded. Note: "-n" switches reset that count.
4171 ;; `org-export-unravel-code' extracts source code (along with a code
4172 ;; references alist) from an `element-block' or `src-block' type
4173 ;; element.
4175 ;; `org-export-format-code' applies a formatting function to each line
4176 ;; of code, providing relative line number and code reference when
4177 ;; appropriate. Since it doesn't access the original element from
4178 ;; which the source code is coming, it expects from the code calling
4179 ;; it to know if lines should be numbered and if code references
4180 ;; should appear.
4182 ;; Eventually, `org-export-format-code-default' is a higher-level
4183 ;; function (it makes use of the two previous functions) which handles
4184 ;; line numbering and code references inclusion, and returns source
4185 ;; code in a format suitable for plain text or verbatim output.
4187 (defun org-export-get-loc (element info)
4188 "Return accumulated lines of code up to ELEMENT.
4190 INFO is the plist used as a communication channel.
4192 ELEMENT is excluded from count."
4193 (let ((loc 0))
4194 (org-element-map (plist-get info :parse-tree)
4195 `(src-block example-block ,(org-element-type element))
4196 (lambda (el)
4197 (cond
4198 ;; ELEMENT is reached: Quit the loop.
4199 ((eq el element))
4200 ;; Only count lines from src-block and example-block elements
4201 ;; with a "+n" or "-n" switch. A "-n" switch resets counter.
4202 ((not (memq (org-element-type el) '(src-block example-block))) nil)
4203 ((let ((linums (org-element-property :number-lines el)))
4204 (when linums
4205 ;; Accumulate locs or reset them.
4206 (let ((lines (org-count-lines
4207 (org-trim (org-element-property :value el)))))
4208 (setq loc (if (eq linums 'new) lines (+ loc lines))))))
4209 ;; Return nil to stay in the loop.
4210 nil)))
4211 info 'first-match)
4212 ;; Return value.
4213 loc))
4215 (defun org-export-unravel-code (element)
4216 "Clean source code and extract references out of it.
4218 ELEMENT has either a `src-block' an `example-block' type.
4220 Return a cons cell whose CAR is the source code, cleaned from any
4221 reference and protective comma and CDR is an alist between
4222 relative line number (integer) and name of code reference on that
4223 line (string)."
4224 (let* ((line 0) refs
4225 ;; Get code and clean it. Remove blank lines at its
4226 ;; beginning and end.
4227 (code (replace-regexp-in-string
4228 "\\`\\([ \t]*\n\\)+" ""
4229 (replace-regexp-in-string
4230 "\\([ \t]*\n\\)*[ \t]*\\'" "\n"
4231 (org-element-property :value element))))
4232 ;; Get format used for references.
4233 (label-fmt (regexp-quote
4234 (or (org-element-property :label-fmt element)
4235 org-coderef-label-format)))
4236 ;; Build a regexp matching a loc with a reference.
4237 (with-ref-re
4238 (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)[ \t]*\\)$"
4239 (replace-regexp-in-string
4240 "%s" "\\([-a-zA-Z0-9_ ]+\\)" label-fmt nil t))))
4241 ;; Return value.
4242 (cons
4243 ;; Code with references removed.
4244 (org-element-normalize-string
4245 (mapconcat
4246 (lambda (loc)
4247 (incf line)
4248 (if (not (string-match with-ref-re loc)) loc
4249 ;; Ref line: remove ref, and signal its position in REFS.
4250 (push (cons line (match-string 3 loc)) refs)
4251 (replace-match "" nil nil loc 1)))
4252 (org-split-string code "\n") "\n"))
4253 ;; Reference alist.
4254 refs)))
4256 (defun org-export-format-code (code fun &optional num-lines ref-alist)
4257 "Format CODE by applying FUN line-wise and return it.
4259 CODE is a string representing the code to format. FUN is
4260 a function. It must accept three arguments: a line of
4261 code (string), the current line number (integer) or nil and the
4262 reference associated to the current line (string) or nil.
4264 Optional argument NUM-LINES can be an integer representing the
4265 number of code lines accumulated until the current code. Line
4266 numbers passed to FUN will take it into account. If it is nil,
4267 FUN's second argument will always be nil. This number can be
4268 obtained with `org-export-get-loc' function.
4270 Optional argument REF-ALIST can be an alist between relative line
4271 number (i.e. ignoring NUM-LINES) and the name of the code
4272 reference on it. If it is nil, FUN's third argument will always
4273 be nil. It can be obtained through the use of
4274 `org-export-unravel-code' function."
4275 (let ((--locs (org-split-string code "\n"))
4276 (--line 0))
4277 (org-element-normalize-string
4278 (mapconcat
4279 (lambda (--loc)
4280 (incf --line)
4281 (let ((--ref (cdr (assq --line ref-alist))))
4282 (funcall fun --loc (and num-lines (+ num-lines --line)) --ref)))
4283 --locs "\n"))))
4285 (defun org-export-format-code-default (element info)
4286 "Return source code from ELEMENT, formatted in a standard way.
4288 ELEMENT is either a `src-block' or `example-block' element. INFO
4289 is a plist used as a communication channel.
4291 This function takes care of line numbering and code references
4292 inclusion. Line numbers, when applicable, appear at the
4293 beginning of the line, separated from the code by two white
4294 spaces. Code references, on the other hand, appear flushed to
4295 the right, separated by six white spaces from the widest line of
4296 code."
4297 ;; Extract code and references.
4298 (let* ((code-info (org-export-unravel-code element))
4299 (code (car code-info))
4300 (code-lines (org-split-string code "\n")))
4301 (if (null code-lines) ""
4302 (let* ((refs (and (org-element-property :retain-labels element)
4303 (cdr code-info)))
4304 ;; Handle line numbering.
4305 (num-start (case (org-element-property :number-lines element)
4306 (continued (org-export-get-loc element info))
4307 (new 0)))
4308 (num-fmt
4309 (and num-start
4310 (format "%%%ds "
4311 (length (number-to-string
4312 (+ (length code-lines) num-start))))))
4313 ;; Prepare references display, if required. Any reference
4314 ;; should start six columns after the widest line of code,
4315 ;; wrapped with parenthesis.
4316 (max-width
4317 (+ (apply 'max (mapcar 'length code-lines))
4318 (if (not num-start) 0 (length (format num-fmt num-start))))))
4319 (org-export-format-code
4320 code
4321 (lambda (loc line-num ref)
4322 (let ((number-str (and num-fmt (format num-fmt line-num))))
4323 (concat
4324 number-str
4326 (and ref
4327 (concat (make-string
4328 (- (+ 6 max-width)
4329 (+ (length loc) (length number-str))) ? )
4330 (format "(%s)" ref))))))
4331 num-start refs)))))
4334 ;;;; For Tables
4336 ;; `org-export-table-has-special-column-p' and and
4337 ;; `org-export-table-row-is-special-p' are predicates used to look for
4338 ;; meta-information about the table structure.
4340 ;; `org-table-has-header-p' tells when the rows before the first rule
4341 ;; should be considered as table's header.
4343 ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
4344 ;; and `org-export-table-cell-borders' extract information from
4345 ;; a table-cell element.
4347 ;; `org-export-table-dimensions' gives the number on rows and columns
4348 ;; in the table, ignoring horizontal rules and special columns.
4349 ;; `org-export-table-cell-address', given a table-cell object, returns
4350 ;; the absolute address of a cell. On the other hand,
4351 ;; `org-export-get-table-cell-at' does the contrary.
4353 ;; `org-export-table-cell-starts-colgroup-p',
4354 ;; `org-export-table-cell-ends-colgroup-p',
4355 ;; `org-export-table-row-starts-rowgroup-p',
4356 ;; `org-export-table-row-ends-rowgroup-p',
4357 ;; `org-export-table-row-starts-header-p' and
4358 ;; `org-export-table-row-ends-header-p' indicate position of current
4359 ;; row or cell within the table.
4361 (defun org-export-table-has-special-column-p (table)
4362 "Non-nil when TABLE has a special column.
4363 All special columns will be ignored during export."
4364 ;; The table has a special column when every first cell of every row
4365 ;; has an empty value or contains a symbol among "/", "#", "!", "$",
4366 ;; "*" "_" and "^". Though, do not consider a first row containing
4367 ;; only empty cells as special.
4368 (let ((special-column-p 'empty))
4369 (catch 'exit
4370 (mapc
4371 (lambda (row)
4372 (when (eq (org-element-property :type row) 'standard)
4373 (let ((value (org-element-contents
4374 (car (org-element-contents row)))))
4375 (cond ((member value '(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
4376 (setq special-column-p 'special))
4377 ((not value))
4378 (t (throw 'exit nil))))))
4379 (org-element-contents table))
4380 (eq special-column-p 'special))))
4382 (defun org-export-table-has-header-p (table info)
4383 "Non-nil when TABLE has a header.
4385 INFO is a plist used as a communication channel.
4387 A table has a header when it contains at least two row groups."
4388 (let ((cache (or (plist-get info :table-header-cache)
4389 (plist-get (setq info
4390 (plist-put info :table-header-cache
4391 (make-hash-table :test 'eq)))
4392 :table-header-cache))))
4393 (or (gethash table cache)
4394 (let ((rowgroup 1) row-flag)
4395 (puthash
4396 table
4397 (org-element-map table 'table-row
4398 (lambda (row)
4399 (cond
4400 ((> rowgroup 1) t)
4401 ((and row-flag (eq (org-element-property :type row) 'rule))
4402 (incf rowgroup) (setq row-flag nil))
4403 ((and (not row-flag) (eq (org-element-property :type row)
4404 'standard))
4405 (setq row-flag t) nil)))
4406 info 'first-match)
4407 cache)))))
4409 (defun org-export-table-row-is-special-p (table-row info)
4410 "Non-nil if TABLE-ROW is considered special.
4412 INFO is a plist used as the communication channel.
4414 All special rows will be ignored during export."
4415 (when (eq (org-element-property :type table-row) 'standard)
4416 (let ((first-cell (org-element-contents
4417 (car (org-element-contents table-row)))))
4418 ;; A row is special either when...
4420 ;; ... it starts with a field only containing "/",
4421 (equal first-cell '("/"))
4422 ;; ... the table contains a special column and the row start
4423 ;; with a marking character among, "^", "_", "$" or "!",
4424 (and (org-export-table-has-special-column-p
4425 (org-export-get-parent table-row))
4426 (member first-cell '(("^") ("_") ("$") ("!"))))
4427 ;; ... it contains only alignment cookies and empty cells.
4428 (let ((special-row-p 'empty))
4429 (catch 'exit
4430 (mapc
4431 (lambda (cell)
4432 (let ((value (org-element-contents cell)))
4433 ;; Since VALUE is a secondary string, the following
4434 ;; checks avoid expanding it with `org-export-data'.
4435 (cond ((not value))
4436 ((and (not (cdr value))
4437 (stringp (car value))
4438 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
4439 (car value)))
4440 (setq special-row-p 'cookie))
4441 (t (throw 'exit nil)))))
4442 (org-element-contents table-row))
4443 (eq special-row-p 'cookie)))))))
4445 (defun org-export-table-row-group (table-row info)
4446 "Return TABLE-ROW's group number, as an integer.
4448 INFO is a plist used as the communication channel.
4450 Return value is the group number, as an integer, or nil for
4451 special rows and rows separators. First group is also table's
4452 header."
4453 (let ((cache (or (plist-get info :table-row-group-cache)
4454 (plist-get (setq info
4455 (plist-put info :table-row-group-cache
4456 (make-hash-table :test 'eq)))
4457 :table-row-group-cache))))
4458 (cond ((gethash table-row cache))
4459 ((eq (org-element-property :type table-row) 'rule) nil)
4460 (t (let ((group 0) row-flag)
4461 (org-element-map (org-export-get-parent table-row) 'table-row
4462 (lambda (row)
4463 (if (eq (org-element-property :type row) 'rule)
4464 (setq row-flag nil)
4465 (unless row-flag (incf group) (setq row-flag t)))
4466 (when (eq table-row row) (puthash table-row group cache)))
4467 info 'first-match))))))
4469 (defun org-export-table-cell-width (table-cell info)
4470 "Return TABLE-CELL contents width.
4472 INFO is a plist used as the communication channel.
4474 Return value is the width given by the last width cookie in the
4475 same column as TABLE-CELL, or nil."
4476 (let* ((row (org-export-get-parent table-cell))
4477 (table (org-export-get-parent row))
4478 (cells (org-element-contents row))
4479 (columns (length cells))
4480 (column (- columns (length (memq table-cell cells))))
4481 (cache (or (plist-get info :table-cell-width-cache)
4482 (plist-get (setq info
4483 (plist-put info :table-cell-width-cache
4484 (make-hash-table :test 'eq)))
4485 :table-cell-width-cache)))
4486 (width-vector (or (gethash table cache)
4487 (puthash table (make-vector columns 'empty) cache)))
4488 (value (aref width-vector column)))
4489 (if (not (eq value 'empty)) value
4490 (let (cookie-width)
4491 (dolist (row (org-element-contents table)
4492 (aset width-vector column cookie-width))
4493 (when (org-export-table-row-is-special-p row info)
4494 ;; In a special row, try to find a width cookie at COLUMN.
4495 (let* ((value (org-element-contents
4496 (elt (org-element-contents row) column)))
4497 (cookie (car value)))
4498 ;; The following checks avoid expanding unnecessarily
4499 ;; the cell with `org-export-data'.
4500 (when (and value
4501 (not (cdr value))
4502 (stringp cookie)
4503 (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" cookie)
4504 (match-string 1 cookie))
4505 (setq cookie-width
4506 (string-to-number (match-string 1 cookie)))))))))))
4508 (defun org-export-table-cell-alignment (table-cell info)
4509 "Return TABLE-CELL contents alignment.
4511 INFO is a plist used as the communication channel.
4513 Return alignment as specified by the last alignment cookie in the
4514 same column as TABLE-CELL. If no such cookie is found, a default
4515 alignment value will be deduced from fraction of numbers in the
4516 column (see `org-table-number-fraction' for more information).
4517 Possible values are `left', `right' and `center'."
4518 (let* ((row (org-export-get-parent table-cell))
4519 (table (org-export-get-parent row))
4520 (cells (org-element-contents row))
4521 (columns (length cells))
4522 (column (- columns (length (memq table-cell cells))))
4523 (cache (or (plist-get info :table-cell-alignment-cache)
4524 (plist-get (setq info
4525 (plist-put info :table-cell-alignment-cache
4526 (make-hash-table :test 'eq)))
4527 :table-cell-alignment-cache)))
4528 (align-vector (or (gethash table cache)
4529 (puthash table (make-vector columns nil) cache))))
4530 (or (aref align-vector column)
4531 (let ((number-cells 0)
4532 (total-cells 0)
4533 cookie-align
4534 previous-cell-number-p)
4535 (dolist (row (org-element-contents (org-export-get-parent row)))
4536 (cond
4537 ;; In a special row, try to find an alignment cookie at
4538 ;; COLUMN.
4539 ((org-export-table-row-is-special-p row info)
4540 (let ((value (org-element-contents
4541 (elt (org-element-contents row) column))))
4542 ;; Since VALUE is a secondary string, the following
4543 ;; checks avoid useless expansion through
4544 ;; `org-export-data'.
4545 (when (and value
4546 (not (cdr value))
4547 (stringp (car value))
4548 (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
4549 (car value))
4550 (match-string 1 (car value)))
4551 (setq cookie-align (match-string 1 (car value))))))
4552 ;; Ignore table rules.
4553 ((eq (org-element-property :type row) 'rule))
4554 ;; In a standard row, check if cell's contents are
4555 ;; expressing some kind of number. Increase NUMBER-CELLS
4556 ;; accordingly. Though, don't bother if an alignment
4557 ;; cookie has already defined cell's alignment.
4558 ((not cookie-align)
4559 (let ((value (org-export-data
4560 (org-element-contents
4561 (elt (org-element-contents row) column))
4562 info)))
4563 (incf total-cells)
4564 ;; Treat an empty cell as a number if it follows
4565 ;; a number.
4566 (if (not (or (string-match org-table-number-regexp value)
4567 (and (string= value "") previous-cell-number-p)))
4568 (setq previous-cell-number-p nil)
4569 (setq previous-cell-number-p t)
4570 (incf number-cells))))))
4571 ;; Return value. Alignment specified by cookies has
4572 ;; precedence over alignment deduced from cell's contents.
4573 (aset align-vector
4574 column
4575 (cond ((equal cookie-align "l") 'left)
4576 ((equal cookie-align "r") 'right)
4577 ((equal cookie-align "c") 'center)
4578 ((>= (/ (float number-cells) total-cells)
4579 org-table-number-fraction)
4580 'right)
4581 (t 'left)))))))
4583 (defun org-export-table-cell-borders (table-cell info)
4584 "Return TABLE-CELL borders.
4586 INFO is a plist used as a communication channel.
4588 Return value is a list of symbols, or nil. Possible values are:
4589 `top', `bottom', `above', `below', `left' and `right'. Note:
4590 `top' (resp. `bottom') only happen for a cell in the first
4591 row (resp. last row) of the table, ignoring table rules, if any.
4593 Returned borders ignore special rows."
4594 (let* ((row (org-export-get-parent table-cell))
4595 (table (org-export-get-parent-table table-cell))
4596 borders)
4597 ;; Top/above border? TABLE-CELL has a border above when a rule
4598 ;; used to demarcate row groups can be found above. Hence,
4599 ;; finding a rule isn't sufficient to push `above' in BORDERS:
4600 ;; another regular row has to be found above that rule.
4601 (let (rule-flag)
4602 (catch 'exit
4603 (mapc (lambda (row)
4604 (cond ((eq (org-element-property :type row) 'rule)
4605 (setq rule-flag t))
4606 ((not (org-export-table-row-is-special-p row info))
4607 (if rule-flag (throw 'exit (push 'above borders))
4608 (throw 'exit nil)))))
4609 ;; Look at every row before the current one.
4610 (cdr (memq row (reverse (org-element-contents table)))))
4611 ;; No rule above, or rule found starts the table (ignoring any
4612 ;; special row): TABLE-CELL is at the top of the table.
4613 (when rule-flag (push 'above borders))
4614 (push 'top borders)))
4615 ;; Bottom/below border? TABLE-CELL has a border below when next
4616 ;; non-regular row below is a rule.
4617 (let (rule-flag)
4618 (catch 'exit
4619 (mapc (lambda (row)
4620 (cond ((eq (org-element-property :type row) 'rule)
4621 (setq rule-flag t))
4622 ((not (org-export-table-row-is-special-p row info))
4623 (if rule-flag (throw 'exit (push 'below borders))
4624 (throw 'exit nil)))))
4625 ;; Look at every row after the current one.
4626 (cdr (memq row (org-element-contents table))))
4627 ;; No rule below, or rule found ends the table (modulo some
4628 ;; special row): TABLE-CELL is at the bottom of the table.
4629 (when rule-flag (push 'below borders))
4630 (push 'bottom borders)))
4631 ;; Right/left borders? They can only be specified by column
4632 ;; groups. Column groups are defined in a row starting with "/".
4633 ;; Also a column groups row only contains "<", "<>", ">" or blank
4634 ;; cells.
4635 (catch 'exit
4636 (let ((column (let ((cells (org-element-contents row)))
4637 (- (length cells) (length (memq table-cell cells))))))
4638 (mapc
4639 (lambda (row)
4640 (unless (eq (org-element-property :type row) 'rule)
4641 (when (equal (org-element-contents
4642 (car (org-element-contents row)))
4643 '("/"))
4644 (let ((column-groups
4645 (mapcar
4646 (lambda (cell)
4647 (let ((value (org-element-contents cell)))
4648 (when (member value '(("<") ("<>") (">") nil))
4649 (car value))))
4650 (org-element-contents row))))
4651 ;; There's a left border when previous cell, if
4652 ;; any, ends a group, or current one starts one.
4653 (when (or (and (not (zerop column))
4654 (member (elt column-groups (1- column))
4655 '(">" "<>")))
4656 (member (elt column-groups column) '("<" "<>")))
4657 (push 'left borders))
4658 ;; There's a right border when next cell, if any,
4659 ;; starts a group, or current one ends one.
4660 (when (or (and (/= (1+ column) (length column-groups))
4661 (member (elt column-groups (1+ column))
4662 '("<" "<>")))
4663 (member (elt column-groups column) '(">" "<>")))
4664 (push 'right borders))
4665 (throw 'exit nil)))))
4666 ;; Table rows are read in reverse order so last column groups
4667 ;; row has precedence over any previous one.
4668 (reverse (org-element-contents table)))))
4669 ;; Return value.
4670 borders))
4672 (defun org-export-table-cell-starts-colgroup-p (table-cell info)
4673 "Non-nil when TABLE-CELL is at the beginning of a row group.
4674 INFO is a plist used as a communication channel."
4675 ;; A cell starts a column group either when it is at the beginning
4676 ;; of a row (or after the special column, if any) or when it has
4677 ;; a left border.
4678 (or (eq (org-element-map (org-export-get-parent table-cell) 'table-cell
4679 'identity info 'first-match)
4680 table-cell)
4681 (memq 'left (org-export-table-cell-borders table-cell info))))
4683 (defun org-export-table-cell-ends-colgroup-p (table-cell info)
4684 "Non-nil when TABLE-CELL is at the end of a row group.
4685 INFO is a plist used as a communication channel."
4686 ;; A cell ends a column group either when it is at the end of a row
4687 ;; or when it has a right border.
4688 (or (eq (car (last (org-element-contents
4689 (org-export-get-parent table-cell))))
4690 table-cell)
4691 (memq 'right (org-export-table-cell-borders table-cell info))))
4693 (defun org-export-table-row-starts-rowgroup-p (table-row info)
4694 "Non-nil when TABLE-ROW is at the beginning of a column group.
4695 INFO is a plist used as a communication channel."
4696 (unless (or (eq (org-element-property :type table-row) 'rule)
4697 (org-export-table-row-is-special-p table-row info))
4698 (let ((borders (org-export-table-cell-borders
4699 (car (org-element-contents table-row)) info)))
4700 (or (memq 'top borders) (memq 'above borders)))))
4702 (defun org-export-table-row-ends-rowgroup-p (table-row info)
4703 "Non-nil when TABLE-ROW is at the end of a column group.
4704 INFO is a plist used as a communication channel."
4705 (unless (or (eq (org-element-property :type table-row) 'rule)
4706 (org-export-table-row-is-special-p table-row info))
4707 (let ((borders (org-export-table-cell-borders
4708 (car (org-element-contents table-row)) info)))
4709 (or (memq 'bottom borders) (memq 'below borders)))))
4711 (defun org-export-table-row-starts-header-p (table-row info)
4712 "Non-nil when TABLE-ROW is the first table header's row.
4713 INFO is a plist used as a communication channel."
4714 (and (org-export-table-has-header-p
4715 (org-export-get-parent-table table-row) info)
4716 (org-export-table-row-starts-rowgroup-p table-row info)
4717 (= (org-export-table-row-group table-row info) 1)))
4719 (defun org-export-table-row-ends-header-p (table-row info)
4720 "Non-nil when TABLE-ROW is the last table header's row.
4721 INFO is a plist used as a communication channel."
4722 (and (org-export-table-has-header-p
4723 (org-export-get-parent-table table-row) info)
4724 (org-export-table-row-ends-rowgroup-p table-row info)
4725 (= (org-export-table-row-group table-row info) 1)))
4727 (defun org-export-table-row-number (table-row info)
4728 "Return TABLE-ROW number.
4729 INFO is a plist used as a communication channel. Return value is
4730 zero-based and ignores separators. The function returns nil for
4731 special colums and separators."
4732 (when (and (eq (org-element-property :type table-row) 'standard)
4733 (not (org-export-table-row-is-special-p table-row info)))
4734 (let ((number 0))
4735 (org-element-map (org-export-get-parent-table table-row) 'table-row
4736 (lambda (row)
4737 (cond ((eq row table-row) number)
4738 ((eq (org-element-property :type row) 'standard)
4739 (incf number) nil)))
4740 info 'first-match))))
4742 (defun org-export-table-dimensions (table info)
4743 "Return TABLE dimensions.
4745 INFO is a plist used as a communication channel.
4747 Return value is a CONS like (ROWS . COLUMNS) where
4748 ROWS (resp. COLUMNS) is the number of exportable
4749 rows (resp. columns)."
4750 (let (first-row (columns 0) (rows 0))
4751 ;; Set number of rows, and extract first one.
4752 (org-element-map table 'table-row
4753 (lambda (row)
4754 (when (eq (org-element-property :type row) 'standard)
4755 (incf rows)
4756 (unless first-row (setq first-row row)))) info)
4757 ;; Set number of columns.
4758 (org-element-map first-row 'table-cell (lambda (cell) (incf columns)) info)
4759 ;; Return value.
4760 (cons rows columns)))
4762 (defun org-export-table-cell-address (table-cell info)
4763 "Return address of a regular TABLE-CELL object.
4765 TABLE-CELL is the cell considered. INFO is a plist used as
4766 a communication channel.
4768 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4769 zero-based index. Only exportable cells are considered. The
4770 function returns nil for other cells."
4771 (let* ((table-row (org-export-get-parent table-cell))
4772 (row-number (org-export-table-row-number table-row info)))
4773 (when row-number
4774 (cons row-number
4775 (let ((col-count 0))
4776 (org-element-map table-row 'table-cell
4777 (lambda (cell)
4778 (if (eq cell table-cell) col-count (incf col-count) nil))
4779 info 'first-match))))))
4781 (defun org-export-get-table-cell-at (address table info)
4782 "Return regular table-cell object at ADDRESS in TABLE.
4784 Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
4785 zero-based index. TABLE is a table type element. INFO is
4786 a plist used as a communication channel.
4788 If no table-cell, among exportable cells, is found at ADDRESS,
4789 return nil."
4790 (let ((column-pos (cdr address)) (column-count 0))
4791 (org-element-map
4792 ;; Row at (car address) or nil.
4793 (let ((row-pos (car address)) (row-count 0))
4794 (org-element-map table 'table-row
4795 (lambda (row)
4796 (cond ((eq (org-element-property :type row) 'rule) nil)
4797 ((= row-count row-pos) row)
4798 (t (incf row-count) nil)))
4799 info 'first-match))
4800 'table-cell
4801 (lambda (cell)
4802 (if (= column-count column-pos) cell
4803 (incf column-count) nil))
4804 info 'first-match)))
4807 ;;;; For Tables Of Contents
4809 ;; `org-export-collect-headlines' builds a list of all exportable
4810 ;; headline elements, maybe limited to a certain depth. One can then
4811 ;; easily parse it and transcode it.
4813 ;; Building lists of tables, figures or listings is quite similar.
4814 ;; Once the generic function `org-export-collect-elements' is defined,
4815 ;; `org-export-collect-tables', `org-export-collect-figures' and
4816 ;; `org-export-collect-listings' can be derived from it.
4818 (defun org-export-collect-headlines (info &optional n)
4819 "Collect headlines in order to build a table of contents.
4821 INFO is a plist used as a communication channel.
4823 When optional argument N is an integer, it specifies the depth of
4824 the table of contents. Otherwise, it is set to the value of the
4825 last headline level. See `org-export-headline-levels' for more
4826 information.
4828 Return a list of all exportable headlines as parsed elements.
4829 Footnote sections, if any, will be ignored."
4830 (unless (wholenump n) (setq n (plist-get info :headline-levels)))
4831 (org-element-map (plist-get info :parse-tree) 'headline
4832 (lambda (headline)
4833 (unless (org-element-property :footnote-section-p headline)
4834 ;; Strip contents from HEADLINE.
4835 (let ((relative-level (org-export-get-relative-level headline info)))
4836 (unless (> relative-level n) headline))))
4837 info))
4839 (defun org-export-collect-elements (type info &optional predicate)
4840 "Collect referenceable elements of a determined type.
4842 TYPE can be a symbol or a list of symbols specifying element
4843 types to search. Only elements with a caption are collected.
4845 INFO is a plist used as a communication channel.
4847 When non-nil, optional argument PREDICATE is a function accepting
4848 one argument, an element of type TYPE. It returns a non-nil
4849 value when that element should be collected.
4851 Return a list of all elements found, in order of appearance."
4852 (org-element-map (plist-get info :parse-tree) type
4853 (lambda (element)
4854 (and (org-element-property :caption element)
4855 (or (not predicate) (funcall predicate element))
4856 element))
4857 info))
4859 (defun org-export-collect-tables (info)
4860 "Build a list of tables.
4861 INFO is a plist used as a communication channel.
4863 Return a list of table elements with a caption."
4864 (org-export-collect-elements 'table info))
4866 (defun org-export-collect-figures (info predicate)
4867 "Build a list of figures.
4869 INFO is a plist used as a communication channel. PREDICATE is
4870 a function which accepts one argument: a paragraph element and
4871 whose return value is non-nil when that element should be
4872 collected.
4874 A figure is a paragraph type element, with a caption, verifying
4875 PREDICATE. The latter has to be provided since a \"figure\" is
4876 a vague concept that may depend on back-end.
4878 Return a list of elements recognized as figures."
4879 (org-export-collect-elements 'paragraph info predicate))
4881 (defun org-export-collect-listings (info)
4882 "Build a list of src blocks.
4884 INFO is a plist used as a communication channel.
4886 Return a list of src-block elements with a caption."
4887 (org-export-collect-elements 'src-block info))
4890 ;;;; Smart Quotes
4892 ;; The main function for the smart quotes sub-system is
4893 ;; `org-export-activate-smart-quotes', which replaces every quote in
4894 ;; a given string from the parse tree with its "smart" counterpart.
4896 ;; Dictionary for smart quotes is stored in
4897 ;; `org-export-smart-quotes-alist'.
4899 ;; Internally, regexps matching potential smart quotes (checks at
4900 ;; string boundaries are also necessary) are defined in
4901 ;; `org-export-smart-quotes-regexps'.
4903 (defconst org-export-smart-quotes-alist
4904 '(("de"
4905 (opening-double-quote :utf-8 "„" :html "&bdquo;" :latex "\"`"
4906 :texinfo "@quotedblbase{}")
4907 (closing-double-quote :utf-8 "“" :html "&ldquo;" :latex "\"'"
4908 :texinfo "@quotedblleft{}")
4909 (opening-single-quote :utf-8 "‚" :html "&sbquo;" :latex "\\glq{}"
4910 :texinfo "@quotesinglbase{}")
4911 (closing-single-quote :utf-8 "‘" :html "&lsquo;" :latex "\\grq{}"
4912 :texinfo "@quoteleft{}")
4913 (apostrophe :utf-8 "’" :html "&rsquo;"))
4914 ("en"
4915 (opening-double-quote :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
4916 (closing-double-quote :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
4917 (opening-single-quote :utf-8 "‘" :html "&lsquo;" :latex "`" :texinfo "`")
4918 (closing-single-quote :utf-8 "’" :html "&rsquo;" :latex "'" :texinfo "'")
4919 (apostrophe :utf-8 "’" :html "&rsquo;"))
4920 ("es"
4921 (opening-double-quote :utf-8 "«" :html "&laquo;" :latex "\\guillemotleft{}"
4922 :texinfo "@guillemetleft{}")
4923 (closing-double-quote :utf-8 "»" :html "&raquo;" :latex "\\guillemotright{}"
4924 :texinfo "@guillemetright{}")
4925 (opening-single-quote :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
4926 (closing-single-quote :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
4927 (apostrophe :utf-8 "’" :html "&rsquo;"))
4928 ("fr"
4929 (opening-double-quote :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
4930 :texinfo "@guillemetleft{}@tie{}")
4931 (closing-double-quote :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
4932 :texinfo "@tie{}@guillemetright{}")
4933 (opening-single-quote :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
4934 :texinfo "@guillemetleft{}@tie{}")
4935 (closing-single-quote :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
4936 :texinfo "@tie{}@guillemetright{}")
4937 (apostrophe :utf-8 "’" :html "&rsquo;")))
4938 "Smart quotes translations.
4940 Alist whose CAR is a language string and CDR is an alist with
4941 quote type as key and a plist associating various encodings to
4942 their translation as value.
4944 A quote type can be any symbol among `opening-double-quote',
4945 `closing-double-quote', `opening-single-quote',
4946 `closing-single-quote' and `apostrophe'.
4948 Valid encodings include `:utf-8', `:html', `:latex' and
4949 `:texinfo'.
4951 If no translation is found, the quote character is left as-is.")
4953 (defconst org-export-smart-quotes-regexps
4954 (list
4955 ;; Possible opening quote at beginning of string.
4956 "\\`\\([\"']\\)\\(\\w\\|\\s.\\|\\s_\\)"
4957 ;; Possible closing quote at beginning of string.
4958 "\\`\\([\"']\\)\\(\\s-\\|\\s)\\|\\s.\\)"
4959 ;; Possible apostrophe at beginning of string.
4960 "\\`\\('\\)\\S-"
4961 ;; Opening single and double quotes.
4962 "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\(?:\\w\\|\\s.\\|\\s_\\)"
4963 ;; Closing single and double quotes.
4964 "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\(?:\\s-\\|\\s)\\|\\s.\\)"
4965 ;; Apostrophe.
4966 "\\S-\\('\\)\\S-"
4967 ;; Possible opening quote at end of string.
4968 "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\'"
4969 ;; Possible closing quote at end of string.
4970 "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\'"
4971 ;; Possible apostrophe at end of string.
4972 "\\S-\\('\\)\\'")
4973 "List of regexps matching a quote or an apostrophe.
4974 In every regexp, quote or apostrophe matched is put in group 1.")
4976 (defun org-export-activate-smart-quotes (s encoding info &optional original)
4977 "Replace regular quotes with \"smart\" quotes in string S.
4979 ENCODING is a symbol among `:html', `:latex', `:texinfo' and
4980 `:utf-8'. INFO is a plist used as a communication channel.
4982 The function has to retrieve information about string
4983 surroundings in parse tree. It can only happen with an
4984 unmodified string. Thus, if S has already been through another
4985 process, a non-nil ORIGINAL optional argument will provide that
4986 original string.
4988 Return the new string."
4989 (if (equal s "") ""
4990 (let* ((prev (org-export-get-previous-element (or original s) info))
4991 ;; Try to be flexible when computing number of blanks
4992 ;; before object. The previous object may be a string
4993 ;; introduced by the back-end and not completely parsed.
4994 (pre-blank (and prev
4995 (or (org-element-property :post-blank prev)
4996 ;; A string with missing `:post-blank'
4997 ;; property.
4998 (and (stringp prev)
4999 (string-match " *\\'" prev)
5000 (length (match-string 0 prev)))
5001 ;; Fallback value.
5002 0)))
5003 (next (org-export-get-next-element (or original s) info))
5004 (get-smart-quote
5005 (lambda (q type)
5006 ;; Return smart quote associated to a give quote Q, as
5007 ;; a string. TYPE is a symbol among `open', `close' and
5008 ;; `apostrophe'.
5009 (let ((key (case type
5010 (apostrophe 'apostrophe)
5011 (open (if (equal "'" q) 'opening-single-quote
5012 'opening-double-quote))
5013 (otherwise (if (equal "'" q) 'closing-single-quote
5014 'closing-double-quote)))))
5015 (or (plist-get
5016 (cdr (assq key
5017 (cdr (assoc (plist-get info :language)
5018 org-export-smart-quotes-alist))))
5019 encoding)
5020 q)))))
5021 (if (or (equal "\"" s) (equal "'" s))
5022 ;; Only a quote: no regexp can match. We have to check both
5023 ;; sides and decide what to do.
5024 (cond ((and (not prev) (not next)) s)
5025 ((not prev) (funcall get-smart-quote s 'open))
5026 ((and (not next) (zerop pre-blank))
5027 (funcall get-smart-quote s 'close))
5028 ((not next) s)
5029 ((zerop pre-blank) (funcall get-smart-quote s 'apostrophe))
5030 (t (funcall get-smart-quote 'open)))
5031 ;; 1. Replace quote character at the beginning of S.
5032 (cond
5033 ;; Apostrophe?
5034 ((and prev (zerop pre-blank)
5035 (string-match (nth 2 org-export-smart-quotes-regexps) s))
5036 (setq s (replace-match
5037 (funcall get-smart-quote (match-string 1 s) 'apostrophe)
5038 nil t s 1)))
5039 ;; Closing quote?
5040 ((and prev (zerop pre-blank)
5041 (string-match (nth 1 org-export-smart-quotes-regexps) s))
5042 (setq s (replace-match
5043 (funcall get-smart-quote (match-string 1 s) 'close)
5044 nil t s 1)))
5045 ;; Opening quote?
5046 ((and (or (not prev) (> pre-blank 0))
5047 (string-match (nth 0 org-export-smart-quotes-regexps) s))
5048 (setq s (replace-match
5049 (funcall get-smart-quote (match-string 1 s) 'open)
5050 nil t s 1))))
5051 ;; 2. Replace quotes in the middle of the string.
5052 (setq s (replace-regexp-in-string
5053 ;; Opening quotes.
5054 (nth 3 org-export-smart-quotes-regexps)
5055 (lambda (text)
5056 (funcall get-smart-quote (match-string 1 text) 'open))
5057 s nil t 1))
5058 (setq s (replace-regexp-in-string
5059 ;; Closing quotes.
5060 (nth 4 org-export-smart-quotes-regexps)
5061 (lambda (text)
5062 (funcall get-smart-quote (match-string 1 text) 'close))
5063 s nil t 1))
5064 (setq s (replace-regexp-in-string
5065 ;; Apostrophes.
5066 (nth 5 org-export-smart-quotes-regexps)
5067 (lambda (text)
5068 (funcall get-smart-quote (match-string 1 text) 'apostrophe))
5069 s nil t 1))
5070 ;; 3. Replace quote character at the end of S.
5071 (cond
5072 ;; Apostrophe?
5073 ((and next (string-match (nth 8 org-export-smart-quotes-regexps) s))
5074 (setq s (replace-match
5075 (funcall get-smart-quote (match-string 1 s) 'apostrophe)
5076 nil t s 1)))
5077 ;; Closing quote?
5078 ((and (not next)
5079 (string-match (nth 7 org-export-smart-quotes-regexps) s))
5080 (setq s (replace-match
5081 (funcall get-smart-quote (match-string 1 s) 'close)
5082 nil t s 1)))
5083 ;; Opening quote?
5084 ((and next (string-match (nth 6 org-export-smart-quotes-regexps) s))
5085 (setq s (replace-match
5086 (funcall get-smart-quote (match-string 1 s) 'open)
5087 nil t s 1))))
5088 ;; Return string with smart quotes.
5089 s))))
5091 ;;;; Topology
5093 ;; Here are various functions to retrieve information about the
5094 ;; neighbourhood of a given element or object. Neighbours of interest
5095 ;; are direct parent (`org-export-get-parent'), parent headline
5096 ;; (`org-export-get-parent-headline'), first element containing an
5097 ;; object, (`org-export-get-parent-element'), parent table
5098 ;; (`org-export-get-parent-table'), previous element or object
5099 ;; (`org-export-get-previous-element') and next element or object
5100 ;; (`org-export-get-next-element').
5102 ;; `org-export-get-genealogy' returns the full genealogy of a given
5103 ;; element or object, from closest parent to full parse tree.
5105 (defsubst org-export-get-parent (blob)
5106 "Return BLOB parent or nil.
5107 BLOB is the element or object considered."
5108 (org-element-property :parent blob))
5110 (defun org-export-get-genealogy (blob)
5111 "Return full genealogy relative to a given element or object.
5113 BLOB is the element or object being considered.
5115 Ancestors are returned from closest to farthest, the last one
5116 being the full parse tree."
5117 (let (genealogy (parent blob))
5118 (while (setq parent (org-element-property :parent parent))
5119 (push parent genealogy))
5120 (nreverse genealogy)))
5122 (defun org-export-get-parent-headline (blob)
5123 "Return BLOB parent headline or nil.
5124 BLOB is the element or object being considered."
5125 (let ((parent blob))
5126 (while (and (setq parent (org-element-property :parent parent))
5127 (not (eq (org-element-type parent) 'headline))))
5128 parent))
5130 (defun org-export-get-parent-element (object)
5131 "Return first element containing OBJECT or nil.
5132 OBJECT is the object to consider."
5133 (let ((parent object))
5134 (while (and (setq parent (org-element-property :parent parent))
5135 (memq (org-element-type parent) org-element-all-objects)))
5136 parent))
5138 (defun org-export-get-parent-table (object)
5139 "Return OBJECT parent table or nil.
5140 OBJECT is either a `table-cell' or `table-element' type object."
5141 (let ((parent object))
5142 (while (and (setq parent (org-element-property :parent parent))
5143 (not (eq (org-element-type parent) 'table))))
5144 parent))
5146 (defun org-export-get-previous-element (blob info &optional n)
5147 "Return previous element or object.
5149 BLOB is an element or object. INFO is a plist used as
5150 a communication channel. Return previous exportable element or
5151 object, a string, or nil.
5153 When optional argument N is a positive integer, return a list
5154 containing up to N siblings before BLOB, from farthest to
5155 closest. With any other non-nil value, return a list containing
5156 all of them."
5157 (let ((siblings
5158 ;; An object can belong to the contents of its parent or
5159 ;; to a secondary string. We check the latter option
5160 ;; first.
5161 (let ((parent (org-export-get-parent blob)))
5162 (or (and (not (memq (org-element-type blob)
5163 org-element-all-elements))
5164 (let ((sec-value
5165 (org-element-property
5166 (cdr (assq (org-element-type parent)
5167 org-element-secondary-value-alist))
5168 parent)))
5169 (and (memq blob sec-value) sec-value)))
5170 (org-element-contents parent))))
5171 prev)
5172 (catch 'exit
5173 (mapc (lambda (obj)
5174 (cond ((memq obj (plist-get info :ignore-list)))
5175 ((null n) (throw 'exit obj))
5176 ((not (wholenump n)) (push obj prev))
5177 ((zerop n) (throw 'exit prev))
5178 (t (decf n) (push obj prev))))
5179 (cdr (memq blob (reverse siblings))))
5180 prev)))
5182 (defun org-export-get-next-element (blob info &optional n)
5183 "Return next element or object.
5185 BLOB is an element or object. INFO is a plist used as
5186 a communication channel. Return next exportable element or
5187 object, a string, or nil.
5189 When optional argument N is a positive integer, return a list
5190 containing up to N siblings after BLOB, from closest to farthest.
5191 With any other non-nil value, return a list containing all of
5192 them."
5193 (let ((siblings
5194 ;; An object can belong to the contents of its parent or to
5195 ;; a secondary string. We check the latter option first.
5196 (let ((parent (org-export-get-parent blob)))
5197 (or (and (not (memq (org-element-type blob)
5198 org-element-all-objects))
5199 (let ((sec-value
5200 (org-element-property
5201 (cdr (assq (org-element-type parent)
5202 org-element-secondary-value-alist))
5203 parent)))
5204 (cdr (memq blob sec-value))))
5205 (cdr (memq blob (org-element-contents parent))))))
5206 next)
5207 (catch 'exit
5208 (mapc (lambda (obj)
5209 (cond ((memq obj (plist-get info :ignore-list)))
5210 ((null n) (throw 'exit obj))
5211 ((not (wholenump n)) (push obj next))
5212 ((zerop n) (throw 'exit (nreverse next)))
5213 (t (decf n) (push obj next))))
5214 siblings)
5215 (nreverse next))))
5218 ;;;; Translation
5220 ;; `org-export-translate' translates a string according to the language
5221 ;; specified by the LANGUAGE keyword. `org-export-dictionary' contains
5222 ;; the dictionary used for the translation.
5224 (defconst org-export-dictionary
5225 '(("Author"
5226 ("ca" :default "Autor")
5227 ("cs" :default "Autor")
5228 ("da" :default "Ophavsmand")
5229 ("de" :default "Autor")
5230 ("eo" :html "A&#365;toro")
5231 ("es" :default "Autor")
5232 ("fi" :html "Tekij&auml;")
5233 ("fr" :default "Auteur")
5234 ("hu" :default "Szerz&otilde;")
5235 ("is" :html "H&ouml;fundur")
5236 ("it" :default "Autore")
5237 ("ja" :html "&#33879;&#32773;" :utf-8 "著者")
5238 ("nl" :default "Auteur")
5239 ("no" :default "Forfatter")
5240 ("nb" :default "Forfatter")
5241 ("nn" :default "Forfattar")
5242 ("pl" :default "Autor")
5243 ("ru" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
5244 ("sv" :html "F&ouml;rfattare")
5245 ("uk" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
5246 ("zh-CN" :html "&#20316;&#32773;" :utf-8 "作者")
5247 ("zh-TW" :html "&#20316;&#32773;" :utf-8 "作者"))
5248 ("Date"
5249 ("ca" :default "Data")
5250 ("cs" :default "Datum")
5251 ("da" :default "Dato")
5252 ("de" :default "Datum")
5253 ("eo" :default "Dato")
5254 ("es" :default "Fecha")
5255 ("fi" :html "P&auml;iv&auml;m&auml;&auml;r&auml;")
5256 ("hu" :html "D&aacute;tum")
5257 ("is" :default "Dagsetning")
5258 ("it" :default "Data")
5259 ("ja" :html "&#26085;&#20184;" :utf-8 "日付")
5260 ("nl" :default "Datum")
5261 ("no" :default "Dato")
5262 ("nb" :default "Dato")
5263 ("nn" :default "Dato")
5264 ("pl" :default "Data")
5265 ("ru" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
5266 ("sv" :default "Datum")
5267 ("uk" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
5268 ("zh-CN" :html "&#26085;&#26399;" :utf-8 "日期")
5269 ("zh-TW" :html "&#26085;&#26399;" :utf-8 "日期"))
5270 ("Equation"
5271 ("de" :default "Gleichung")
5272 ("es" :html "Ecuaci&oacute;n" :default "Ecuación")
5273 ("fr" :ascii "Equation" :default "Équation"))
5274 ("Figure"
5275 ("de" :default "Abbildung")
5276 ("es" :default "Figura"))
5277 ("Footnotes"
5278 ("ca" :html "Peus de p&agrave;gina")
5279 ("cs" :default "Pozn\xe1mky pod carou")
5280 ("da" :default "Fodnoter")
5281 ("de" :html "Fu&szlig;noten" :default "Fußnoten")
5282 ("eo" :default "Piednotoj")
5283 ("es" :html "Nota al pie de p&aacute;gina" :default "Nota al pie de página")
5284 ("fi" :default "Alaviitteet")
5285 ("fr" :default "Notes de bas de page")
5286 ("hu" :html "L&aacute;bjegyzet")
5287 ("is" :html "Aftanm&aacute;lsgreinar")
5288 ("it" :html "Note a pi&egrave; di pagina")
5289 ("ja" :html "&#33050;&#27880;" :utf-8 "脚注")
5290 ("nl" :default "Voetnoten")
5291 ("no" :default "Fotnoter")
5292 ("nb" :default "Fotnoter")
5293 ("nn" :default "Fotnotar")
5294 ("pl" :default "Przypis")
5295 ("ru" :html "&#1057;&#1085;&#1086;&#1089;&#1082;&#1080;" :utf-8 "Сноски")
5296 ("sv" :default "Fotnoter")
5297 ("uk" :html "&#1055;&#1088;&#1080;&#1084;&#1110;&#1090;&#1082;&#1080;"
5298 :utf-8 "Примітки")
5299 ("zh-CN" :html "&#33050;&#27880;" :utf-8 "脚注")
5300 ("zh-TW" :html "&#33139;&#35387;" :utf-8 "腳註"))
5301 ("List of Listings"
5302 ("de" :default "Programmauflistungsverzeichnis")
5303 ("es" :default "Indice de Listados de programas")
5304 ("fr" :default "Liste des programmes"))
5305 ("List of Tables"
5306 ("de" :default "Tabellenverzeichnis")
5307 ("es" :default "Indice de tablas")
5308 ("fr" :default "Liste des tableaux"))
5309 ("Listing %d:"
5310 ("de" :default "Programmlisting %d")
5311 ("es" :default "Listado de programa %d")
5312 ("fr"
5313 :ascii "Programme %d :" :default "Programme nº %d :"
5314 :latin1 "Programme %d :"))
5315 ("See section %s"
5316 ("de" :default "siehe Abschnitt %s")
5317 ("es" :default "vea seccion %s")
5318 ("fr" :default "cf. section %s"))
5319 ("Table %d:"
5320 ("de" :default "Tabelle %d")
5321 ("es" :default "Tabla %d")
5322 ("fr"
5323 :ascii "Tableau %d :" :default "Tableau nº %d :" :latin1 "Tableau %d :"))
5324 ("Table of Contents"
5325 ("ca" :html "&Iacute;ndex")
5326 ("cs" :default "Obsah")
5327 ("da" :default "Indhold")
5328 ("de" :default "Inhaltsverzeichnis")
5329 ("eo" :default "Enhavo")
5330 ("es" :html "&Iacute;ndice")
5331 ("fi" :html "Sis&auml;llysluettelo")
5332 ("fr" :ascii "Sommaire" :default "Table des matières")
5333 ("hu" :html "Tartalomjegyz&eacute;k")
5334 ("is" :default "Efnisyfirlit")
5335 ("it" :default "Indice")
5336 ("ja" :html "&#30446;&#27425;" :utf-8 "目次")
5337 ("nl" :default "Inhoudsopgave")
5338 ("no" :default "Innhold")
5339 ("nb" :default "Innhold")
5340 ("nn" :default "Innhald")
5341 ("pl" :html "Spis tre&#x015b;ci")
5342 ("ru" :html "&#1057;&#1086;&#1076;&#1077;&#1088;&#1078;&#1072;&#1085;&#1080;&#1077;"
5343 :utf-8 "Содержание")
5344 ("sv" :html "Inneh&aring;ll")
5345 ("uk" :html "&#1047;&#1084;&#1110;&#1089;&#1090;" :utf-8 "Зміст")
5346 ("zh-CN" :html "&#30446;&#24405;" :utf-8 "目录")
5347 ("zh-TW" :html "&#30446;&#37636;" :utf-8 "目錄"))
5348 ("Unknown reference"
5349 ("de" :default "Unbekannter Verweis")
5350 ("es" :default "referencia desconocida")
5351 ("fr" :ascii "Destination inconnue" :default "Référence inconnue")))
5352 "Dictionary for export engine.
5354 Alist whose CAR is the string to translate and CDR is an alist
5355 whose CAR is the language string and CDR is a plist whose
5356 properties are possible charsets and values translated terms.
5358 It is used as a database for `org-export-translate'. Since this
5359 function returns the string as-is if no translation was found,
5360 the variable only needs to record values different from the
5361 entry.")
5363 (defun org-export-translate (s encoding info)
5364 "Translate string S according to language specification.
5366 ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
5367 and `:utf-8'. INFO is a plist used as a communication channel.
5369 Translation depends on `:language' property. Return the
5370 translated string. If no translation is found, try to fall back
5371 to `:default' encoding. If it fails, return S."
5372 (let* ((lang (plist-get info :language))
5373 (translations (cdr (assoc lang
5374 (cdr (assoc s org-export-dictionary))))))
5375 (or (plist-get translations encoding)
5376 (plist-get translations :default)
5377 s)))
5381 ;;; Asynchronous Export
5383 ;; `org-export-async-start' is the entry point for asynchronous
5384 ;; export. It recreates current buffer (including visibility,
5385 ;; narrowing and visited file) in an external Emacs process, and
5386 ;; evaluates a command there. It then applies a function on the
5387 ;; returned results in the current process.
5389 ;; Asynchronously generated results are never displayed directly.
5390 ;; Instead, they are stored in `org-export-stack-contents'. They can
5391 ;; then be retrieved by calling `org-export-stack'.
5393 ;; Export Stack is viewed through a dedicated major mode
5394 ;;`org-export-stack-mode' and tools: `org-export-stack-refresh',
5395 ;;`org-export-stack-delete', `org-export-stack-view' and
5396 ;;`org-export-stack-clear'.
5398 ;; For back-ends, `org-export-add-to-stack' add a new source to stack.
5399 ;; It should used whenever `org-export-async-start' is called.
5401 (defmacro org-export-async-start (fun &rest body)
5402 "Call function FUN on the results returned by BODY evaluation.
5404 BODY evaluation happens in an asynchronous process, from a buffer
5405 which is an exact copy of the current one.
5407 Use `org-export-add-to-stack' in FUN in order to register results
5408 in the stack. Examples for, respectively a temporary buffer and
5409 a file are:
5411 \(org-export-async-start
5412 \(lambda (output)
5413 \(with-current-buffer (get-buffer-create \"*Org BACKEND Export*\")
5414 \(erase-buffer)
5415 \(insert output)
5416 \(goto-char (point-min))
5417 \(org-export-add-to-stack (current-buffer) 'backend)))
5418 `(org-export-as 'backend ,subtreep ,visible-only ,body-only ',ext-plist))
5422 \(org-export-async-start
5423 \(lambda (f) (org-export-add-to-stack f 'backend))
5424 `(expand-file-name
5425 \(org-export-to-file
5426 'backend ,outfile ,subtreep ,visible-only ,body-only ',ext-plist)))"
5427 (declare (indent 1) (debug t))
5428 (org-with-gensyms (process temp-file copy-fun proc-buffer handler coding)
5429 ;; Write the full sexp evaluating BODY in a copy of the current
5430 ;; buffer to a temporary file, as it may be too long for program
5431 ;; args in `start-process'.
5432 `(with-temp-message "Initializing asynchronous export process"
5433 (let ((,copy-fun (org-export--generate-copy-script (current-buffer)))
5434 (,temp-file (make-temp-file "org-export-process"))
5435 (,coding buffer-file-coding-system))
5436 (with-temp-file ,temp-file
5437 (insert
5438 ;; Null characters (from variable values) are inserted
5439 ;; within the file. As a consequence, coding system for
5440 ;; buffer contents will not be recognized properly. So,
5441 ;; we make sure it is the same as the one used to display
5442 ;; the original buffer.
5443 (format ";; -*- coding: %s; -*-\n%S"
5444 ,coding
5445 `(with-temp-buffer
5446 ,(when org-export-async-debug '(setq debug-on-error t))
5447 ;; Ignore `kill-emacs-hook' and code evaluation
5448 ;; queries from Babel as we need a truly
5449 ;; non-interactive process.
5450 (setq kill-emacs-hook nil
5451 org-babel-confirm-evaluate-answer-no t)
5452 ;; Initialize export framework.
5453 (require 'ox)
5454 ;; Re-create current buffer there.
5455 (funcall ,,copy-fun)
5456 (restore-buffer-modified-p nil)
5457 ;; Sexp to evaluate in the buffer.
5458 (print (progn ,,@body))))))
5459 ;; Start external process.
5460 (let* ((process-connection-type nil)
5461 (,proc-buffer (generate-new-buffer-name "*Org Export Process*"))
5462 (,process
5463 (start-process
5464 "org-export-process" ,proc-buffer
5465 (expand-file-name invocation-name invocation-directory)
5466 "-Q" "--batch"
5467 "-l" org-export-async-init-file
5468 "-l" ,temp-file)))
5469 ;; Register running process in stack.
5470 (org-export-add-to-stack (get-buffer ,proc-buffer) nil ,process)
5471 ;; Set-up sentinel in order to catch results.
5472 (set-process-sentinel
5473 ,process
5474 (let ((handler ',fun))
5475 `(lambda (p status)
5476 (let ((proc-buffer (process-buffer p)))
5477 (when (eq (process-status p) 'exit)
5478 (unwind-protect
5479 (if (zerop (process-exit-status p))
5480 (unwind-protect
5481 (let ((results
5482 (with-current-buffer proc-buffer
5483 (goto-char (point-max))
5484 (backward-sexp)
5485 (read (current-buffer)))))
5486 (funcall ,handler results))
5487 (unless org-export-async-debug
5488 (and (get-buffer proc-buffer)
5489 (kill-buffer proc-buffer))))
5490 (org-export-add-to-stack proc-buffer nil p)
5491 (ding)
5492 (message "Process '%s' exited abnormally" p))
5493 (unless org-export-async-debug
5494 (delete-file ,,temp-file)))))))))))))
5496 (defun org-export-add-to-stack (source backend &optional process)
5497 "Add a new result to export stack if not present already.
5499 SOURCE is a buffer or a file name containing export results.
5500 BACKEND is a symbol representing export back-end used to generate
5503 Entries already pointing to SOURCE and unavailable entries are
5504 removed beforehand. Return the new stack."
5505 (setq org-export-stack-contents
5506 (cons (list source backend (or process (current-time)))
5507 (org-export-stack-remove source))))
5509 (defun org-export-stack ()
5510 "Menu for asynchronous export results and running processes."
5511 (interactive)
5512 (let ((buffer (get-buffer-create "*Org Export Stack*")))
5513 (set-buffer buffer)
5514 (when (zerop (buffer-size)) (org-export-stack-mode))
5515 (org-export-stack-refresh)
5516 (pop-to-buffer buffer))
5517 (message "Type \"q\" to quit, \"?\" for help"))
5519 (defun org-export--stack-source-at-point ()
5520 "Return source from export results at point in stack."
5521 (let ((source (car (nth (1- (org-current-line)) org-export-stack-contents))))
5522 (if (not source) (error "Source unavailable, please refresh buffer")
5523 (let ((source-name (if (stringp source) source (buffer-name source))))
5524 (if (save-excursion
5525 (beginning-of-line)
5526 (looking-at (concat ".* +" (regexp-quote source-name) "$")))
5527 source
5528 ;; SOURCE is not consistent with current line. The stack
5529 ;; view is outdated.
5530 (error "Source unavailable; type `g' to update buffer"))))))
5532 (defun org-export-stack-clear ()
5533 "Remove all entries from export stack."
5534 (interactive)
5535 (setq org-export-stack-contents nil))
5537 (defun org-export-stack-refresh (&rest dummy)
5538 "Refresh the asynchronous export stack.
5539 DUMMY is ignored. Unavailable sources are removed from the list.
5540 Return the new stack."
5541 (let ((inhibit-read-only t))
5542 (org-preserve-lc
5543 (erase-buffer)
5544 (insert (concat
5545 (let ((counter 0))
5546 (mapconcat
5547 (lambda (entry)
5548 (let ((proc-p (processp (nth 2 entry))))
5549 (concat
5550 ;; Back-end.
5551 (format " %-12s " (or (nth 1 entry) ""))
5552 ;; Age.
5553 (let ((data (nth 2 entry)))
5554 (if proc-p (format " %6s " (process-status data))
5555 ;; Compute age of the results.
5556 (org-format-seconds
5557 "%4h:%.2m "
5558 (float-time (time-since data)))))
5559 ;; Source.
5560 (format " %s"
5561 (let ((source (car entry)))
5562 (if (stringp source) source
5563 (buffer-name source)))))))
5564 ;; Clear stack from exited processes, dead buffers or
5565 ;; non-existent files.
5566 (setq org-export-stack-contents
5567 (org-remove-if-not
5568 (lambda (el)
5569 (if (processp (nth 2 el))
5570 (buffer-live-p (process-buffer (nth 2 el)))
5571 (let ((source (car el)))
5572 (if (bufferp source) (buffer-live-p source)
5573 (file-exists-p source)))))
5574 org-export-stack-contents)) "\n")))))))
5576 (defun org-export-stack-remove (&optional source)
5577 "Remove export results at point from stack.
5578 If optional argument SOURCE is non-nil, remove it instead."
5579 (interactive)
5580 (let ((source (or source (org-export--stack-source-at-point))))
5581 (setq org-export-stack-contents
5582 (org-remove-if (lambda (el) (equal (car el) source))
5583 org-export-stack-contents))))
5585 (defun org-export-stack-view (&optional in-emacs)
5586 "View export results at point in stack.
5587 With an optional prefix argument IN-EMACS, force viewing files
5588 within Emacs."
5589 (interactive "P")
5590 (let ((source (org-export--stack-source-at-point)))
5591 (cond ((processp source)
5592 (org-switch-to-buffer-other-window (process-buffer source)))
5593 ((bufferp source) (org-switch-to-buffer-other-window source))
5594 (t (org-open-file source in-emacs)))))
5596 (defvar org-export-stack-mode-map
5597 (let ((km (make-sparse-keymap)))
5598 (define-key km " " 'next-line)
5599 (define-key km "n" 'next-line)
5600 (define-key km "\C-n" 'next-line)
5601 (define-key km [down] 'next-line)
5602 (define-key km "p" 'previous-line)
5603 (define-key km "\C-p" 'previous-line)
5604 (define-key km "\C-?" 'previous-line)
5605 (define-key km [up] 'previous-line)
5606 (define-key km "C" 'org-export-stack-clear)
5607 (define-key km "v" 'org-export-stack-view)
5608 (define-key km (kbd "RET") 'org-export-stack-view)
5609 (define-key km "d" 'org-export-stack-remove)
5611 "Keymap for Org Export Stack.")
5613 (define-derived-mode org-export-stack-mode special-mode "Org-Stack"
5614 "Mode for displaying asynchronous export stack.
5616 Type \\[org-export-stack] to visualize the asynchronous export
5617 stack.
5619 In an Org Export Stack buffer, use \\<org-export-stack-mode-map>\\[org-export-stack-view] to view export output
5620 on current line, \\[org-export-stack-remove] to remove it from the stack and \\[org-export-stack-clear] to clear
5621 stack completely.
5623 Removing entries in an Org Export Stack buffer doesn't affect
5624 files or buffers, only the display.
5626 \\{org-export-stack-mode-map}"
5627 (abbrev-mode 0)
5628 (auto-fill-mode 0)
5629 (setq buffer-read-only t
5630 buffer-undo-list t
5631 truncate-lines t
5632 header-line-format
5633 '(:eval
5634 (format " %-12s | %6s | %s" "Back-End" "Age" "Source")))
5635 (org-add-hook 'post-command-hook 'org-export-stack-refresh nil t)
5636 (set (make-local-variable 'revert-buffer-function)
5637 'org-export-stack-refresh))
5641 ;;; The Dispatcher
5643 ;; `org-export-dispatch' is the standard interactive way to start an
5644 ;; export process. It uses `org-export--dispatch-ui' as a subroutine
5645 ;; for its interface, which, in turn, delegates response to key
5646 ;; pressed to `org-export--dispatch-action'.
5648 ;;;###autoload
5649 (defun org-export-dispatch (&optional arg)
5650 "Export dispatcher for Org mode.
5652 It provides an access to common export related tasks in a buffer.
5653 Its interface comes in two flavours: standard and expert.
5655 While both share the same set of bindings, only the former
5656 displays the valid keys associations in a dedicated buffer.
5657 Scrolling (resp. line-wise motion) in this buffer is done with
5658 SPC and DEL (resp. C-n and C-p) keys.
5660 Set variable `org-export-dispatch-use-expert-ui' to switch to one
5661 flavour or the other.
5663 When ARG is \\[universal-argument], repeat the last export action, with the same set
5664 of options used back then, on the current buffer.
5666 When ARG is \\[universal-argument] \\[universal-argument], display the asynchronous export stack."
5667 (interactive "P")
5668 (let* ((input
5669 (cond ((equal arg '(16)) '(stack))
5670 ((and arg org-export-dispatch-last-action))
5671 (t (save-window-excursion
5672 (unwind-protect
5673 (progn
5674 ;; Remember where we are
5675 (move-marker org-export-dispatch-last-position
5676 (point)
5677 (org-base-buffer (current-buffer)))
5678 ;; Get and store an export command
5679 (setq org-export-dispatch-last-action
5680 (org-export--dispatch-ui
5681 (list org-export-initial-scope
5682 (and org-export-in-background 'async))
5684 org-export-dispatch-use-expert-ui)))
5685 (and (get-buffer "*Org Export Dispatcher*")
5686 (kill-buffer "*Org Export Dispatcher*")))))))
5687 (action (car input))
5688 (optns (cdr input)))
5689 (unless (memq 'subtree optns)
5690 (move-marker org-export-dispatch-last-position nil))
5691 (case action
5692 ;; First handle special hard-coded actions.
5693 (template (org-export-insert-default-template nil optns))
5694 (stack (org-export-stack))
5695 (publish-current-file
5696 (org-publish-current-file (memq 'force optns) (memq 'async optns)))
5697 (publish-current-project
5698 (org-publish-current-project (memq 'force optns) (memq 'async optns)))
5699 (publish-choose-project
5700 (org-publish (assoc (org-icompleting-read
5701 "Publish project: "
5702 org-publish-project-alist nil t)
5703 org-publish-project-alist)
5704 (memq 'force optns)
5705 (memq 'async optns)))
5706 (publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
5707 (otherwise
5708 (save-excursion
5709 (when arg
5710 ;; Repeating command, maybe move cursor to restore subtree
5711 ;; context.
5712 (if (eq (marker-buffer org-export-dispatch-last-position)
5713 (org-base-buffer (current-buffer)))
5714 (goto-char org-export-dispatch-last-position)
5715 ;; We are in a different buffer, forget position.
5716 (move-marker org-export-dispatch-last-position nil)))
5717 (funcall action
5718 ;; Return a symbol instead of a list to ease
5719 ;; asynchronous export macro use.
5720 (and (memq 'async optns) t)
5721 (and (memq 'subtree optns) t)
5722 (and (memq 'visible optns) t)
5723 (and (memq 'body optns) t)))))))
5725 (defun org-export--dispatch-ui (options first-key expertp)
5726 "Handle interface for `org-export-dispatch'.
5728 OPTIONS is a list containing current interactive options set for
5729 export. It can contain any of the following symbols:
5730 `body' toggles a body-only export
5731 `subtree' restricts export to current subtree
5732 `visible' restricts export to visible part of buffer.
5733 `force' force publishing files.
5734 `async' use asynchronous export process
5736 FIRST-KEY is the key pressed to select the first level menu. It
5737 is nil when this menu hasn't been selected yet.
5739 EXPERTP, when non-nil, triggers expert UI. In that case, no help
5740 buffer is provided, but indications about currently active
5741 options are given in the prompt. Moreover, \[?] allows to switch
5742 back to standard interface."
5743 (let* ((fontify-key
5744 (lambda (key &optional access-key)
5745 ;; Fontify KEY string. Optional argument ACCESS-KEY, when
5746 ;; non-nil is the required first-level key to activate
5747 ;; KEY. When its value is t, activate KEY independently
5748 ;; on the first key, if any. A nil value means KEY will
5749 ;; only be activated at first level.
5750 (if (or (eq access-key t) (eq access-key first-key))
5751 (org-propertize key 'face 'org-warning)
5752 key)))
5753 (fontify-value
5754 (lambda (value)
5755 ;; Fontify VALUE string.
5756 (org-propertize value 'face 'font-lock-variable-name-face)))
5757 ;; Prepare menu entries by extracting them from
5758 ;; `org-export-registered-backends', and sorting them by
5759 ;; access key and by ordinal, if any.
5760 (backends
5761 (sort
5762 (sort
5763 (delq nil
5764 (mapcar
5765 (lambda (b)
5766 (let ((name (car b)))
5767 (catch 'ignored
5768 ;; Ignore any back-end belonging to
5769 ;; `org-export-invisible-backends' or derived
5770 ;; from one of them.
5771 (dolist (ignored org-export-invisible-backends)
5772 (when (org-export-derived-backend-p name ignored)
5773 (throw 'ignored nil)))
5774 (org-export-backend-menu name))))
5775 org-export-registered-backends))
5776 (lambda (a b)
5777 (let ((key-a (nth 1 a))
5778 (key-b (nth 1 b)))
5779 (cond ((and (numberp key-a) (numberp key-b))
5780 (< key-a key-b))
5781 ((numberp key-b) t)))))
5782 (lambda (a b) (< (car a) (car b)))))
5783 ;; Compute a list of allowed keys based on the first key
5784 ;; pressed, if any. Some keys
5785 ;; (?^B, ?^V, ?^S, ?^F, ?^A, ?&, ?# and ?q) are always
5786 ;; available.
5787 (allowed-keys
5788 (nconc (list 2 22 19 6 1)
5789 (if (not first-key) (org-uniquify (mapcar 'car backends))
5790 (let (sub-menu)
5791 (dolist (backend backends (sort (mapcar 'car sub-menu) '<))
5792 (when (eq (car backend) first-key)
5793 (setq sub-menu (append (nth 2 backend) sub-menu))))))
5794 (cond ((eq first-key ?P) (list ?f ?p ?x ?a))
5795 ((not first-key) (list ?P)))
5796 (list ?& ?#)
5797 (when expertp (list ??))
5798 (list ?q)))
5799 ;; Build the help menu for standard UI.
5800 (help
5801 (unless expertp
5802 (concat
5803 ;; Options are hard-coded.
5804 (format "[%s] Body only: %s [%s] Visible only: %s
5805 \[%s] Export scope: %s [%s] Force publishing: %s
5806 \[%s] Async export: %s\n\n"
5807 (funcall fontify-key "C-b" t)
5808 (funcall fontify-value
5809 (if (memq 'body options) "On " "Off"))
5810 (funcall fontify-key "C-v" t)
5811 (funcall fontify-value
5812 (if (memq 'visible options) "On " "Off"))
5813 (funcall fontify-key "C-s" t)
5814 (funcall fontify-value
5815 (if (memq 'subtree options) "Subtree" "Buffer "))
5816 (funcall fontify-key "C-f" t)
5817 (funcall fontify-value
5818 (if (memq 'force options) "On " "Off"))
5819 (funcall fontify-key "C-a" t)
5820 (funcall fontify-value
5821 (if (memq 'async options) "On " "Off")))
5822 ;; Display registered back-end entries. When a key
5823 ;; appears for the second time, do not create another
5824 ;; entry, but append its sub-menu to existing menu.
5825 (let (last-key)
5826 (mapconcat
5827 (lambda (entry)
5828 (let ((top-key (car entry)))
5829 (concat
5830 (unless (eq top-key last-key)
5831 (setq last-key top-key)
5832 (format "\n[%s] %s\n"
5833 (funcall fontify-key (char-to-string top-key))
5834 (nth 1 entry)))
5835 (let ((sub-menu (nth 2 entry)))
5836 (unless (functionp sub-menu)
5837 ;; Split sub-menu into two columns.
5838 (let ((index -1))
5839 (concat
5840 (mapconcat
5841 (lambda (sub-entry)
5842 (incf index)
5843 (format
5844 (if (zerop (mod index 2)) " [%s] %-26s"
5845 "[%s] %s\n")
5846 (funcall fontify-key
5847 (char-to-string (car sub-entry))
5848 top-key)
5849 (nth 1 sub-entry)))
5850 sub-menu "")
5851 (when (zerop (mod index 2)) "\n"))))))))
5852 backends ""))
5853 ;; Publishing menu is hard-coded.
5854 (format "\n[%s] Publish
5855 [%s] Current file [%s] Current project
5856 [%s] Choose project [%s] All projects\n\n\n"
5857 (funcall fontify-key "P")
5858 (funcall fontify-key "f" ?P)
5859 (funcall fontify-key "p" ?P)
5860 (funcall fontify-key "x" ?P)
5861 (funcall fontify-key "a" ?P))
5862 (format "[%s] Export stack [%s] Insert template\n"
5863 (funcall fontify-key "&" t)
5864 (funcall fontify-key "#" t))
5865 (format "[%s] %s"
5866 (funcall fontify-key "q" t)
5867 (if first-key "Main menu" "Exit")))))
5868 ;; Build prompts for both standard and expert UI.
5869 (standard-prompt (unless expertp "Export command: "))
5870 (expert-prompt
5871 (when expertp
5872 (format
5873 "Export command (C-%s%s%s%s%s) [%s]: "
5874 (if (memq 'body options) (funcall fontify-key "b" t) "b")
5875 (if (memq 'visible options) (funcall fontify-key "v" t) "v")
5876 (if (memq 'subtree options) (funcall fontify-key "s" t) "s")
5877 (if (memq 'force options) (funcall fontify-key "f" t) "f")
5878 (if (memq 'async options) (funcall fontify-key "a" t) "a")
5879 (mapconcat (lambda (k)
5880 ;; Strip control characters.
5881 (unless (< k 27) (char-to-string k)))
5882 allowed-keys "")))))
5883 ;; With expert UI, just read key with a fancy prompt. In standard
5884 ;; UI, display an intrusive help buffer.
5885 (if expertp
5886 (org-export--dispatch-action
5887 expert-prompt allowed-keys backends options first-key expertp)
5888 ;; At first call, create frame layout in order to display menu.
5889 (unless (get-buffer "*Org Export Dispatcher*")
5890 (delete-other-windows)
5891 (org-switch-to-buffer-other-window
5892 (get-buffer-create "*Org Export Dispatcher*"))
5893 (setq cursor-type nil
5894 header-line-format "Use SPC, DEL, C-n or C-p to navigate.")
5895 ;; Make sure that invisible cursor will not highlight square
5896 ;; brackets.
5897 (set-syntax-table (copy-syntax-table))
5898 (modify-syntax-entry ?\[ "w"))
5899 ;; At this point, the buffer containing the menu exists and is
5900 ;; visible in the current window. So, refresh it.
5901 (with-current-buffer "*Org Export Dispatcher*"
5902 ;; Refresh help. Maintain display continuity by re-visiting
5903 ;; previous window position.
5904 (let ((pos (window-start)))
5905 (erase-buffer)
5906 (insert help)
5907 (set-window-start nil pos)))
5908 (org-fit-window-to-buffer)
5909 (org-export--dispatch-action
5910 standard-prompt allowed-keys backends options first-key expertp))))
5912 (defun org-export--dispatch-action
5913 (prompt allowed-keys backends options first-key expertp)
5914 "Read a character from command input and act accordingly.
5916 PROMPT is the displayed prompt, as a string. ALLOWED-KEYS is
5917 a list of characters available at a given step in the process.
5918 BACKENDS is a list of menu entries. OPTIONS, FIRST-KEY and
5919 EXPERTP are the same as defined in `org-export--dispatch-ui',
5920 which see.
5922 Toggle export options when required. Otherwise, return value is
5923 a list with action as CAR and a list of interactive export
5924 options as CDR."
5925 (let (key)
5926 ;; Scrolling: when in non-expert mode, act on motion keys (C-n,
5927 ;; C-p, SPC, DEL).
5928 (while (and (setq key (read-char-exclusive prompt))
5929 (not expertp)
5930 (memq key '(14 16 ?\s ?\d)))
5931 (case key
5932 (14 (if (not (pos-visible-in-window-p (point-max)))
5933 (ignore-errors (scroll-up 1))
5934 (message "End of buffer")
5935 (sit-for 1)))
5936 (16 (if (not (pos-visible-in-window-p (point-min)))
5937 (ignore-errors (scroll-down 1))
5938 (message "Beginning of buffer")
5939 (sit-for 1)))
5940 (?\s (if (not (pos-visible-in-window-p (point-max)))
5941 (scroll-up nil)
5942 (message "End of buffer")
5943 (sit-for 1)))
5944 (?\d (if (not (pos-visible-in-window-p (point-min)))
5945 (scroll-down nil)
5946 (message "Beginning of buffer")
5947 (sit-for 1)))))
5948 (cond
5949 ;; Ignore undefined associations.
5950 ((not (memq key allowed-keys))
5951 (ding)
5952 (unless expertp (message "Invalid key") (sit-for 1))
5953 (org-export--dispatch-ui options first-key expertp))
5954 ;; q key at first level aborts export. At second level, cancel
5955 ;; first key instead.
5956 ((eq key ?q) (if (not first-key) (error "Export aborted")
5957 (org-export--dispatch-ui options nil expertp)))
5958 ;; Help key: Switch back to standard interface if expert UI was
5959 ;; active.
5960 ((eq key ??) (org-export--dispatch-ui options first-key nil))
5961 ;; Send request for template insertion along with export scope.
5962 ((eq key ?#) (cons 'template (memq 'subtree options)))
5963 ;; Switch to asynchronous export stack.
5964 ((eq key ?&) '(stack))
5965 ;; Toggle options: C-b (2) C-v (22) C-s (19) C-f (6) C-a (1).
5966 ((memq key '(2 22 19 6 1))
5967 (org-export--dispatch-ui
5968 (let ((option (case key (2 'body) (22 'visible) (19 'subtree)
5969 (6 'force) (1 'async))))
5970 (if (memq option options) (remq option options)
5971 (cons option options)))
5972 first-key expertp))
5973 ;; Action selected: Send key and options back to
5974 ;; `org-export-dispatch'.
5975 ((or first-key (functionp (nth 2 (assq key backends))))
5976 (cons (cond
5977 ((not first-key) (nth 2 (assq key backends)))
5978 ;; Publishing actions are hard-coded. Send a special
5979 ;; signal to `org-export-dispatch'.
5980 ((eq first-key ?P)
5981 (case key
5982 (?f 'publish-current-file)
5983 (?p 'publish-current-project)
5984 (?x 'publish-choose-project)
5985 (?a 'publish-all)))
5986 ;; Return first action associated to FIRST-KEY + KEY
5987 ;; path. Indeed, derived backends can share the same
5988 ;; FIRST-KEY.
5989 (t (catch 'found
5990 (mapc (lambda (backend)
5991 (let ((match (assq key (nth 2 backend))))
5992 (when match (throw 'found (nth 2 match)))))
5993 (member (assq first-key backends) backends)))))
5994 options))
5995 ;; Otherwise, enter sub-menu.
5996 (t (org-export--dispatch-ui options key expertp)))))
6000 (provide 'ox)
6002 ;; Local variables:
6003 ;; generated-autoload-file: "org-loaddefs.el"
6004 ;; End:
6006 ;;; ox.el ends here