C# Class Subtext.Framework.Text.HtmlHelper

Static class used for parsing, formatting, and validating HTML.
Afficher le fichier Open project: ayende/Subtext

Méthodes publiques

Méthode Description
AppendAttributeValue ( WebControl control, string name, string value ) : void

Appends the attribute value to the control appropriately.

AppendCssClass ( WebControl control, string newClass ) : void

Appends a CSS class to a control.

CheckForUrl ( string text ) : Uri

Checks the text and prepends "http://" if it doesn't have it already.

ConvertHtmlToXHtml ( Entry entry ) : bool

Converts the entry body into XHTML compliant text. Returns false if it encounters a problem in doing so.

ConvertHtmlToXHtml ( string html, string>.Converter converter ) : string

Converts the specified html into XHTML compliant text.

ConvertToAllowedHtml ( NameValueCollection allowedHtmlTags, string text ) : string

Filters text to only allow defined HTML.

ConvertToAllowedHtml ( string text ) : string

Filters text to only allow defined HTML.

ConvertUrlsToHyperLinks ( string html ) : string

Wraps an anchor tag around all urls. Makes sure not to wrap already wrapped urls.

GetLinks ( string text ) : StringCollection

Returns a string collection of URLs within the specified text.

HasIllegalContent ( string s ) : bool

Tests the specified string looking for illegal characters or html tags.

ParseTags ( string html ) : List

Parses some html and returns a string collection of the tag names contained within the HTML.

ParseUri ( string uri ) : Uri

Parses the URI.

RemoveCssClass ( WebControl control, string classToRemove ) : void

Removes a CSS class to a control.

RemoveHtml ( string text ) : string

Strips HTML tags from the specified text.

RemoveHtmlAndComments ( string text ) : string

Strips HTML tags and comments from the specified text

RemoveHtmlComments ( string text ) : string

Strips HTML comments from the specified text

ReplaceHost ( string originalUrl, string newHost ) : string

Replaces the host in the given url with the new host.

SafeFormat ( string stringToTransform ) : string

The only HTML we will allow is hyperlinks. We will however, check for line breaks and replace them with

ShortenUrl ( string url, int max ) : string

Shortens a url for display.

StripRTB ( string text, string host ) : string

Strips the RTB, whatever that is.

Private Methods

Méthode Description
ConvertHtmlToXHtml ( SgmlReader reader, string html, string>.Converter converter ) : string

Converts the specified html into XHTML compliant text.

FilterAttributes ( string tagName, Match match, NameValueCollection allowedHtml ) : string

Removes any non-permitted attributes for the given tagName. The permitted attributes are determined by the given allowedHtml collection.

This will be a high volume method, so make it as efficient as possible

GetAttributeNameValues ( Match match ) : NameValueCollection
HtmlSafe ( string text ) : string
RemoveNewLineBeforeCDATA ( string text ) : string

Method Details

AppendAttributeValue() public static méthode

Appends the attribute value to the control appropriately.
public static AppendAttributeValue ( WebControl control, string name, string value ) : void
control System.Web.UI.WebControls.WebControl
name string
value string
Résultat void

AppendCssClass() public static méthode

Appends a CSS class to a control.
public static AppendCssClass ( WebControl control, string newClass ) : void
control System.Web.UI.WebControls.WebControl The control.
newClass string The new class.
Résultat void

CheckForUrl() public static méthode

Checks the text and prepends "http://" if it doesn't have it already.
public static CheckForUrl ( string text ) : Uri
text string Text.
Résultat System.Uri

ConvertHtmlToXHtml() public static méthode

Converts the entry body into XHTML compliant text. Returns false if it encounters a problem in doing so.
public static ConvertHtmlToXHtml ( Entry entry ) : bool
entry Subtext.Framework.Components.Entry Entry.
Résultat bool

ConvertHtmlToXHtml() public static méthode

Converts the specified html into XHTML compliant text.
public static ConvertHtmlToXHtml ( string html, string>.Converter converter ) : string
html string html to convert.
converter string>.Converter The converter.
Résultat string

ConvertToAllowedHtml() public static méthode

Filters text to only allow defined HTML.
public static ConvertToAllowedHtml ( NameValueCollection allowedHtmlTags, string text ) : string
allowedHtmlTags System.Collections.Specialized.NameValueCollection The allowed html tags.
text string Text.
Résultat string

ConvertToAllowedHtml() public static méthode

Filters text to only allow defined HTML.
public static ConvertToAllowedHtml ( string text ) : string
text string Text.
Résultat string

ConvertUrlsToHyperLinks() public static méthode

Wraps an anchor tag around all urls. Makes sure not to wrap already wrapped urls.
public static ConvertUrlsToHyperLinks ( string html ) : string
html string Html containing urls to convert.
Résultat string

GetLinks() public static méthode

Returns a string collection of URLs within the specified text.
public static GetLinks ( string text ) : StringCollection
text string The text.
Résultat System.Collections.Specialized.StringCollection

HasIllegalContent() public static méthode

Tests the specified string looking for illegal characters or html tags.
public static HasIllegalContent ( string s ) : bool
s string S.
Résultat bool

ParseTags() public static méthode

Parses some html and returns a string collection of the tag names contained within the HTML.
public static ParseTags ( string html ) : List
html string
Résultat List

ParseUri() public static méthode

Parses the URI.
public static ParseUri ( string uri ) : Uri
uri string The URI.
Résultat System.Uri

RemoveCssClass() public static méthode

Removes a CSS class to a control.
public static RemoveCssClass ( WebControl control, string classToRemove ) : void
control System.Web.UI.WebControls.WebControl The control.
classToRemove string The new class.
Résultat void

RemoveHtml() public static méthode

Strips HTML tags from the specified text.
public static RemoveHtml ( string text ) : string
text string The text.
Résultat string

RemoveHtmlAndComments() public static méthode

Strips HTML tags and comments from the specified text
public static RemoveHtmlAndComments ( string text ) : string
text string The text
Résultat string

RemoveHtmlComments() public static méthode

Strips HTML comments from the specified text
public static RemoveHtmlComments ( string text ) : string
text string The text
Résultat string

ReplaceHost() public static méthode

Replaces the host in the given url with the new host.
public static ReplaceHost ( string originalUrl, string newHost ) : string
originalUrl string
newHost string
Résultat string

SafeFormat() public static méthode

The only HTML we will allow is hyperlinks. We will however, check for line breaks and replace them with
public static SafeFormat ( string stringToTransform ) : string
stringToTransform string
Résultat string

ShortenUrl() public static méthode

Shortens a url for display.
public static ShortenUrl ( string url, int max ) : string
url string The URL.
max int Maximum size for the url. Anything longer gets shortened.
Résultat string

StripRTB() public static méthode

Strips the RTB, whatever that is.
public static StripRTB ( string text, string host ) : string
text string Text.
host string Host.
Résultat string