From be30afb65f5420cf8e8dbd046927716e0ec60919 Mon Sep 17 00:00:00 2001 From: JounQin Date: Fri, 2 Jul 2021 12:54:37 +0800 Subject: [PATCH] fix(angular-parser): support namespaced svg tags like `svg:defs` (#48) --- .changeset/lemon-hotels-heal.md | 5 ++ packages/angular-parser/src/index.ts | 2 +- .../test/__snapshots__/parser.spec.ts.snap | 64 +++++++++++++++++-- 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .changeset/lemon-hotels-heal.md diff --git a/.changeset/lemon-hotels-heal.md b/.changeset/lemon-hotels-heal.md new file mode 100644 index 00000000..a2dc3f1a --- /dev/null +++ b/.changeset/lemon-hotels-heal.md @@ -0,0 +1,5 @@ +--- +"markuplint-angular-parser": patch +--- + +fix(angular-parser): support namespaced svg tags like `svg:defs` diff --git a/packages/angular-parser/src/index.ts b/packages/angular-parser/src/index.ts index 839bc77e..fc046610 100644 --- a/packages/angular-parser/src/index.ts +++ b/packages/angular-parser/src/index.ts @@ -135,7 +135,7 @@ const visitor = { namespace = attrs.find(attr => attr.name === 'xmlns')?.value || namespace || - (nodeName === 'svg' + (nodeName === 'svg' || nodeName.startsWith('svg:') ? 'http://www.w3.org/2000/svg' : 'http://www.w3.org/1999/xhtml') diff --git a/packages/angular-parser/test/__snapshots__/parser.spec.ts.snap b/packages/angular-parser/test/__snapshots__/parser.spec.ts.snap index 2b186a27..e9d36dcd 100644 --- a/packages/angular-parser/test/__snapshots__/parser.spec.ts.snap +++ b/packages/angular-parser/test/__snapshots__/parser.spec.ts.snap @@ -1896,7 +1896,7 @@ Object { "isCustomElement": false, "isFragment": false, "isGhost": false, - "namespace": "http://www.w3.org/1999/xhtml", + "namespace": "http://www.w3.org/2000/svg", "nodeName": "svg:defs", "raw": "", "selfClosingSolidus": Object { @@ -1947,7 +1947,7 @@ Object { "isCustomElement": false, "isFragment": false, "isGhost": false, - "namespace": "http://www.w3.org/1999/xhtml", + "namespace": "http://www.w3.org/2000/svg", "nodeName": "svg:linearGradient", "raw": "", "selfClosingSolidus": Object { @@ -1974,7 +1974,7 @@ Object { "isCustomElement": false, "isFragment": false, "isGhost": false, - "namespace": "http://www.w3.org/1999/xhtml", + "namespace": "http://www.w3.org/2000/svg", "nodeName": "svg:linearGradient", "raw": "", "startCol": 27, @@ -2006,7 +2006,7 @@ Object { "isCustomElement": false, "isFragment": false, "isGhost": false, - "namespace": "http://www.w3.org/1999/xhtml", + "namespace": "http://www.w3.org/2000/svg", "nodeName": "svg:defs", "raw": "", "startCol": 5, @@ -2022,7 +2022,61 @@ Object { exports[`parser tag namespace 2`] = ` "Snapshot Diff: -Compared values have no visual difference." +- First value ++ Second value + +@@ -17,11 +17,11 @@ + }, + \\"hasSpreadAttr\\": false, + \\"isCustomElement\\": false, + \\"isFragment\\": false, + \\"isGhost\\": false, +- \\"namespace\\": \\"http://www.w3.org/1999/xhtml\\", ++ \\"namespace\\": \\"http://www.w3.org/2000/svg\\", + \\"nodeName\\": \\"svg:defs\\", + \\"raw\\": \\"\\", + \\"selfClosingSolidus\\": Object { + \\"endCol\\": 10, + \\"endLine\\": 1, +@@ -68,11 +68,11 @@ + }, + \\"hasSpreadAttr\\": false, + \\"isCustomElement\\": false, + \\"isFragment\\": false, + \\"isGhost\\": false, +- \\"namespace\\": \\"http://www.w3.org/1999/xhtml\\", ++ \\"namespace\\": \\"http://www.w3.org/2000/svg\\", + \\"nodeName\\": \\"svg:linearGradient\\", + \\"raw\\": \\"\\", + \\"selfClosingSolidus\\": Object { + \\"endCol\\": 26, + \\"endLine\\": 2, +@@ -95,11 +95,11 @@ + \\"endLine\\": 2, + \\"endOffset\\": 58, + \\"isCustomElement\\": false, + \\"isFragment\\": false, + \\"isGhost\\": false, +- \\"namespace\\": \\"http://www.w3.org/1999/xhtml\\", ++ \\"namespace\\": \\"http://www.w3.org/2000/svg\\", + \\"nodeName\\": \\"svg:linearGradient\\", + \\"raw\\": \\"\\", + \\"startCol\\": 27, + \\"startLine\\": 2, + \\"startOffset\\": 37, +@@ -127,11 +127,11 @@ + \\"endLine\\": 3, + \\"endOffset\\": 74, + \\"isCustomElement\\": false, + \\"isFragment\\": false, + \\"isGhost\\": false, +- \\"namespace\\": \\"http://www.w3.org/1999/xhtml\\", ++ \\"namespace\\": \\"http://www.w3.org/2000/svg\\", + \\"nodeName\\": \\"svg:defs\\", + \\"raw\\": \\"\\", + \\"startCol\\": 5, + \\"startLine\\": 3, + \\"startOffset\\": 63," `; exports[`parser void element 1`] = `