HtmlExtensions Class

Namespace:
Weavy.Core.Helpers
Assembly:
Weavy.Core.dll

Helper and extension methods for parsing, formatting, and validating HTML.

public static class HtmlExtensions
Inheritance:
System.Object → HtmlExtensions

Fields

BindingPattern A regular expression pattern for validating a binding, i.e. an IP adress or a DNS host name.
EmailPattern A regular expression pattern for validating an email address and splitting it in the local and domain part.
HostPattern A regular expression pattern for validating a DNS host name.
IpAddressPattern A regular expression pattern for validating an IP adress.
LinkifyPattern A regular expression pattern for finding urls in text.
PageSeparator A string used to split a string in more and less portions.
QuotePattern A regular expression pattern for matching html quotes.
RolePattern A regular expression pattern for validating roles. All charachters are valid except , + " \ < > and ;
RootRelativeUrlPattern A regular expression pattern for finding root-relative urls in html.
SlugPattern A regular expression pattern for validating slugs. Valid characters are [a-zA-Z0-9-_.!~'();@=$,]. A slug must also start and end with a letter or digit.
UriPattern A regular expression pattern for parsing the components (scheme, host, path, query and fragment) of an url.
UrlPattern A regular expression pattern for validating urls.
UsernamePattern A regular expression pattern for validating usernames. Valid characters are [a-zA-Z0-9_].

Methods

AttributeSafe(String) Converts quotation marks ("), ampersands (&) and left angle brackets (<) to equivalent character entities. The result should be used only for attributes that are in double quotation marks.
CleanHtml(String) Performs various cleanup functions on a html string.
Emphasize(String, IList) Emphasizes (wraps in <em></em>) all matching search terms in the input text.
FixUrlWithoutProtocol(String, String) Fixes urls without protocol, e.g. www.weavy.com => http://www.weavy.com
GetDataUris(String) Returns a collection of data-uris found in the specified html string, see https://tools.ietf.org/html/rfc2397.
GetHtmlForEmail(Message) Helper method that makes the message suitable for sending in emails.
GetHtmlForEmail(Notification) Helper method that makes the notification suitable for sending in emails
GetLinks(String) Returns a string collection of links (<a href=""></a>) within the specified text.
GetMatchingText(String, Int32, IList) Gets a relevant section of text related to the search terms.
HtmlSafe(String, Boolean) Converts ampersands (&), left angle brackets (<), right angle brackets (>) and optionally line breaks (\n) to equivalent character entities.
Linkify(String, String) Wraps an <a href=""></a> tag with the specified rel attribute around all urls in the text.
RemoveLinks(String) Remove all anchors from the specified html string but preserve other content.
ShortenUrl(String, Int32) Shortens a url for display.
StripHtml(String, Boolean) Returns a string with all HTML tags and comments removed. This is useful for displaying HTML in plain text and stripping formatting like bold and italics.
ToAbsoluteUrls(String, String) Converts all relative urls within the provided html string to absolute urls.
TruncateQuotes(String, Int32) Will truncate the content of any q-tag.
TruncateQuotesAndConvertEmojiToImage(String, Int32) Will truncate the content of any q-tag and also convert emoji in the quoted text to images.