Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graphify/extractors/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 31 additions & 0 deletions tests/test_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand Down Expand Up @@ -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)."""
Expand Down