diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-11-05 12:22:18 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-11-05 12:22:18 +0100 |
commit | 8d43a0c49f54a76b9a0cb1d1d2afee8a1cf4f82b (patch) | |
tree | 5fa3ac85bbe5a6a86723c1eda8cfaf1b60ab8420 | |
parent | 04f35fc473a8bec330c8f8cafd98564783193d9a (diff) | |
download | org-mode-8d43a0c49f54a76b9a0cb1d1d2afee8a1cf4f82b.tar.gz |
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)".
-rw-r--r-- | lisp/ox-texinfo.el | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index 66d3fc9..9b27349 100644 --- a/lisp/ox-texinfo.el +++ b/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))))) |