C# Class Subtext.Framework.Text.HtmlHelper

Static class used for parsing, formatting, and validating HTML.
显示文件 Open project: ayende/Subtext

Public Methods

Method 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

Method 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 method

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
return void

AppendCssClass() public static method

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.
return void

CheckForUrl() public static method

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

ConvertHtmlToXHtml() public static method

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.
return bool

ConvertHtmlToXHtml() public static method

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.
return string

ConvertToAllowedHtml() public static method

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.
return string

ConvertToAllowedHtml() public static method

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

ConvertUrlsToHyperLinks() public static method

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.
return string

GetLinks() public static method

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

HasIllegalContent() public static method

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

ParseTags() public static method

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

ParseUri() public static method

Parses the URI.
public static ParseUri ( string uri ) : Uri
uri string The URI.
return System.Uri

RemoveCssClass() public static method

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.
return void

RemoveHtml() public static method

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

RemoveHtmlAndComments() public static method

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

RemoveHtmlComments() public static method

Strips HTML comments from the specified text
public static RemoveHtmlComments ( string text ) : string
text string The text
return string

ReplaceHost() public static method

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

SafeFormat() public static method

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

ShortenUrl() public static method

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.
return string

StripRTB() public static method

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