documentation: Remove duplicate heading IDs on server side.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-08-21 14:55:47 -07:00 committed by Tim Abbott
parent 832d4f97fd
commit 328cdde243
3 changed files with 7 additions and 5 deletions

View File

@ -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\.",
(

View File

@ -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.

View File

@ -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)