From 0c0be9429f756acc7d9c0dc66b4456b29900e5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 5 Mar 2026 09:46:10 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Update=20script=20to=20autofix?= =?UTF-8?q?=20permalinks=20to=20account=20for=20headers=20with=20Markdown?= =?UTF-8?q?=20links=20(#15062)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/docs.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/docs.py b/scripts/docs.py index 23d74aaf4a..39845144b9 100644 --- a/scripts/docs.py +++ b/scripts/docs.py @@ -66,6 +66,15 @@ code_block3_pattern = re.compile(r"^\s*```") code_block4_pattern = re.compile(r"^\s*````") +# Pattern to match markdown links: [text](url) → text +md_link_pattern = re.compile(r"\[([^\]]+)\]\([^)]+\)") + + +def strip_markdown_links(text: str) -> str: + """Replace markdown links with just their visible text.""" + return md_link_pattern.sub(r"\1", text) + + class VisibleTextExtractor(HTMLParser): """Extract visible text from a string with HTML tags.""" @@ -688,7 +697,11 @@ def add_permalinks_page(path: Path, update_existing: bool = False): if match: hashes, title, _permalink = match.groups() if (not _permalink) or update_existing: - slug = slugify(visible_text_extractor.extract_visible_text(title)) + slug = slugify( + visible_text_extractor.extract_visible_text( + strip_markdown_links(title) + ) + ) if slug in permalinks: # If the slug is already used, append a number to make it unique count = 1