diff --git a/sphinx_comments/__init__.py b/sphinx_comments/__init__.py index 9faeff1..42a774b 100644 --- a/sphinx_comments/__init__.py +++ b/sphinx_comments/__init__.py @@ -77,8 +77,8 @@ def activate_comments(app, config): script.setAttribute("label", "{label}"); script.setAttribute("crossorigin", "{crossorigin}"); - sections = document.querySelectorAll("div.section"); - if (sections !== null) {{ + sections = document.querySelectorAll("div.section,section"); + if (sections !== null && sections.length > 0) {{ section = sections[sections.length-1]; section.appendChild(script); }} diff --git a/tests/test_comments/utterances.html b/tests/test_comments/utterances.html index af5ae70..1ab7e05 100644 --- a/tests/test_comments/utterances.html +++ b/tests/test_comments/utterances.html @@ -23,8 +23,8 @@ script.setAttribute("label", "💬 comment"); script.setAttribute("crossorigin", "anonymous"); - sections = document.querySelectorAll("div.section"); - if (sections !== null) { + sections = document.querySelectorAll("div.section,section"); + if (sections !== null && sections.length > 0) { section = sections[sections.length-1]; section.appendChild(script); }