Browse Source

ox-texinfo: Gracefully handle node collision in the same hierarchy

* lisp/ox-texinfo.el (org-texinfo--get-node): Ensure the upper element
  get the shorter node.

Considering the following document:

* Headline
** Headline

the level 1 headlines get "Headline" node and the other one
"Headline (1)".
Nicolas Goaziou 7 năm trước cách đây
mục cha
commit
8d43a0c49f
1 tập tin đã thay đổi với 11 bổ sung0 xóa
  1. 11 0
      lisp/ox-texinfo.el

+ 11 - 0
lisp/ox-texinfo.el

@@ -486,6 +486,17 @@ node or anchor name is unique."
 		   (type
 		    (error "Cannot generate node name for type: %S" type)))))
 	       (name basename))
+	  ;; Org exports deeper elements before their parents.  If two
+	  ;; node names collide -- e.g., they have the same title --
+	  ;; within the same hierarchy, the second one would get the
+	  ;; shorter node name.  This is counter-intuitive.
+	  ;; Consequently, we ensure that every parent headline get
+	  ;; its node beforehand. As a recursive operation, this
+	  ;; achieves the desired effect.
+	  (let ((parent (org-element-lineage datum '(headline))))
+	    (when (and parent (not (assq parent cache)))
+	      (org-texinfo--get-node parent info)
+	      (setq cache (plist-get info :texinfo-node-cache))))
 	  ;; Ensure NAME is unique and not reserved node name "Top".
 	  (while (or (equal name "Top") (rassoc name cache))
 	    (setq name (concat basename (format " (%d)" (cl-incf salt)))))