Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit c4387d8

Browse files
committed
chore: fix formatting
1 parent a4d2d9a commit c4387d8

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

mkdocs_site_urls/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
1818
attributes = (re.escape(attr) for attr in self.config["attributes"])
1919
self.prefix = re.escape(self.config["prefix"])
2020
regex_parts = [
21-
r"(", # capturing group 1
22-
"|".join(attributes), # attributes
23-
r")", # end of capturing group 1
24-
r"\s*=\s*", # equals sign with optional whitespace
25-
r"([\"'])", # quote with capturing group 2
26-
self.prefix, # url prefix
27-
r"([^\"']*)", # remainder of the url with capturing group 3
28-
r"\2", # matching quote
21+
r"(", # capturing group 1
22+
"|".join(attributes), # attributes
23+
r")", # end of capturing group 1
24+
r"\s*=\s*", # equals sign with optional whitespace
25+
r"([\"'])", # quote with capturing group 2
26+
self.prefix, # url prefix
27+
r"([^\"']*)", # remainder of the url with capturing group 3
28+
r"\2", # matching quote
2929
]
3030
regex = "".join(regex_parts)
3131
self._regex = re.compile(regex, re.IGNORECASE)
@@ -37,11 +37,12 @@ def on_page_content(self, html, page, config, files):
3737
if not site_url.endswith("/"):
3838
site_url += "/"
3939
path = urllib.parse.urlparse(site_url).path
40+
4041
def _replacer(match):
4142
attribute = match.group(1)
4243
url = match.group(3)
4344

4445
logger.info(f"Replacing absolute url '{self.prefix}{url}' with '{path}{url}'")
4546
return f'{attribute}="{path}{url}"'
4647

47-
return self._regex.sub(_replacer, html)
48+
return self._regex.sub(_replacer, html)

tests/test_mkdocs_site_urls.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import re
2+
from unittest.mock import MagicMock
23

34
import pytest
4-
5-
from unittest.mock import MagicMock
65
from resolve_absolute_urls.plugin import ResolveAbsoluteUrlsPlugin
76

7+
88
@pytest.fixture
99
def mock_plugin_config():
1010
return {"attributes": ["src", "href"], "prefix": "site:"}
@@ -114,6 +114,7 @@ def test_on_config_sets_regex(
114114
else:
115115
assert match is None
116116

117+
117118
@pytest.mark.parametrize(
118119
"site_url",
119120
[
@@ -124,27 +125,29 @@ def test_on_config_sets_regex(
124125
)
125126
def test_on_page_content(create_plugin, site_url):
126127
"""Test the on_page_content method of the ResolveAbsoluteUrlsPlugin."""
127-
plugin = create_plugin({
128-
"attributes": ["src", "data"],
129-
"prefix": "prefix",
130-
})
128+
plugin = create_plugin(
129+
{
130+
"attributes": ["src", "data"],
131+
"prefix": "prefix",
132+
}
133+
)
131134
page = MagicMock()
132135
config = MagicMock()
133136
config.__getitem__.side_effect = lambda key: site_url if key == "site_url" else None
134137
files = MagicMock()
135-
html = '''
138+
html = """
136139
<img src ="prefixexample.png" alt="Image">
137140
<img data = \'prefix/image.png\'>
138141
<img data="site:docs/image.svg" class="example">
139142
<img attr ="prefix/docs/image.png" >
140-
'''
143+
"""
141144

142145
plugin.on_config(config)
143146
result = plugin.on_page_content(html, page, config, files)
144-
expected_result = '''
147+
expected_result = """
145148
<img src="/docs/subpage/example.png" alt="Image">
146149
<img data="/docs/subpage//image.png">
147150
<img data="site:docs/image.svg" class="example">
148151
<img attr ="prefix/docs/image.png" >
149-
'''
150-
assert result == expected_result
152+
"""
153+
assert result == expected_result

0 commit comments

Comments
 (0)