private HtmlTag UpgradeToMetaCharsetTag(HtmlTag tag)
{
HtmlTag upgradedTag = tag;
HtmlAttribute contentAttribute = tag.Attributes.SingleOrDefault(a => a.NameInLowercase == "content");
if (contentAttribute != null)
{
string content = contentAttribute.Value.Trim();
if (content.Length > 0)
{
Match contentMatch = _metaContentTypeTagValueRegex.Match(content);
if (contentMatch.Success)
{
string charset = contentMatch.Groups["charset"].Value;
upgradedTag = new HtmlTag(tag.Name, tag.NameInLowercase,
new List<HtmlAttribute>
{
new HtmlAttribute("charset", "charset", charset, HtmlAttributeType.Text)
},
tag.Flags
);
}
}
}
return upgradedTag;
}