From 6846bb4e48a8b165be1e22b641a415c096eb36c2 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:03:00 +0100 Subject: [PATCH] fix: strip links with bracketed text from meta --- scripts/generate_site.py | 10 ++++++++-- tests/test_site_emulator_page.py | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/generate_site.py b/scripts/generate_site.py index 22ac647b6..9f2c3ee95 100644 --- a/scripts/generate_site.py +++ b/scripts/generate_site.py @@ -2485,10 +2485,16 @@ def _browser_title(relative: Path, title: str) -> str: return title +_LINK_TEXT = r"(?:`[^`]*`|\[[^\]\[]*\]|[^\]\[])" + + def _plain_markdown(text: str) -> str: text = re.sub(r"<[^>]+>", " ", text) - text = re.sub(r"!\[([^]]*)\]\([^)]*\)", r"\1", text) - text = re.sub(r"\[([^]]+)\]\([^)]*\)", r"\1", text) + # Link text may hold brackets: a code span or a No-Intro name such as + # `[BIOS] LaserActive PAC-N1 (Japan) (v1.02).bin` left the whole link, + # anchor included, in the Pioneer page's meta description. + text = re.sub(rf"!\[({_LINK_TEXT}*)\]\([^)]*\)", r"\1", text) + text = re.sub(rf"\[({_LINK_TEXT}+)\]\([^)]*\)", r"\1", text) # Code spans keep their text whole: validate_schemas.py read # validateschemas.py once every underscore was taken for emphasis. pieces = re.split(r"(`[^`]*`)", text) diff --git a/tests/test_site_emulator_page.py b/tests/test_site_emulator_page.py index be1165ee1..0973ed36c 100644 --- a/tests/test_site_emulator_page.py +++ b/tests/test_site_emulator_page.py @@ -148,6 +148,15 @@ class WhatASearchSnippetSays(unittest.TestCase): self.assertTrue(plain.startswith(text[:-3])) self.assertIn(plain[len(text) - 3], " ,:") + def test_a_link_whose_text_holds_brackets_keeps_its_text_only(self): + """The Pioneer meta description published the whole link, anchor + included: the text `[BIOS] ...bin` stopped the pattern at its "]".""" + self.assertEqual( + gs._plain_markdown("**Start with** [`[BIOS] LaserActive PAC-N1 (Japan) (v1.02).bin`]" + "(#sha1-6973e2593e66). ares reads it."), + "Start with [BIOS] LaserActive PAC-N1 (Japan) (v1.02).bin. ares reads it.") + self.assertEqual(gs._plain_markdown("[a [b] c](x) and [d](y)"), "a [b] c and d") + def test_code_keeps_its_underscores(self): self.assertEqual(gs._plain_markdown("only `validate_schemas.py` and _this_"), "only validate_schemas.py and this")