fix(zhihu): remove noscript tags to prevent duplicate images
PR Test / lint (pull_request) Successful in 1s
PR Test / lint (pull_request) Successful in 1s
Zhihu HTML structure includes noscript fallback images: <figure><img data-actualsrc=...><noscript><img src=...></noscript></figure> After fixing lazy-load (replacing src with data-actualsrc), both imgs have real URLs, causing duplicates. The fix removes noscript tags before processing img elements. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,30 @@ class TestMarkdownConverterImages:
|
||||
assert "https://pic.zhimg.com/fig.jpg" in result
|
||||
assert "Image caption" in result
|
||||
|
||||
def test_noscript_images_not_duplicated(self):
|
||||
"""Test that images inside noscript tags don't cause duplicates
|
||||
|
||||
Zhihu HTML structure includes noscript fallback images:
|
||||
<figure><img data-actualsrc=...><noscript><img src=...></noscript></figure>
|
||||
|
||||
After fixing lazy-load, both imgs would have real URLs, causing duplicates.
|
||||
The fix removes noscript tags before processing.
|
||||
"""
|
||||
html = '''
|
||||
<figure>
|
||||
<img src="data:image/svg+xml;..." data-actualsrc="https://pic.zhimg.com/test.jpg">
|
||||
<noscript>
|
||||
<img src="https://pic.zhimg.com/test.jpg">
|
||||
</noscript>
|
||||
</figure>
|
||||
'''
|
||||
converter = MarkdownConverter()
|
||||
result = converter.convert(html)
|
||||
|
||||
# Should appear exactly once, not twice
|
||||
assert result.count("zhimg.com") == 1
|
||||
assert "https://pic.zhimg.com/test.jpg" in result
|
||||
|
||||
def test_empty_src_with_data_actualsrc(self):
|
||||
"""Test handling of empty src with data-actualsrc"""
|
||||
html = '<img src="" data-actualsrc="https://example.com/fallback.jpg">'
|
||||
|
||||
Reference in New Issue
Block a user