forked from aautar/svg-foreignobject-screenshot
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove some fn's from export; fix images loading
- Loading branch information
Showing
5 changed files
with
47 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export const getImageUrlsFromFromHtml = (html: string): string[] => { | ||
const urls = Array.from( | ||
html.matchAll(/<(?:img|image).*?(?:href|src)=(["|'])(.*?)(\1)/gm) | ||
) | ||
.map(match => match[2]) | ||
.filter( | ||
url => !url.startsWith('data:') && !url.startsWith('#') && url !== '' | ||
) | ||
return urls | ||
} | ||
|
||
export const getUrlsFromCssString = (cssRuleString: string): string[] => { | ||
const urls = Array.from(cssRuleString.matchAll(/url\((.*?)\)/gi)) | ||
.map(match => removeQuotes(match[1])) | ||
.filter(url => !url.startsWith('data:') && url !== '') | ||
|
||
return urls | ||
} | ||
|
||
export const removeQuotes = (str: string) => | ||
str.replace(/^("|').*?(\1)$/gm, match => match.slice(1, -1)) | ||
|
||
const escaped: { [key: string]: string } = { | ||
'"': '"', | ||
''': "'", | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
} | ||
|
||
export const descape = (string: string) => | ||
string.replace(/&(quot|#39|amp|lt|gt);/g, match => escaped[match]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters