11import { HtmlParser } from '@starptech/webparser'
22import fromWebParser from '../index'
33
4+ function getParserOpt ( ) {
5+ return {
6+ ignoreFirstLf : false ,
7+ decodeEntities : false ,
8+ selfClosingCustomElements : true ,
9+ selfClosingElements : true
10+ }
11+ }
12+
413test ( 'Attributes' , ( ) => {
5- const parser = new HtmlParser ( )
14+ const parser = new HtmlParser ( getParserOpt ( ) )
615 const result = parser . parse (
716 `<p id="foo" class="bar baz" data-qux="quux"></p>
817 <p data-123="456"></p>
@@ -20,7 +29,7 @@ test('Attributes', () => {
2029} )
2130
2231test ( 'Element void' , ( ) => {
23- const parser = new HtmlParser ( )
32+ const parser = new HtmlParser ( getParserOpt ( ) )
2433 const result = parser . parse (
2534 `
2635 <img>
@@ -39,7 +48,7 @@ test('Element void', () => {
3948} )
4049
4150test ( 'Simple' , ( ) => {
42- const parser = new HtmlParser ( )
51+ const parser = new HtmlParser ( getParserOpt ( ) )
4352 const result = parser . parse ( `<div><p>foo</p></div>` , 'TestComp' )
4453
4554 expect ( result . errors . length ) . toBe ( 0 )
@@ -50,7 +59,7 @@ test('Simple', () => {
5059} )
5160
5261test ( 'SVG' , ( ) => {
53- const parser = new HtmlParser ( )
62+ const parser = new HtmlParser ( getParserOpt ( ) )
5463 const result = parser . parse (
5564 `<div>
5665 <svg width="230" height="120" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
@@ -69,7 +78,7 @@ test('SVG', () => {
6978} )
7079
7180test ( 'SVG - should preserve explicit svg namespace' , ( ) => {
72- const parser = new HtmlParser ( )
81+ const parser = new HtmlParser ( getParserOpt ( ) )
7382 const result = parser . parse (
7483 `<div>
7584 <svg:svg width="230" height="120" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
@@ -88,7 +97,7 @@ test('SVG - should preserve explicit svg namespace', () => {
8897} )
8998
9099test ( 'Template' , ( ) => {
91- const parser = new HtmlParser ( )
100+ const parser = new HtmlParser ( getParserOpt ( ) )
92101 const result = parser . parse (
93102 `<template id="text">!</template>
94103 <TEMPLATE id="html"><strong>importance</strong> and <em>emphasis</em>.</TEMPLATE>` ,
@@ -103,7 +112,7 @@ test('Template', () => {
103112} )
104113
105114test ( 'Comment' , ( ) => {
106- const parser = new HtmlParser ( )
115+ const parser = new HtmlParser ( getParserOpt ( ) )
107116 const result = parser . parse ( `<!-- foo -->` , 'TestComp' )
108117
109118 expect ( result . errors . length ) . toBe ( 0 )
@@ -114,7 +123,7 @@ test('Comment', () => {
114123} )
115124
116125test ( 'Attributes with colon or @ as prefix' , ( ) => {
117- const parser = new HtmlParser ( )
126+ const parser = new HtmlParser ( getParserOpt ( ) )
118127 const result = parser . parse ( `<div :type="" @foo="bar"></div>` , 'TestComp' )
119128
120129 expect ( result . errors . length ) . toBe ( 0 )
@@ -124,8 +133,22 @@ test('Attributes with colon or @ as prefix', () => {
124133 expect ( node ) . toMatchSnapshot ( )
125134} )
126135
136+ test ( 'Attributes with colon, binding syntax and namespace' , ( ) => {
137+ const parser = new HtmlParser ( getParserOpt ( ) )
138+ const result = parser . parse (
139+ `<div id="app"><prism-editor :xlink:href="'myHref'" :foo="dddd" xmlns:xlink="http://www.w3.org/1999/xlink" /></div>` ,
140+ 'TestComp'
141+ )
142+
143+ expect ( result . errors . length ) . toBe ( 0 )
144+
145+ const node = fromWebParser ( result . rootNodes , { } )
146+
147+ expect ( node ) . toMatchSnapshot ( )
148+ } )
149+
127150test ( 'Case sensitive attributes' , ( ) => {
128- const parser = new HtmlParser ( )
151+ const parser = new HtmlParser ( getParserOpt ( ) )
129152 const result = parser . parse ( `<div ASYNC></div>` , 'TestComp' )
130153
131154 expect ( result . errors . length ) . toBe ( 0 )
@@ -136,7 +159,7 @@ test('Case sensitive attributes', () => {
136159} )
137160
138161test ( 'Doctype' , ( ) => {
139- const parser = new HtmlParser ( )
162+ const parser = new HtmlParser ( getParserOpt ( ) )
140163 const result = parser . parse ( `<!DOCTYPE html>` , 'TestComp' )
141164
142165 expect ( result . errors . length ) . toBe ( 0 )
@@ -147,7 +170,7 @@ test('Doctype', () => {
147170} )
148171
149172test ( 'Doctype nameless' , ( ) => {
150- const parser = new HtmlParser ( )
173+ const parser = new HtmlParser ( getParserOpt ( ) )
151174 const result = parser . parse ( `<!DOCTYPE>` , 'TestComp' )
152175
153176 expect ( result . errors . length ) . toBe ( 0 )
@@ -158,7 +181,7 @@ test('Doctype nameless', () => {
158181} )
159182
160183test ( 'Doctype with html skeleton' , ( ) => {
161- const parser = new HtmlParser ( )
184+ const parser = new HtmlParser ( getParserOpt ( ) )
162185 const result = parser . parse (
163186 `<!DOCTYPE><html><head></head><body>foo</body></html>` ,
164187 'TestComp'
@@ -172,7 +195,7 @@ test('Doctype with html skeleton', () => {
172195} )
173196
174197test ( 'Attributes with namespace' , ( ) => {
175- const parser = new HtmlParser ( )
198+ const parser = new HtmlParser ( getParserOpt ( ) )
176199 const result = parser . parse (
177200 `<svg xmlns:xlink="http://www.w3.org/1999/xlink"></svg>` ,
178201 'TestComp'
@@ -186,7 +209,7 @@ test('Attributes with namespace', () => {
186209} )
187210
188211test ( 'Gaps detection - should set gapAfter data on elements followed by empty lines' , ( ) => {
189- const parser = new HtmlParser ( )
212+ const parser = new HtmlParser ( getParserOpt ( ) )
190213 const result = parser . parse (
191214 `<div></div>
192215
0 commit comments