Ox.sanitizeHTML: add replaceTags option

This commit is contained in:
rolux 2013-02-15 18:01:28 +05:30
parent 092f27ca19
commit 3cdaebadee

View file

@ -40,7 +40,7 @@
img: [ img: [
[ [
/<img [^<>]*?src="((\/|https?:\/\/).+?)".*?>/gi, /<img [^<>]*?src="((\/|https?:\/\/).+?)".*?>/gi,
'<img src="$1">' '<img src="{1}">'
] ]
], ],
rtl: [ rtl: [
@ -499,9 +499,10 @@
> Ox.sanitizeHTML('<http://foo.com>') > Ox.sanitizeHTML('<http://foo.com>')
'&lt;<a href="http://foo.com">http://foo.com</a>&gt;' '&lt;<a href="http://foo.com">http://foo.com</a>&gt;'
@*/ @*/
Ox.sanitizeHTML = function(html, tags) { Ox.sanitizeHTML = function(html, tags, replaceTags) {
var matches = []; var matches = [];
tags = tags || defaultTags; tags = tags || defaultTags;
replaceTags = replaceTags || {};
// html = Ox.clean(html); fixme: can this be a parameter? // html = Ox.clean(html); fixme: can this be a parameter?
if (tags.indexOf('[]') > -1) { if (tags.indexOf('[]') > -1) {
html = html.replace( html = html.replace(
@ -513,7 +514,7 @@
}); });
} }
tags.forEach(function(tag) { tags.forEach(function(tag) {
var array = replace[tag] || replace['*'](tag); var array = replaceTags[tag] || replace[tag] || replace['*'](tag);
Ox.forEach(array, function(value) { Ox.forEach(array, function(value) {
html = html.replace(value[0], function() { html = html.replace(value[0], function() {
matches.push(Ox.formatString(value[1], arguments)); matches.push(Ox.formatString(value[1], arguments));