1- import { Parser , ParserOptions } from ' htmlparser2' ;
2- import { LocationTracker , SourceLocation } from ' ./location-tracker' ;
1+ import { Parser , ParserOptions } from " htmlparser2" ;
2+ import { LocationTracker , SourceLocation } from " ./location-tracker" ;
33
44export type Directive = {
55 name : string | RegExp ;
@@ -30,15 +30,15 @@ export type Node = NodeText | NodeTag;
3030const defaultOptions : ParserOptions = {
3131 lowerCaseTags : false ,
3232 lowerCaseAttributeNames : false ,
33- decodeEntities : false
33+ decodeEntities : false ,
3434} ;
3535
3636const defaultDirectives : Directive [ ] = [
3737 {
38- name : ' !doctype' ,
39- start : '<' ,
40- end : '>'
41- }
38+ name : " !doctype" ,
39+ start : "<" ,
40+ end : ">" ,
41+ } ,
4242] ;
4343
4444export const parser = ( html : string , options : Options = { } ) : Node [ ] => {
@@ -54,7 +54,7 @@ export const parser = (html: string, options: Options = {}): Node[] => {
5454
5555 function isDirective ( directive : Directive , tag : string ) : boolean {
5656 if ( directive . name instanceof RegExp ) {
57- const regex = new RegExp ( directive . name . source , 'i' ) ;
57+ const regex = new RegExp ( directive . name . source , "i" ) ;
5858
5959 return regex . test ( tag ) ;
6060 }
@@ -96,7 +96,7 @@ export const parser = (html: string, options: Options = {}): Node[] => {
9696 return ;
9797 }
9898
99- if ( typeof last === ' object' ) {
99+ if ( typeof last === " object" ) {
100100 if ( last . content === undefined ) {
101101 last . content = [ ] ;
102102 }
@@ -118,7 +118,7 @@ export const parser = (html: string, options: Options = {}): Node[] => {
118118 return ;
119119 }
120120
121- if ( typeof last === ' object' ) {
121+ if ( typeof last === " object" ) {
122122 if ( last . content === undefined ) {
123123 last . content = [ ] ;
124124 }
@@ -146,7 +146,7 @@ export const parser = (html: string, options: Options = {}): Node[] => {
146146 if ( options . sourceLocations ) {
147147 buf . location = {
148148 start : locationTracker . getPosition ( parser . startIndex ) ,
149- end : locationTracker . getPosition ( parser . endIndex )
149+ end : locationTracker . getPosition ( parser . endIndex ) ,
150150 } ;
151151 lastOpenTagEndIndex = parser . endIndex ;
152152 }
@@ -165,7 +165,7 @@ export const parser = (html: string, options: Options = {}): Node[] => {
165165 function onclosetag ( name : string , isImplied : boolean ) {
166166 const buf : Node | undefined = bufArray . pop ( ) ;
167167
168- if ( buf && typeof buf === ' object' && buf . location && parser . endIndex !== null ) {
168+ if ( buf && typeof buf === " object" && buf . location && parser . endIndex !== null ) {
169169 if ( ! isImplied ) {
170170 buf . location . end = locationTracker . getPosition ( parser . endIndex ) ;
171171 } else if ( lastOpenTagEndIndex < parser . startIndex ) {
@@ -181,7 +181,7 @@ export const parser = (html: string, options: Options = {}): Node[] => {
181181 return ;
182182 }
183183
184- if ( typeof last === ' object' ) {
184+ if ( typeof last === " object" ) {
185185 if ( last . content === undefined ) {
186186 last . content = [ ] ;
187187 }
@@ -201,10 +201,10 @@ export const parser = (html: string, options: Options = {}): Node[] => {
201201 return ;
202202 }
203203
204- if ( typeof last === ' object' ) {
204+ if ( typeof last === " object" ) {
205205 if ( last . content && Array . isArray ( last . content ) && last . content . length > 0 ) {
206206 const lastContentNode = last . content [ last . content . length - 1 ] ;
207- if ( typeof lastContentNode === ' string' && ! lastContentNode . startsWith ( ' <!--' ) ) {
207+ if ( typeof lastContentNode === " string" && ! lastContentNode . startsWith ( " <!--" ) ) {
208208 last . content [ last . content . length - 1 ] = `${ lastContentNode } ${ text } ` ;
209209 return ;
210210 }
@@ -220,14 +220,17 @@ export const parser = (html: string, options: Options = {}): Node[] => {
220220 }
221221 }
222222
223- const parser = new Parser ( {
224- onprocessinginstruction,
225- oncomment,
226- onattribute,
227- onopentag,
228- onclosetag,
229- ontext
230- } , { ...defaultOptions , ...options } ) ;
223+ const parser = new Parser (
224+ {
225+ onprocessinginstruction,
226+ oncomment,
227+ onattribute,
228+ onopentag,
229+ onclosetag,
230+ ontext,
231+ } ,
232+ { ...defaultOptions , ...options } ,
233+ ) ;
231234
232235 parser . write ( html ) ;
233236 parser . end ( ) ;
0 commit comments