diff --git a/graphify/extractors/markdown.py b/graphify/extractors/markdown.py index d6d45ac8f..e3c19a797 100644 --- a/graphify/extractors/markdown.py +++ b/graphify/extractors/markdown.py @@ -133,7 +133,7 @@ def add_link(raw: str, line: int) -> None: # Skip over fenced code blocks so their contents are not parsed as # headings, but do not emit nodes/edges for them (#1077). stripped = line_text.strip() - if stripped.startswith("```"): + if stripped.startswith(("```", "~~~")): in_code_block = not in_code_block continue diff --git a/tests/test_languages.py b/tests/test_languages.py index f36ea7603..a3816c1db 100644 --- a/tests/test_languages.py +++ b/tests/test_languages.py @@ -2239,6 +2239,22 @@ def test_markdown_fenced_heading_not_parsed(): assert not any("Not A Heading" in l for l in labels), \ f"fenced '## Not A Heading' was incorrectly parsed as a node: {labels}" + +def test_markdown_tilde_fenced_heading_not_parsed(tmp_path): + path = tmp_path / "tilde-fenced-heading.md" + path.write_text( + "# Real Heading\n\n" + "~~~python\n" + "# Not A Heading\n" + "~~~\n" + ) + + r = extract_markdown(path) + labels = _labels(r) + + assert any("Real Heading" in label for label in labels) + assert not any("Not A Heading" in label for label in labels) + def test_markdown_no_dangling_edges(): r = extract_markdown(FIXTURES / "deploy_guide.md") node_ids = {n["id"] for n in r["nodes"]} @@ -2290,6 +2306,21 @@ def test_markdown_link_skips_external_and_images(tmp_path): assert "logo" not in e["target"] +def test_markdown_tilde_fenced_link_not_parsed(tmp_path): + path = tmp_path / "tilde-fenced-link.md" + path.write_text( + "# Real Heading\n\n" + "~~~markdown\n" + "[Not A Reference](./hidden.md)\n" + "~~~\n" + ) + + r = extract_markdown(path) + refs = [e for e in r["edges"] if e["relation"] == "references"] + + assert not refs + + def test_markdown_link_edges_resolve_to_real_nodes(tmp_path): """End-to-end: after extract()'s ID remap, link targets are real doc nodes, so the hub doc gains edges into existing nodes instead of ghost nodes (#1376)."""