mirror of
https://github.com/zensical/zensical.git
synced 2026-08-23 15:46:44 +00:00
fix: invalid code span detection in reference extractor
Signed-off-by: squidfunk <martin.donath@squidfunk.com>
This commit is contained in:
+21
@@ -1819,6 +1819,27 @@ class TestInlineCode:
|
||||
assert text(md, links[0].text) == b"text"
|
||||
assert text(md, links[0].href) == b"href"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"md",
|
||||
[
|
||||
pytest.param(
|
||||
b"a`\n\n`[b]`",
|
||||
id="blank-line",
|
||||
),
|
||||
pytest.param(
|
||||
b"a`\n \n`[b]`",
|
||||
id="whitespace-only-line",
|
||||
),
|
||||
pytest.param(
|
||||
b"a`\r\n\r\n`[b]`",
|
||||
id="blank-line-crlf",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_inline_code_does_not_cross_blank_line(self, md: bytes) -> None:
|
||||
refs = collect(md)
|
||||
assert len(refs) == 0
|
||||
|
||||
# --- negative cases ---
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1083,6 +1083,19 @@ def _scan_inline_code(cursor: Cursor) -> int | None:
|
||||
|
||||
# Search for matching closing backticks
|
||||
while pos < cursor.end:
|
||||
# Inline code spans may contain line endings, but cannot cross a
|
||||
# blank line because that starts a new block in Python-Markdown.
|
||||
if cursor.data[pos] in (_CR, _NL):
|
||||
line = pos + 1
|
||||
if (
|
||||
cursor.data[pos] == _CR
|
||||
and line < cursor.end
|
||||
and cursor.data[line] == _NL
|
||||
):
|
||||
line += 1
|
||||
if _is_blank_line(cursor, line):
|
||||
return None
|
||||
|
||||
if cursor.data[pos] == _BACKTICK:
|
||||
end = pos
|
||||
|
||||
|
||||
Reference in New Issue
Block a user