From 0b645b60cb6bc1b248631acabeb6012884584aeb Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Fri, 15 Sep 2023 17:40:14 +0200 Subject: [PATCH] fix: Recognize links with multi-line text --- 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(