Skip to content

Commit

Permalink
fix: use xlink:href for image instead of href (#116)
Browse files Browse the repository at this point in the history
xlink:href is removed from SVG2.0, but non-namespaced href is not supported by Inkscape.

Fixes #113
  • Loading branch information
felixfbecker authored Apr 11, 2021
1 parent 7895cc6 commit c36bcba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function handleElement(element: Element, context: Readonly<TraversalConte
) {
const svgImage = context.svgDocument.createElementNS(svgNamespace, 'image')
svgImage.id = `${id}-image` // read by inlineResources()
svgImage.setAttribute('href', element.currentSrc || element.src)
svgImage.setAttribute('xlink:href', element.currentSrc || element.src)
const paddingLeft = parseCSSLength(styles.paddingLeft, bounds.width) ?? 0
const paddingRight = parseCSSLength(styles.paddingRight, bounds.width) ?? 0
const paddingTop = parseCSSLength(styles.paddingTop, bounds.height) ?? 0
Expand Down Expand Up @@ -294,7 +294,7 @@ function addBackgroundAndBorders(
// not the page. But we have no means to know what stylesheet the style came from
// (unless we iterate through all rules in all style sheets and find the matching one).
const url = new URL(unescapeStringValue(urlArgument.value), window.location.href)
image.setAttribute('href', url.href)
image.setAttribute('xlink:href', url.href)

if (
backgroundRepeat === 'no-repeat' ||
Expand Down
2 changes: 1 addition & 1 deletion src/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function inlineResources(element: Element): Promise<void> {
// Inline binary images as base64 data: URL
const dataUrl = await blobToDataURL(blob)
element.dataset.src = element.href.baseVal
element.setAttribute('href', dataUrl.href)
element.setAttribute('xlink:href', dataUrl.href)
}
} else if (isSVGStyleElement(element)) {
try {
Expand Down

0 comments on commit c36bcba

Please sign in to comment.