Skip to content

Commit 577f2f7

Browse files
authored
Fix checking image link (#82)
1 parent d9fd2ce commit 577f2f7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

htmlproofer/plugin.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ def on_post_page(self, output_content: str, page: Page, config: Config) -> None:
116116

117117
all_element_ids = set(tag['id'] for tag in soup.select('[id]'))
118118
all_element_ids.add('') # Empty anchor is commonly used, but not real
119-
for a in soup.find_all('a', href=True):
120-
url = a['href']
121119

120+
urls = set(a['href'] for a in soup.find_all('a', href=True)) | set(img['src'] for img in soup.find_all('img'))
121+
122+
for url in urls:
122123
if any(fnmatch.fnmatch(url, ignore_url) for ignore_url in self.config['ignore_urls']):
123124
if self.config['warn_on_ignored_urls']:
124125
log_warning(f"ignoring URL {url} from {page.file.src_path}")

tests/unit/test_plugin.py

+15
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ def test_on_post_page__plugin_disabled():
108108
plugin.on_post_page('<a href="https://google.com"><a/>', Mock(spec=Page), Mock(spec=Config))
109109

110110

111+
def test_on_post_page__img():
112+
plugin = HtmlProoferPlugin()
113+
plugin.load_config({
114+
'validate_rendered_template': True,
115+
'raise_error': True,
116+
})
117+
page = Mock(
118+
spec=Page,
119+
file=Mock(spec=File, src_path='blah.md'),
120+
content='',
121+
)
122+
with pytest.raises(PluginError):
123+
plugin.on_post_page('<img src="not-existing.png" />', page, Mock(spec=Config))
124+
125+
111126
@pytest.mark.parametrize(
112127
'url',
113128
(

0 commit comments

Comments
 (0)