Skip to content

Commit

Permalink
fix(angular-parser): support namespaced svg tags like svg:defs (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Jul 2, 2021
1 parent 47f09b2 commit be30afb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-hotels-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"markuplint-angular-parser": patch
---

fix(angular-parser): support namespaced svg tags like `svg:defs`
2 changes: 1 addition & 1 deletion packages/angular-parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
64 changes: 59 additions & 5 deletions packages/angular-parser/test/__snapshots__/parser.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<svg:defs>",
"selfClosingSolidus": Object {
Expand Down Expand Up @@ -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": "<svg:linearGradient>",
"selfClosingSolidus": Object {
Expand All @@ -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": "</svg:linearGradient>",
"startCol": 27,
Expand Down Expand Up @@ -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": "</svg:defs>",
"startCol": 5,
Expand All @@ -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\\": \\"<svg:defs>\\",
\\"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\\": \\"<svg:linearGradient>\\",
\\"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\\": \\"</svg:linearGradient>\\",
\\"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\\": \\"</svg:defs>\\",
\\"startCol\\": 5,
\\"startLine\\": 3,
\\"startOffset\\": 63,"
`;
exports[`parser void element 1`] = `
Expand Down

0 comments on commit be30afb

Please sign in to comment.