From 328cdde24331b82baa4c9b1bf1cb7b2015799826 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 21 Aug 2023 14:55:47 -0700 Subject: [PATCH] documentation: Remove duplicate heading IDs on server side. Signed-off-by: Anders Kaseorg --- .../documentation_crawler/spiders/common/spiders.py | 2 -- web/src/portico/help.js | 3 --- zerver/views/documentation.py | 7 +++++++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py b/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py index 40834256da..1ad9bb9987 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 e8b2ea7863..71635f2d4d 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 6f707f4dfb..39c4fe4696 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)