From a72cf1908e4e81e3e8a6b706336988e7a712623a Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 16 Oct 2021 14:55:32 +0200 Subject: [PATCH] Fix SVG parsing. Closes #3866 --- src/parser/model/ParserHtml.js | 4 ++-- test/specs/parser/model/ParserHtml.js | 34 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/parser/model/ParserHtml.js b/src/parser/model/ParserHtml.js index dee26c945..b04c12166 100644 --- a/src/parser/model/ParserHtml.js +++ b/src/parser/model/ParserHtml.js @@ -209,8 +209,8 @@ export default config => { }; } else { model.components = this.parseNode(node, { - inSvg: model.type === 'svg', - ...opts + ...opts, + inSvg: opts.inSvg || model.type === 'svg' }); } } diff --git a/test/specs/parser/model/ParserHtml.js b/test/specs/parser/model/ParserHtml.js index 4342ed08b..15caca26e 100644 --- a/test/specs/parser/model/ParserHtml.js +++ b/test/specs/parser/model/ParserHtml.js @@ -531,4 +531,38 @@ describe('ParserHtml', () => { ]; expect(obj.parse(str).html).toEqual(result); }); + + test('SVG is properly parsed', () => { + const str = `
+ + + +
`; + const result = [ + { + tagName: 'div', + components: [ + { + type: 'svg', + tagName: 'svg', + attributes: { + xmlns: 'http://www.w3.org/2000/svg', + viewBox: '0 0 24 24' + }, + components: [ + { + tagName: 'path', + attributes: { + d: + 'M13 12h7v1.5h-7m0-4h7V11h-7m0 3.5h7V16h-7m8-12H3c-1.1 0-2 .9-2 2v13c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m0 15h-9V6h9' + }, + type: 'svg-in' + } + ] + } + ] + } + ]; + expect(obj.parse(str).html).toEqual(result); + }); });