branch: externals/org
commit b42867b5a13753888fca946f16f2f90c9e0d45c2
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    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 <michel.dami...@gmail.com>
    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 0471a573b5..1db65de480 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 "<div id=\"text-table-of-contents\" role=\"doc-toc\">"
-                        (org-html--toc-text toc-entries)
-                        "</div>\n")))
+      (let* ((toc-id-counter (plist-get info :org-html--toc-counter))
+             (toc (concat (format "<div id=\"text-table-of-contents%s\" 
role=\"doc-toc\">"
+                                  (if toc-id-counter (format "-%d" 
toc-id-counter) ""))
+                         (org-html--toc-text toc-entries)
+                         "</div>\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 "<h%d>%s</h%d>\n"
                              top-level

Reply via email to