mirror of
https://github.com/zensical/zensical.git
synced 2026-09-23 14:55:34 +00:00
fix: don't consider [] and [][] link references (#663)
Signed-off-by: squidfunk <martin.donath@squidfunk.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user