Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ArjunVachhani/9f0e4d1b1ff894ae72f075acbffbbc15 to your computer and use it in GitHub Desktop.
Save ArjunVachhani/9f0e4d1b1ff894ae72f075acbffbbc15 to your computer and use it in GitHub Desktop.
public static class HtmlExtension
{
private static string[] htmlBooleanAttributes = (new[] { "selected", "checked", "disabled", "readonly", "multiple" }).SelectMany(x => new[] { x + "=\"\"", x + "=\"false\"" }).ToArray();
public static IHtmlString HackIt(this IHtmlString htmlString)
{
if (htmlString != null)
{
string str = htmlString.ToString();
foreach (var attribute in htmlBooleanAttributes)
{
int index = -1;
do
{
var searchIndex = index == -1 ? 0 : index;
index = str.IndexOf(attribute, searchIndex, StringComparison.OrdinalIgnoreCase);
if (index > -1)
str = str.Remove(index, attribute.Length);
} while (index > -1);
}
return new HtmlString(str);
}
return htmlString;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment