fix: don't consider [] and [][] link references (#663)

Signed-off-by: squidfunk <martin.donath@squidfunk.com>
This commit is contained in:
Martin Donath
2026-05-12 09:51:22 +02:00
committed by GitHub
parent c338b270b5
commit 820755463d
2 changed files with 14 additions and 6 deletions
@@ -310,12 +310,6 @@ class TestLinkReferences:
b"id",
id="link-ref-with-empty-text",
),
pytest.param(
b"[][]",
b"",
b"",
id="link-ref-with-empty-text-and-id",
),
pytest.param(
b"[text \\]][id]",
b"text \\]",
@@ -472,6 +466,16 @@ class TestLinkReferences:
refs = collect(md)
assert len(refs) == 0
def test_no_link_ref_empty_shortcut(self) -> None:
md = b"[]"
refs = collect(md)
assert len(refs) == 0
def test_no_link_ref_empty_brackets(self) -> None:
md = b"[][]"
refs = collect(md)
assert len(refs) == 0
# ---------------------------------------------------------------------------
@@ -424,6 +424,10 @@ def _scan_link_or_link_ref(cursor: Cursor) -> Link | LinkReference | None:
# Consume link id
id, end = _scan_link_id(cursor, end)
# Ignore empty shortcut references like `[]` or `[][]`.
if id is None and text.start == text.end:
return None
# Advance cursor and return link reference
cursor.advance(end - start)
return LinkReference(