fix(markdown): parse escaped wikilink aliases

This commit is contained in:
Peter Pshenichny committed 2026-09-23 02:06:45 +02:00
1 parent a5957aa6ef
commit f50f96f3c8
2 files changed
+13 -1

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@ _MD_INLINE_LINK_RE = re.compile(r'(?<!\!)\[[^\]]*\]\(\s*<?([^)\s>]+)>?(?:\s+[^)]
_MD_REF_DEF_RE = re.compile(r'^\s{0,3}\[[^\]]+\]:\s*<?([^\s>]+)>?')
_MD_WIKILINK_RE = re.compile(r'(?<!\!)\[\[([^\]|#]+)(?:[#|][^\]]*)?\]\]')
_MD_WIKILINK_RE = re.compile(r'(?<!\!)\[\[([^\]|#]+?)(?:\\?\|[^\]]*|#[^\]]*)?\]\]')
_MD_LINKABLE_EXTS = {".md", ".mdx", ".qmd", ".markdown", ".rst", ".txt"}
+12
View File
@@ -3037,6 +3037,18 @@ def test_markdown_wikilink_vault_fallback(tmp_path):
assert e["target"] in node_ids, f"link target is a ghost node: {e}"
@pytest.mark.parametrize("separator", ["|", "\\|"])
def test_markdown_wikilink_alias_separator(tmp_path, separator):
r"""Obsidian table aliases escape the pipe as ``\|``."""
target = tmp_path / "target.md"
source = tmp_path / "source.md"
target.write_text("# Target\n")
source.write_text(f"| Link |\n| --- |\n| [[target{separator}Alias]] |\n")
refs = [e for e in extract_markdown(source)["edges"]
if e["relation"] == "references"]
assert [e.get("target_file") for e in refs] == [str(target)]
def test_markdown_wikilink_fallback_path_qualified(tmp_path):
"""[[folder/name]] from a subfolder matches on the full segment suffix."""
vault = tmp_path / "vault"