ox-html: Fix links to targets that do not have a number

* lisp/ox.el (org-export-get-ordinal): Return nil when ELEMENT does
not match PREDICATE.  `ox-html-link' expects this behavior when a link
refers to target that does not have a caption.
* testing/lisp/test-ox.el (test-org-export/get-ordinal): Fix tests.

Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/7bf1f79071a714750634e76130fe5963@posteo.net
This commit is contained in:
Ihor Radchenko 2024-01-25 13:28:14 +01:00
parent d2986be076
commit ea529007d7
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 6 additions and 3 deletions

View File

@ -4795,7 +4795,10 @@ objects of the same type."
(lambda (el)
(let ((cached (org-element-property :org-export--counter el)))
(cond
((eq element el) (1+ counter))
((and (eq element el)
(or (not predicate)
(funcall predicate el info)))
(1+ counter))
;; Use cached result.
((and cached
(equal predicate (car cached))

View File

@ -445,12 +445,12 @@ Paragraph"
(should (= 1 (org-export-get-ordinal table info)))
(should (= 2 (org-export-get-ordinal table info '(section))))
(should (= 1 (org-export-get-ordinal table info nil #'org-ascii--has-caption-p)))
(should (= 1 (org-export-get-ordinal table info nil from-third))))
(should-not (org-export-get-ordinal table info nil from-third)))
("Should be Table 2"
(should (= 2 (org-export-get-ordinal table info)))
(should (= 3 (org-export-get-ordinal table info '(section))))
(should (= 2 (org-export-get-ordinal table info nil #'org-ascii--has-caption-p)))
(should (= 1 (org-export-get-ordinal table info nil from-third))))
(should-not (org-export-get-ordinal table info nil from-third)))
("Should be Table 3"
(should (= 3 (org-export-get-ordinal table info)))
(should (= 4 (org-export-get-ordinal table info '(section))))