mirror of
https://github.com/vinta/awesome-python.git
synced 2026-11-08 02:15:12 -06:00
feat: keep only the lead above the table for an intro without a pick list
An intro without a "How to choose" list, as a one-project category has no picks to compare, rendered all of its guide paragraphs above the table, pushing the table down. It now shows the lead above the table and moves the rest into the guide. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+3
-2
@@ -351,7 +351,8 @@ def load_category_intro(path: Path, entry_names: Sequence[str] = ()) -> tuple[st
|
||||
|
||||
Returns the part shown above the table, the guide shown below it, and the
|
||||
first paragraph as plain text for the meta description and as HTML for
|
||||
group pages. A file without the list keeps everything above the table.
|
||||
group pages. A file without the list, like a one-project category's,
|
||||
keeps only its lead above the table.
|
||||
Returns empty strings if the category has no intro file.
|
||||
"""
|
||||
if not path.exists():
|
||||
@@ -364,7 +365,7 @@ def load_category_intro(path: Path, entry_names: Sequence[str] = ()) -> tuple[st
|
||||
child.attrSet("target", "_blank")
|
||||
child.attrSet("rel", "noopener")
|
||||
lead = next(node for node in SyntaxTreeNode(tokens).children if node.type == "paragraph")
|
||||
split_at = len(tokens)
|
||||
split_at = next(j for j, token in enumerate(tokens) if token.type == "paragraph_close" and token.level == 0) + 1
|
||||
for i, token in enumerate(tokens):
|
||||
if token.type == "inline" and token.level == 1 and token.content == "How to choose:" and i + 2 < len(tokens) and tokens[i + 2].type == "bullet_list_open":
|
||||
split_at = next(j for j in range(i + 3, len(tokens)) if tokens[j].type == "bullet_list_close" and tokens[j].level == 0) + 1
|
||||
|
||||
@@ -1673,12 +1673,12 @@ class TestLoadCategoryIntro:
|
||||
assert lead == "Use w1 for most apps."
|
||||
assert lead_html == "<p>Use <code>w1</code> for most apps.</p>\n"
|
||||
|
||||
def test_keeps_everything_above_table_without_how_to_choose_list(self, tmp_path):
|
||||
def test_splits_after_lead_without_how_to_choose_list(self, tmp_path):
|
||||
path = tmp_path / "widgets.md"
|
||||
path.write_text("Use w1.\n\n- Small apps: w1\n\nConfigure w1 once.\n", encoding="utf-8")
|
||||
intro_html, guide_html, _, _ = load_category_intro(path)
|
||||
assert "Configure w1 once." in intro_html
|
||||
assert guide_html == ""
|
||||
assert intro_html == "<p>Use w1.</p>\n"
|
||||
assert guide_html == "<ul>\n<li>Small apps: w1</li>\n</ul>\n<p>Configure w1 once.</p>\n"
|
||||
|
||||
def test_returns_empty_strings_without_intro_file(self, tmp_path):
|
||||
assert load_category_intro(tmp_path / "missing.md") == ("", "", "", "")
|
||||
|
||||
Reference in New Issue
Block a user