Skip to content

Commit

Permalink
Added support for downloading external images in SVG for privacy plug…
Browse files Browse the repository at this point in the history
…in (#7650)
  • Loading branch information
nejch authored Oct 30, 2024
1 parent 1357cd2 commit 7dc96f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion material/plugins/privacy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,19 @@ def replace(match: Match):
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
)

Expand Down
9 changes: 8 additions & 1 deletion src/plugins/privacy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,19 @@ def replace(match: Match):
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
)

Expand Down

0 comments on commit 7dc96f1

Please sign in to comment.