File tree 3 files changed +11
-3
lines changed
3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ Remove all html tags from a string.
137
137
var noItalics = html.stripTags('i');
138
138
//returns "<b>This is a string with html in it.</b>"
139
139
var noItalicsContent = html.stripTags('i', true);
140
- returns "<b>This is a string with in it.</b>"
140
+ // returns "<b>This is a string with in it.</b>"
141
141
142
142
### Returns
143
143
Original file line number Diff line number Diff line change @@ -95,8 +95,8 @@ var walk = function(string, replacements){
95
95
} ;
96
96
97
97
var getRegexForTag = function ( tag , contents ) {
98
- tag = tag || '' ;
99
- var regstr = contents ? "<" + tag + "(?!\\w)[^>]*>([\\s\\S]*?)<\/" + tag + "(?!\\w)>" : "<\/?" + tag + "([ ^>]+)? >" ;
98
+ tag = tag || ( contents ? '' : '\\w+' ) ;
99
+ var regstr = contents ? "<" + tag + "(?!\\w)[^>]*>([\\s\\S]*?)<\/" + tag + "(?!\\w)>" : "<\/?" + tag + "\/?>|<" + tag + "[\\s|\/][ ^>]* >";
100
100
return new RegExp ( regstr , "gi" ) ;
101
101
} ;
102
102
Original file line number Diff line number Diff line change @@ -50,6 +50,14 @@ describe('String.stripTags', function(){
50
50
expect ( 'i like cookies' . stripTags ( ) ) . toEqual ( 'i like cookies' ) ;
51
51
} ) ;
52
52
53
+ it ( 'should leave a string with <b></b> but no <br/>' , function ( ) {
54
+ expect ( '<b>Header</b><br/>' . stripTags ( 'br' ) ) . toEqual ( '<b>Header</b>' ) ;
55
+ } ) ;
56
+
57
+ it ( 'should leave a string with <br/> but no <b></b>' , function ( ) {
58
+ expect ( '<b class="foo">Header</b><br/>' . stripTags ( 'b' ) ) . toEqual ( 'Header<br/>' ) ;
59
+ } ) ;
60
+
53
61
} ) ;
54
62
55
63
describe ( 'String.truncate' , function ( ) {
You can’t perform that action at this time.
0 commit comments