mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 11:47:54 +01:00
clipper: remove invalid element attributes for screenshot clips
Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
@@ -138,6 +138,20 @@ function makeSvgDataUri(
|
||||
) {
|
||||
body.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
||||
|
||||
/**
|
||||
* We're removing all attributes that contain non-word characters
|
||||
* Sometimes a webpage could have invalid html and that causes attribute names to break
|
||||
* HTML is resilient to this but SVG is not and will throw an error, so we remove these attributes altogether
|
||||
*/
|
||||
for (const element of body.querySelectorAll("img, svg, video, iframe")) {
|
||||
const attributes = element.getAttributeNames();
|
||||
for (const attribute of attributes) {
|
||||
if (attribute.match(/\W/)) {
|
||||
element.removeAttribute(attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const xhtml = new XMLSerializer().serializeToString(body);
|
||||
|
||||
const xstyles = Array.from(head.getElementsByTagName("style"))
|
||||
|
||||
Reference in New Issue
Block a user