From 225a6f275069bcdfb3411e80d4a7fa645b857b88 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Thu, 15 Feb 2024 16:30:41 +0100 Subject: [PATCH] fix: Recognize links with multi-line text Issue #31: https://github.com/mkdocstrings/autorefs/issues/31 PR #32: https://github.com/mkdocstrings/autorefs/pull/32 --- src/mkdocs_autorefs/references.py | 1 + tests/test_references.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/mkdocs_autorefs/references.py b/src/mkdocs_autorefs/references.py index dd527de..66b4931 100644 --- a/src/mkdocs_autorefs/references.py +++ b/src/mkdocs_autorefs/references.py @@ -18,6 +18,7 @@ AUTO_REF_RE = re.compile( r"autorefs-identifier|autorefs-optional|autorefs-optional-hover)=" r'("?)(?P[^"<>]*)\2>(?P.*?)</span>', + flags=re.DOTALL, ) """A regular expression to match mkdocs-autorefs' special reference markers in the [`on_post_page` hook][mkdocs_autorefs.plugin.AutorefsPlugin.on_post_page]. diff --git a/tests/test_references.py b/tests/test_references.py index 14e9a78..5a25844 100644 --- a/tests/test_references.py +++ b/tests/test_references.py @@ -111,6 +111,15 @@ def test_reference_to_relative_path() -> None: ) +def test_multiline_links() -> None: + """Check that links with multiline text are recognized.""" + run_references_test( + url_map={"foo-bar": "foo.html#bar"}, + source="This [Foo\nbar][foo-bar].", + output='<p>This <a class="autorefs autorefs-internal" href="foo.html#bar">Foo\nbar</a>.</p>', + ) + + def test_no_reference_with_space() -> None: """Check that references with spaces are not fixed.""" run_references_test(