lisp/ox-texinfo.el: Fix @menu in headlines without contents

* lisp/ox-texinfo.el (org-texinfo--normalize-headlines): Do not rely
upon undocumented implementation side-effects in `org-element-create'
that have been changed.

*
testing/lisp/test-ox-texinfo.el (test-ox-texinfo/normalize-headlines):
New test.

Reported-by: Jonas Bernoulli <jonas@bernoul.li>
Link: https://orgmode.org/list/87zfybnqwf.fsf@bernoul.li
This commit is contained in:
Ihor Radchenko 2023-12-16 15:00:42 +01:00
parent 8fd21d04ce
commit d2ce1c6ec1
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 24 additions and 1 deletions

View File

@ -503,7 +503,9 @@ Return new tree."
(let ((first (org-element-map contents '(headline section)
#'identity info t)))
(unless (org-element-type-p first 'section)
(org-element-create 'section nil contents))))))
(apply #'org-element-set-contents
hl
(org-element-create 'section `(:parent ,hl)) contents))))))
info)
tree)

View File

@ -324,5 +324,26 @@
nil nil nil nil nil
#'texinfo-mode)))))
;;; Filters
(ert-deftest test-ox-texinfo/normalize-headlines ()
"Test adding empty sections to headlines without one."
(org-test-with-temp-text
"* only subsections, no direct content
** sub 1
body
** sub 2
body
"
(let ((tree (org-element-parse-buffer)))
(setq tree (org-texinfo--normalize-headlines tree nil nil))
(let* ((first-heading (car (org-element-contents tree)))
(section (car (org-element-contents first-heading))))
(should (org-element-type-p first-heading 'headline))
(should (org-element-type-p section 'section))
(should-not (org-element-contents section))
(should (eq first-heading (org-element-parent section)))))))
(provide 'test-ox-texinfo)
;;; test-ox-texinfo.el end here