Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

documentation: Remove duplicate heading IDs on server side.

Anders Kaseorg328cdde24331
diff --git a/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py b/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py
index 40834256da7..1ad9bb99871 100644
--- a/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py
+++ b/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py
@@ -40,8 +40,6 @@ EXCLUDED_URLS = [
VNU_IGNORE = [
# Real errors that should be fixed.
- r"Duplicate ID “[^”]*”\.",
- r"The first occurrence of ID “[^”]*” was here\.",
r"Attribute “markdown” not allowed on element “div” at this point\.",
r"No “p” element in scope but a “p” end tag seen\.",
(
diff --git a/web/src/portico/help.js b/web/src/portico/help.js
index e8b2ea78635..71635f2d4d5 100644
--- a/web/src/portico/help.js
+++ b/web/src/portico/help.js
@@ -97,9 +97,6 @@ function render_code_sections() {
new SimpleBar($(".markdown")[0]);
new SimpleBar($(".sidebar")[0]);
-// Remove ID attributes from sidebar links so they don't conflict with index page anchor links
-$(".help .sidebar h1, .help .sidebar h2, .help .sidebar h3").removeAttr("id");
-
// Scroll to anchor link when clicked. Note that landing-page.js has a
// similar function; this file and landing-page.js are never included
// on the same page.
diff --git a/zerver/views/documentation.py b/zerver/views/documentation.py
index 6f707f4dfb4..39c4fe4696d 100644
--- a/zerver/views/documentation.py
+++ b/zerver/views/documentation.py
@@ -68,6 +68,7 @@ class ApiURLView(TemplateView):
return context
+sidebar_headings = XPath("//*[self::h1 or self::h2 or self::h3 or self::h4]")
sidebar_links = XPath("//a[@href=$url]")
@@ -239,6 +240,12 @@ class MarkdownDirectoryView(ApiURLView):
home_link.text = context["doc_root_title"] + " home"
tree.insert(0, home_h1)
url = context["doc_root"] + article
+ # Remove ID attributes from sidebar headings so they don't conflict with index page headings
+ headings = sidebar_headings(tree)
+ assert isinstance(headings, list)
+ for h in headings:
+ assert isinstance(h, _Element)
+ h.attrib.pop("id", "")
# Highlight current article link
links = sidebar_links(tree, url=url)
assert isinstance(links, list)