Skip to content

Commit

Permalink
fix: some images did not being replaced after fetcher; export Options…
Browse files Browse the repository at this point in the history
… type
  • Loading branch information
yhdgms1 committed Mar 7, 2022
1 parent 938fdd2 commit 70cf78f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Use SVG foreignObject to render images of HTML content",
"author": "Artem Schukin",
"license": "MIT",
"version": "0.5.0",
"version": "0.5.1",
"type": "module",
"homepage": "https://github.com/Artemis69/svg-foreignobject-screenshot",
"repository": {
Expand Down
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getImageUrlsFromHtml, getUrlsFromCss } from './lib'
import { getImageUrlsFromHtml, getUrlsFromCss, descape } from './lib'
import { Options, HookName, HookParameter, BuildSvgDataURI } from './types'
export { fetcher } from './fetcher'

Expand All @@ -12,7 +12,7 @@ const useFetcher = async (resources: string[], fetcher: Options['fetcher']) => {
const results = [] as Array<[string, string]>

for (const resource of resources) {
const result = await fetcher(resource)
const result = await fetcher(descape(resource))
results.push([resource, result])
}

Expand Down Expand Up @@ -66,8 +66,8 @@ export const buildSvgDataURI: BuildSvgDataURI = async (html, options) => {
const base64Resources = await useFetcher(uniqueResources, options.fetcher)

for (const [url, base64] of base64Resources) {
css = css.replace(new RegExp(url, 'g'), base64)
html = html.replace(new RegExp(url, 'g'), base64)
css = css.replaceAll(url, base64)
html = html.replaceAll(url, base64)
}

const hook = async <T extends keyof HookName, K extends HookParameter<T>>(
Expand Down Expand Up @@ -128,3 +128,5 @@ export const renderToBase64Png = (dataURI: string): Promise<string> => {
img.onerror = controller
})
}

export { Options }
2 changes: 1 addition & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getUrlsFromCss = (cssRuleString: string): string[] => {
const regex = /url\((.*?)\)/gi

const urls = Array.from(cssRuleString.matchAll(regex))
.map(match => removeQuotes(descape(match[1])))
.map(match => removeQuotes(match[1]))
.filter(filterer)

return urls
Expand Down

0 comments on commit 70cf78f

Please sign in to comment.