Created
April 6, 2016 12:40
-
-
Save ArjunVachhani/9f0e4d1b1ff894ae72f075acbffbbc15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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