mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-19 16:17:49 -06:00
fix: strip links with bracketed text from meta
This commit is contained in:
1 parent
9930f46f03
commit
6846bb4e48
2 files changed
+17
-2
No files matched your search
@@ -2485,10 +2485,16 @@ def _browser_title(relative: Path, title: str) -> str:
|
|||||||
return title
|
return title
|
||||||
|
|
||||||
|
|
||||||
|
_LINK_TEXT = r"(?:`[^`]*`|\[[^\]\[]*\]|[^\]\[])"
|
||||||
|
|
||||||
|
|
||||||
def _plain_markdown(text: str) -> str:
|
def _plain_markdown(text: str) -> str:
|
||||||
text = re.sub(r"<[^>]+>", " ", text)
|
text = re.sub(r"<[^>]+>", " ", text)
|
||||||
text = re.sub(r"!\[([^]]*)\]\([^)]*\)", r"\1", text)
|
# Link text may hold brackets: a code span or a No-Intro name such as
|
||||||
text = re.sub(r"\[([^]]+)\]\([^)]*\)", r"\1", text)
|
# `[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
|
# Code spans keep their text whole: validate_schemas.py read
|
||||||
# validateschemas.py once every underscore was taken for emphasis.
|
# validateschemas.py once every underscore was taken for emphasis.
|
||||||
pieces = re.split(r"(`[^`]*`)", text)
|
pieces = re.split(r"(`[^`]*`)", text)
|
||||||
|
|||||||
@@ -148,6 +148,15 @@ class WhatASearchSnippetSays(unittest.TestCase):
|
|||||||
self.assertTrue(plain.startswith(text[:-3]))
|
self.assertTrue(plain.startswith(text[:-3]))
|
||||||
self.assertIn(plain[len(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):
|
def test_code_keeps_its_underscores(self):
|
||||||
self.assertEqual(gs._plain_markdown("only `validate_schemas.py` and _this_"),
|
self.assertEqual(gs._plain_markdown("only `validate_schemas.py` and _this_"),
|
||||||
"only validate_schemas.py and this")
|
"only validate_schemas.py and this")
|
||||||
|
|||||||
Reference in new issue
Block a user