diff --git a/src/mkdocs_autorefs/references.py b/src/mkdocs_autorefs/references.py index eac458e..7c361d1 100644 --- a/src/mkdocs_autorefs/references.py +++ b/src/mkdocs_autorefs/references.py @@ -88,11 +88,10 @@ def handleMatch(self, m: Match[str], data: str) -> tuple[Element | None, int | N if not handled or identifier is None: return None, None, None - if re.search(r"[/ \x00-\x1f]", identifier): - # Do nothing if the matched reference contains: - # - a space, slash or control character (considered unintended); - # - specifically \x01 is used by Python-Markdown HTML stash when there's inline formatting, - # but references with Markdown formatting are not possible anyway. + if re.search(r"[\x00-\x1f]", identifier): + # Do nothing if the matched reference contains control characters (from 0 to 31 included). + # Specifically `\x01` is used by Python-Markdown HTML stash when there's inline formatting, + # but references with Markdown formatting are not possible anyway. return None, m.start(0), end return self._make_tag(identifier, text), m.start(0), end diff --git a/tests/test_references.py b/tests/test_references.py index 18fdc6e..3eab1f0 100644 --- a/tests/test_references.py +++ b/tests/test_references.py @@ -146,11 +146,11 @@ def test_multiline_links() -> None: def test_no_reference_with_space() -> None: - """Check that references with spaces are not fixed.""" + """Check that references with spaces are fixed.""" run_references_test( - url_map={"Foo bar": "foo.html#Foo bar"}, + url_map={"Foo bar": "foo.html#bar"}, source="This [Foo bar][].", - output="

This [Foo bar][].

", + output='

This Foo bar.

', ) @@ -203,12 +203,17 @@ def test_missing_reference_with_markdown_implicit() -> None: ) -def test_ignore_reference_with_special_char() -> None: - """Check that references are not considered if there is a space character inside.""" +def test_reference_with_markup() -> None: + """Check that references with markup are resolved (and need escaping to prevent rendering).""" run_references_test( - url_map={"a b": "foo.html#Foo"}, + url_map={"*a b*": "foo.html#Foo"}, source="This [*a b*][].", - output="

This [a b][].

", + output='

This a b.

', + ) + run_references_test( + url_map={"*a/b*": "foo.html#Foo"}, + source="This [`*a/b*`][].", + output='

This *a/b*.

', )