Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-buses-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure svg namespace for `<a>` elements is correct
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,23 @@ export function RegularElement(node, context) {
(attribute) => attribute.type === 'SpreadAttribute'
);

node.metadata.svg = is_svg(node.name);
const is_svg_element = () => {
if (is_svg(node.name)) {
return true;
}
if (node.name === 'a') {
for (let i = context.path.length - 1; i >= 0; i--) {
const ancestor = context.path[i];
if (ancestor.type === 'RegularElement') {
return ancestor.metadata.svg;
}
}
}

return false;
};

node.metadata.svg = is_svg_element();
node.metadata.mathml = is_mathml(node.name);

if (is_custom_element_node(node) && node.attributes.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test, ok } from '../../test';

export default test({
html: `<svg><a href="/docs"><text class="small" x="20" y="40"></text></a></svg>`,
test({ assert, target }) {
const a = target.querySelector('a');
ok(a);

assert.equal(a.namespaceURI, 'http://www.w3.org/2000/svg');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<svg>
{#if true}
<a href="/docs">
<text x="20" y="40" class="small">{name}</text>
</a>
{/if}
</svg>
Loading