Skip to content

Fix checking image link #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions htmlproofer/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ def on_post_page(self, output_content: str, page: Page, config: Config) -> None:

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

urls = set(a['href'] for a in soup.find_all('a', href=True)) | set(img['src'] for img in soup.find_all('img'))

for url in urls:
if any(fnmatch.fnmatch(url, ignore_url) for ignore_url in self.config['ignore_urls']):
if self.config['warn_on_ignored_urls']:
log_warning(f"ignoring URL {url} from {page.file.src_path}")
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ def test_on_post_page__plugin_disabled():
plugin.on_post_page('<a href="https://google.com"><a/>', Mock(spec=Page), Mock(spec=Config))


def test_on_post_page__img():
plugin = HtmlProoferPlugin()
plugin.load_config({
'validate_rendered_template': True,
'raise_error': True,
})
page = Mock(
spec=Page,
file=Mock(spec=File, src_path='blah.md'),
content='',
)
with pytest.raises(PluginError):
plugin.on_post_page('<img src="not-existing.png" />', page, Mock(spec=Config))


@pytest.mark.parametrize(
'url',
(
Expand Down