Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,22 @@ string.js - Copyright (C) 2012-2013, JP Richardson <[email protected]>
return new this.constructor(s);
},

allowTags: function(allowed) { //from php.js
var raw = this.s, args = arguments.length > 0 ? arguments : [''];
allowed = (((allowed || '') + '')
.toLowerCase()
.match(/<[a-z][a-z0-9]*>/g) || [])
.join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
var s = raw.replace(commentsAndPhpTags, '')
.replace(tags, function ($0, $1) {
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
});

return new this.constructor(s);
},

template: function(values, opening, closing) {
var s = this.s
var opening = opening || Export.TMPL_OPEN
Expand Down
Loading