private string EscapeSpecialCharsWithinTagAttributes(string text)
{
var tokens = TokenizeHTML(text);
// now, rebuild text from the tokens
var sb = new StringBuilder(text.Length);
foreach (var token in tokens)
{
string value = token.Value;
if (token.Type == TokenType.Tag)
{
value = value.Replace(@"\", _escapeTable[@"\"]);
if (_autoHyperlink && value.StartsWith("<!")) // escape slashes in comments to prevent autolinking there -- http://meta.stackoverflow.com/questions/95987/html-comment-containing-url-breaks-if-followed-by-another-html-comment
value = value.Replace("/", _escapeTable["/"]);
value = Regex.Replace(value, "(?<=.)</?code>(?=.)", _escapeTable[@"`"]);
value = EscapeBoldItalic(value);
}
sb.Append(value);
}
return sb.ToString();
}