[FIX] qweb: support of svg in t-raw

Before this commit, t-raw a string containing `<svg>` did not display
the svg element. This was because of missing namespace in vnode's data.

Now, `vdom.addNS` is called to add the svg namespace when necessary.
This commit is contained in:
Michael Mattiello (mcm)
2020-05-25 13:49:21 +02:00
committed by Géry Debongnie
parent 85318b3ae6
commit 9fd8315c53
2 changed files with 13 additions and 2 deletions
+6 -2
View File
@@ -1,4 +1,4 @@
import { VNode, h } from "./vdom";
import { VNode, h, addNS } from "./vdom";
const parser = new DOMParser();
@@ -23,5 +23,9 @@ function htmlToVNode(node: ChildNode): VNode {
for (let c of node.childNodes) {
children.push(htmlToVNode(c));
}
return h((node as Element).tagName, { attrs }, children);
const vnode = h((node as Element).tagName, { attrs }, children);
if (vnode.sel === "svg") {
addNS(vnode.data, (vnode as any).children, vnode.sel);
}
return vnode;
}
+7
View File
@@ -1105,4 +1105,11 @@ describe("html to vdom", function () {
elm = patch(vnode0, nodeList[0]).elm;
expect(elm.outerHTML).toEqual(`<span a="1" b="2">abc<div>1</div></span>`);
});
test("svg", function () {
const nodeList = htmlToVDOM(`<svg></svg>`);
expect(nodeList).toHaveLength(1);
elm = patch(vnode0, nodeList[0]).elm;
expect(elm).toBeInstanceOf(SVGSVGElement);
});
});