Table of Contents

Class HTMLHelper

Namespace
CMS.Helpers
Assembly
CMS.Helpers.dll

HTML utility methods.

public static class HTMLHelper
Inheritance
object
HTMLHelper

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 string

Input 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 string

Text 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 string

HTML code.

pathBase string

Path base.

urlPrefix string

URL prefix to ensure.

decorateHrefAttributes bool

Indicates whether 'href' attributes should be decorated with the virtual context prefix.

decoratePathArbiter HTMLHelper.DecoratePathArbiterHandler

The 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 string

HTML code.

pathBase string

Path base.

urlPrefix string

URL prefix to ensure.

domains IEnumerable<Uri>

Domains that can be unresolved.

decorateHrefAttributes bool

Indicates whether 'href' attributes should be decorated with the virtual context prefix.

decoratePathArbiter HTMLHelper.DecoratePathArbiterHandler

The 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 string

Input 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 string

Input 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 string
attribute 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 string

HTML text

commentsReplacement string

Replacement 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 string

HTML code

pathBase string

Path 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 string

HTML code.

pathBase string

Path 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 string

HTML text

replaceEntities bool

True if replace special entities

replaceComments bool

Whether to replace HTML comments

tagReplacement string

Replacement for HTML tags - inner of tag is string "$2"

entitiesReplacement string

Replacement for HTML entities

commentsReplacement string

Replacement 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 string

HTML text

replaceEntities bool

True if replace special entities

tagReplacement string

Replacement 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 string

HTML code.

pathBase string

Path 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 string

HTML code.

pathBase string

Path base.

pathModifier Func<string, string>

Method that is called after each of the local path is unresolved. Input parameter format: "~/relativePath?query=.."

Returns

string