Class HTMLHelper
HTML utility methods.
public static class HTMLHelper
- Inheritance
-
objectHTMLHelper
Fields
HTML_BREAK
HTML break tag - "<br />".
[Obsolete("Constant is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public const string HTML_BREAK = "<br />"
Field Value
- string
Properties
RegexHtmlToTextWhiteSpace
Regular expression for removing white spaces
[Obsolete("Property is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static Regex RegexHtmlToTextWhiteSpace { get; }
Property Value
- Regex
Methods
EncodeForHtmlAttribute(string)
Encodes string to be used as the HTML attribute value.
public static string EncodeForHtmlAttribute(string inputText)
Parameters
inputText
stringInput text to encode
Returns
- string
EnsureHtmlLineEndings(string)
Ensures the HTML line endings (<br />) in the given text.
[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static string EnsureHtmlLineEndings(string text)
Parameters
text
stringText to process
Returns
- string
EnsureURLPrefixes(string, string, string, bool, DecoratePathArbiterHandler)
Ensures that all local URLs have given prefix.
[Obsolete("Use EnsureURLPrefixes(string, string, string, IEnumerable<Uri>, bool, DecoratePathArbiterHandler) instead.")]
[ObsoleteSince(29, 7)]
public static string EnsureURLPrefixes(string html, string pathBase, string urlPrefix, bool decorateHrefAttributes = true, HTMLHelper.DecoratePathArbiterHandler decoratePathArbiter = null)
Parameters
html
stringHTML code.
pathBase
stringPath base.
urlPrefix
stringURL prefix to ensure.
decorateHrefAttributes
boolIndicates whether 'href' attributes should be decorated with the virtual context prefix.
decoratePathArbiter
HTMLHelper.DecoratePathArbiterHandlerThe arbiter which decides whether the given path should be decorated with a virtual context prefix or kept as is.
Returns
- string
EnsureURLPrefixes(string, string, string, IEnumerable<Uri>, bool, DecoratePathArbiterHandler)
Ensures that all local URLs have given prefix.
public static string EnsureURLPrefixes(string html, string pathBase, string urlPrefix, IEnumerable<Uri> domains, bool decorateHrefAttributes = true, HTMLHelper.DecoratePathArbiterHandler decoratePathArbiter = null)
Parameters
html
stringHTML code.
pathBase
stringPath base.
urlPrefix
stringURL prefix to ensure.
domains
IEnumerable<Uri>Domains that can be unresolved.
decorateHrefAttributes
boolIndicates whether 'href' attributes should be decorated with the virtual context prefix.
decoratePathArbiter
HTMLHelper.DecoratePathArbiterHandlerThe arbiter which decides whether the given path should be decorated with a virtual context prefix or kept as is.
Returns
- string
HTMLDecode(string)
HTML decoding function. Returns a string converted into an HTML-decoded string.
[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static string HTMLDecode(string inputText)
Parameters
inputText
stringInput text to encode
Returns
- string
HTMLEncode(string)
HTML encoding function. Returns a string converted into an HTML-encoded string. Function does not encode previously encoded HTML entity (avoiding double HTML escaping).
public static string HTMLEncode(string inputText)
Parameters
inputText
stringInput text to encode
Returns
- string
RemoveAttribute(string, string)
Removes all occurrences of and its value in the .
public static string RemoveAttribute(string html, string attribute)
Parameters
html
stringattribute
string
Returns
- string
RemoveComments(string, string)
Remove HTML comments from given text.
[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static string RemoveComments(string htmlText, string commentsReplacement = "")
Parameters
htmlText
stringHTML text
commentsReplacement
stringReplacement for HTML comments
Returns
- string
ResolveUrls(string, string)
Resolves relative URLs in the given HTML(string).
public static string ResolveUrls(string html, string pathBase)
Parameters
html
stringHTML code
pathBase
stringPath base
Returns
- string
Remarks
In the live site it resolves all URLs ("~/"). In the administration interface only URLs in "src", "href", "poster", "srcset" attributes and "url()" CSS function are resolved.
ResolveUrls(string, string, Func<string, string>)
Resolves relative URI if used in "src=" or "href=" or "poster=" or "srcset=" or "url(".
public static string ResolveUrls(string html, string pathBase, Func<string, string> pathModifier)
Parameters
html
stringHTML code.
pathBase
stringPath base.
pathModifier
Func<string, string>Method that is called before each of the local path is resolved. Input parameter format: "~/relativePath?query=.."
Returns
- string
StripTags(string, bool, bool, string, string, string)
Remove HTML tags from text.
public static string StripTags(string htmlText, bool replaceEntities, bool replaceComments, string tagReplacement, string entitiesReplacement, string commentsReplacement)
Parameters
htmlText
stringHTML text
replaceEntities
boolTrue if replace special entities
replaceComments
boolWhether to replace HTML comments
tagReplacement
stringReplacement for HTML tags - inner of tag is string "$2"
entitiesReplacement
stringReplacement for HTML entities
commentsReplacement
stringReplacement for HTML comments
Returns
- string
StripTags(string, bool, string)
Remove HTML tags from text.
public static string StripTags(string htmlText, bool replaceEntities = true, string tagReplacement = "")
Parameters
htmlText
stringHTML text
replaceEntities
boolTrue if replace special entities
tagReplacement
stringReplacement for HTML tags - inner of tag is string "$2"
Returns
- string
UnResolveUrls(string, string, IEnumerable<Uri>, Func<string, string>)
Unresolves relative URI if used in "src=" or "href=" or "poster=" or "srcset=" or "url(".
public static string UnResolveUrls(string html, string pathBase, IEnumerable<Uri> domains, Func<string, string> pathModifier)
Parameters
html
stringHTML code.
pathBase
stringPath base.
domains
IEnumerable<Uri>Domains to unresolve.
pathModifier
Func<string, string>Method that is called after each of the local path is unresolved. Input parameter format: "~/relativePath?query=.."
Returns
- string
UnResolveUrls(string, string, Func<string, string>)
Unresolves relative URI if used in "src=" or "href=" or "poster=" or "srcset=" or "url(".
[Obsolete("Use UnResolveUrls(string, string, IEnumerable<Uri>, Func<string, string>) instead.")]
[ObsoleteSince(29, 7)]
public static string UnResolveUrls(string html, string pathBase, Func<string, string> pathModifier = null)
Parameters
html
stringHTML code.
pathBase
stringPath base.
pathModifier
Func<string, string>Method that is called after each of the local path is unresolved. Input parameter format: "~/relativePath?query=.."
Returns
- string