Skip to content

Commit b36a0d1

Browse files
committed
fix: Don't ignore identifiers containing spaces and slashes
Issue-55: #55
1 parent 4f2be46 commit b36a0d1

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/mkdocs_autorefs/references.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ def handleMatch(self, m: Match[str], data: str) -> tuple[Element | None, int | N
8888
if not handled or identifier is None:
8989
return None, None, None
9090

91-
if re.search(r"[/ \x00-\x1f]", identifier):
92-
# Do nothing if the matched reference contains:
93-
# - a space, slash or control character (considered unintended);
94-
# - specifically \x01 is used by Python-Markdown HTML stash when there's inline formatting,
95-
# but references with Markdown formatting are not possible anyway.
91+
if re.search(r"[\x00-\x1f]", identifier):
92+
# Do nothing if the matched reference contains control characters (from 0 to 31 included).
93+
# Specifically `\x01` is used by Python-Markdown HTML stash when there's inline formatting,
94+
# but references with Markdown formatting are not possible anyway.
9695
return None, m.start(0), end
9796

9897
return self._make_tag(identifier, text), m.start(0), end

tests/test_references.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ def test_multiline_links() -> None:
146146

147147

148148
def test_no_reference_with_space() -> None:
149-
"""Check that references with spaces are not fixed."""
149+
"""Check that references with spaces are fixed."""
150150
run_references_test(
151-
url_map={"Foo bar": "foo.html#Foo bar"},
151+
url_map={"Foo bar": "foo.html#bar"},
152152
source="This [Foo bar][].",
153-
output="<p>This [Foo bar][].</p>",
153+
output='<p>This <a class="autorefs autorefs-internal" href="foo.html#bar">Foo bar</a>.</p>',
154154
)
155155

156156

@@ -203,12 +203,17 @@ def test_missing_reference_with_markdown_implicit() -> None:
203203
)
204204

205205

206-
def test_ignore_reference_with_special_char() -> None:
207-
"""Check that references are not considered if there is a space character inside."""
206+
def test_reference_with_markup() -> None:
207+
"""Check that references with markup are resolved (and need escaping to prevent rendering)."""
208208
run_references_test(
209-
url_map={"a b": "foo.html#Foo"},
209+
url_map={"*a b*": "foo.html#Foo"},
210210
source="This [*a b*][].",
211-
output="<p>This [<em>a b</em>][].</p>",
211+
output='<p>This <a class="autorefs autorefs-internal" href="foo.html#Foo"><em>a b</em></a>.</p>',
212+
)
213+
run_references_test(
214+
url_map={"*a/b*": "foo.html#Foo"},
215+
source="This [`*a/b*`][].",
216+
output='<p>This <a class="autorefs autorefs-internal" href="foo.html#Foo"><code>*a/b*</code></a>.</p>',
212217
)
213218

214219

0 commit comments

Comments
 (0)