1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-13 18:40:54 +01:00

Added support for downloading external images in SVG for privacy plugin (#7650)

This commit is contained in:
Nejc Habjan 2024-10-30 13:54:31 +01:00 committed by GitHub
parent 1357cd26af
commit 7dc96f1e13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -313,12 +313,19 @@ class PrivacyPlugin(BasePlugin[PrivacyConfig]):
file = self._queue(url, config)
el.set("src", resolve(file))
# Handle external image in SVG
if el.tag == "image":
url = urlparse(el.get("href"))
if not self._is_excluded(url, initiator):
file = self._queue(url, config)
el.set("href", resolve(file))
# Return element as string
return self._print(el)
# Find and replace all external asset URLs in current page
return re.sub(
r"<(?:(?:a|link)[^>]+href|(?:script|img)[^>]+src)=['\"]?http[^>]+>",
r"<(?:(?:a|link|image)[^>]+href|(?:script|img)[^>]+src)=['\"]?http[^>]+>",
replace, output, flags = re.I | re.M
)

View File

@ -313,12 +313,19 @@ class PrivacyPlugin(BasePlugin[PrivacyConfig]):
file = self._queue(url, config)
el.set("src", resolve(file))
# Handle external image in SVG
if el.tag == "image":
url = urlparse(el.get("href"))
if not self._is_excluded(url, initiator):
file = self._queue(url, config)
el.set("href", resolve(file))
# Return element as string
return self._print(el)
# Find and replace all external asset URLs in current page
return re.sub(
r"<(?:(?:a|link)[^>]+href|(?:script|img)[^>]+src)=['\"]?http[^>]+>",
r"<(?:(?:a|link|image)[^>]+href|(?:script|img)[^>]+src)=['\"]?http[^>]+>",
replace, output, flags = re.I | re.M
)