diff --git a/python/tests/unit/collectors/test_references.py b/python/tests/unit/collectors/test_references.py index bdc831c..75b6978 100644 --- a/python/tests/unit/collectors/test_references.py +++ b/python/tests/unit/collectors/test_references.py @@ -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( diff --git a/python/zensical/collectors/references/cursor.py b/python/zensical/collectors/references/cursor.py index 054ce59..49d9a38 100644 --- a/python/zensical/collectors/references/cursor.py +++ b/python/zensical/collectors/references/cursor.py @@ -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