exclude svg from image group (belongs to svg_icon)
Browse files
app/services/extractors/images.py
CHANGED
|
@@ -1,10 +1,15 @@
|
|
| 1 |
-
"""Extract image assets from HTML.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
import re
|
| 4 |
|
| 5 |
from ..resolver import resolve
|
| 6 |
|
| 7 |
_IMAGE_EXT = r"\.(?:jpe?g|png|gif|webp|avif|bmp|apng)(?:$|[\?#])"
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def _parse_srcset(srcset: str) -> list[str]:
|
|
@@ -34,6 +39,9 @@ def extract(soup, base_url: str, include_data_uris: bool = False) -> list[str]:
|
|
| 34 |
return
|
| 35 |
if ref.startswith("data:") and not include_data_uris:
|
| 36 |
return
|
|
|
|
|
|
|
|
|
|
| 37 |
if resolved not in found:
|
| 38 |
found.append(resolved)
|
| 39 |
|
|
|
|
| 1 |
+
"""Extract image assets from HTML.
|
| 2 |
+
|
| 3 |
+
SVG files are intentionally excluded — they belong to the ``svg_icon``
|
| 4 |
+
category, not ``image``.
|
| 5 |
+
"""
|
| 6 |
|
| 7 |
import re
|
| 8 |
|
| 9 |
from ..resolver import resolve
|
| 10 |
|
| 11 |
_IMAGE_EXT = r"\.(?:jpe?g|png|gif|webp|avif|bmp|apng)(?:$|[\?#])"
|
| 12 |
+
_SVG_EXT = r"\.svg(?:$|[\?#])"
|
| 13 |
|
| 14 |
|
| 15 |
def _parse_srcset(srcset: str) -> list[str]:
|
|
|
|
| 39 |
return
|
| 40 |
if ref.startswith("data:") and not include_data_uris:
|
| 41 |
return
|
| 42 |
+
# SVG belongs to svg_icon, never image.
|
| 43 |
+
if re.search(_SVG_EXT, resolved, re.IGNORECASE):
|
| 44 |
+
return
|
| 45 |
if resolved not in found:
|
| 46 |
found.append(resolved)
|
| 47 |
|