File tree 3 files changed +20
-2
lines changed
3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ Tag objects can contain three keys. The `tag` key takes the name of the tag as t
82
82
### ` directives `
83
83
Type: ` Array `
84
84
Default: ` [{name: '!doctype', start: '<', end: '>'}] `
85
- Description: * Adds processing of custom directives*
85
+ Description: * Adds processing of custom directives. Note: The property ``` name ``` in custom directives can be ``` String ``` or ``` RegExp ``` type *
86
86
87
87
## License
88
88
Original file line number Diff line number Diff line change @@ -29,11 +29,20 @@ function postHTMLParser(html, options) {
29
29
var directives = options . directives || defaultDirectives ;
30
30
var last = bufArray . last ( ) ;
31
31
32
+ var tagName ;
32
33
for ( var i = 0 ; i < directives . length ; i ++ ) {
33
34
var directive = directives [ i ] ;
34
35
var directiveText = directive . start + data + directive . end ;
36
+ var isDirective = false ;
35
37
36
- if ( name . toLowerCase ( ) === directive . name ) {
38
+ tagName = name . toLowerCase ( ) ;
39
+ if ( ( directive . name instanceof RegExp ) && directive . name . test ( tagName ) ) {
40
+ isDirective = true ;
41
+ } else if ( tagName === directive . name ) {
42
+ isDirective = true ;
43
+ }
44
+
45
+ if ( isDirective ) {
37
46
if ( ! last ) {
38
47
results . push ( directiveText ) ;
39
48
return ;
Original file line number Diff line number Diff line change @@ -131,6 +131,15 @@ describe('PostHTML-Parser test', function() {
131
131
expect ( parser ( '<?php echo "Hello word"; ?>' , customDirectives ) ) . to . eql ( [ '<?php echo "Hello word"; ?>' ] ) ;
132
132
} ) ;
133
133
134
+ it ( 'should be parse regular expression directive' , function ( ) {
135
+ var customDirectives = { directives : [
136
+ { name : / \? ( p h p | = ) .* / , start : '<' , end : '>' }
137
+ ] } ;
138
+
139
+ expect ( parser ( '<?php echo "Hello word"; ?>' , customDirectives ) ) . to . eql ( [ '<?php echo "Hello word"; ?>' ] ) ;
140
+ expect ( parser ( '<?="Hello word"?>' , customDirectives ) ) . to . eql ( [ '<?="Hello word"?>' ] ) ;
141
+ } ) ;
142
+
134
143
it ( 'should be parse directives and tag' , function ( ) {
135
144
var customDirectives = { directives : [
136
145
{ name : '!doctype' , start : '<' , end : '>' } ,
You can’t perform that action at this time.
0 commit comments