@@ -4,7 +4,8 @@ import path from 'path';
4
4
5
5
const LOCALES_DIR = path . join ( '..' , 'locales' ) ;
6
6
7
- const ALLOWED_TAGS = [ 'b' ] ;
7
+ const ALLOWED_TAGS = [ 'b' , 'br' ] ;
8
+ const ALLOWED_VOID_TAGS = [ 'br' ] ;
8
9
9
10
function getLocales ( ) : string [ ] {
10
11
const localesContent = fs . readdirSync ( LOCALES_DIR ) ;
@@ -70,22 +71,25 @@ function checkHtmlTagsImpl(value: string): { correct: boolean, amount: number }
70
71
// item.
71
72
let tagStack : string [ ] = [ ] ;
72
73
for ( let tag of tagTypes ) {
74
+ const selfClosing = tag . endsWith ( '/' ) ;
73
75
const endTag = tag . startsWith ( '/' ) ;
74
- tag = endTag ? tag . slice ( 1 ) : tag ;
76
+ tag = endTag ? tag . slice ( 1 ) : selfClosing ? tag . slice ( 0 , - 1 ) : tag ;
75
77
76
78
if ( ! ALLOWED_TAGS . includes ( tag ) ) {
77
79
console . error ( `Tag "<${ tag } >" not allowed: "${ value } "` ) ;
78
80
return { correct : false , amount : NaN } ;
79
81
}
80
82
81
- if ( endTag ) {
82
- // End tags require a matching start tag.
83
- if ( tag !== tagStack . pop ( ) ) {
84
- console . error ( `Closing non-existent start-tag (</${ tag } >) in "${ value } "` ) ;
85
- return { correct : false , amount : NaN } ;
83
+ if ( ! ALLOWED_VOID_TAGS . includes ( tag ) ) {
84
+ if ( endTag ) {
85
+ // End tags require a matching start tag.
86
+ if ( tag !== tagStack . pop ( ) ) {
87
+ console . error ( `Closing non-existent start-tag (</${ tag } >) in "${ value } "` ) ;
88
+ return { correct : false , amount : NaN } ;
89
+ }
90
+ } else {
91
+ tagStack . push ( tag ) ;
86
92
}
87
- } else {
88
- tagStack . push ( tag ) ;
89
93
}
90
94
}
91
95
0 commit comments