Skip to content

Commit

Permalink
compiler: text util: preserve space after svg <tspan> tags (#4107)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Kondrad authored and Conduitry committed Dec 23, 2019
1 parent c0dab9f commit f287736
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/compiler/compile/render_dom/wrappers/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ function should_skip(node: Text) {
if (parent_element.type === 'Head') return true;
if (parent_element.type === 'InlineComponent') return parent_element.children.length === 1 && node === parent_element.children[0];

// svg namespace exclusions
if (/svg$/.test(parent_element.namespace)) {
if (node.prev && node.prev.type === "Element" && node.prev.name === "tspan") return false;
}

return parent_element.namespace || elements_without_text.has(parent_element.name);
}

Expand Down
3 changes: 3 additions & 0 deletions test/runtime/samples/svg-tspan-preserve-space/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
html: `<svg><text x=0 y=50><tspan>foo</tspan> bar<tspan>foo</tspan> bar</text></svg>`,
};
1 change: 1 addition & 0 deletions test/runtime/samples/svg-tspan-preserve-space/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<svg><text x=0 y=50><tspan>foo</tspan> {"bar"}<tspan>foo</tspan> bar</text></svg>

0 comments on commit f287736

Please sign in to comment.