1 ;;; test-ox.el --- Tests for ox.el
3 ;; Copyright (C) 2012-2015 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
24 (unless (featurep 'ox
)
25 (signal 'missing-test-dependency
"org-export"))
27 (defun org-test-default-backend ()
28 "Return a default export back-end.
29 This back-end simply returns parsed data as Org syntax."
30 (org-export-create-backend
31 :transcoders
(let (transcode-table)
32 (dolist (type (append org-element-all-elements
33 org-element-all-objects
)
37 (lambda (obj contents info
)
39 (intern (format "org-element-%s-interpreter"
44 (defmacro org-test-with-parsed-data
(data &rest body
)
45 "Execute body with parsed data available.
46 DATA is a string containing the data to be parsed. BODY is the
47 body to execute. Parse tree is available under the `tree'
48 variable, and communication channel under `info'."
49 (declare (debug (form body
)) (indent 1))
50 `(org-test-with-temp-text ,data
51 (org-export--delete-commented-subtrees)
52 (let* ((tree (org-element-parse-buffer))
53 (info (org-export-get-environment)))
54 (org-export--prune-tree tree info
)
55 (org-export--remove-uninterpreted-data tree info
)
56 (let ((info (org-combine-plists
57 info
(org-export-collect-tree-properties tree info
))))
64 (ert-deftest test-org-export
/bind-keyword
()
65 "Test reading #+BIND: keywords."
66 ;; Test with `org-export-allow-bind-keywords' set to t.
68 (org-test-with-temp-text "#+BIND: test-ox-var value"
69 (let ((org-export-allow-bind-keywords t
))
70 (org-export-get-environment)
71 (eq test-ox-var
'value
))))
72 ;; Test with `org-export-allow-bind-keywords' set to nil.
74 (org-test-with-temp-text "#+BIND: test-ox-var value"
75 (let ((org-export-allow-bind-keywords nil
))
76 (org-export-get-environment)
77 (boundp 'test-ox-var
))))
78 ;; BIND keywords are case-insensitive.
80 (org-test-with-temp-text "#+bind: test-ox-var value"
81 (let ((org-export-allow-bind-keywords t
))
82 (org-export-get-environment)
83 (eq test-ox-var
'value
))))
84 ;; Preserve order of BIND keywords.
86 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
87 (let ((org-export-allow-bind-keywords t
))
88 (org-export-get-environment)
90 ;; Read BIND keywords in setup files.
92 (org-test-with-temp-text
93 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
94 (let ((org-export-allow-bind-keywords t
))
95 (org-export-get-environment)
96 (eq variable
'value
))))
97 ;; Verify that bound variables are seen during export.
100 (org-test-with-temp-text "#+BIND: test-ox-var value"
101 (let ((org-export-allow-bind-keywords t
))
103 (org-export-create-backend
105 '((section .
(lambda (s c i
)
106 (if (eq test-ox-var
'value
) "Yes" "No")))))))))))
108 (ert-deftest test-org-export
/parse-option-keyword
()
109 "Test reading all standard #+OPTIONS: items."
112 (org-export--parse-option-keyword
113 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
114 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
117 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
118 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
119 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
120 :with-footnotes t
:with-inlinetasks nil
:with-priority t
121 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
122 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
123 :with-title t
:with-todo-keywords t
)))
124 ;; Test some special values.
127 (org-export--parse-option-keyword
128 "arch:headline d:(\"TEST\") ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
131 :with-archived-trees headline
:with-drawers
("TEST")
132 :with-sub-superscript
{} :with-toc
1 :with-tags not-in-toc
133 :with-tasks todo
:with-timestamps active
))))
135 (ert-deftest test-org-export
/get-inbuffer-options
()
136 "Test reading all standard export keywords."
137 ;; Properties should follow buffer order.
140 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
141 (org-export--get-inbuffer-options))
142 '(:language
"fr" :creator
"Me" :email
"email")))
143 ;; Parse document keywords.
146 (org-test-with-temp-text "#+AUTHOR: Me"
147 (org-export--get-inbuffer-options))
149 ;; Test `space' behaviour.
152 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
153 (org-export--get-inbuffer-options))
154 '(:title
("Some title with spaces"))))
155 ;; Test `newline' behaviour.
158 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
159 (org-export--get-inbuffer-options))
160 '(:description
"With\ntwo lines")))
161 ;; Test `split' behaviour.
164 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
165 (org-export--get-inbuffer-options))
166 '(:select-tags
("a" "b"))))
167 ;; Options set through SETUPFILE.
170 (org-test-with-temp-text
171 (format "#+DESCRIPTION: l1
175 #+SETUPFILE: \"%s/examples/setupfile.org\"
181 (org-export--get-inbuffer-options))
182 '(:description
"l1\nl2\nl3":language
"fr" :select-tags
("a" "b" "c")
184 ;; More than one property can refer to the same buffer keyword.
186 (equal '(:k2
"value" :k1
"value")
187 (let ((backend (org-export-create-backend
188 :options
'((:k1
"KEYWORD")
190 (org-test-with-temp-text "#+KEYWORD: value"
191 (org-export--get-inbuffer-options backend
)))))
192 ;; Keywords in commented subtrees are ignored.
195 (org-test-with-parsed-data "* COMMENT H1\n#+AUTHOR: Me"
196 (plist-get info
:author
))))
199 (org-test-with-parsed-data "* COMMENT H1\n** H2\n#+EMAIL: Mine"
200 (plist-get info
:email
)))))
202 (ert-deftest test-org-export
/get-subtree-options
()
203 "Test setting options from headline's properties."
205 (org-test-with-temp-text "#+TITLE: Title
208 :EXPORT_TITLE: Subtree Title
212 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
213 '("Subtree Title"))))
217 (org-test-with-temp-text "#+OPTIONS: H:1
225 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
227 (org-test-with-temp-text "#+DATE: today
230 :EXPORT_DATE: 29-03-2012
234 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
236 ;; Properties with `split' behaviour are stored as a list of
240 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
243 :EXPORT_EXCLUDE_TAGS: a b
248 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
249 ;; Handle :PROPERTY+: syntax.
252 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
255 :EXPORT_EXCLUDE_TAGS: a
256 :EXPORT_EXCLUDE_TAGS+: b
261 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
262 ;; Export properties are case-insensitive.
263 (org-test-with-temp-text "* Headline
265 :EXPORT_Date: 29-03-2012
268 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
270 ;; Still grab correct options when section above is empty.
273 (org-test-with-temp-text "* H1\n** H11\n** H12"
274 (progn (forward-line 2)
275 (plist-get (org-export-get-environment nil t
) :title
))))))
277 (ert-deftest test-org-export
/set-title
()
278 "Test title setting."
279 ;; Without TITLE keyword.
283 (let (org-export-filter-body-functions
284 org-export-filter-final-output-functions
)
285 (org-test-with-temp-text "Test"
287 (org-export-create-backend
289 '((template .
(lambda (text info
)
290 (org-element-interpret-data
291 (plist-get info
:title
)))))))))))
292 ;; With a blank TITLE keyword.
296 (let (org-export-filter-body-functions
297 org-export-filter-final-output-functions
)
298 (org-test-with-temp-text "#+TITLE:\nTest"
300 (org-export-create-backend
302 '((template .
(lambda (text info
)
303 (org-element-interpret-data
304 (plist-get info
:title
)))))))))))
305 ;; With a non-empty TITLE keyword.
309 (org-test-with-temp-text "#+TITLE: Title\nTest"
311 (org-export-create-backend
313 '((template .
(lambda (text info
)
314 (org-element-interpret-data
315 (plist-get info
:title
))))))))))
316 ;; When exporting a subtree, its heading becomes the headline of the
321 (org-test-with-temp-text "* Headline\nBody"
323 (org-export-create-backend
325 '((template .
(lambda (text info
)
326 (org-element-interpret-data
327 (plist-get info
:title
))))))
329 ;; ... unless there is an EXPORT_TITLE property at the root of the
334 (org-test-with-temp-text
335 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
337 (org-export-create-backend
339 '((template .
(lambda (text info
)
340 (org-element-interpret-data
341 (plist-get info
:title
))))))
344 (ert-deftest test-org-export
/handle-options
()
345 "Test if export options have an impact on output."
346 ;; Test exclude tags for headlines and inlinetasks.
349 (let (org-export-filter-body-functions
350 org-export-filter-final-output-functions
)
351 (org-test-with-temp-text "* Head1 :noexp:"
352 (org-export-as (org-test-default-backend)
353 nil nil nil
'(:exclude-tags
("noexp")))))))
354 ;; Test include tags for headlines and inlinetasks.
356 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
357 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
358 (let ((org-tags-column 0))
359 (org-export-as (org-test-default-backend)
360 nil nil nil
'(:select-tags
("exp")))))))
361 ;; If there is an include tag, ignore the section before the first
364 (equal "* H1 :exp:\nBody\n"
365 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
366 (let ((org-tags-column 0))
367 (org-export-as (org-test-default-backend)
368 nil nil nil
'(:select-tags
("exp")))))))
370 (equal "* H1 :exp:\n"
371 (org-test-with-temp-text "* H1 :exp:\nBody"
372 (let ((org-tags-column 0))
373 (org-export-as (org-test-default-backend)
374 nil nil nil
'(:select-tags
("exp")))))))
375 ;; Test mixing include tags and exclude tags.
378 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
379 (org-test-with-temp-text "
381 ** Sub-Head1 :noexport:
384 ** Sub-Head1 :export:"
385 (org-export-as (org-test-default-backend) nil nil nil
386 '(:select-tags
("export") :exclude-tags
("noexport"))))))
390 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
391 org-export-filter-body-functions
392 org-export-filter-final-output-functions
)
393 (org-test-with-temp-text "* TODO Head1"
394 (org-export-as (org-test-default-backend)
395 nil nil nil
'(:with-tasks nil
))))))
397 (equal "* TODO Head1\n"
398 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
399 (org-test-with-temp-text "* TODO Head1"
400 (org-export-as (org-test-default-backend)
401 nil nil nil
'(:with-tasks t
))))))
405 (let (org-export-filter-body-functions
406 org-export-filter-final-output-functions
)
407 (org-test-with-temp-text "* Head1 :archive:"
408 (let ((org-archive-tag "archive"))
409 (org-export-as (org-test-default-backend)
410 nil nil nil
'(:with-archived-trees nil
)))))))
413 "\\* Head1[ \t]+:archive:"
414 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
415 (let ((org-archive-tag "archive"))
416 (org-export-as (org-test-default-backend) nil nil nil
417 '(:with-archived-trees headline
))))))
420 "\\`\\* Head1[ \t]+:archive:\n\\'"
421 (org-test-with-temp-text "* Head1 :archive:"
422 (let ((org-archive-tag "archive"))
423 (org-export-as (org-test-default-backend)
424 nil nil nil
'(:with-archived-trees t
))))))
427 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
428 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
429 (org-export-as (org-test-default-backend)
430 nil nil nil
'(:with-clocks t
)))))
433 (let (org-export-filter-body-functions
434 org-export-filter-final-output-functions
)
435 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
436 (org-export-as (org-test-default-backend)
437 nil nil nil
'(:with-clocks nil
))))))
441 (let (org-export-filter-body-functions
442 org-export-filter-final-output-functions
)
443 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
444 (org-export-as (org-test-default-backend)
445 nil nil nil
'(:with-drawers nil
))))))
447 (equal ":TEST:\ncontents\n:END:\n"
448 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
449 (org-export-as (org-test-default-backend)
450 nil nil nil
'(:with-drawers t
)))))
452 (equal ":FOO:\nkeep\n:END:\n"
453 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
454 (org-export-as (org-test-default-backend)
455 nil nil nil
'(:with-drawers
("FOO"))))))
457 (equal ":FOO:\nkeep\n:END:\n"
458 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
459 (org-export-as (org-test-default-backend)
460 nil nil nil
'(:with-drawers
(not "BAR"))))))
464 (org-test-with-temp-text ": A"
465 (org-export-as (org-test-default-backend) nil nil nil
466 '(:with-fixed-width t
)))))
469 (let (org-export-filter-body-functions
470 org-export-filter-final-output-functions
)
471 (org-test-with-temp-text ": A"
472 (org-export-as (org-test-default-backend) nil nil nil
473 '(:with-fixed-width nil
))))))
477 (let ((org-footnote-section nil
))
478 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
479 (org-trim (org-export-as (org-test-default-backend)
480 nil nil nil
'(:with-footnotes nil
)))))))
482 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
483 (let ((org-footnote-section nil
))
484 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
485 (org-trim (org-export-as (org-test-default-backend)
486 nil nil nil
'(:with-footnotes t
)))))))
488 (when (featurep 'org-inlinetask
)
492 (let ((org-inlinetask-min-level 15)
493 org-export-filter-body-functions
494 org-export-filter-final-output-functions
)
495 (org-test-with-temp-text "*************** Task"
496 (org-export-as (org-test-default-backend)
497 nil nil nil
'(:with-inlinetasks nil
))))))
501 (let ((org-inlinetask-min-level 15)
502 org-export-filter-body-functions
503 org-export-filter-final-output-functions
)
504 (org-test-with-temp-text
505 "*************** Task\nContents\n*************** END"
506 (org-export-as (org-test-default-backend)
507 nil nil nil
'(:with-inlinetasks nil
)))))))
511 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
512 (let ((org-closed-string "CLOSED:"))
513 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
514 (org-export-as (org-test-default-backend)
515 nil nil nil
'(:with-planning t
))))))
518 (let ((org-closed-string "CLOSED:"))
519 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
520 (org-export-as (org-test-default-backend)
521 nil nil nil
'(:with-planning nil
))))))
525 (org-test-with-temp-text
526 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
527 (org-export-as (org-test-default-backend)
528 nil nil nil
'(:with-properties nil
)))))
530 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
531 (org-test-with-temp-text
532 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
533 (org-export-as (org-test-default-backend)
534 nil nil nil
'(:with-properties t
)))))
536 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
537 (org-test-with-temp-text
538 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
539 (org-export-as (org-test-default-backend)
540 nil nil nil
'(:with-properties
("B"))))))
541 ;; Statistics cookies.
544 (let (org-export-filter-body-functions
545 org-export-filter-final-output-functions
)
547 (org-test-with-temp-text "[0/0]"
548 (org-export-as (org-test-default-backend)
549 nil nil nil
'(:with-statistics-cookies nil
)))))))
553 (org-test-with-temp-text "| A |"
554 (org-export-as (org-test-default-backend) nil nil nil
555 '(:with-tables t
)))))
558 (let (org-export-filter-body-functions
559 org-export-filter-final-output-functions
)
560 (org-test-with-temp-text "| A |"
561 (org-export-as (org-test-default-backend) nil nil nil
562 '(:with-tables nil
)))))))
564 (ert-deftest test-org-export
/with-timestamps
()
565 "Test `org-export-with-timestamps' specifications."
569 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
570 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
571 (org-export-as (org-test-default-backend)
572 nil nil nil
'(:with-timestamps t
)))))
577 (let (org-export-filter-body-functions
578 org-export-filter-final-output-functions
)
580 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
581 (org-export-as (org-test-default-backend)
582 nil nil nil
'(:with-timestamps nil
)))))))
586 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
587 (org-test-with-temp-text
588 "<2012-03-29 Thu>[2012-03-29 Thu]
590 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
591 (org-export-as (org-test-default-backend)
592 nil nil nil
'(:with-timestamps active
)))))
596 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
597 (org-test-with-temp-text
598 "<2012-03-29 Thu>[2012-03-29 Thu]
600 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
601 (org-export-as (org-test-default-backend)
602 nil nil nil
'(:with-timestamps inactive
))))))
604 (ert-deftest test-org-export
/comment-tree
()
605 "Test if export process ignores commented trees."
608 (let (org-export-filter-body-functions
609 org-export-filter-final-output-functions
)
610 (org-test-with-temp-text "* COMMENT Head1"
611 (org-export-as (org-test-default-backend)))))))
613 (ert-deftest test-org-export
/uninterpreted
()
614 "Test handling of uninterpreted elements."
618 (org-test-with-temp-text "\\alpha"
620 (org-export-create-backend
621 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
622 (paragraph .
(lambda (p c i
) c
))
623 (section .
(lambda (s c i
) c
))))
624 nil nil nil
'(:with-entities t
)))))
627 (org-test-with-temp-text "\\alpha"
629 (org-export-create-backend
630 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
631 (paragraph .
(lambda (p c i
) c
))
632 (section .
(lambda (s c i
) c
))))
633 nil nil nil
'(:with-entities nil
)))))
637 (org-test-with-temp-text "*bold*"
639 (org-export-create-backend
640 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
641 (paragraph .
(lambda (p c i
) c
))
642 (section .
(lambda (s c i
) c
))))
643 nil nil nil
'(:with-emphasize t
)))))
646 (org-test-with-temp-text "*bold*"
648 (org-export-create-backend
649 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
650 (paragraph .
(lambda (p c i
) c
))
651 (section .
(lambda (s c i
) c
))))
652 nil nil nil
'(:with-emphasize nil
)))))
653 ;; LaTeX environment.
656 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
658 (org-export-create-backend
659 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
660 (section .
(lambda (s c i
) c
))))
661 nil nil nil
'(:with-latex t
)))))
663 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
664 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
666 (org-export-create-backend
667 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
668 (section .
(lambda (s c i
) c
))))
669 nil nil nil
'(:with-latex verbatim
)))))
673 (org-test-with-temp-text "$1$"
675 (org-export-create-backend
676 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
677 (paragraph .
(lambda (p c i
) c
))
678 (section .
(lambda (s c i
) c
))))
679 nil nil nil
'(:with-latex t
)))))
682 (org-test-with-temp-text "$1$"
684 (org-export-create-backend
685 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
686 (paragraph .
(lambda (p c i
) c
))
687 (section .
(lambda (s c i
) c
))))
688 nil nil nil
'(:with-latex verbatim
)))))
692 (org-test-with-temp-text "a_b"
694 (org-export-create-backend
695 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
696 (paragraph .
(lambda (p c i
) c
))
697 (section .
(lambda (s c i
) c
))))
698 nil nil nil
'(:with-sub-superscript t
)))))
701 (org-test-with-temp-text "a_b"
703 (org-export-create-backend
704 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
705 (paragraph .
(lambda (p c i
) c
))
706 (section .
(lambda (s c i
) c
))))
707 nil nil nil
'(:with-sub-superscript nil
)))))
710 (org-test-with-temp-text "a_b"
712 (org-export-create-backend
713 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
714 (paragraph .
(lambda (p c i
) c
))
715 (section .
(lambda (s c i
) c
))))
716 nil nil nil
'(:with-sub-superscript
{})))))
719 (org-test-with-temp-text "a_{b}"
721 (org-export-create-backend
722 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
723 (paragraph .
(lambda (p c i
) c
))
724 (section .
(lambda (s c i
) c
))))
725 nil nil nil
'(:with-sub-superscript
{})))))
726 ;; Also handle uninterpreted objects in title.
729 (org-test-with-temp-text "#+TITLE: a_b"
731 (org-export-create-backend
733 '((subscript .
(lambda (s c i
) "dummy"))
734 (template .
(lambda (c i
) (org-export-data
735 (plist-get i
:title
) i
)))
736 (section .
(lambda (s c i
) c
))))
737 nil nil nil
'(:with-sub-superscript nil
)))))
738 ;; Special case: multiples uninterpreted objects in a row.
741 (org-test-with-temp-text "a_b_c_d"
743 (org-export-create-backend
744 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
745 (paragraph .
(lambda (p c i
) c
))
746 (section .
(lambda (s c i
) c
))))
747 nil nil nil
'(:with-sub-superscript
{}))))))
749 (ert-deftest test-org-export
/export-scope
()
750 "Test all export scopes."
751 (org-test-with-temp-text "
758 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
759 "text\n*** Head3\n"))
761 (goto-char (point-min))
764 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
767 (goto-char (point-min))
769 (transient-mark-mode 1)
770 (push-mark (point) t t
)
771 (goto-char (point-at-eol))
772 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
773 ;; Subtree with a code block calling another block outside.
774 (let ((org-export-babel-evaluate t
))
777 (org-test-with-temp-text "
779 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
784 #+BEGIN_SRC emacs-lisp
788 (org-export-as (org-test-default-backend) 'subtree
)))))
790 (let ((backend (org-test-default-backend)))
791 (setf (org-export-backend-transcoders backend
)
792 (cons '(template .
(lambda (body i
)
793 (format "BEGIN\n%sEND" body
)))
794 (org-export-backend-transcoders backend
)))
795 (org-test-with-temp-text "Text"
796 (should (equal (org-export-as backend nil nil
'body-only
)
798 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
800 (ert-deftest test-org-export
/output-file-name
()
801 "Test `org-export-output-file-name' specifications."
802 ;; Export from a file: name is built from original file name.
804 (org-test-with-temp-text-in-file "Test"
805 (equal (concat (file-name-as-directory ".")
806 (file-name-nondirectory
807 (file-name-sans-extension (buffer-file-name))))
808 (file-name-sans-extension (org-export-output-file-name ".ext")))))
809 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
811 (org-test-with-temp-text-in-file
812 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
813 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
814 ;; From a buffer not associated to a file, too.
816 (org-test-with-temp-text
817 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
818 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
819 ;; When provided name is absolute, preserve it.
821 (org-test-with-temp-text
822 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
823 (expand-file-name "test"))
824 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
825 ;; When PUB-DIR argument is provided, use it.
827 (org-test-with-temp-text-in-file "Test"
828 (equal (file-name-directory
829 (org-export-output-file-name ".ext" nil
"dir/"))
831 ;; When returned name would overwrite original file, add EXTENSION
834 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
835 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
837 (ert-deftest test-org-export
/expand-include
()
838 "Test file inclusion in an Org buffer."
839 ;; Error when file isn't specified.
841 (org-test-with-temp-text "#+INCLUDE: dummy.org"
842 (org-export-expand-include-keyword)))
843 ;; Full insertion with recursive inclusion.
848 (expand-file-name "examples/include.org" org-test-dir
))
849 (replace-regexp-in-string
850 (regexp-quote "#+INCLUDE: \"include2.org\"")
851 "Success!" (buffer-string)))
852 (org-test-with-temp-text
853 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
854 (org-export-expand-include-keyword)
856 ;; Localized insertion.
857 (org-test-with-temp-text
858 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
860 (org-export-expand-include-keyword)
861 (should (equal (buffer-string)
862 "Small Org file with an include keyword.\n")))
863 ;; Insertion with constraints on headlines level.
866 "* Top heading\n** Heading\nbody\n"
867 (org-test-with-temp-text
869 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
871 (org-export-expand-include-keyword)
875 "* Top heading\n* Heading\nbody\n"
876 (org-test-with-temp-text
878 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
880 (org-export-expand-include-keyword)
882 ;; Inclusion within an example block.
885 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
886 (org-test-with-temp-text
887 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
889 (org-export-expand-include-keyword)
891 ;; Inclusion within a src-block.
894 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
895 (org-test-with-temp-text
897 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
899 (org-export-expand-include-keyword)
901 ;; Inclusion within an html export-block.
904 "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
905 (org-test-with-temp-text
907 "#+INCLUDE: \"%s/examples/include.html\" HTML"
909 (org-export-expand-include-keyword)
911 ;; Inclusion within an center paragraph
914 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
915 (org-test-with-temp-text
917 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
919 (org-export-expand-include-keyword)
921 ;; Footnotes labels are local to each included file.
927 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
929 \[fn:test] Footnote \"test\""))
930 (org-test-with-temp-text-in-file contents
931 (let ((file1 (buffer-file-name)))
932 (org-test-with-temp-text-in-file contents
933 (let ((file2 (buffer-file-name)))
934 (org-test-with-temp-text
935 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
937 (org-export-expand-include-keyword)
938 (org-element-map (org-element-parse-buffer)
941 (org-element-property :label ref
)))))))))))))
942 ;; Footnotes labels are not local to each include keyword.
948 Footnotes[fn:1], [fn:test], [2] and [fn:inline:anonymous footnote].
951 \[fn:test] Footnote \"test\""))
952 (org-test-with-temp-text-in-file contents
953 (let ((file (buffer-file-name)))
954 (org-test-with-temp-text
955 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
956 (org-export-expand-include-keyword)
957 (org-element-map (org-element-parse-buffer)
959 (lambda (ref) (org-element-property :label ref
)))))))))))
960 ;; Footnotes are supported by :lines-like elements and unnecessary
961 ;; footnotes are dropped.
970 Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote]
975 \[fn:test] Footnote \"test\"
978 (org-test-with-temp-text-in-file contents
979 (let ((file (buffer-file-name)))
980 (org-test-with-temp-text
981 (format "#+INCLUDE: \"%s::*bar\"
983 (org-export-expand-include-keyword)
984 (org-element-map (org-element-parse-buffer)
986 (lambda (ref) (org-element-property :label ref
)))))))))))
987 ;; If only-contents is non-nil only include contents of element.
991 (org-test-with-temp-text
993 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" " org-test-dir
)
995 (org-export-expand-include-keyword)
997 ;; Headings can be included via CUSTOM_ID.
999 (org-test-with-temp-text
1000 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1001 (org-export-expand-include-keyword)
1002 (goto-char (point-min))
1003 (looking-at "* Another heading")))
1004 ;; Named objects can be included.
1008 (org-test-with-temp-text
1009 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t" org-test-dir
)
1010 (org-export-expand-include-keyword)
1012 ;; Including non-existing elements should result in an error.
1014 (org-test-with-temp-text
1015 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\"" org-test-dir
)
1016 (org-export-expand-include-keyword)))
1017 ;; Lines work relatively to an included element.
1021 (org-test-with-temp-text
1022 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t :lines \"2-3\"" org-test-dir
)
1023 (org-export-expand-include-keyword)
1025 ;; Properties should be dropped from headlines.
1028 (org-test-with-temp-text
1029 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t" org-test-dir
)
1030 (org-export-expand-include-keyword)
1032 (org-test-with-temp-text
1033 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1034 (org-export-expand-include-keyword)
1036 ;; Properties should be dropped, drawers should not be.
1039 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1040 (org-test-with-temp-text
1041 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t" org-test-dir
)
1042 (org-export-expand-include-keyword)
1044 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1046 (org-every (lambda (level) (zerop (1- level
)))
1047 (org-test-with-temp-text
1049 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n" org-test-dir
)
1050 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\"" org-test-dir
))
1051 (org-export-expand-include-keyword)
1052 (org-element-map (org-element-parse-buffer) 'headline
1053 (lambda (head) (org-element-property :level head
))))))
1054 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1057 (org-test-with-temp-text
1058 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp" org-test-dir
)
1059 (org-export-expand-include-keyword)
1061 (org-test-with-temp-text
1062 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1" org-test-dir
)
1063 (org-export-expand-include-keyword)
1065 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1067 (org-test-with-temp-text-in-file
1068 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1069 (narrow-to-region (point) (point-max))
1070 (org-export-expand-include-keyword)
1071 (eq 1 (org-current-level))))
1072 ;; If :minlevel is present do not alter it.
1074 (org-test-with-temp-text
1075 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3" org-test-dir
)
1076 (narrow-to-region (point) (point-max))
1077 (org-export-expand-include-keyword)
1078 (eq 3 (org-current-level)))))
1080 (ert-deftest test-org-export
/expand-macro
()
1081 "Test macro expansion in an Org buffer."
1082 ;; Standard macro expansion.
1084 (equal "#+MACRO: macro1 value\nvalue\n"
1085 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1086 (org-export-as (org-test-default-backend)))))
1087 ;; Expand specific macros.
1089 (equal "me 2012-03-29 me@here Title\n"
1090 (org-test-with-temp-text
1096 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1097 (let ((output (org-export-as (org-test-default-backend))))
1098 (substring output
(string-match ".*\n\\'" output
))))))
1099 ;; Expand specific macros when property contained a regular macro
1103 (org-test-with-temp-text "
1104 #+MACRO: macro1 value
1105 #+TITLE: {{{macro1}}}
1107 (let ((output (org-export-as (org-test-default-backend))))
1108 (substring output
(string-match ".*\n\\'" output
))))))
1109 ;; Expand macros with templates in included files.
1112 (org-test-with-temp-text
1113 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1114 {{{included-macro}}}" org-test-dir
)
1115 (let ((output (org-export-as (org-test-default-backend))))
1116 (substring output
(string-match ".*\n\\'" output
))))))
1117 ;; Date macro takes a optional formatting argument
1120 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1121 (org-export-as (org-test-default-backend)))))
1122 ;; Only single timestamps are formatted
1124 (equal "<2015-02x-09>\n"
1125 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1126 (org-export-as (org-test-default-backend)))))
1127 ;; Throw an error when a macro definition is missing.
1129 (org-test-with-temp-text "{{{missing}}}"
1130 (org-export-as (org-test-default-backend))))
1131 ;; Macros defined in commented subtrees are ignored.
1133 (org-test-with-temp-text
1134 "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
1135 (org-export-as (org-test-default-backend))))
1137 (org-test-with-temp-text
1138 "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
1139 (org-export-as (org-test-default-backend)))))
1141 (ert-deftest test-org-export
/before-processing-hook
()
1142 "Test `org-export-before-processing-hook'."
1145 "#+MACRO: mac val\nTest\n"
1146 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1147 (let ((org-export-before-processing-hook
1149 (while (re-search-forward "{{{" nil t
)
1150 (let ((object (org-element-context)))
1151 (when (eq (org-element-type object
) 'macro
)
1153 (org-element-property :begin object
)
1154 (org-element-property :end object
)))))))))
1155 (org-export-as (org-test-default-backend)))))))
1157 (ert-deftest test-org-export
/before-parsing-hook
()
1158 "Test `org-export-before-parsing-hook'."
1160 (equal "Body 1\nBody 2\n"
1161 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1162 (let ((org-export-before-parsing-hook
1164 (goto-char (point-min))
1165 (while (re-search-forward org-outline-regexp-bol nil t
)
1167 (point-at-bol) (progn (forward-line) (point))))))))
1168 (org-export-as (org-test-default-backend)))))))
1172 ;;; Affiliated Keywords
1174 (ert-deftest test-org-export
/read-attribute
()
1175 "Test `org-export-read-attribute' specifications."
1179 (org-export-read-attribute
1181 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1182 (org-element-at-point)))
1184 ;; Return nil on empty attribute.
1186 (org-export-read-attribute
1188 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1189 ;; Return nil on "nil" string.
1191 (equal '(:a nil
:b nil
)
1192 (org-export-read-attribute
1194 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1195 (org-element-at-point)))))
1196 ;; Return nil on empty string.
1198 (equal '(:a nil
:b nil
)
1199 (org-export-read-attribute
1201 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1202 (org-element-at-point)))))
1203 ;; Return empty string when value is "".
1206 (org-export-read-attribute
1208 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1209 (org-element-at-point)))))
1210 ;; Return \"\" when value is """".
1213 (org-export-read-attribute
1215 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1216 (org-element-at-point)))))
1217 ;; Ignore text before first property.
1220 (org-export-read-attribute
1222 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1223 (org-element-at-point))))))
1225 (ert-deftest test-org-export
/get-caption
()
1226 "Test `org-export-get-caption' specifications."
1227 ;; Without optional argument, return long caption
1231 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1232 (org-export-get-caption (org-element-at-point)))))
1233 ;; With optional argument, return short caption.
1237 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1238 (org-export-get-caption (org-element-at-point) t
))))
1239 ;; Multiple lines are separated by white spaces.
1243 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1244 (org-export-get-caption (org-element-at-point))))))
1250 (ert-deftest test-org-export
/define-backend
()
1251 "Test back-end definition and accessors."
1254 (equal '((headline . my-headline-test
))
1255 (let (org-export--registered-backends)
1256 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1257 (org-export-get-all-transcoders 'test
))))
1260 (equal '((:filter-headline . my-filter
))
1261 (let (org-export--registered-backends)
1262 (org-export-define-backend 'test
1263 '((headline . my-headline-test
))
1264 :filters-alist
'((:filter-headline . my-filter
)))
1265 (org-export-backend-filters (org-export-get-backend 'test
)))))
1268 (equal '((:prop value
))
1269 (let (org-export--registered-backends)
1270 (org-export-define-backend 'test
1271 '((headline . my-headline-test
))
1272 :options-alist
'((:prop value
)))
1273 (org-export-backend-options (org-export-get-backend 'test
)))))
1276 (equal '(?k
"Test Export" test
)
1277 (let (org-export--registered-backends)
1278 (org-export-define-backend 'test
1279 '((headline . my-headline-test
))
1280 :menu-entry
'(?k
"Test Export" test
))
1281 (org-export-backend-menu (org-export-get-backend 'test
)))))
1284 (equal '(("TEST" . org-element-export-block-parser
))
1285 (let (org-export--registered-backends org-element-block-name-alist
)
1286 (org-export-define-backend 'test
1287 '((headline . my-headline-test
))
1288 :export-block
'("test"))
1289 org-element-block-name-alist
))))
1291 (ert-deftest test-org-export
/define-derived-backend
()
1292 "Test `org-export-define-derived-backend' specifications."
1293 ;; Error when parent back-end is not defined.
1295 (let (org-export--registered-backends)
1296 (org-export-define-derived-backend 'test
'parent
)))
1297 ;; Append translation table to parent's.
1299 (equal '((:headline . test
) (:headline . parent
))
1300 (let (org-export--registered-backends)
1301 (org-export-define-backend 'parent
'((:headline . parent
)))
1302 (org-export-define-derived-backend 'test
'parent
1303 :translate-alist
'((:headline . test
)))
1304 (org-export-get-all-transcoders 'test
))))
1305 ;; Options defined in the new back have priority over those defined
1309 (let (org-export--registered-backends)
1310 (org-export-define-backend 'parent
1311 '((:headline . parent
))
1312 :options-alist
'((:a nil nil
'parent
)))
1313 (org-export-define-derived-backend 'test
'parent
1314 :options-alist
'((:a nil nil
'test
)))
1315 (plist-get (org-export--get-global-options
1316 (org-export-get-backend 'test
))
1319 (ert-deftest test-org-export
/derived-backend-p
()
1320 "Test `org-export-derived-backend-p' specifications."
1321 ;; Non-nil with direct match.
1323 (let (org-export--registered-backends)
1324 (org-export-define-backend 'test
'((headline . test
)))
1325 (org-export-derived-backend-p 'test
'test
)))
1327 (let (org-export--registered-backends)
1328 (org-export-define-backend 'test
'((headline . test
)))
1329 (org-export-define-derived-backend 'test2
'test
)
1330 (org-export-derived-backend-p 'test2
'test2
)))
1331 ;; Non-nil with a direct parent.
1333 (let (org-export--registered-backends)
1334 (org-export-define-backend 'test
'((headline . test
)))
1335 (org-export-define-derived-backend 'test2
'test
)
1336 (org-export-derived-backend-p 'test2
'test
)))
1337 ;; Non-nil with an indirect parent.
1339 (let (org-export--registered-backends)
1340 (org-export-define-backend 'test
'((headline . test
)))
1341 (org-export-define-derived-backend 'test2
'test
)
1342 (org-export-define-derived-backend 'test3
'test2
)
1343 (org-export-derived-backend-p 'test3
'test
)))
1346 (let (org-export--registered-backends)
1347 (org-export-define-backend 'test
'((headline . test
)))
1348 (org-export-define-backend 'test2
'((headline . test2
)))
1349 (org-export-derived-backend-p 'test2
'test
)))
1351 (let (org-export--registered-backends)
1352 (org-export-define-backend 'test
'((headline . test
)))
1353 (org-export-define-backend 'test2
'((headline . test2
)))
1354 (org-export-define-derived-backend 'test3
'test2
)
1355 (org-export-derived-backend-p 'test3
'test
))))
1357 (ert-deftest test-org-export
/get-all-transcoders
()
1358 "Test `org-export-get-all-transcoders' specifications."
1359 ;; Return nil when back-end cannot be found.
1360 (should-not (org-export-get-all-transcoders nil
))
1361 ;; Same as `org-export-transcoders' if no parent.
1363 (equal '((headline . ignore
))
1364 (org-export-get-all-transcoders
1365 (org-export-create-backend
1366 :transcoders
'((headline . ignore
))))))
1367 ;; But inherit from all ancestors whenever possible.
1369 (equal '((section . ignore
) (headline . ignore
))
1370 (let (org-export--registered-backends)
1371 (org-export-define-backend 'b1
'((headline . ignore
)))
1372 (org-export-get-all-transcoders
1373 (org-export-create-backend
1374 :parent
'b1
:transcoders
'((section . ignore
)))))))
1376 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1377 (let (org-export--registered-backends)
1378 (org-export-define-backend 'b1
'((headline . ignore
)))
1379 (org-export-define-derived-backend 'b2
'b1
1380 :translate-alist
'((section . ignore
)))
1381 (org-export-get-all-transcoders
1382 (org-export-create-backend
1383 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1384 ;; Back-end transcoders overrule inherited ones.
1387 (let (org-export--registered-backends)
1388 (org-export-define-backend 'b1
'((headline . a
)))
1389 (cdr (assq 'headline
1390 (org-export-get-all-transcoders
1391 (org-export-create-backend
1392 :parent
'b1
:transcoders
'((headline . b
))))))))))
1394 (ert-deftest test-org-export
/get-all-options
()
1395 "Test `org-export-get-all-options' specifications."
1396 ;; Return nil when back-end cannot be found.
1397 (should-not (org-export-get-all-options nil
))
1398 ;; Same as `org-export-options' if no parent.
1400 (equal '((headline . ignore
))
1401 (org-export-get-all-options
1402 (org-export-create-backend
1403 :options
'((headline . ignore
))))))
1404 ;; But inherit from all ancestors whenever possible.
1406 (equal '((:key2 value2
) (:key1 value1
))
1407 (let (org-export--registered-backends)
1408 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1409 (org-export-get-all-options
1410 (org-export-create-backend
1411 :parent
'b1
:options
'((:key2 value2
)))))))
1413 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1414 (let (org-export--registered-backends)
1415 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1416 (org-export-define-derived-backend 'b2
'b1
1417 :options-alist
'((:key2 value2
)))
1418 (org-export-get-all-options
1419 (org-export-create-backend
1420 :parent
'b2
:options
'((:key3 value3
)))))))
1421 ;; Back-end options overrule inherited ones.
1424 (let (org-export--registered-backends)
1425 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1427 (org-export-get-all-options
1428 (org-export-create-backend
1429 :parent
'b1
:options
'((:key1 . b
))))))))))
1431 (ert-deftest test-org-export
/get-all-filters
()
1432 "Test `org-export-get-all-filters' specifications."
1433 ;; Return nil when back-end cannot be found.
1434 (should-not (org-export-get-all-filters nil
))
1435 ;; Same as `org-export-filters' if no parent.
1437 (equal '((:filter-headline . ignore
))
1438 (org-export-get-all-filters
1439 (org-export-create-backend
1440 :filters
'((:filter-headline . ignore
))))))
1441 ;; But inherit from all ancestors whenever possible.
1443 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1444 (let (org-export--registered-backends)
1445 (org-export-define-backend 'b1
1446 nil
:filters-alist
'((:filter-headline . ignore
)))
1447 (org-export-get-all-filters
1448 (org-export-create-backend
1449 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1451 (equal '((:filter-paragraph . ignore
)
1452 (:filter-section . ignore
)
1453 (:filter-headline . ignore
))
1454 (let (org-export--registered-backends)
1455 (org-export-define-backend 'b1
1456 nil
:filters-alist
'((:filter-headline . ignore
)))
1457 (org-export-define-derived-backend 'b2
'b1
1458 :filters-alist
'((:filter-section . ignore
)))
1459 (org-export-get-all-filters
1460 (org-export-create-backend
1461 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1462 ;; Back-end filters overrule inherited ones.
1465 (let (org-export--registered-backends)
1466 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1467 (cdr (assq :filter-headline
1468 (org-export-get-all-filters
1469 (org-export-create-backend
1470 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1472 (ert-deftest test-org-export
/with-backend
()
1473 "Test `org-export-with-backend' definition."
1474 ;; Error when calling an undefined back-end
1475 (should-error (org-export-with-backend nil
"Test"))
1476 ;; Error when called back-end doesn't have an appropriate
1479 (org-export-with-backend
1480 (org-export-create-backend :transcoders
'((headline . ignore
)))
1482 ;; Otherwise, export using correct transcoder
1485 (let (org-export--registered-backends)
1486 (org-export-define-backend 'test
1487 '((plain-text .
(lambda (text contents info
) "Failure"))))
1488 (org-export-define-backend 'test2
1489 '((plain-text .
(lambda (text contents info
) "Success"))))
1490 (org-export-with-backend 'test2
"Test"))))
1491 ;; Provide correct back-end if transcoder needs to use recursive
1495 (let ((test-back-end
1496 (org-export-create-backend
1498 '((headline .
(lambda (headline contents info
)
1500 (org-element-property :title headline
)
1502 (plain-text .
(lambda (text info
) "Success"))))))
1503 (org-export-string-as
1505 (org-export-create-backend
1507 '((headline .
(lambda (headline contents info
)
1508 (org-export-with-backend
1509 test-back-end headline contents info
))))))))))
1511 (ert-deftest test-org-export
/data-with-backend
()
1512 "Test `org-export-data-with-backend' specifications."
1513 ;; Error when calling an undefined back-end.
1514 (should-error (org-export-data-with-backend nil
"nil" nil
))
1515 ;; Otherwise, export data recursively, using correct back-end.
1519 (org-export-data-with-backend
1521 (org-export-create-backend
1523 '((plain-text .
(lambda (text info
) "Success"))
1524 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1525 '(:with-emphasize t
)))))
1531 (ert-deftest test-org-export
/export-snippet
()
1532 "Test export snippets transcoding."
1534 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1535 (let ((backend (org-test-default-backend)))
1536 (setf (org-export-backend-name backend
) 'test
)
1537 (setf (org-export-backend-transcoders backend
)
1538 (cons (cons 'export-snippet
1539 (lambda (snippet contents info
)
1540 (when (eq (org-export-snippet-backend snippet
) 'test
)
1541 (org-element-property :value snippet
))))
1542 (org-export-backend-transcoders backend
)))
1543 (let ((org-export-snippet-translation-alist nil
))
1544 (should (equal (org-export-as backend
) "A\n")))
1545 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1546 (should (equal (org-export-as backend
) "AB\n")))))
1547 ;; Ignored export snippets do not remove any blank.
1549 (equal "begin end\n"
1550 (org-test-with-parsed-data "begin @@test:A@@ end"
1551 (org-export-data-with-backend
1553 (org-export-create-backend
1555 '((paragraph .
(lambda (paragraph contents info
) contents
))
1556 (section .
(lambda (section contents info
) contents
))))
1563 (ert-deftest test-org-export
/footnote-first-reference-p
()
1564 "Test `org-export-footnote-first-reference-p' specifications."
1568 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1571 (org-export-create-backend
1573 `(,(cons 'footnote-reference
1575 (push (org-export-footnote-first-reference-p f info
)
1578 (section .
(lambda (s c i
) c
))
1579 (paragraph .
(lambda (p c i
) c
))))
1580 nil nil nil
'(:with-footnotes t
))
1581 (nreverse result
)))))
1582 ;; Limit check to DATA, when non-nil.
1586 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1588 (org-element-map tree
'footnote-reference
1591 (org-export-footnote-first-reference-p
1592 ref info
(org-element-map tree
'headline
#'identity info t
))
1595 (nreverse result
)))))
1599 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1601 (org-element-map tree
'footnote-reference
1603 (push (org-export-footnote-first-reference-p ref info
) result
))
1605 (nreverse result
)))))
1606 ;; If optional argument BODY-FIRST is non-nil, first find footnote
1607 ;; in the main body of the document. Otherwise, enter footnote
1608 ;; definitions when they are encountered.
1612 (org-test-with-temp-text
1613 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1616 (org-export-create-backend
1618 `(,(cons 'footnote-reference
1620 (when (org-element-lineage f
'(drawer))
1621 (push (org-export-footnote-first-reference-p f info nil
)
1624 (drawer .
(lambda (d c i
) c
))
1625 (footnote-definition .
(lambda (d c i
) c
))
1626 (section .
(lambda (s c i
) c
))
1627 (paragraph .
(lambda (p c i
) c
))))
1628 nil nil nil
'(:with-footnotes t
))
1629 (nreverse result
)))))
1633 (org-test-with-temp-text
1634 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1637 (org-export-create-backend
1639 `(,(cons 'footnote-reference
1641 (when (org-element-lineage f
'(drawer))
1642 (push (org-export-footnote-first-reference-p f info nil t
)
1645 (drawer .
(lambda (d c i
) c
))
1646 (footnote-definition .
(lambda (d c i
) c
))
1647 (section .
(lambda (s c i
) c
))
1648 (paragraph .
(lambda (p c i
) c
))))
1649 nil nil nil
'(:with-footnotes t
))
1650 (nreverse result
))))))
1652 (ert-deftest test-org-export
/get-footnote-number
()
1653 "Test `org-export-get-footnote-number' specifications."
1656 (org-test-with-parsed-data
1657 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
1658 (org-element-map tree
'footnote-reference
1659 (lambda (ref) (org-export-get-footnote-number ref info
))
1661 ;; Anonymous footnotes all get a new number.
1664 (org-test-with-parsed-data
1665 "Text[fn::anon1][fn::anon2]"
1666 (org-element-map tree
'footnote-reference
1667 (lambda (ref) (org-export-get-footnote-number ref info
))
1669 ;; Test nested footnotes order.
1672 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (3 .
"fn:3") (4))
1673 (org-test-with-parsed-data
1674 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1675 (org-element-map tree
'footnote-reference
1677 (cons (org-export-get-footnote-number ref info
)
1678 (org-element-property :label ref
)))
1680 ;; Limit number to provided DATA, when non-nil.
1684 (org-test-with-parsed-data
1685 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1686 (org-element-map tree
'footnote-reference
1688 (org-export-get-footnote-number
1689 ref info
(org-element-map tree
'headline
#'identity info t
)))
1694 (org-test-with-parsed-data
1695 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
1696 (org-element-map tree
'footnote-reference
1697 (lambda (ref) (org-export-get-footnote-number ref info
))
1699 ;; With a non-nil BODY-FIRST optional argument, first check body,
1700 ;; then footnote definitions.
1703 '(("fn:1" .
1) ("fn:2" .
2) ("fn:3" .
3) ("fn:3" .
3))
1704 (org-test-with-parsed-data
1705 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1706 (org-element-map tree
'footnote-reference
1708 (cons (org-element-property :label ref
)
1709 (org-export-get-footnote-number ref info nil t
)))
1713 '(("fn:1" .
1) ("fn:2" .
3) ("fn:3" .
2) ("fn:3" .
2))
1714 (org-test-with-parsed-data
1715 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1716 (org-element-map tree
'footnote-reference
1718 (cons (org-element-property :label ref
)
1719 (org-export-get-footnote-number ref info nil
)))
1722 (ert-deftest test-org-export
/collect-footnote-definitions
()
1723 "Test `org-export-collect-footnote-definitions' specifications."
1726 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1728 \[fn:2] B [fn:3] [fn::D].
1731 (length (org-export-collect-footnote-definitions info
)))))
1732 ;; Limit number to provided DATA, when non-nil.
1736 (org-test-with-parsed-data
1737 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1739 (org-export-collect-footnote-definitions
1740 info
(org-element-map tree
'headline
#'identity info t
))))))
1743 '((1 "fn:1") (2 "fn:2"))
1744 (org-test-with-parsed-data
1745 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1746 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
1747 ;; With optional argument BODY-FIRST, first check body, then
1748 ;; footnote definitions.
1750 (equal '("fn:1" "fn:3" "fn:2" nil
)
1751 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1753 \[fn:2] B [fn:3] [fn::D].
1756 (mapcar (lambda (e) (nth 1 e
))
1757 (org-export-collect-footnote-definitions info nil t
)))))
1759 (equal '("fn:1" "fn:3" "fn:2" nil
)
1760 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1762 \[fn:2] B [fn:3] [fn::D].
1765 (mapcar (lambda (e) (nth 1 e
))
1766 (org-export-collect-footnote-definitions info
))))))
1768 (ert-deftest test-org-export
/footnotes
()
1769 "Miscellaneous tests on footnotes."
1770 (let ((org-footnote-section nil
)
1771 (org-export-with-footnotes t
))
1772 ;; Read every type of footnote.
1775 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1776 (org-test-with-parsed-data
1777 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1778 (org-element-map tree
'footnote-reference
1780 (let ((def (org-export-get-footnote-definition ref info
)))
1781 (cons (org-export-get-footnote-number ref info
)
1782 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1783 (car (org-element-contents
1784 (car (org-element-contents def
))))))))
1786 ;; Test nested footnote in invisible definitions.
1787 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1788 ;; Hide definitions.
1789 (narrow-to-region (point) (point-at-eol))
1790 (let* ((tree (org-element-parse-buffer))
1791 (info (org-combine-plists
1792 `(:parse-tree
,tree
)
1793 (org-export-collect-tree-properties
1794 tree
(org-export-get-environment)))))
1795 ;; Both footnotes should be seen.
1797 (= (length (org-export-collect-footnote-definitions info
)) 2))))
1798 ;; Test export of footnotes defined outside parsing scope.
1801 "ParagraphOut of scope\n"
1802 (org-test-with-temp-text "[fn:1] Out of scope
1805 (let ((backend (org-test-default-backend)))
1806 (setf (org-export-backend-transcoders backend
)
1807 (cons (cons 'footnote-reference
1808 (lambda (fn contents info
)
1809 (org-element-interpret-data
1810 (org-export-get-footnote-definition fn info
))))
1811 (org-export-backend-transcoders backend
)))
1813 (org-export-as backend
'subtree
)))))
1814 ;; Footnotes without a definition should throw an error.
1816 (org-test-with-parsed-data "Text[fn:1]"
1817 (org-export-get-footnote-definition
1818 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1819 ;; Footnote section should be ignored in TOC and in headlines
1822 (= 1 (let ((org-footnote-section "Footnotes"))
1823 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1824 (org-export-collect-headlines info
))))))
1827 (let ((org-footnote-section "Footnotes"))
1828 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1829 (org-element-map tree
'headline
1831 (when (equal (org-element-property :raw-value hl
) "H2")
1832 (org-export-get-headline-number hl info
)))
1837 ;;; Headlines and Inlinetasks
1839 (ert-deftest test-org-export
/get-relative-level
()
1840 "Test `org-export-get-relative-level' specifications."
1844 (let ((org-odd-levels-only nil
))
1845 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1846 (org-element-map tree
'headline
1847 (lambda (h) (org-export-get-relative-level h info
))
1852 (let ((org-odd-levels-only nil
))
1853 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1854 (org-element-map tree
'headline
1855 (lambda (h) (org-export-get-relative-level h info
))
1858 (ert-deftest test-org-export
/low-level-p
()
1859 "Test `org-export-low-level-p' specifications."
1863 (let ((org-odd-levels-only nil
))
1864 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1865 (org-element-map tree
'headline
1866 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1867 (plist-put info
:headline-levels
1)))))))
1869 (ert-deftest test-org-export
/get-headline-number
()
1870 "Test `org-export-get-headline-number' specifications."
1875 (let ((org-odd-levels-only nil
))
1876 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1877 (org-element-map tree
'headline
1878 (lambda (h) (org-export-get-headline-number h info
))
1880 ;; Missing levels are replaced with 0.
1884 (let ((org-odd-levels-only nil
))
1885 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1886 (org-element-map tree
'headline
1887 (lambda (h) (org-export-get-headline-number h info
))
1890 (ert-deftest test-org-export
/numbered-headline-p
()
1891 "Test `org-export-numbered-headline-p' specifications."
1892 ;; If `:section-numbers' is nil, never number headlines.
1894 (org-test-with-parsed-data "* Headline"
1895 (org-element-map tree
'headline
1896 (lambda (h) (org-export-numbered-headline-p h info
))
1897 (plist-put info
:section-numbers nil
))))
1898 ;; If `:section-numbers' is a number, only number headlines with
1899 ;; a level greater that it.
1903 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1904 (org-element-map tree
'headline
1905 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1906 (plist-put info
:section-numbers
1)))))
1907 ;; Otherwise, headlines are always numbered.
1909 (org-test-with-parsed-data "* Headline"
1910 (org-element-map tree
'headline
1911 (lambda (h) (org-export-numbered-headline-p h info
))
1912 (plist-put info
:section-numbers t
)))))
1914 (ert-deftest test-org-export
/org-export-get-headline-id
()
1915 "Test `org-export-get-headline-id' specifications."
1916 ;; Numbered headlines have IDs akin to "sec-N".
1919 (org-test-with-parsed-data "* H"
1920 (org-export-get-headline-id
1921 (org-element-map tree
'headline
#'identity info t
)
1923 ;; The ID of numbered headlines reflect the hierarchy.
1926 (org-test-with-parsed-data "* H1\n** H2"
1927 (org-export-get-headline-id
1928 (org-element-map tree
'headline
1930 (and (equal "H2" (org-element-property :raw-value h
)) h
))
1933 ;; Unnumbered headlines have IDs akin to "unnumbered-N".
1935 (equal "unnumbered-1"
1936 (org-test-with-parsed-data
1937 "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
1938 (org-export-get-headline-id
1939 (org-element-map tree
'headline
#'identity info t
)
1941 ;; The ID of Unnumbered headlines do not reflect the hierarchy.
1943 (equal "unnumbered-2"
1944 (org-test-with-parsed-data
1945 "* H1\n:PROPERTIES:\n:UNNUMBERED: t\n:END:\n** H2"
1946 (org-export-get-headline-id
1947 (org-element-map tree
'headline
1949 (and (equal "H2" (org-element-property :raw-value h
)) h
))
1952 ;; When #+OPTIONS: num:nil all headlines are unnumbered.
1954 (equal "unnumbered-1"
1955 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
1956 (org-export-get-headline-id
1957 (org-element-map tree
'headline
'identity info t
)
1959 ;; UNNUMBERED ignores inheritance. Any non-nil value among
1960 ;; ancestors disables numbering.
1962 (org-test-with-parsed-data
1973 (lambda (h) (not (org-export-numbered-headline-p h info
)))
1974 (org-element-map tree
'headline
#'identity info
)))))
1976 (ert-deftest test-org-export
/number-to-roman
()
1977 "Test `org-export-number-to-roman' specifications."
1978 ;; If number is negative, return it as a string.
1979 (should (equal (org-export-number-to-roman -
1) "-1"))
1980 ;; Otherwise, return it as a roman number.
1981 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1983 (ert-deftest test-org-export
/get-optional-title
()
1984 "Test `org-export-get-alt-title' specifications."
1985 ;; If ALT_TITLE property is defined, use it.
1988 (org-test-with-parsed-data
1989 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1990 (org-export-get-alt-title
1991 (org-element-map tree
'headline
'identity info t
)
1993 ;; Otherwise, fall-back to regular title.
1995 (equal '("Headline")
1996 (org-test-with-parsed-data "* Headline"
1997 (org-export-get-alt-title
1998 (org-element-map tree
'headline
'identity info t
)
2001 (ert-deftest test-org-export
/get-tags
()
2002 "Test `org-export-get-tags' specifications."
2003 (let ((org-export-exclude-tags '("noexport"))
2004 (org-export-select-tags '("export")))
2005 ;; Standard test: tags which are not a select tag, an exclude tag,
2006 ;; or specified as optional argument shouldn't be ignored.
2008 (org-test-with-parsed-data "* Headline :tag:"
2009 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2011 ;; Exclude tags are removed.
2013 (org-test-with-parsed-data "* Headline :noexport:"
2014 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2016 ;; Select tags are removed.
2018 (org-test-with-parsed-data "* Headline :export:"
2019 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2024 (org-test-with-parsed-data "* Headline :tag:export:"
2025 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2027 ;; Tags provided in the optional argument are also ignored.
2029 (org-test-with-parsed-data "* Headline :ignore:"
2030 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2032 ;; Allow tag inheritance.
2036 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2037 (org-element-map tree
'headline
2038 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2039 ;; Tag inheritance checks FILETAGS keywords.
2043 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2044 (org-element-map tree
'headline
2045 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
2047 (ert-deftest test-org-export
/get-node-property
()
2048 "Test`org-export-get-node-property' specifications."
2052 (org-test-with-parsed-data "* Headline
2056 (org-export-get-node-property
2057 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2058 ;; Test inheritance.
2061 (org-test-with-parsed-data "* Parent
2067 (org-export-get-node-property
2068 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2069 ;; Cannot return a value before the first headline.
2071 (org-test-with-parsed-data "Paragraph
2076 (org-export-get-node-property
2077 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2079 (ert-deftest test-org-export
/get-category
()
2080 "Test `org-export-get-category' specifications."
2084 (org-test-with-parsed-data "* Headline
2088 (org-export-get-category
2089 (org-element-map tree
'headline
'identity nil t
) info
))))
2090 ;; Test inheritance from a parent headline.
2092 (equal '("value" "value")
2093 (org-test-with-parsed-data "* Headline1
2098 (org-element-map tree
'headline
2099 (lambda (hl) (org-export-get-category hl info
)) info
))))
2100 ;; Test inheritance from #+CATEGORY keyword
2103 (org-test-with-parsed-data "#+CATEGORY: value
2105 (org-export-get-category
2106 (org-element-map tree
'headline
'identity nil t
) info
))))
2107 ;; Test inheritance from file name.
2110 (org-test-with-parsed-data "* Headline"
2111 (let ((info (plist-put info
:input-file
"~/test.org")))
2112 (org-export-get-category
2113 (org-element-map tree
'headline
'identity nil t
) info
)))))
2117 (org-test-with-parsed-data "* Headline"
2118 (org-export-get-category
2119 (org-element-map tree
'headline
'identity nil t
) info
)))))
2121 (ert-deftest test-org-export
/first-sibling-p
()
2122 "Test `org-export-first-sibling-p' specifications."
2127 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2128 (org-element-map tree
'headline
2129 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2133 (org-test-with-parsed-data "- item\n\n para"
2134 (org-element-map tree
'paragraph
2135 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2137 ;; Ignore sections for headlines.
2140 (org-test-with-parsed-data "* H\nSection\n** H 2"
2141 (org-element-map tree
'headline
2142 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2144 ;; Ignore headlines not exported.
2148 (let ((org-export-exclude-tags '("ignore")))
2149 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2150 (org-element-map tree
'headline
2151 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2154 (ert-deftest test-org-export
/last-sibling-p
()
2155 "Test `org-export-last-sibling-p' specifications."
2160 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2161 (org-element-map tree
'headline
2162 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2166 (org-test-with-parsed-data "- item\n\n para"
2167 (org-element-map tree
'paragraph
2168 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2170 ;; Ignore headlines not exported.
2174 (let ((org-export-exclude-tags '("ignore")))
2175 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2176 (org-element-map tree
'headline
2177 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2180 (ert-deftest test-org-export
/handle-inlinetasks
()
2181 "Test inlinetask export."
2182 ;; Inlinetask with an exclude tag.
2183 (when (featurep 'org-inlinetask
)
2187 (let ((org-inlinetask-min-level 3)
2188 org-export-filter-body-functions
2189 org-export-filter-final-output-functions
)
2190 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2191 (org-export-as (org-test-default-backend)
2192 nil nil nil
'(:exclude-tags
("noexp")))))))
2193 ;; Inlinetask with an include tag.
2196 "* H2\n*** Inline :exp:\n"
2197 (let ((org-inlinetask-min-level 3)
2198 (org-tags-column 0))
2199 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2200 (org-export-as (org-test-default-backend)
2201 nil nil nil
'(:select-tags
("exp")))))))
2202 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2205 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2206 (org-inlinetask-min-level 3)
2207 org-export-filter-body-functions
2208 org-export-filter-final-output-functions
)
2209 (org-test-with-temp-text "*** TODO Inline"
2210 (org-export-as (org-test-default-backend)
2211 nil nil nil
'(:with-tasks nil
))))))))
2217 (ert-deftest test-org-export
/get-date
()
2218 "Test `org-export-get-date' specifications."
2219 ;; Return a properly formatted string when
2220 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2221 ;; consists in a single timestamp.
2224 (let ((org-export-date-timestamp-format "%d %m %Y"))
2225 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2226 (org-export-get-date info
)))))
2227 ;; Return a secondary string otherwise.
2230 (let ((org-export-date-timestamp-format nil
))
2231 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2232 (org-export-get-date info
)))))
2235 (org-test-with-parsed-data "#+DATE: Date"
2236 (org-export-get-date info
))))
2237 ;; Optional argument has precedence over
2238 ;; `org-export-date-timestamp-format'.
2241 (let ((org-export-date-timestamp-format "%d %m %Y"))
2242 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2243 (org-export-get-date info
"%d %m"))))))
2249 (ert-deftest test-org-export
/custom-protocol-maybe
()
2250 "Test `org-export-custom-protocol-maybe' specifications."
2254 (let ((org-link-types (copy-sequence org-link-types
)))
2255 (org-add-link-type "foo" nil
(lambda (p d f
) "success"))
2256 (org-export-string-as
2258 (org-export-create-backend
2261 '((section .
(lambda (s c i
) c
))
2262 (paragraph .
(lambda (p c i
) c
))
2263 (link .
(lambda (l c i
)
2264 (or (org-export-custom-protocol-maybe l c
'test
)
2269 (let ((org-link-types (copy-sequence org-link-types
)))
2271 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2272 (org-export-string-as
2274 (org-export-create-backend
2277 '((section .
(lambda (s c i
) c
))
2278 (paragraph .
(lambda (p c i
) c
))
2279 (link .
(lambda (l c i
)
2280 (or (org-export-custom-protocol-maybe l c
'no-test
)
2282 ;; Ignore anonymous back-ends.
2286 (let ((org-link-types (copy-sequence org-link-types
)))
2288 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2289 (org-export-string-as
2291 (org-export-create-backend
2293 '((section .
(lambda (s c i
) c
))
2294 (paragraph .
(lambda (p c i
) c
))
2295 (link .
(lambda (l c i
)
2296 (or (org-export-custom-protocol-maybe l c nil
)
2299 (ert-deftest test-org-export
/get-coderef-format
()
2300 "Test `org-export-get-coderef-format' specifications."
2301 ;; A link without description returns "%s"
2302 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2304 ;; Return "%s" when path is matched within description.
2305 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2307 ;; Otherwise return description.
2308 (should (equal (org-export-get-coderef-format "path" "desc")
2311 (ert-deftest test-org-export
/inline-image-p
()
2312 "Test `org-export-inline-image-p' specifications."
2314 (org-export-inline-image-p
2315 (org-test-with-temp-text "[[#id]]"
2316 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2317 '(("custom-id" .
"id")))))
2319 (ert-deftest test-org-export
/fuzzy-link
()
2320 "Test fuzzy links specifications."
2321 ;; Link to an headline should return headline's number.
2322 (org-test-with-parsed-data
2323 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2325 ;; Note: Headline's number is in fact a list of numbers.
2327 (org-element-map tree
'link
2329 (org-export-get-ordinal
2330 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2331 ;; Link to a target in an item should return item's number.
2332 (org-test-with-parsed-data
2333 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2335 ;; Note: Item's number is in fact a list of numbers.
2337 (org-element-map tree
'link
2339 (org-export-get-ordinal
2340 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2341 ;; Link to a target in a footnote should return footnote's number.
2342 (org-test-with-parsed-data "
2343 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
2346 (org-element-map tree
'link
2348 (org-export-get-ordinal
2349 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2350 ;; Link to a named element should return sequence number of that
2352 (org-test-with-parsed-data
2353 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2356 (org-element-map tree
'link
2358 (org-export-get-ordinal
2359 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2360 ;; Link to a target not within an item, a table, a footnote
2361 ;; reference or definition should return section number.
2362 (org-test-with-parsed-data
2363 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2366 (org-element-map tree
'link
2368 (org-export-get-ordinal
2369 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2370 ;; Space are not significant when matching a fuzzy link.
2372 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2373 (org-element-map tree
'link
2374 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2376 ;; Statistics cookies are ignored for headline match.
2378 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2379 (org-element-map tree
'link
2380 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2383 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2384 (org-element-map tree
'link
2385 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2387 ;; Headline match is position dependent.
2391 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
2392 (org-element-map tree
'link
2393 (lambda (link) (org-export-resolve-fuzzy-link link info
)) info
)))))
2395 (ert-deftest test-org-export
/resolve-coderef
()
2396 "Test `org-export-resolve-coderef' specifications."
2397 (let ((org-coderef-label-format "(ref:%s)"))
2398 ;; A link to a "-n -k -r" block returns line number.
2401 (org-test-with-parsed-data
2402 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2403 (org-export-resolve-coderef "coderef" info
))))
2406 (org-test-with-parsed-data
2407 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2408 (org-export-resolve-coderef "coderef" info
))))
2409 ;; A link to a "-n -r" block returns line number.
2412 (org-test-with-parsed-data
2413 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2414 (org-export-resolve-coderef "coderef" info
))))
2417 (org-test-with-parsed-data
2418 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2419 (org-export-resolve-coderef "coderef" info
))))
2420 ;; A link to a "-n" block returns coderef.
2423 (org-test-with-parsed-data
2424 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2425 (org-export-resolve-coderef "coderef" info
))))
2428 (org-test-with-parsed-data
2429 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2430 (org-export-resolve-coderef "coderef" info
))))
2431 ;; A link to a "-r" block returns line number.
2434 (org-test-with-parsed-data
2435 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2436 (org-export-resolve-coderef "coderef" info
))))
2439 (org-test-with-parsed-data
2440 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2441 (org-export-resolve-coderef "coderef" info
))))
2442 ;; A link to a block without a switch returns coderef.
2445 (org-test-with-parsed-data
2446 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2447 (org-export-resolve-coderef "coderef" info
))))
2448 (org-test-with-parsed-data
2449 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2450 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2451 ;; Correctly handle continued line numbers. A "+n" switch should
2452 ;; resume numbering from previous block with numbered lines,
2453 ;; ignoring blocks not numbering lines in the process. A "-n"
2454 ;; switch resets count.
2457 (org-test-with-parsed-data "
2462 #+BEGIN_SRC emacs-lisp
2466 #+BEGIN_SRC emacs-lisp +n -r
2467 \(+ 1 1) (ref:addition)
2470 #+BEGIN_EXAMPLE -n -r
2471 Another text. (ref:text)
2473 (list (org-export-resolve-coderef "addition" info
)
2474 (org-export-resolve-coderef "text" info
)))))
2475 ;; Recognize coderef with user-specified syntax.
2478 (org-test-with-parsed-data
2479 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
2480 (org-export-resolve-coderef "text" info
))))
2481 ;; Unresolved coderefs throw an error.
2483 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2484 (org-export-resolve-coderef "unknown" info
)))))
2486 (ert-deftest test-org-export
/resolve-fuzzy-link
()
2487 "Test `org-export-resolve-fuzzy-link' specifications."
2488 ;; Match target objects.
2490 (org-test-with-parsed-data "<<target>> [[target]]"
2491 (org-export-resolve-fuzzy-link
2492 (org-element-map tree
'link
'identity info t
) info
)))
2493 ;; Match named elements.
2495 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2496 (org-export-resolve-fuzzy-link
2497 (org-element-map tree
'link
'identity info t
) info
)))
2498 ;; Match exact headline's name.
2500 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2501 (org-export-resolve-fuzzy-link
2502 (org-element-map tree
'link
'identity info t
) info
)))
2503 ;; Targets objects have priority over named elements and headline
2507 (org-test-with-parsed-data
2508 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2510 (org-export-resolve-fuzzy-link
2511 (org-element-map tree
'link
'identity info t
) info
)))))
2512 ;; Named elements have priority over headline titles.
2515 (org-test-with-parsed-data
2516 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2518 (org-export-resolve-fuzzy-link
2519 (org-element-map tree
'link
'identity info t
) info
)))))
2520 ;; If link's path starts with a "*", only match headline titles,
2524 (org-test-with-parsed-data
2525 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2527 (org-export-resolve-fuzzy-link
2528 (org-element-map tree
'link
'identity info t
) info
)))))
2529 ;; Error if no match.
2531 (org-test-with-parsed-data "[[target]]"
2532 (org-export-resolve-fuzzy-link
2533 (org-element-map tree
'link
'identity info t
) info
)))
2534 ;; Match fuzzy link even when before first headline.
2537 (org-test-with-parsed-data "[[hl]]\n* hl"
2539 (org-export-resolve-fuzzy-link
2540 (org-element-map tree
'link
'identity info t
) info
))))))
2542 (ert-deftest test-org-export
/resolve-id-link
()
2543 "Test `org-export-resolve-id-link' specifications."
2544 ;; Regular test for custom-id link.
2546 (equal '("Headline1")
2547 (org-test-with-parsed-data "* Headline1
2553 (org-element-property
2555 (org-export-resolve-id-link
2556 (org-element-map tree
'link
'identity info t
) info
)))))
2557 ;; Throw an error on failing searches.
2559 (org-test-with-parsed-data "* Headline1
2565 (org-export-resolve-id-link
2566 (org-element-map tree
'link
'identity info t
) info
)))
2567 ;; Test for internal id target.
2569 (equal '("Headline1")
2570 (org-test-with-parsed-data "* Headline1
2576 (org-element-property
2578 (org-export-resolve-id-link
2579 (org-element-map tree
'link
'identity info t
) info
)))))
2580 ;; Test for external id target.
2584 (org-test-with-parsed-data "[[id:aaaa]]"
2585 (org-export-resolve-id-link
2586 (org-element-map tree
'link
'identity info t
)
2587 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
2589 (ert-deftest test-org-export
/resolve-radio-link
()
2590 "Test `org-export-resolve-radio-link' specifications."
2593 (org-test-with-temp-text "<<<radio>>> radio"
2594 (org-update-radio-target-regexp)
2595 (let* ((tree (org-element-parse-buffer))
2596 (info `(:parse-tree
,tree
)))
2597 (org-export-resolve-radio-link
2598 (org-element-map tree
'link
'identity info t
)
2600 ;; Radio targets are case-insensitive.
2602 (org-test-with-temp-text "<<<RADIO>>> radio"
2603 (org-update-radio-target-regexp)
2604 (let* ((tree (org-element-parse-buffer))
2605 (info `(:parse-tree
,tree
)))
2606 (org-export-resolve-radio-link
2607 (org-element-map tree
'link
'identity info t
)
2609 ;; Radio target with objects.
2611 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2612 (org-update-radio-target-regexp)
2613 (let* ((tree (org-element-parse-buffer))
2614 (info `(:parse-tree
,tree
)))
2615 (org-export-resolve-radio-link
2616 (org-element-map tree
'link
'identity info t
)
2618 ;; Radio target with objects at its beginning.
2620 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2621 (org-update-radio-target-regexp)
2622 (let* ((tree (org-element-parse-buffer))
2623 (info `(:parse-tree
,tree
)))
2624 (org-export-resolve-radio-link
2625 (org-element-map tree
'link
'identity info t
)
2627 ;; Radio link next to an apostrophe.
2629 (org-test-with-temp-text "<<<radio>>> radio's"
2630 (org-update-radio-target-regexp)
2631 (let* ((tree (org-element-parse-buffer))
2632 (info `(:parse-tree
,tree
)))
2633 (org-export-resolve-radio-link
2634 (org-element-map tree
'link
'identity info t
)
2636 ;; Multiple radio targets.
2638 (equal '("radio1" "radio2")
2639 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2640 (org-update-radio-target-regexp)
2641 (let* ((tree (org-element-parse-buffer))
2642 (info `(:parse-tree
,tree
)))
2643 (org-element-map tree
'link
2645 (org-element-property
2646 :value
(org-export-resolve-radio-link link info
)))
2648 ;; Radio target is whitespace insensitive.
2650 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2651 (org-update-radio-target-regexp)
2652 (let* ((tree (org-element-parse-buffer))
2653 (info `(:parse-tree
,tree
)))
2654 (org-element-map tree
'link
2655 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2659 ;;; Src-block and example-block
2661 (ert-deftest test-org-export
/unravel-code
()
2662 "Test `org-export-unravel-code' function."
2663 ;; Code without reference.
2665 (equal '("(+ 1 1)\n")
2666 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2667 (org-export-unravel-code (org-element-at-point)))))
2668 ;; Code with reference.
2670 (equal '("(+ 1 1)\n" (1 .
"test"))
2671 (org-test-with-temp-text
2672 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2673 (let ((org-coderef-label-format "(ref:%s)"))
2674 (org-export-unravel-code (org-element-at-point))))))
2675 ;; Code with user-defined reference.
2678 '("(+ 1 1)\n" (1 .
"test"))
2679 (org-test-with-temp-text
2680 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2681 (let ((org-coderef-label-format "(ref:%s)"))
2682 (org-export-unravel-code (org-element-at-point))))))
2683 ;; Code references keys are relative to the current block.
2685 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2686 (org-test-with-temp-text "
2695 (let ((org-coderef-label-format "(ref:%s)"))
2696 (org-export-unravel-code (org-element-at-point)))))))
2698 (ert-deftest test-org-export
/format-code-default
()
2699 "Test `org-export-format-code-default' specifications."
2700 ;; Return the empty string when code is empty.
2703 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2704 (org-export-format-code-default
2705 (org-element-map tree
'src-block
'identity info t
) info
))))
2706 ;; Number lines, two whitespace characters before the actual loc.
2709 (org-test-with-parsed-data
2710 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2711 (org-export-format-code-default
2712 (org-element-map tree
'src-block
'identity info t
) info
))))
2713 ;; Put references 6 whitespace characters after the widest line,
2714 ;; wrapped within parenthesis.
2716 (equal "123 (a)\n1 (b)\n"
2717 (let ((org-coderef-label-format "(ref:%s)"))
2718 (org-test-with-parsed-data
2719 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2720 (org-export-format-code-default
2721 (org-element-map tree
'src-block
'identity info t
) info
))))))
2727 (ert-deftest test-org-export
/activate-smart-quotes
()
2728 "Test `org-export-activate-smart-quotes' specifications."
2729 ;; Opening double quotes: standard test.
2732 '("some “paragraph")
2733 (let ((org-export-default-language "en"))
2734 (org-test-with-parsed-data "some \"paragraph"
2735 (org-element-map tree
'plain-text
2736 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2738 ;; Opening quotes: at the beginning of a paragraph.
2742 (let ((org-export-default-language "en"))
2743 (org-test-with-parsed-data "\"begin"
2744 (org-element-map tree
'plain-text
2745 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2747 ;; Opening quotes: after an object.
2751 (let ((org-export-default-language "en"))
2752 (org-test-with-parsed-data "=verb= \"begin"
2753 (org-element-map tree
'plain-text
2754 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2756 ;; Closing quotes: standard test.
2759 '("some” paragraph")
2760 (let ((org-export-default-language "en"))
2761 (org-test-with-parsed-data "some\" paragraph"
2762 (org-element-map tree
'plain-text
2763 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2765 ;; Closing quotes: at the end of a paragraph.
2769 (let ((org-export-default-language "en"))
2770 (org-test-with-parsed-data "end\""
2771 (org-element-map tree
'plain-text
2772 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2774 ;; Apostrophe: standard test.
2777 '("It shouldn’t fail")
2778 (let ((org-export-default-language "en"))
2779 (org-test-with-parsed-data "It shouldn't fail"
2780 (org-element-map tree
'plain-text
2781 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2783 ;; Apostrophe: before an object.
2787 (let ((org-export-default-language "en"))
2788 (org-test-with-parsed-data "a'=b="
2789 (org-element-map tree
'plain-text
2790 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2792 ;; Apostrophe: after an object.
2796 (let ((org-export-default-language "en"))
2797 (org-test-with-parsed-data "=code='s"
2798 (org-element-map tree
'plain-text
2799 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2801 ;; Special case: isolated quotes.
2803 (equal '("“" "”")
2804 (let ((org-export-default-language "en"))
2805 (org-test-with-parsed-data "\"$x$\""
2806 (org-element-map tree
'plain-text
2807 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2809 ;; Smart quotes in secondary strings.
2811 (equal '("“" "”")
2812 (let ((org-export-default-language "en"))
2813 (org-test-with-parsed-data "* \"$x$\""
2814 (org-element-map tree
'plain-text
2815 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2817 ;; Smart quotes in document keywords.
2819 (equal '("“" "”")
2820 (let ((org-export-default-language "en"))
2821 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2822 (org-element-map (plist-get info
:title
) 'plain-text
2823 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2825 ;; Smart quotes in parsed affiliated keywords.
2827 (equal '("“" "”" "Paragraph")
2828 (let ((org-export-default-language "en"))
2829 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2830 (org-element-map tree
'plain-text
2831 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2832 info nil nil t
))))))
2838 (ert-deftest test-org-export
/special-column
()
2839 "Test if the table's special column is properly recognized."
2840 ;; 1. First column is special if it contains only a special marking
2841 ;; characters or empty cells.
2842 (org-test-with-temp-text "
2846 (org-export-table-has-special-column-p
2848 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2849 ;; 2. If the column contains anything else, it isn't special.
2850 (org-test-with-temp-text "
2854 (org-export-table-has-special-column-p
2856 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2857 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2859 (org-test-with-temp-text "
2868 (org-export-table-has-special-column-p
2870 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2871 ;; 4. A first column with only empty cells isn't considered as
2873 (org-test-with-temp-text "
2877 (org-export-table-has-special-column-p
2879 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2881 (ert-deftest test-org-export
/table-row-is-special-p
()
2882 "Test `org-export-table-row-is-special-p' specifications."
2883 ;; 1. A row is special if it has a special marking character in the
2885 (org-test-with-parsed-data "| ! | 1 |"
2887 (org-export-table-row-is-special-p
2888 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2889 ;; 2. A row is special when its first field is "/"
2890 (org-test-with-parsed-data "
2894 (org-export-table-row-is-special-p
2895 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2896 ;; 3. A row only containing alignment cookies is also considered as
2898 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2900 (org-export-table-row-is-special-p
2901 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2902 ;; 4. Everything else isn't considered as special.
2903 (org-test-with-parsed-data "| \alpha | | c |"
2905 (org-export-table-row-is-special-p
2906 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2907 ;; 5. Table's rules are never considered as special rows.
2908 (org-test-with-parsed-data "|---+---|"
2910 (org-export-table-row-is-special-p
2911 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2913 (ert-deftest test-org-export
/has-header-p
()
2914 "Test `org-export-table-has-header-p' specifications."
2915 ;; 1. With an header.
2916 (org-test-with-parsed-data "
2921 (org-export-table-has-header-p
2922 (org-element-map tree
'table
'identity info
'first-match
)
2924 ;; 2. Without an header.
2925 (org-test-with-parsed-data "
2929 (org-export-table-has-header-p
2930 (org-element-map tree
'table
'identity info
'first-match
)
2932 ;; 3. Don't get fooled with starting and ending rules.
2933 (org-test-with-parsed-data "
2939 (org-export-table-has-header-p
2940 (org-element-map tree
'table
'identity info
'first-match
)
2943 (ert-deftest test-org-export
/table-row-group
()
2944 "Test `org-export-table-row-group' specifications."
2945 ;; 1. A rule creates a new group.
2948 (org-test-with-parsed-data "
2952 (org-element-map tree
'table-row
2954 (if (eq (org-element-property :type row
) 'rule
) 'rule
2955 (org-export-table-row-group row info
)))))))
2956 ;; 2. Special rows are ignored in count.
2960 (org-test-with-parsed-data "
2964 (org-element-map tree
'table-row
2966 (if (eq (org-element-property :type row
) 'rule
) 'rule
2967 (org-export-table-row-group row info
)))
2969 ;; 3. Double rules also are ignored in count.
2971 (equal '(1 rule rule
2)
2972 (org-test-with-parsed-data "
2977 (org-element-map tree
'table-row
2979 (if (eq (org-element-property :type row
) 'rule
) 'rule
2980 (org-export-table-row-group row info
))))))))
2982 (ert-deftest test-org-export
/table-row-number
()
2983 "Test `org-export-table-row-number' specifications."
2984 ;; Standard test. Number is 0-indexed.
2987 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2988 (org-element-map tree
'table-row
2989 (lambda (row) (org-export-table-row-number row info
)) info
))))
2990 ;; Number ignores separators.
2993 (org-test-with-parsed-data "
2997 (org-element-map tree
'table-row
2998 (lambda (row) (org-export-table-row-number row info
)) info
))))
2999 ;; Number ignores special rows.
3002 (org-test-with-parsed-data "
3008 (org-element-map tree
'table-row
3009 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3011 (ert-deftest test-org-export
/table-cell-width
()
3012 "Test `org-export-table-cell-width' specifications."
3013 ;; 1. Width is primarily determined by width cookies. If no cookie
3014 ;; is found, cell's width is nil.
3015 (org-test-with-parsed-data "
3016 | / | <l> | <6> | <l7> |
3021 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3022 (org-element-map tree
'table-cell
'identity info
)))))
3023 ;; 2. The last width cookie has precedence.
3024 (org-test-with-parsed-data "
3031 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3032 (org-element-map tree
'table-cell
'identity info
)))))
3033 ;; 3. Valid width cookies must have a specific row.
3034 (org-test-with-parsed-data "| <6> | cell |"
3038 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3039 (org-element-map tree
'table-cell
'identity
))))))
3041 (ert-deftest test-org-export
/table-cell-alignment
()
3042 "Test `org-export-table-cell-alignment' specifications."
3043 ;; 1. Alignment is primarily determined by alignment cookies.
3045 (equal '(left center right
)
3046 (let ((org-table-number-fraction 0.5)
3047 (org-table-number-regexp "^[0-9]+$"))
3048 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3049 (mapcar (lambda (cell)
3050 (org-export-table-cell-alignment cell info
))
3051 (org-element-map tree
'table-cell
'identity
))))))
3052 ;; 2. The last alignment cookie has precedence.
3054 (equal '(right right right
)
3055 (org-test-with-parsed-data "
3059 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3060 (org-element-map tree
'table-cell
'identity
)))))
3061 ;; 3. If there's no cookie, cell's contents determine alignment.
3062 ;; A column mostly made of cells containing numbers will align
3063 ;; its cells to the right.
3065 (equal '(right right right
)
3066 (let ((org-table-number-fraction 0.5)
3067 (org-table-number-regexp "^[0-9]+$"))
3068 (org-test-with-parsed-data "
3072 (mapcar (lambda (cell)
3073 (org-export-table-cell-alignment cell info
))
3074 (org-element-map tree
'table-cell
'identity
))))))
3075 ;; 4. Otherwise, they will be aligned to the left.
3077 (equal '(left left left
)
3078 (org-test-with-parsed-data "
3082 (mapcar (lambda (cell)
3083 (org-export-table-cell-alignment cell info
))
3084 (org-element-map tree
'table-cell
'identity info
))))))
3086 (ert-deftest test-org-export
/table-cell-borders
()
3087 "Test `org-export-table-cell-borders' specifications."
3088 ;; 1. Recognize various column groups indicators.
3089 (org-test-with-parsed-data "| / | < | > | <> |"
3092 '((right bottom top
) (left bottom top
) (right bottom top
)
3093 (right left bottom top
))
3094 (mapcar (lambda (cell)
3095 (org-export-table-cell-borders cell info
))
3096 (org-element-map tree
'table-cell
'identity
)))))
3097 ;; 2. Accept shortcuts to define column groups.
3098 (org-test-with-parsed-data "| / | < | < |"
3101 '((right bottom top
) (right left bottom top
) (left bottom top
))
3102 (mapcar (lambda (cell)
3103 (org-export-table-cell-borders cell info
))
3104 (org-element-map tree
'table-cell
'identity
)))))
3105 ;; 3. A valid column groups row must start with a "/".
3106 (org-test-with-parsed-data "
3110 (equal '((top) (top) (bottom) (bottom))
3111 (mapcar (lambda (cell)
3112 (org-export-table-cell-borders cell info
))
3113 (org-element-map tree
'table-cell
'identity
)))))
3114 ;; 4. Take table rules into consideration.
3115 (org-test-with-parsed-data "
3120 (equal '((below top
) (bottom above
))
3121 (mapcar (lambda (cell)
3122 (org-export-table-cell-borders cell info
))
3123 (org-element-map tree
'table-cell
'identity
)))))
3124 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3125 ;; (resp. `bottom' and `below') borders. Any special row is
3127 (org-test-with-parsed-data "
3133 (equal '((bottom below top above
))
3135 (mapcar (lambda (cell)
3136 (org-export-table-cell-borders cell info
))
3137 (org-element-map tree
'table-cell
'identity
)))))))
3139 (ert-deftest test-org-export
/table-dimensions
()
3140 "Test `org-export-table-dimensions' specifications."
3141 ;; 1. Standard test.
3142 (org-test-with-parsed-data "
3147 (org-export-table-dimensions
3148 (org-element-map tree
'table
'identity info
'first-match
) info
))))
3149 ;; 2. Ignore horizontal rules and special columns.
3150 (org-test-with-parsed-data "
3157 (org-export-table-dimensions
3158 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
3160 (ert-deftest test-org-export
/table-cell-address
()
3161 "Test `org-export-table-cell-address' specifications."
3162 ;; 1. Standard test: index is 0-based.
3163 (org-test-with-parsed-data "| a | b |"
3165 (equal '((0 .
0) (0 .
1))
3166 (org-element-map tree
'table-cell
3167 (lambda (cell) (org-export-table-cell-address cell info
))
3169 ;; 2. Special column isn't counted, nor are special rows.
3170 (org-test-with-parsed-data "
3175 (org-export-table-cell-address
3176 (car (last (org-element-map tree
'table-cell
'identity info
)))
3178 ;; 3. Tables rules do not count either.
3179 (org-test-with-parsed-data "
3187 (org-export-table-cell-address
3188 (car (last (org-element-map tree
'table-cell
'identity info
)))
3190 ;; 4. Return nil for special cells.
3191 (org-test-with-parsed-data "| / | a |"
3193 (org-export-table-cell-address
3194 (org-element-map tree
'table-cell
'identity nil
'first-match
)
3197 (ert-deftest test-org-export
/get-table-cell-at
()
3198 "Test `org-export-get-table-cell-at' specifications."
3199 ;; 1. Address ignores special columns, special rows and rules.
3200 (org-test-with-parsed-data "
3207 (org-element-contents
3208 (org-export-get-table-cell-at
3210 (org-element-map tree
'table
'identity info
'first-match
)
3212 ;; 2. Return value for a non-existent address is nil.
3213 (org-test-with-parsed-data "| a |"
3215 (org-export-get-table-cell-at
3217 (org-element-map tree
'table
'identity info
'first-match
)
3219 (org-test-with-parsed-data "| / |"
3221 (org-export-get-table-cell-at
3223 (org-element-map tree
'table
'identity info
'first-match
)
3226 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
3227 "Test `org-export-table-cell-starts-colgroup-p' specifications."
3228 ;; 1. A cell at a beginning of a row always starts a column group.
3229 (org-test-with-parsed-data "| a |"
3231 (org-export-table-cell-starts-colgroup-p
3232 (org-element-map tree
'table-cell
'identity info
'first-match
)
3234 ;; 2. Special column should be ignored when determining the
3235 ;; beginning of the row.
3236 (org-test-with-parsed-data "
3240 (org-export-table-cell-starts-colgroup-p
3241 (org-element-map tree
'table-cell
'identity info
'first-match
)
3243 ;; 2. Explicit column groups.
3244 (org-test-with-parsed-data "
3250 (org-element-map tree
'table-cell
3252 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
3255 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
3256 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3257 ;; 1. A cell at the end of a row always ends a column group.
3258 (org-test-with-parsed-data "| a |"
3260 (org-export-table-cell-ends-colgroup-p
3261 (org-element-map tree
'table-cell
'identity info
'first-match
)
3263 ;; 2. Special column should be ignored when determining the
3264 ;; beginning of the row.
3265 (org-test-with-parsed-data "
3269 (org-export-table-cell-ends-colgroup-p
3270 (org-element-map tree
'table-cell
'identity info
'first-match
)
3272 ;; 3. Explicit column groups.
3273 (org-test-with-parsed-data "
3279 (org-element-map tree
'table-cell
3281 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
3284 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
3285 "Test `org-export-table-row-starts-rowgroup-p' specifications."
3286 ;; 1. A row at the beginning of a table always starts a row group.
3287 ;; So does a row following a table rule.
3288 (org-test-with-parsed-data "
3295 (org-element-map tree
'table-row
3297 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3299 ;; 2. Special rows should be ignored when determining the beginning
3301 (org-test-with-parsed-data "
3310 (org-element-map tree
'table-row
3312 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3315 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
3316 "Test `org-export-table-row-ends-rowgroup-p' specifications."
3317 ;; 1. A row at the end of a table always ends a row group. So does
3318 ;; a row preceding a table rule.
3319 (org-test-with-parsed-data "
3326 (org-element-map tree
'table-row
3328 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3330 ;; 2. Special rows should be ignored when determining the beginning
3332 (org-test-with-parsed-data "
3341 (org-element-map tree
'table-row
3343 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3346 (ert-deftest test-org-export
/table-row-in-header-p
()
3347 "Test `org-export-table-row-in-header-p' specifications."
3348 ;; Standard test. Separators are always nil.
3352 (org-test-with-parsed-data "| a |\n|---|\n| b |"
3353 (org-element-map tree
'table-row
3355 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
3356 ;; Nil when there is no header.
3360 (org-test-with-parsed-data "| a |\n| b |"
3361 (org-element-map tree
'table-row
3363 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
3365 (ert-deftest test-org-export
/table-row-starts-header-p
()
3366 "Test `org-export-table-row-starts-header-p' specifications."
3367 ;; 1. Only the row starting the first row group starts the table
3369 (org-test-with-parsed-data "
3377 (org-element-map tree
'table-row
3379 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
3381 ;; 2. A row cannot start an header if there's no header in the
3383 (org-test-with-parsed-data "
3387 (org-export-table-row-starts-header-p
3388 (org-element-map tree
'table-row
'identity info
'first-match
)
3391 (ert-deftest test-org-export
/table-row-ends-header-p
()
3392 "Test `org-export-table-row-ends-header-p' specifications."
3393 ;; 1. Only the row starting the first row group starts the table
3395 (org-test-with-parsed-data "
3403 (org-element-map tree
'table-row
3405 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
3407 ;; 2. A row cannot start an header if there's no header in the
3409 (org-test-with-parsed-data "
3413 (org-export-table-row-ends-header-p
3414 (org-element-map tree
'table-row
'identity info
'first-match
)
3419 ;;; Tables of Contents
3421 (ert-deftest test-org-export
/collect-headlines
()
3422 "Test `org-export-collect-headlines' specifications."
3427 (org-test-with-parsed-data "* H1\n** H2"
3428 (org-export-collect-headlines info
)))))
3429 ;; Do not collect headlines below optional argument.
3433 (org-test-with-parsed-data "* H1\n** H2"
3434 (org-export-collect-headlines info
1)))))
3435 ;; Never collect headlines below maximum headline level.
3439 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3440 (org-export-collect-headlines info
)))))
3444 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3445 (org-export-collect-headlines info
2)))))
3446 ;; Collect headlines locally.
3449 (org-test-with-parsed-data "* H1\n** H2\n** H3"
3450 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3451 (length (org-export-collect-headlines info nil scope
))))))
3452 ;; When collecting locally, optional level is relative.
3455 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
3456 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3457 (length (org-export-collect-headlines info
1 scope
)))))))
3463 (ert-deftest test-org-export
/inner-template
()
3464 "Test `inner-template' translator specifications."
3467 (org-test-with-temp-text "* Headline"
3469 (org-export-create-backend
3471 '((inner-template .
(lambda (contents info
) "Success!"))
3472 (headline .
(lambda (h c i
) "Headline"))))))))
3473 ;; Inner template is applied even in a "body-only" export.
3476 (org-test-with-temp-text "* Headline"
3478 (org-export-create-backend
3479 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
3480 (headline .
(lambda (h c i
) "Headline"))))
3481 nil nil
'body-only
)))))
3483 (ert-deftest test-org-export
/template
()
3484 "Test `template' translator specifications."
3487 (org-test-with-temp-text "* Headline"
3489 (org-export-create-backend
3490 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3491 (headline .
(lambda (h c i
) "Headline"))))))))
3492 ;; Template is not applied in a "body-only" export.
3495 (org-test-with-temp-text "* Headline"
3497 (org-export-create-backend
3498 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3499 (headline .
(lambda (h c i
) "Headline"))))
3500 nil nil
'body-only
)))))
3506 (ert-deftest test-org-export
/get-next-element
()
3507 "Test `org-export-get-next-element' specifications."
3511 (org-test-with-parsed-data "* Headline\n*a* b"
3512 (org-export-get-next-element
3513 (org-element-map tree
'bold
'identity info t
) info
))))
3514 ;; Return nil when no previous element.
3516 (org-test-with-parsed-data "* Headline\na *b*"
3517 (org-export-get-next-element
3518 (org-element-map tree
'bold
'identity info t
) info
)))
3519 ;; Non-exportable elements are ignored.
3521 (let ((org-export-with-timestamps nil
))
3522 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3523 (org-export-get-next-element
3524 (org-element-map tree
'entity
'identity info t
) info
))))
3525 ;; Find next element in secondary strings.
3528 (org-test-with-parsed-data "* a =verb="
3530 (org-export-get-next-element
3531 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3534 (org-test-with-parsed-data "* /italic/ =verb="
3536 (org-export-get-next-element
3537 (org-element-map tree
'italic
'identity info t
) info
)))))
3538 ;; Find next element in document keywords.
3541 (org-test-with-parsed-data "#+TITLE: a =verb="
3543 (org-export-get-next-element
3545 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3546 ;; Find next element in parsed affiliated keywords.
3549 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3551 (org-export-get-next-element
3552 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3553 ;; With optional argument N, return a list containing all the
3554 ;; following elements.
3557 '(bold code underline
)
3558 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3560 (org-export-get-next-element
3561 (org-element-map tree
'italic
'identity info t
) info t
)))))
3562 ;; When N is a positive integer, return a list containing up to
3563 ;; N following elements.
3567 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3569 (org-export-get-next-element
3570 (org-element-map tree
'italic
'identity info t
) info
2))))))
3572 (ert-deftest test-org-export
/get-previous-element
()
3573 "Test `org-export-get-previous-element' specifications."
3577 (org-test-with-parsed-data "* Headline\na *b*"
3578 (org-export-get-previous-element
3579 (org-element-map tree
'bold
'identity info t
) info
))))
3580 ;; Return nil when no previous element.
3582 (org-test-with-parsed-data "* Headline\n*a* b"
3583 (org-export-get-previous-element
3584 (org-element-map tree
'bold
'identity info t
) info
)))
3585 ;; Non-exportable elements are ignored.
3587 (let ((org-export-with-timestamps nil
))
3588 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3589 (org-export-get-previous-element
3590 (org-element-map tree
'entity
'identity info t
) info
))))
3591 ;; Find previous element in secondary strings.
3594 (org-test-with-parsed-data "* =verb= a"
3596 (org-export-get-previous-element
3597 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3600 (org-test-with-parsed-data "* =verb= /italic/"
3602 (org-export-get-previous-element
3603 (org-element-map tree
'italic
'identity info t
) info
)))))
3604 ;; Find previous element in document keywords.
3607 (org-test-with-parsed-data "#+TITLE: =verb= a"
3609 (org-export-get-previous-element
3611 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3612 ;; Find previous element in parsed affiliated keywords.
3615 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3617 (org-export-get-previous-element
3618 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3619 ;; With optional argument N, return a list containing up to
3620 ;; N previous elements.
3622 (equal '(underline italic bold
)
3623 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3625 (org-export-get-previous-element
3626 (org-element-map tree
'code
'identity info t
) info t
)))))
3627 ;; When N is a positive integer, return a list containing up to
3628 ;; N previous elements.
3630 (equal '(italic bold
)
3631 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3633 (org-export-get-previous-element
3634 (org-element-map tree
'code
'identity info t
) info
2))))))
3638 ;;; test-org-export.el end here