This commit is contained in:
Divya 2026-11-17 15:00:40 +08:00 • committed by GitHub
commit a8bb87ad70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -46,6 +46,7 @@ PICK_ALIASES = {
"Beautiful Soup": "beautifulsoup4",
"Cacheops": "django-cacheops",
"Chroma": "chromadb",
"Colour": "colour-science",
"Coverage.py": "coverage",
"Django AI Skills": "django-ai-plugins",
"Django ORM": "django.db.models",
@ -340,8 +341,12 @@ def link_intro_picks(text: str, entry_names: Sequence[str]) -> str:
for i, line in enumerate(lines):
if not line.startswith("- "):
break
situation, _, pick = line.rpartition(": ")
lines[i] = f"{situation}: {link_pick_names(pick, slugs_by_key)}"
# A line can pair several situations with their picks: "- Physical units: Pint; astronomy: Astropy"
segments = []
for segment in line.split("; "):
situation, sep, pick = segment.rpartition(": ")
segments.append(f"{situation}{sep}{link_pick_names(pick, slugs_by_key)}" if sep else segment)
lines[i] = "; ".join(segments)
return head + marker + "\n".join(lines)

View file

@ -1645,3 +1645,16 @@ class TestLoadCategoryIntro:
path.write_text("Use w1.\n\nHow to choose:\n\n- Vision: OpenCV\n", encoding="utf-8")
intro_html, _, _, _ = load_category_intro(path, ["opencv-python"])
assert '<li>Vision: <a href="#entry-opencv-python">OpenCV</a></li>' in intro_html
def test_links_every_pick_on_a_line_pairing_several_situations(self, tmp_path):
path = tmp_path / "widgets.md"
path.write_text("Use w1.\n\nHow to choose:\n\n- Physical units: Pint; astronomy: Astropy; seismology: ObsPy\n- Colour science: Colour; math animations: Manim\n", encoding="utf-8")
intro_html, _, _, _ = load_category_intro(path, ["pint", "astropy", "obspy", "colour-science", "manim"])
assert '<li>Physical units: <a href="#entry-pint">Pint</a>; astronomy: <a href="#entry-astropy">Astropy</a>; seismology: <a href="#entry-obspy">ObsPy</a></li>' in intro_html
assert '<li>Colour science: <a href="#entry-colour-science">Colour</a>; math animations: <a href="#entry-manim">Manim</a></li>' in intro_html
def test_leaves_a_pick_line_without_a_situation_unchanged(self, tmp_path):
path = tmp_path / "widgets.md"
path.write_text("Use w1.\n\nHow to choose:\n\n- Django for everything\n", encoding="utf-8")
intro_html, _, _, _ = load_category_intro(path, ["Django"])
assert "<li>Django for everything</li>" in intro_html