branch: externals/org
commit 58a07087c61933550ab083947130c14fb41ecf65
Author: Rudolf Adamkovič <rud...@adamkovic.org>
Commit: Ihor Radchenko <yanta...@posteo.net>

    ox-texinfo: Sanitize links in headings to avoid broken Texinfo menus
    
    * lisp/ox-texinfo.el (org-texinfo-headline): Sanitize links in the
    titles of heading exported as chapters, sections, and the like, as
    they break Texinfo menus.
    (org-texinfo--build-menu): Sanitize TOC headings and rename `h' to
    `headline' to harmonize with `ox-html'.
    * testing/lisp/test-ox-texinfo.el
    (test-ox-texinfo/headings-with-links): Update the relevant test.
---
 lisp/ox-texinfo.el              | 18 ++++++++++++------
 testing/lisp/test-ox-texinfo.el | 40 +++++++++++++++++++++++++++-------------
 2 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index 639d68443a..866f1feafb 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -1132,8 +1132,11 @@ holding contextual information."
                      (org-export-get-tags headline info)))
           (priority (and (plist-get info :with-priority)
                          (org-element-property :priority headline)))
-          (text (org-texinfo--sanitize-title
-                 (org-element-property :title headline) info))
+          (text (funcall (if command
+                              #'org-texinfo--sanitize-title-reference
+                            #'org-texinfo--sanitize-title)
+                          (org-element-property :title headline)
+                          info))
           (full-text
            (funcall (plist-get info :texinfo-format-headline-function)
                     todo todo-type priority text tags))
@@ -1482,14 +1485,17 @@ is an integer, build the menu recursively, down to this 
depth."
    ((zerop level) "\n")
    (t
     (mapconcat
-     (lambda (h)
-       (let ((entries (org-texinfo--menu-entries h info)))
+     (lambda (headline)
+       (let ((entries (org-texinfo--menu-entries headline info)))
         (when entries
           (concat
            (format "%s\n\n%s\n"
-                   (org-export-data (org-export-get-alt-title h info) info)
+                   (org-export-data-with-backend
+                     (org-export-get-alt-title headline info)
+                     (org-export-toc-entry-backend 'texinfo)
+                     info)
                    (org-texinfo--format-entries entries info))
-           (org-texinfo--build-menu h info (1- level))))))
+           (org-texinfo--build-menu headline info (1- level))))))
      (org-texinfo--menu-entries scope info)
      ""))))
 
diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo.el
index 77605dccd0..df176fbc2b 100644
--- a/testing/lisp/test-ox-texinfo.el
+++ b/testing/lisp/test-ox-texinfo.el
@@ -428,14 +428,18 @@ body
 ;;; Headings with links
 
 (ert-deftest test-ox-texinfo/headings-with-links ()
-  "Test node and chapter names."
+  "Test links are removed from headings conditionally.
+
+Headings exported as chapters, sections, and subsections must not
+contain links in their titles, for such links break Texinfo menus.
+Headings exported as list items have no such problem."
   (should
    (org-test-with-temp-text
        (string-join
-        (list "* Heading 1"
-              "  ...."
-              "* Heading 2 ([[* Heading 1][Heading 1]])"
-              "  ....")
+        (list "* Chapter [[https://example.com][Example]]";
+              "** Section [[https://example.com][Example]]";
+              "*** Subsection [[https://example.com][Example]]";
+              "**** Item [[https://example.com][Example]]";)
         "\n")
      (let ((export-buffer "*Test Texinfo Export*")
            (org-export-show-temporary-export-buffer nil))
@@ -445,14 +449,24 @@ body
        (with-current-buffer export-buffer
          (goto-char (point-min))
          (and
-          (re-search-forward "^* Heading 1::$")
-          (re-search-forward "^* Heading 2 (Heading 1)::$")
-          (re-search-forward "^@node Heading 1$")
-          (re-search-forward "^@chapter Heading 1$")
-          (re-search-forward "^@node Heading 2 (Heading 1)$")
-          (re-search-forward
-           "^@chapter Heading 2 (@ref{Heading 1, , Heading 1})$")))))))
-
+          (re-search-forward "^@menu$")
+          (re-search-forward "^\\* Chapter Example::$")
+          (re-search-forward "^Chapter Example$")
+          (re-search-forward "^\\* Section Example::$")
+          (re-search-forward "^Section Example$")
+          (re-search-forward "^\\* Subsection Example::$")
+          (re-search-forward "^@node Chapter Example$")
+          (re-search-forward "^@chapter Chapter Example$")
+          (re-search-forward "^@menu$")
+          (re-search-forward "^\\* Section Example::$")
+          (re-search-forward "^@node Section Example$")
+          (re-search-forward "^@section Section Example$")
+          (re-search-forward "^@menu$")
+          (re-search-forward "^\\* Subsection Example::$")
+          (re-search-forward "^@node Subsection Example$")
+          (re-search-forward "^@subsection Subsection Example$")
+          (re-search-forward "^@item$")
+          (re-search-forward "^@anchor{Item Example}Item 
@uref{https://example.com, Example}$")))))))
 
 
 ;;; Definitions

Reply via email to