// (c) Kuso Mendokusee, 2004
RichEdit.prototype.cleanUpAttributesTagOne = function( tag, reAttr, reverseAttr )
{
var re = /([a-z\:]+)=(("[^"]*")|([^ >]*))/i;
var arr = re.exec(tag);
if (arr === null) return tag;
arrs = String(arr[0]);
var eq = arrs.indexOf("=");
var name = arrs.substr(0,eq);
var li = arr.index + arrs.length;
var t = reAttr.test(name);
if ((!reAttr.test(name) && !reverseAttr) || (reAttr.test(name) && reverseAttr))
return tag.substr(0,arr.index) + tag.substr(li);
var value = arrs.substr(eq+1);
if (value.charAt(0) == '"') value = value.substr(1);
if (value.charAt(value.length-1) == '"') value = value.substr(0,value.length-1);
value = '"'+ value.replace('"',"\\\"") +'"';
return tag.substr(0,arr.index) + name + "~=" + value + tag.substr(li);
}
RichEdit.prototype.cleanUpAttributesTag = function( tag, reAttr, reverseAttr )
{
var s1 = tag;
var s2 = tag+"+";
while (s1 != s2)
{ s2 = s1;
s1 = this.cleanUpAttributesTagOne(s1, reAttr, reverseAttr);
}
s1 = s1.replace( /[ ]+/, " ");
s1 = s1.replace( /[ ]+>/, ">");
return s1.replace( /~=/g, "=" );
}
// standard MSIE s1-s2 tag walker
RichEdit.prototype.cleanUpAttributesOne = function( s, reTag, reAttr, reverseTag, reverseAttr )
{
var re = /<[^>~][^>]*>/i;
arr = re.exec(s);
if (arr === null) return s;
arrs = String(arr);
new_arrs = "<~" + arrs.substr(1);
var li = arr.index + arrs.length;
var t = reTag.test(arrs)
if ((t && !reverseTag) || (!t &&reverseTag))
s = s.substr(0,arr.index) + this.cleanUpAttributesTag( new_arrs, reAttr, reverseAttr ) + s.substr(li);
else
s = s.substr(0,arr.index) + new_arrs + s.substr(li);
return s;
}
RichEdit.prototype.cleanUpAttributesAll = function( s, restrTag, restrAttr, reverseTag, reverseAttr )
{
// create res
var reTag = new RegExp( "<("+restrTag+")[ >]", "i" );
var reAttr = new RegExp( "^("+restrAttr+")$", "i" );
// s1-s2 standard MSIE5 workaround
var s1 = s;
var s2 = s+"+";
while (s1 != s2)
{ s2 = s1;
s1 = this.cleanUpAttributesOne(s1, reTag, reAttr, reverseTag, reverseAttr);
}
return s1.replace( /<~/g, "<" );
}