From b42867b5a13753888fca946f16f2f90c9e0d45c2 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sun, 14 Apr 2024 13:33:07 +0300 Subject: [PATCH] org-html-toc: Fix duplicate ids when there are multiples TOCs * lisp/ox-html.el (org-html-toc): When multiple TOCs are generated inside the exported document, make sure that they do not have duplicate IDs. Reported-by: Michel Damiens Link: https://orgmode.org/list/87sfj6av4t.fsf@localhost --- lisp/ox-html.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 0471a573b..1db65de48 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2462,14 +2462,19 @@ of contents as a string, or nil if it is empty." (org-export-get-relative-level headline info))) (org-export-collect-headlines info depth scope)))) (when toc-entries - (let ((toc (concat "
" - (org-html--toc-text toc-entries) - "
\n"))) + (let* ((toc-id-counter (plist-get info :org-html--toc-counter)) + (toc (concat (format "
" + (if toc-id-counter (format "-%d" toc-id-counter) "")) + (org-html--toc-text toc-entries) + "
\n"))) + (plist-put info :org-html--toc-counter (1+ (or toc-id-counter 0))) (if scope toc (let ((outer-tag (if (org-html--html5-fancy-p info) "nav" "div"))) - (concat (format "<%s id=\"table-of-contents\" role=\"doc-toc\">\n" outer-tag) + (concat (format "<%s id=\"table-of-contents%s\" role=\"doc-toc\">\n" + outer-tag + (if toc-id-counter (format "-%d" toc-id-counter) "")) (let ((top-level (plist-get info :html-toplevel-hlevel))) (format "%s\n" top-level